#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int C = 26;
void add(int &x, int y) {
  x += y;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
}
int fix(int x) {
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
int pw(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % MOD;
    b >>= 1;
    a = 1ll * a * a % MOD;
  }
  return ret;
}
const int MAXN = 2e5 + 10;
int msb(int n) { return 31 - __builtin_clz(n); }
template <typename T>
struct SparseTable {
  int n;
  vector<vector<T>> tab;
  void build(vector<T> a) {
    n = a.size();
    int B = msb(n) + 1;
    tab.resize(B);
    for (int b = 0; b < B; b++) {
      tab[b].resize(n);
      int len = 1 << b;
      for (int i = 0; i <= n - len; i++) {
        if (len == 1) {
          tab[b][i] = a[i];
        } else {
          tab[b][i] = min(tab[b - 1][i], tab[b - 1][i + len / 2]);
        }
      }
    }
  }
  T get(int L, int R) const {
    int b = msb(R - L + 1);
    return min(tab[b][L], tab[b][R - (1 << b) + 1]);
  }
};
int n, a[MAXN];
int fr[MAXN];
int pre[MAXN];
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) ++fr[a[i]];
  for (int i = 0; i < MAXN; i++) {
    pre[i] = fr[i];
    if (i > 0) {
      pre[i] += pre[i - 1];
    }
  }
  vector<int> vec(fr, fr + MAXN);
  SparseTable<int> st;
  st.build(vec);
  array<int, 4> ans = {0, 0, 0, 0};
  for (int x = 0; x + 2 < MAXN; x++) {
    if (fr[x + 1] < 2) continue;
    if (fr[x] == 0) continue;
    int lo = x + 1, hi = MAXN - 1;
    while (hi - lo > 1) {
      int mid = (lo + hi) / 2;
      if (st.get(x + 1, mid) >= 2) {
        lo = mid;
      } else {
        hi = mid;
      }
    }
    int now = pre[lo] - (x == 0 ? 0 : pre[x - 1]);
    int peak = 0;
    if (fr[lo + 1] > 0) {
      assert(fr[lo + 1] == 1);
      peak = 1;
      now += 1;
    }
    array<int, 4> ar = {now, x, lo, peak};
    ans = max(ans, ar);
  }
  for (int i = 0; i + 1 < MAXN; i++) {
    array<int, 4> ar = {fr[i] + fr[i + 1], i, i + 1, -1};
    ans = max(ans, ar);
  }
  cout << ans[0] << "\n";
  if (ans[3] == -1) {
    for (int rep = 0; rep < fr[ans[1]]; rep++) cout << ans[1] << " ";
    for (int rep = 0; rep < fr[ans[2]]; rep++) cout << ans[2] << " ";
    cout << "\n";
  } else {
    for (int rep = 0; rep < fr[ans[1]]; rep++) cout << ans[1] << " ";
    for (int x = ans[1] + 1; x <= ans[2]; x++) {
      for (int rep = 1; rep < fr[x]; rep++) {
        cout << x << " ";
      }
    }
    if (ans[3]) cout << ans[2] + 1 << " ";
    for (int x = ans[2]; x > ans[1]; x--) {
      cout << x << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int te = 1;
  for (int w = 1; w <= te; w++) {
    solve();
  }
  return 0;
}
