#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  int n = read();
  vector<int> vec, ans(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    vec.push_back(read());
  }
  sort(vec.begin(), vec.end());
  int cur1 = 0, cur2 = n - 1;
  for (int i = 2; i <= n; i += 2) {
    ans[i] = vec[cur1++];
  }
  for (int i = 1; i <= n; i += 2) {
    ans[i] = vec[cur1++];
  }
  int cnt = 0;
  for (int i = 2; i < n; i++) {
    if (ans[i - 1] > ans[i] && 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;
}
