#include <bits/stdc++.h>
using namespace std;
long long const MOD = 998244353;
void yes() { cout << "YES" << '\n'; }
void no() { cout << "NO" << '\n'; }
long long fact(int n) {
  long long ans = 1;
  for (int i = 2; i <= n; i++) {
    ans = (ans * i) % MOD;
  }
  return ans;
}
long long powM(int n, int x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return n % MOD;
  }
  if (x % 2 == 0) {
    long long a = powM(n, x / 2);
    return (a * a) % MOD;
  } else {
    return (n * powM(n, x - 1)) % MOD;
  }
}
long long C(int n, int k) {
  return (fact(n) * powM((fact(k) * fact(n - k)) % MOD, MOD - 2)) % MOD;
}
long long A(int n, int k) {
  return (fact(n) * powM(fact(n - k) % MOD, MOD - 2)) % MOD;
}
void add_self(int &a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
}
void sub_self(int &a, int b) {
  a -= b;
  if (a < 0) {
    a += MOD;
  }
}
struct segtree {
  vector<long long> tree;
  int size;
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    tree.assign(2 * size - 1, 0);
  }
  void build(vector<int> &a, int x, int lx, int rx) {
    if (rx - lx == 1) {
      if (lx < a.size()) tree[x] = a[lx];
    } else {
      int m = (lx + rx) / 2;
      build(a, 2 * x + 1, lx, m);
      build(a, 2 * x + 2, m, rx);
      tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
    }
  }
  void build(vector<int> &a) {
    init(a.size());
    build(a, 0, 0, size);
  }
  void set(int i, int v, int x, int lx, int rx) {
    if (rx - lx == 1) {
      tree[x] = v;
      return;
    }
    int m = (lx + rx) / 2;
    if (i < m) {
      set(i, v, 2 * x + 1, lx, m);
    } else {
      set(i, v, 2 * x + 2, m, rx);
    }
    tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
  }
  void set(int i, int v) { set(i, v, 0, 0, size); }
  long long sum(int l, int r, int x, int lx, int rx) {
    if (l >= rx || lx >= r) {
      return 0;
    }
    if (lx >= l && rx <= r) {
      return tree[x];
    }
    int m = (rx + lx) / 2;
    long long s1 = sum(l, r, 2 * x + 1, lx, m);
    long long s2 = sum(l, r, 2 * x + 2, m, rx);
    return s1 + s2;
  }
  long long sum(int l, int r) { return sum(l, r, 0, 0, size); }
};
void solve() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort((a).rbegin(), (a).rend());
  int l = 0;
  int r = n - 1;
  vector<long long> ans(n);
  for (int i = 0; i < n; i += 2) {
    ans[i] = a[l++];
  }
  if (n % 2 == 0) {
    for (int i = n - 1; i >= 0; i -= 2) {
      ans[i] = a[l++];
    }
  } else {
    for (int i = n - 2; i >= 0; i -= 2) {
      ans[i] = a[l++];
    }
  }
  int ans1 = 0;
  for (int i = 1; i < n - 1; i++) {
    if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) {
      ans1++;
    }
  }
  vector<long long> ans2(n);
  l = 0;
  for (int i = 0; i < n; i += 2) {
    ans2[i] = a[l++];
  }
  for (int i = 1; i < n; i += 2) {
    ans2[i] = a[l++];
  }
  int ans22 = 0;
  for (int i = 1; i < n - 1; i++) {
    if (ans2[i] < ans2[i - 1] && ans2[i] < ans2[i + 1]) {
      ans22++;
    }
  }
  if (ans1 > ans22) {
    cout << ans1 << '\n';
    for (auto x : ans) {
      cout << x << ' ';
    }
    cout << '\n';
  } else {
    cout << ans22 << '\n';
    for (auto x : ans2) {
      cout << x << ' ';
    }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
