#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int N = 5e5 + 5;
int n, res, a[N], lg[N], ma[N], na[N], b[N];
struct st {
  int c[20][N];
  void work(int *a) {
    memcpy(c[0], a, (n + 1) << 2);
    for (int j = 1; j < 20; ++j)
      for (int i = 0; i + (1 << j) - 1 <= n; ++i)
        c[j][i] = min(c[j - 1][i], c[j - 1][i + (1 << (j - 1))]);
  }
  int ask(int x, int d) {
    int l = x - d - 1, r = x + d, t = lg[r - l + 1];
    return min(c[t][l], c[t][r - (1 << t) + 1]);
  }
} mx, mn;
signed main() {
  read(n);
  lg[0] = -1;
  for (int i = 1; i <= n + 1; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; ++i) read(a[i]);
  a[0] = a[1], a[n + 1] = a[n];
  for (int i = 0; i <= n; ++i)
    ma[i] = -min(a[i], a[i + 1]), na[i] = max(a[i], a[i + 1]);
  mn.work(na), mx.work(ma);
  for (int i = 1; i <= n; ++i) {
    int l = 0, r = min(i - 1, n - i), mid;
    int ta, tb, val = 0;
    while (l <= r) {
      mid = l + r >> 1;
      ta = mn.ask(i, mid), tb = -mx.ask(i, mid);
      val = max(val, min(ta, tb));
      ta > tb ? l = mid + 1 : r = mid - 1;
    }
    b[i] = val, res = max(res, l);
  }
  printf("%d\n", res);
  for (int i = 1; i <= n; ++i) printf("%d ", b[i]);
  puts("");
  return 0;
}
