#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (y > x) x = y;
}
const long long int mod = 1000000007;
const long long inf = (long long int)1e18 + 17;
const int inff = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
bool test_case = 0;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n + 10];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int pre = 0;
  long long int ans[n + 10];
  for (int i = n - 1; pre < n; i--) {
    ans[pre] = a[i];
    pre += 2;
  }
  pre = (n / 2) * 2 - 1;
  for (int i = 0; pre >= 0; i++) {
    ans[pre] = a[i];
    pre -= 2;
  }
  long long int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) cnt++;
  }
  if (n % 2 == 0) {
    for (int i = 1; i < n - 1; i += 2) {
      if (!(ans[i] < ans[i - 1] && ans[i] < ans[i + 1])) {
        if (ans[n - 1] < ans[i - 1] && ans[n - 1] < ans[i + 1]) {
          swap(ans[n - 1], ans[i]);
          cnt++;
          break;
        }
      }
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  if (test_case == 1) cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
