#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int a;
  cin >> a;
  vector<int> v(a);
  for (auto &it : v) cin >> it;
  sort(v.begin(), v.end());
  long long int p = 0;
  vector<int> an(a);
  for (long long int i = 1; i < a; i += 2) an[i] = v[p++];
  for (long long int i = 0; i < a; i += 2) an[i] = v[p++];
  long long int cnt = 0;
  for (long long int i = 1; i <= a - 2; i++) {
    if (an[i] < min(an[i - 1], an[i + 1])) cnt++;
  }
  cout << cnt << endl;
  for (auto it : an) cout << it << ' ';
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
