Description
Solutions
Submission
Construct Maximum Balanced Circle
🔥 FULLTIME

There are n people in a row. The height of the i-th person is a[i]. You can choose any subset of these people and try to arrange them into a balanced circle.

A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than 1. For example, let heights of chosen people be [a[i1], a[i2], ..., a[ik]], where k is the number of people you choose. Then the condition |a[ij] - a[ij+1]| ≤ 1 should be satisfied for all j from 1 to k - 1 and the condition |a[i1] - a[ik]| ≤ 1 should be also satisfied. |x| means the absolute value of x. It is obvious that the circle consisting of one person is balanced.

Your task is to choose the maximum number of people and construct a balanced circle consisting of all chosen people. It is obvious that the circle consisting of one person is balanced so the answer always exists.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 · 10^5) — the number of people.

The second line of the input contains n integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 2 · 10^5), where a[i] is the height of the i-th person.

Output

In the first line of the output print k — the number of people in the maximum balanced circle.

In the second line print k integers res[1], res[2], ..., res[k], where res[j] is the height of the j-th person in the maximum balanced circle. The condition |res[j] - res[j+1]| ≤ 1 should be satisfied for all j from 1 to k - 1 and the condition |res[1] - res[k]| ≤ 1 should be also satisfied.

Example 1:

Input:  heights = [4, 3, 5, 1, 2, 2, 1]
Output: [2, 1, 1, 2, 3]
Explanation:
N/A

Example 2:

Input:  heights = [3, 7, 5, 1, 5]
Output: [5, 5]
Explanation:
N/A

Example 3:

Input:  heights = [5, 1, 4]
Output: [4, 5]
Explanation:
N/A

Example 4:

Input:  heights = [2, 2, 3, 2, 1, 2, 2]
Output: [1, 2, 2, 2, 2, 3, 2]
Explanation:
N/A
Constraints:
    N/A
Thumbnail 0
Testcase

Result
Case 1

input:

output: