The following languages are only available languages for the problems from the contest

Kotlin Heroes: Episode 1:

- Kotlin 1.4.0

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
H. Longest Saw

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given the sequence $$$a_1, a_2, \dots, a_n$$$. You can choose any subset of elements and then reorder them to create a "saw".

The sequence $$$b_1, b_2, \dots, b_m$$$ is called a "saw" if the elements satisfy one of the following series of inequalities: $$$b_1>b_2<b_3>b_4<\dots$$$ or $$$b_1<b_2>b_3<b_4>\dots$$$.

Find the longest saw which can be obtained from a given array.

Note that both the given sequence $$$a$$$ and the required saw $$$b$$$ can contain duplicated (non-unique) values.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases in the input. Then the descriptions of the $$$t$$$ test cases follow. Each test case begins with a line containing integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$). Then a line containing $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) follows.

It's guaranteed that $$$\sum{n}$$$ doesn't exceed $$$2 \cdot 10^5$$$.

Output

For each test case, print two lines: print the length of the longest saw in the first line, and the saw itself in the second line. If there are several solutions, print any of them.

Example

Input

3 10 10 9 8 7 6 5 4 3 2 1 7 1 2 2 2 3 2 2 3 100 100 100

Output

10 1 6 2 7 3 8 4 9 5 10 4 2 1 3 2 1 100

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/21/2021 08:40:48 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|