#include <bits/stdc++.h>
using namespace std;
const int N = 500003;
void rd(int &x) {
  int ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
int n, a[N], res, ans[N], lg2[N], mx[19][N], mn[19][N];
pair<int, int> qry(int l, int r) {
  int k = lg2[r - l + 1];
  return make_pair(min(mn[k][l], mn[k][r + 1 - (1 << k)]),
                   max(mx[k][l], mx[k][r + 1 - (1 << k)]));
}
int main() {
  rd(n);
  for (int i = 1; i <= n; ++i) rd(a[i]);
  a[0] = a[1];
  a[n + 1] = a[n];
  for (int i = 2; i < N; ++i) lg2[i] = lg2[i >> 1] + 1;
  for (int i = 0; i <= n; ++i) {
    mx[0][i] = min(a[i], a[i + 1]);
    mn[0][i] = max(a[i], a[i + 1]);
  }
  for (int i = 1; i < 19; ++i)
    for (int j = 0; j + (1 << i) <= n + 1; ++j) {
      mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + (1 << i - 1)]);
      mn[i][j] = min(mn[i - 1][j], mn[i - 1][j + (1 << i - 1)]);
    }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == a[i - 1] || a[i] == a[i + 1]) {
      ans[i] = a[i];
      continue;
    }
    int l = 1, r = min(i, n + 1 - i);
    while (l < r) {
      int md = l + r >> 1;
      pair<int, int> _ = qry(i - md, i + md - 1);
      if (_.first <= _.second)
        r = md;
      else
        l = md + 1;
    }
    chmax(res, r - 1);
    pair<int, int> _ = qry(i - r, i + r - 1);
    ans[i] = (r & 1) == (a[i] > a[i - 1]) ? _.first : _.second;
  }
  printf("%d\n", res);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
}
