#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int cas = 1;
  while (cas--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &x : a) {
      cin >> x;
    }
    vector<int> b = a;
    sort(b.begin(), b.end());
    int j = 0;
    for (int i = 1; i < n; i += 2) a[i] = b[j++];
    for (int i = 0; i < n; i += 2) a[i] = b[j++];
    int res = 0;
    for (int i = 1; i < n - 1; i += 2) {
      if (a[i] < a[i - 1] && a[i] < a[i + 1]) ++res;
    }
    cout << res << "\n";
    for (auto u : a) {
      cout << u << " ";
    }
    cout << "\n";
  }
  return 0;
}
