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