#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 505000;
int n, a[N], f[N], ans[N], sz;
set<pair<int, int> > Set;
pair<int, int> b[N];
struct Heap {
  int cnt[N];
  set<int> Set;
  inline void era(int x) {
    cnt[x]--;
    if (!cnt[x]) Set.erase(x);
  }
  inline void ins(int x) {
    if (!cnt[x]) Set.insert(x);
    cnt[x]++;
  }
  inline int qry() { return Set.empty() ? 0 : *Set.rbegin(); }
} heap;
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void updans(int l, int r, int x) {
  for (l = find(l); l <= r; l = find(l)) ans[l] = x, f[l] = l + 1;
}
void era(set<pair<int, int> >::iterator it) {
  if (((int)Set.size()) == 1) {
    Set.erase(it);
    return;
  }
  if (it == Set.begin()) {
    auto nxt = it;
    nxt++;
    heap.era((*nxt).first - (*it).second - 1);
    Set.erase(it);
    return;
  }
  if (it == (--Set.end())) {
    auto pre = it;
    pre--;
    heap.era((*it).first - (*pre).second - 1);
    Set.erase(it);
    return;
  }
  auto nxt = it;
  nxt++;
  auto pre = it;
  pre--;
  heap.era((*nxt).first - (*it).second - 1);
  heap.era((*it).first - (*pre).second - 1);
  heap.ins((*nxt).first - (*pre).second - 1);
  Set.erase(it);
}
void ins(int l, int r) {
  auto it = Set.insert(make_pair(l, r)).first;
  if (((int)Set.size()) == 1) return;
  if (it == Set.begin()) {
    auto nxt = it;
    nxt++;
    heap.ins((*nxt).first - (*it).second - 1);
    return;
  }
  if (it == (--Set.end())) {
    auto pre = it;
    pre--;
    heap.ins((*it).first - (*pre).second - 1);
    return;
  }
  auto nxt = it;
  nxt++;
  auto pre = it;
  pre--;
  heap.ins((*nxt).first - (*it).second - 1);
  heap.ins((*it).first - (*pre).second - 1);
  heap.era((*nxt).first - (*pre).second - 1);
}
void mdy(int p) {
  auto it = Set.lower_bound(make_pair(p + 1, 0));
  if (!Set.empty() && it != Set.begin()) {
    --it;
    if ((*it).first <= p && (*it).second >= p) {
      int l = (*it).first, r = (*it).second;
      era(it);
      if (l < p - 1) ins(l, p - 1);
      if (p + 1 < r) ins(p + 1, r);
    }
  }
  a[p] = 1;
  int l = p, r = p;
  if (a[p + 1] == 1) {
    auto it = Set.lower_bound(make_pair(p + 1, 0));
    if (!Set.empty() && it != Set.end() && (*it).first == p + 1)
      r = (*it).second, era(it);
    else
      r = p + 1;
  }
  if (a[p - 1] == 1) {
    auto it = Set.lower_bound(make_pair(p, 0));
    if (!Set.empty() && it != Set.end() && (*(--it)).second == p - 1)
      l = (*it).first, era(it);
    else
      l = p - 1;
  }
  if (l < r) ins(l, r);
}
int CUR;
void handle(set<pair<int, int> >::iterator it) {
  auto nxt = it;
  nxt++;
  int mid = ((*it).second + (*nxt).first) / 2;
  if ((*it).second < mid && a[(*it).second] == 1)
    updans((*it).second + 1, mid, CUR);
  if (mid + 1 <= (*nxt).first - 1 && a[(*nxt).second] == 1)
    updans(mid + 1, (*nxt).first - 1, CUR);
}
int main() {
  read(n);
  for (register int i = (1); i <= (n); i++) {
    int x;
    read(x);
    b[++sz] = make_pair(x, i + 2);
    if (i == 1 || i == n) b[++sz] = make_pair(x, i == 1 ? 2 : n + 3);
  }
  a[1] = a[n + 4] = 2;
  Set.insert(make_pair(2, n + 3));
  for (register int i = (1); i <= (n + 5); i++) f[i] = i;
  sort(b + 1, b + sz + 1);
  reverse(b + 1, b + sz + 1);
  int mx = 0;
  for (register int l = (1); l <= (sz); l++) {
    int r = l;
    while (r + 1 <= sz && b[r + 1].first == b[l].first) r++;
    CUR = b[l].first;
    for (register int t = (l); t <= (r); t++) mdy(b[t].second);
    for (register int t = (l); t <= (r); t++) {
      int p = b[t].second;
      if (a[p] + a[p - 1] + a[p + 1] >= 2) {
        auto it = Set.lower_bound(make_pair(p + 1, 0));
        it--;
        updans((*it).first, (*it).second, b[t].first);
        if (it != Set.end()) handle(it);
        if (it != Set.begin()) {
          auto pre = it;
          handle(--pre);
        }
      } else {
        auto it = Set.lower_bound(make_pair(p + 1, 0));
        if (it != Set.end() && it != Set.begin()) {
          auto pre = it;
          handle(--pre);
        }
      }
    }
    umax(mx, heap.qry());
    l = r;
  }
  printf("%d\n", mx + 1 >> 1);
  for (register int i = (3); i <= (n + 2); i++) printf("%d ", ans[i]);
  return 0;
}
