dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findRange ( int arr [ ] , int N , int K ) { int L = INT_MIN ; int R = INT_MAX ; for ( int i = 0 ; i < N ; i ++ ) { int l = ( int ) ceil ( 1.0 * arr [ i ] * K / ( i + 1 ) ) ; int r = ( int ) ceil ( ( 1.0 + arr [ i ] ) * K / ( i + 1 ) ) - 1 ; L = max ( L , l ) ; R = min ( R , r ) ; } cout << L << " ▁ " << R ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 , 9 , 11 } ; int K = 10 ; int N = sizeof ( arr ) / sizeof ( int ) ; findRange ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findAnagram ( string s ) { string check = s ; int i = 0 , j = s . length ( ) - 1 ; while ( i < s . length ( ) && j >= 0 ) { if ( s [ i ] != s [ j ] && check [ i ] != s [ j ] && check [ j ] != s [ i ] ) { swap ( s [ i ] , s [ j ] ) ; i ++ ; j = s . length ( ) - 1 ; } else { j -- ; } } if ( s . length ( ) % 2 != 0 ) { int mid = s . length ( ) / 2 ; if ( check [ mid ] == s [ mid ] ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( check [ i ] != s [ mid ] && s [ i ] != s [ mid ] ) { swap ( s [ i ] , s [ mid ] ) ; break ; } } } } bool ok = true ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( check [ i ] == s [ i ] ) { ok = false ; break ; } } if ( ok ) cout << s ; else cout << -1 ; } int main ( ) { string S = " geek " ; findAnagram ( S ) ; return 0 ; }

