Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-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.

This round has an unusual addition to the rules. For each problem you must use distinct language. Thus, if you have a submission that has passed at least one test or is being tested at the moment, then for this task you can use only this language and can not use it for other tasks. More details can be read by the link. Different implementations of the same language are considered to be the same language (for example, in C++ you can only solve one problem, regardless of the exact chosen compiler).

No tag edit access

E. Merge Equal Elements

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given a sequence of positive integers *a*_{1}, *a*_{2}, ..., *a*_{n}.

While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both and insert a single integer *x* + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.

You stop performing the operation when there is no pair of equal consecutive elements.

For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.

Determine the final sequence after you stop performing the operation.

Input

The first line contains a single integer *n* (2 ≤ *n* ≤ 2·10^{5}) — the number of elements in the sequence.

The second line contains the sequence of integers *a*_{1}, *a*_{2}, ..., *a*_{n} (1 ≤ *a*_{i} ≤ 10^{9}).

Output

In the first line print a single integer *k* — the number of elements in the sequence after you stop performing the operation.

In the second line print *k* integers — the sequence after you stop performing the operation.

Examples

Input

6

5 2 1 1 2 2

Output

2

5 4

Input

4

1000000000 1000000000 1000000000 1000000000

Output

1

1000000002

Input

7

4 10 22 11 12 5 6

Output

7

4 10 22 11 12 5 6

Note

The first example is described in the statements.

In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].

In the third example there are no two equal consecutive elements initially, so the sequence does not change.

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/12/2018 18:37:29 (d2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|