#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
int a[N], ans[N];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  sort(a + 1, a + 1 + n);
  int x = 1, y = n / 2 + 1;
  for (int i = 1; i <= n; i++) {
    if (i % 2) {
      ans[i] = a[y++];
    } else {
      ans[i] = a[x++];
    }
  }
  long long cnt = 0;
  for (int i = 2; i < n; i++) {
    if ((ans[i] < ans[i - 1]) && (ans[i] < ans[i + 1])) cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  return 0;
}
