#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], n, b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  int j = 1;
  for (int i = 2; i <= n; i += 2) {
    b[i] = a[j++];
  }
  for (int i = 1; i <= n; i += 2) {
    b[i] = a[j++];
  }
  int k = 0;
  for (int i = 2; i < n; ++i)
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) ++k;
  cout << k << endl;
  for (int i = 1; i <= n; ++i) cout << b[i] << " ";
  cout << endl;
}
