#include <bits/stdc++.h>
using namespace std;
long long ara[100005], ans[100005];
int main() {
  long long n, i, ind = 1, ans1 = 0;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> ara[i];
  sort(ara + 1, ara + n + 1);
  for (i = 2; i <= n; i += 2) {
    ans[i] = ara[ind];
    ind++;
  }
  for (i = 1; i <= n; i += 2) {
    ans[i] = ara[ind];
    ind++;
  }
  for (i = 2; i <= n - 1; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) {
      ans1++;
    }
  }
  cout << ans1 << endl;
  for (i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
}
