#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int n, ans = 1, A[100005];
map<int, int> freq, tmp;
vector<pair<int, int> > v;
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
bool check(int i) {
  for (auto it = freq.begin(); it != freq.end(); it++) tmp[it->second]++;
  for (auto it = tmp.begin(); it != tmp.end(); it++)
    v.push_back(pair<int, int>(it->second, it->first));
  sort(v.begin(), v.end(), compare);
  if (tmp.size() == 2) {
    if (v[0].first == 1) {
      if (v[0].second == 1 || v[0].second - v[1].second == 1)
        return 1;
      else
        return 0;
    } else
      return 0;
  } else if (tmp.size() == 1) {
    if (v[0].first == 1 || v[0].second == 1)
      return 1;
    else
      return 0;
  } else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    freq[A[i]]++;
    if (check(i)) ans = i + 1;
    tmp.clear();
    v.clear();
  }
  cout << ans << '\n';
  return 0;
}
