#include <bits/stdc++.h>
using namespace std;
vector<int> m(200001);
void Print(int pick, int ans) {
  if (m[pick] == 0) {
    Print(pick + 1, ans);
    return;
  }
  if (pick == ans) {
    for (int i = 0; i < m[pick]; ++i) cout << pick << ' ';
  } else {
    cout << pick << ' ';
    Print(pick + 1, ans);
    for (int i = 1; i < m[pick]; ++i) cout << pick << ' ';
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    m[x]++;
  }
  int ans = 0;
  pair<int, int> value = {0, 0};
  int cur_shit = 0;
  int cur_fuck = 0;
  for (int i = 0; i <= 200001; ++i) {
    if (m[i] == 0) {
      cur_shit = 0;
    } else if (m[i] == 1) {
      cur_shit++;
      if (ans < cur_shit) {
        ans = cur_shit;
        cur_fuck = i;
      }
      cur_shit = 1;
    } else if (m[i] >= 2) {
      cur_shit += m[i];
      if (ans < cur_shit) {
        ans = cur_shit;
        cur_fuck = i;
      }
    }
  }
  cout << ans << endl;
  cur_shit = cur_fuck;
  do {
    cur_fuck--;
  } while (m[cur_fuck] != 0 && m[cur_fuck] != 1);
  Print(cur_fuck, cur_shit);
}
