#include <bits/stdc++.h>
using namespace std;
const int maxn = 1E5 + 5;
const long long inf = 1e18;
int main() {
  int n, a;
  int cnta[maxn];
  int cnt[maxn];
  int MAX = -1;
  memset(cnta, 0, sizeof cnta);
  memset(cnt, 0, sizeof cnt);
  cin >> n;
  int ans;
  bool ok = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    cnt[cnta[a]]--;
    cnta[a]++;
    cnt[cnta[a]]++;
    MAX = max(MAX, cnta[a]);
    ok = 0;
    if (cnt[1] == i)
      ok = 1;
    else if (cnt[i] == 1)
      ok = 1;
    else if (cnt[MAX] * MAX == i - 1 && cnt[1] == 1)
      ok = 1;
    else if (cnt[MAX - 1] * (MAX - 1) == i - MAX && cnt[MAX] == 1)
      ok = 1;
    if (ok) ans = i;
  }
  cout << ans << "\n";
  return 0;
}
