D. Merge Equals
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value x
).
Determine how the array will look after described operations are performed.
For example, consider the given array looks like [3,4,1,2,2,1,1]
. It will be changed in the following way: [3,4,1,2,2,1,1] → [3,4,2,2,2,1] → [3,4,4,2,1] → [3,8,2,1].
If the given array is look like [1,1,3,1,1]
it will be changed in the following way: [1,1,3,1,1] → [2,3,1,1] → [2,3,2] → [3,4].
Input
The first line contains a single integer n
) — the number of elements in the array.
The second line contains a sequence from n
elements a1,a2,…,an (1≤ai≤109) — the elements of the array.
Output
In the first line print an integer k