func_code_string: #include<bits/stdc++.h>   #pragma GCC optimize ( -O3 )   #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define ll long long   #define double long double   #define pb push_back   #define mod 1000000007   #define int long long   #define endl   n    #define ss second   #define ff first   #define INF 1000000000   #define all(a) a.begin(),a.end()   #define gcd(a, b) __gcd((a), (b))   //ceil(a/b) is equal to (a+b-1)/b   using namespace std;         int power(int a,int n,int p)   {       int res=1;       while(n)       {           if(n%2)           {           res=(res*a)%p;           n--;}           else           {           a=(a*a)%p;           n=n/2;}       }       return res;   }          int binarySearch(int arr[],int l,int r,int x)    {        int mid;       while(l<=r)       {           mid=(l+r)/2;           if(arr[mid]==x)               return mid;           if(arr[mid]<x)               l=mid+1;           else               r=mid-1;       }       return -1;   }           int fact(int n,int k)       //for calculating nCk   {       int ans=1;       if(k>n-k)       {           k=n-k;       }       for(int i=1;i<=k;i++)       {           ans*=(n-i+1);           ans/=i;       }       return ans;   }   // cout << std::fixed;   // std::cout << std::setprecision(9);    // auto it = lower_bound(v.begin(), v.end(), n);           int32_t main()   {       IOS;       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           int a[n+1];              std::map<int, int> m;           for(int i=0;i<n;i++){               cin>>a[i];               m[a[i]]++;           }           set<int>s;           std::map<int, int> m1;           for(auto x:m)           {               s.insert(x.ss);               m1[x.ss]++;           }           int ans=INF;           for(int x:s)           {               int cnt=0;               for(auto y:m1)               {                   if(y.ff<x){                       cnt+=y.ss*y.ff;                   }                   else                   {                       cnt+=abs(y.ff-x)*y.ss;                   }               }               ans=min(ans,cnt);           }              cout<<ans<<endl;          }   }                                         