#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a.begin() + 1, a.end());
  for (int i = 1; i <= n / 2; i++) b[2 * i] = a[i];
  for (int i = n / 2 + 1; i <= n; i++) b[(i - n / 2) * 2 - 1] = a[i];
  int ans = 0;
  for (int i = 2; i < n; i++) ans += (b[i] < b[i - 1]) * (b[i] < b[i + 1]);
  cout << ans << endl;
  for (auto i = b.begin() + 1; i != b.end(); i++) cout << *i << " ";
  cout << endl;
}
