#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long l = 0, r = n / 2;
  vector<long long> order;
  while (l < n / 2 and r < n) {
    order.push_back(a[r]);
    order.push_back(a[l]);
    l++;
    r++;
  }
  if (n % 2) order.push_back(a[n - 1]);
  long long spheres = 0;
  for (long long i = 1; i < order.size() - 1; i++) {
    if (order[i] < order[i - 1] and order[i] < order[i + 1]) {
      spheres++;
    }
  }
  cout << spheres << endl;
  for (auto it : order) cout << it << " ";
  return 0;
}
