#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
void solve() {
  long long n;
  cin >> n;
  std::vector<long long> v(n), ans(n);
  queue<long long> q;
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  if (n == 2) {
    cout << 0 << endl;
    cout << v[0] << " " << v[1] << endl;
    return;
  }
  sort(v.begin(), v.end());
  long long k = (n - 1) / 2;
  if (n % 2 == 0) k = n / 2;
  for (long long i = 0; i < k; i++) q.push(v[i]);
  for (long long i = 1; i < n; i += 2) {
    ans[i] = q.front();
    q.pop();
  }
  for (long long i = k; i < n; i++) q.push(v[i]);
  for (long long i = 0; i < n; i += 2) {
    ans[i] = q.front();
    q.pop();
  }
  long long f = 0;
  for (long long i = 1; i < n - 1; i += 2) {
    if (ans[i] < ans[i - 1] and ans[i] < ans[i + 1]) f++;
  }
  cout << f << endl;
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
