func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long eps = 1e9 + 7;   const double inf = 1e-12;   bool F(set<pair<int, int> > &a) {     pair<int, int> p = *a.rbegin();     a.erase(p);     --p.first;     if (p.first != 0) {       a.insert(p);     }     if (!a.empty() && a.rbegin()->first == a.begin()->first) {       if (p.first != 0) {         a.erase(p);       }       ++p.first;       a.insert(p);       return true;     }     if (p.first != 0) {       a.erase(p);     }     ++p.first;     a.insert(p);     p = *a.begin();     a.erase(p);     --p.first;     if (p.first != 0) {       a.insert(p);     }     if (!a.empty() && a.rbegin()->first == a.begin()->first) {       if (p.first != 0) {         a.erase(p);       }       ++p.first;       a.insert(p);       return true;     }     if (p.first != 0) {       a.erase(p);     }     ++p.first;     a.insert(p);     return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     set<pair<int, int> > a;     vector<int> b(1e5 + 5);     int max1 = 1;     for (int i = 1; i <= n; ++i) {       int first;       cin >> first;       a.erase(pair<int, int>(b[first], first));       ++b[first];       a.insert(pair<int, int>(b[first], first));       if (F(a)) {         max1 = i;       }     }     cout << max1;     return 0;   }   