#include <bits/stdc++.h>
using namespace std;
long long n, m, k, t, caseno;
long long a[100005];
long long cnt[100005];
long long tree[4 * 100005];
void update(long long node, long long left, long long right, long long pos,
            long long val) {
  if (left == right) {
    tree[node] = val;
    return;
  }
  long long mid = left + ((right - left) >> 1);
  if (mid >= pos) {
    update(node * 2, left, mid, pos, val);
  } else {
    update(node * 2 + 1, mid + 1, right, pos, val);
  }
  if (tree[node * 2] && tree[node * 2 + 1])
    tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
  else if (tree[node * 2])
    tree[node] = tree[node * 2];
  else
    tree[node] = tree[node * 2 + 1];
}
int main() {
  long long i, j, q;
  scanf("%lld", &n);
  m = 100000;
  long long Mx_koyta = 0, Mx = 0;
  long long res = 1;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    cnt[a[i]]++;
    if (cnt[a[i]] == Mx) {
      Mx_koyta++;
    } else if (cnt[a[i]] > Mx) {
      Mx = cnt[a[i]];
      Mx_koyta = 1;
    }
    update(1, 1, m, a[i], cnt[a[i]]);
    long long Mn = tree[1];
    if ((Mx - Mn == 0 && Mx_koyta == 1) || (Mx - Mn == 1 && Mx_koyta == 1) ||
        (Mx * Mx_koyta + 1 == i) || (Mx == 1 && Mx_koyta == i)) {
      res = i;
    }
  }
  printf("%lld\n", res);
  return 0;
}
