#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  long long arr2[n];
  for (long long i = 0; i < n; i++) arr2[i] = -1;
  long long pt = 0, r = 1;
  for (long long r = 1; r < n; r += 2) arr2[r] = arr[pt++];
  for (long long i = 0; i < n; i++) {
    if (arr2[i] == -1) {
      arr2[i] = arr[pt++];
    }
  }
  long long ans = 0;
  for (long long i = 1; i < n - 1; i++) {
    if (arr2[i - 1] > arr2[i] && arr2[i + 1] > arr2[i]) ans++;
  }
  cout << ans << '\n';
  for (auto k : arr2) cout << k << " ";
  cout << '\n';
}
