#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, i, j, k, best = 0;
  cin >> n;
  vector<int> ct(100010, 0);
  set<pair<int, int>> s;
  set<pair<int, int>>::reverse_iterator it;
  set<pair<int, int>>::iterator itt;
  for (i = 0; i < n; i++) {
    cin >> x;
    s.erase({ct[x], x});
    ct[x]++;
    s.insert({ct[x], x});
    bool valid = false;
    if (s.size() == 1) valid = true;
    if (s.rbegin()->first == 1) valid = true;
    if ((s.size() == 2) && (s.rbegin()->first - 1 == s.begin()->first))
      valid = true;
    if ((s.size() == 2) && (s.begin()->first == 1)) valid = true;
    if ((s.size() > 2) && (s.rbegin()->first - 1 == s.begin()->first)) {
      it = s.rbegin();
      it++;
      if (s.rbegin()->first - 1 == it->first) valid = true;
    }
    if ((s.size() > 2) && (s.begin()->first == 1)) {
      itt = s.begin();
      itt++;
      if (itt->first == s.rbegin()->first) valid = true;
    }
    if (valid) {
      best = i + 1;
    }
  }
  cout << best << "\n";
  return 0;
}
