#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n = 0;
  cin >> n;
  vector<int> v(n), ans(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int idx = 0;
  for (int i = 1; i < n; i += 2) {
    ans[i] = v[idx++];
  }
  for (int j = 0; j < n; j += 2) {
    ans[j] = v[idx++];
  }
  int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) {
      cnt++;
    }
  }
  cout << cnt << '\n';
  for (int &x : ans) {
    cout << x << ' ';
  }
  cout << '\n';
  return 0;
}
