#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  vector<long long> v(n);
  long long j = 0;
  for (int i = 1; i < n; i += 2) {
    v[i] = a[j];
    j++;
  }
  for (int i = 0; i < n; i += 2) {
    v[i] = a[j];
    j++;
  }
  long long cou = 0;
  for (int i = 1; i < v.size() - 1; i++) {
    if ((v[i] < v[i - 1]) && (v[i] < v[i + 1])) {
      cou++;
    }
  }
  cout << cou << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
