#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;
template <typename T>
void _(const char* s, T h) {
  cerr << s << " = " << h << "\n";
}
template <typename T, typename... Ts>
void _(const char* s, T h, Ts... t) {
  int b = 0;
  while (((b += *s == '(') -= *s == ')') != 0 || *s != ',') cerr << *s++;
  cerr << " = " << h << ",";
  _(s + 1, t...);
}
struct init {
  init() {
    cin.tie(0);
    iostream::sync_with_stdio(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(5);
  }
  ~init() {}
} init;
template <typename T, typename U>
void upx(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
void upn(T& x, U y) {
  if (x > y) x = y;
}
const ll N = 5e5 + 5;
ll a[N];
ll mx[N * 4];
ll second = 1, n;
void putmax(ll l, ll r, ll x) {
  for (l += second, r += second + 1; l < r; l /= 2, r /= 2) {
    if (l & 1) upn(mx[l++], x);
    if (r & 1) upn(mx[--r], x);
  }
}
void out(ll v, ll px = 1e9) {
  upn(mx[v], px);
  if (v < second) {
    upn(px, mx[v]);
    out(v + v, px);
    out(v + v + 1, px);
  } else if (v < second + n)
    cout << mx[v] << ' ';
}
map<ll, vector<ll>> w;
ll lt[N], b[N];
ll ans = 0;
void kek(ll r, ll x) {
  if (r == n) return;
  ll l = lt[r];
  ll len = r - l + 1;
  upx(ans, (len - 1) / 2);
  ll m = (l + r) / 2;
  if (b[l] == 1 && b[r] == 2) {
    putmax(l, m, x);
  }
  if (b[l] == 2 && b[r] == 1) {
    putmax(m + 1, r, x);
  }
  if (b[l] == 2 && b[r] == 2) {
  }
  if (b[l] == 1 && b[r] == 1) {
    putmax(l, r, x);
  }
}
int32_t main() {
  cin >> n;
  for (ll i = 0; i < (n); ++i) {
    cin >> a[i];
    w[a[i]].emplace_back(i);
  }
  while (second < n) second *= 2;
  for (ll i = 0; i < (second + second); ++i) mx[i] = 1e9;
  set<ll> m;
  for (ll i = 0; i < (n + 1); ++i) {
    lt[i] = i;
    b[i] = 2;
    m.insert(i);
  }
  for (auto& [k, v] : w) {
    for (ll i : v) {
      b[i] = 1;
      ll sl = (i && b[i - 1] == 2);
      ll sr = (i + 1 < n && b[i + 1] == 2);
      if (sl && sr) {
        ll er = *m.lower_bound(i + 1);
        m.erase(i - 1);
        m.erase(i);
        lt[er] = lt[i - 1];
      } else if (sl) {
        ll er = *m.lower_bound(i + 1);
        m.erase(i - 1);
        m.insert(i);
        lt[er] = i + 1;
        lt[i] = lt[i - 1];
      } else if (sr) {
        ll er = *m.lower_bound(i + 1);
        m.erase(i);
        if (i) {
          m.insert(i - 1);
          lt[i - 1] = lt[i];
        };
        lt[er] = i;
      } else {
        ll er = *m.lower_bound(i);
        if (i) {
          m.insert(i - 1);
          lt[i - 1] = lt[er];
        }
        lt[er] = i + 1;
        lt[i] = i;
        m.insert(i);
      }
    }
    for (ll i : v) {
      for (ll j = -1; j < 2; ++j) {
        kek(*m.lower_bound(i + j), k);
      }
    }
  }
  cout << ans << '\n';
  out(1);
  cout << '\n';
  return 0;
}
