#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn];
long long x;
int n, m, k;
string s, s1;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  int ans = 0, id = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] != a[i - 1]) {
      if ((n - i + 1) - (i - 1) < 1) break;
      id = i - 1;
    }
  }
  int j = 1;
  for (int i = 2; i <= n; i += 2) {
    b[i] = a[j];
    j++;
  }
  for (int i = 1; i <= n; i += 2) {
    b[i] = a[j];
    j++;
  }
  for (int i = 2; i <= n - 1; i++) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}
