#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int a[MAX], b[MAX];
int main() {
  int N, ans, x, maxx = -0x3f3f3f3f;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &x);
    a[x]++;
    maxx = max(a[x], maxx);
    b[a[x]]++;
    b[a[x] - 1]--;
    if (maxx * b[maxx] + (maxx - 1) * b[maxx - 1] == i) {
      if (b[maxx] == 1) ans = i;
      if (maxx == 1) ans = i;
    }
    if (maxx * b[maxx] + b[1] == i) {
      if (b[1] == 1) ans = i;
    }
  }
  printf("%d\n", min(ans, N));
  return 0;
}
