#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 500000;
const int MAXS = 4 * MAXN;
struct Block {
  int sval, len;
  bool alternating;
  Block() {}
  Block(int sval, int len, bool alternating)
      : sval(sval), len(len), alternating(alternating) {}
};
int n;
int a[MAXN];
int tans;
int ans[MAXN];
int v[MAXN], nv;
vector<int> pos[MAXN];
map<int, Block> blocks;
vector<Block> normalize(vector<Block> seq, bool hasfst, bool haslst) {
  vector<Block> ret;
  for (int i = (0); i < (((int)(seq).size())); ++i) {
    Block cur = seq[i];
    if (cur.len == 0) continue;
    if (((int)(ret).size()) == 0) {
      if (hasfst) {
        if (cur.alternating) {
          ret.push_back(Block(cur.sval, 1, false));
          cur.sval = 1 - cur.sval, --cur.len;
          if (cur.len == 0) continue;
          ret.push_back(cur);
        } else {
          ret.push_back(cur);
        }
      } else {
        ret.push_back(cur);
      }
    } else {
      Block prv = ret.back();
      ret.pop_back();
      if (!prv.alternating) {
        if (!cur.alternating) {
          if (cur.sval == prv.sval) {
            prv.len += cur.len;
            ret.push_back(prv);
          } else {
            if (cur.len == 1) cur.alternating = true;
            ret.push_back(prv);
            ret.push_back(cur);
          }
        } else {
          if (cur.sval == prv.sval) {
            ++prv.len, --cur.len, cur.sval = 1 - cur.sval;
            ret.push_back(prv);
            if (cur.len >= 1) ret.push_back(cur);
          } else {
            ret.push_back(prv);
            ret.push_back(cur);
          }
        }
      } else {
        int prvtval = prv.len % 2 == 0 ? 1 - prv.sval : prv.sval;
        if (!cur.alternating) {
          if (cur.sval == prvtval) {
            --prv.len, ++cur.len;
            if (prv.len >= 1) ret.push_back(prv);
            ret.push_back(cur);
          } else {
            if (cur.len == 1) {
              ++prv.len;
              ret.push_back(prv);
            } else {
              ret.push_back(prv);
              ret.push_back(cur);
            }
          }
        } else {
          if (cur.sval == prvtval) {
            --prv.len, --cur.len;
            cur.sval = 1 - cur.sval;
            if (prv.len >= 1) ret.push_back(prv);
            ret.push_back(Block(prvtval, 2, false));
            if (cur.len >= 1) ret.push_back(cur);
          } else {
            prv.len += cur.len;
            ret.push_back(prv);
          }
        }
      }
    }
  }
  if (((int)(ret).size()) >= 1) {
    Block prv = ret.back();
    ret.pop_back();
    int prvtval = prv.len % 2 == 0 ? 1 - prv.sval : prv.sval;
    if (haslst) {
      if (prv.alternating) {
        --prv.len;
        if (prv.len >= 1) ret.push_back(prv);
        ret.push_back(Block(prvtval, 1, false));
      } else {
        ret.push_back(prv);
      }
    } else {
      ret.push_back(prv);
    }
  }
  return ret;
}
int sval[MAXS];
void sapply(int x, int val) { sval[x] = max(sval[x], val); }
void sinit(int x, int l, int r) {
  sval[x] = INT_MIN;
  if (l != r) {
    int m = l + (r - l) / 2;
    sinit(2 * x + 1, l, m);
    sinit(2 * x + 2, m + 1, r);
  }
}
void supd(int x, int l, int r, int L, int R, int VAL) {
  if (L <= l && r <= R) {
    sapply(x, VAL);
  } else {
    int m = l + (r - l) / 2;
    if (L <= m) supd(2 * x + 1, l, m, L, R, VAL);
    if (m + 1 <= R) supd(2 * x + 2, m + 1, r, L, R, VAL);
  }
}
int sget(int x, int l, int r, int IDX) {
  int ret = sval[x];
  if (l != r) {
    int m = l + (r - l) / 2;
    if (IDX <= m)
      ret = max(ret, sget(2 * x + 1, l, m, IDX));
    else
      ret = max(ret, sget(2 * x + 2, m + 1, r, IDX));
  }
  return ret;
}
void updateans(int idx, Block block, int val) {
  if (block.alternating) tans = max(tans, (block.len + 1) / 2);
  if (!block.alternating) {
    if (block.sval == 1) supd(0, 0, n - 1, idx, idx + block.len - 1, val);
  } else if (block.len % 2 == 1) {
    if (block.sval == 0) supd(0, 0, n - 1, idx, idx + block.len - 1, val);
  } else {
    if (block.sval == 0) supd(0, 0, n - 1, idx, idx + block.len / 2 - 1, val);
    if (block.sval == 1)
      supd(0, 0, n - 1, idx + block.len / 2, idx + block.len - 1, val);
  }
}
void solve() {
  nv = 0;
  for (int i = (0); i < (n); ++i) v[nv++] = a[i];
  sort(v, v + nv);
  nv = unique(v, v + nv) - v;
  for (int i = (0); i < (n); ++i) a[i] = lower_bound(v, v + nv, a[i]) - v;
  for (int i = (0); i < (nv); ++i) pos[i].clear();
  for (int i = (0); i < (n); ++i) pos[a[i]].push_back(i);
  blocks.clear();
  blocks[0] = Block(0, n, false);
  tans = 0;
  sinit(0, 0, n - 1);
  for (int x = nv - 1; x >= 0; --x) {
    set<int> changed;
    for (int i = (0); i < (((int)(pos[x]).size())); ++i) {
      int at = pos[x][i];
      auto it = blocks.upper_bound(at);
      if (it != blocks.end()) assert(it != blocks.begin());
      it = prev(it);
      Block cur = it->second;
      int curidx = it->first;
      assert(curidx <= at && at < curidx + cur.len);
      Block prv;
      bool haveprv;
      Block nxt;
      bool havenxt;
      if (it == blocks.begin())
        haveprv = false;
      else {
        haveprv = true;
        prv = prev(it)->second;
        blocks.erase(prev(it));
      }
      if (next(it) == blocks.end())
        havenxt = false;
      else {
        havenxt = true;
        nxt = next(it)->second;
        blocks.erase(next(it));
      }
      blocks.erase(it);
      vector<Block> seq;
      if (haveprv) seq.push_back(prv);
      int offset = at - curidx;
      if (!cur.alternating) {
        assert(cur.sval == 0);
        seq.push_back(Block(0, offset, false));
        seq.push_back(Block(1, 1, false));
        seq.push_back(Block(0, cur.len - offset - 1, false));
      } else {
        assert((offset % 2 == 0) == (cur.sval == 0));
        seq.push_back(Block(cur.sval, offset, true));
        seq.push_back(Block(1, 1, false));
        seq.push_back(Block(1, cur.len - offset - 1, true));
      }
      if (havenxt) seq.push_back(nxt);
      int seqstart = curidx - (haveprv ? prv.len : 0);
      int seqend = curidx + cur.len + (havenxt ? nxt.len : 0);
      seq = normalize(seq, seqstart == 0, seqend == n);
      int atidx = seqstart;
      for (int j = (0); j < (((int)(seq).size())); ++j) {
        changed.insert(atidx);
        blocks[atidx] = seq[j];
        atidx += seq[j].len;
      }
    }
    for (auto it = changed.begin(); it != changed.end(); ++it) {
      int idx = *it;
      auto blocksit = blocks.find(idx);
      if (blocksit != blocks.end()) updateans(idx, blocksit->second, v[x]);
    }
  }
  for (int i = (0); i < (n); ++i) ans[i] = sget(0, 0, n - 1, i);
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  solve();
  printf("%d\n", tans);
  for (int i = (0); i < (n); ++i) {
    if (i != 0) printf(" ");
    printf("%d", ans[i]);
  }
  puts("");
}
std::mt19937 rnd(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
void stress() {
  for (int rep = (0); rep < (1000); ++rep) {
    n = rnd() % 100 + 2;
    for (int i = (0); i < (n); ++i) a[i] = rnd() % 10 + 1;
    printf("%d\n", n);
    for (int i = (0); i < (n); ++i) {
      if (i != 0) printf(" ");
      printf("%d", a[i]);
    }
    puts("");
    solve();
    printf(".");
  }
}
int main() {
  run();
  return 0;
}
