#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int h[500005];
vector<int> tr;
int res[500005];
int ans;
int poi;
vector<int> pl[500005];
set<int> r[2];
int tp[500005];
int n;
void upd(int pl) {
  r[(tp[pl] + pl) % 2].erase(pl);
  tp[pl] ^= 1;
  r[(tp[pl] + pl) % 2].insert(pl);
}
pair<int, int> gt(int pl) {
  int df = (tp[pl] + pl) % 2;
  pair<int, int> gg;
  int t = 0;
  for (int k = pl + 1; k <= pl + 7; k++)
    if (((tp[k] ^ k ^ df) & 1) || (k > n)) {
      gg.second = k - 1, t++;
      break;
    }
  for (int k = pl - 1; k >= pl - 7; k--)
    if (((tp[k] ^ k ^ df) & 1) || (k <= 0)) {
      gg.first = k + 1, t++;
      break;
    }
  if (t >= 2) return gg;
  df ^= 1;
  set<int>::iterator rs = r[df].lower_bound(pl);
  set<int>::iterator ls = rs;
  ls--;
  pair<int, int> fn = make_pair((*ls) + 1, (*rs) - 1);
  return fn;
}
int fa[500005];
vector<int> gg[500005];
int gfa(int a) {
  if (fa[a] == a) return a;
  return fa[a] = gfa(fa[a]);
}
vector<int> cur;
void push(int l, int r, int tp) {
  int i = gfa(l);
  while (i <= r) {
    fa[i] = i + 1;
    res[i] = tp;
    cur.push_back(i);
    i = gfa(i + 1);
  }
}
void work(int l, int r, int t) {
  if (tp[l] && tp[r])
    push(l, r, t);
  else {
    int mid = (l + r) >> 1;
    if (tp[l]) push(l, mid, t);
    if (tp[r]) push(mid + 1, r, t);
  }
}
void read(int &a) {
  a = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') a = a * 10 + ch - '0', ch = getchar();
}
int st[30];
void otp(int a) {
  int cnt = 0;
  if (!a) st[cnt++] = 0;
  while (a) st[cnt++] = a % 10, a /= 10;
  for (int i = cnt - 1; i >= 0; i--) putchar('0' + st[i]);
  putchar(' ');
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(h[i]), tr.push_back(h[i]);
  sort(tr.begin(), tr.end());
  if (n <= 2) {
    cout << 0 << endl;
    for (int i = 1; i <= n; i++) cout << h[i] << ' ';
    return 0;
  }
  for (int i = 1; i <= n; i++)
    h[i] = lower_bound(tr.begin(), tr.end(), h[i]) - tr.begin(),
    pl[h[i]].push_back(i);
  for (int i = 0; i <= n + 1; i++) fa[i] = i;
  res[1] = h[1], res[n] = h[n];
  poi = n;
  r[0].insert(0), r[0].insert(n + 1);
  r[1].insert(0), r[1].insert(n + 1);
  for (int i = 1; i <= n; i++) r[(tp[i] + i) % 2].insert(i);
  for (int i = n - 1; i >= 0; i--) {
    cur.clear();
    for (auto v : pl[i]) {
      pair<int, int> tx = gt(v);
      upd(v);
      work(v + 1, tx.second, i);
      work(tx.first, v - 1, i);
      tx = gt(v);
      work(tx.first, tx.second, i);
    }
    for (auto v : cur) {
      pair<int, int> tx = gt(v);
      ans = max(ans, min(v - tx.first, tx.second - v));
    }
  }
  r[0].clear(), r[1].clear();
  r[0].insert(0), r[0].insert(n + 1);
  r[1].insert(0), r[1].insert(n + 1);
  memset(tp, 0, sizeof(tp));
  for (int i = 1; i <= n; i++) r[(tp[i] + i) % 2].insert(i);
  for (int i = 2; i < n; i++) gg[res[i]].push_back(i);
  for (int i = 0; i < n; i++) {
    for (auto v : pl[i]) upd(v);
    for (auto g : gg[i]) {
      pair<int, int> q = gt(g);
      int na = min(g - q.first, q.second - g);
      ans = max(ans, na);
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", tr[res[i]]);
  return 0;
}
