#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int a[N], n, bad[N], res[N], b[N], f[N], c[N];
void fset(int r, int x) {
  int d = x - c[r];
  c[r] = x;
  r++;
  while (r < N) {
    f[r] += d;
    r += r & -r;
  }
}
int fsum(int r) {
  r++;
  int res = 0;
  while (r) {
    res += f[r];
    r -= r & -r;
  }
  return res;
}
int get_l(int i) {
  if (c[i] == 0) {
    return i + 1;
  }
  int l = 0, r = i;
  int x = fsum(i);
  if (x == i + 1) {
    return l;
  }
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (x - fsum(mid - 1) == i - mid + 1) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return r;
}
int get_r(int i) {
  if (i == n - 1) {
    return n - 1;
  }
  int l = i + 1, r = n - 1;
  int x = fsum(i);
  if (fsum(i + 1) - x != 1) {
    return i;
  }
  if (fsum(n - 1) - x == n - 1 - i) {
    return n - 1;
  }
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (fsum(mid) - x == mid - i) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return l;
}
set<int> setik;
struct node {
  int ans;
  int pref, suff, l, r, len;
  node() { ans = suff = l = r = pref = len = 0; }
};
node combine(node &l, node &r) {
  node res;
  res.pref = l.pref;
  res.suff = r.suff;
  res.ans = max(l.ans, r.ans);
  res.l = l.l;
  res.r = r.r;
  if (l.r != r.l) {
    if (l.pref == l.len) {
      res.pref += r.pref;
    }
    if (r.suff == r.len) {
      res.suff += l.suff;
    }
    res.ans = max(res.ans, l.suff + r.pref);
  }
  res.ans = max({res.ans, res.pref, res.suff});
  res.len = l.len + r.len;
  return res;
}
node t[N * 4];
void build(int v, int tl, int tr) {
  t[v].l = t[v].r = 0;
  t[v].len = tr - tl + 1;
  t[v].ans = t[v].pref = t[v].suff = 1;
  if (tl == tr) {
    return;
  }
  int tm = (tl + tr) / 2;
  build(v << 1, tl, tm);
  build(v << 1 | 1, tm + 1, tr);
}
void flip(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    t[v].l ^= 1, t[v].r ^= 1;
    t[v].suff = t[v].pref = t[v].ans = 1;
    t[v].len = 1;
  } else {
    int tm = (tl + tr) / 2;
    if (tm >= pos) {
      flip(v << 1, tl, tm, pos);
    } else {
      flip(v << 1 | 1, tm + 1, tr, pos);
    }
    t[v] = combine(t[v << 1], t[v << 1 | 1]);
  }
}
void PUNKS_NOT_DEAD() {
  cin >> n;
  vector<int> xx;
  vector<pair<int, int>> keker;
  for (int i = 0; i < n; i++) {
    b[i] = 1;
    cin >> a[i];
    keker.emplace_back(a[i] + 1, i);
    xx.push_back(a[i] + 1);
    setik.insert(i);
  }
  build(1, 0, n - 1);
  sort(xx.begin(), xx.end());
  sort(keker.begin(), keker.end());
  xx.resize(unique(xx.begin(), xx.end()) - xx.begin());
  int ans = 0;
  int z = 0;
  for (auto x : xx) {
    vector<int> check;
    vector<int> mem;
    while (z < keker.size() && keker[z].first < x) z++;
    while (z < keker.size() && keker[z].first == x) {
      mem.push_back(keker[z].second);
      z++;
    }
    for (auto i : mem) {
      b[i] ^= 1;
      flip(1, 0, n - 1, i);
      check.push_back(i);
      if (i) {
        check.push_back(i - 1);
        fset(i, b[i] != b[i - 1]);
      } else {
        fset(i, 1);
      }
      if (i + 1 < n) {
        check.push_back(i + 1);
        fset(i + 1, b[i + 1] != b[i]);
      }
    }
    for (auto i : check) {
      int L = max(0, get_l(i) - 1);
      int R = get_r(i);
      if ((R - L + 1) % 2 == 1 && b[L] == 0) {
        while (setik.size()) {
          auto it = setik.lower_bound(L);
          if (it == setik.end() || *it > R) break;
          res[*it] = x - 1;
          setik.erase(it);
        }
      }
      if ((R - L + 1) % 2 == 0) {
        if (b[L] == 0) {
          R = R - (R - L) / 2 - 1;
        } else {
          L = L + (R - L) / 2 + 1;
        }
        while (setik.size()) {
          auto it = setik.lower_bound(L);
          if (it == setik.end() || *it > R) break;
          res[*it] = x - 1;
          setik.erase(it);
        }
      }
    }
    ans = max(ans, (t[1].ans - 1) / 2);
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) {
    cout << res[i] << ' ';
  }
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  PUNKS_NOT_DEAD();
}
