#include <bits/stdc++.h>
using namespace std;
int ribbons[100000] = {0};
int cnt[100000 + 1] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, x = 1;
  cin >> n;
  multiset<int> counts;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    int c = ribbons[t];
    ribbons[t]++;
    if (counts.count(c)) {
      counts.erase(counts.find(c));
      cnt[c]--;
    }
    counts.insert(c + 1);
    cnt[c + 1]++;
    int minCount = *counts.begin(), maxCount = *counts.rbegin(),
        allCount = counts.size();
    int minA = cnt[minCount], maxA = cnt[maxCount];
    if (minA + maxA == allCount) {
      if (maxA == 1 && minCount == maxCount - 1) {
        x = i + 1;
      }
      if (cnt[1] == 1) {
        x = i + 1;
      }
    }
    if (minA == allCount && minCount == 1) {
      x = i + 1;
    }
    if (allCount == 1) x = i + 1;
  }
  cout << x;
}
