#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
  int n, a[100005];
  int ans[100005];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int pos = (n / 2) + 1;
  for (int i = 1; i <= n; i += 2) {
    ans[i] = a[pos];
    pos++;
  }
  pos = 1;
  for (int i = 2; i <= n; i += 2) {
    ans[i] = a[pos];
    pos++;
  }
  int d = 0;
  for (int i = 2; i < n; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) {
      d++;
    }
  }
  cout << d << '\n';
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
}
