This is the code for Rock and Lever question in CF. I am getting runtime error for 2nd testcase.

Question link :- http://codeforces.com/problemset/problem/1420/B

My code :-

#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll highbit(ll n){

ll cnt = 0, ans = 0;

while(n > 0){

cnt++;

if(n & 1)

ans = cnt;

n >>= 1;

}

return ans;

}

bool cmp(pair<ll, ll> a, pair<ll, ll> b){

return (a.first <= b.first);

}

int main(){

ll t;

cin >> t;

while(t–){

ll n;

cin >> n;

ll ar[n];

for(ll i = 0;i<n;i++){

cin >> ar[i];

}

vector<pair<ll, ll > > v;

for(ll i = 0;i<n;i++){

ll h = highbit(ar[i]);

v.push_back(make_pair(h, ar[i]));

}

sort(v.begin(), v.end(), cmp);

ll sum = 1, ans = 0;

for(ll i = 0;i<n-1;i++){

if(v[i].first == v[i+1].first){

sum++;

}

else{

ans += (sum-1)*sum/2;

sum = 1;

}

}

ans += (sum-1)*sum/2;

cout << ans << “\n”;

}

}

Please help me in finding mistake.