Art of balance codechef question

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;
}

}

}

IT IS GIVING WRONG ANSWER

paste your code on IDE and share the link.
It is easy implementation problem. Time complexity- o(26*26).

whats the logic? @Anubhav-Aron-1353657628083250

just string immplementation.
Store the frequency of every character and sort them in decreasing order and find the count of making x different characters in array where (x is between 1 to 26 cozz max 26 different character in array and minimum 1 ).
you will have clear explaination when contest is over and you can get its editorial on official site.