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