#include <bits/stdc++.h>
using namespace std;
const long long N = 1001;
void read() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
long long dp[N][N];
void Solve() {
  long long n, m;
  cin >> n;
  vector<long long> v(n);
  for (auto &i : v) cin >> i;
  sort(v.rbegin(), v.rend());
  vector<long long> big, smal, res;
  long long ok = (n % 2);
  for (int i = 0; i < n / 2 + ok; ++i) {
    big.push_back(v[i]);
  }
  for (int i = n / 2 + ok; i <= n; ++i) {
    smal.push_back(v[i]);
  }
  long long l = 0, r = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      if (r >= big.size()) continue;
      res.push_back(big[r]);
      r++;
    } else {
      if (l >= smal.size()) continue;
      res.push_back(smal[l]);
      l++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < res.size(); ++i) {
    if (!i || i == res.size() - 1) continue;
    if (res[i] < res[i - 1] && res[i] < res[i + 1]) ans++;
  }
  cout << ans << '\n';
  for (auto i : res) cout << i << ' ';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    Solve();
    cout << '\n';
  }
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
