#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) cout << ' ';
    cout << v[i];
  }
  return out;
}
int movei[] = {0, 0, 1, -1, 1, 1, -1, -1};
int movej[] = {1, -1, 0, 0, 1, -1, 1, -1};
const double PI = acos(-1.0);
const int MXN = 1e5 + 7;
int v[MXN];
int n;
bool ok(const int &mid) {
  int j = mid;
  for (int i = 0; i < mid; i++) {
    if (j >= n) return false;
    while (v[j] == v[i]) {
      j++;
      if (j >= n) return false;
    }
    j++;
  }
  if (j >= n) return false;
  while (v[j] == v[mid - 1]) {
    j++;
    if (j >= n) return false;
  }
  return true;
}
void build(const int &mid) {
  vector<bool> vis(n, false);
  int j = mid;
  for (int i = 0; i < mid; i++) {
    while (v[j] == v[i]) j++;
    cout << v[j] << ' ' << v[i] << ' ';
    vis[i] = vis[j] = true;
    j++;
  }
  while (v[j] == v[mid - 1]) j++;
  cout << v[j] << ' ';
  vis[j] = true;
  for (int i = 0; i < n; i++)
    if (!vis[i]) cout << v[i] << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v, v + n);
  int l = 0, r = n / 2, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ok(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << '\n';
  build(ans);
}
