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