#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100010], ans[100010];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int pos = 0;
  for (int i = 0; i < n / 2; i++) {
    ans[pos++] = a[n / 2 + i];
    ans[pos++] = a[i];
  }
  int cnt = 0;
  if (n % 2 == 1) ans[pos++] = a[n - 1];
  for (int i = 1; i < n - 1; i++) {
    if (ans[i - 1] > ans[i] && ans[i + 1] > ans[i]) cnt++;
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}
