#include <bits/stdc++.h>
using namespace std;
const long long inf = 5e18;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
void solve() {
  long long n;
  cin >> n;
  deque<long long> q(n);
  vector<long long> ans(n);
  for (long long i = (0); i < (n); i++) cin >> q[i];
  sort(q.begin(), q.end());
  long long curr = 0;
  for (long long i = 1; i < n; i += 2) ans[i] = q[curr++];
  for (long long i = 0; i < n; i += 2) ans[i] = q[curr++];
  long long cnt = 0;
  for (long long i = (1); i < (n - 1); i++)
    cnt += (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]);
  cout << cnt << '\n';
  for (long long x : ans) cout << x << " ";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
