#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int tests = 1;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  int m = n / 2 + 1, d = 1;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1) {
      b[i] = a[m++];
    } else {
      b[i] = a[d++];
    }
  }
  int ans = 0;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) ans++;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", b[i]);
  return 0;
}
