#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
struct sparse_table {
  int n;
  vector<int> a;
  vector<vector<int>> st;
  int combine(int dl, int dr) { return a[dl] > a[dr] ? dl : dr; }
  sparse_table() {}
  sparse_table(vector<int>& a)
      : n(a.size()), a(a), st((31 - __builtin_clz(n)) + 1, vector<int>(n)) {
    for (int i = 0; i < n; i++) st[0][i] = i;
    for (int j = 1; 1 << j <= n; j++)
      for (int i = 0; i + (1 << j) <= n; i++)
        st[j][i] = combine(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
  }
  int query(int l, int r) {
    int s = (31 - __builtin_clz(r - l));
    return abs(a[combine(st[s][l], st[s][r - (1 << s)])]);
  }
};
int a[N], b[N], c[N];
int main() {
  auto med = [&](int i, int j, int k) {
    vector<int> tmp = {i, j, k};
    sort(tmp.begin(), tmp.end());
    return tmp[1];
  };
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  vector<int> ox(n), on(n), ex(n), en(n);
  for (int i = 0; i < n; i++) {
    if (i != 0 && i != n - 1) c[i] = a[i] != med(a[i - 1], a[i], a[i + 1]);
    ox[i] = -inf, on[i] = -inf;
    ex[i] = -inf, en[i] = -inf;
    if (i & 1)
      ex[i] = a[i], en[i] = -a[i];
    else
      ox[i] = a[i], on[i] = -a[i];
  }
  sparse_table sp[2][2];
  sp[0][0] = sparse_table(ox);
  sp[0][1] = sparse_table(ex);
  sp[1][0] = sparse_table(en);
  sp[1][1] = sparse_table(on);
  auto calc = [&](int i, int cur) {
    if (cur == 0 || i == 0 || i == n - 1 || c[i] == 0) return a[i];
    bool f = a[i] > max(a[i - 1], a[i + 1]);
    return sp[(cur & 1) ^ f][(i & 1) ^ f].query(i - cur, i + cur + 1);
  };
  auto check = [&](int i, int cur) {
    if (cur + 1 > min(i, n - i - 1)) return false;
    return cur + 1 <= 0 || (c[i + cur] == 1 &&
                            calc(i, cur) != med(calc(i - 1, cur), calc(i, cur),
                                                calc(i + 1, cur)));
  };
  int cur = 0, ans = 0;
  b[0] = a[0], b[n - 1] = a[n - 1];
  for (int i = 1; i + 1 < n; i++) {
    cur--;
    for (int j = 0; j <= 1 && check(i, cur); j++) cur++;
    b[i] = calc(i, cur);
    ans = max(ans, cur);
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) printf("%d ", b[i]);
  return 0;
}
