#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  char ch = getchar();
  int f = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  x *= f;
}
template <class T>
void cmin(T &x, T y) {
  x = min(x, y);
}
template <class T>
void cmax(T &x, T y) {
  x = max(x, y);
}
const int mod = 998244353;
template <class T>
T add(T x, T y) {
  return x + y >= mod ? x + y - mod : x + y;
}
template <class T>
T sub(T x, T y) {
  return x - y < 0 ? x - y + mod : x - y;
}
template <class T>
T mul(T x, T y) {
  return 1ll * x * y % mod;
}
template <class T>
void Add(T &x, T y) {
  x = (x + y >= mod ? x + y - mod : x + y);
}
template <class T>
void Sub(T &x, T y) {
  x = (x - y < 0 ? x - y + mod : x - y);
}
template <class T>
void Mul(T &x, T y) {
  x = 1ll * x * y % mod;
}
template <class T>
T qpow(T a, T b = mod - 2) {
  T ret = 1;
  for (; b; b >>= 1, Mul(a, a))
    if (b & 1) Mul(ret, a);
  return ret;
}
const int N = 5e5 + 10;
int n, a[N], ans[N], mxt, num[N], id[N];
set<int> bel, equ;
struct DSU {
  int fa[N];
  void init(int n) {
    for (int i = 1; i <= n; i++) fa[i] = i;
  }
  int gfa(int x) { return fa[x] == x ? x : fa[x] = gfa(fa[x]); }
  void unite(int x, int y) {
    x = gfa(x), y = gfa(y);
    if (x == y) return;
    fa[x] = y;
  }
} s1, s2;
bool cmp(int x, int y) { return a[x] < a[y]; }
void upd1(int x) {
  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]) {
    s1.unite(x, x - 1);
    s2.unite(x - 1, x);
  }
  if (x < n && num[x + 1]) {
    s1.unite(x + 1, x);
    s2.unite(x, x + 1);
  }
}
void upd2(int x) {
  int l = s1.gfa(x), r = s2.gfa(x);
  if (l < r || x == 1 || x == n) {
    set<int>::iterator it = equ.lower_bound(l);
    if (l > 1 && it != equ.begin()) {
      --it;
      int p = (*it) + 1;
      cmax(mxt, (l - p) / 2);
      if (num[p]) {
        l = p + 1;
      } else {
        l = ((l + p) / 2) + 1;
      }
    }
    it = equ.upper_bound(r);
    if (r < n && it != equ.end()) {
      int p = (*it);
      cmax(mxt, (p - r) / 2);
      if (num[p]) {
        r = p - 1;
      } else {
        r = (p + r) / 2;
      }
    }
  } else {
    set<int>::iterator it1 = equ.lower_bound(x);
    --it1;
    set<int>::iterator it2 = equ.upper_bound(x);
    int nl = (*it1) + 1, nr = (*it2);
    cmax(mxt, (nr - nl) / 2);
    if (num[nl] && num[nr]) {
      l = nl + 1, r = nr - 1;
    } else if (num[nl]) {
      l = nl + 1, r = ((nl + nr) / 2);
    } else if (num[nr]) {
      l = ((nl + nr) / 2) + 1, r = nr - 1;
    } else {
      l = 1, r = 0;
    }
  }
  if (l <= r) {
    while (1) {
      set<int>::iterator it = bel.lower_bound(l);
      if (it != bel.end() && (*it) <= r) {
        ans[*it] = a[x];
        bel.erase(it);
      } else
        break;
    }
  }
}
signed main() {
  rd(n);
  s1.init(n), s2.init(n);
  for (int i = 1; i <= n; i++) {
    rd(a[i]);
    id[i] = i;
    bel.insert(i);
  }
  sort(id + 1, id + n + 1, cmp);
  for (int i = 0; i <= n; i++) equ.insert(i);
  for (int l = 1, r; l <= n; l = r + 1) {
    r = l;
    while (r < n && a[id[r + 1]] == a[id[l]]) ++r;
    for (int i = l; i <= r; i++) upd1(id[i]);
    for (int i = l; i <= r; i++) upd2(id[i]);
  }
  printf("%d\n", mxt);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
