#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long Linf = 0x3f3f3f3f3f3f3f3f;
int arr[100005];
int n;
bool chick(int mid) {
  int idx = mid;
  while (idx < n && arr[idx] <= arr[0]) idx++;
  idx++;
  for (int i = 1; i < mid; i++) {
    while (idx < n && arr[idx] <= arr[i]) idx++;
    idx++;
  }
  while (idx < n && arr[idx] <= arr[mid - 1]) idx++;
  if (idx >= n)
    return false;
  else
    return true;
}
queue<int> xx;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int ans = 0;
  sort(arr, arr + n);
  int l = 0, r = 2 * n;
  while (r > l + 1) {
    int mid = (l + r) >> 1;
    if (chick(mid)) {
      l = mid;
    } else
      r = mid - 1;
  }
  if (chick(r))
    ans = r;
  else
    ans = l;
  cout << ans << endl;
  int idx = ans;
  while (idx < n && arr[idx] <= arr[0]) {
    xx.push(arr[idx]);
    idx++;
  }
  if (idx < n) cout << arr[idx] << ' ' << arr[0] << ' ';
  idx++;
  for (int i = 1; i < ans; i++) {
    while (idx < n && arr[idx] <= arr[i]) {
      xx.push(arr[idx]);
      idx++;
    }
    cout << arr[idx] << ' ' << arr[i] << ' ';
    idx++;
  }
  while (idx < n && arr[idx] <= arr[ans - 1]) {
    xx.push(arr[idx]);
    idx++;
  }
  for (; idx < n; idx++) cout << arr[idx] << ' ';
  while (!xx.empty()) {
    cout << xx.front() << ' ';
    xx.pop();
  }
  return 0;
}
