#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 10e5;
int main() {
  int n, ans, mx, mn, c_mx, c_mn, k, clr, cmx;
  int freq[N + 1];
  mx = 0;
  cmx = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> clr;
    freq[clr] += 1;
    if (freq[clr] >= 1 && freq[clr] > mx) {
      mx = freq[clr];
    }
    cmx = max(cmx, clr);
    k = 0;
    c_mx = 0;
    c_mn = 0;
    mn = 10e5;
    for (int j = 1; j <= cmx; j++) {
      if (freq[j]) {
        mn = min(mn, freq[j]);
      }
    }
    for (int j = 1; j <= cmx; j++) {
      if (freq[j]) {
        k++;
      }
      if (freq[j] == mx) {
        c_mx++;
      }
      if (freq[j] == mn) {
        c_mn++;
      }
    }
    if (mx == 1) {
      ans = i;
    } else if (mx - mn == 1 && c_mx == 1 && c_mn == k - 1) {
      ans = i;
    } else if (mn == 1 && c_mn == 1 && c_mx == k - 1) {
      ans = i;
    } else if (c_mx == c_mn && mx == mn && k == 1) {
      ans = i;
    }
  }
  cout << ans;
  return 0;
}
