#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  long long arr[100005];
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  vector<long long> res;
  for (int i = n / 2; i < n; i++) {
    res.push_back(arr[i]);
    if (i - (n / 2) < (n / 2)) res.push_back(arr[i - (n / 2)]);
  }
  long cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (res[i] < res[i - 1] && res[i] < res[i + 1]) cnt++;
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
  cout << endl;
  return 0;
}
