#include <bits/stdc++.h>
using namespace std;
int n, a[100001], b[100001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (register int i = (1); i < (n + 1); ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int p = 1, ans = 0;
  for (int i = 2; i <= n; i += 2) b[i] = a[p++];
  for (int i = 1; i <= n; i += 2) b[i] = a[p++];
  for (register int i = (2); i < (n); ++i) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) ans++;
  }
  cout << ans << endl;
  for (register int i = (1); i < (n + 1); ++i) cout << b[i] << ' ';
  cout << endl;
  return 0;
}
