IT IS A QUESTION FROM CODECHEF
ITS GIVING WRONG ANSWER
https://www.codechef.com/FEB19B/problems/ARTBALAN
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll t;
cin>>t;
while(t–){
string s;
cin>>s;
map<char,ll> m;
ll uniq=0;
m.clear();
for(ll i=0;i<s.length();i++){
if(m[s[i]]==0)uniq++;
m[s[i]]++;
}
ll a[s.length()],j=0;
for(auto i:m){
a[j++]=i.second;
}
sort(a,a+j);
ll ans=0;
for(ll i=uniq;i>=1;i–){
if(s.length()%i!=0)continue;
ll h=j-i;
for(ll i1=0;i1<h;i1++)ans+=a[i1];
ll g=s.length()/i;
for(ll i2=h;i2<j;i2++){
if(a[i2]>=g)ans+=a[i2]-g;
}
cout<<ans<<"\n";
break;
}
}
}