Index/key variables: i, j, mid
Accumulator variables: i, j, stdc
Iterator variables: i
Boolean variables: ok
C++ program:
#include <bits/stdc++.h>
using namespace std ; void constructPermutation ( string S , int N ) { int ans [ N ] ; ans [ 0 ] = 1 ; for ( int i = 1 ; i < N ; ++ i ) { if ( S [ i - 1 ] == '0' ) { ans [ i ] = i + 1 ; } else { ans [ i ] = ans [ i - 1 ] ; } for ( int j = 0 ; j < i ; ++ j ) { if ( ans [ j ] >= ans [ i ] ) { ans [ j ] ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { cout << ans [ i ] ; if ( i != N - 1 ) { cout << " ▁ " ; } } } int main ( ) { string S = "100101" ; constructPermutation ( S , S . length ( ) + 1 ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, stdc
Iterator variables: i, j
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 = 10 , 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 ; int countArrays ( int n , int k ) { vector < vector < int > > divisors ( k + 1 ) ; for ( int i = 1 ; i <= k ; i ++ ) { for ( int j = 2 * i ; j <= k ; j += i ) { divisors [ j ] . push_back ( i ) ; } } vector < vector < int > > dp ( n + 1 , vector < int > ( k + 1 ) ) ; for ( int j = 1 ; j <= k ; j ++ ) { dp [ 1 ] [ j ] = 1 ; } for ( int x = 2 ; x <= n ; x ++ ) { int sum = 0 ; for ( int j = 1 ; j <= k ; j ++ ) { sum += dp [ x - 1 ] [ j ] ; } for ( int y = 1 ; y <= k ; y ++ ) { dp [ x ] [ y ] = sum ; for ( int d : divisors [ y ] ) { dp [ x ] [ y ] = ( dp [ x ] [ y ] - dp [ x - 1 ] [ d ] ) ; } } } int sum = 0 ; for ( int j = 1 ; j <= k ; j ++ ) { sum += dp [ n ] [ j ] ; } return sum ; } int main ( ) { int N = 2 , K = 3 ; cout << countArrays ( N , K ) ; return 0 ; }

Index/key variables: d, j, n, x, y
Accumulator variables: i, j, stdc, sum, x, y
Iterator variables: d, i, j, x, y
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumMoves ( int A [ ] , int B [ ] , int N ) { int ans = 0 ; int sum_A = 0 , sum_B = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum_A += A [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { sum_B += B [ i ] ; } if ( sum_A != sum_B ) { return -1 ; } int i = 0 ; while ( i < N ) { if ( A [ i ] > B [ i ] ) { int temp = A [ i ] - B [ i ] ; int j = i - 1 ; while ( j >= 0 && temp > 0 ) { if ( B [ j ] > A [ j ] ) { int cnt = min ( temp , ( B [ j ] - A [ j ] ) ) ; A [ j ] += cnt ; temp -= cnt ; ans += ( cnt * abs ( j - i ) ) ; } j -- ; } if ( temp > 0 ) { int j = i + 1 ; while ( j < N && temp > 0 ) { if ( B [ j ] > A [ j ] ) { int cnt = min ( temp , ( B [ j ] - A [ j ] ) ) ; A [ j ] += cnt ; temp -= cnt ; ans += ( cnt * abs ( j - i ) ) ; } j ++ ; } } } i ++ ; } return ans ; } int main ( ) { int A [ ] = { 1 , 5 , 7 } ; int B [ ] = { 13 , 0 , 0 } ; int N = sizeof ( A ) / sizeof ( int ) ; cout << minimumMoves ( A , B , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc, sum_A, sum_B, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int possibleReachingSequence ( int X , int D , int T ) { if ( X < T ) { cout << " NO " ; return 0 ; } if ( T * D < X ) { cout << " NO " ; return 0 ; } if ( ( X - T ) % ( D - 1 ) == 0 ) { cout << " YES " ; } else { cout << " NO " ; } return 0 ; } int main ( ) { int X = 10 , D = 3 , T = 6 ; possibleReachingSequence ( X , D , T ) ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int arrayDivisionByTwo ( int arr [ ] , int n ) { int cnt = 0 ; int ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { cnt = 0 ; while ( arr [ i ] % 2 == 0 ) { arr [ i ] = arr [ i ] / 2 ; cnt ++ ; } ans = min ( ans , cnt ) ; } return ans ; } int main ( ) { int arr [ ] = { 8 , 12 , 40 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << arrayDivisionByTwo ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printMinInteger ( int P , int Q , int N ) { if ( Q > P ) { swap ( P , Q ) ; } if ( Q == 0 && ( P == 0 N % P != 0 ) ) { cout << " Not ▁ Possible " ; return ; } int count_P = 0 , count_Q = 0 ; while ( N > 0 ) { if ( N % P == 0 ) { count_P += N / P ; N = 0 ; } else { N = N - Q ; count_Q ++ ; } } if ( N == 0 ) { for ( int i = 0 ; i < count_Q ; i ++ ) cout << Q ; for ( int i = 0 ; i < count_P ; i ++ ) cout << P ; } else { cout << " Not ▁ Possible " ; } } int main ( ) { int N = 32 ; int P = 7 ; int Q = 4 ; printMinInteger ( P , Q , N ) ; return 0 ; }

Accumulator variables: count_P, count_Q, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minPushes ( int N , int K , vector < int > arr ) { vector < int > dp ( 100000 , -1 ) ; dp [ N ] = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { for ( int xx = 0 ; xx < 100000 ; xx ++ ) { int x = xx ; if ( dp [ x ] == -1 ) continue ; int next = ( x + arr [ i ] ) % 100000 ; while ( dp [ next ] == -1 dp [ next ] > dp [ x ] + 1 ) { dp [ next ] = dp [ x ] + 1 ; x = next ; next = ( next + arr [ i ] ) % 100000 ; } } } return dp [ K ] ; } int main ( ) { int N = 99880 , K = 89 ; vector < int > arr { 100 , 3 } ; cout << minPushes ( N , K , arr ) ; return 0 ; }

Index/key variables: K, N, i, next, x
Accumulator variables: i, stdc, xx
Iterator variables: i, xx
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minApples ( int M , int K , int N , int S , int W , int E ) { if ( M <= S * K ) return M ; else if ( M <= S * K + E + W ) return S * K + ( M - S * K ) * K ; else return -1 ; } int main ( ) { int M = 10 ; int K = 15 ; int N = 0 ; int S = 1 ; int W = 0 ; int E = 0 ; int ans = minApples ( M , K , N , S , W , E ) ; cout << ans << endl ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumOperations ( int A [ ] , int N ) { int cur_prefix_1 = 0 ; int parity = -1 ; int minOperationsCase1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { cur_prefix_1 += A [ i ] ; if ( cur_prefix_1 == 0 parity * cur_prefix_1 < 0 ) { minOperationsCase1 += abs ( parity - cur_prefix_1 ) ; cur_prefix_1 = parity ; } parity *= -1 ; } int cur_prefix_2 = 0 ; parity = 1 ; int minOperationsCase2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { cur_prefix_2 += A [ i ] ; if ( cur_prefix_2 == 0 parity * cur_prefix_2 < 0 ) { minOperationsCase2 += abs ( parity - cur_prefix_2 ) ; cur_prefix_2 = parity ; } parity *= -1 ; } return min ( minOperationsCase1 , minOperationsCase2 ) ; } int main ( ) { int A [ ] = { 1 , -3 , 1 , 0 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minimumOperations ( A , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cur_prefix_1, cur_prefix_2, i, minOperationsCase1, minOperationsCase2, parity, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maximumSumArray ( int arr [ ] , int N ) { vector < int > arrA ( N ) , ans ( N ) ; int maxSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) arrA [ i ] = arr [ i ] ; for ( int i = 0 ; i < N ; i ++ ) { vector < int > arrB ( N ) ; int maximum = arrA [ i ] ; arrB [ i ] = maximum ; for ( int j = i - 1 ; j >= 0 ; j -- ) { arrB [ j ] = min ( maximum , arrA [ j ] ) ; maximum = arrB [ j ] ; } maximum = arrA [ i ] ; for ( int j = i + 1 ; j < N ; j ++ ) { arrB [ j ] = min ( maximum , arrA [ j ] ) ; maximum = arrB [ j ] ; } int sum = 0 ; for ( int j = 0 ; j < N ; j ++ ) sum += arrB [ j ] ; if ( sum > maxSum ) { maxSum = sum ; ans = arrB ; } } for ( int val : ans ) { cout << val << " ▁ " ; } } int main ( ) { int A [ ] = { 10 , 6 , 8 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; maximumSumArray ( A , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j, val
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minProductUtil ( int R1 , int B1 , int R2 , int B2 , int M ) { int x = min ( R1 - B1 , M ) ; M -= x ; R1 -= x ; if ( M > 0 ) { int y = min ( R2 - B2 , M ) ; M -= y ; R2 -= y ; } return R1 * R2 ; } int minProduct ( int R1 , int B1 , int R2 , int B2 , int M ) { int res1 = minProductUtil ( R1 , B1 , R2 , B2 , M ) ; int res2 = minProductUtil ( R2 , B2 , R1 , B1 , M ) ; return min ( res1 , res2 ) ; } int main ( ) { int R1 = 21 , B1 = 10 , R2 = 13 , B2 = 11 , M = 3 ; cout << ( minProduct ( R1 , B1 , R2 , B2 , M ) ) ; return 0 ; }

Accumulator variables: M, R1, R2, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxAmount ( int n , int k , int arr [ ] ) { int A [ 1000001 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { A [ arr [ i ] ] ++ ; } int j = 0 ; for ( int i = 0 ; i < 1000001 ; i ++ ) { while ( A [ i ] != 0 ) { arr [ j ++ ] = i ; A [ i ] -- ; } } long long int ans = 0 ; int mod = 1e9 + 7 ; int i = n - 1 ; j = n - 2 ; while ( k > 0 && j >= 0 ) { if ( arr [ i ] > arr [ j ] ) { ans = ans + min ( k , ( i - j ) ) * arr [ i ] ; k = k - ( i - j ) ; arr [ i ] -- ; } else { while ( j >= 0 && arr [ j ] == arr [ i ] ) j -- ; if ( j < 0 ) break ; ans = ans + min ( k , ( i - j ) ) * arr [ i ] ; k = k - ( i - j ) ; arr [ i ] -- ; } } while ( k > 0 && arr [ i ] != 0 ) { ans = ans + min ( n , k ) * arr [ i ] ; k -= n ; arr [ i ] -- ; } ans = ans % mod ; int x = ans ; return x ; } int main ( ) { int n = 5 ; int k = 3 ; int arr [ n ] = { 4 , 3 , 6 , 2 , 4 } ; int ans = maxAmount ( n , k , arr ) ; cout << ans ; 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 ; void maxAverage ( int A [ ] , int N , int X , int Y ) { sort ( A , A + N ) ; int sum = 0 ; double res = 0 ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; count ++ ; if ( count == X ) { if ( N - i - 1 < X ) { i ++ ; int cnt = 0 ; while ( i < N ) { cnt ++ ; sum += A [ i ] ; i ++ ; } X = X + cnt ; res += ( double ) sum / double ( X ) ; break ; } res += ( double ) sum / double ( X ) ; sum = 0 ; count = 0 ; } } cout << fixed << setprecision ( 2 ) << res << " STRNEWLINE " ; } int main ( ) { int A [ ] = { 4 , 10 , 6 , 5 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int X = 2 , Y = 3 ; maxAverage ( A , N , X , Y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, count, i, res, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isAdjChar ( string & s ) { for ( int i = 0 ; i < s . size ( ) - 1 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) return true ; } return false ; } void rearrangeStringUtil ( string & S , int N ) { int i = 0 , j = 1 , k = 2 ; while ( k < N ) { if ( S [ i ] != S [ j ] ) { i ++ ; j ++ ; if ( j == k ) { k ++ ; } } else { if ( S [ j ] == S [ k ] ) { k ++ ; } else { swap ( S [ k ] , S [ j ] ) ; i ++ ; j ++ ; if ( j == k ) { k ++ ; } } } } } string rearrangeString ( string & S , int N ) { if ( isAdjChar ( S ) == false ) { return S ; } if ( S . size ( ) == 2 ) return " - 1" ; rearrangeStringUtil ( S , N ) ; reverse ( S . begin ( ) , S . end ( ) ) ; rearrangeStringUtil ( S , N ) ; if ( isAdjChar ( S ) == false ) { return S ; } return " - 1" ; } int main ( ) { string S = " aaabc " ; int N = S . length ( ) ; cout << rearrangeString ( S , N ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string largestMerge ( string word1 , string word2 ) { string merge = " " ; while ( word1 . size ( ) != 0 || word2 . size ( ) != 0 ) { if ( word1 >= word2 ) { merge = merge + word1 [ 0 ] ; word1 . erase ( word1 . begin ( ) + 0 ) ; } else { merge = merge + word2 [ 0 ] ; word2 . erase ( word2 . begin ( ) + 0 ) ; } } return merge ; } int main ( ) { string S1 = " xyzxyz " ; string S2 = " xywzxyx " ; cout << largestMerge ( S1 , S2 ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaximumPoints ( int N , int X [ ] , int H [ ] ) { int ans = 0 ; int prev = INT_MIN ; for ( int i = 0 ; i < N ; ++ i ) { if ( prev < ( X [ i ] - H [ i ] ) ) { ++ ans ; prev = X [ i ] ; } else if ( i == N - 1 || ( X [ i ] + H [ i ] ) < X [ i + 1 ] ) { ++ ans ; prev = X [ i ] + H [ i ] ; } else { prev = X [ i ] ; } } return ans ; } int main ( ) { int X [ ] = { 1 , 2 , 3 } ; int H [ ] = { 2 , 5 , 5 } ; int N = sizeof ( X ) / sizeof ( X [ 0 ] ) ; cout << findMaximumPoints ( N , X , H ) ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sumOfCombinationOf4OR5 ( vector < int > arr , int N ) { vector < int > ans ( N , -1 ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 4 ) { continue ; } int sum = INT_MAX , cnt = 0 ; for ( int j = 0 ; j <= arr [ i ] ; j += 4 ) { if ( ( arr [ i ] - j ) % 5 == 0 ) { sum = min ( sum , cnt + ( arr [ i ] - j ) / 5 ) ; } cnt ++ ; } if ( sum != INT_MAX ) ans [ i ] = sum ; } for ( auto num : ans ) cout << num << " ▁ " ; } int main ( ) { vector < int > arr = { 7 , 15 , 17 , 22 } ; int N = arr . size ( ) ; sumOfCombinationOf4OR5 ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j, num
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printBinaryString ( int arr [ ] [ 3 ] , int N ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( i % 2 ) { cout << 0 ; } else { cout << 1 ; } } } int main ( ) { int N = 5 , M = 3 ; int arr [ ] [ 3 ] = { { 1 , 3 } , { 2 , 4 } , { 2 , 5 } } ; printBinaryString ( arr , N ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxZeroes ( vector < int > & A , vector < int > & B ) { map < pair < int , int > , int > mp ; int N = A . size ( ) ; int ans = 0 ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int num = - B [ i ] ; int den = A [ i ] ; int gc = __gcd ( num , den ) ; if ( den != 0 ) { num /= gc ; den /= gc ; } if ( num <= 0 ) { num *= -1 ; den *= -1 ; } if ( den == 0 and num == 0 ) cnt ++ ; if ( den != 0 ) { mp [ { num , den } ] ++ ; ans = max ( mp [ { num , den } ] , ans ) ; } } cout << ans + cnt << endl ; } int main ( ) { vector < int > A = { 1 , 2 , -1 } ; vector < int > B = { -6 , -12 , 6 } ; maxZeroes ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, den, i, num, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MinCost ( int days [ ] , int cost [ ] , int N ) { int size = days [ N - 1 ] + 1 ; int dp [ size ] ; dp [ size - 1 ] = min ( cost [ 0 ] , min ( cost [ 1 ] , cost [ 2 ] ) ) ; int ptr = N - 2 ; for ( int i = size - 2 ; i > 0 ; i -- ) { if ( ptr >= 0 && days [ ptr ] == i ) { int val1 = dp [ i + 1 ] + cost [ 0 ] ; int val2 = cost [ 1 ] + ( ( i + 7 >= size ) ? 0 : dp [ i + 7 ] ) ; int val3 = cost [ 2 ] + ( ( i + 30 >= size ) ? 0 : dp [ i + 30 ] ) ; dp [ i ] = min ( val1 , min ( val2 , val3 ) ) ; ptr -- ; } else { dp [ i ] = dp [ i + 1 ] ; } } return dp [ 1 ] ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 , 7 , 8 , 10 , 17 } ; int cost [ ] = { 3 , 8 , 20 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << MinCost ( arr , cost , N ) ; return 0 ; }

Index/key variables: i, ptr, size
Accumulator variables: i, ptr, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int minElements ( int arr [ ] , int N , int K ) { int count = 0 ; long long requiredNum = 1 ; int i = 0 ; while ( requiredNum <= K ) { if ( i < N && requiredNum >= arr [ i ] ) { requiredNum += arr [ i ] ; i ++ ; } else { count ++ ; requiredNum += requiredNum ; } } return count ; } int main ( ) { int arr [ ] = { 1 , 3 } ; int K = 6 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minElements ( arr , N , K ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, requiredNum
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool comp ( pair < long long , long long > p1 , pair < long long , long long > p2 ) { long double a = p1 . first , b = p1 . second ; long double c = p2 . first , d = p2 . second ; long double val1 = 0 , val2 = 0 ; val1 = a / b ; val2 = c / d ; return val1 > val2 ; } long double maximumProfit ( int A [ ] , int B [ ] , int N , long long W ) { vector < pair < long long , long long > > V ; for ( int i = 0 ; i < N ; i ++ ) { long long temp = sqrt ( A [ i ] ) ; if ( temp * temp == A [ i ] ) continue ; V . push_back ( { B [ i ] , A [ i ] } ) ; } sort ( V . begin ( ) , V . end ( ) , comp ) ; long double profit = 0.00 ; for ( int i = 0 ; i < V . size ( ) ; i ++ ) { if ( V [ i ] . second <= W ) { profit += V [ i ] . first ; W -= V [ i ] . second ; } else { profit += V [ i ] . first * ( ( long double ) W / V [ i ] . second ) ; break ; } } return profit ; } int main ( ) { int N = 3 ; long long W = 10 ; int A [ ] = { 4 , 5 , 7 } ; int B [ ] = { 8 , 5 , 4 } ; cout << maximumProfit ( A , B , N , W ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: W, i, profit, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumCount ( int arr [ ] , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 ) odd ++ ; else even ++ ; } if ( odd and even ) return N - 2 ; else return N - 1 ; } int main ( ) { int arr [ ] = { 9 , 13 , 15 , 3 , 16 , 9 , 13 , 18 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximumCount ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: even, i, odd, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minPossibleValue ( int N , int K , int X ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( X <= K ) { X = X * 2 ; } else { X = X + K ; } } return X ; } int main ( ) { int N = 7 , K = 4 , X = 1 ; cout << minPossibleValue ( N , K , X ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMissingValue ( int arr [ ] , int N ) { int minE = INT_MAX , maxE = INT_MIN ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] == -1 && arr [ i + 1 ] != -1 ) { minE = min ( minE , arr [ i + 1 ] ) ; maxE = max ( maxE , arr [ i + 1 ] ) ; } if ( arr [ i ] != -1 && arr [ i + 1 ] == -1 ) { minE = min ( minE , arr [ i ] ) ; maxE = max ( maxE , arr [ i ] ) ; } } if ( minE == INT_MAX and maxE == INT_MIN ) { cout << "0" ; } else { cout << ( minE + maxE ) / 2 ; } } int main ( ) { int arr [ ] = { 1 , -1 , -1 , -1 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findMissingValue ( 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 findLastElement ( int N , vector < int > A ) { int l = A . size ( ) ; int j = 0 ; while ( N > l * ( pow ( 2 , j ) ) ) { N = N - l * pow ( 2 , j ) ; j += 1 ; } int k = 1 ; int r = pow ( 2 , j ) ; for ( int i = 1 ; i < l ; i ++ ) { if ( N > r * i ) k += 1 ; } for ( int i = 0 ; i < l ; i ++ ) { if ( i + 1 == k ) { cout << ( A [ i ] ) ; return ; } } } int main ( ) { int K = 7 ; vector < int > A = { 1 , 2 , 3 } ; findLastElement ( K , A ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } int findMaxD ( int arr [ ] , int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = abs ( arr [ i ] - K ) ; } int D = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { D = gcd ( D , arr [ i ] ) ; } return D ; } int main ( ) { int arr [ ] = { 1 , 7 , 11 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << findMaxD ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxOperations ( string S , int N ) { int X = 0 ; int Y = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '0' ) break ; Y ++ ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S [ i ] == '1' ) break ; X ++ ; } if ( N == X + Y ) return 0 ; return N - ( X + Y ) - 1 ; } int main ( ) { string S = "001111" ; int N = S . length ( ) ; cout << maxOperations ( S , N ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: X, Y, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumSum ( string S , int N , int K ) { int sum = 0 ; int freq [ 256 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { freq [ int ( S [ i ] ) ] ++ ; } sort ( freq , freq + 256 , greater < int > ( ) ) ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( K > freq [ i ] ) { sum += freq [ i ] * freq [ i ] ; K -= freq [ i ] ; } else { sum += freq [ i ] * K ; break ; } } return sum ; } int main ( ) { string S = " GEEKSFORGEEKS " ; int K = 10 ; int N = S . length ( ) ; cout << maximumSum ( S , 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 dp [ 100 ] [ 10 ] [ 10 ] ; int countOfNumbers ( int digit , int prev1 , int prev2 , int n ) { if ( digit == n + 1 ) { return 1 ; } int & val = dp [ digit ] [ prev1 ] [ prev2 ] ; if ( val != -1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( int i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else if ( digit == 2 ) { for ( int i = 0 ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else { int diff = abs ( prev2 - prev1 ) ; for ( int i = 0 ; i <= 9 ; ++ i ) { if ( abs ( prev1 - i ) <= diff ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } } return val ; } int countNumbersUtil ( int N ) { memset ( dp , -1 , sizeof dp ) ; cout << countOfNumbers ( 1 , 0 , 0 , N ) ; } int main ( ) { int N = 3 ; countNumbersUtil ( N ) ; return 0 ; }

Index/key variables: digit, prev1, prev2
Accumulator variables: stdc, val
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void possibleNumbers ( set < int > & numbers , int N , int M , int A , int B ) { if ( M == 0 ) { numbers . insert ( N ) ; return ; } possibleNumbers ( numbers , N + A , M - 1 , A , B ) ; possibleNumbers ( numbers , N + B , M - 1 , A , B ) ; } int main ( ) { int N = 5 , M = 3 , A = 4 , B = 6 ; set < int > numbers ; possibleNumbers ( numbers , N , M , A , B ) ; for ( int x : numbers ) { cout << x << " ▁ " ; } return 0 ; }

Accumulator variables: stdc
Iterator variables: x