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>
using namespace std;

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

Problem Link: ALEXNUMB Problem - CodeChef

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 ;