Help me in solving MIXCOLOR problem

My issue

plz help fix the error …

My code

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	   ll n;
	    cin>>n;
	   ll a[n];
	   for(ll i=0;i<n;i++){
	       cin>>a[i];
	   }
	   sort(a,a+n,greater<int>());
	   ll count=0;
	   for(ll i=0;i<n;i++){
	       if(a[i]==a[i+1]){
	        a[i]+=a[0];
	        sort(a,a+i,greater<int>());
	        count++;
	       }
	       else{
	           continue;
	       }
	   }
	   cout<<count<<endl;
	}
	return 0;
}

Problem Link: MIXCOLOR Problem - CodeChef

@deepakjdh31
The logic is count the frequency of each number and add frequency -1 of each number .
like 1 1 1 2 2 3
1’s= 3
2’s=2
3’s=1;
the ans would be 3-1+2-1+1-1=3;