Help me in solving ALEXNUMB problem

My issue

Two unknown test cases are failing. Moreover, accepted solutions have used to sum of terms in an ap which I don’t understand why

My code

#include <iostream>
#include<algorithm>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    //distinct integers hai
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++){
	        cin>>a[i];
	    }
	    
	    sort(a, a+n);
	    int count =0;
	    for(int i=0;i<n-1;i++){
	        for(int k=i+1;k<n;k++){
	            count++;
	        }
	    }
	    cout<<count<<endl;
	    
	}
	return 0;
}

Problem Link: ALEXNUMB Problem - CodeChef

@ak_4629
if u see carefully after sorting u are also doing the same thing that is sum of n since all numbers are distinct so it will work no need to loop it through and then count cozz it it results the same and also moreover your time complexity will also increase which will give u tle.
so just print (n*(n-1))/2 ;