#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> V(n), ans(n);
  for (auto& x : V) {
    cin >> x;
  }
  sort(V.begin(), V.end());
  int j = n - 1;
  for (int i = n - 1; i > -1; i -= 2) {
    ans[i] = V[j];
    j--;
  }
  for (int i = n - 2; i > -1; i -= 2) {
    ans[i] = V[j];
    j--;
  }
  int sum = 0;
  for (int i = 1; i < n - 1; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) {
      sum++;
    }
  }
  cout << sum << '\n';
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
}
