#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
int N;
int h[200005];
int n[200005];
deque<int> q;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
    ++n[h[i]];
  }
  int ans = 0;
  int id = 0;
  int ans1 = 0;
  for (int i = 1; i <= 2e5; i++) {
    ans1 += n[i];
    if (n[i] <= 1) {
      if (ans < ans1) {
        ans = ans1;
        id = i;
      }
      ans1 = n[i];
    }
  }
  if (ans < ans1) {
    ans = ans1;
    id = 2e5;
  }
  cout << ans << endl;
  for (int i = id; i >= 1; i--) {
    bool f = 0;
    for (int k = 1; k <= n[i]; k++) {
      if (f == 0) q.push_front(i);
      if (f == 1) q.push_back(i);
      f ^= 1;
    }
    if (i != id && n[i] <= 1) break;
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop_front();
    cout << x << " ";
  }
  return 0;
}
