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