#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6 + 10;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v.push_back(x);
  };
  sort(v.begin(), v.end());
  long long int k = 0;
  vector<long long int> ans(n);
  for (long long int i = 1; i < n; i += 2) ans[i] = v[k++];
  for (long long int i = 0; i < n; i += 2) ans[i] = v[k++];
  long long int cnt = 0;
  for (int i = 1; i < n - 1; i++)
    cnt += ans[i] < ans[i - 1] && ans[i] < ans[i + 1];
  cout << cnt;
  cout << endl;
  ;
  for (long long int i = 0; i < n; i++) cout << ans[i] << ' ';
  cout << endl;
  ;
}
