#include <bits/stdc++.h>
using namespace std;
void FAST_IO();
int main() {
  long long int n, u, mx = 0, res;
  vector<long long int> colors(100010), frequencycnt(100010);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> u;
    frequencycnt[colors[u]]--;
    colors[u]++;
    frequencycnt[colors[u]]++;
    mx = max(mx, colors[u]);
    if (i == 1)
      res = 1;
    else if (frequencycnt[1] == i)
      res = i;
    else if (frequencycnt[mx] * mx == i - 1 && frequencycnt[1] == 1)
      res = i;
    else if (frequencycnt[mx] == 1 && frequencycnt[mx - 1] * (mx - 1) == i - mx)
      res = i;
  }
  cout << res << '\n';
  return 0;
}
void FAST_IO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
