#include <bits/stdc++.h>
using namespace std;
int b, r, n, i, f;
pair<int, int> A, B, C;
map<int, int> a;
int main() {
  for (cin >> n; i < n; i++) {
    A.first = A.second = B.first = B.second = f = 0;
    cin >> b;
    a[b]++;
    for (auto& x : a) {
      if (!A.first)
        A.first = x.second, A.second++;
      else if (A.first == x.second)
        A.second++;
      else if (!B.first)
        B.first = x.second, B.second++;
      else if (B.first == x.second)
        B.second++;
      else {
        f = 1;
        break;
      }
      if ((A.second > 1 && B.second > 1)) {
        f = 1;
        break;
      }
    }
    if (!f) {
      if (A.second > 1 && B.first > 0) {
        C = A;
        A = B;
        B = C;
      }
      if (B.first + 1 == A.first || A.first == 1 ||
          (B.first == 0 && A.second == 1))
        r = i;
    }
  }
  cout << r + 1;
}
