#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  long long int arr[n];
  for (int j = 0; j < n; j++) {
    cin >> arr[j];
  }
  long long int brr[n];
  sort(arr, arr + n);
  int pos = 1, p = 0;
  while (pos < n) {
    brr[pos] = arr[p];
    p++;
    pos += 2;
  }
  pos = 0;
  while (pos < n) {
    brr[pos] = arr[p];
    p++;
    pos += 2;
  }
  int ans = 0;
  for (int j = 1; j < n; j = j + 2) {
    if (j + 1 < n) {
      if (brr[j - 1] > brr[j] && brr[j + 1] > brr[j]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  for (int j = 0; j < n; j++) {
    cout << brr[j] << " ";
  }
}
