#include <bits/stdc++.h>
using namespace std;
int n, a[100005], ans[100005], flag[100005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int res = 0;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (i % 2)
      ans[i] = a[n / 2 + i / 2 + 1];
    else
      ans[i] = a[i / 2];
  }
  for (int i = 2; i < n; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) res++;
  }
  printf("%d\n", res);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
