#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int ans = 0;
  long long int count[100005] = {0};
  multiset<long long int> s;
  for (int i = 0; i < n; i++) {
    if (count[a[i]] >= 1) s.erase(s.find(count[a[i]]));
    count[a[i]]++;
    s.insert(count[a[i]]);
    long long int first = *(s.begin());
    long long int last = *(s.rbegin());
    s.erase(s.find(first));
    if (first > 1) s.insert(first - 1);
    if (!s.size() || *(s.begin()) == *(s.rbegin())) ans = i + 1;
    if (first > 1) s.erase(s.find(first - 1));
    s.insert(first);
    s.erase(s.find(last));
    if (last > 1) s.insert(last - 1);
    if (!s.size() || *(s.begin()) == *(s.rbegin())) ans = i + 1;
    if (last > 1) s.erase(s.find(last - 1));
    s.insert(last);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
