#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<int> A(n);
  for (long long int i = 0; i < n; i++) {
    cin >> A[i];
  }
  map<int, int> mp;
  long long int count = 0, ma = 0;
  long long int x = 1;
  for (long long int i = 0; i < n; i++) {
    mp[A[i]]++;
    if (mp[A[i]] > ma) {
      ma = mp[A[i]];
      count = 1;
    } else if (mp[A[i]] == ma) {
      count++;
    }
    if ((count * (ma) + 1 == i + 1) ||
        (((ma - 1) * (mp.size()) + 1 == i + 1) && (count == 1)) || (ma == 1)) {
      x = i + 1;
    }
  }
  cout << x;
  return 0;
}
