#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
void wenjian() {
  freopen("concatenation.in", "r", stdin);
  freopen("concatenation.out", "w", stdout);
}
void tempwj() {
  freopen("hash.in", "r", stdin);
  freopen("hash.out", "w", stdout);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long mod) {
  a %= mod;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
struct chongzai {
  int c;
  bool operator<(const chongzai &b) const { return c > b.c; }
} sss;
const int maxn = 5e5 + 177;
const long long mod = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int a[maxn], b[maxn];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  if (n <= 2) {
    printf("0\n");
    for (int i = 1; i <= n; i++) {
      printf("%d ", a[i]);
    }
    return 0;
  }
  int index = 1;
  for (int i = 2; i <= n; i = i + 2) {
    b[i] = a[index];
    index++;
  }
  for (int i = 1; i <= n; i = i + 2) {
    b[i] = a[index];
    index++;
  }
  int now = 0;
  for (int i = 2; i < n; i++) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) {
      now++;
    }
  }
  printf("%d\n", now);
  for (int i = 1; i <= n; i++) {
    printf("%d ", b[i]);
  }
  printf("\n");
}
