dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MakePreSum ( int arr [ ] , int presum [ ] , int n ) { presum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) presum [ i ] = presum [ i - 1 ] + arr [ i ] ; } int BinaryLifting ( int presum [ ] , int n , int x ) { int pos = 0 ; int LOGN = log2 ( n ) ; if ( x <= presum [ 0 ] ) return 0 ; for ( int i = LOGN ; i >= 0 ; i -- ) { if ( pos + ( 1 << i ) < n && presum [ pos + ( 1 << i ) ] < x ) { pos += ( 1 << i ) ; } } return pos + 1 ; } int main ( ) { int arr [ ] = { 2 , 5 , 7 , 1 , 6 , 9 , 12 , 4 , 6 } ; int x = 8 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int presum [ n ] = { 0 } ; MakePreSum ( arr , presum , n ) ; cout << BinaryLifting ( presum , n , x ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, pos, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int bit_count ( int n ) { int count = 0 ; while ( n ) { count ++ ; n = n & ( n - 1 ) ; } return count ; } int maxsum ( int arr [ ] , int n ) { int bits [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { bits [ i ] = bit_count ( arr [ i ] ) ; } int sum [ 32 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { sum [ bits [ i ] ] += arr [ i ] ; } int maximum = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { maximum = max ( sum [ i ] , maximum ) ; } return maximum ; } int main ( ) { int arr [ ] = { 2 , 3 , 8 , 5 , 6 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxsum ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int xorPairSum ( int ar [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum ^ ar [ i ] ; return 2 * sum ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << xorPairSum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findEvenPair ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( ! ( A [ i ] & 1 ) ) count ++ ; return count * ( count - 1 ) / 2 ; } int main ( ) { int A [ ] = { 5 , 6 , 2 , 8 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << findEvenPair ( A , N ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool allBitsSetInTheGivenRange ( unsigned int n , unsigned int l , unsigned int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; int new_num = n & num ; if ( new_num == 0 ) return true ; return false ; } int main ( ) { unsigned int n = 17 ; unsigned int l = 2 , r = 4 ; if ( allBitsSetInTheGivenRange ( n , l , r ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkSame ( int n ) { int set = 0 , unset = 0 ; while ( n ) { if ( n & 1 ) set ++ ; else unset ++ ; n = n >> 1 ; } if ( set == unset ) return true ; else return false ; } int main ( ) { int n = 12 ; if ( checkSame ( n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }

Accumulator variables: set, stdc, unset
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isBalanced ( string s ) { stack < char > st ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ( ' ) st . push ( s [ i ] ) ; else { if ( st . empty ( ) ) { return false ; } else st . pop ( ) ; } } if ( ! st . empty ( ) ) return false ; return true ; } bool isBalancedSeq ( string s1 , string s2 ) { if ( isBalanced ( s1 + s2 ) ) return true ; return isBalanced ( s2 + s1 ) ; } int main ( ) { string s1 = " ) ( ) ( ( ) ) ) ) " ; string s2 = " ( ( ) ( ( ) ( " ; if ( isBalancedSeq ( s1 , s2 ) ) cout << " Balanced " ; else cout << " Not ▁ Balanced " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void KthCharacter ( int m , int n , int k ) { int distance = pow ( 2 , n ) ; int Block_number = k / distance ; int remaining = k % distance ; int s [ 32 ] , x = 0 ; for ( ; m > 0 ; x ++ ) { s [ x ] = m % 2 ; m = m / 2 ; } int root = s [ x - 1 - Block_number ] ; if ( remaining == 0 ) { cout << root << endl ; return ; } bool flip = true ; while ( remaining > 1 ) { if ( remaining & 1 ) { flip = ! flip ; } remaining = remaining >> 1 ; } if ( flip ) { cout << ! root << endl ; } else { cout << root << endl ; } } int main ( ) { int m = 5 , k = 5 , n = 3 ; KthCharacter ( m , n , k ) ; return 0 ; }

Index/key variables: x
Accumulator variables: stdc, x
Boolean variables: flip
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool onlyFirstAndLastAreSet ( unsigned int n ) { if ( n == 1 ) return true ; if ( n == 2 ) return false ; return ( ( ( n - 1 ) & ( n - 2 ) ) == 0 ) ; } int main ( ) { unsigned int n = 9 ; if ( onlyFirstAndLastAreSet ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getInteger ( int L , int R ) { int number = 0 ; for ( int i = L ; i <= R ; i ++ ) number += pow ( 2 , i ) ; return number ; } int main ( ) { int L = 2 , R = 5 ; cout << getInteger ( L , R ) ; return 0 ; }

Accumulator variables: i, number, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int setbitsfromLtoR ( int L , int R ) { return ( 1 << ( R + 1 ) ) - ( 1 << L ) ; } int main ( ) { int L = 2 , R = 5 ; cout << setbitsfromLtoR ( L , R ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findXor ( int arr [ ] , int n ) { int xoR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xoR = xoR ^ arr [ i ] ; } return xoR * 2 ; } int main ( ) { int arr [ 3 ] = { 1 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findXor ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void setBitwiseORk ( int n ) { vector < int > v ; for ( int i = 0 ; i <= n ; i ++ ) { if ( ( i n ) == n ) v . push_back ( i ) ; } for ( int i = 0 ; i < v . size ( ) ; i ++ ) cout << v [ i ] << ' ▁ ' ; } int main ( ) { int n = 5 ; setBitwiseORk ( n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printOdds ( int arr [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res = res ^ arr [ i ] ; int set_bit = res & ( ~ ( res - 1 ) ) ; int x = 0 , y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & set_bit ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } cout << x << " ▁ " << y ; } int main ( ) { int arr [ ] = { 2 , 3 , 3 , 4 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printOdds ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void subsetBitwiseORk ( int arr [ ] , int n , int k ) { vector < int > v ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] k ) == k ) v . push_back ( arr [ i ] ) ; } int ans = 0 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) ans |= v [ i ] ; if ( ans != k ) { cout << " Subset ▁ does ▁ not ▁ exist " << endl ; return ; } for ( int i = 0 ; i < v . size ( ) ; i ++ ) cout << v [ i ] << ' ▁ ' ; } int main ( ) { int k = 3 ; int arr [ ] = { 1 , 4 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; subsetBitwiseORk ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findEletobeInserted ( int A [ ] , int n , int k ) { int ans = k ; for ( int i = 0 ; i < n ; i ++ ) return ans ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int k = 10 ; cout << findEletobeInserted ( A , n , k ) << " ▁ has ▁ to ▁ be ▁ inserted " " ▁ in ▁ the ▁ given ▁ array ▁ to ▁ make ▁ xor ▁ sum ▁ of ▁ " << k << endl ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int BitCount [ 10000 ] = { 0 } ; void fillSetBitsMatrix ( int arr [ ] , int n ) { for ( int i = 0 ; i < 32 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { long temp = arr [ j ] >> i ; if ( temp % 2 != 0 ) BitCount [ j ] += 1 ; } } for ( int i = 1 ; i < n ; i ++ ) BitCount [ i ] += BitCount [ i - 1 ] ; } void Query ( int Q [ ] [ 2 ] , int q ) { for ( int i = 0 ; i < q ; i ++ ) cout << ( BitCount [ Q [ i ] [ 1 ] ] - BitCount [ Q [ i ] [ 0 ] - 1 ] ) << endl ; } int main ( ) { int Arr [ ] = { 1 , 5 , 6 , 10 , 9 , 4 , 67 } ; int n = sizeof ( Arr ) / sizeof ( Arr [ 0 ] ) ; fillSetBitsMatrix ( Arr , n ) ; int q = 2 ; int Q [ 2 ] [ 2 ] = { { 1 , 5 } , { 2 , 6 } } ; Query ( Q , q ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void decimalToBinaryNumber ( int x , int n ) { int * binaryNumber = new int ( x ) ; int i = 0 ; while ( x > 0 ) { binaryNumber [ i ] = x % 2 ; x = x / 2 ; i ++ ; } for ( int j = 0 ; j < n - i ; j ++ ) cout << '0' ; for ( int j = i - 1 ; j >= 0 ; j -- ) cout << binaryNumber [ j ] ; } void generateGrayarr ( int n ) { int N = 1 << n ; for ( int i = 0 ; i < N ; i ++ ) { int x = i ^ ( i >> 1 ) ; decimalToBinaryNumber ( x , n ) ; cout << endl ; } } int main ( ) { int n = 3 ; generateGrayarr ( n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define BITS  32
int andSum ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < BITS ; i ++ ) { int countSetBits = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] & ( 1 << i ) ) countSetBits ++ ; } int subset = ( 1 << countSetBits ) - 1 ; subset = ( subset * ( 1 << i ) ) ; ans += subset ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << andSum ( arr , size ) ; return 0 ; }

Index/key variables: j
Accumulator variables: ans, countSetBits, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define ll  unsigned int
using namespace std ; ll maximize ( ll a ) { ll n = _popcnt32 ( a ) ; if ( n == 32 ) return a ; ll res = ( 1 << n ) - 1 ; return ( res << ( 32 - n ) ) ; } int main ( ) { ll a = 3 ; cout << maximize ( a ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
#define ll  unsigned int
using namespace std ; ll minimize ( ll a ) { ll n = _popcnt32 ( a ) ; return ( pow ( 2 , n ) - 1 ) ; } int main ( ) { ll a = 11 ; cout << minimize ( a ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  100010
struct Edge { int u , v ; } ; vector < int > v [ N ] ; int p [ N ] ; struct wunionfind { int id [ N ] , sz [ N ] ; void initial ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) id [ i ] = i , sz [ i ] = 1 ; } int Root ( int idx ) { int i = idx ; while ( i != id [ i ] ) id [ i ] = id [ id [ i ] ] , i = id [ i ] ; return i ; } void Union ( int a , int b ) { int i = Root ( a ) , j = Root ( b ) ; if ( i != j ) { if ( sz [ i ] >= sz [ j ] ) { id [ j ] = i , sz [ i ] += sz [ j ] ; sz [ j ] = 0 ; } else { id [ i ] = j , sz [ j ] += sz [ i ] ; sz [ i ] = 0 ; } } } } ; wunionfind W ; void dfs ( int u , int parent ) { for ( int i = 0 ; i < v [ u ] . size ( ) ; i ++ ) { int j = v [ u ] [ i ] ; if ( j != parent ) { p [ j ] = u ; dfs ( j , u ) ; } } } int UnionUtil ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int maxi = 1 ; for ( int x = i ; x <= n ; x = ( i | ( x + 1 ) ) ) { int y = p [ x ] ; if ( ( y & i ) == i ) { W . Union ( x , y ) ; maxi = max ( maxi , W . sz [ W . Root ( x ) ] ) ; } } ans = max ( ans , maxi * i ) ; for ( int x = i ; x <= n ; x = ( i | ( x + 1 ) ) ) { W . sz [ x ] = 1 ; W . id [ x ] = x ; } } return ans ; } int main ( ) { int n , i ; n = 6 ; W . initial ( n ) ; Edge e [ ] = { { 1 , 2 } , { 2 , 3 } , { 3 , 4 } , { 3 , 5 } , { 5 , 6 } } ; int q = sizeof ( e ) / sizeof ( e [ 0 ] ) ; for ( i = 0 ; i < q ; i ++ ) { int x , y ; x = e [ i ] . u , y = e [ i ] . v ; v [ x ] . push_back ( y ) ; v [ y ] . push_back ( x ) ; } p [ 1 ] = 1 ; dfs ( 1 , -1 ) ; int ans = UnionUtil ( n ) ; printf ( " Maximum ▁ Cost ▁ = ▁ % d STRNEWLINE " , ans ) ; return 0 ; }

Index/key variables: N, i, j, u, x, y
Accumulator variables: i, stdc
Iterator variables: i, x
Class/struct names: Edge, wunionfind
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned int countSetBits ( unsigned int n ) { unsigned int count = 0 ; while ( n ) { count += n & 1 ; n >>= 1 ; } return count ; } int main ( ) { int i = 3 ; cout << countSetBits ( i ) ; return 0 ; }

Accumulator variables: count, stdc
C++ program:
#include <iostream>
using namespace std ; bool isEven ( int n ) { bool isEven = true ; for ( int i = 1 ; i <= n ; i ++ ) isEven = ! isEven ; return isEven ; } int main ( ) { int n = 101 ; isEven ( n ) ? cout << " Even " : cout << " Odd " ; return 0 ; }

Accumulator variables: i
Iterator variables: i
Boolean variables: isEven
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkValidPair ( int num1 , int num2 ) { string s1 = to_string ( num1 ) ; string s2 = to_string ( num2 ) ; for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) for ( int j = 0 ; j < s2 . size ( ) ; j ++ ) if ( s1 [ i ] == s2 [ j ] ) return true ; return false ; } int countPairs ( int arr [ ] , int n ) { int numberOfPairs = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( checkValidPair ( arr [ i ] , arr [ j ] ) ) numberOfPairs ++ ; return numberOfPairs ; } int main ( ) { int arr [ ] = { 10 , 12 , 24 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairs ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, numberOfPairs, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int NUM_BITS = 32 ; bool isPowerOf2 ( int num ) { return ( num && ! ( num & ( num - 1 ) ) ) ; } bool checkSubsequence ( int arr [ ] , int n ) { if ( n == 1 ) return isPowerOf2 ( arr [ 0 ] ) ; int total = 0 ; for ( int i = 0 ; i < NUM_BITS ; i ++ ) total = total | ( 1 << i ) ; for ( int i = 0 ; i < NUM_BITS ; i ++ ) { int ans = total ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] & ( 1 << i ) ) ans = ans & arr [ j ] ; } if ( isPowerOf2 ( ans ) ) return true ; } return false ; } int main ( ) { int arr [ ] = { 12 , 13 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( checkSubsequence ( arr , n ) ) printf ( " YES STRNEWLINE " ) ; else printf ( " NO STRNEWLINE " ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } void constructSTUtil ( int arr [ ] , int ss , int se , int * st , int si , int operation ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return ; } int mid = getMid ( ss , se ) ; constructSTUtil ( arr , ss , mid , st , si * 2 + 1 , ! operation ) ; constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 , ! operation ) ; if ( operation == 1 ) { st [ si ] = ( st [ 2 * si + 1 ] st [ 2 * si + 2 ] ) ; } else { st [ si ] = ( st [ 2 * si + 1 ] ^ st [ 2 * si + 2 ] ) ; } } int * constructST ( int arr [ ] , int n ) { int x = ( int ) ( ceil ( log2 ( n ) ) ) ; int max_size = 2 * ( int ) pow ( 2 , x ) - 1 ; int * st = new int [ max_size ] ; int operationAtRoot = ( x % 2 == 0 ? 0 : 1 ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 , operationAtRoot ) ; return st ; } int main ( ) { int leaves [ ] = { 1 , 6 , 3 , 7 , 5 , 9 , 10 , 4 } ; int n = sizeof ( leaves ) / sizeof ( leaves [ 0 ] ) ; int * segmentTree = constructST ( leaves , n ) ; int rootIndex = 0 ; cout << " Value ▁ at ▁ Root ▁ Node ▁ = ▁ " << segmentTree [ rootIndex ] ; }

Index/key variables: max_size, rootIndex, si, ss
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  1000
int lastElement ( int a [ ] , int n ) { int steps = 1 ; vector < int > v [ N ] ; if ( n == 1 ) return a [ 0 ] ; for ( int i = 0 ; i < n ; i += 2 ) v [ steps ] . push_back ( a [ i ] a [ i + 1 ] ) ; while ( v [ steps ] . size ( ) > 1 ) { steps += 1 ; for ( int i = 0 ; i < v [ steps - 1 ] . size ( ) ; i += 2 ) { if ( steps & 1 ) v [ steps ] . push_back ( v [ steps - 1 ] [ i ] v [ steps - 1 ] [ i + 1 ] ) ; v [ steps ] . push_back ( v [ steps - 1 ] [ i ] ^ v [ steps - 1 ] [ i + 1 ] ) ; } } return v [ steps ] [ 0 ] ; } int main ( ) { int a [ ] = { 1 , 4 , 5 , 6 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int index = 0 ; int value = 2 ; a [ 0 ] = 2 ; cout << lastElement ( a , n ) << endl ; index = 3 ; value = 5 ; a [ index ] = value ; cout << lastElement ( a , n ) << endl ; return 0 ; }

Index/key variables: N, i, index, steps
Accumulator variables: i, stdc, steps
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findWinner ( int A [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res ^= A [ i ] ; if ( res == 0 n % 2 == 0 ) return " Alice " ; else return " Bob " ; } int main ( ) { int A [ ] = { 1 , 4 , 3 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << " Winner ▁ = ▁ " << findWinner ( A , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isFibbinaryNum ( unsigned int n ) { if ( ( n & ( n >> 1 ) ) == 0 ) return true ; return false ; } int main ( ) { unsigned int n = 10 ; if ( isFibbinaryNum ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxXOR ( int n , int k ) { int c = log2 ( n ) + 1 ; return ( ( 1 << c ) - 1 ) ; } int main ( ) { int n = 12 ; int k = 3 ; cout << maxXOR ( n , k ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int divide ( long long dividend , long long divisor ) { int sign = ( ( dividend < 0 ) ^ ( divisor < 0 ) ) ? -1 : 1 ; dividend = abs ( dividend ) ; divisor = abs ( divisor ) ; long long quotient = 0 , temp = 0 ; for ( int i = 31 ; i >= 0 ; -- i ) { if ( temp + ( divisor << i ) <= dividend ) { temp += divisor << i ; quotient |= 1LL << i ; } } if ( sign == -1 ) quotient = - quotient ; return quotient ; } int main ( ) { int a = 10 , b = 3 ; cout << divide ( a , b ) << " STRNEWLINE " ; a = 43 , b = -8 ; cout << divide ( a , b ) ; return 0 ; }

Accumulator variables: quotient, stdc, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count ( int n ) { int c = 0 ; while ( n ) { c ++ ; n = n >> 1 ; } return c ; } int XOR ( int a , int b ) { int c = min ( a , b ) ; int d = max ( a , b ) ; if ( count ( c ) < count ( d ) ) c = c << ( count ( d ) - count ( c ) ) ; return ( c ^ d ) ; } int main ( ) { int a = 13 , b = 5 ; cout << XOR ( a , b ) ; return 0 ; }

Accumulator variables: c, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CheckDivisibilty ( string A ) { int oddbits = 0 , evenbits = 0 ; for ( int counter = 0 ; counter < A . length ( ) ; counter ++ ) { if ( A [ counter ] == '1' ) { if ( counter % 2 == 0 ) { evenbits ++ ; } else { oddbits ++ ; } } } if ( abs ( oddbits - evenbits ) % 3 == 0 ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } } int main ( ) { string A = "10101" ; CheckDivisibilty ( A ) ; return 0 ; }

Index/key variables: counter
Accumulator variables: counter, evenbits, oddbits, stdc
Iterator variables: counter
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned int swapBitsInPair ( unsigned int x ) { return ( ( x & 0b10101010 ) >> 1 ) | ( ( x & 0b01010101 ) << 1 ) ; } int main ( ) { unsigned int x = 4 ; cout << swapBitsInPair ( x ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int setevenbits ( int n ) { int temp = n ; int count = 0 ; int res = 0 ; for ( temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return ( n & res ) ; } int setoddbits ( int m ) { int count = 0 ; int res = 0 ; for ( int temp = m ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return ( m & res ) ; } int getAlternateBits ( int n , int m ) { int tempn = setevenbits ( n ) ; int tempm = setoddbits ( m ) ; return ( tempn tempm ) ; } int main ( ) { int n = 10 ; int m = 11 ; cout << getAlternateBits ( n , m ) ; return 0 ; }

Accumulator variables: count, res
Iterator variables: temp
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isDivisibleBy10 ( char bin [ ] , int n ) { if ( bin [ n - 1 ] == '1' ) return false ; int sum = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( bin [ i ] == '1' ) { int posFromRight = n - i - 1 ; if ( posFromRight % 4 == 1 ) sum = sum + 2 ; else if ( posFromRight % 4 == 2 ) sum = sum + 4 ; else if ( posFromRight % 4 == 3 ) sum = sum + 8 ; else if ( posFromRight % 4 == 0 ) sum = sum + 6 ; } } if ( sum % 10 == 0 ) return true ; return false ; } bool isDivisibleBy20 ( char bin [ ] , int n ) { if ( bin [ n - 1 ] == '1' ) return false ; return isDivisibleBy10 ( bin , n - 1 ) ; } int main ( ) { char bin [ ] = "101000" ; int n = sizeof ( bin ) / sizeof ( bin [ 0 ] ) ; if ( isDivisibleBy20 ( bin , n - 1 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int toggleBits ( int n1 , int n2 ) { return n1 ^ n2 ; } int main ( ) { int n1 = 2 , n2 = 5 ; cout << toggleBitst ( n1 , n2 ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int evenbittogglenumber ( int n ) { int res = 0 , count = 0 ; for ( int temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return n ^ res ; } int main ( ) { int n = 11 ; cout << evenbittogglenumber ( n ) ; return 0 ; }

Accumulator variables: count, res
Iterator variables: temp
C++ program:
#include <iostream>
using namespace std ; int takeLandFsetbits ( int n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( ( n + 1 ) >> 1 ) + 1 ; } int toggleFandLbits ( int n ) { if ( n == 1 ) return 0 ; return n ^ takeLandFsetbits ( n ) ; } int main ( ) { int n = 10 ; cout << toggleFandLbits ( n ) ; return 0 ; }

Accumulator variables: n
C++ program:
#include <iostream>
using namespace std ; #include <math.h>
int countSetBits ( int n ) { unsigned int count = 0 ; while ( n ) { n &= ( n - 1 ) ; count ++ ; } return count ; } int checkOdious ( int n ) { return ( countSetBits ( n ) % 2 == 1 ) ; } int main ( ) { int num = 32 ; if ( checkOdious ( num ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: count, n
C++ program:
#include <iostream>
using namespace std ; int setleftmostunsetbit ( int n ) { if ( ( n & ( n + 1 ) ) == 0 ) return n ; int pos = 0 ; for ( int temp = n , count = 0 ; temp > 0 ; temp >>= 1 , count ++ ) if ( ( temp & 1 ) == 0 ) pos = count ; return ( n | ( 1 << ( pos ) ) ) ; } int main ( ) { int n = 10 ; cout << setleftmostunsetbit ( n ) ; return 0 ; }

Accumulator variables: count
Iterator variables: temp
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxXorSum ( int n , int k ) { if ( k == 1 ) return n ; int res = 1 ; while ( res <= n ) res <<= 1 ; return res - 1 ; } int main ( ) { int n = 4 , k = 3 ; cout << maxXorSum ( n , k ) ; return 0 ; }

Accumulator variables: stdc