#include <bits/stdc++.h>
using namespace std;
int a[int(1100000)], s[int(1100000)];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int len = 0;
  for (int i = 1; i < n; i += 2) s[i] = a[len++];
  for (int i = 0; i < n; i += 2) s[i] = a[len++];
  int res = 0;
  for (int i = 1; i < n - 1; i++)
    if (s[i] < s[i - 1] && s[i] < s[i + 1]) res++;
  cout << res << '\n';
  for (int i = 0; i < n; i++) cout << s[i] << " ";
  cout << '\n';
  return 0;
}
