302427: CF467E. Alex and Complicated Task

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Alex and Complicated Task

题意翻译

给出一个序列 $\{a_i\}$,要求出其一个最长的子序列 $\{b_i\}$,使得这个子序列的长度 $len$ 满足 $len=4m$ ($m \in N^*$),且对于任意的 $k\in[0,m),k\in N^*$,都有 $b_{4k+1}=b_{4k+3}$ ,$b_{4k+2}=b_{4k+4}$ 成立。

题目描述

After you have read all the problems, probably, you think Alex is genius person. That's true! One day he came up with the following task. Given a sequence of integer numbers $ a_{1},a_{2},...,a_{n} $ . You are to find a longest sequence $ b_{1},b_{2},...,b_{4m} $ , that satisfies the following conditions: - $ b_{4k+1}=b_{4k+3} $ for all valid integer $ k $ ; - $ b_{4k+2}=b_{4k+4} $ for all valid integer $ k $ ; - sequence $ b $ is subsequence of $ a $ (not necessarily contiguous subsequence). And finally... Alex had given this complicated task to George, and George gave it to you. Help George to cope with the task.

输入输出格式

输入格式


The first line contains a single integer $ n $ $ (1<=n<=5·10^{5}) $ . The next line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ $ (1<=a_{i}<=10^{9}) $ .

输出格式


In the first line print a single integer $ 4m $ — the maximal possible length of required sequence $ b $ . In the second line print $ 4m $ integers $ b_{1},b_{2},...,b_{4m} $ , that is required sequence. If there are multiple optimal answers you may print any of them.

输入输出样例

输入样例 #1

4
3 5 3 5

输出样例 #1

4
3 5 3 5

输入样例 #2

10
35 1 2 1 2 35 100 200 100 200

输出样例 #2

8
1 2 1 2 100 200 100 200

Input

题意翻译

给出一个序列 $\{a_i\}$,要求出其一个最长的子序列 $\{b_i\}$,使得这个子序列的长度 $len$ 满足 $len=4m$ ($m \in N^*$),且对于任意的 $k\in[0,m),k\in N^*$,都有 $b_{4k+1}=b_{4k+3}$ ,$b_{4k+2}=b_{4k+4}$ 成立。

加入题单

算法标签: