#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long inf64 = 1e18;
const int mod = inf + 7;
const int N = 1e5 + 10;
vector<int> fr(N), cnt(N);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  int mx = -1, ans = 1;
  for (int i = 1; i < n + 1; i++) {
    int x;
    cin >> x;
    cnt[fr[x]]--;
    fr[x]++;
    cnt[fr[x]]++;
    mx = max(mx, fr[x]);
    bool ok = false;
    if (cnt[i] == 1) ok = true;
    if (cnt[1] == i) ok = true;
    if (cnt[1] == 1 and cnt[mx] * mx == i - 1) ok = true;
    if (cnt[mx] == 1 and cnt[mx - 1] * (mx - 1) == i - mx) ok = true;
    if (ok) ans = i;
  }
  cout << ans;
}
