#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int tmp, n;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (b != 0) {
    n = a % b;
    a = b;
    b = n;
  }
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> ve;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    ve.push_back(num);
  }
  sort(ve.begin(), ve.end());
  int idx = 0;
  int _idx = n / 2;
  vector<int> r_ve;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      r_ve.push_back(ve[_idx++]);
    } else {
      r_ve.push_back(ve[idx++]);
    }
  }
  for (int i = 1; i < n - 1; i++) {
    int l = r_ve[i - 1];
    int r = r_ve[i + 1];
    if (r_ve[i] < l && r_ve[i] < r) count++;
  }
  cout << count << "\n";
  for (auto i : r_ve) {
    cout << i << " ";
  }
  return 0;
}
