#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int dh[5] = {1, 0, 0, -1};
int dc[5] = {0, 1, -1, 0};
const int oo = 1111111111;
int a[N], ans1[N], ans2[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int dem = 1;
  int cc = n / 2 + (n % 2 == 1);
  int kq1 = 0, kq2 = 0;
  for (int i = n; i >= n - cc + 1; i--) {
    ans1[dem] = a[i];
    ans2[dem] = a[i];
    dem += 2;
  }
  dem = 2;
  for (int i = n - cc; i >= 1; i--) {
    ans1[dem] = a[i];
    dem += 2;
  }
  dem = 2;
  for (int i = 1; i <= n - cc; i++) {
    ans2[dem] = a[i];
    dem += 2;
  }
  for (int i = 1; i <= n; i++) {
    if (i > 1 && i < n) {
      if (ans1[i] < ans1[i - 1] && ans1[i] < ans1[i + 1]) kq1++;
    }
    if (i > 1 && i < n) {
      if (ans2[i] < ans2[i - 1] && ans2[i] < ans2[i + 1]) kq2++;
    }
  }
  int ccc = max(kq1, kq2);
  cout << ccc << "\n";
  if (kq1 > kq2)
    for (int i = 1; i <= n; i++) cout << ans1[i] << " ";
  else
    for (int i = 1; i <= n; i++) cout << ans2[i] << " ";
}
