Meaning of the questions: n give you the number, find the greatest x, so that makes removing one of the first x, so that the same number of other figures have emerged;
Defines two map <int, int> a, b;
a number of times to deposit entered (set to x), b for a number of the current number of times (set y) appears deposit;
Description All numbers are equal when the front i to position i, i if and only if when x * y == i! = Ans = i + 1 when n-; (due to the removal of one)
Or when x * y == i-1, i to be described when the position in front of one, i.e., meet the requirements ans = i;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; map<int,int>a,b; int main() { int n; cin>>n; int x; int ans=1; for(int i=1;i<=n;i++){ cin>>x; a[x]++; b[a[x]]++; if(a[x]*b[a[x]]==i&&i!=n){ ans=i+1; } if(a[x]*b[a[x]]==i-1){ ans=i; } } cout<<ans<<endl; return 0; }