#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100010], b[100010], ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int s = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      b[i] = a[n / 2 + s];
    else {
      b[i] = a[s];
      s++;
    }
  }
  for (int i = 1; i < n - 1; i++) {
    if (b[i - 1] > b[i] && b[i + 1] > b[i]) ans++;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << b[i] << " ";
  return 0;
}
