#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
void swap(int j, int i) {
  int temp = a[i];
  a[i] = a[j];
  a[j] = temp;
}
void qsort(int left, int right) {
  int i = left;
  int j = right;
  int mid = a[(left + right) / 2];
  do {
    while (a[i] < mid) i++;
    while (a[j] > mid) j--;
    if (i <= j) {
      swap(i, j);
      i++;
      j--;
    }
  } while (i <= j);
  if (j > left) qsort(left, j);
  if (i < right) qsort(i, right);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  qsort(0, n - 1);
  int ans;
  if (n % 2 == 0)
    ans = n / 2 - 1;
  else
    ans = n / 2;
  int k1 = 0, k2 = n / 2;
  k1 = 0;
  k2 = n / 2;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      b[i] = a[k2++];
    else
      b[i] = a[k1++];
  }
  for (int i = 1; i < n - 1; i += 2) {
    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] << " ";
  return 0;
}
