#include <bits/stdc++.h>
using namespace std;
const int MXN = 100;
int binary(int a[], int l, int r, int x) {
  if (l + 1 >= r) {
    return l;
  }
  int m = (l + r) / 2;
  if (a[m] > x) {
    return binary(a, l, m, x);
  }
  if (a[m] <= x) {
    return binary(a, m, r, x);
  }
}
long long int saghf(long long int a, long long int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  vector<int> big, small;
  for (int i = 0; i < n; i++) {
    if (i >= n / 2) {
      big.push_back(v[i]);
    } else {
      small.push_back(v[i]);
    }
  }
  int a[n];
  for (int i = 0; i < big.size(); i++) {
    a[2 * i] = big[i];
  }
  for (int i = 0; i < small.size(); i++) {
    a[2 * i + 1] = small[i];
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    if (a[i] < a[i - 1] && a[i] < a[i + 1]) {
      ans++;
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
