#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7;
long long n;
long long a[N];
long long b[N];
void solve() {
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long cnt = 0;
  long long cur = n / 2;
  for (long long i = 0; i < n; i += 2) {
    b[i] = a[cur++];
  }
  cur = 0;
  for (long long i = 1; i < n; i += 2) {
    b[i] = a[cur++];
    if (i + 1 < n and b[i] < b[i - 1] and b[i] < b[i + 1]) ++cnt;
  }
  cout << cnt << "\n";
  for (long long i = 0; i < n; ++i) {
    cout << b[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
