#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n], ans[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long j = 0;
  for (long long i = 1; i < n; i += 2) {
    ans[i] = arr[j];
    j++;
  }
  for (long long i = 0; i < n; i += 2) {
    ans[i] = arr[j];
    j++;
  }
  long long count = 0;
  for (long long i = 1; i < n - 1; i += 2) {
    if (ans[i] < ans[i + 1] && ans[i] < ans[i - 1]) {
      count++;
    }
  }
  cout << count << '\n';
  for (auto x : ans) {
    cout << x << " ";
  }
}
