#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  vector<long long> ans(n);
  sort(v.begin(), v.end());
  long long idx = 0;
  for (long long i = 1; i < n; i += 2) {
    ans[i] = v[idx++];
  }
  for (long long i = 0; i < n; i += 2) {
    ans[i] = v[idx++];
  }
  long long x = 0;
  for (long long i = 1; i < n - 1; i++) {
    if (ans[i] < ans[i - 1] and ans[i] < ans[i + 1]) x++;
  }
  cout << x << "\n";
  for (auto i : ans) {
    cout << i << " ";
  }
  return 0;
}
