#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const double PI = atan(1.0) * 4;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};
const long long INF = (long long)2e18 + 50;
const int maximum = numeric_limits<int>::max();
const int minimum = numeric_limits<int>::min();
const int N = 2e5 + 50;
const int P = 998244353;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    int ans = 0;
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<int> res(n);
    int j = 0;
    for (int i = 1; i < n; i += 2) {
      res[i] = a[j++];
    }
    for (int i = 0; i < n; i += 2) {
      res[i] = a[j++];
    }
    for (int i = 1; i < n - 1; i++) {
      if (res[i] < res[i - 1] && res[i] < res[i + 1]) ans++;
    }
    cout << ans << "\n";
    for (int i = 0; i < n; i++) {
      cout << res[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
