#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int N = 1e5 + 4;
int f[N];
int a[N];
multiset<int> s;
void solve() {
  int n;
  cin >> n;
  int ans = 1;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (f[x] == 0) {
      s.insert(1);
    } else {
      s.erase(s.find(f[x]));
      s.insert(f[x] + 1);
    }
    ++f[x];
    int valid = 0;
    if ((int)s.size() == 1)
      valid = 1;
    else if (*s.begin() == 1 and *s.rbegin() == 1)
      valid = 1;
    else if (*s.begin() + 1 == *s.rbegin() and s.count(*s.rbegin()) == 1) {
      valid = 1;
    } else if (*s.begin() == 1 and s.count(1) == 1 and
               s.count(*s.rbegin()) == (int)s.size() - 1)
      valid = 1;
    if (valid) ans = i + 1;
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
