dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; void maxArea ( int point_x [ ] , int point_y [ ] , int n , int length , int width ) { sort ( point_x , point_x + n ) ; sort ( point_y , point_y + n ) ; int dx = point_x [ 0 ] ; int dy = point_y [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { dx = max ( dx , point_x [ i ] - point_x [ i - 1 ] ) ; dy = max ( dy , point_y [ i ] - point_y [ i - 1 ] ) ; } dx = max ( dx , ( length + 1 ) - point_x [ n - 1 ] ) ; dy = max ( dy , ( width + 1 ) - point_y [ n - 1 ] ) ; cout << ( dx - 1 ) * ( dy - 1 ) ; cout << endl ; } int main ( ) { int length = 15 , width = 8 ; int n = 3 ; int point_x [ ] = { 3 , 11 , 8 } ; int point_y [ ] = { 8 , 2 , 6 } ; maxArea ( point_x , point_y , n , length , width ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int make_cuts ( int arr [ ] , int n , int K ) { int ans = 0 ; vector < int > poss ; int ce = 0 ; int co = 0 ; for ( int x = 0 ; x < n - 1 ; x ++ ) { if ( arr [ x ] % 2 == 0 ) ce ++ ; else co ++ ; if ( ce == co && co > 0 && ce > 0 ) { poss . push_back ( abs ( arr [ x ] - arr [ x + 1 ] ) ) ; } } sort ( poss . begin ( ) , poss . end ( ) ) ; for ( int x : poss ) { if ( K >= x ) { ans ++ ; K -= x ; } else break ; } return ans ; } int main ( ) { int N = 6 ; int K = 4 ; int arr [ ] = { 1 , 2 , 5 , 10 , 15 , 20 } ; cout << make_cuts ( arr , N , K ) ; }

Index/key variables: x
Accumulator variables: K, ans, ce, co, stdc, x
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void Arrange ( int arr [ ] , int n ) { int cost = 0 ; unordered_map < int , int > index ; for ( int i = 0 ; i < n ; i ++ ) { index [ arr [ i ] ] = i ; } sort ( arr , arr + n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { if ( arr [ i ] > arr [ i + 1 ] + arr [ n - 1 ] ) { cout << " - 1" ; return ; } else { cost += abs ( index [ arr [ i ] ] - i ) ; } } else if ( i == n - 1 ) { if ( arr [ i ] > arr [ i - 1 ] + arr [ 0 ] ) { cout << " - 1" ; return ; } else { cost += abs ( index [ arr [ i ] ] - i ) ; } } else { if ( arr [ i ] > arr [ i - 1 ] + arr [ i + 1 ] ) { cout << " - 1" ; return ; } else { cost += abs ( index [ arr [ i ] ] - i ) ; } } } cout << cost ; return ; } int main ( ) { int arr [ ] = { 2 , 4 , 5 , 1 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Arrange ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cost, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int XorSum ( int A [ ] , int B [ ] , int N ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { ans = ans ^ ( A [ i ] + B [ j ] ) ; } } return ans ; } int main ( ) { int A [ ] = { 4 , 6 , 0 , 0 , 3 , 3 } ; int B [ ] = { 0 , 5 , 6 , 5 , 0 , 3 } ; int N = sizeof A / sizeof A [ 0 ] ; cout << XorSum ( A , B , N ) << endl ; 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 ; int maxDistinctChar ( string s , int n , int k ) { unordered_map < int , int > freq ; for ( int i = 0 ; i < n ; i ++ ) freq [ s [ i ] ] ++ ; vector < int > v ; for ( auto it = freq . begin ( ) ; it != freq . end ( ) ; it ++ ) { v . push_back ( it -> second ) ; } sort ( v . begin ( ) , v . end ( ) ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { int mn = min ( v [ i ] - 1 , k ) ; v [ i ] -= mn ; k -= mn ; } if ( k > 0 ) { for ( int i = 0 ; i < v . size ( ) ; i ++ ) { int mn = min ( v [ i ] , k ) ; v [ i ] -= mn ; k -= mn ; } } int res = 0 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) if ( v [ i ] == 1 ) res ++ ; return res ; } int main ( ) { string S = " geeksforgeeks " ; int N = S . size ( ) ; int K = 1 ; cout << maxDistinctChar ( S , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, it, k, res, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > primes ; void SieveOfEratosthenes ( ) { bool prime [ 10005 ] ; memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= 1000 ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= 1000 ; i += p ) prime [ i ] = false ; } } for ( int p = 2 ; p <= 1000 ; p ++ ) if ( prime [ p ] ) primes . push_back ( p ) ; } void generate ( int n , int k ) { vector < long long > prod ; SieveOfEratosthenes ( ) ; int l = primes . size ( ) ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = i + 1 ; j < l ; j ++ ) { if ( primes [ i ] * primes [ j ] > 0 ) prod . push_back ( primes [ i ] * primes [ j ] ) ; } } sort ( prod . begin ( ) , prod . end ( ) ) ; int sum = 0 ; for ( int i = 0 ; i < k - 1 ; i ++ ) sum += prod [ i ] ; if ( sum > n ) cout << " - 1" ; else { for ( int i = 0 ; i < k - 1 ; i ++ ) { cout << prod [ i ] << " , ▁ " ; } cout << n - sum << " STRNEWLINE " ; } } int main ( ) { int n = 52 , k = 5 ; generate ( n , k ) ; return 0 ; }

Index/key variables: i, j, p
Accumulator variables: i, j, p, stdc, sum
Iterator variables: i, j, p
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; ll findMaxValue ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; ll ans = arr [ n - 1 ] ; ll maxPossible = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; -- i ) { if ( maxPossible > 0 ) { if ( arr [ i ] >= maxPossible ) { ans += ( maxPossible - 1 ) ; maxPossible = maxPossible - 1 ; } else { maxPossible = arr [ i ] ; ans += maxPossible ; } } } return ans ; } int main ( ) { int arr [ ] = { 4 , 4 , 1 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxValue ( arr , n ) ; }

Index/key variables: i
Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCost ( int arr [ ] , int n ) { pair < int , int > sorted [ n ] ; int total_cost = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sorted [ i ] . first = arr [ i ] ; sorted [ i ] . second = i ; } sort ( sorted , sorted + n ) ; int overall_minimum = sorted [ 0 ] . first ; bool vis [ n ] = { false } ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] && sorted [ i ] . second == i ) continue ; vector < int > v ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = true ; v . push_back ( sorted [ j ] . first ) ; j = sorted [ j ] . second ; } if ( v . size ( ) > 0 ) { int local_minimum = v [ 0 ] , result1 = 0 , result2 = 0 ; for ( int k = 1 ; k < v . size ( ) ; k ++ ) result1 += ( local_minimum * v [ k ] ) ; for ( int k = 0 ; k < v . size ( ) ; k ++ ) result2 += ( overall_minimum * v [ k ] ) ; result2 += ( overall_minimum * local_minimum ) ; total_cost += min ( result1 , result2 ) ; } } return total_cost ; } int main ( ) { int arr [ ] = { 1 , 8 , 9 , 7 , 6 } ; int n = ( sizeof ( arr ) / sizeof ( int ) ) ; cout << minCost ( arr , n ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, k, result1, result2, stdc, total_cost
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximizeFinalElement ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; if ( arr [ 0 ] != 1 ) arr [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] > 1 ) { arr [ i ] = arr [ i - 1 ] + 1 ; } } return arr [ n - 1 ] ; } int main ( ) { int n = 4 ; int arr [ ] = { 3 , 1 , 3 , 4 } ; int max = maximizeFinalElement ( arr , n ) ; cout << max ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findLeastDist ( int A [ ] , int N ) { sort ( A , A + N ) ; if ( N % 2 == 0 ) { return A [ ( N - 1 ) / 2 ] ; } else { return A [ N / 2 ] ; } } int main ( ) { int A [ ] = { 4 , 1 , 5 , 10 , 2 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << " ( " << findLeastDist ( A , N ) << " , ▁ " << 0 << " ) " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSubMatSum ( vector < vector < int > > mat ) { int n = mat . size ( ) ; int m = mat [ 0 ] . size ( ) ; int i , j ; int dp [ n ] [ m ] ; dp [ n - 1 ] [ m - 1 ] = mat [ n - 1 ] [ m - 1 ] ; int res = dp [ n - 1 ] [ m - 1 ] ; for ( i = m - 2 ; i >= 0 ; i -- ) { dp [ n - 1 ] [ i ] = mat [ n - 1 ] [ i ] + dp [ n - 1 ] [ i + 1 ] ; res = max ( res , dp [ n - 1 ] [ i ] ) ; } for ( i = n - 2 ; i >= 0 ; i -- ) { dp [ i ] [ m - 1 ] = mat [ i ] [ m - 1 ] + dp [ i + 1 ] [ m - 1 ] ; res = max ( res , dp [ i ] [ m - 1 ] ) ; } for ( i = n - 2 ; i >= 0 ; i -- ) { for ( j = m - 2 ; j >= 0 ; j -- ) { dp [ i ] [ j ] = mat [ i ] [ j ] + dp [ i ] [ j + 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j + 1 ] ; res = max ( res , dp [ i ] [ j ] ) ; } } return res ; } int main ( ) { vector < vector < int > > mat ; mat = { { -6 , -4 , -1 } , { -3 , 2 , 4 } , { 2 , 5 , 8 } } ; cout << maxSubMatSum ( mat ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canMadeEqual ( int A [ ] , int B [ ] , int n ) { sort ( A , A + n ) ; sort ( B , B + n ) ; for ( int i = 0 ; i < n ; i ++ ) if ( A [ i ] != B [ i ] ) return false ; return true ; } int main ( ) { int A [ ] = { 1 , 2 , 3 } ; int B [ ] = { 1 , 3 , 2 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( canMadeEqual ( A , B , n ) ) 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 maxMinDifference ( int arr [ ] , int n , int k ) { if ( k >= n - 1 ) return 0 ; sort ( arr , arr + n ) ; int ans = arr [ n - 1 ] - arr [ 0 ] ; for ( int i = k , j = n - 1 ; i >= 0 ; -- i , -- j ) { ans = min ( arr [ j ] - arr [ i ] , ans ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 4 , 6 , 11 , 15 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << maxMinDifference ( arr , N , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void max_sum ( int ar [ ] , int n , int q , int x [ ] , int y [ ] ) { int ans = 0 , i ; priority_queue < pair < int , int > > pq ; for ( i = 0 ; i < n ; i ++ ) pq . push ( { ar [ i ] , 1 } ) ; for ( i = 0 ; i < q ; i ++ ) pq . push ( { y [ i ] , x [ i ] } ) ; while ( n > 0 ) { auto pr = pq . top ( ) ; pq . pop ( ) ; ans += pr . first * min ( n , pr . second ) ; n -= pr . second ; } cout << ans << " STRNEWLINE " ; } int main ( ) { int ar [ ] = { 200 , 100 , 200 , 300 } ; int n = ( sizeof ar ) / ( sizeof ar [ 0 ] ) ; int q = 2 ; int x [ ] = { 2 , 3 } ; int y [ ] = { 100 , 90 } ; max_sum ( ar , n , q , x , y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, n, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortarray ( int arr [ ] , int N ) { if ( N == 3 ) cout << " NO " << endl ; else if ( N % 4 == 0 N % 4 == 1 ) { cout << " YES " << endl ; cout << ( N / 2 ) << endl ; int k = 1 ; for ( int l = 0 ; l < ( N / 4 ) ; l ++ ) { cout << k << " ▁ " << k + 1 << " ▁ " << N << endl ; cout << k + 1 << " ▁ " << N << " ▁ " << N - 1 << endl ; k = k + 2 ; N = N - 2 ; } } else cout << " NO " << endl ; } int main ( ) { int N = 5 ; int arr [ ] = { 5 , 4 , 3 , 2 , 1 } ; sortarray ( arr , N ) ; return 0 ; }

Accumulator variables: l, stdc
Iterator variables: l
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 1e5 + 5 ; void find_missing ( vector < pair < int , int > > interval ) { vector < int > vis ( MAX ) ; for ( int i = 0 ; i < interval . size ( ) ; ++ i ) { int start = interval [ i ] . first ; int end = interval [ i ] . second ; vis [ start ] ++ ; vis [ end + 1 ] -- ; } for ( int i = 1 ; i < MAX ; i ++ ) { vis [ i ] += vis [ i - 1 ] ; if ( ! vis [ i ] ) { cout << i << endl ; return ; } } } int main ( ) { vector < pair < int , int > > interval = { { 0 , 14 } , { 86 , 108 } , { 22 , 30 } , { 5 , 17 } } ; find_missing ( interval ) ; return 0 ; }

Index/key variables: i, start
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void find_missing ( vector < pair < int , int > > interval ) { sort ( interval . begin ( ) , interval . end ( ) ) ; int mx = 0 ; for ( int i = 0 ; i < ( int ) interval . size ( ) ; ++ i ) { if ( interval [ i ] . first > mx ) { cout << mx ; return ; } else mx = max ( mx , interval [ i ] . second + 1 ) ; } cout << mx ; } int main ( ) { vector < pair < int , int > > interval = { { 0 , 14 } , { 86 , 108 } , { 22 , 30 } , { 5 , 17 } } ; find_missing ( interval ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int build_num ( int bit [ ] ) { int ans = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) if ( bit [ i ] ) ans += ( 1 << i ) ; return ans ; } int maximumOR ( int arr [ ] , int n , int k ) { int bit [ 32 ] = { 0 } ; for ( int i = 31 ; i >= 0 ; i -- ) { if ( bit [ i ] == 0 && k > 0 ) { int temp = build_num ( bit ) ; int temp1 = temp ; int val = -1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( temp1 < ( temp arr [ j ] ) ) { temp1 = temp | arr [ j ] ; val = arr [ j ] ; } } if ( val != -1 ) { k -- ; for ( int j = 0 ; j < 32 ; j ++ ) { if ( val & ( 1 << j ) ) bit [ j ] ++ ; } } } } return build_num ( bit ) ; } int main ( ) { int arr [ ] = { 5 , 9 , 7 , 19 } ; int k = 3 ; int n = sizeof arr / sizeof arr [ 0 ] ; cout << maximumOR ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, k
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void smallest_string ( string s , int m ) { int n = s . size ( ) ; int a [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int distance = s [ i ] - ' a ' ; if ( distance == 0 ) a [ i ] = 0 ; else a [ i ] = 26 - distance ; } for ( int i = 0 ; i < n ; i ++ ) { if ( m >= a [ i ] ) { s [ i ] = ' a ' ; m = m - a [ i ] ; } } m = m % 26 ; s [ n - 1 ] = s [ n - 1 ] + m ; cout << s ; } int main ( ) { string str = " aazzx " ; int m = 6 ; smallest_string ( str , m ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find_maximum_jobs ( int N , vector < pair < int , int > > ranges ) { priority_queue < int , vector < int > , greater < int > > queue ; sort ( ranges . begin ( ) , ranges . end ( ) ) ; int min_day = ranges [ 0 ] . first ; int max_day = 0 ; for ( int i = 0 ; i < N ; i ++ ) max_day = max ( max_day , ranges [ i ] . second ) ; int index = 0 , count_jobs = 0 ; for ( int i = min_day ; i <= max_day ; i ++ ) { while ( index < ranges . size ( ) && ranges [ index ] . first <= i ) { queue . push ( ranges [ index ] . second ) ; index ++ ; } while ( ! queue . empty ( ) && queue . top ( ) < i ) queue . pop ( ) ; if ( queue . empty ( ) ) continue ; count_jobs ++ ; queue . pop ( ) ; } return count_jobs ; } int main ( ) { int N = 5 ; vector < pair < int , int > > ranges ; ranges . push_back ( { 1 , 5 } ) ; ranges . push_back ( { 1 , 5 } ) ; ranges . push_back ( { 1 , 5 } ) ; ranges . push_back ( { 2 , 3 } ) ; ranges . push_back ( { 2 , 3 } ) ; cout << find_maximum_jobs ( N , ranges ) ; }

Index/key variables: i, index
Accumulator variables: count_jobs, i, index, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minBox ( int arr [ ] , int n ) { int box = n ; sort ( arr , arr + n ) ; int curr_box = 0 , next_box = 1 ; while ( curr_box < n && next_box < n ) { if ( arr [ curr_box ] < arr [ next_box ] ) { box -- ; curr_box ++ ; next_box ++ ; } else if ( arr [ curr_box ] == arr [ next_box ] ) next_box ++ ; } cout << box << endl ; } int main ( ) { int size [ ] = { 1 , 2 , 3 } ; int n = sizeof ( size ) / sizeof ( size [ 0 ] ) ; minBox ( size , n ) ; return 0 ; }

Index/key variables: curr_box, next_box
Accumulator variables: box, curr_box, next_box, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortString ( vector < int > & arr , int n , int moves ) { vector < int > pos ; vector < vector < int > > indices ; bool flag = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != i ) { if ( arr [ arr [ arr [ i ] ] ] == i && arr [ arr [ i ] ] != i ) { int temp = arr [ arr [ i ] ] ; indices . push_back ( { i , arr [ i ] , arr [ arr [ i ] ] } ) ; swap ( arr [ i ] , arr [ arr [ i ] ] ) ; swap ( arr [ i ] , arr [ temp ] ) ; } } if ( arr [ i ] != i ) { pos . push_back ( i ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != i ) { int pos1 = i , pos2 = arr [ i ] ; int pos3 = arr [ arr [ i ] ] ; if ( pos3 != pos1 ) { indices . push_back ( { pos1 , pos2 , pos3 } ) ; swap ( arr [ pos1 ] , arr [ pos2 ] ) ; swap ( arr [ pos1 ] , arr [ pos3 ] ) ; pos . erase ( find ( pos . begin ( ) , pos . end ( ) , pos2 ) ) ; pos . erase ( find ( pos . begin ( ) , pos . end ( ) , pos3 ) ) ; if ( arr [ pos1 ] == pos1 ) { pos . erase ( find ( pos . begin ( ) , pos . end ( ) , pos1 ) ) ; } } else { if ( pos3 == * pos . begin ( ) ) { if ( * pos . begin ( ) != pos . back ( ) ) { auto it = ++ pos . begin ( ) ; pos3 = * ( it ) ; if ( * it != pos . back ( ) && pos3 == pos2 ) { pos3 = * ( ++ it ) ; } else if ( * it == pos . back ( ) && pos3 == pos2 ) { flag = true ; break ; } } else { flag = true ; break ; } } indices . push_back ( { pos1 , pos2 , pos3 } ) ; swap ( arr [ pos1 ] , arr [ pos2 ] ) ; swap ( arr [ pos1 ] , arr [ pos3 ] ) ; pos . erase ( find ( pos . begin ( ) , pos . end ( ) , pos2 ) ) ; } } if ( arr [ i ] != i ) { i -- ; } } if ( flag == true || indices . size ( ) > moves ) { cout << " Not ▁ Possible " << endl ; } else { cout << indices . size ( ) << endl ; } } int main ( ) { string s = " adceb " ; vector < int > arr ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { arr . push_back ( s [ i ] - ' a ' ) ; } sortString ( arr , s . size ( ) , floor ( s . size ( ) / 2 ) ) ; }

Index/key variables: i, pos1, pos2, pos3, temp
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countReductions ( vector < pair < int , int > > & v , int K ) { int sum = 0 ; for ( auto i : v ) { sum += i . first ; } if ( sum <= K ) { return 0 ; } sort ( v . begin ( ) , v . end ( ) , [ & ] ( pair < int , int > a , pair < int , int > b ) { return ( a . first - a . second ) > ( b . first - b . second ) ; } ) ; int i = 0 ; while ( sum > K && i < v . size ( ) ) { sum -= ( v [ i ] . first - v [ i ] . second ) ; i ++ ; } if ( sum <= K ) return i ; return -1 ; } int main ( ) { int N = 4 , K = 25 ; vector < pair < int , int > > v ( N ) ; v [ 0 ] = { 10 , 5 } ; v [ 1 ] = { 20 , 9 } ; v [ 2 ] = { 12 , 10 } ; v [ 3 ] = { 4 , 2 } ; cout << countReductions ( v , K ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; node * next ; } ; void setData ( node * head ) { node * tmp ; tmp = head ; while ( tmp != NULL ) { cout << tmp -> data << " ▁ - > ▁ " ; tmp = tmp -> next ; } } node * getData ( node * head , int num ) { node * temp = new node ; node * tail = head ; temp -> data = num ; temp -> next = NULL ; if ( head == NULL ) { head = temp ; tail = temp ; } else { while ( tail != NULL ) { if ( tail -> next == NULL ) { tail -> next = temp ; tail = tail -> next ; } tail = tail -> next ; } } return head ; } node * mergelists ( node * * head1 , node * * head2 ) { node * tail = * head1 ; while ( tail != NULL ) { if ( tail -> next == NULL && head2 != NULL ) { tail -> next = * head2 ; break ; } tail = tail -> next ; } return * head1 ; } void sortlist ( node * * head1 ) { node * curr = * head1 ; node * temp = * head1 ; while ( curr -> next != NULL ) { temp = curr -> next ; while ( temp != NULL ) { if ( temp -> data < curr -> data ) { int t = temp -> data ; temp -> data = curr -> data ; curr -> data = t ; } temp = temp -> next ; } curr = curr -> next ; } } int main ( ) { node * head1 = new node ; node * head2 = new node ; head1 = NULL ; head2 = NULL ; head1 = getData ( head1 , 4 ) ; head1 = getData ( head1 , 7 ) ; head1 = getData ( head1 , 5 ) ; head2 = getData ( head2 , 2 ) ; head2 = getData ( head2 , 1 ) ; head2 = getData ( head2 , 8 ) ; head2 = getData ( head2 , 1 ) ; head1 = mergelists ( & head1 , & head2 ) ; sortlist ( & head1 ) ; setData ( head1 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; double findMedian ( int a [ ] , int n ) { if ( n % 2 != 0 ) return ( double ) a [ n / 2 ] ; return ( double ) ( a [ ( n - 1 ) / 2 ] + a [ n / 2 ] ) / 2.0 ; } void kStrongest ( int arr [ ] , int n , int k ) { sort ( arr , arr + n ) ; double median = findMedian ( arr , n ) ; int diff [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { diff [ i ] = abs ( median - arr [ i ] ) ; } int i = 0 , j = n - 1 ; while ( k > 0 ) { if ( diff [ i ] > diff [ j ] ) { cout << arr [ i ] << " ▁ " ; i ++ ; } else { cout << arr [ j ] << " ▁ " ; j -- ; } k -- ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int k = 3 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; kStrongest ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sorting_possible ( int a [ ] , int b [ ] , int n ) { bool sorted = true ; int type1 = 0 , type0 = 0 , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < a [ i - 1 ] ) { sorted = false ; break ; } } for ( i = 0 ; i < n ; i ++ ) { if ( b [ i ] == 0 ) type0 ++ ; else type1 ++ ; } if ( sorted ) return true ; else if ( type1 == n type0 == n ) return false ; else return true ; } int main ( ) { int a [ ] = { 15 , 1 , 2 , 17 , 6 } ; int b [ ] = { 1 , 1 , 0 , 1 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; bool res = sorting_possible ( a , b , n ) ; if ( res ) cout << " Yes " ; else cout << " No " ; }

Index/key variables: i
Accumulator variables: i, stdc, type0, type1
Iterator variables: i
Boolean variables: sorted