#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (long long i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    vector<long long> a, b;
    for (long long i = 0; i < n; ++i) {
      if (i < n / 2) {
        a.push_back(v[i]);
        continue;
      } else
        b.push_back(v[i]);
    }
    long long cnt = 0;
    vector<long long> ans;
    for (long long i = 0; i < n; ++i) {
      if (cnt == n) break;
      if (i & 1) {
        ans.push_back(a.front());
        a.erase(a.begin());
      } else {
        ans.push_back(b.front());
        b.erase(b.begin());
      }
      cnt++;
    }
    cnt = 0;
    for (long long i = 1; i < n - 1; ++i) {
      if (ans[i] < ans[i - 1] and ans[i] < ans[i + 1]) cnt++;
    }
    cout << cnt << "\n";
    for (long long i = 0; i < ans.size(); ++i) cout << ans[i] << ' ';
    cout << "\n";
  }
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  solve();
  return 0;
}
