#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int ans[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  int cnt = 0;
  if (n & 1) {
    int l = 1, r = n / 2 + 1;
    ans[++cnt] = a[r];
    r++;
    for (int i = 1; i <= n / 2; i++) {
      ans[++cnt] = a[l], ans[++cnt] = a[r];
      l++, r++;
    }
  } else {
    int l = 1, r = n / 2 + 1;
    for (int i = 1; i <= n / 2; i++) {
      ans[++cnt] = a[r], ans[++cnt] = a[l];
      l++, r++;
    }
  }
  int num = 0;
  for (int i = 2; i <= n; i += 2) {
    if (ans[i - 1] > ans[i] && ans[i + 1] > ans[i]) num++;
  }
  printf("%d\n", num);
  for (int i = 1; i <= cnt; i++) {
    printf("%d%c", ans[i], i == n ? '\n' : ' ');
  }
  return 0;
}
