#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int inf = 1000000000;
const double eps = 0.0000001;
long long n;
long long a[200100];
long long e[200100];
long long h[200100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = (0); i < (n); ++i) {
    cin >> a[i];
    e[a[i]]++;
    h[a[i]]++;
  };
  long long res = 0;
  long long loc = -1;
  long long rtot = 0;
  long long len = 0;
  long long start = -1;
  long long tot = 0;
  for (long long i = (0); i < (200100); ++i) {
    if (e[i] == 1) {
      if (start != -1) {
        len++;
        tot += e[i];
        if (tot > rtot) {
          loc = start;
          res = len;
          rtot = tot;
        }
      }
      len = 1;
      start = i;
      tot = e[i];
    } else if (e[i] > 1) {
      if (start == -1) {
        start = i;
        len = 0;
        tot = 0;
      }
      len++;
      tot += e[i];
      if (tot > rtot) {
        loc = start;
        res = len;
        rtot = tot;
      }
    } else {
      len = 0;
      start = -1;
      tot = 0;
    }
    if (tot > rtot) {
      loc = start;
      res = len;
      rtot = tot;
    }
  }
  cout << rtot << endl;
  for (long long i = (loc); i < (loc + res); ++i) {
    for (long long j = (0); j < (e[i] - 1); ++j) {
      cout << i << " ";
    }
  }
  for (long long i = loc + res - 1; i >= loc; i--) {
    cout << i << " ";
  }
  return 0;
}
