#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5;
int main() {
  int n;
  scanf("%d", &n);
  int a[n + 1], un = 0, freq[mx] = {0}, vis[mx] = {0}, ans = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ++vis[a[i]];
    --freq[vis[a[i]] - 1];
    ++freq[vis[a[i]]];
    if (((freq[vis[a[i]]] + min(1, freq[vis[a[i]] + 1])) * vis[a[i]]) ==
        (i - 1))
      ans = max(ans, i);
    if (i < n && (freq[vis[a[i]]] * vis[a[i]]) == i) ans = max(ans, i + 1);
  }
  printf("%d\n", ans);
  return 0;
}
