fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. void solve(){
  7. string s;
  8. cin>>s;
  9. int n=s.size(),ans=0;
  10. for(int i=0;i<n;i++){
  11. unordered_map<char,int>mp;
  12. int mx=0;
  13. for(int j=i;j<n;j++){
  14. mp[s[j]]++;
  15. mx=max(mx,mp[s[j]]);
  16. if(mp.size()-mx>=0)ans++;
  17. }
  18. }
  19. cout<<ans<<"\n";
  20. }
  21.  
  22. int main(){
  23. ios_base::sync_with_stdio(false);
  24. cin.tie(NULL);
  25. solve();
  26. return 0;
  27. }
Success #stdin #stdout 0s 5320KB
stdin
abaa
stdout
10