#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int f[N], cnt[N];
int main() {
  int n;
  cin >> n;
  int tmp;
  int ans = 0;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tmp);
    cnt[f[tmp]]--;
    f[tmp]++;
    cnt[f[tmp]]++;
    mx = max(mx, f[tmp]);
    bool ok = false;
    if (i == 1 && cnt[1] == 1)
      ok = true;
    else if (cnt[1] == i)
      ok = true;
    else if (cnt[1] == 1 && cnt[mx] * mx == i - 1)
      ok = true;
    else if (cnt[mx] == 1 && cnt[mx - 1] * (mx - 1) == i - mx)
      ok = true;
    if (ok) ans = i;
  }
  cout << ans << endl;
  return 0;
}
