dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int key ; Node * left , * right ; Node ( int key_ ) { key = key_ ; left = NULL ; right = NULL ; } } ; int sumOfLeftLeaves ( Node * root ) { if ( root == NULL ) return 0 ; queue < pair < Node * , bool > > q ; q . push ( { root , 0 } ) ; int sum = 0 ; while ( ! q . empty ( ) ) { Node * temp = q . front ( ) . first ; bool is_left_child = q . front ( ) . second ; q . pop ( ) ; if ( ! temp -> left && ! temp -> right && is_left_child ) sum = sum + temp -> key ; if ( temp -> left ) { q . push ( { temp -> left , 1 } ) ; } if ( temp -> right ) { q . push ( { temp -> right , 0 } ) ; } } return sum ; } int main ( ) { Node * root = new Node ( 20 ) ; root -> left = new Node ( 9 ) ; root -> right = new Node ( 49 ) ; root -> right -> left = new Node ( 23 ) ; root -> right -> right = new Node ( 52 ) ; root -> right -> right -> left = new Node ( 50 ) ; root -> left -> left = new Node ( 5 ) ; root -> left -> right = new Node ( 12 ) ; root -> left -> right -> right = new Node ( 12 ) ; cout << " Sum ▁ of ▁ left ▁ leaves ▁ is ▁ " << sumOfLeftLeaves ( root ) << endl ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; int countNestedPolygons ( int sides ) { int count = 0 ; while ( sides > 5 ) { sides /= 2 ; count += 1 ; } return count ; } int main ( ) { int N = 12 ; cout << countNestedPolygons ( N ) ; return 0 ; }

Accumulator variables: count, sides
C++ program:
#include <bits/stdc++.h>
using namespace std ; void print2largest ( int arr [ ] , int arr_size ) { int i , first , second ; if ( arr_size < 2 ) { printf ( " ▁ Invalid ▁ Input ▁ " ) ; return ; } int largest = second = INT_MIN ; for ( int i = 0 ; i < arr_size ; i ++ ) { largest = max ( largest , arr [ i ] ) ; } for ( int i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] != largest ) second = max ( second , arr [ i ] ) ; } if ( second == INT_MIN ) printf ( " There ▁ is ▁ no ▁ second ▁ largest ▁ element STRNEWLINE " ) ; else printf ( " The ▁ second ▁ largest ▁ element ▁ is ▁ % d STRNEWLINE " , second ) ; } int main ( ) { int arr [ ] = { 12 , 35 , 1 , 10 , 34 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; print2largest ( 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 print2largest ( int arr [ ] , int arr_size ) { int i , first , second ; if ( arr_size < 2 ) { cout << " ▁ Invalid ▁ Input ▁ " ; return ; } first = second = INT_MIN ; for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second && arr [ i ] != first ) { second = arr [ i ] ; } } if ( second == INT_MIN ) cout << " There ▁ is ▁ no ▁ second ▁ largest " " element STRNEWLINE " ; else cout << " The ▁ second ▁ largest ▁ element ▁ is ▁ " << second ; } int main ( ) { int arr [ ] = { 12 , 35 , 1 , 10 , 34 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; print2largest ( 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 queryResult ( int prefix [ ] , pair < int , int > Q ) { int l = Q . first ; int r = Q . second ; if ( l == 0 ) { int xorval = prefix [ r ] ; cout << __builtin_popcount ( xorval ) << endl ; } else { int xorval = prefix [ r ] ^ prefix [ l - 1 ] ; cout << __builtin_popcount ( xorval ) << endl ; } } void calculateCount ( string S , pair < int , int > Q [ ] , int m ) { int n = S . length ( ) ; int arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = ( 1 << ( S [ i ] - ' a ' ) ) ; } int prefix [ n ] ; int x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x ^= arr [ i ] ; prefix [ i ] = x ; } for ( int i = 0 ; i < m ; i ++ ) { queryResult ( prefix , Q [ i ] ) ; } } int main ( ) { string S = " geeksforgeeks " ; pair < int , int > Q [ ] = { { 2 , 4 } , { 0 , 3 } , { 0 , 12 } } ; calculateCount ( S , Q , 3 ) ; }

Index/key variables: i, n, r
Accumulator variables: i, stdc, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long countStrings ( long long A , long long B , long long K ) { long long X = ( A + B ) / ( K + 1 ) ; return ( min ( A , min ( B , X ) ) * ( K + 1 ) ) ; } int main ( ) { long long N = 101 , M = 231 , K = 15 ; cout << countStrings ( N , M , K ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void UniqueMatrix ( int N ) { int element_value = 1 ; int i = 0 ; while ( i < N ) { if ( i % 2 == 0 ) { for ( int f = element_value ; f < element_value + N ; f ++ ) { cout << f << " ▁ " ; } element_value += N ; } else { for ( int k = element_value + N - 1 ; k > element_value - 1 ; k -- ) { cout << k << " ▁ " ; } element_value += N ; } cout << endl ; i = i + 1 ; } } int main ( ) { int N = 4 ; UniqueMatrix ( N ) ; }

Accumulator variables: element_value, f, k, stdc
Iterator variables: f, k
C++ program:
#include <iostream>
using namespace std ; struct Pair { int min ; int max ; } ; struct Pair getMinMax ( int arr [ ] , int n ) { struct Pair minmax ; int i ; if ( n == 1 ) { minmax . max = arr [ 0 ] ; minmax . min = arr [ 0 ] ; return minmax ; } if ( arr [ 0 ] > arr [ 1 ] ) { minmax . max = arr [ 0 ] ; minmax . min = arr [ 1 ] ; } else { minmax . max = arr [ 1 ] ; minmax . min = arr [ 0 ] ; } for ( i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > minmax . max ) minmax . max = arr [ i ] ; else if ( arr [ i ] < minmax . min ) minmax . min = arr [ i ] ; } return minmax ; } int main ( ) { int arr [ ] = { 1000 , 11 , 445 , 1 , 330 , 3000 } ; int arr_size = 6 ; struct Pair minmax = getMinMax ( arr , arr_size ) ; cout << " Minimum ▁ element ▁ is ▁ " << minmax . min << endl ; cout << " Maximum ▁ element ▁ is ▁ " << minmax . max ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Pair
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumNodes ( int l ) { int leafNodeCount = pow ( 2 , l - 1 ) ; vector < int > vec [ l ] ; for ( int i = 1 ; i <= leafNodeCount ; i ++ ) vec [ l - 1 ] . push_back ( i ) ; for ( int i = l - 2 ; i >= 0 ; i -- ) { int k = 0 ; while ( k < vec [ i + 1 ] . size ( ) - 1 ) { vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ; k += 2 ; } } int sum = 0 ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 0 ; j < vec [ i ] . size ( ) ; j ++ ) sum += vec [ i ] [ j ] ; } return sum ; } int main ( ) { int l = 3 ; cout << sumNodes ( l ) ; return 0 ; }

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, stdc, sum
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; struct Pair { int min ; int max ; } ; struct Pair getMinMax ( int arr [ ] , int n ) { struct Pair minmax ; int i ; if ( n % 2 == 0 ) { if ( arr [ 0 ] > arr [ 1 ] ) { minmax . max = arr [ 0 ] ; minmax . min = arr [ 1 ] ; } else { minmax . min = arr [ 0 ] ; minmax . max = arr [ 1 ] ; } i = 2 ; } else { minmax . min = arr [ 0 ] ; minmax . max = arr [ 0 ] ; i = 1 ; } while ( i < n - 1 ) { if ( arr [ i ] > arr [ i + 1 ] ) { if ( arr [ i ] > minmax . max ) minmax . max = arr [ i ] ; if ( arr [ i + 1 ] < minmax . min ) minmax . min = arr [ i + 1 ] ; } else { if ( arr [ i + 1 ] > minmax . max ) minmax . max = arr [ i + 1 ] ; if ( arr [ i ] < minmax . min ) minmax . min = arr [ i ] ; } i += 2 ; } return minmax ; } int main ( ) { int arr [ ] = { 1000 , 11 , 445 , 1 , 330 , 3000 } ; int arr_size = 6 ; Pair minmax = getMinMax ( arr , arr_size ) ; cout << " nMinimum ▁ element ▁ is ▁ " << minmax . min << endl ; cout << " nMaximum ▁ element ▁ is ▁ " << minmax . max ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Class/struct names: Pair
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Query { int L , R ; } ; void printQuerySums ( int a [ ] , int n , Query q [ ] , int m ) { for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; int sum = 0 ; for ( int j = L ; j <= R ; j ++ ) sum += a [ j ] ; cout << " Sum ▁ of ▁ [ " << L << " , ▁ " << R << " ] ▁ is ▁ " << sum << endl ; } } int main ( ) { int a [ ] = { 1 , 1 , 2 , 1 , 3 , 4 , 5 , 2 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Query q [ ] = { { 0 , 4 } , { 1 , 3 } , { 2 , 4 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; printQuerySums ( a , n , q , m ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long findways ( string s , int x ) { if ( x > ( int ) s . length ( ) ) return 0 ; long long int n = ( int ) s . length ( ) ; int freq [ 26 ] ; memset ( freq , 0 , sizeof freq ) ; for ( int i = 0 ; i < n ; ++ i ) freq [ s [ i ] - ' a ' ] ++ ; multiset < int > se ; for ( int i = 0 ; i < 26 ; ++ i ) if ( freq [ i ] > 0 ) se . insert ( freq [ i ] ) ; long long ans = 1 ; for ( int i = 0 ; i < x / 2 ; ++ i ) { long long int count = 0 ; for ( auto u : se ) { if ( u >= 2 ) count ++ ; } if ( count == 0 ) return 0 ; else ans = ans * count ; auto p = se . end ( ) ; p -- ; int val = * p ; se . erase ( p ) ; if ( val > 2 ) se . insert ( val - 2 ) ; } if ( x % 2 != 0 ) { long long int count = 0 ; for ( auto u : se ) if ( u > 0 ) count ++ ; ans = ans * count ; } return ans ; } int main ( ) { string s = " aaa " ; int x = 2 ; cout << findways ( s , x ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, p, stdc
Iterator variables: i, u
C++ program:
#include <iostream>
using namespace std ; int findIfPossible ( int n , int a , int b ) { if ( b % a != 0 ) { if ( n == 1 ) return 0 ; else if ( n % b != 0 ) return -1 ; else return ( int ) n / b ; } int c = b / a ; int x = 0 , y = 0 ; while ( n % b == 0 ) { n = n / b ; x ++ ; } while ( n % c == 0 ) { n = n / c ; y ++ ; } if ( n == 1 ) { int total_steps = x + ( 2 * y ) ; return total_steps ; } else return -1 ; } int main ( ) { int n = 48 ; int a = 3 , b = 12 ; cout << findIfPossible ( n , a , b ) ; return 0 ; }

Accumulator variables: x, y
C++ program:
#include " iostream "
#include " math . h "
using namespace std ; #define MAXN  10000
#define SQRSIZE  100
int arr [ MAXN ] ; int block [ SQRSIZE ] ; int blk_sz ; void update ( int idx , int val ) { int blockNumber = idx / blk_sz ; block [ blockNumber ] += val - arr [ idx ] ; arr [ idx ] = val ; } int query ( int l , int r ) { int sum = 0 ; while ( l < r and l % blk_sz != 0 and l != 0 ) { sum += arr [ l ] ; l ++ ; } while ( l + blk_sz <= r ) { sum += block [ l / blk_sz ] ; l += blk_sz ; } while ( l <= r ) { sum += arr [ l ] ; l ++ ; } return sum ; } void preprocess ( int input [ ] , int n ) { int blk_idx = -1 ; blk_sz = sqrt ( n ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = input [ i ] ; if ( i % blk_sz == 0 ) { blk_idx ++ ; } block [ blk_idx ] += arr [ i ] ; } } int main ( ) { int input [ ] = { 1 , 5 , 2 , 4 , 6 , 1 , 3 , 5 , 7 , 10 } ; int n = sizeof ( input ) / sizeof ( input [ 0 ] ) ; preprocess ( input , n ) ; cout << " query ( 3,8 ) ▁ : ▁ " << query ( 3 , 8 ) << endl ; cout << " query ( 1,6 ) ▁ : ▁ " << query ( 1 , 6 ) << endl ; update ( 8 , 0 ) ; cout << " query ( 8,8 ) ▁ : ▁ " << query ( 8 , 8 ) << endl ; return 0 ; }

Index/key variables: MAXN, SQRSIZE, blk_idx, blockNumber, i, idx, l
Accumulator variables: blk_idx, i, l, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; string removeLeadingZeros ( string str ) { int i = 0 ; int n = str . length ( ) ; while ( str [ i ] == '0' && i < n ) i ++ ; str . erase ( 0 , i ) ; return str ; } void findPairs ( int sum , int K ) { string A , B ; A = " " ; B = " " ; string N = to_string ( sum ) ; int n = N . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int D = N [ i ] - '0' ; if ( D == K ) { int D1 , D2 ; D1 = D / 2 ; D2 = D / 2 + D % 2 ; A = A + char ( D1 + '0' ) ; B = B + char ( D2 + '0' ) ; } else { A = A + char ( D + '0' ) ; B = B + '0' ; } } A = removeLeadingZeros ( A ) ; B = removeLeadingZeros ( B ) ; cout << A << " , ▁ " << B << endl ; } int main ( ) { int N = 33673 ; int K = 3 ; findPairs ( N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  500
int lookup [ MAX ] [ MAX ] ; struct Query { int L , R ; } ; void preprocess ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) lookup [ i ] [ i ] = i ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ lookup [ i ] [ j - 1 ] ] < arr [ j ] ) lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ] ; else lookup [ i ] [ j ] = j ; } } void RMQ ( int arr [ ] , int n , Query q [ ] , int m ) { preprocess ( arr , n ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; cout << " Minimum ▁ of ▁ [ " << L << " , ▁ " << R << " ] ▁ is ▁ " << arr [ lookup [ L ] [ R ] ] << endl ; } } int main ( ) { int a [ ] = { 7 , 2 , 3 , 0 , 5 , 10 , 3 , 12 , 18 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Query q [ ] = { { 0 , 4 } , { 4 , 7 } , { 7 , 8 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; RMQ ( a , n , q , m ) ; return 0 ; }

Index/key variables: L, MAX, R, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  500
int lookup [ MAX ] [ MAX ] ; struct Query { int L , R ; } ; void preprocess ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) lookup [ i ] [ 0 ] = i ; for ( int j = 1 ; ( 1 << j ) <= n ; j ++ ) { for ( int i = 0 ; ( i + ( 1 << j ) - 1 ) < n ; i ++ ) { if ( arr [ lookup [ i ] [ j - 1 ] ] < arr [ lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ] ) lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ] ; else lookup [ i ] [ j ] = lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ; } } } int query ( int arr [ ] , int L , int R ) { int j = ( int ) log2 ( R - L + 1 ) ; if ( arr [ lookup [ L ] [ j ] ] <= arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ) return arr [ lookup [ L ] [ j ] ] ; else return arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ; } void RMQ ( int arr [ ] , int n , Query q [ ] , int m ) { preprocess ( arr , n ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; cout << " Minimum ▁ of ▁ [ " << L << " , ▁ " << R << " ] ▁ is ▁ " << query ( arr , L , R ) << endl ; } } int main ( ) { int a [ ] = { 7 , 2 , 3 , 0 , 5 , 10 , 3 , 12 , 18 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Query q [ ] = { { 0 , 4 } , { 4 , 7 } , { 7 , 8 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; RMQ ( a , n , q , m ) ; return 0 ; }

Index/key variables: L, MAX, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumNodes ( int l ) { int leafNodeCount = pow ( 2 , l - 1 ) ; int sumLastLevel = 0 ; sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ; int sum = sumLastLevel * l ; return sum ; } int main ( ) { int l = 3 ; cout << sumNodes ( l ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 100005 ] [ 27 ] ; int calculate ( int pos , int prev , string & s ) { if ( pos == s . length ( ) ) { return 0 ; } if ( dp [ pos ] [ prev ] != -1 ) return dp [ pos ] [ prev ] ; int val = 0 ; if ( s [ pos ] - ' a ' + 1 != prev ) { val = max ( val , 1 + calculate ( pos + 1 , s [ pos ] - ' a ' + 1 , s ) ) ; } val = max ( val , calculate ( pos + 1 , prev , s ) ) ; return dp [ pos ] [ prev ] = val ; } int longestSubsequence ( string s ) { int n = s . length ( ) ; memset ( dp , -1 , sizeof ( dp ) ) ; return calculate ( 0 , 0 , s ) ; } int main ( ) { string str = " ababa " ; cout << longestSubsequence ( str ) ; return 0 ; }

Index/key variables: pos, prev
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void add ( int arr [ ] , int N , int lo , int hi , int val ) { arr [ lo ] += val ; if ( hi != N - 1 ) arr [ hi + 1 ] -= val ; } void updateArray ( int arr [ ] , int N ) { for ( int i = 1 ; i < N ; i ++ ) arr [ i ] += arr [ i - 1 ] ; } void printArr ( int arr [ ] , int N ) { updateArray ( arr , N ) ; for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } int main ( ) { int N = 6 ; int arr [ N ] = { 0 } ; add ( arr , N , 0 , 2 , 100 ) ; add ( arr , N , 1 , 5 , 100 ) ; add ( arr , N , 2 , 3 , 100 ) ; printArr ( arr , N ) ; return 0 ; }

Index/key variables: N, i, lo
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find_count ( vector < int > arr , int k ) { int ans = 0 ; for ( int i : arr ) { int x = __builtin_popcount ( i ) ; if ( x % k == 0 ) ans += 1 ; } return ans ; } int main ( ) { vector < int > arr = { 12 , 345 , 2 , 68 , 7896 } ; int K = 2 ; cout << find_count ( arr , K ) ; return 0 ; }

Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void KPrimeDivisors ( int N , int K ) { int maximum_split = 0 ; while ( N % 2 == 0 ) { maximum_split ++ ; N /= 2 ; } for ( int i = 3 ; i * i <= N ; i = i + 2 ) { while ( N % i == 0 ) { N = N / i ; maximum_split ++ ; } } if ( N > 2 ) maximum_split ++ ; if ( maximum_split < K ) { printf ( " No STRNEWLINE " ) ; return ; } printf ( " Yes STRNEWLINE " ) ; } int main ( ) { int N = 12 ; int K = 3 ; KPrimeDivisors ( N , K ) ; return 0 ; }

Accumulator variables: N, maximum_split, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProfit ( int n , int k , int prices [ ] ) { int ans = 0 , buy = 0 , sell = 0 ; stack < pair < int , int > > transaction ; priority_queue < int > profits ; while ( sell < n ) { buy = sell ; while ( buy < n - 1 && prices [ buy ] >= prices [ buy + 1 ] ) buy ++ ; sell = buy + 1 ; while ( sell < n && prices [ sell ] >= prices [ sell - 1 ] ) sell ++ ; while ( ! transaction . empty ( ) && prices [ buy ] < prices [ transaction . top ( ) . first ] ) { pair < int , int > p = transaction . top ( ) ; profits . push ( prices [ p . second - 1 ] - prices [ p . first ] ) ; transaction . pop ( ) ; } while ( ! transaction . empty ( ) && prices [ sell - 1 ] > prices [ transaction . top ( ) . second - 1 ] ) { pair < int , int > p = transaction . top ( ) ; profits . push ( prices [ p . second - 1 ] - prices [ buy ] ) ; buy = p . first ; transaction . pop ( ) ; } transaction . push ( { buy , sell } ) ; } while ( ! transaction . empty ( ) ) { profits . push ( prices [ transaction . top ( ) . second - 1 ] - prices [ transaction . top ( ) . first ] ) ; transaction . pop ( ) ; } while ( k && ! profits . empty ( ) ) { ans += profits . top ( ) ; profits . pop ( ) ; -- k ; } return ans ; } int main ( ) { int k = 3 ; int prices [ ] = { 1 , 12 , 10 , 7 , 10 , 13 , 11 , 10 , 7 , 6 , 9 } ; int n = sizeof ( prices ) / sizeof ( prices [ 0 ] ) ; cout << " Maximum ▁ profit ▁ is ▁ " << maxProfit ( n , k , prices ) ; return 0 ; }

Index/key variables: buy, sell
Accumulator variables: ans, buy, sell, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int * st ; int constructST ( int arr [ ] , int ss , int se , int si ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return st [ si ] ; } int mid = ss + ( se - ss ) / 2 ; st [ si ] = __gcd ( constructST ( arr , ss , mid , si * 2 + 1 ) , constructST ( arr , mid + 1 , se , si * 2 + 2 ) ) ; return st [ si ] ; } int * constructSegmentTree ( int arr [ ] , int n ) { int height = ( int ) ( ceil ( log2 ( n ) ) ) ; int size = 2 * ( int ) pow ( 2 , height ) - 1 ; st = new int [ size ] ; constructST ( arr , 0 , n - 1 , 0 ) ; return st ; } int findGcd ( int ss , int se , int qs , int qe , int si ) { if ( ss > qe se < qs ) return 0 ; if ( qs <= ss && qe >= se ) return st [ si ] ; int mid = ss + ( se - ss ) / 2 ; return __gcd ( findGcd ( ss , mid , qs , qe , si * 2 + 1 ) , findGcd ( mid + 1 , se , qs , qe , si * 2 + 2 ) ) ; } int findRangeGcd ( int ss , int se , int arr [ ] , int n ) { if ( ss < 0 se > n -1 ss > se ) { cout << " Invalid ▁ Arguments " << " STRNEWLINE " ; return - 1 ; } return findGcd ( 0 , n - 1 , ss , se , 0 ) ; } int main ( ) { int a [ ] = { 2 , 3 , 6 , 9 , 5 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; constructSegmentTree ( a , n ) ; int l = 1 ; int r = 3 ; cout << " GCD ▁ of ▁ the ▁ given ▁ range ▁ is : " ; cout << findRangeGcd ( l , r , a , n ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: si, size, ss
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( int L , int R ) { vector < int > arr ; int i = 0 ; int x = 2 ; while ( i <= R ) { arr . push_back ( i + x ) ; if ( i + 1 <= R ) arr . push_back ( i + 1 + x ) ; x *= -1 ; i += 2 ; } int sum = 0 ; for ( int i = L ; i <= R ; ++ i ) sum += arr [ i ] ; return sum ; } int main ( ) { int L = 0 , R = 5 ; cout << findSum ( L , R ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void FillPrefixSuffix ( int prefix [ ] , int arr [ ] , int suffix [ ] , int n ) { prefix [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefix [ i ] = __gcd ( prefix [ i - 1 ] , arr [ i ] ) ; suffix [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffix [ i ] = __gcd ( suffix [ i + 1 ] , arr [ i ] ) ; } int GCDoutsideRange ( int l , int r , int prefix [ ] , int suffix [ ] , int n ) { if ( l == 0 ) return suffix [ r + 1 ] ; if ( r == n - 1 ) return prefix [ l - 1 ] ; return __gcd ( prefix [ l - 1 ] , suffix [ r + 1 ] ) ; } int main ( ) { int arr [ ] = { 2 , 6 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int prefix [ n ] , suffix [ n ] ; FillPrefixSuffix ( prefix , arr , suffix , n ) ; int l = 0 , r = 0 ; cout << GCDoutsideRange ( l , r , prefix , suffix , n ) << endl ; l = 1 ; r = 1 ; cout << GCDoutsideRange ( l , r , prefix , suffix , n ) << endl ; l = 1 ; r = 2 ; cout << GCDoutsideRange ( l , r , prefix , suffix , n ) << endl ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int check ( int A [ ] , int B [ ] , int N ) { priority_queue < int > pq1 , pq2 ; for ( int i = 0 ; i < N ; i ++ ) { pq1 . push ( A [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) { pq2 . push ( B [ i ] ) ; } int c = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( pq1 . top ( ) > pq2 . top ( ) ) { c ++ ; pq1 . pop ( ) ; pq2 . pop ( ) ; } else { if ( pq2 . size ( ) == 0 ) { break ; } pq2 . pop ( ) ; } } return ( c ) ; } int main ( ) { int A [ ] = { 10 , 3 , 7 , 5 , 8 } ; int B [ ] = { 8 , 6 , 2 , 5 , 9 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << ( check ( A , B , N ) ) ; }

Index/key variables: i
Accumulator variables: c, i, stdc
Iterator variables: i