#include <bits/stdc++.h>
using namespace std;
int ans, n, a1, ma1, siz, ma2, t1, id1, id2, sum, s[100005], a[100005];
int gets() {
  int v = 0;
  bool f = 0;
  char ch;
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    v = (v << 3) + (v << 1) + ch - 48;
    ch = getchar();
  }
  return f ? -v : v;
}
int main() {
  n = gets();
  ans = 1;
  for (int i = 1; i <= n; i++) a[i] = gets();
  for (int i = 1; i <= n; i++) {
    s[a[i]]++;
    sum += s[a[i]] == 1;
    siz += s[a[i]] == 1, siz -= s[a[i]] == 2;
    if (s[a[i]] > ma1) {
      if (id1 == a[i])
        ma1 = s[a[i]];
      else
        ma2 = ma1, id2 = id1, ma1 = s[a[i]], id1 = a[i];
    } else {
      if (s[a[i]] > ma2) {
        if (id2 == a[i])
          ma2 = s[a[i]];
        else
          ma2 = s[a[i]], id2 = a[i];
      }
    }
    if (i == 1) continue;
    if (ma1 == 1) {
      ans = i;
      continue;
    }
    if (siz == 1) {
      if ((i - 1) % (sum - 1) == 0) {
        t1 = (i - 1) / (sum - 1);
        if (t1 == ma1) ans = i;
      }
    }
    if (sum == 1) ans = i;
    if ((i - 1) % sum == 0) {
      t1 = (i - 1) / sum;
      if (t1 == ma1 - 1 && t1 == ma2) ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
