#include <bits/stdc++.h>
using namespace std;
map<int, double> code;
map<int, int> m1, m2, m3;
int main() {
  int i, j, k, l, p, q, r, s, t, n;
  cin >> n;
  if (n == 1) {
    cin >> p;
    cout << "1";
    return 0;
  }
  for (i = 1; i <= n; i++) {
    cin >> p;
    m1[p]++;
    m2[m1[p]]++;
    if (m1[p] * m2[m1[p]] == i && i != n) {
      t = i + 1;
    }
    if (m1[p] * m2[m1[p]] == i - 1) {
      t = i;
    }
  }
  cout << t << '\n';
}
