#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100005;
long long n, x, Max, cnt[MAXN] = {0}, mp[MAXN] = {0};
long long ans = 0;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  mp[0] = 100000;
  cin >> n;
  for (long long i = 0, ThxDem = n; i < ThxDem; i++) {
    cin >> x;
    mp[cnt[x]]--;
    cnt[x]++;
    Max = max(Max, cnt[x]);
    mp[cnt[x]]++;
    if (Max == 1) ans = i;
    if (mp[1] == 1 && mp[Max] + mp[0] == 99999) ans = i;
    if (mp[Max] == 1 && mp[Max - 1] + mp[0] == 99999) ans = i;
  }
  cout << ans + 1;
  return 0;
}
