#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 500005;
int n;
int a[N], b[N], c[N];
vector<int> value;
int ans, trace[N];
int lg[N], rmqMin[N][20], rmqMax[N][20];
void solve(int l, int r, int lo, int hi) {
  if (l > r) return;
  if (lo == hi) {
    for (int i = l; i <= r; i++) trace[i] = value[lo];
    return;
  }
  int mid = (lo + hi) >> 1;
  for (int i = l - 1; i <= r + 1; i++) b[i] = (a[i] > mid ? 1 : 0);
  for (int i = l - 1; i <= r + 1; i++) {
    int ptr = i;
    while (ptr + 1 <= r + 1 && b[ptr + 1] != b[ptr]) ptr++;
    if (i == l - 1 && ptr == r + 1) {
      int typeL = (c[l - 1] > mid ? 1 : 0);
      int typeR = (c[r + 1] > mid ? 1 : 0);
      if (typeL == typeR) {
        for (int j = l; j <= r; j++) b[j] = typeL;
      } else {
        int L = l - 1, R = r + 1;
        if (typeL == 1) {
          for (int j = lg[L]; j >= 0; j--) {
            if (L - (1 << j) >= 1 && rmqMax[L - (1 << j) + 1][j] <= mid) {
              L -= (1 << j);
            }
          }
        } else {
          for (int j = lg[L]; j >= 0; j--) {
            if (L - (1 << j) >= 1 && rmqMin[L - (1 << j) + 1][j] > mid) {
              L -= (1 << j);
            }
          }
        }
        if (typeR == 1) {
          for (int j = lg[n - R + 1]; j >= 0; j--) {
            if (R + (1 << j) - 1 <= n && rmqMax[R][j] <= mid) {
              R += (1 << j);
            }
          }
        } else {
          for (int j = lg[n - R + 1]; j >= 0; j--) {
            if (R + (1 << j) - 1 <= n && rmqMin[R][j] > mid) {
              R += (1 << j);
            }
          }
        }
        R--;
        int pivot = (L + R) >> 1;
        for (int j = l; j <= r; j++) {
          b[j] = (j <= pivot ? typeL : typeR);
        }
        ans = max(ans, (R - L) / 2);
      }
    } else if (i == l - 1 && (c[l - 1] > mid) == b[ptr]) {
      for (int j = i; j <= ptr; j++) b[j] = b[ptr];
    } else if (ptr == r + 1 && (c[r + 1] > mid) == b[i]) {
      for (int j = i; j <= ptr; j++) b[j] = b[i];
    } else {
      int L = i, R = ptr;
      while (L - 1 >= 1 && (a[L - 1] > mid) != (a[L] > mid)) L--;
      while (R + 1 <= n && (a[R + 1] > mid) != (a[R] > mid)) R++;
      if ((a[L] > mid) == (a[R] > mid)) {
        for (int j = L; j <= R; j++) b[j] = (a[L] > mid);
      } else {
        int pivot = (L + R) >> 1;
        for (int j = L; j <= pivot; j++) b[j] = (a[L] > mid);
        for (int j = pivot + 1; j <= R; j++) b[j] = (a[R] > mid);
      }
      ans = max(ans, (R - L) / 2);
    }
    i = ptr;
  }
  vector<pair<pair<int, int>, int> > seg;
  for (int i = l; i <= r; i++) {
    int ptr = i;
    while (ptr + 1 <= r && b[ptr + 1] == b[i]) ptr++;
    seg.push_back({{i, ptr}, b[i]});
    for (int j = i; j <= ptr; j++) c[j] = (b[j] == 1 ? mid + 1 : mid);
    i = ptr;
  }
  for (auto i : seg) {
    int L = i.first.first, R = i.first.second, type = i.second;
    if (type == 1) {
      solve(L, R, mid + 1, hi);
    } else {
      solve(L, R, lo, mid);
    }
  }
}
void getAns(int i, int val) {
  int l, r, type;
  int tmp = i;
  for (int j = lg[tmp]; j >= 0; j--) {
    if (tmp - (1 << j) >= 1 && rmqMin[tmp - (1 << j) + 1][j] > val) {
      tmp -= (1 << j);
    }
  }
  l = tmp;
  tmp = i;
  for (int j = lg[tmp]; j >= 0; j--) {
    if (tmp - (1 << j) >= 1 && rmqMax[tmp - (1 << j) + 1][j] <= val) {
      tmp -= (1 << j);
    }
  }
  l = max(l, tmp);
  tmp = i;
  for (int j = lg[n - tmp + 1]; j >= 0; j--) {
    if (tmp + (1 << j) - 1 <= n && rmqMin[tmp][j] > val) {
      tmp += (1 << j);
    }
  }
  r = tmp - 1;
  tmp = i;
  for (int j = lg[n - tmp + 1]; j >= 0; j--) {
    if (tmp + (1 << j) - 1 <= n && rmqMax[tmp][j] <= val) {
      tmp += (1 << j);
    }
  }
  r = min(r, tmp - 1);
  if (l <= r) ans = max(ans, (r - l) / 2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    value.push_back(a[i]);
  }
  sort(value.begin(), value.end());
  value.resize(distance(value.begin(), unique(value.begin(), value.end())));
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(value.begin(), value.end(), a[i]) - value.begin();
    rmqMin[i][0] = max(a[i], a[i - 1]);
    rmqMax[i][0] = min(a[i], a[i - 1]);
    lg[i] = log2(i);
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      rmqMin[i][j] = min(rmqMin[i][j - 1], rmqMin[i + (1 << (j - 1))][j - 1]);
      rmqMax[i][j] = max(rmqMax[i][j - 1], rmqMax[i + (1 << (j - 1))][j - 1]);
    }
  }
  c[1] = a[1];
  c[n] = a[n];
  solve(2, n - 1, 0, (int)value.size() - 1);
  for (int i = 2; i <= n - 1; i++) {
    getAns(i, a[i] - 1);
    getAns(i, a[i]);
  }
  cout << ans << "\n";
  trace[1] = value[a[1]];
  trace[n] = value[a[n]];
  for (int i = 1; i <= n; i++) cout << trace[i] << " ";
}
