#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
int a[maxn], arr[maxn], ans[maxn], C, n;
vector<int> tdo[maxn];
int cnt[4 * maxn];
void add(int f, int s, int x, int l = 0, int r = n, int id = 1) {
  if (f >= s || l >= r || s <= l || r <= f || cnt[id] == r - l) return;
  if (r - l == 1) {
    ans[l] = x;
    cnt[id] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  add(f, s, x, l, mid, 2 * id);
  add(f, s, x, mid, r, 2 * id + 1);
  cnt[id] = cnt[2 * id] + cnt[2 * id + 1];
}
bool nw[maxn], ONE[maxn];
set<pair<int, int> > seg;
multiset<int> sval;
int X;
void eval(int l, int r) {
  if ((r - l) & 1) {
    if (nw[l])
      add(l, ((l + r) / 2) + 1, X);
    else
      add(((l + r) / 2) + 1, r + 1, X);
  } else {
    if (nw[l]) add(l, r + 1, X);
  }
}
void add_seg(int l, int r) {
  if (l == r) {
    ONE[l] = 1;
  } else {
    sval.insert((r - l) / 2);
    seg.insert({l, r});
  }
  eval(l, r);
}
void era_seg(int l, int r) {
  if (l == r) {
    ONE[l] = 0;
  } else {
    sval.erase(sval.find((r - l) / 2));
    seg.erase({l, r});
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    arr[i] = a[i];
    ONE[i] = 1;
  }
  sort(arr, arr + n);
  C = unique(arr, arr + n) - arr;
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(arr, arr + C, a[i]) - arr;
    tdo[a[i]].push_back(i);
  }
  int ANS = 0;
  for (int i = n - 1; i >= 0; i--) {
    X = i;
    for (int pos : tdo[i]) {
      auto it = seg.lower_bound((pair<int, int>){pos, inf});
      pair<int, int> p, p_bef, p_aft;
      if (it == seg.begin() || prev(it)->second < pos)
        p = {pos, pos};
      else
        p = *prev(it);
      if (it != seg.end() && p.second + 1 == it->first)
        p_aft = *it;
      else
        p_aft = {p.second + 1, p.second + 1};
      it = seg.lower_bound({p.first, p.second});
      if (it == seg.begin() || prev(it)->second != p.first - 1)
        p_bef = {p.first - 1, p.first - 1};
      else
        p_bef = *prev(it);
      int L = p.first, R = p.second;
      nw[pos] = 1;
      if (pos != 0 && nw[pos - 1] == 0)
        L = p_bef.first, era_seg(p_bef.first, p_bef.second);
      if (pos != n - 1 && nw[pos + 1] == 0)
        R = p_aft.second, era_seg(p_aft.first, p_aft.second);
      era_seg(p.first, p.second);
      if (L < pos && nw[pos - 1]) {
        add_seg(L, pos - 1);
        L = pos;
      }
      if (pos < R && nw[pos + 1]) {
        add_seg(pos + 1, R);
        R = pos;
      }
      add_seg(L, R);
    }
    if (int((sval).size())) ANS = max(ANS, *sval.rbegin());
  }
  cout << ANS << "\n";
  for (int i = 0; i < n; i++) {
    cout << arr[ans[i]] << " ";
  }
  return cout << endl, 0;
}
