CF467E.Alex and Complicated Task

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 a1,a2,...,ana_{1},a_{2},...,a_{n} . You are to find a longest sequence b1,b2,...,b4mb_{1},b_{2},...,b_{4m} , that satisfies the following conditions:

  • b4k+1=b4k+3b_{4k+1}=b_{4k+3} for all valid integer kk ;
  • b4k+2=b4k+4b_{4k+2}=b_{4k+4} for all valid integer kk ;
  • sequence bb is subsequence of aa (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 nn (1<=n<=5105)(1<=n<=5·10^{5}) . The next line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=109)(1<=a_{i}<=10^{9}) .

输出格式

In the first line print a single integer 4m4m — the maximal possible length of required sequence bb . In the second line print 4m4m integers b1,b2,...,b4mb_{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
    
首页