#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 3;
int n;
int a[maxn];
int result[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    memset(result, 0, sizeof(result));
    int temp1 = 1, temp2 = n;
    sort(a + 1, a + 1 + n);
    for (int i = 2; i <= n; i += 2) {
      result[i] = a[temp1++];
    }
    for (int i = n; i >= 1; i--) {
      if (!result[i]) {
        result[i] = a[temp2--];
      }
    }
    int ans = 0;
    for (int i = 2; i <= n - 1; i++) {
      if (result[i] < result[i - 1] && result[i] < result[i - 1]) {
        ans++;
      }
    }
    cout << ans << endl;
    for (int i = 1; i <= n; i++) {
      cout << result[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
