#include <bits/stdc++.h>
using namespace std;
struct SETS {
  int fa[500005];
  void init(int n) {
    for (int i = 1; i <= n; i++) fa[i] = i;
  }
  int find_father(int x) {
    return (fa[x] == x) ? x : fa[x] = find_father(fa[x]);
  }
  void merge(int x, int y) {
    x = find_father(x);
    y = find_father(y);
    if (x == y) return;
    fa[x] = y;
  }
} st1, st2;
set<int> bel, equ;
int num[500005], ans[500005], maxn, n;
int fir[500005], id[500005];
void change1(int x, bool v) {
  if (x == 1 || num[x] == num[x - 1]) equ.erase(x - 1);
  if (x == n || num[x] == num[x + 1]) equ.erase(x);
  num[x] = 1;
  if (x == 1 || num[x] == num[x - 1]) equ.insert(x - 1);
  if (x == n || num[x] == num[x + 1]) equ.insert(x);
  if (x == 1) num[x - 1] = 1;
  if (x == n) num[x + 1] = 1;
  if (x > 1 && num[x - 1]) {
    st1.merge(x, x - 1);
    st2.merge(x - 1, x);
  }
  if (x < n && num[x + 1]) {
    st2.merge(x, x + 1);
    st1.merge(x + 1, x);
  }
}
void change2(int x, bool v) {
  int l = st1.find_father(x), r = st2.find_father(x);
  if (l < r || x == 1 || x == n) {
    set<int>::iterator it = equ.lower_bound(l);
    if (l > 1 && it != equ.begin()) {
      it--;
      int t = (*it) + 1;
      if (num[t]) {
        if (v) maxn = max(maxn, (l - t) >> 1);
        l = t + 1;
      } else {
        if (v) maxn = max(maxn, (l - t) >> 1);
        l = ((t + l) >> 1) + 1;
      }
    }
    it = equ.upper_bound(r);
    if (r < n && it != equ.end()) {
      int t = (*it);
      if (num[t]) {
        if (v) maxn = max(maxn, (t - r) >> 1);
        r = t - 1;
      } else {
        if (v) maxn = max(maxn, (t - r) >> 1);
        r = ((t + r) >> 1);
      }
    }
  } else {
    set<int>::iterator it1 = equ.lower_bound(x);
    it1--;
    set<int>::iterator it2 = equ.upper_bound(x);
    int nl = (*it1) + 1, nr = (*it2);
    if (v) maxn = max(maxn, (nr - nl) >> 1);
    if (num[nl] && num[nr]) {
      l = nl + 1;
      r = nr - 1;
    } else if (num[nl]) {
      l = nl + 1;
      r = ((nl + nr) >> 1);
    } else if (num[nr]) {
      l = ((nl + nr) >> 1) + 1;
      r = nr - 1;
    } else {
      l = 1;
      r = 0;
    }
  }
  if (l <= r) {
    for (;;) {
      set<int>::iterator it = bel.lower_bound(l);
      if (it != bel.end() && (*it) <= r) {
        ans[*it] = fir[x];
        bel.erase(it);
      } else
        break;
    }
  }
}
bool cmp(int x, int y) { return fir[x] < fir[y]; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &fir[i]);
    id[i] = i;
    bel.insert(i);
  }
  sort(id + 1, id + n + 1, cmp);
  st1.init(n);
  st2.init(n);
  for (int i = 0; i <= n; i++) equ.insert(i);
  int r;
  for (int i = 1; i <= n; i = r + 1)
    if (fir[id[i]] > fir[id[i - 1]]) {
      r = i;
      while (r < n && fir[id[r + 1]] == fir[id[r]]) r++;
      for (int j = i; j <= r; j++) change1(id[j], 1);
      for (int j = i; j <= r; j++) change2(id[j], 1);
    }
  printf("%d\n", maxn);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
