#include <bits/stdc++.h>
using namespace std;
int cnt[200021];
int main() {
  int n, k;
  cin >> n;
  int arr[n + 10];
  set<int> st;
  for (int i = 1; i <= n; i++) cin >> arr[i], cnt[arr[i]]++, st.insert(arr[i]);
  map<int, int> mp;
  int ns = 0;
  auto it = st.begin();
  int pos = 0;
  for (; it != st.end(); it++) {
    int ans = 0;
    int prev = *it - 1;
    if (cnt[prev] > 1)
      ans = mp[prev];
    else
      ans = cnt[prev];
    ans += cnt[*it];
    mp[*it] = ans;
    if (ans > ns) {
      pos = *it;
      ns = ans;
    }
  }
  vector<int> v;
  cout << ns << endl;
  int cnt1 = 0;
  vector<int> ans(ns + 5);
  int j = ns, i = 1;
  while (cnt1 != ns) {
    for (int k = 1; k < cnt[pos]; k++) {
      ans[i] = pos;
      i++;
      cnt1++;
    }
    ans[j] = pos;
    j--;
    pos--;
    cnt1++;
    if (cnt1 == ns) break;
  }
  for (int i = 1; i <= ns; ++i) cout << ans[i] << " ";
}
