#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
template <typename T>
bool cmax(T &a, T b) {
  return (a < b) ? a = b, 1 : 0;
}
template <typename T>
bool cmin(T &a, T b) {
  return (a > b) ? a = b, 1 : 0;
}
template <typename T>
T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T>
void write(T x, char y) {
  if (x == 0) {
    putchar('0'), putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10) wr[++top] = x % 10 + '0';
  while (top) putchar(wr[top--]);
  putchar(y);
}
void file() {}
int n, a[N];
void input() {
  n = read<int>();
  for (register int i = (int)1; i <= (int)n; ++i) a[i] = read<int>();
}
int pre[N], nex[N], m;
void work() {
  m = n;
  nex[0] = 1;
  for (register int i = (int)1; i <= (int)n; ++i)
    pre[i] = i - 1, nex[i] = i + 1;
  for (int i = 1; i <= n;) {
    if (a[i] == a[nex[i]]) {
      m--;
      a[i]++;
      nex[i] = nex[nex[i]];
      pre[nex[i]] = i;
      i = pre[i];
    } else
      i = nex[i];
  }
  write(m, '\n');
  for (int i = 1; i <= n; i = nex[i]) write(a[i], ' ');
}
int main() {
  file();
  input();
  work();
  return 0;
}
