Codeforces Round 267 (Div. 2)
E
Alex and Complicated Task
Codeforces
2300
原题
← D→
翻译中…

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*_{4*m*}$, that satisfies the following conditions:

翻译中…
  • $*b*_{4*k* + 1} = *b*_{4*k* + 3}$ for all valid integer $*k*$;
  • $*b*_{4*k* + 2} = *b*_{4*k* + 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.

翻译中…

Input

翻译中…

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})$.

翻译中…

Output

翻译中…

In the first line print a single integer $4*m*$ — the maximal possible length of required sequence $*b*$. In the second line print $4*m*$ integers $*b*_{1}, *b*_{2}, ..., *b*_{4*m*}$, that is required sequence.

翻译中…

If there are multiple optimal answers you may print any of them.

翻译中…

样例

Input #1
4
3 5 3 5
Output #1
4
3 5 3 5
InputCopy OutputCopy
Input #2
10
35 1 2 1 2 35 100 200 100 200
Output #2
8
1 2 1 2 100 200 100 200
InputCopy OutputCopy
题目信息
题号
467E
时间限制
2 s
内存限制
256 MB
标签
数据结构
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。