#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int a[N], n, bad[N], res[N], b[N], f[N], c[N];
void fset(int r, int x) {
  int d = x - c[r];
  c[r] = x;
  r++;
  while (r < N) {
    f[r] += d;
    r += r & -r;
  }
}
int fsum(int r) {
  r++;
  int res = 0;
  while (r) {
    res += f[r];
    r -= r & -r;
  }
  return res;
}
int get_l(int i) {
  if (c[i] == 0) {
    return i + 1;
  }
  int l = 0, r = i;
  int x = fsum(i);
  if (x == i + 1) {
    return l;
  }
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (x - fsum(mid - 1) == i - mid + 1) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return r;
}
int get_r(int i) {
  if (i == n - 1) {
    return n - 1;
  }
  int l = i + 1, r = n - 1;
  int x = fsum(i);
  if (fsum(i + 1) - x != 1) {
    return i;
  }
  if (fsum(n - 1) - x == n - 1 - i) {
    return n - 1;
  }
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (fsum(mid) - x == mid - i) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return l;
}
set<int> setik;
void PUNKS_NOT_DEAD() {
  cin >> n;
  vector<int> xx;
  vector<pair<int, int>> keker;
  for (int i = 0; i < n; i++) {
    b[i] = 1;
    cin >> a[i];
    keker.emplace_back(a[i] + 1, i);
    xx.push_back(a[i] + 1);
    setik.insert(i);
  }
  sort(xx.begin(), xx.end());
  sort(keker.begin(), keker.end());
  xx.resize(unique(xx.begin(), xx.end()) - xx.begin());
  int ans = 0;
  int z = 0;
  for (auto x : xx) {
    vector<int> check;
    vector<int> mem;
    while (z < keker.size() && keker[z].first < x) z++;
    while (z < keker.size() && keker[z].first == x) {
      mem.push_back(keker[z].second);
      z++;
    }
    for (auto i : mem) {
      b[i] ^= 1;
      check.push_back(i);
      if (i) {
        check.push_back(i - 1);
        fset(i, b[i] != b[i - 1]);
      } else {
        fset(i, 1);
      }
      if (i + 1 < n) {
        check.push_back(i + 1);
        fset(i + 1, b[i + 1] != b[i]);
      }
    }
    for (auto i : check) {
      int L = max(0, get_l(i) - 1);
      int R = get_r(i);
      ans = max(ans, (R - L) / 2);
      if ((R - L + 1) % 2 == 1 && b[L] == 0) {
        while (setik.size()) {
          auto it = setik.lower_bound(L);
          if (it == setik.end() || *it > R) break;
          res[*it] = x - 1;
          setik.erase(it);
        }
      }
      if ((R - L + 1) % 2 == 0) {
        if (b[L] == 0) {
          R = R - (R - L) / 2 - 1;
        } else {
          L = L + (R - L) / 2 + 1;
        }
        while (setik.size()) {
          auto it = setik.lower_bound(L);
          if (it == setik.end() || *it > R) break;
          res[*it] = x - 1;
          setik.erase(it);
        }
      }
    }
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) {
    cout << res[i] << ' ';
  }
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  PUNKS_NOT_DEAD();
}
