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