#include <bits/stdc++.h>
using namespace std;
inline int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
inline long long int bigmod(long long int a, long long int b, long long int m) {
  if (b == 0) return 1 % m;
  long long int x = bigmod(a, b / 2, m);
  x = (x * x) % m;
  if (b % 2 == 1) {
    x = (x * a) % m;
  }
  return x;
}
inline long long int phi(long long int n) {
  long long int ret = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
    }
    ret -= ret / i;
  }
  if (n > 1) {
    ret -= ret / n;
  }
  return ret;
}
long long int missing_number(long long int A[], long long int n) {
  long long int x1 = A[0], x2 = 1;
  for (int i = 1; i < n; i++) x1 ^= A[i];
  for (int i = 2; i <= n + 1; i++) x2 ^= i;
  return (x1 ^ x2);
}
bool isFibo(long long int n) {
  long long int A = (5 * n * n + 4);
  long long int B = (5 * n * n - 4);
  long long int C = sqrt(A);
  long long int D = sqrt(B);
  return (A == (C * C) || B == (D * D));
}
long long int classini(long long int n) { return (n & 1) ? -1 : 1; }
long long int factorial(int n) {
  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
long long int catanal(long long int n) {
  return (factorial(2 * n) / ((factorial(n + 1) * factorial(n))));
}
string orientation_3_ordered_point(vector<pair<int, int> > V) {
  long long int value =
      (V[1].second - V[0].second) * (V[2].first - V[1].first) -
      (V[1].first * V[0].first) * (V[2].second - V[1].second);
  string res;
  if (value == 0) res = "colinear";
  value == 1 ? res = "clockwise" : res = "counterclockwise";
  return res;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
string make_string(long long int num) {
  stringstream ss;
  ss << num;
  string s;
  ss >> s;
  return s;
}
long long int make_num(string s) {
  stringstream ss;
  long long int tmp;
  ss << s;
  ss >> tmp;
  return tmp;
}
int SET(int mask, int pos) { return (mask | (1 << pos)); }
int check(int mask, int pos) { return (mask & (1 << pos)); }
map<long long, vector<int> > G;
long long A[3000001];
map<long long, int> Nisi;
class cmp {
 public:
  bool operator()(long long &A, long long &B) { return A > B; }
};
priority_queue<long long, vector<long long>, cmp> PQ;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    PQ.push(A[i]);
    G[A[i]].push_back(i);
  }
  while (PQ.size()) {
    long long cur = PQ.top();
    PQ.pop();
    if (G[cur].size() < 2 || Nisi[cur]) continue;
    Nisi[cur] = 1;
    sort(G[cur].begin(), G[cur].end());
    for (int j = 0; j < G[cur].size(); j += 2) {
      if (j + 1 >= G[cur].size())
        break;
      else {
        long long newval = cur * 2;
        A[G[cur][j]] = 0;
        A[G[cur][j + 1]] = newval;
        G[newval].push_back(G[cur][j + 1]);
        PQ.push(newval);
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (A[i]) cnt++;
  }
  printf("%d", cnt);
  printf("\n");
  for (int i = 0; i < n; i++) {
    if (A[i]) printf("%lld ", A[i]);
  }
  printf("\n");
  return 0;
}

### Prompt

In CPP, your task is to solve the following problem:

You 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 that occurs in the array 2 or more times. Take the first two occurrences of x in this array (the two leftmost occurrences). Remove the left of these two occurrences, and the right one is replaced by the sum of this two values (that is, 2 ⋅ 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 (2 ≤ n ≤ 150 000) — the number of elements in the array.

The second line contains a sequence from n elements a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^{9}) — the elements of the array.

Output

In the first line print an integer k — the number of elements in the array after all the performed operations. In the second line print k integers — the elements of the array after all the performed operations.

Examples

Input

7
3 4 1 2 2 1 1


Output

4
3 8 2 1 


Input

5
1 1 3 1 1


Output

2
3 4 


Input

5
10 40 20 50 30


Output

5
10 40 20 50 30 

Note

The first two examples were considered in the statement.

In the third example all integers in the given array are distinct, so it will not change.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
inline long long int bigmod(long long int a, long long int b, long long int m) {
  if (b == 0) return 1 % m;
  long long int x = bigmod(a, b / 2, m);
  x = (x * x) % m;
  if (b % 2 == 1) {
    x = (x * a) % m;
  }
  return x;
}
inline long long int phi(long long int n) {
  long long int ret = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
    }
    ret -= ret / i;
  }
  if (n > 1) {
    ret -= ret / n;
  }
  return ret;
}
long long int missing_number(long long int A[], long long int n) {
  long long int x1 = A[0], x2 = 1;
  for (int i = 1; i < n; i++) x1 ^= A[i];
  for (int i = 2; i <= n + 1; i++) x2 ^= i;
  return (x1 ^ x2);
}
bool isFibo(long long int n) {
  long long int A = (5 * n * n + 4);
  long long int B = (5 * n * n - 4);
  long long int C = sqrt(A);
  long long int D = sqrt(B);
  return (A == (C * C) || B == (D * D));
}
long long int classini(long long int n) { return (n & 1) ? -1 : 1; }
long long int factorial(int n) {
  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
long long int catanal(long long int n) {
  return (factorial(2 * n) / ((factorial(n + 1) * factorial(n))));
}
string orientation_3_ordered_point(vector<pair<int, int> > V) {
  long long int value =
      (V[1].second - V[0].second) * (V[2].first - V[1].first) -
      (V[1].first * V[0].first) * (V[2].second - V[1].second);
  string res;
  if (value == 0) res = "colinear";
  value == 1 ? res = "clockwise" : res = "counterclockwise";
  return res;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
string make_string(long long int num) {
  stringstream ss;
  ss << num;
  string s;
  ss >> s;
  return s;
}
long long int make_num(string s) {
  stringstream ss;
  long long int tmp;
  ss << s;
  ss >> tmp;
  return tmp;
}
int SET(int mask, int pos) { return (mask | (1 << pos)); }
int check(int mask, int pos) { return (mask & (1 << pos)); }
map<long long, vector<int> > G;
long long A[3000001];
map<long long, int> Nisi;
class cmp {
 public:
  bool operator()(long long &A, long long &B) { return A > B; }
};
priority_queue<long long, vector<long long>, cmp> PQ;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    PQ.push(A[i]);
    G[A[i]].push_back(i);
  }
  while (PQ.size()) {
    long long cur = PQ.top();
    PQ.pop();
    if (G[cur].size() < 2 || Nisi[cur]) continue;
    Nisi[cur] = 1;
    sort(G[cur].begin(), G[cur].end());
    for (int j = 0; j < G[cur].size(); j += 2) {
      if (j + 1 >= G[cur].size())
        break;
      else {
        long long newval = cur * 2;
        A[G[cur][j]] = 0;
        A[G[cur][j + 1]] = newval;
        G[newval].push_back(G[cur][j + 1]);
        PQ.push(newval);
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (A[i]) cnt++;
  }
  printf("%d", cnt);
  printf("\n");
  for (int i = 0; i < n; i++) {
    if (A[i]) printf("%lld ", A[i]);
  }
  printf("\n");
  return 0;
}

```