dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 10001 ; void update ( int idx , int blk , int val , int bit [ ] [ MAX ] ) { for ( ; idx < MAX ; idx += ( idx & - idx ) ) bit [ blk ] [ idx ] += val ; } int query ( int l , int r , int k , int arr [ ] , int blk_sz , int bit [ ] [ MAX ] ) { int sum = 0 ; while ( l < r && l % blk_sz != 0 && l != 0 ) { if ( arr [ l ] <= k ) sum ++ ; l ++ ; } while ( l + blk_sz <= r ) { int idx = k ; for ( ; idx > 0 ; idx -= idx & - idx ) sum += bit [ l / blk_sz ] [ idx ] ; l += blk_sz ; } while ( l <= r ) { if ( arr [ l ] <= k ) sum ++ ; l ++ ; } return sum ; } void preprocess ( int arr [ ] , int blk_sz , int n , int bit [ ] [ MAX ] ) { for ( int i = 0 ; i < n ; i ++ ) update ( arr [ i ] , i / blk_sz , 1 , bit ) ; } void preprocessUpdate ( int i , int v , int blk_sz , int arr [ ] , int bit [ ] [ MAX ] ) { update ( arr [ i ] , i / blk_sz , -1 , bit ) ; update ( v , i / blk_sz , 1 , bit ) ; arr [ i ] = v ; } int main ( ) { int arr [ ] = { 5 , 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int blk_sz = sqrt ( n ) ; int bit [ blk_sz + 1 ] [ MAX ] ; memset ( bit , 0 , sizeof ( bit ) ) ; preprocess ( arr , blk_sz , n , bit ) ; cout << query ( 1 , 3 , 1 , arr , blk_sz , bit ) << endl ; preprocessUpdate ( 3 , 10 , blk_sz , arr , bit ) ; cout << query ( 3 , 3 , 4 , arr , blk_sz , bit ) << endl ; preprocessUpdate ( 2 , 1 , blk_sz , arr , bit ) ; preprocessUpdate ( 0 , 2 , blk_sz , arr , bit ) ; cout << query ( 0 , 4 , 5 , arr , blk_sz , bit ) << endl ; return 0 ; }

Index/key variables: MAX, blk, i, idx, l
Accumulator variables: i, idx, l, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countInRange ( int arr [ ] , int n , int x , int y ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ; } return count ; } int main ( ) { int arr [ ] = { 1 , 3 , 4 , 9 , 10 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int i = 1 , j = 4 ; cout << countInRange ( arr , n , i , j ) << endl ; i = 9 , j = 12 ; cout << countInRange ( arr , n , i , j ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; double dijkstra ( int s , int d , vector < vector < pair < int , double > > > gr ) { if ( s == d ) return 0 ; set < pair < int , int > > pq ; pq . insert ( { 1 , s } ) ; bool v [ gr . size ( ) ] = { 0 } ; while ( pq . size ( ) ) { int curr = pq . begin ( ) -> second ; int dist = pq . begin ( ) -> first ; pq . erase ( pq . begin ( ) ) ; if ( v [ curr ] ) continue ; v [ curr ] = 1 ; if ( curr == d ) return dist ; for ( auto it : gr [ curr ] ) pq . insert ( { dist * it . second , it . first } ) ; } return -1 ; } int main ( ) { int n = 3 ; vector < vector < pair < int , double > > > gr ( n + 1 ) ; gr [ 1 ] . push_back ( { 3 , 9 } ) ; gr [ 2 ] . push_back ( { 3 , 1 } ) ; gr [ 1 ] . push_back ( { 2 , 5 } ) ; int s = 1 , d = 3 ; cout << dijkstra ( s , d , gr ) ; return 0 ; }

Index/key variables: curr
Accumulator variables: stdc
Iterator variables: it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lowerIndex ( int arr [ ] , int n , int x ) { int l = 0 , h = n - 1 ; while ( l <= h ) { int mid = ( l + h ) / 2 ; if ( arr [ mid ] >= x ) h = mid - 1 ; else l = mid + 1 ; } return l ; } int upperIndex ( int arr [ ] , int n , int y ) { int l = 0 , h = n - 1 ; while ( l <= h ) { int mid = ( l + h ) / 2 ; if ( arr [ mid ] <= y ) l = mid + 1 ; else h = mid - 1 ; } return h ; } int countInRange ( int arr [ ] , int n , int x , int y ) { int count = 0 ; count = upperIndex ( arr , n , y ) - lowerIndex ( arr , n , x ) + 1 ; return count ; } int main ( ) { int arr [ ] = { 1 , 4 , 4 , 9 , 10 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , arr + n ) ; int i = 1 , j = 4 ; cout << countInRange ( arr , n , i , j ) << endl ; i = 9 , j = 12 ; cout << countInRange ( arr , n , i , j ) << endl ; return 0 ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void precompute ( int arr [ ] , int n , int pre [ ] ) { memset ( pre , 0 , n * sizeof ( int ) ) ; pre [ n - 1 ] = arr [ n - 1 ] * pow ( 2 , 0 ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) pre [ i ] = pre [ i + 1 ] + arr [ i ] * ( 1 << ( n - 1 - i ) ) ; } int decimalOfSubarr ( int arr [ ] , int l , int r , int n , int pre [ ] ) { if ( r != n - 1 ) return ( pre [ l ] - pre [ r + 1 ] ) / ( 1 << ( n - 1 - r ) ) ; return pre [ l ] / ( 1 << ( n - 1 - r ) ) ; } int main ( ) { int arr [ ] = { 1 , 0 , 1 , 0 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int pre [ n ] ; precompute ( arr , n , pre ) ; cout << decimalOfSubarr ( arr , 2 , 4 , n , pre ) << endl ; cout << decimalOfSubarr ( arr , 4 , 5 , n , pre ) << endl ; return 0 ; }

Index/key variables: i, l, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int answerQuery ( int a [ ] , int n , int l , int r ) { int count = 0 ; l = l - 1 ; for ( int i = l ; i < r ; i ++ ) { int element = a [ i ] ; int divisors = 0 ; for ( int j = l ; j < r ; j ++ ) { if ( a [ j ] % a [ i ] == 0 ) divisors ++ ; else break ; } if ( divisors == ( r - l ) ) count ++ ; } return count ; } int main ( ) { int a [ ] = { 1 , 2 , 3 , 5 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int l = 1 , r = 4 ; cout << answerQuery ( a , n , l , r ) << endl ; l = 2 , r = 4 ; cout << answerQuery ( a , n , l , r ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, divisors, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minBinary ( int n ) { int digit [ 10 ] , len = 0 ; while ( n > 0 ) { digit [ len ++ ] = n % 10 ; n /= 10 ; } reverse ( digit , digit + len ) ; int ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { ans = max ( ans , digit [ i ] ) ; } cout << " Minimum ▁ Number ▁ of ▁ binary ▁ strings ▁ needed : ▁ " << ans << endl ; for ( int i = 1 ; i <= ans ; i ++ ) { int num = 0 ; for ( int j = 0 ; j < len ; j ++ ) { if ( digit [ j ] > 0 ) { num = num * 10 + 1 ; digit [ j ] -- ; } else { num *= 10 ; } } cout << num << " ▁ " ; } } int main ( ) { int n = 564 ; minBinary ( n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, len, n, num, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  2147483647
int one [ 100001 ] [ 32 ] ; void make_prefix ( int A [ ] , int n ) { for ( int j = 0 ; j < 32 ; j ++ ) one [ 0 ] [ j ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int a = A [ i - 1 ] ; for ( int j = 0 ; j < 32 ; j ++ ) { int x = pow ( 2 , j ) ; if ( a & x ) one [ i ] [ j ] = 1 + one [ i - 1 ] [ j ] ; else one [ i ] [ j ] = one [ i - 1 ] [ j ] ; } } } int Solve ( int L , int R ) { int l = L , r = R ; int tot_bits = r - l + 1 ; int X = MAX ; for ( int i = 0 ; i < 31 ; i ++ ) { int x = one [ r ] [ i ] - one [ l - 1 ] [ i ] ; if ( x >= tot_bits - x ) { int ith_bit = pow ( 2 , i ) ; X = X ^ ith_bit ; } } return X ; } int main ( ) { int n = 5 , q = 3 ; int A [ ] = { 210 , 11 , 48 , 22 , 133 } ; int L [ ] = { 1 , 4 , 2 } , R [ ] = { 3 , 14 , 4 } ; make_prefix ( A , n ) ; for ( int j = 0 ; j < q ; j ++ ) cout << Solve ( L [ j ] , R [ j ] ) << endl ; return 0 ; }

Index/key variables: i, j, r
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void type1 ( int arr [ ] , int start , int limit ) { for ( int i = start ; i <= limit ; i ++ ) arr [ i ] ++ ; } void type2 ( int arr [ ] , int query [ ] [ 3 ] , int start , int limit ) { for ( int i = start ; i <= limit ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else if ( query [ i ] [ 0 ] == 2 ) type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; } } int main ( ) { int n = 5 , m = 5 ; int arr [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) arr [ i ] = 0 ; int temp [ 15 ] = { 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 } ; int query [ 5 ] [ 3 ] ; int j = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { query [ i ] [ 0 ] = temp [ j ++ ] ; query [ i ] [ 1 ] = temp [ j ++ ] ; query [ i ] [ 2 ] = temp [ j ++ ] ; } for ( int i = 1 ; i <= m ; i ++ ) if ( query [ i ] [ 0 ] == 1 ) type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else if ( query [ i ] [ 0 ] == 2 ) type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; for ( int i = 1 ; i <= n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void record_sum ( int record [ ] , int l , int r , int n , int adder ) { for ( int i = l ; i <= r ; i ++ ) record [ i ] += adder ; } int main ( ) { int n = 5 , m = 5 ; int arr [ n ] ; memset ( arr , 0 , sizeof arr ) ; int query [ 5 ] [ 3 ] = { { 1 , 1 , 2 } , { 1 , 4 , 5 } , { 2 , 1 , 2 } , { 2 , 1 , 3 } , { 2 , 3 , 4 } } ; int record [ m ] ; memset ( record , 0 , sizeof record ) ; for ( int i = m - 1 ; i >= 0 ; i -- ) { if ( query [ i ] [ 0 ] == 2 ) record_sum ( record , query [ i ] [ 1 ] - 1 , query [ i ] [ 2 ] - 1 , m , record [ i ] + 1 ) ; else record_sum ( record , i , i , m , 1 ) ; } for ( int i = 0 ; i < m ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) record_sum ( arr , query [ i ] [ 1 ] - 1 , query [ i ] [ 2 ] - 1 , n , record [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << ' ▁ ' ; return 0 ; }

Index/key variables: i, m, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define max  10000
using namespace std ; void update ( int arr [ ] , int l ) { arr [ l ] += arr [ l - 1 ] ; } void record_func ( int block_size , int block [ ] , int record [ ] , int l , int r , int value ) { while ( l < r && l % block_size != 0 && l != 0 ) { record [ l ] += value ; l ++ ; } while ( l + block_size <= r + 1 ) { block [ l / block_size ] += value ; l += block_size ; } while ( l <= r ) { record [ l ] += value ; l ++ ; } } void print ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int n = 5 , m = 5 ; int arr [ n ] , record [ m ] ; int block_size = sqrt ( m ) ; int block [ max ] ; int command [ 5 ] [ 3 ] = { { 1 , 1 , 2 } , { 1 , 4 , 5 } , { 2 , 1 , 2 } , { 2 , 1 , 3 } , { 2 , 3 , 4 } } ; memset ( arr , 0 , sizeof arr ) ; memset ( record , 0 , sizeof record ) ; memset ( block , 0 , sizeof block ) ; for ( int i = m - 1 ; i >= 0 ; i -- ) { if ( command [ i ] [ 0 ] == 2 ) { int x = i / ( block_size ) ; record_func ( block_size , block , record , command [ i ] [ 1 ] - 1 , command [ i ] [ 2 ] - 1 , ( block [ x ] + record [ i ] + 1 ) ) ; } else record [ i ] ++ ; } for ( int i = 0 ; i < m ; i ++ ) { int check = ( i / block_size ) ; record [ i ] += block [ check ] ; } for ( int i = 0 ; i < m ; i ++ ) { if ( command [ i ] [ 0 ] == 1 ) { arr [ command [ i ] [ 1 ] - 1 ] += record [ i ] ; if ( ( command [ i ] [ 2 ] - 1 ) < n - 1 ) arr [ ( command [ i ] [ 2 ] ) ] -= record [ i ] ; } } for ( int i = 1 ; i < n ; i ++ ) update ( arr , i ) ; print ( arr , n ) ; return 0 ; }

Index/key variables: check, i, l, m, max, n, x
Accumulator variables: i, l, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void updateBIT ( int BITree [ ] , int n , int index , int val ) { index = index + 1 ; while ( index <= n ) { BITree [ index ] = ( val + BITree [ index ] ) ; index = ( index + ( index & ( - index ) ) ) ; } return ; } int * constructBITree ( int n ) { int * BITree = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) BITree [ i ] = 0 ; return BITree ; } int getSum ( int BITree [ ] , int index ) { int sum = 0 ; index = index + 1 ; while ( index > 0 ) { sum = ( sum + BITree [ index ] ) ; index -= index & ( - index ) ; } return sum ; } void update ( int BITree [ ] , int l , int r , int n , int val ) { updateBIT ( BITree , n , l , val ) ; updateBIT ( BITree , n , r + 1 , - val ) ; return ; } int main ( ) { int n = 5 , m = 5 ; int temp [ 15 ] = { 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 } ; int q [ 5 ] [ 3 ] ; int j = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { q [ i ] [ 0 ] = temp [ j ++ ] ; q [ i ] [ 1 ] = temp [ j ++ ] ; q [ i ] [ 2 ] = temp [ j ++ ] ; } int * BITree = constructBITree ( m ) ; int * BITree2 = constructBITree ( n ) ; for ( int i = 1 ; i <= m ; i ++ ) cin >> q [ i ] [ 0 ] >> q [ i ] [ 1 ] >> q [ i ] [ 2 ] ; for ( int i = m ; i >= 1 ; i -- ) if ( q [ i ] [ 0 ] == 2 ) update ( BITree , q [ i ] [ 1 ] - 1 , q [ i ] [ 2 ] - 1 , m , 1 ) ; for ( int i = m ; i >= 1 ; i -- ) { if ( q [ i ] [ 0 ] == 2 ) { long int val = getSum ( BITree , i - 1 ) ; update ( BITree , q [ i ] [ 1 ] - 1 , q [ i ] [ 2 ] - 1 , m , val ) ; } } for ( int i = m ; i >= 1 ; i -- ) { if ( q [ i ] [ 0 ] == 1 ) { long int val = getSum ( BITree , i - 1 ) ; update ( BITree2 , q [ i ] [ 1 ] - 1 , q [ i ] [ 2 ] - 1 , n , ( val + 1 ) ) ; } } for ( int i = 1 ; i <= n ; i ++ ) cout << ( getSum ( BITree2 , i - 1 ) ) << " ▁ " ; return 0 ; }

Index/key variables: i, index
Accumulator variables: i, index, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Query { int L , R , X ; } ; const int maxn = 100 ; int root [ maxn ] ; int find ( int x ) { return x == root [ x ] ? x : root [ x ] = find ( root [ x ] ) ; } int uni ( int x , int y ) { int p = find ( x ) , q = find ( y ) ; if ( p != q ) { root [ p ] = root [ q ] ; } } void initialize ( int a [ ] , int n , Query q [ ] , int m ) { for ( int i = 0 ; i < n ; i ++ ) root [ i ] = i ; for ( int i = 1 ; i < n ; i ++ ) if ( a [ i ] == a [ i - 1 ] ) uni ( i , i - 1 ) ; } int main ( ) { int a [ ] = { 1 , 1 , 5 , 4 , 5 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Query q [ ] = { { 0 , 2 , 2 } , { 1 , 4 , 1 } , { 2 , 4 , 5 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; initialize ( a , n , q , m ) ; for ( int i = 0 ; i < m ; i ++ ) { int flag = 0 ; int l = q [ i ] . L , r = q [ i ] . R , x = q [ i ] . X ; int p = r ; while ( p >= l ) { if ( a [ p ] == x ) { flag = 1 ; break ; } p = find ( p ) - 1 ; } if ( flag != 0 ) cout << x << " ▁ exists ▁ between ▁ [ " << l << " , ▁ " << r << " ] ▁ " << endl ; else cout << x << " ▁ does ▁ not ▁ exist ▁ between ▁ [ " << l << " , ▁ " << r << " ] ▁ " << endl ; } }

Index/key variables: i, maxn, p, q, x
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCountOfPairs ( int a , int b , int n ) { int ans = 0 ; for ( int i = 1 ; i <= a ; i ++ ) { ans += b / n ; ans += ( i % n + b % n ) >= n ? 1 : 0 ; } return ans ; } int main ( ) { int a = 5 , b = 13 , n = 3 ; cout << findCountOfPairs ( a , b , n ) ; return 0 ; }

Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCountOfPairs ( int a , int b , int n ) { if ( a > b ) { swap ( a , b ) ; } int temp = 1 , count = 0 ; for ( int i = n ; temp > 0 ; i += n ) { if ( a >= i ) { temp = i - 1 ; } else if ( b >= i ) { temp = a ; } else if ( i > b ) { temp = a - ( i - b ) + 1 ; } if ( temp > 0 ) { count += temp ; } } return count ; } int main ( ) { int a = 5 , b = 13 , n = 3 ; cout << findCountOfPairs ( a , b , n ) ; return 0 ; }

Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solveQuery ( int start , int end , int arr [ ] ) { unordered_map < int , int > frequency ; for ( int i = start ; i <= end ; i ++ ) frequency [ arr [ i ] ] ++ ; int count = 0 ; for ( auto x : frequency ) if ( x . first == x . second ) count ++ ; return count ; } int main ( ) { int A [ ] = { 1 , 2 , 2 , 3 , 3 , 3 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int queries [ ] [ 3 ] = { { 0 , 1 } , { 1 , 1 } , { 0 , 2 } , { 1 , 3 } , { 3 , 5 } , { 0 , 5 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) { int start = queries [ i ] [ 0 ] ; int end = queries [ i ] [ 1 ] ; cout << " Answer ▁ for ▁ Query ▁ " << ( i + 1 ) << " ▁ = ▁ " << solveQuery ( start , end , A ) << endl ; } return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minItems ( int k , int r ) { for ( int i = 1 ; i < 10 ; i ++ ) if ( ( i * k - r ) % 10 == 0 || ( i * k ) % 10 == 0 ) return i ; return 10 ; } int main ( ) { int k = 15 ; int r = 2 ; cout << minItems ( k , r ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int answer_query ( int a [ ] , int n , int l , int r ) { int count = 0 ; for ( int i = l ; i < r ; i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ; return count ; } int main ( ) { int a [ ] = { 1 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int L , R ; L = 1 ; R = 8 ; cout << answer_query ( a , n , L , R ) << endl ; L = 0 ; R = 4 ; cout << answer_query ( a , n , L , R ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; map < int , int > grid ; struct Node * newNode ( int data ) { struct Node * Node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; Node -> data = data ; Node -> left = Node -> right = NULL ; return Node ; } void addConsideringGrid ( Node * root , int level , int index ) { if ( root == NULL ) return ; grid [ level - index ] += ( root -> data ) ; addConsideringGrid ( root -> left , level + 1 , index - 1 ) ; addConsideringGrid ( root -> right , level + 1 , index + 1 ) ; } vector < int > diagonalSum ( Node * root ) { grid . clear ( ) ; addConsideringGrid ( root , 0 , 0 ) ; vector < int > ans ; for ( auto x : grid ) { ans . push_back ( x . second ) ; } return ans ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 9 ) ; root -> left -> right = newNode ( 6 ) ; root -> right -> left = newNode ( 4 ) ; root -> right -> right = newNode ( 5 ) ; root -> right -> left -> right = newNode ( 7 ) ; root -> right -> left -> left = newNode ( 12 ) ; root -> left -> right -> left = newNode ( 11 ) ; root -> left -> left -> right = newNode ( 10 ) ; vector < int > v = diagonalSum ( root ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) cout << v [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 1000 ; int prefixans [ N ] ; int countIndex ( int a [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == a [ i + 1 ] ) prefixans [ i ] = 1 ; if ( i != 0 ) prefixans [ i ] += prefixans [ i - 1 ] ; } } int answer_query ( int l , int r ) { if ( l == 0 ) return prefixans [ r - 1 ] ; else return prefixans [ r - 1 ] - prefixans [ l - 1 ] ; } int main ( ) { int a [ ] = { 1 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; countIndex ( a , n ) ; int L , R ; L = 1 ; R = 8 ; cout << answer_query ( L , R ) << endl ; L = 0 ; R = 4 ; cout << answer_query ( L , R ) << endl ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int primeSubarrays ( int A [ ] , int n ) { int max_val = int ( pow ( 10 , 7 ) ) ; vector < bool > prime ( max_val + 1 , true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int cnt = 0 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { int val = A [ i ] ; for ( int j = i + 1 ; j < n ; ++ j ) { val += A [ j ] ; if ( prime [ val ] ) ++ cnt ; } } return cnt ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << primeSubarrays ( A , n ) ; return 0 ; }

Index/key variables: i, j, p, val
Accumulator variables: i, p, stdc, val
Iterator variables: i, j, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int repeated_digit ( int n ) { unordered_set < int > s ; while ( n != 0 ) { int d = n % 10 ; if ( s . find ( d ) != s . end ( ) ) { return 0 ; } s . insert ( d ) ; n = n / 10 ; } return 1 ; } int calculate ( int L , int R ) { int answer = 0 ; for ( int i = L ; i < R + 1 ; ++ i ) { answer = answer + repeated_digit ( i ) ; } return answer ; } int main ( ) { int L = 1 , R = 100 ; cout << calculate ( L , R ) ; return 0 ; }

Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMinSwaps ( string st ) { int min_swaps = 0 ; int odd_0 = 0 , even_0 = 0 ; int odd_1 = 0 , even_1 = 0 ; int n = st . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( st [ i ] == '1' ) even_1 ++ ; else even_0 ++ ; } else { if ( st [ i ] == '1' ) odd_1 ++ ; else odd_0 ++ ; } } int cnt_swaps_1 = min ( even_0 , odd_1 ) ; int cnt_swaps_2 = min ( even_1 , odd_0 ) ; return min ( cnt_swaps_1 , cnt_swaps_2 ) ; } int main ( ) { string st = "000111" ; cout << countMinSwaps ( st ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: even_0, even_1, i, odd_0, odd_1, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MAX = 1000 ; vector < int > Prefix = { 0 } ; int repeated_digit ( int n ) { unordered_set < int > a ; int d ; while ( n != 0 ) { d = n % 10 ; if ( a . find ( d ) != a . end ( ) ) return 0 ; a . insert ( d ) ; n = n / 10 ; } return 1 ; } void pre_calculation ( int MAX ) { Prefix . push_back ( repeated_digit ( 1 ) ) ; for ( int i = 2 ; i < MAX + 1 ; i ++ ) Prefix . push_back ( repeated_digit ( i ) + Prefix [ i - 1 ] ) ; } int calculate ( int L , int R ) { return Prefix [ R ] - Prefix [ L - 1 ] ; } int main ( ) { int L = 1 , R = 100 ; pre_calculation ( MAX ) ; cout << calculate ( L , R ) << endl ; return 0 ; }

Index/key variables: R
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > initializeDiffArray ( vector < int > & A ) { int n = A . size ( ) ; vector < int > D ( n + 1 ) ; D [ 0 ] = A [ 0 ] , D [ n ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) D [ i ] = A [ i ] - A [ i - 1 ] ; return D ; } void update ( vector < int > & D , int l , int r , int x ) { D [ l ] += x ; D [ r + 1 ] -= x ; } int printArray ( vector < int > & A , vector < int > & D ) { for ( int i = 0 ; i < A . size ( ) ; i ++ ) { if ( i == 0 ) A [ i ] = D [ i ] ; else A [ i ] = D [ i ] + A [ i - 1 ] ; cout << A [ i ] << " ▁ " ; } cout << endl ; } int main ( ) { vector < int > A { 10 , 5 , 20 , 40 } ; vector < int > D = initializeDiffArray ( A ) ; update ( D , 0 , 1 , 10 ) ; printArray ( A , D ) ; update ( D , 1 , 3 , 20 ) ; update ( D , 2 , 2 , 30 ) ; printArray ( A , D ) ; return 0 ; }

Index/key variables: i, l, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int modpow ( long long int base , long long int exp , long long int modulus ) { base %= modulus ; long long int result = 1 ; while ( exp > 0 ) { if ( exp & 1 ) result = ( result * base ) % modulus ; base = ( base * base ) % modulus ; exp >>= 1 ; } return result ; } int main ( ) { long long int n = 654654 , mod = 971 ; cout << ( ( ( modpow ( n , 6 , mod ) + modpow ( n , 2 , mod ) ) % mod + 355 ) % mod ) ; return 0 ; }

Accumulator variables: stdc