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