#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  bool operator<(const P &a) const {
    if (y != a.y) return y < a.y;
    return x < a.x;
  };
};
int a, b, c, d, i, n, m, e, k, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
int o[114441];
int l[111111];
long long ss[1];
long long x, y, z, mod = 1000000007, hf = (mod + 1) / 2;
char r[1];
vector<int> v[1];
P u[1];
queue<P> q;
set<int> s;
map<int, int> p;
bool as(P a, P b) { return a.x < b.x; }
void f(int n) {
  memset(l, 0, sizeof(l));
  for (int t = 2, w = n; w; w--, t += 2) l[t] = o[w];
  for (int t = 1, w = a; t <= a; t++)
    if (l[t] == 0) {
      l[t] = o[w];
      w--;
    }
}
int g() {
  int k = 0;
  for (int t = 2; t < a; t += 2) {
    if (l[t - 1] > l[t] && l[t] < l[t + 1]) k++;
  }
  return k;
}
int main() {
  scanf("%d", &a);
  for (int t = 1; t <= a; t++) {
    scanf("%d", &o[t]);
  }
  sort(o + 1, o + a + 1);
  n = 0, m = a / 2;
  for (; n < m;) {
    int h = (n + m) / 2 + 1;
    f(h);
    if (h == g())
      n = h;
    else
      m = h - 1;
  }
  f(n);
  printf("%d\n", g());
  for (int t = 1; t <= a; t++) printf("%d ", l[t]);
}
