#include <bits/stdc++.h>
using namespace std;
long long a, n, ymax, i, flag, x, y[100001] = {0}, z[100001] = {0};
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    flag = 0;
    cin >> a;
    z[y[a]]--;
    y[a]++;
    z[y[a]]++;
    ymax = max(ymax, y[a]);
    if (z[1] == i) flag = 1;
    if (z[i] == 1) flag = 1;
    if (z[1] == 1 && z[ymax] * ymax == i - 1) flag = 1;
    if (z[ymax - 1] * (ymax - 1) == i - ymax && z[ymax] == 1) flag = 1;
    if (flag) x = i;
  }
  cout << x << endl;
  return 0;
}
