#include <bits/stdc++.h>
using namespace std;
const long long int mxn = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    long long int i, j, k, n, m;
    cin >> n;
    vector<long long int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<long long int> ans(n);
    for (i = 0, j = 1; j < n; i++, j += 2) ans[j] = a[i];
    for (j = 0; j < n; j += 2, i++) ans[j] = a[i];
    long long int c = 0;
    for (i = 1; i < n - 1; i++)
      if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) c++;
    cout << c << "\n";
    for (i = 0; i < n; i++) cout << ans[i] << " ";
  }
  return 0;
}
