#include <bits/stdc++.h>
using namespace std;
long long pow(int a, int n) {
  if (n == 1)
    return a;
  else
    return a * pow(a, n - 1);
}
int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ma;
  sort(a, a + n);
  long long b[n];
  long long k = 0;
  for (long long i = 1; i < n; i += 2) b[i] = a[k++];
  for (long long i = 0; i < n; i += 2) b[i] = a[k++];
  long long count = 0;
  for (long long i = 1; i < n - 1; i++) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) count++;
  }
  cout << count << "\n";
  for (long long i = 0; i < n; i++) cout << b[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  solve();
}
