func_code_string: #include <bits/stdc++.h>   using namespace std;   int cnt[(100000 + 10)];   int f[(100000 + 10)];   int main() {     int n;     cin >> n;     int ans = 0;     int mx = 0;     for (int i = 1; i <= n; i++) {       int v;       cin >> v;       cnt[f[v]]--;       f[v]++;       cnt[f[v]]++;       int ok = 0;       mx = max(mx, f[v]);       if (cnt[1] == i) {         ok = 1;       } else if (cnt[mx] == i) {         ok = 1;       } else if (cnt[mx] * mx == i - 1 && cnt[1] == 1) {         ok = 1;       } else if (cnt[mx - 1] * (mx - 1) == i - mx && cnt[mx] == 1) {         ok = 1;       }       if (ok) {         ans = i;       }     }     cout << ans << endl;     return 0;   }   