#include <bits/stdc++.h>
using namespace std;
const long long sz = 1e5 + 10;
long long ara[sz], ans[sz];
multiset<int> lst;
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &ara[i]);
    lst.insert(ara[i]);
  }
  long long res = 0, idx = n;
  for (long long i = n; i >= 1; i -= 2) {
    long long v = *(--lst.end());
    ans[i] = v;
    lst.erase(lst.find(v));
  }
  for (long long i = n - 1; i >= 1; i -= 2) {
    if (i == 1) {
      ans[i] = *(--lst.end());
      continue;
    }
    long long v = *(--lst.end());
    if (ans[i - 1] != v) {
      ans[i] = v;
      res++;
      lst.erase(lst.find(v));
      continue;
    }
    auto it = lst.lower_bound(v);
    if (it == lst.begin()) {
      ans[i] = v;
      lst.erase(it);
      continue;
    }
    ans[i] = *(--it);
    lst.erase(it);
    res++;
  }
  cout << res << '\n';
  for (long long i = 1; i <= n; ++i) {
    if (i != 1) printf(" ");
    printf("%lld", ans[i]);
  }
  printf("\n");
  return 0;
}
