#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, x;
  cin >> n;
  vector<long long> a(100000, 0);
  vector<long long> b(100000, 0);
  long long ma = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
    b[a[x]]++;
    if (b[a[x]] * a[x] == i + 1) {
      if (i != n - 1) ma = i + 2;
    } else if (b[a[x]] * a[x] == i)
      ma = i + 1;
  }
  if (n == 1) {
    cout << 1 << endl;
  } else
    cout << ma << endl;
  return 0;
}
