#include <bits/stdc++.h>
#pragma GCC optimize("O2")
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int n, u[MAXN];
int occ[MAXN];
multiset<int> se;
bool check() {
  if (se.size() == 1) return 1;
  int c = *se.begin() - 1;
  int cc = *se.rbegin();
  if (c == 0 && *next(se.begin()) == cc) return 1;
  c = *se.begin();
  cc = *se.rbegin() - 1;
  auto tt = prev(se.end());
  tt--;
  if (c == cc && *tt == cc) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> u[i];
  int ans = 1;
  se.insert(1);
  occ[u[0]] = 1;
  for (int i = 1; i < n; i++) {
    occ[u[i]]++;
    if (occ[u[i]] != 1) se.erase(se.find(occ[u[i]] - 1));
    se.insert(occ[u[i]]);
    if (check()) ans = i + 1;
  }
  cout << ans;
  return 0;
}
