#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long Mod = 1e9 + 7;
int U[100007];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int A[n];
  set<int> tot;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    U[A[i]]++;
    tot.insert(A[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    bool x = true, y = true;
    int count = 0, dash = 0;
    if (i % tot.size() == 0) {
      for (auto it : tot) {
        if (U[it] == (i / tot.size()) + 1)
          count++;
        else if (U[it] != i / tot.size())
          x = false;
        if (count > 1) break;
      }
    }
    int size = tot.size() - 1;
    if (size != 0) {
      if (i % size == 0) {
        for (auto it : tot) {
          if ((U[it] == 1) && dash < 1)
            dash++;
          else if (U[it] != i / size)
            y = false;
        }
      }
    }
    U[A[i]]--;
    if (U[A[i]] == 0) tot.erase(A[i]);
    if ((x && (count == 1)) || (y && (dash == 1))) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}
