Help me in solving CFRTEST problem

My issue

My code

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

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

Problem Link: CFRTEST Problem - CodeChef

@nayanshree28
you have understood the logic and solved 90% of the question but last part was not executed well.

just return n-count , that will be the answer . if 2 dates are same he can only save 1 friendship so increasing count by 1 will calculate how many friendships he cannot save.
so, the total friendships he can save is total friendships - no of he cannot save.

i have pasted my correct code below

hope this helps!!

include
#include<bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{ int n,count=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(a[i]==a[i+1])
count++;
}
int res=n-count;
std::cout << res << std::endl;

}
return 0;

}