#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
int in[N];
void solve() {
  int n;
  scanf("%d ", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d ", &in[i]);
  }
  set<pair<int, int> > s;
  map<int, int> cc;
  int ret = 1;
  for (int i = 1; i <= n; ++i) {
    int u = ++cc[in[i]];
    if (u == 1) {
      s.insert(make_pair(u, in[i]));
    } else {
      s.erase(make_pair(u - 1, in[i]));
      s.insert(make_pair(u, in[i]));
    }
    pair<int, int> v = *prev(s.end());
    {
      pair<int, int> f = *s.begin();
      s.erase(f);
      bool g = false;
      if (f.first != 1) {
        g = true;
        f.first -= 1;
        s.insert(f);
      }
      if (s.size() == 0 || ((*s.begin()).first == (*prev(s.end())).first)) {
        ret = i;
      }
      if (g) {
        s.erase(f);
        f.first += 1;
        s.insert(f);
      } else {
        s.insert(f);
      }
    }
    {
      pair<int, int> f = *prev(s.end());
      s.erase(f);
      s.erase(f);
      bool g = false;
      if (f.first != 1) {
        g = true;
        f.first -= 1;
        s.insert(f);
      }
      if (s.size() == 0 || ((*s.begin()).first == (*prev(s.end())).first)) {
        ret = i;
      }
      if (g) {
        s.erase(f);
        f.first += 1;
        s.insert(f);
      } else {
        s.insert(f);
      }
    }
  }
  printf("%d\n", ret);
}
int main() { solve(); }
