#include <bits/stdc++.h>
using namespace std;
template <typename arg>
void debugger(const char* varname, arg&& var) {
  cout << varname << " = " << var << endl;
}
template <typename arg, typename... args>
void debugger(const char* varnames, arg&& var, args&&... vars) {
  const char* comma = strchr(varnames + 1, ',');
  cout.write(varnames, comma - varnames) << " = " << var << " | ";
  int sz = 1;
  if (isspace(comma[sz])) sz++;
  debugger(comma + sz, vars...);
}
using ll = long long;
extern const int INF = INT_MAX - 10;
extern const ll LINF = LLONG_MAX - 10;
extern const int MOD = 1e9 + 7;
extern const int N = 2e5 + 10;
int n;
ll a[N];
ll ans[N];
multiset<int> st;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a + i);
    st.emplace(a[i]);
  }
  int start = 0;
  for (int i = 1; i < n - 1; i += 2) {
    ans[i] = *st.begin();
    st.erase(st.begin());
    start++;
  }
  bool cont = false;
  for (int i = 0; i < n; i += 2) {
    start++;
    if (cont) {
      ans[i] = *st.begin();
      st.erase(st.begin());
      continue;
    }
    int m1 = 0, m2 = 0;
    if (i - 1 >= 0) m1 = ans[i - 1];
    if (i + 1 < n) m2 = ans[i + 1];
    int mx = max(m1, m2);
    auto it = st.upper_bound(mx);
    if (it == st.end()) {
      cont = true;
      ans[i] = *st.begin();
      st.erase(st.begin());
      continue;
    }
    ans[i] = *it;
    st.erase(it);
  }
  if (start == n - 1) ans[n - 1] = *st.begin();
  int res = 0;
  for (int i = 1; i < n - 1; i += 2) {
    if (ans[i] < ans[i - 1] and ans[i] < ans[i + 1]) {
      res++;
    }
  }
  cout << res << '\n';
  for (int i = 0; i < n; ++i) {
    printf("%lld%c", ans[i], i == n - 1 ? '\n' : ' ');
  }
  return 0;
}
