#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int first = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) {
    if (ch == '-') f = -1;
  }
  for (; isdigit(ch); ch = getchar()) {
    first = first * 10 + ch - 48;
  }
  return first * f;
}
const int mxN = 5e5;
int uf[mxN + 5];
int a[mxN + 3], b[mxN + 3], ans[mxN + 3], per[mxN + 3];
multiset<int> len;
set<pair<int, int> > s;
int n, ans0, curval;
int findfa(int u) { return u == uf[u] ? u : uf[u] = findfa(uf[u]); }
void cover(int l, int r) {
  for (int i = findfa(l); i <= r; i = findfa(i + 1)) {
    ans[i] = curval;
    uf[i] = findfa(i + 1);
  }
}
void insert(int l, int r) {
  s.insert(make_pair(l, r));
  len.insert(r - l + 1);
  if (!b[l] && !b[r]) {
    cover(l, r);
  } else if (!b[l]) {
    cover(l, l + r >> 1);
  } else if (!b[r]) {
    cover(l + r + 2 >> 1, r);
  }
}
void delet(int l, int r) {
  s.erase(make_pair(l, r));
  len.erase(len.find(r - l + 1));
}
void modify(int u) {
  b[u] = 0;
  set<pair<int, int> >::iterator it = s.lower_bound(make_pair(u + 1, 0)), itl,
                                 itr;
  it--;
  pair<int, int> cur = *it, l, r;
  if (u == 1) {
    if (b[u + 1] == 1) {
      itr = it;
      itr++;
      assert(itr != s.end());
      r = *itr;
      delet(u, u);
      delet(r.first, r.second);
      insert(u, r.second);
    } else {
      delet(u, cur.second);
      insert(u, u);
      insert(u + 1, cur.second);
    }
  } else if (u == n) {
    if (b[u - 1] == 1) {
      itl = it;
      assert(itl != s.begin());
      itl--;
      l = *itl;
      delet(l.first, l.second);
      delet(u, u);
      insert(l.first, u);
    } else {
      delet(cur.first, u);
      insert(cur.first, u - 1);
      insert(u, u);
    }
  } else {
    if (b[u - 1] && b[u + 1]) {
      itl = itr = it;
      assert(itl != s.begin());
      itl--, itr++;
      assert(itr != s.end());
      l = *itl, r = *itr;
      delet(l.first, l.second);
      delet(u, u);
      delet(r.first, r.second);
      insert(l.first, r.second);
    } else if (b[u - 1]) {
      itl = it;
      assert(itl != s.begin());
      itl--;
      l = *itl;
      delet(l.first, l.second);
      delet(cur.first, cur.second);
      insert(l.first, u);
      insert(u + 1, cur.second);
    } else if (b[u + 1]) {
      itr = it;
      itr++;
      assert(itr != s.end());
      r = *itr;
      delet(cur.first, cur.second);
      delet(r.first, r.second);
      insert(cur.first, u - 1);
      insert(u, r.second);
    } else {
      delet(cur.first, cur.second);
      insert(cur.first, u - 1);
      insert(u, u);
      insert(u + 1, cur.second);
    }
  }
}
bool cmp(int first, int second) { return a[first] < a[second]; }
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read(), per[i] = i;
  if (n == 1) {
    printf("%d\n%d\n", 0, a[1]);
    return 0;
  }
  for (int i = 0; i <= n + 2; i++) uf[i] = i;
  for (int i = 1; i <= n; i++)
    b[i] = 1, s.insert(make_pair(i, i)), len.insert(1);
  sort(per + 1, per + n + 1, cmp);
  for (int l = 1; l <= n; l++) {
    curval = a[per[l]];
    int r = l;
    while (r < n && a[per[r + 1]] == a[per[l]]) {
      r++;
    }
    for (int i = l; i <= r; i++) {
      modify(per[i]);
    }
    ans0 = max(ans0, *len.rbegin());
    l = r;
  }
  printf("%d\n", ans0 - 1 >> 1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
