#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, i, j, n, x, l, r, k;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n, greater<long long int>());
  vector<long long int> v;
  k = n / 2;
  if (n % 2 == 0) k--;
  l = 0;
  r = n - k;
  x = r;
  while (r < n) {
    v.push_back(a[l]);
    v.push_back(a[r]);
    l++;
    r++;
  }
  while (l < x) {
    v.push_back(a[l]);
    l++;
  }
  x = 0;
  for (i = 1; i < n - 1; i++)
    if (v[i] < v[i - 1] && v[i] < v[i + 1]) x++;
  cout << x << "\n";
  for (i = 0; i < n; i++) cout << v[i] << " ";
  return 0;
}
