#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
struct IntvMax {
  vector<vi> data;
  int n, lg;
  IntvMax(const vi &what) {
    debug() << " ["
            << "what"
               ": "
            << (what) << "] ";
    n = ((int)(what).size());
    lg = 1;
    while ((1 << lg) < n) {
      ++lg;
    }
    n = (1 << lg);
    data = vector<vi>(lg + 1, vi(n, -1e9));
    for (int i = 0; i < ((int)(what).size()); ++i) {
      data[0][i] = what[i];
    }
    for (int lvl = 1; lvl <= lg; ++lvl) {
      data[lvl] = data[lvl - 1];
      const int jump = (1 << (lvl - 1));
      for (int i = 0; i + jump < n; ++i) {
        data[lvl][i] = max(data[lvl - 1][i], data[lvl - 1][i + jump]);
      }
    }
    debug() << " ["
            << "data"
               ": "
            << (data) << "] ";
  }
  int GetMax(int L, int R) {
    L = max(L, 0);
    R = min(R, n - 1);
    assert(L <= R);
    int len = R - L + 1;
    int lvl = 31 - __builtin_clz(len);
    debug() << " ["
            << "lvl"
               ": "
            << (lvl) << "] "
            << " ["
            << "data[lvl]"
               ": "
            << (data[lvl]) << "] ";
    return max(data[lvl][L], data[lvl][R - (1 << lvl) + 1]);
  }
};
int n;
vi h;
int Median(int a, int b, int c) {
  return a ^ b ^ c ^ min({a, b, c}) ^ max({a, b, c});
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  h.resize(n);
  for (int &x : h) {
    cin >> x;
  }
  vi h_even, h_odd;
  for (int i = 0; i < n; ++i) {
    (i % 2 == 0 ? h_even : h_odd).push_back(h[i]);
  }
  IntvMax max_even(h_even), max_odd(h_odd);
  for (int &x : h_even) {
    x = -x;
  }
  for (int &x : h_odd) {
    x = -x;
  }
  IntvMax min_even(h_even), min_odd(h_odd);
  auto GetEx = [&](int L, int R, bool max) {
    debug() << " ["
            << "L"
               ": "
            << (L) << "] "
            << " ["
            << "R"
               ": "
            << (R) << "] "
            << " ["
            << "max"
               ": "
            << (max) << "] ";
    if (L < 0) {
      L = (L % 2 == 0) ? 0 : 1;
    }
    if (R >= n) {
      if (R % 2 == n % 2) {
        R = n;
      } else {
        R = n - 1;
      }
    }
    assert(L % 2 == R % 2);
    if (L % 2 == 0) {
      if (max) {
        return max_even.GetMax(L / 2, R / 2);
      } else {
        return -min_even.GetMax(L / 2, R / 2);
      }
    } else {
      if (max) {
        return max_odd.GetMax(L / 2, R / 2);
      } else {
        return -min_odd.GetMax(L / 2, R / 2);
      }
    }
  };
  vi lasth(n);
  vi ans(n);
  for (int i = 0; i < n; ++i) {
    if (i == 0 || i == n - 1) {
      lasth[i] = h[i];
      continue;
    }
    if (Median(h[i - 1], h[i], h[i + 1]) == h[i]) {
      lasth[i] = h[i];
      continue;
    }
    bool small = (h[i] < h[i - 1] && h[i] < h[i + 1]);
    debug() << " ["
            << "i"
               ": "
            << (i) << "] ";
    auto Can = [&](int steps) {
      int radl = steps / 2;
      int radr = (steps + 1) / 2;
      if (small) {
        return GetEx(i - 2 * radl, i + 2 * radl, true) <
               GetEx(i - 2 * radr + 1, i + 2 * radr - 1, false);
      } else {
        int a = GetEx(i - 2 * radl, i + 2 * radl, false);
        int b = GetEx(i - 2 * radr + 1, i + 2 * radr - 1, true);
        debug() << " ["
                << "steps"
                   ": "
                << (steps) << "] "
                << " ["
                << "a"
                   ": "
                << (a) << "] "
                << " ["
                << "b"
                   ": "
                << (b) << "] ";
        return a > b;
      }
    };
    int L = ans[i - 1];
    if (Can(L + 1)) {
      ++L;
    } else if (!Can(L)) {
      --L;
    }
    L = min(L, i);
    L = min(L, (n - 1) - i);
    ans[i] = L;
    int A = i - L;
    int B = i + L;
    bool mx = small ^ (L % 2 == 1);
    debug() << " ["
            << "A"
               ": "
            << (A) << "] "
            << " ["
            << "B"
               ": "
            << (B) << "] "
            << " ["
            << "mx"
               ": "
            << (mx) << "] "
            << " !!!!";
    lasth[i] = GetEx(A, B, mx);
  }
  debug() << " ["
          << "ans"
             ": "
          << (ans) << "] ";
  cout << *max_element((ans).begin(), (ans).end()) << "\n";
  for (int x : lasth) {
    cout << x << " ";
  }
  cout << "\n";
}
