#include <bits/stdc++.h>
using namespace std;
void sublime() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  sublime();
  long long n, i, j;
  cin >> n;
  long long arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  if (n <= 2) {
    cout << 0 << '\n';
    for (i = 0; i < n; i++) cout << arr[i] << " ";
    cout << '\n';
    return 0;
  } else {
    sort(arr, arr + n);
    vector<long long> v;
    i = 0, j = (n - 1) / 2;
    if (n & 1) {
      while (i < (n - 1) / 2 || j < n) {
        v.push_back(arr[j]);
        j++;
        if (i < (n - 1) / 2) {
          v.push_back(arr[i]);
          i++;
        }
      }
    } else {
      j = n / 2;
      while (i < (n - 1) / 2 || j < n) {
        v.push_back(arr[j]);
        j++;
        if (i < (n - 1) / 2) {
          v.push_back(arr[i]);
          i++;
        }
      }
      v.push_back(arr[(n - 1) / 2]);
    }
    long long ans = 0;
    for (i = 1; i < v.size() - 1; i += 2) {
      if (v[i] < v[i + 1] && v[i] < v[i - 1]) ans++;
    }
    cout << ans << '\n';
    for (auto x : v) cout << x << " ";
    cout << '\n';
  }
  return 0;
}
