#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (auto &i : a) cin >> i;
  sort(a.begin(), a.end());
  int ind = 0;
  for (int i = 1; i < n; i += 2) b[i] = a[ind++];
  for (int i = 0; i < n; i += 2) b[i] = a[ind++];
  int ans = 0;
  for (int i = 1; i < n - 1; i += 2)
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) ans++;
  cout << ans << "\n";
  for (auto &i : b) cout << i << " ";
  cout << "\n";
}
