#include <bits/stdc++.h>
using namespace std;
int dr[8] = {0, 0, -1, 1, -1, -1, +1, +1};
int dc[8] = {-1, 1, 0, 0, -1, +1, -1, +1};
const int N = 5005;
long long modPow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int main() {
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int x;
    vector<int> vec;
    for (int i = 1; i <= n; ++i) {
      cin >> x;
      vec.push_back(x);
    }
    sort(vec.rbegin(), vec.rend());
    int a[n + 1];
    memset(a, -1, sizeof a);
    x = (n + 1) / 2;
    int cnt = 1;
    for (int i = 1; i <= x; ++i) {
      a[cnt] = vec[i - 1];
      cnt += 2;
    }
    cnt = 2;
    vector<int> vv;
    for (int i = x + 1; i <= n; ++i) {
      if (vec[i - 1] < a[cnt - 1] && vec[i - 1] < a[cnt + 1]) {
        a[cnt] = vec[i - 1];
        cnt += 2;
      } else {
        vv.push_back(vec[i - 1]);
      }
    }
    for (int i = 1; i <= n; ++i) {
      if (a[i] == -1) {
        a[i] = vv.back();
        vv.pop_back();
      }
    }
    cnt = 0;
    for (int i = 2; i <= n - 1; ++i) {
      if (a[i] < a[i + 1] && a[i] < a[i - 1]) cnt++;
    }
    cout << cnt << endl;
    for (int i = 1; i <= n; ++i) cout << a[i] << ' ';
    cout << endl;
  }
}
