#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 - 1;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  for (int q = 0; q < n; q++) {
    cin >> a[q];
  }
  sort(a, a + n);
  int k = 0;
  int t = 0;
  for (int i = 0; i < n / 2; i++) {
    b[t] = a[n / 2 + k];
    b[t + 1] = a[k];
    t += 2;
    k++;
  }
  if (n % 2 == 1) {
    b[n - 1] = a[n - 1];
  }
  int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) cnt++;
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
  return 0;
}
