#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (const auto& x : v) os << x << " ";
  return os << "\n";
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) is >> x;
  return is;
}
ll power(ll a, ll n) {
  if (n == 0) {
    return 1;
  }
  ll sqrt_a = pow(a, n / 2);
  if (n % 2 == 1) {
    return sqrt_a * sqrt_a * a;
  } else {
    return sqrt_a * sqrt_a;
  }
}
template <typename T>
T sign(T a) {
  if (a < 0) return -1;
  if (a > 0) return 1;
  return 0;
}
template <typename T>
T log_2(T n) {
  T i = 1;
  T j = 0;
  while (i < n) {
    i *= 2;
    ++j;
  }
  return j;
}
template <typename T>
T mod(T a, T b) {
  T ans = a % b;
  return ans < 0 ? ans + b : ans;
}
ll gcd(ll a, ll b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
class Node {
 public:
  queue<pair<int, int>> q;
};
class Compare {
 public:
  bool operator()(pair<int, int>& a, pair<int, int>& b) {
    if (a.first < b.first) {
      return true;
    } else if (a.first == b.first) {
      return a.second < b.second;
    } else {
      return false;
    }
  }
};
vector<pair<int, int>> divs(int n) {
  vector<pair<int, int>> s;
  for (int i = 3; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      if (i % 2 == 1 && (n / i) % 2 == 0) {
        s.emplace_back(i, n / i);
      }
      if (i % 2 == 0 && (n / i) % 2 == 1) {
        s.emplace_back(n / i, i);
      }
    }
  }
  return s;
}
ll MOD = 1000000007;
void find(vector<ll>& count, vector<int>& first, ll n) {
  if (n <= 4) {
    return;
  }
  ll ans = count[n - 2] + 2 * count[n - 3];
  if (first[n - 2] == 0 && first[n - 3] == 0) {
    ans += 4;
    first[n - 1] = 1;
  }
  count[n - 1] = ans % MOD;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  if (n == 1) {
    cout << 0 << "\n";
    cout << a;
    return;
  }
  sort(a.begin(), a.end());
  vector<int> b(n);
  vector<int> pass(n, 0);
  int i = 0;
  int j = n / 2;
  int t = 0;
  while (j < n) {
    b[t++] = a[j++];
    if (i < n / 2) {
      b[t++] = a[i++];
    }
  }
  int count = 0;
  for (i = 1; i < n - 1; i += 2) {
    if (b[i - 1] > b[i] && b[i + 1] > b[i]) {
      ++count;
    }
  }
  cout << count << "\n";
  cout << b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
