Please help me find Mistake in my code

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

Question link :-

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){
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;
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){
ans += (sum-1)*sum/2;
sum = 1;
ans += (sum-1)*sum/2;
cout << ans << “\n”;

Please help me in finding mistake.

error is in the cmp function created. In cpp by default sort function sorts the vector of pairs on the basis of the first element. you can simply write sort(v.begin(),v.end())
and why are you using a vector of pairs without any use you can simply create vector and push back h to it

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
return (a.first < b.first);

use this

Using this, I got AC. Thanks for the help

How is the result affected by using ‘<’ instead o ‘<=’. I tried to observe the results for both the cases but couldn’t find difference.