#include <bits/stdc++.h>
using namespace std;
int n;
int a[500007], id[500007], b[500007];
set<int> now;
set<pair<int, int> > seg;
int take = 1;
int ans[500007];
bool cmp(int x, int y) { return a[x] < a[y]; }
void inp() {
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i];
    id[i] = i;
    b[i] = 2;
    now.insert(i);
    seg.insert(make_pair(i, i));
  }
  sort(id + 1, id + n + 1, cmp);
}
void split(int x) {
  auto it = seg.upper_bound(make_pair(x, 500007));
  --it;
  int l = it->first, r = it->second;
  if (x == l) return;
  seg.erase(it);
  seg.insert(make_pair(l, x - 1));
  seg.insert(make_pair(x, r));
}
void ins(int x) {
  auto it = seg.upper_bound(make_pair(x, 500007));
  int l = x, r = x;
  if (x > 1 && b[x] != b[x - 1]) l = prev(it)->first, seg.erase(prev(it));
  if (x < n && b[x] != b[x + 1]) r = it->second, seg.erase(it);
  seg.insert(make_pair(l, r));
}
int gett(int l, int r) {
  auto it = now.lower_bound(l);
  if (it == now.end() || *it > r) return 0;
  return *it;
}
void solve(int x, int d) {
  auto it = seg.upper_bound(make_pair(x, 500007));
  --it;
  int l = it->first, r = it->second;
  take = max(take, r - l + 1);
  int mid = (l + r) >> 1;
  if (b[l] == 1) {
    int id;
    while (id = gett(l, mid)) ans[id] = d, now.erase(id);
  }
  if (b[r] == 1) {
    int id;
    while (id = gett(mid + 1, r)) ans[id] = d, now.erase(id);
  }
}
void answer() {
  for (int i = 1, j; i <= n; i = j) {
    for (j = i; j <= n && a[id[i]] == a[id[j]]; ++j) {
      b[id[j]] = 1;
      split(id[j]);
      split(id[j] + 1);
      seg.erase(make_pair(id[j], id[j]));
      ins(id[j]);
    }
    for (j = i; j <= n && a[id[i]] == a[id[j]]; ++j) {
      solve(id[j], a[id[i]]);
      if (id[j] < n && b[id[j] + 1] == 1) solve(id[j] + 1, a[id[i]]);
      if (id[j] > 1 && b[id[j] - 1] == 1) solve(id[j] - 1, a[id[i]]);
    }
  }
  cout << (take - 1) / 2 << "\n";
  for (int i = (1); i <= (n); ++i) cout << ans[i] << " ";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  inp();
  answer();
}
