#include <bits/stdc++.h>
using namespace std;
long long n, k, res;
long long a[1000010];
long long ans[1000010];
bool cmp(long long a, long long b) { return a > b; }
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  for (long long i = 2; i <= n; i += 2) {
    ans[i] = a[++k];
  }
  for (long long i = 1; i <= n; i += 2) {
    ans[i] = a[++k];
  }
  for (long long i = 1; i <= n; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) res++;
  }
  cout << res << endl;
  for (long long i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
