#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
inline int read() {
  int p = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch == '-' ? p = -1 : 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return p * x;
}
struct Node {
  int l, r, ansl, ansr, ans, opt;
  inline void init(int x) { l = r = x, ansl = ansr = ans = opt = 1; }
} a[MAXN << 2];
inline Node operator+(Node a, Node b) {
  Node c;
  c.l = a.l, c.r = b.r, c.ans = max(a.ans, b.ans);
  if (a.r == b.l)
    c.ansl = a.ansl, c.ansr = b.ansr, c.opt = 0;
  else
    c.ansl = (a.opt ? a.ans + b.ansl : a.ansl),
    c.ansr = (b.opt ? b.ans + a.ansr : b.ansr),
    c.ans = max(c.ans, a.ansr + b.ansl), c.opt = (a.opt & b.opt);
  return c;
}
inline void pushup(int x) { a[x] = a[x << 1] + a[x << 1 | 1]; }
void Build(int x, int l, int r) {
  if (l == r) return a[x].init(0);
  int mid = l + r >> 1;
  Build(x << 1, l, mid), Build(x << 1 | 1, mid + 1, r), pushup(x);
}
void Change(int x, int l, int r, int p) {
  if (l == r) return a[x].init(1);
  int mid = l + r >> 1;
  if (p <= mid)
    Change(x << 1, l, mid, p);
  else
    Change(x << 1 | 1, mid + 1, r, p);
  pushup(x);
}
Node Askl(int x, int l, int r, int p) {
  if (l == r) return a[x];
  int mid = l + r >> 1;
  if (p <= mid)
    return Askl(x << 1, l, mid, p);
  else
    return a[x << 1] + Askl(x << 1 | 1, mid + 1, r, p);
}
Node Askr(int x, int l, int r, int p) {
  if (l == r) return a[x];
  int mid = l + r >> 1;
  if (p > mid)
    return Askr(x << 1 | 1, mid + 1, r, p);
  else
    return Askr(x << 1, l, mid, p) + a[x << 1 | 1];
}
int n, h[MAXN], b[MAXN], id[MAXN], Ans, ans[MAXN];
set<int> S;
vector<int> o;
inline void upd(int l, int r, int v) {
  o.clear();
  for (set<int>::iterator it = S.lower_bound(l); it != S.end() && *it <= r;
       ++it)
    o.push_back(*it);
  for (auto x : o) S.erase(x), ans[x] = v;
}
int main() {
  n = read(), Build(1, 1, n);
  for (int i = 1; i <= n; ++i) h[i] = read(), id[i] = i, S.insert(i);
  sort(id + 1, id + n + 1, [](int x, int y) { return h[x] > h[y]; });
  for (int i = 1; i <= n; ++i) {
    int p = id[i];
    Change(1, 1, n, p), b[p] = 1;
    if (h[id[i]] != h[id[i + 1]]) Ans = max(Ans, (a[1].ans - 1) / 2);
    Node l = Askl(1, 1, n, p), r = Askr(1, 1, n, p);
    int lp = p - l.ansr + 1, rp = p + r.ansl - 1, len = rp - lp + 1;
    if (b[lp] == 0 && b[rp] == 0) continue;
    if (b[lp] == 1 && b[rp] == 1) upd(lp - 1, rp + 1, h[p]);
    if (b[lp] == 0 && b[rp] == 1) upd(lp + len / 2, rp + 1, h[p]);
    if (b[lp] == 1 && b[rp] == 0) upd(lp - 1, rp - len / 2, h[p]);
    if (lp == p && p != 1) {
      Node ll = Askl(1, 1, n, p - 1);
      int lx = p - ll.ansr;
      len = p - lx;
      if (b[lx] == 0)
        upd(lx + len / 2, p, h[p]);
      else
        upd(lx - 1, p, h[p]);
    }
    if (rp == p && p != n) {
      Node rr = Askr(1, 1, n, p + 1);
      int rx = p + rr.ansl;
      len = rx - p;
      if (b[rx] == 0)
        upd(p, rx - len / 2, h[p]);
      else
        upd(p, rx, h[p]);
    }
  }
  cout << Ans << '\n';
  for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
  return 0;
}
