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