#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
queue<long long> Q, P;
long long b[maxn], a[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> b[i];
  sort(b + 1, b + n + 1);
  for (int i = 1; i < n + 1; i++) {
    if (i <= n / 2)
      Q.push(b[i]);
    else
      P.push(b[i]);
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      long long top = P.front();
      P.pop();
      a[i] = top;
    } else {
      long long top = Q.front();
      Q.pop();
      a[i] = top;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans++;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
