#include <bits/stdc++.h>
using namespace std;
int n, a[100010], ans, d[100010], k, kf, ansf;
pair<int, int> par[100010];
int f(int cnt, int k) {
  int x;
  int sum = 0;
  for (int j = 1; j <= cnt; j++) {
    if (d[j] >= a[k]) {
      x = (par[j].second - k + 1) - par[j].first + 1;
      if (x > 0) {
        sum += x;
      }
    }
  }
  return sum;
}
int main(void) {
  int x, y, temp, cnt;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    x = 1;
    cnt = 1;
    for (int i = 2; i <= n; i++) {
      if (a[i] != a[i - 1]) {
        y = i - 1;
        par[cnt].first = x;
        d[cnt] = a[x];
        par[cnt].second = y;
        cnt++;
        x = i;
      }
    }
    par[cnt].first = x;
    d[cnt] = a[x];
    par[cnt].second = n;
    for (int i = n; i >= 2; i--) {
      if (a[i] > a[1]) {
        kf = k;
        k = i;
        x = n;
        temp = x - i + 1;
        ansf = ans;
        ans = max(ans, temp);
      }
    }
    ans = 0;
    for (int i = 1; i <= cnt; i++) {
      if (d[i] == a[k]) {
        for (int j = par[i].first; j <= par[i].second; j++) {
          temp = n - j + 1 - f(cnt, j);
          ans = max(ans, temp);
        }
        for (int j = par[i + 1].first; j <= par[i + 1].second; j++) {
          temp = n - j + 1 - f(cnt, j);
          ans = max(ans, temp);
        }
        break;
      }
    }
    if (ans < 0) {
      ans = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
