dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSurpasser ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ; cout << count << " ▁ " ; } } void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) printf ( " % d ▁ " , arr [ i ] ) ; printf ( " STRNEWLINE " ) ; } int main ( ) { int arr [ ] = { 2 , 7 , 5 , 3 , 0 , 8 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " Given ▁ array ▁ is ▁ STRNEWLINE " ) ; printArray ( arr , n ) ; printf ( " Surpasser ▁ Count ▁ of ▁ array ▁ is ▁ STRNEWLINE " ) ; findSurpasser ( 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 ; int solve ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int a = 0 , b = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i & 1 ) a = a * 10 + arr [ i ] ; else b = b * 10 + arr [ i ] ; } return a + b ; } int main ( ) { int arr [ ] = { 6 , 8 , 4 , 5 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Sum ▁ is ▁ " << solve ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProduct ( int arr [ ] , int n ) { if ( n < 3 ) return -1 ; int max_product = INT_MIN ; for ( int i = 0 ; i < n - 2 ; i ++ ) for ( int j = i + 1 ; j < n - 1 ; j ++ ) for ( int k = j + 1 ; k < n ; k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ; return max_product ; } int main ( ) { int arr [ ] = { 10 , 3 , 5 , 6 , 20 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = maxProduct ( arr , n ) ; if ( max == -1 ) cout << " No ▁ Triplet ▁ Exists " ; else cout << " Maximum ▁ product ▁ is ▁ " << max ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProduct ( int arr [ ] , int n ) { if ( n < 3 ) return -1 ; vector < int > leftMin ( n , -1 ) ; vector < int > rightMin ( n , -1 ) ; vector < int > leftMax ( n , -1 ) ; vector < int > rightMax ( n , -1 ) ; int max_product = INT_MIN ; int max_sum = arr [ 0 ] ; int min_sum = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { leftMax [ i ] = max_sum ; if ( arr [ i ] > max_sum ) max_sum = arr [ i ] ; leftMin [ i ] = min_sum ; if ( arr [ i ] < min_sum ) min_sum = arr [ i ] ; } max_sum = arr [ n - 1 ] ; min_sum = arr [ n - 1 ] ; for ( int j = n - 2 ; j >= 0 ; j -- ) { rightMax [ j ] = max_sum ; if ( arr [ j ] > max_sum ) max_sum = arr [ j ] ; rightMin [ j ] = min_sum ; if ( arr [ j ] < min_sum ) min_sum = arr [ j ] ; } for ( int i = 1 ; i < n - 1 ; i ++ ) { int max1 = max ( arr [ i ] * leftMax [ i ] * rightMax [ i ] , arr [ i ] * leftMin [ i ] * rightMin [ i ] ) ; int max2 = max ( arr [ i ] * leftMax [ i ] * rightMin [ i ] , arr [ i ] * leftMin [ i ] * rightMax [ i ] ) ; max_product = max ( max_product , max ( max1 , max2 ) ) ; } return max_product ; } int main ( ) { int arr [ ] = { 1 , 4 , 3 , -6 , -7 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = maxProduct ( arr , n ) ; if ( max == -1 ) cout << " No ▁ Triplet ▁ Exists " ; else cout << " Maximum ▁ product ▁ is ▁ " << max ; 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 maxProduct ( int arr [ ] , int n ) { if ( n < 3 ) return -1 ; sort ( arr , arr + n ) ; return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ; } int main ( ) { int arr [ ] = { -10 , -3 , 5 , 6 , -20 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = maxProduct ( arr , n ) ; if ( max == -1 ) cout << " No ▁ Triplet ▁ Exists " ; else cout << " Maximum ▁ product ▁ is ▁ " << max ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProduct ( int arr [ ] , int n ) { if ( n < 3 ) return -1 ; int maxA = INT_MIN , maxB = INT_MIN , maxC = INT_MIN ; int minA = INT_MAX , minB = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > maxA ) { maxC = maxB ; maxB = maxA ; maxA = arr [ i ] ; } else if ( arr [ i ] > maxB ) { maxC = maxB ; maxB = arr [ i ] ; } else if ( arr [ i ] > maxC ) maxC = arr [ i ] ; if ( arr [ i ] < minA ) { minB = minA ; minA = arr [ i ] ; } else if ( arr [ i ] < minB ) minB = arr [ i ] ; } return max ( minA * minB * maxA , maxA * maxB * maxC ) ; } int main ( ) { int arr [ ] = { 1 , -4 , 3 , -6 , 7 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = maxProduct ( arr , n ) ; if ( max == -1 ) cout << " No ▁ Triplet ▁ Exists " ; else cout << " Maximum ▁ product ▁ is ▁ " << max ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMax ( int arr [ ] [ 3 ] , int n , int q ) { int maxi = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { maxi = max ( maxi , arr [ i ] [ q ] ) ; } return maxi ; } void sortDatesUtil ( int arr [ ] [ 3 ] , int n , int q ) { int maxi = getMax ( arr , n , q ) ; int p = 1 ; while ( maxi > 0 ) { int cnt [ 10 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { cnt [ ( arr [ i ] [ q ] / p ) % 10 ] ++ ; } for ( int i = 1 ; i < 10 ; i ++ ) { cnt [ i ] += cnt [ i - 1 ] ; } int ans [ n ] [ 3 ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int lastDigit = ( arr [ i ] [ q ] / p ) % 10 ; for ( int j = 0 ; j < 3 ; j ++ ) { ans [ cnt [ lastDigit ] - 1 ] [ j ] = arr [ i ] [ j ] ; } cnt [ lastDigit ] -- ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { arr [ i ] [ j ] = ans [ i ] [ j ] ; } } p *= 10 ; maxi /= 10 ; } } void sortDates ( int dates [ ] [ 3 ] , int n ) { sortDatesUtil ( dates , n , 0 ) ; sortDatesUtil ( dates , n , 1 ) ; sortDatesUtil ( dates , n , 2 ) ; } void printArr ( int arr [ ] [ 3 ] , int n ) { for ( int i = 0 ; i < 6 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { cout << arr [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { int dates [ ] [ 3 ] = { { 20 , 1 , 2014 } , { 25 , 3 , 2010 } , { 3 , 12 , 2000 } , { 18 , 11 , 2000 } , { 19 , 4 , 2015 } , { 9 , 7 , 2005 } } ; int n = sizeof ( dates ) / sizeof ( dates [ 0 ] ) ; sortDates ( dates , n ) ; cout << " Sorted Dates " printArr ( dates , n ) ; return 0 ; }

Index/key variables: i, j, lastDigit, n, q
Accumulator variables: i, j, maxi, p, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; double maxAverageRatio ( vector < vector < int > > & arr , int K ) { int N = arr . size ( ) ; priority_queue < pair < double , int > > q ; for ( int i = 0 ; i < N ; i ++ ) { double extra = ( ( ( double ) arr [ i ] [ 0 ] + 1 ) / ( ( double ) arr [ i ] [ 1 ] + 1 ) ) - ( ( double ) arr [ i ] [ 0 ] / ( double ) arr [ i ] [ 1 ] ) ; q . push ( make_pair ( extra , i ) ) ; } while ( K -- ) { int i = q . top ( ) . second ; q . pop ( ) ; arr [ i ] [ 0 ] += 1 ; arr [ i ] [ 1 ] += 1 ; double extra = ( ( ( double ) arr [ i ] [ 0 ] + 1 ) / ( ( double ) arr [ i ] [ 1 ] + 1 ) ) - ( ( double ) arr [ i ] [ 0 ] / ( double ) arr [ i ] [ 1 ] ) ; q . push ( make_pair ( extra , i ) ) ; } double ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += ( ( double ) arr [ i ] [ 0 ] / ( double ) arr [ i ] [ 1 ] ) ; } return ans / N ; } int main ( ) { vector < vector < int > > arr = { { 1 , 2 } , { 3 , 5 } , { 2 , 2 } } ; int K = 2 ; cout << maxAverageRatio ( arr , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: K, ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minMoves ( vector < vector < char > > a , vector < vector < char > > b , int K ) { int n = a . size ( ) , m = a [ 0 ] . size ( ) ; int cntOperations = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] != b [ i ] [ j ] ) { cntOperations ++ ; if ( i + K - 1 >= n j + K - 1 >= m ) { return -1 ; } for ( int p = 0 ; p <= K - 1 ; p ++ ) { for ( int q = 0 ; q <= K - 1 ; q ++ ) { if ( a [ i + p ] [ j + q ] == '0' ) { a [ i + p ] [ j + q ] = '1' ; } else { a [ i + p ] [ j + q ] = '0' ; } } } } } } return cntOperations ; } int main ( ) { vector < vector < char > > A = { { '1' , '0' , '0' } , { '0' , '0' , '0' } , { '0' , '0' , '0' } } ; vector < vector < char > > B = { { '0' , '0' , '0' } , { '0' , '0' , '0' } , { '0' , '0' , '0' } } ; int K = 3 ; cout << minMoves ( A , B , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: cntOperations, i, j, p, q, stdc
Iterator variables: i, j, p, q
C++ program:
#include <bits/stdc++.h>
using namespace std ; void largestPermutation ( int arr [ ] , int N ) { deque < int > p ; int mx = arr [ 0 ] ; p . push_back ( arr [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] < mx ) p . push_back ( arr [ i ] ) ; else { p . push_front ( arr [ i ] ) ; mx = arr [ i ] ; } } for ( auto i : p ) cout << i << " ▁ " ; } int main ( ) { int arr [ ] = { 3 , 1 , 2 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; largestPermutation ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxConsecutiveCnt ( vector < int > arr ) { int X = 0 ; sort ( arr . begin ( ) , arr . end ( ) ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] <= ( X + 1 ) ) { X = X + arr [ i ] ; } else { break ; } } return X + 1 ; } int main ( ) { vector < int > arr = { 1 , 1 , 1 , 4 } ; cout << maxConsecutiveCnt ( arr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include " bits / stdc + + . h "
using namespace std ; int maxLength ( vector < int > & A , vector < int > & B ) { int n = A . size ( ) ; int maxSize = 0 ; unordered_map < int , int > pre ; int diff = 0 ; pre [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { diff += ( A [ i ] - B [ i ] ) ; if ( pre . find ( diff ) == pre . end ( ) ) { pre = i + 1 ; } else { maxSize = max ( maxSize , i - pre + 1 ) ; } } return maxSize ; } int main ( ) { vector < int > A = { 1 , 2 , 3 , 4 } ; vector < int > B = { 4 , 3 , 2 , 1 } ; cout << maxLength ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: diff, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ar  array
ar < int , 2 > expand ( int idx , vector < int > & A ) { int l = idx - 1 ; int r = idx + 1 ; while ( l >= 0 ) { if ( ( int ) ( A [ idx ] ) > A [ l ] ) { -- l ; } else { break ; } } if ( l < 0 l == idx ) { l = -2 ; } while ( r < ( int ) ( A . size ( ) ) ) { if ( ( int ) A [ idx ] > A [ r ] ) { ++ r ; } else { break ; } } if ( r >= ( int ) ( A . size ( ) ) r == idx ) { r = -2 ; } return { l , r } ; } vector < int > minJumps ( int N , vector < int > & A ) { vector < int > ans ( N , 0 ) ; map < int , ar < int , 2 > > mp ; map < int , int > iToA ; map < int , int > AToi ; int big = A [ 0 ] ; for ( int i = 0 ; i < N ; ++ i ) { big = max ( { big , A [ i ] } ) ; mp [ i ] = expand ( i , A ) ; iToA [ i ] = A [ i ] ; AToi [ A [ i ] ] = i ; } sort ( A . begin ( ) , A . end ( ) , greater < int > ( ) ) ; for ( int i = 0 ; i < A . size ( ) ; ++ i ) { int m ; if ( A [ i ] == big ) { int cur = AToi [ A [ i ] ] ; ans [ cur ] = 0 ; continue ; } int cur = AToi [ A [ i ] ] ; int l = mp [ cur ] [ 0 ] ; int r = mp [ cur ] [ 1 ] ; if ( l >= 0 && r < N ) { m = min ( ans [ l ] , ans [ r ] ) + 1 ; } else if ( l < 0 && r < N ) { m = ans [ r ] + 1 ; } else if ( l >= 0 && r >= N ) { m = ans [ l ] + 1 ; } ans [ cur ] = m ; } return ans ; } int main ( ) { vector < int > arr = { 5 , 1 , 3 , 4 , 7 } ; int N = arr . size ( ) ; vector < int > out = minJumps ( N , arr ) ; for ( auto & it : out ) cout << it << ' ▁ ' ; return 0 ; }

Index/key variables: cur, i, idx, l, r
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int prefix_sum_row [ 50 ] [ 51 ] ; int prefix_sum_col [ 51 ] [ 50 ] ; bool is_valid ( int r , int c , int size , vector < vector < int > > & grid ) { int r_end = r + size , c_end = c + size ; int sum = 0 ; for ( int i = r , j = c ; i < r_end ; i ++ , j ++ ) { sum += grid [ i ] [ j ] ; } for ( int i = r ; i < r_end ; i ++ ) { if ( prefix_sum_row [ i ] [ c_end ] - prefix_sum_row [ i ] != sum ) { return false ; } } for ( int i = c ; i < c_end ; i ++ ) { if ( prefix_sum_col [ r_end ] [ i ] - prefix_sum_col [ r ] [ i ] != sum ) { return false ; } } int ad_sum = 0 ; for ( int i = r , j = c_end - 1 ; i < r_end ; i ++ , j -- ) { ad_sum += grid [ i ] [ j ] ; } return ad_sum == sum ; } int largestSquareValidMatrix ( vector < vector < int > > & grid ) { int m = grid . size ( ) , n = grid [ 0 ] . size ( ) ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { prefix_sum_row [ i ] [ j ] = prefix_sum_row [ i ] [ j - 1 ] + grid [ i ] [ j - 1 ] ; } } for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { prefix_sum_col [ i ] [ j ] = prefix_sum_col [ i - 1 ] [ j ] + grid [ i - 1 ] [ j ] ; } } for ( int size = min ( m , n ) ; size > 1 ; size -- ) { for ( int i = 0 ; i <= m - size ; i ++ ) { for ( int j = 0 ; j <= n - size ; j ++ ) { if ( is_valid ( i , j , size , grid ) ) { return size ; } } } } return 1 ; } int main ( ) { vector < vector < int > > grid = { { 7 , 1 , 4 , 5 , 6 } , { 2 , 5 , 1 , 6 , 4 } , { 1 , 5 , 4 , 3 , 2 } , { 1 , 2 , 7 , 3 , 4 } } ; cout << largestSquareValidMatrix ( grid ) ; return 0 ; }

Index/key variables: c_end, i, j, r, r_end
Accumulator variables: ad_sum, i, j, size, stdc, sum
Iterator variables: i, j, size
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumPossibleProduct ( int K ) { int res = 1 ; int range = ( 1 << K ) - 1 ; for ( int i = 0 ; i < K ; i ++ ) { res *= ( range - 1 ) ; } res *= range ; return res ; } int main ( ) { int K = 3 ; cout << minimumPossibleProduct ( K ) ; return 0 ; }

Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximizeSubset ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; int maxSize = 0 ; int i = 0 ; int j = i + 2 ; while ( i < N - 2 ) { while ( arr [ i ] + arr [ i + 1 ] > arr [ j ] ) { j ++ ; } maxSize = max ( maxSize , j - i ) ; i ++ ; j = max ( j , i + 2 ) ; } return maxSize ; } int main ( ) { int arr [ ] = { 2 , 7 , 4 , 1 , 6 , 9 , 5 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximizeSubset ( arr , N ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxShiftArrayValue ( int arr [ ] , int cap [ ] , int N ) { int sumVals = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sumVals += arr [ i ] ; } int maxCapacity = 0 ; for ( int i = 0 ; i < N ; i ++ ) { maxCapacity = max ( cap [ i ] , maxCapacity ) ; } return min ( maxCapacity , sumVals ) ; } int main ( ) { int arr [ ] = { 2 , 3 } ; int cap [ ] = { 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxShiftArrayValue ( arr , cap , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sumVals
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Find ( vector < int > & parent , int a ) { return parent [ a ] = ( parent [ a ] == a ? a : Find ( parent , parent [ a ] ) ) ; } void Union ( vector < int > & parent , vector < int > & rank , vector < int > & minVal , int a , int b ) { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( rank [ a ] == rank [ b ] ) rank [ a ] ++ ; if ( rank [ a ] > rank [ b ] ) { parent [ b ] = a ; if ( minVal [ a ] >= 0 && minVal [ b ] >= 0 ) { minVal [ a ] = min ( minVal [ a ] , minVal [ b ] ) ; } else if ( minVal [ a ] >= 0 && minVal [ b ] < 0 ) { minVal [ a ] = minVal [ a ] ; } else if ( minVal [ a ] < 0 && minVal [ b ] >= 0 ) { minVal [ a ] = minVal [ b ] ; } else { minVal [ a ] = max ( minVal [ a ] , minVal [ b ] ) ; } } else { parent [ a ] = b ; if ( minVal [ a ] >= 0 && minVal [ b ] >= 0 ) { minVal [ b ] = min ( minVal [ a ] , minVal [ b ] ) ; } else if ( minVal [ a ] >= 0 && minVal [ b ] < 0 ) { minVal [ b ] = minVal [ a ] ; } else if ( minVal [ a ] < 0 && minVal [ b ] >= 0 ) { minVal [ b ] = minVal [ b ] ; } else { minVal [ b ] = max ( minVal [ a ] , minVal [ b ] ) ; } } } void findMinCost ( vector < pair < int , int > > & G , vector < int > & cost , int N , int M ) { vector < int > parent ( N + 1 ) ; vector < int > rank ( N + 1 , 0 ) ; vector < int > minVal ( N + 1 ) ; for ( int i = 1 ; i < N + 1 ; i ++ ) { parent [ i ] = i ; minVal [ i ] = cost [ i - 1 ] ; } for ( auto i : G ) { Union ( parent , rank , minVal , i . first , i . second ) ; } set < int > s ; for ( int i = 1 ; i < N + 1 ; i ++ ) { s . insert ( Find ( parent , i ) ) ; } pair < int , int > min = { 0 , INT_MAX } ; bool flag = false ; for ( auto i : s ) { if ( minVal [ i ] < 0 ) { flag = true ; } if ( min . second > minVal [ i ] ) { min = { i , minVal [ i ] } ; } } int minCost = 0 ; if ( ! flag || ( flag && s . size ( ) == 1 ) ) { for ( auto i : s ) { if ( i != min . first ) { minCost += ( minVal [ i ] + min . second ) ; } } cout << minCost << endl ; } else { cout << -1 << endl ; } } int main ( ) { int N = 6 ; vector < pair < int , int > > G = { { 3 , 1 } , { 2 , 3 } , { 2 , 1 } , { 4 , 5 } , { 5 , 6 } , { 6 , 4 } } ; vector < int > cost { 2 , 1 , 5 , 3 , 2 , 9 } ; int M = G . size ( ) ; findMinCost ( G , cost , N , M ) ; return 0 ; }

Index/key variables: a, b, i
Accumulator variables: i, minCost, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumSizeArray ( int S , int P ) { if ( S == P ) { return 1 ; } for ( int i = 2 ; i <= S ; i ++ ) { double d = i ; if ( ( S / d ) >= pow ( P , 1.0 / d ) ) { return i ; } } return -1 ; } int main ( ) { int S = 5 , P = 6 ; cout << minimumSizeArray ( S , P ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findVal ( int A [ ] , int B [ ] , int N ) { unordered_set < int > s ; for ( int i = 0 ; i < N ; i ++ ) { s . insert ( A [ i ] ) ; } sort ( A , A + N ) ; sort ( B , B + N - 1 ) ; int X = B [ 0 ] - A [ 1 ] ; if ( X <= 0 ) X = B [ 0 ] - A [ 0 ] ; else { for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( s . count ( B [ i ] - X ) == 0 ) { X = B [ 0 ] - A [ 0 ] ; break ; } } } cout << X << endl ; } int main ( ) { int A [ ] = { 1 , 4 , 3 , 8 } ; int B [ ] = { 15 , 8 , 11 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; findVal ( A , B , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPoints ( int D ) { int count = 0 ; for ( int x = 1 ; x * x < D * D ; x ++ ) { int y = ( int ) sqrt ( double ( D * D - x * x ) ) ; if ( x * x + y * y == D * D ) { count += 4 ; } } count += 4 ; return count ; } int main ( ) { int D = 5 ; cout << countPoints ( D ) ; return 0 ; }

Accumulator variables: count, stdc, x
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findTotalDistance ( string S , int N ) { vector < int > prefixDistance ( N ) ; vector < int > suffixDistance ( N ) ; int cnt = 0 ; bool haveOne = false ; for ( int i = 0 ; i < N ; ++ i ) { if ( S [ i ] == '1' ) { haveOne = true ; cnt = 0 ; prefixDistance [ i ] = 0 ; } else if ( haveOne ) { cnt ++ ; prefixDistance [ i ] = cnt ; } else prefixDistance [ i ] = INT_MAX ; } haveOne = false ; for ( int i = N - 1 ; i >= 0 ; -- i ) { if ( S [ i ] == '1' ) { haveOne = true ; cnt = 0 ; suffixDistance [ i ] = 0 ; } else if ( haveOne ) { cnt ++ ; suffixDistance [ i ] = cnt ; } else suffixDistance [ i ] = INT_MAX ; } int sum = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( S [ i ] == '0' ) { sum += min ( prefixDistance [ i ] , suffixDistance [ i ] ) ; } } cout << sum << endl ; } int main ( ) { string S = "100100" ; int N = S . length ( ) ; findTotalDistance ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, stdc, sum
Iterator variables: i
Boolean variables: haveOne
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimizeCost ( int A , int B , int C ) { int ans = A + B + C ; for ( int i = 1 ; i <= 2 * C ; i ++ ) { int j = 0 ; while ( i * j <= 2 * C ) { ans = min ( ans , abs ( A - i ) + abs ( B - j ) + abs ( i * j - C ) ) ; j ++ ; } } return ans ; } int main ( ) { int A = 19 , B = 28 , C = 522 ; cout << minimizeCost ( A , B , C ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; double averageSetBits ( int N , int K , int arr [ ] ) { double p = N ; double q = 0 ; for ( int i = 0 ; i < K ; i ++ ) { double _p = p , _q = q ; p = _p - _p * arr [ i ] / N + _q * arr [ i ] / N ; q = _q - _q * arr [ i ] / N + _p * arr [ i ] / N ; } return p ; } int main ( ) { int N = 5 ; int arr [ ] = { 1 , 2 , 3 } ; int K = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << setprecision ( 10 ) << averageSetBits ( N , K , arr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSubseq ( int arr [ ] , int N , int K ) { int sum = 0 ; sort ( arr , arr + N ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( K == 0 ) break ; if ( arr [ i ] < 0 ) { arr [ i ] = - arr [ i ] ; K -- ; } } for ( int i = 0 ; i < N ; i ++ ) if ( arr [ i ] > 0 ) sum += arr [ i ] ; return sum ; } int main ( ) { int arr [ ] = { 6 , -10 , -1 , 0 , -4 , 2 } ; int K = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSubseq ( arr , N , K ) ; 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 minimizeSegment ( vector < pair < int , int > > A , pair < int , int > X ) { sort ( A . begin ( ) , A . end ( ) ) ; A . push_back ( { INT_MAX , INT_MAX } ) ; int start = X . first ; int end = X . first - 1 ; int cnt = 0 ; for ( int i = 0 ; i < A . size ( ) ; ) { if ( A [ i ] . first <= start ) { end = max ( A [ i ++ ] . second , end ) ; } else { start = end ; ++ cnt ; if ( A [ i ] . first > end end >= X . second ) { break ; } } } if ( end < X . second ) { return -1 ; } return cnt ; } int main ( ) { vector < pair < int , int > > A = { { 1 , 3 } , { 2 , 4 } , { 2 , 10 } , { 2 , 3 } , { 1 , 1 } } ; pair < int , int > X = { 1 , 10 } ; cout << minimizeSegment ( A , X ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long KthSolution ( long long X , long long K ) { long long ans = 0 ; for ( int i = 0 ; i < 64 ; i ++ ) { if ( ! ( X & ( 1LL << i ) ) ) { if ( K & 1 ) { ans |= ( 1LL << i ) ; } K >>= 1 ; if ( ! K ) { break ; } } } return ans ; } int main ( ) { long long X = 5 , K = 5 ; cout << KthSolution ( X , K ) ; return 0 ; }

Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printTheArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; } void rearrange ( int arr [ ] , int N ) { if ( N & 1 ) N -- ; int odd_idx = 1 , even_idx = 0 ; int i , max_elem = arr [ N - 1 ] + 1 ; for ( i = 0 ; i < N / 2 ; i ++ ) { arr [ i ] += ( arr [ odd_idx ] % max_elem ) * max_elem ; odd_idx += 2 ; } for ( ; i < N ; i ++ ) { arr [ i ] += ( arr [ even_idx ] % max_elem ) * max_elem ; even_idx += 2 ; } for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = arr [ i ] / max_elem ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 16 , 18 , 19 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrange ( arr , N ) ; printTheArray ( arr , N ) ; return 0 ; }

Index/key variables: even_idx, i, odd_idx
Accumulator variables: N, even_idx, i, odd_idx, stdc
Iterator variables: i