#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long quickpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int main(void) {
  int n;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> vt(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> vt[i];
  }
  sort(vt.begin() + 1, vt.end());
  vector<int> ans(n + 1);
  int now = n;
  for (int i = 1; i <= n; i += 2, now--) {
    ans[i] = vt[now];
  }
  for (int i = 2; i <= n; i += 2, now--) {
    ans[i] = vt[now];
  }
  if (n % 2 == 0) {
    int index = 0;
    for (index; index <= n; index += 2) {
      if (ans[index] < ans[index - 1] && ans[index] < ans[index + 1]) {
        continue;
      } else {
        break;
      }
    }
    if (index <= n) swap(ans[index], ans[n]);
  }
  int m = 0;
  for (int i = 2; i <= n - 1; i++) {
    m += (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]);
  }
  cout << m << endl;
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
