#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
int main() {
  ll n;
  cin >> n;
  vl counter(100010);
  ll maxVal = 0;
  ll maxCount = 0;
  ll secondMaxCount = 0;
  ll totalCount = 0;
  ll best = 0;
  ll onecount = 0;
  for (int i = (0); i < (n); i++) {
    ll x;
    cin >> x;
    if (counter[x] == 0) {
      totalCount++;
      onecount++;
    } else if (counter[x] == 1) {
      onecount--;
    }
    counter[x]++;
    if (counter[x] > maxVal) {
      maxVal = counter[x];
      secondMaxCount = max(0ll, maxCount - 1);
      maxCount = 1;
    } else if (counter[x] == maxVal) {
      maxCount++;
      secondMaxCount--;
    } else if (counter[x] == maxVal - 1) {
      secondMaxCount++;
    }
    if (maxCount == 1 && (1 + secondMaxCount == totalCount)) best = i + 1;
    if (1 + maxCount == totalCount && onecount == 1) best = i + 1;
    if (maxVal == 1) best = i + 1;
  }
  cout << best << endl;
}
