#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int n, turn, a[maxn], b[maxn], id[maxn], cur[maxn];
set<int> S;
struct DSU {
  int fa[maxn];
  void init() { iota(fa + 1, fa + n + 1, 1); }
  int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
  void unite(int x, int y) { fa[find(x)] = find(y); }
} L, R, chk;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  iota(id + 1, id + n + 1, 1);
  sort(id + 1, id + n + 1, [&](int x, int y) { return a[x] < a[y]; });
  L.init(), R.init();
  chk.init(), chk.fa[n + 1] = n + 1;
  for (int i = 0; i <= n; i++) {
    S.insert(i);
  }
  auto upd = [&](int x) {
    if (x == 1 || cur[x] == cur[x - 1]) S.erase(x - 1);
    if (x == n || cur[x] == cur[x + 1]) S.erase(x);
    cur[x] = 1;
    if (x == 1 || cur[x] == cur[x - 1]) S.insert(x - 1);
    if (x == n || cur[x] == cur[x + 1]) S.insert(x);
    if (x == 1) cur[0] = 1;
    if (x == n) cur[n + 1] = 1;
    if (x > 1 && cur[x - 1]) L.unite(x, x - 1), R.unite(x - 1, x);
    if (x < n && cur[x + 1]) L.unite(x + 1, x), R.unite(x, x + 1);
  };
  auto calc = [&](int x) {
    int l = L.find(x), r = R.find(x);
    if (l < r || x == 1 || x == n) {
      auto it = S.lower_bound(l);
      if (l > 1 && it != S.begin()) {
        int v = *--it + 1;
        turn = max(turn, (l - v) >> 1);
        if (cur[v])
          l = v + 1;
        else
          l = ((l + v) >> 1) + 1;
      }
      it = S.upper_bound(r);
      if (r < n && it != S.end()) {
        int v = *it;
        turn = max(turn, (v - r) >> 1);
        if (cur[v])
          r = v - 1;
        else
          r = (r + v) >> 1;
      }
    } else {
      int lb = *--S.lower_bound(x) + 1;
      int rb = *S.upper_bound(x);
      turn = max(turn, (rb - lb) >> 1);
      if (!cur[lb] && !cur[rb]) return;
      if (cur[lb])
        l = lb + 1;
      else
        l = ((lb + rb) >> 1) + 1;
      if (cur[rb])
        r = rb - 1;
      else
        r = (lb + rb) >> 1;
    }
    for (l = chk.find(l); l <= r; l = chk.find(l)) {
      b[l] = a[x], chk.unite(l, l + 1);
    }
  };
  for (int i = 1, j; i <= n; i = j) {
    for (j = i; j <= n && a[id[i]] == a[id[j]]; j++)
      ;
    for (int k = i; k < j; k++) upd(id[k]);
    for (int k = i; k < j; k++) calc(id[k]);
  }
  printf("%d\n", turn);
  for (int i = 1; i <= n; i++) {
    printf("%d ", b[i]);
  }
  return 0;
}
