dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maximumMex ( int arr [ ] , int N ) { vector < int > ans ; sort ( arr , arr + N ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 arr [ i ] != arr [ i - 1 ] ) ans . push_back ( arr [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( i > 0 && arr [ i ] == arr [ i - 1 ] ) ans . push_back ( arr [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) cout << ans [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 0 , 0 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maximumMex ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > bubble_sort ( vector < int > ar ) { if ( ar . size ( ) <= 1 ) return ar ; if ( ar . size ( ) == 2 ) { if ( ar [ 0 ] < ar [ 1 ] ) return ar ; else return { ar [ 1 ] , ar [ 0 ] } ; } int a = ar [ 0 ] ; int b = ar [ 1 ] ; vector < int > bs ; for ( int i = 2 ; i < ar . size ( ) ; i ++ ) bs . push_back ( ar [ i ] ) ; vector < int > res ; if ( a < b ) { vector < int > temp1 ; temp1 . push_back ( b ) ; for ( int i = 0 ; i < bs . size ( ) ; i ++ ) temp1 . push_back ( bs [ i ] ) ; vector < int > v = bubble_sort ( temp1 ) ; v . insert ( v . begin ( ) , a ) ; res = v ; } else { vector < int > temp1 ; temp1 . push_back ( a ) ; for ( int i = 0 ; i < bs . size ( ) ; i ++ ) temp1 . push_back ( bs [ i ] ) ; vector < int > v = bubble_sort ( temp1 ) ; v . insert ( v . begin ( ) , b ) ; res = v ; } vector < int > pass ; for ( int i = 0 ; i < res . size ( ) - 1 ; i ++ ) pass . push_back ( res [ i ] ) ; vector < int > ans = bubble_sort ( pass ) ; ans . push_back ( res [ res . size ( ) - 1 ] ) ; return ans ; } int main ( ) { vector < int > arr { 1 , 3 , 4 , 5 , 6 , 2 } ; vector < int > res = bubble_sort ( arr ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) cout << res [ i ] << " ▁ " ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printMatrix ( vector < vector < int > > a ) { for ( auto x : a ) { for ( auto y : x ) { cout << y << " ▁ " ; } cout << " STRNEWLINE " ; } } void sortBoundaryWise ( vector < vector < int > > a ) { int i , k = 0 , l = 0 ; int m = a . size ( ) , n = a [ 0 ] . size ( ) ; int n_i , n_k = 0 , n_l = 0 , n_m = m , n_n = n ; while ( k < m && l < n ) { vector < int > boundary ; for ( i = l ; i < n ; ++ i ) { boundary . push_back ( a [ k ] [ i ] ) ; } k ++ ; for ( i = k ; i < m ; ++ i ) { boundary . push_back ( a [ i ] [ n - 1 ] ) ; } n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) { boundary . push_back ( a [ m - 1 ] [ i ] ) ; } m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) { boundary . push_back ( a [ i ] [ l ] ) ; } l ++ ; } sort ( boundary . begin ( ) , boundary . end ( ) ) ; int ind = 0 ; for ( i = n_l ; i < n_n ; ++ i ) { a [ n_k ] [ i ] = boundary [ ind ++ ] ; } n_k ++ ; for ( i = n_k ; i < n_m ; ++ i ) { a [ i ] [ n_n - 1 ] = boundary [ ind ++ ] ; } n_n -- ; if ( n_k < n_m ) { for ( i = n_n - 1 ; i >= n_l ; -- i ) { a [ n_m - 1 ] [ i ] = boundary [ ind ++ ] ; } n_m -- ; } if ( n_l < n_n ) { for ( i = n_m - 1 ; i >= n_k ; -- i ) { a [ i ] [ n_l ] = boundary [ ind ++ ] ; } n_l ++ ; } } printMatrix ( a ) ; } int main ( ) { vector < vector < int > > matrix = { { 9 , 7 , 4 , 5 } , { 1 , 6 , 2 , -6 } , { 12 , 20 , 2 , 0 } , { -5 , -6 , 7 , -2 } } ; sortBoundaryWise ( matrix ) ; return 0 ; }

Index/key variables: i, k, l, n_k, n_l
Accumulator variables: ind, k, l, m, n, n_k, n_l, n_m, n_n, stdc
Iterator variables: i, x, y
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimum_sum ( int A [ ] , int N ) { sort ( A , A + N ) ; int sum = INT_MAX ; for ( int i = 0 ; i <= N - 3 ; i ++ ) { sum = min ( sum , abs ( A [ i ] - A [ i + 1 ] ) + abs ( A [ i + 1 ] - A [ i + 2 ] ) ) ; } cout << sum ; } int main ( ) { int A [ ] = { 1 , 1 , 2 , 3 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; minimum_sum ( A , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sameChar ( string S , int N ) { sort ( S . begin ( ) , S . end ( ) ) ; int mid = S [ N / 2 ] ; int total_operations = 0 ; for ( int i = 0 ; i < N ; i ++ ) { total_operations += abs ( int ( S [ i ] ) - mid ) ; } cout << total_operations ; } int main ( ) { string S = " geeks " ; int N = S . size ( ) ; sameChar ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, total_operations
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxScore ( int i , int A [ ] , int K , int N , int dp [ ] ) { if ( i >= N - 1 ) return A [ N - 1 ] ; if ( dp [ i ] != -1 ) return dp [ i ] ; int score = INT_MIN ; for ( int j = 1 ; j <= K ; j ++ ) { score = max ( score , maxScore ( i + j , A , K , N , dp ) ) ; } return dp [ i ] = score + A [ i ] ; } int getScore ( int A [ ] , int N , int K ) { int dp [ N ] ; for ( int i = 0 ; i < N ; i ++ ) dp [ i ] = -1 ; cout << maxScore ( 0 , A , K , N , dp ) ; } int main ( ) { int A [ ] = { 100 , -30 , -50 , -15 , -20 , -30 } ; int K = 3 ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; getScore ( A , N , K ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct mycomp { bool operator() ( pair < int , int > p1 , pair < int , int > p2 ) { return p1 . first < p2 . first ; } } ; int maxScore ( int A [ ] , int K , int N ) { priority_queue < pair < int , int > , vector < pair < int , int > > , mycomp > maxheap ; int maxScore = 0 ; maxheap . push ( { A [ 0 ] , 0 } ) ; for ( int i = 1 ; i < N ; i ++ ) { while ( maxheap . top ( ) . second < ( i - K ) ) { maxheap . pop ( ) ; } maxScore = A [ i ] + maxheap . top ( ) . first ; maxheap . push ( { maxScore , i } ) ; } return maxScore ; } int main ( ) { int A [ ] = { -44 , -17 , -54 , 79 } ; int K = 2 ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << maxScore ( A , K , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: mycomp
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getCount ( int arr [ ] , int N ) { int count = 0 ; if ( N < 3 ) return 0 ; for ( int b = 0 ; b < N ; b ++ ) { for ( int a = 0 ; a < N ; a ++ ) { if ( a == b ) continue ; for ( int c = 0 ; c < N ; c ++ ) { if ( c == a c == b ) continue ; int d = arr [ b ] * arr [ b ] / 4 ; if ( arr [ a ] * arr <= d ) count ++ ; } } } return count ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getCount ( arr , N ) ; return 0 ; }

Index/key variables: a, b
Accumulator variables: a, b, c, count, stdc
Iterator variables: a, b, c
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool findAns ( int A [ ] , int N , int X ) { if ( check ( A , X , N ) ) { return true ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int g = __gcd ( A [ i ] , A [ j ] ) ; if ( g != 1 ) { if ( g <= X ) { return true ; } } } } return false ; } bool check ( int A [ ] , int X , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] > X ) { return false ; } } return true ; } int main ( ) { int X = 4 ; int A [ ] = { 2 , 1 , 5 , 3 , 6 } ; int N = 5 ; if ( findAns ( A , N , X ) ) { cout << " true " ; } else { cout << " false " ; } }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string check ( int a [ ] , int b [ ] , int Na , int Nb , int k , int m ) { if ( Na < k Nb < m ) return " No " ; sort ( a , a + Na ) ; sort ( b , b + Nb ) ; if ( a [ k - 1 ] < b [ Nb - m ] ) { return " Yes " ; } return " No " ; } int main ( ) { int arr1 [ ] = { 1 , 2 , 3 } ; int arr2 [ ] = { 3 , 4 , 5 } ; int N = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int M = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; int X = 2 , Y = 1 ; cout << check ( arr1 , arr2 , N , M , X , Y ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isIncreasing ( vector < int > arr ) { for ( int i = 0 ; i < arr . size ( ) - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } vector < int > sortArr ( vector < int > arr ) { int prev = -1 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { int optEle = arr [ i ] ; string strEle = to_string ( arr [ i ] ) ; for ( int idx = 0 ; idx < strEle . size ( ) ; idx ++ ) { string strEle2 = strEle . substr ( idx ) + strEle . substr ( 0 , idx ) ; int temp = stoi ( strEle2 ) ; if ( temp >= prev && temp < optEle ) optEle = temp ; } arr [ i ] = optEle ; prev = arr [ i ] ; } if ( isIncreasing ( arr ) ) return arr ; else { arr = { -1 } ; return arr ; } } int main ( ) { vector < int > arr = { 511 , 321 , 323 , 432 , 433 } ; vector < int > res = sortArr ( arr ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) cout << res [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, idx, stdc
Iterator variables: i, idx
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compareBy ( const pair < int , int > & a , const pair < int , int > & b ) { if ( a . second != b . second ) return a . second < b . second ; return a . first < b . first ; } int maximumShops ( int * opening , int * closing , int n , int k ) { pair < int , int > a [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] . first = opening [ i ] ; a [ i ] . second = closing [ i ] ; } sort ( a , a + n , compareBy ) ; int count = 0 ; multiset < int > st ; for ( int i = 0 ; i < n ; i ++ ) { bool flag = false ; if ( ! st . empty ( ) ) { auto it = st . upper_bound ( a [ i ] . first ) ; if ( it != st . begin ( ) ) { it -- ; if ( * it <= a [ i ] . first ) { st . erase ( it ) ; st . insert ( a [ i ] . second ) ; count ++ ; flag = true ; } } } if ( st . size ( ) < k && flag == false ) { st . insert ( a [ i ] . second ) ; count ++ ; } } return count ; } int main ( ) { int S [ ] = { 1 , 8 , 3 , 2 , 6 } ; int E [ ] = { 5 , 10 , 6 , 5 , 9 } ; int K = 2 , N = sizeof ( S ) / sizeof ( S [ 0 ] ) ; cout << maximumShops ( S , E , N , K ) << endl ; }

Index/key variables: i, n
Accumulator variables: count, i, it, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxSum ( int * arr , int * brr , int N , int K ) { vector < int > crr ; for ( int i = 0 ; i < N ; i ++ ) { crr . push_back ( arr [ i ] ) ; } for ( int i = 0 ; i < K ; i ++ ) { crr . push_back ( brr [ i ] ) ; } sort ( crr . begin ( ) , crr . end ( ) , greater < int > ( ) ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( crr [ i ] > 0 ) { sum += crr [ i ] ; } else { break ; } } cout << sum << endl ; } int main ( ) { int arr [ ] = { 7 , 2 , -1 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int brr [ ] = { 1 , 2 , 3 , 2 } ; int K = sizeof ( brr ) / sizeof ( brr [ 0 ] ) ; maxSum ( arr , brr , N , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countPairs ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int xo = ( A [ i ] ^ A [ j ] ) ; int mx = max ( A [ i ] , A [ j ] ) ; if ( xo > mx ) { count ++ ; } } } cout << count ; } int main ( ) { int arr [ ] = { 2 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countPairs ( arr , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findTheOrder ( int arr [ ] , string s , int N ) { vector < int > ans ; pair < int , int > A [ N ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = { arr [ i ] , i + 1 } ; sort ( A , A + N ) ; priority_queue < pair < int , int > > q ; int index = 0 ; for ( int i = 0 ; i < 2 * N ; i ++ ) { if ( s [ i ] == '0' ) { ans . push_back ( A [ index ] . second ) ; q . push ( A [ index ] ) ; index ++ ; } else { ans . push_back ( q . top ( ) . second ) ; q . pop ( ) ; } } for ( auto i : ans ) { cout << i << " ▁ " ; } } int main ( ) { int N = 3 ; int arr [ ] = { 2 , 1 , 3 } ; string s = "001011" ; findTheOrder ( arr , s , N ) ; return 0 ; }

Index/key variables: N, i, index
Accumulator variables: i, index, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void evenOddDiff ( int a [ ] , int n , int k ) { int j = -1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) { j ++ ; swap ( a [ i ] , a [ j ] ) ; } } j ++ ; sort ( a , a + j , greater < int > ( ) ) ; sort ( a + j , a + n , greater < int > ( ) ) ; int evenSum = 0 , oddSum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { evenSum += a [ i ] ; } for ( int i = j ; i < ( j + k ) ; i ++ ) { oddSum += a [ i ] ; } cout << abs ( evenSum - oddSum ) ; } int main ( ) { int arr [ ] = { 1 , 8 , 3 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; evenOddDiff ( arr , N , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: evenSum, i, j, oddSum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } void rearrangeArr ( int arr [ ] , int N ) { int totalSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } if ( totalSum == 0 ) { cout << " - 1" << endl ; } else if ( totalSum > 0 ) { sort ( arr , arr + N , greater < int > ( ) ) ; printArr ( arr , N ) ; } else { sort ( arr , arr + N ) ; printArr ( arr , N ) ; } } int main ( ) { int arr [ ] = { 1 , -1 , -2 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrangeArr ( arr , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc, totalSum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MOD = 1000000007 ; int solve ( vector < int > & values , vector < int > & salary ) { long long ret = 1 ; int amt = 0 ; sort ( values . begin ( ) , values . end ( ) ) ; sort ( salary . begin ( ) , salary . end ( ) ) ; while ( salary . size ( ) ) { while ( values . size ( ) && values . back ( ) >= salary . back ( ) ) { amt ++ ; values . pop_back ( ) ; } if ( amt == 0 ) return 0 ; ret *= amt -- ; ret %= MOD ; salary . pop_back ( ) ; } return ret ; } int main ( ) { vector < int > values { 1 , 2 } , salary { 2 } ; cout << solve ( values , salary ) ; return 0 ; }

Accumulator variables: amt, ret, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairs ( int arr [ ] , int n ) { int ans = 0 ; sort ( arr , arr + n ) ; int left = 0 , right = 1 ; while ( right < n ) { if ( arr [ left ] == arr [ right ] ) ans += right - left ; else left = right ; right ++ ; } return ans ; } int main ( ) { int arr [ ] = { 2 , 2 , 3 , 2 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairs ( arr , N ) ; return 0 ; }

Index/key variables: left, right
Accumulator variables: ans, right, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compare ( pair < int , int > p1 , pair < int , int > p2 ) { return p1 . first > p2 . first ; } int maximiseScore ( int A [ ] , int B [ ] , int K , int N ) { vector < pair < int , int > > pairs ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { pairs [ i ] = make_pair ( A [ i ] , B [ i ] ) ; } sort ( pairs . begin ( ) , pairs . end ( ) , compare ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( pairs [ i ] . second == 0 ) { sum += pairs [ i ] . first ; } else if ( pairs [ i ] . second == 1 ) { if ( K > 0 ) { sum += pairs [ i ] . first ; K -- ; } else { sum -= pairs [ i ] . first ; } } } return sum ; } int main ( ) { int A [ ] = { 5 , 4 , 6 , 2 , 8 } ; int B [ ] = { 1 , 0 , 1 , 1 , 0 } ; int K = 2 ; int N = sizeof ( A ) / sizeof ( int ) ; cout << maximiseScore ( A , B , K , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: K, i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sortString ( string S ) { vector < int > sorted , original ; bool insert = false ; if ( S . length ( ) == 1 ) { cout << 0 << endl ; } int curr = 1 ; for ( int i = 0 ; i < ( S . length ( ) - 1 ) ; i ++ ) { if ( S [ i ] == S [ i + 1 ] ) { curr += 1 ; insert = false ; } else { sorted . push_back ( curr ) ; original . push_back ( curr ) ; curr = 1 ; insert = true ; } } if ( ( S [ ( S . length ( ) - 1 ) ] != S [ ( S . length ( ) - 2 ) ] ) insert == false ) { sorted . push_back ( curr ) ; original . push_back ( curr ) ; } sort ( sorted . begin ( ) , sorted . end ( ) ) ; int t_cost = 0 ; for ( int i = 0 ; i < sorted . size ( ) ; i ++ ) { t_cost += abs ( sorted [ i ] - original [ i ] ) ; } return ( t_cost / 2 ) ; } int main ( ) { string S = " aabbcccdeffffggghhhhhii " ; cout << sortString ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr, i, stdc, t_cost
Iterator variables: i
Boolean variables: insert
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int letters [ ] = { 4 , 3 , 3 , 3 , 4 , 4 , 3 , 5 , 5 , 4 } ; int sumOfLetters ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += letters [ n % 10 ] ; n = n / 10 ; } return sum ; } void sortArr ( int arr [ ] , int n ) { vector < pair < int , int > > vp ; for ( int i = 0 ; i < n ; i ++ ) { vp . push_back ( make_pair ( sumOfLetters ( arr [ i ] ) , arr [ i ] ) ) ; } sort ( vp . begin ( ) , vp . end ( ) ) ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) cout << vp [ i ] . second << " ▁ " ; } int main ( ) { int arr [ ] = { 12 , 10 , 31 , 18 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int block ; struct Query { int L , R , index ; int armstrong ; } ; int count_Armstrong ; bool compare ( Query x , Query y ) { if ( x . L / block != y . L / block ) return x . L / block < y . L / block ; return x . R < y . R ; } bool compare1 ( Query x , Query y ) { return x . index < y . index ; } bool isArmstrong ( int x ) { int n = to_string ( x ) . size ( ) ; int sum1 = 0 ; int temp = x ; while ( temp > 0 ) { int digit = temp % 10 ; sum1 += pow ( digit , n ) ; temp /= 10 ; } if ( sum1 == x ) return true ; return false ; } void add ( int currL , int a [ ] ) { if ( isArmstrong ( a [ currL ] ) ) count_Armstrong ++ ; } void remove ( int currR , int a [ ] ) { if ( isArmstrong ( a [ currR ] ) ) count_Armstrong -- ; } void queryResults ( int a [ ] , int n , Query q [ ] , int m ) { count_Armstrong = 0 ; block = ( int ) sqrt ( n ) ; sort ( q , q + m , compare ) ; int currL = 0 , currR = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; while ( currR <= R ) { add ( currR , a ) ; currR ++ ; } while ( currL > L ) { add ( currL - 1 , a ) ; currL -- ; } while ( currR > R + 1 ) { remove ( currR - 1 , a ) ; currR -- ; } while ( currL < L ) { remove ( currL , a ) ; currL ++ ; } q [ i ] . armstrong = count_Armstrong ; } } void printResults ( Query q [ ] , int m ) { sort ( q , q + m , compare1 ) ; for ( int i = 0 ; i < m ; i ++ ) { cout << q [ i ] . armstrong << endl ; } } int main ( ) { int arr [ ] = { 18 , 153 , 8 , 9 , 14 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Query q [ ] = { { 0 , 5 , 0 , 0 } , { 3 , 5 , 1 , 0 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; queryResults ( arr , n , q , m ) ; printResults ( q , m ) ; return 0 ; }

Index/key variables: currL, currR, i
Accumulator variables: count_Armstrong, currL, currR, i, stdc, sum1, temp
Iterator variables: i
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int val ; struct node * right , * left ; } ; struct node * newnode ( int key ) { struct node * temp = new node ; temp -> val = key ; temp -> right = NULL ; temp -> left = NULL ; return temp ; } void func ( node * root ) { queue < node * > q ; bool t = true ; q . push ( root ) ; int i = -1 , j = -1 , k = -1 ; while ( ! q . empty ( ) ) { int h = q . size ( ) ; while ( h > 0 ) { root = q . front ( ) ; if ( i == -1 ) { j = root -> val ; } if ( i == -2 ) { if ( j <= root -> val ) { j = root -> val ; i = -3 ; } else { t = false ; break ; } } if ( root -> left != NULL ) { q . push ( root -> left ) ; } if ( root -> right != NULL ) { q . push ( root -> right ) ; } h = h - 1 ; q . pop ( ) ; } i = -2 ; if ( t == false ) { break ; } } if ( t ) cout << " true " << endl ; else cout << " false " << endl ; } int main ( ) { struct node * root = newnode ( 10 ) ; root -> right = newnode ( 50 ) ; root -> right -> right = newnode ( 15 ) ; root -> left = newnode ( 20 ) ; root -> left -> left = newnode ( 50 ) ; root -> left -> right = newnode ( 23 ) ; root -> right -> left = newnode ( 10 ) ; func ( root ) ; return 0 ; }

Accumulator variables: stdc
Boolean variables: t
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculate_minimum_split ( int n , int a [ ] , int k ) { int p [ n - 1 ] ; for ( int i = 1 ; i < n ; i ++ ) p [ i - 1 ] = a [ i ] - a [ i - 1 ] ; sort ( p , p + n - 1 , greater < int > ( ) ) ; int min_sum = 0 ; for ( int i = 0 ; i < k - 1 ; i ++ ) min_sum += p [ i ] ; int res = a [ n - 1 ] - a [ 0 ] - min_sum ; return res ; } int main ( ) { int arr [ 6 ] = { 4 , 8 , 15 , 16 , 23 , 42 } ; int k = 3 ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << calculate_minimum_split ( n , arr , k ) ; }

Index/key variables: i
Accumulator variables: i, min_sum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int myCompare ( string date1 , string date2 ) { string day1 = date1 . substr ( 0 , 2 ) ; string month1 = date1 . substr ( 3 , 2 ) ; string year1 = date1 . substr ( 6 , 4 ) ; string day2 = date2 . substr ( 0 , 2 ) ; string month2 = date2 . substr ( 3 , 2 ) ; string year2 = date2 . substr ( 6 , 4 ) ; if ( year1 < year2 ) return 1 ; if ( year1 > year2 ) return 0 ; if ( month1 < month2 ) return 1 ; if ( month1 > month2 ) return 0 ; if ( day1 < day2 ) return 1 ; if ( day1 > day2 ) return 0 ; } void printDatesAscending ( vector < string > arr ) { sort ( arr . begin ( ) , arr . end ( ) , myCompare ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) cout << arr [ i ] << " STRNEWLINE " ; } int main ( ) { vector < string > arr ; arr . push_back ( "25-08-1996" ) ; arr . push_back ( "03-08-1970" ) ; arr . push_back ( "09-04-1994" ) ; arr . push_back ( "29-08-1996" ) ; arr . push_back ( "14-02-1972" ) ; printDatesAscending ( arr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char ch ) { ch = toupper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } int countVowels ( string str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) ++ count ; return count ; } void sortArr ( string arr [ ] , int n ) { vector < pair < int , string > > vp ; for ( int i = 0 ; i < n ; i ++ ) { vp . push_back ( make_pair ( countVowels ( arr [ i ] ) , arr [ i ] ) ) ; } sort ( vp . begin ( ) , vp . end ( ) ) ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) cout << vp [ i ] . second << " ▁ " ; } int main ( ) { string arr [ ] = { " lmno " , " pqrst " , " aeiou " , " xyz " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
int minimumCost ( ll price [ ] , int n ) { sort ( price , price + n ) ; ll totalCost = 0 ; for ( int i = n - 1 ; i > 1 ; i -= 2 ) { if ( i == 2 ) { totalCost += price [ 2 ] + price [ 0 ] ; } else { ll price_first = price [ i ] + price [ 0 ] + 2 * price [ 1 ] ; ll price_second = price [ i ] + price [ i - 1 ] + 2 * price [ 0 ] ; totalCost += min ( price_first , price_second ) ; } } if ( n == 1 ) { totalCost += price [ 0 ] ; } else { totalCost += price [ 1 ] ; } return totalCost ; } int main ( ) { ll price [ ] = { 30 , 40 , 60 , 70 } ; int n = sizeof ( price ) / sizeof ( price [ 0 ] ) ; cout << minimumCost ( price , n ) ; return 0 ; }

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