#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n + 10, 0), ans(n + 10, 0);
  for (int i = 1; i <= n; i++) cin >> v[i];
  map<int, int> bag;
  for (int i = 1; i <= n; i++) bag[v[i]]++;
  for (int i = 2; i <= n; i += 2) {
    auto it = bag.begin();
    int key = it->first;
    ans[i] = key;
    bag[key]--;
    if (bag[key] == 0) bag.erase(key);
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 0) {
      int key;
      if (i == 1 || i == n) {
        auto it = bag.upper_bound(v[i]);
        if (it == bag.end()) it = bag.begin();
        key = it->first;
      } else {
        auto it = bag.upper_bound(max(ans[i - 1], ans[i + 1]));
        if (it == bag.end()) it = bag.begin();
        key = it->first;
      }
      bag[key]--;
      ans[i] = key;
      if (bag[key] == 0) bag.erase(key);
    }
  }
  for (int i = 2; i <= n - 1; i++)
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) count++;
  cout << count << endl;
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
}
