#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int a[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m1 = 0, m2 = 0, mx = 0, ans = 1, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
    if (a[x] == 1) {
      if (m1 * mx == i - 1) {
        ans = i;
      }
    }
    if (a[x] == mx - 1) {
      m2++;
      if (a[x] * m2 + mx == i) {
        ans = i;
      }
    } else if (a[x] == mx) {
      m2--;
      m1++;
      if (m1 * mx == i - 1) {
        ans = i;
      }
    } else if (a[x] > mx) {
      mx = a[x];
      m2 = --m1;
      m1 = 1;
      if ((mx - 1) * m2 + mx == i) {
        ans = i;
      }
    }
  }
  cout << ans;
  return 0;
}
