#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int dtx[] = {0, 0, -1, 1, 1, -1, 1, -1};
const int dty[] = {-1, 1, 0, 0, 1, -1, -1, 1};
const int dtxc[] = {1, 1, 2, 2, -1, -1, -2, -2};
const int dtyc[] = {2, -2, 1, -1, 2, -2, 1, -1};
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n, x;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  queue<int> s;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    v.emplace_back(x);
  }
  sort((v).begin(), (v).end());
  for (int &x : v) {
    s.push(x);
  }
  vector<int> ans(n, -1);
  for (int i = 1; i < n; i += 2) {
    ans[i] = s.front();
    s.pop();
  }
  for (int i = 0; i < n; ++i) {
    if (ans[i] == -1) {
      ans[i] = s.front();
      s.pop();
    }
  }
  int answer = 0;
  for (int i = 1; i < n - 1; ++i) {
    answer += (ans[i - 1] > ans[i] and ans[i] < ans[i + 1]);
  }
  cout << answer << '\n';
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " \n"[i == n - 1];
  }
  return 0;
}
