#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5 + 5);
int Max, Min[N], a[N], p, b[N], cnt;
int main() {
  int n, i, j, t;
  cin >> n;
  Min[0] = n;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    t = a[i];
    if (!b[t]) cnt++;
    Min[b[t]]--, Min[b[t] + 1]++, b[t]++;
    Max = max(Max, b[t]);
    if (Min[1] && Max * (cnt - 1) == i)
      p = i + 1;
    else if ((Min[Max - 1] + 1) * (Max - 1) == i)
      p = i + 1;
  }
  cout << p << endl;
}
