#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, x, mx, ans;
int a[N];
int b[N];
int c[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    b[c[x]]--;
    c[x]++;
    b[c[x]]++;
    mx = max(mx, c[x]);
    if (b[1] == i || b[i] == 1) ans = i;
    if (b[1] == 1 && mx * b[mx] == i - 1) ans = i;
    if (mx != 1 && (i - mx) % (mx - 1) == 0 && b[mx] == 1) {
      if (((i - mx) / (mx - 1)) == b[mx - 1]) ans = i;
    }
  }
  cout << ans << ' ';
}
