#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int vis[N];
vector<vector<int>> v;
int dfs(int x) {
  vis[x] = true;
  for (auto i : v[x]) {
    if (not vis[i]) {
      dfs(i);
    }
  }
}
int a[100010];
vector<int> l;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> (a)[i];
  ;
  sort(a, a + n);
  int x = 0, y = n / 2;
  for (int i = 0; i < y; ++i) {
    l.emplace_back(a[i]);
  }
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0)
      ans.emplace_back(a[y++]);
    else
      ans.emplace_back(l[x++]);
  }
  int cnt = 0;
  for (int i = 1; i < n - 1; ++i) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) ++cnt;
  }
  cout << cnt << endl;
  for (int i = 0; i < n; ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
