#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> cnt(100000);
  map<int, int> cntcnt;
  int res = -1;
  for (int i = 0; i < n; ++i) {
    int u;
    cin >> u;
    --u;
    if (cnt[u] > 0) {
      int current = --cntcnt[cnt[u]];
      if (!current) {
        cntcnt.erase(cnt[u]);
      }
    }
    ++cnt[u];
    ++cntcnt[cnt[u]];
    bool good = cntcnt.size() == 1u &&
                (cntcnt.begin()->second == 1 || cntcnt.begin()->first == 1);
    if (cntcnt.size() == 2u) {
      int a = cntcnt.begin()->second;
      int b = next(cntcnt.begin())->second;
      int c = cntcnt.begin()->first;
      int d = next(cntcnt.begin())->first;
      if (b == 1 && d - c == 1) {
        good = true;
      }
      if (a == 1 && c == 1) {
        good = true;
      }
    }
    if (good) {
      res = i + 1;
    }
  }
  assert(res != -1);
  cout << res << endl;
  return 0;
}
