#include <bits/stdc++.h>
std::vector<int> v;
int check(int k, int n) {
  if (2 * k + 1 > n) return false;
  for (int i = 0; i < k; i++)
    if (v[i] >= v[n - 1 - k + i]) return false;
  return true;
}
int main() {
  int n, c;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> c;
    v.push_back(c);
  }
  std::sort(v.begin(), v.end());
  int st = 1, dr = n, ans = 0;
  while (st <= dr) {
    int mijl = (st + dr) / 2;
    if (check(mijl, n)) {
      ans = mijl;
      st = mijl + 1;
    } else
      dr = mijl - 1;
  }
  std::cout << ans << "\n";
  for (int i = 0; i < ans; i++)
    std::cout << v[n - 1 - ans + i] << " " << v[i] << " ";
  std::cout << v[n - 1] << " ";
  for (int i = ans; i < n - 1 - ans; i++) std::cout << v[i] << " ";
}
