In today codebyte score maximum CGPA

3 test cases are not passing
what is the wrong approach in my code and what would be the right approach

#include
#include
using namespace std;
int main ()
{
int n,count=0,i;
cin>>n;

int a[n];
for(i=0;i<n;i++)
cin>>a[i];

sort(a,a+n);


for(i=1;i<n;i++)
{
	if(a[i]==a[i-1])
	swap(a[i],a[i+1]);
}


for(i=1;i<n;i++)
{
	if(a[i]>a[i-1])
	count++;
}
cout<<count;

return 0;

}

@shivamgoel150
Consider this testcase:
10
4 4 4 4 4 5 5 5 5 5
Ans should be 5 ( arrangement 4 5 4 5 4 5 4 5 4 5 ), but your code is giving 2