#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  fast();
  long long int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    long long arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n, greater<int>());
    int a = ceil((float)n / 2);
    int b = n - a;
    int answer = 0;
    int curr = a;
    vector<long long> arr2;
    vector<long long> arr3;
    for (int i = 1; i < a; i++) {
      for (int j = curr; j < n; j++) {
        if (arr[j] < arr[i]) {
          curr = j + 1;
          answer++;
          arr2.push_back(arr[j]);
          break;
        } else
          arr3.push_back(arr[j]);
      }
    }
    cout << answer << endl;
    for (int i = 0; i < arr3.size(); i++) arr2.push_back(arr3[i]);
    if (arr2.size() != b) {
      for (int i = 0; i < (b - arr2.size()); i++)
        arr2.push_back(arr[n - 1 - i]);
    }
    for (int i = 0; i < n; i++) {
      if (i % 2)
        cout << arr2[i / 2] << " ";
      else
        cout << arr[i / 2] << " ";
    }
  }
}
