#include <bits/stdc++.h>
using namespace std;
const int limit = 1000000;
int n;
int amount[limit];
int sol[limit];
int isol;
vector<int> vsol;
void gensol(int i) {
  if (amount[i] == 0) return;
  if (amount[i] == 1) {
    vsol.push_back(i);
    return;
  }
  vsol.push_back(i);
  gensol(i + 1);
  for (int c = 1; c < amount[i]; c++) vsol.push_back(i);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    amount[x]++;
  }
  for (int i = limit - 1; i >= 1; i--) {
    if (amount[i]) {
      if (amount[i + 1] == 1) {
        sol[i] = amount[i] + 1;
      } else if (amount[i + 1] > 1) {
        sol[i] = amount[i] + sol[i + 1];
      } else {
        sol[i] = amount[i];
      }
      if (sol[isol] < sol[i]) isol = i;
    }
  }
  gensol(isol + 1);
  for (int i = 0; i < int(amount[isol]); i++) vsol.push_back(isol);
  cout << int(vsol.size()) << endl;
  for (int i = 0; i < int(vsol.size()); i++) {
    if (i > 0) cout << " ";
    cout << vsol[i];
  }
  cout << endl;
}
