dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <iostream>
using namespace std ; bool CheckForSequence ( int arr [ ] , int n , int k ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( k >= arr [ i ] ) k -= arr [ i ] ; } if ( k != 0 ) return false ; else return true ; } int main ( ) { int A [ ] = { 1 , 3 , 7 , 15 , 31 } ; int n = sizeof ( A ) / sizeof ( int ) ; cout << ( CheckForSequence ( A , n , 18 ) ? " True " : " False " ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void generateArray ( int n , int k ) { vector < int > array ( k , 0 ) ; int remaining = n - int ( k * ( k + 1 ) / 2 ) ; if ( remaining < 0 ) cout << ( " NO " ) ; int right_most = remaining % k ; int high = ceil ( remaining / ( k * 1.0 ) ) ; int low = floor ( remaining / ( k * 1.0 ) ) ; for ( int i = k - right_most ; i < k ; i ++ ) array [ i ] = high ; for ( int i = 0 ; i < ( k - right_most ) ; i ++ ) array [ i ] = low ; for ( int i = 0 ; i < k ; i ++ ) array [ i ] += i + 1 ; if ( k - 1 != remaining or k == 1 ) { for ( int u : array ) cout << u << " ▁ " ; } else if ( k == 2 or k == 3 ) printf ( " - 1 STRNEWLINE " ) ; else { array [ 1 ] -= 1 ; array [ k - 1 ] += 1 ; for ( int u : array ) cout << u << " ▁ " ; } } int main ( ) { int n = 26 , k = 6 ; generateArray ( n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, u
C++ program:
#include <bits/stdc++.h>
using namespace std ; string get_maximum ( string s , int a [ ] ) { int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] - '0' < a [ s [ i ] - '0' ] ) { int j = i ; while ( j < n && ( s [ j ] - '0' <= a [ s [ j ] - '0' ] ) ) { s [ j ] = '0' + a [ s [ j ] - '0' ] ; j ++ ; } return s ; } } return s ; } int main ( ) { string s = "1337" ; int a [ ] = { 0 , 1 , 2 , 5 , 4 , 6 , 6 , 3 , 1 , 9 } ; cout << get_maximum ( s , a ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSteps ( int n ) { int steps = 0 ; while ( n ) { int largest = sqrt ( n ) ; n -= ( largest * largest ) ; steps ++ ; } return steps ; } int main ( ) { int n = 85 ; cout << countSteps ( n ) ; return 0 ; }

Accumulator variables: n, stdc, steps
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumArr ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } int maxSum ( int arr [ ] , int n , int k ) { sort ( arr , arr + n ) ; int i = 0 ; while ( i < n && k > 0 && arr [ i ] < 0 ) { arr [ i ] *= -1 ; k -- ; i ++ ; } if ( k % 2 == 1 ) { int min = 0 ; for ( i = 1 ; i < n ; i ++ ) if ( arr [ min ] > arr [ i ] ) min = i ; arr [ min ] *= -1 ; } return sumArr ( arr , n ) ; } int main ( ) { int arr [ ] = { -5 , 4 , 1 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 4 ; cout << maxSum ( arr , n , k ) << endl ; return 0 ; }

Index/key variables: i, min
Accumulator variables: i, k, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Maxsum ( int c1 , int c2 , int c3 , int c4 ) { int sum = 0 ; int two34 = min ( c2 , min ( c3 , c4 ) ) ; sum = two34 * 234 ; c2 -= two34 ; sum += min ( c2 , c1 ) * 12 ; return sum ; } int main ( ) { int c1 = 5 , c2 = 2 , c3 = 3 , c4 = 4 ; cout << Maxsum ( c1 , c2 , c3 , c4 ) ; return 0 ; }

Accumulator variables: c2, stdc, sum
C++ program:
#include <iostream>
using namespace std ; void printArray ( int N , int arr [ ] ) { for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } void replacedArray ( int N , int arr [ ] ) { int pos_sum , neg_sum , i , j , diff ; pos_sum = 0 ; neg_sum = 0 ; for ( i = N - 1 ; i >= 0 ; i -- ) { diff = abs ( pos_sum ) - abs ( neg_sum ) ; if ( arr [ i ] > 0 ) pos_sum += arr [ i ] ; else neg_sum += arr [ i ] ; arr [ i ] = abs ( diff ) ; } } int main ( ) { int N = 5 ; int arr [ ] = { 1 , -1 , 2 , 3 , -2 } ; replacedArray ( N , arr ) ; printArray ( N , arr ) ; N = 6 ; int arr1 [ ] = { -3 , -4 , -2 , 5 , 1 , -2 } ; replacedArray ( N , arr1 ) ; printArray ( N , arr1 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, neg_sum, pos_sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCountOfPairs ( int a , int b , int n ) { int ans = 0 ; ans += n * ( a / n ) * ( b / n ) ; ans += ( a / n ) * ( b % n ) ; ans += ( a % n ) * ( b / n ) ; ans += ( ( a % n ) + ( b % n ) ) / n ; return ans ; } int main ( ) { int a = 5 , b = 13 , n = 3 ; cout << findCountOfPairs ( a , b , n ) ; return 0 ; }

Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findArray ( int N , int P ) { int ans = ( P * ( P + 1 ) ) / 2 + ( N - P ) ; int arr [ N + 1 ] ; for ( int i = 1 ; i <= P ; i ++ ) arr [ i ] = i ; for ( int i = P + 1 ; i <= N ; i ++ ) arr [ i ] = 1 ; cout << " The ▁ Minimum ▁ Possible ▁ Sum ▁ is : ▁ " << ans << " STRNEWLINE " ; cout << " The ▁ Array ▁ Elements ▁ are : ▁ STRNEWLINE " ; for ( int i = 1 ; i <= N ; i ++ ) cout << arr [ i ] << ' ▁ ' ; } int main ( ) { int N = 5 , P = 3 ; findArray ( N , P ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findIntersection ( int intervals [ ] [ 2 ] , int N ) { int l = intervals [ 0 ] [ 0 ] ; int r = intervals [ 0 ] [ 1 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( intervals [ i ] [ 0 ] > r intervals [ i ] [ 1 ] < l ) { cout << -1 ; return ; } else { l = max ( l , intervals [ i ] [ 0 ] ) ; r = min ( r , intervals [ i ] [ 1 ] ) ; } } cout << " [ " << l << " , ▁ " << r << " ] " ; } int main ( ) { int intervals [ ] [ 2 ] = { { 1 , 6 } , { 2 , 8 } , { 3 , 10 } , { 5 , 8 } } ; int N = sizeof ( intervals ) / sizeof ( intervals [ 0 ] ) ; findIntersection ( intervals , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int cmp ( int a , int b ) { return ( a > b ) - ( a < b ) ; } int maxSubarraySize ( int arr [ ] , int n ) { int ans = 1 ; int anchor = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int c = cmp ( arr [ i - 1 ] , arr [ i ] ) ; if ( c == 0 ) anchor = i ; else if ( i == n - 1 || c * cmp ( arr [ i ] , arr [ i + 1 ] ) != -1 ) { ans = max ( ans , i - anchor + 1 ) ; anchor = i ; } } return ans ; } int main ( ) { int arr [ ] = { 9 , 4 , 2 , 10 , 7 , 8 , 8 , 1 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSubarraySize ( arr , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSubStrings ( string s , int k ) { int maxSubStr = 0 , n = s . size ( ) ; for ( int c = 0 ; c < 26 ; c ++ ) { char ch = ' a ' + c ; int curr = 0 ; for ( int i = 0 ; i <= n - k ; i ++ ) { if ( s [ i ] != ch ) continue ; int cnt = 0 ; while ( i < n && s [ i ] == ch && cnt != k ) { i ++ ; cnt ++ ; } i -- ; if ( cnt == k ) curr ++ ; } maxSubStr = max ( maxSubStr , curr ) ; } return maxSubStr ; } int main ( ) { string s = " aaacaabbaa " ; int k = 2 ; cout << maxSubStrings ( s , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: c, cnt, curr, i, stdc
Iterator variables: c, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ValidPairs ( int arr [ ] , int n ) { int count [ 121 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] += 1 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] ) continue ; if ( abs ( arr [ i ] - arr [ j ] ) % 2 == 1 ) continue ; ans += count [ arr [ i ] ] * count [ arr [ j ] ] ; if ( arr [ i ] == arr [ j ] ) ans -= count [ arr [ i ] ] ; } return ans ; } int main ( ) { int arr [ ] = { 16 , 17 , 18 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << ( ValidPairs ( arr , n ) ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void check_distribution ( int n , int k , int age [ ] , int candy [ ] ) { int mxage = * ( std :: max_element ( age , age + n ) ) + 1 ; int mxcandy = * ( std :: max_element ( candy , candy + k ) ) + 1 ; int fr1 [ mxage ] = { 0 } ; int fr2 [ mxcandy ] = { 0 } ; for ( int j = 0 ; j < n ; j ++ ) { fr1 [ age [ j ] ] += 1 ; } for ( int j = 0 ; j < k ; j ++ ) { fr2 [ candy [ j ] ] += 1 ; } k = 0 ; bool Tf = true ; for ( int j = 0 ; j < mxage ; j ++ ) { if ( fr1 [ j ] == 0 ) continue ; bool flag = false ; while ( k < mxcandy ) { if ( fr1 [ j ] <= fr2 [ k ] ) { flag = true ; break ; } k += 1 ; } k = k + 1 ; if ( flag == false ) { Tf = false ; break ; } } if ( Tf ) cout << " YES " << endl ; else cout << " NO " << endl ; } int main ( ) { int age [ ] = { 5 , 15 , 10 } ; int candy [ ] = { 2 , 2 , 2 , 3 , 3 , 4 } ; int n = sizeof ( age ) / sizeof ( age [ 0 ] ) ; int k = sizeof ( candy ) / sizeof ( candy [ 0 ] ) ; check_distribution ( n , k , age , candy ) ; return 0 ; }

Index/key variables: j, k, mxage, mxcandy
Accumulator variables: j, k, stdc
Iterator variables: j
Boolean variables: Tf, flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkPalindrome ( string s ) { string x = s ; reverse ( s . begin ( ) , s . end ( ) ) ; return s == x ; } string findStringB ( string A ) { string B = A ; reverse ( A . begin ( ) , A . end ( ) ) ; A = A + B ; if ( checkPalindrome ( B ) ) return B ; return A ; } string reverse ( string input ) { string temparray = input ; int left , right = 0 ; right = temparray . length ( ) - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) swap ( temparray [ left ] , temparray [ right ] ) ; return temparray ; } int main ( int argc , char const * argv [ ] ) { string A = " ab " ; cout << findStringB ( A ) << endl ; return 0 ; }

Index/key variables: left, right
Accumulator variables: left, right, stdc
Iterator variables: left
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minChanges ( int A [ ] , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n - 2 ; ++ i ) { if ( ( i - 1 >= 0 ) && A [ i - 1 ] == 1 && A [ i + 1 ] == 1 && A [ i ] == 0 ) { A [ i + 1 ] = 0 ; cnt ++ ; } } return cnt ; } int main ( ) { int A [ ] = { 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 0 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minChanges ( A , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void completeSuquence ( string s ) { int n = s . length ( ) ; int open = 0 , close = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ( ' ) open ++ ; else close ++ ; if ( close > open ) { cout << " Impossible " << endl ; return ; } } cout << s ; for ( int i = 0 ; i < open - close ; i ++ ) cout << ' ) ' ; cout << endl ; } int main ( ) { string s = " ( ( ) ( ( ) ( " ; completeSuquence ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: close, i, open
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string smallestPermute ( int n ) { char res [ n + 1 ] ; if ( n % 2 == 0 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) res [ i ] = 48 + i + 2 ; else res [ i ] = 48 + i ; } } else { for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( i % 2 == 0 ) res [ i ] = 48 + i + 2 ; else res [ i ] = 48 + i ; } res [ n - 1 ] = 48 + n - 2 ; res [ n - 2 ] = 48 + n ; res [ n - 3 ] = 48 + n - 1 ; } res [ n ] = ' \0' ; return res ; } int main ( ) { int n = 7 ; cout << smallestPermute ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minInsertions ( int H [ ] , int n , int K ) { int inser = 0 ; for ( int i = 1 ; i < n ; ++ i ) { float diff = abs ( H [ i ] - H [ i - 1 ] ) ; if ( diff <= K ) continue ; else inser += ceil ( diff / K ) - 1 ; } return inser ; } int main ( ) { int H [ ] = { 2 , 4 , 8 , 16 } , K = 3 ; int n = sizeof ( H ) / sizeof ( H [ 0 ] ) ; cout << minInsertions ( H , n , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: inser, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_minimum_operations ( long long n ) { int count = 0 ; while ( n > 1 ) { if ( n % 3 == 0 ) n /= 3 ; else if ( n % 3 == 1 ) n -- ; else { if ( n == 2 ) n -- ; else n ++ ; } count ++ ; } return count ; } int main ( ) { long long n = 4 ; long long ans = count_minimum_operations ( n ) ; cout << ans << endl ; return 0 ; }

Accumulator variables: count, n, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_minimum_operations ( long long n ) { if ( n == 2 ) { return 1 ; } else if ( n == 1 ) { return 0 ; } if ( n % 3 == 0 ) { return 1 + count_minimum_operations ( n / 3 ) ; } else if ( n % 3 == 1 ) { return 1 + count_minimum_operations ( n - 1 ) ; } else { return 1 + count_minimum_operations ( n + 1 ) ; } } int main ( ) { long long n = 4 ; long long ans = count_minimum_operations ( n ) ; cout << ans << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxSum ( int * a , int n ) { vector < int > l ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += abs ( a [ i ] ) ; if ( a [ i ] >= 0 ) continue ; if ( i == 0 ) l . push_back ( i + 1 ) ; else { l . push_back ( i + 1 ) ; l . push_back ( i ) ; } } cout << s << endl ; for ( int i = 0 ; i < l . size ( ) ; i ++ ) cout << l [ i ] << " ▁ " ; } int main ( ) { int n = 4 ; int a [ ] = { 1 , -2 , -3 , 4 } ; maxSum ( a , n ) ; }

Index/key variables: i
Accumulator variables: i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void LengthLCP ( string x , string y ) { int fr [ 26 ] = { 0 } ; for ( int i = 0 ; i < b ; i ++ ) { fr [ y [ i ] - 97 ] += 1 ; } int c = 0 ; for ( int i = 0 ; i < a ; i ++ ) { if ( fr [ x [ i ] - 97 ] > 0 ) { c += 1 ; fr [ x [ i ] - 97 ] -= 1 ; } else break ; } cout << ( c ) << endl ; } int main ( ) { string x = " here " , y = " there " ; LengthLCP ( x , y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: c, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CountPair ( int L , int R ) { int x = ( R - L + 1 ) ; cout << x / 2 << " STRNEWLINE " ; } int main ( ) { int L , R ; L = 1 , R = 8 ; CountPair ( L , R ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int problemsLeft ( int K , int P , int N ) { if ( K <= P ) return 0 ; else return ( K - P ) * N ; } int main ( ) { int K , P , N ; K = 4 ; P = 1 ; N = 10 ; cout << problemsLeft ( K , P , N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define V  5
int parent [ V ] ; int find ( int i ) { while ( parent [ i ] != i ) i = parent [ i ] ; return i ; } void union1 ( int i , int j ) { int a = find ( i ) ; int b = find ( j ) ; parent [ a ] = b ; } void kruskalMST ( int cost [ ] [ V ] ) { for ( int i = 0 ; i < V ; i ++ ) parent [ i ] = i ; int edge_count = 0 ; while ( edge_count < V - 1 ) { int min = INT_MAX , a = -1 , b = -1 ; for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( find ( i ) != find ( j ) && cost [ i ] [ j ] < min ) { min = cost [ i ] [ j ] ; a = i ; b = j ; } } } union1 ( a , b ) ; printf ( " Edge ▁ % d : ( % d , ▁ % d ) ▁ cost : % d ▁ STRNEWLINE " , edge_count ++ , a , b , min ) ; mincost += min ; } printf ( " Minimum cost = % d " , mincost ) ; } int main ( ) { int cost [ ] [ V ] = { { INT_MAX , 2 , INT_MAX , 6 , INT_MAX } , { 2 , INT_MAX , 3 , 8 , 5 } , { INT_MAX , 3 , INT_MAX , INT_MAX , 7 } , { 6 , 8 , INT_MAX , INT_MAX , 9 } , { INT_MAX , 5 , 7 , 9 , INT_MAX } , } ; kruskalMST ( cost ) ; return 0 ; }

Index/key variables: V, a, i, j
Accumulator variables: edge_count, i, j, mincost, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int results ( int n , int k ) { return round ( pow ( n , ( 1.0 / pow ( 2 , k ) ) ) ) ; } int main ( ) { int k = 3 , n = 100000000 ; cout << " Chocolates ▁ left ▁ after ▁ " << k << " ▁ iterations ▁ are ▁ " << results ( n , k ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int * getSubArray ( int arr [ ] , int n , int K ) { int i = -1 ; int j = -1 ; int currSum = 0 ; int * result = new int [ 3 ] { i , j , abs ( K - abs ( currSum ) ) } ; for ( i = 0 ; i < n ; i ++ ) { currSum = 0 ; for ( j = i ; j < n ; j ++ ) { currSum += arr [ j ] ; int currDev = abs ( K - abs ( currSum ) ) ; if ( currDev < result [ 2 ] ) { result [ 0 ] = i ; result [ 1 ] = j ; result [ 2 ] = currDev ; } if ( currDev == 0 ) return result ; } } return result ; } int main ( ) { int arr [ 8 ] = { 15 , -3 , 5 , 2 , 7 , 6 , 34 , -6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 50 ; int * ans = getSubArray ( arr , n , K ) ; if ( ans [ 0 ] == -1 ) { cout << " The ▁ empty ▁ array ▁ shows ▁ " << " minimum ▁ Deviation " ; } else { for ( int i = ans [ 0 ] ; i <= ans [ 1 ] ; i ++ ) cout << arr [ i ] << " ▁ " ; } return 0 ; }

Index/key variables: i, j
Accumulator variables: currSum, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubsequence ( int a [ ] , int n , int q [ ] , int m ) { sort ( a , a + n ) ; int sum = 0 ; int b [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; double av = ( double ) ( sum ) / ( double ) ( i + 1 ) ; b [ i ] = ( ( int ) ( av + 1 ) ) ; } sort ( b , b + n ) ; for ( int i = 0 ; i < m ; i ++ ) { int k = q [ i ] ; int longest = upper_bound ( b , b + n , k ) - b ; cout << " Answer ▁ to ▁ Query " << i + 1 << " : ▁ " << longest << endl ; } } int main ( ) { int a [ ] = { 1 , 3 , 2 , 5 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int q [ ] = { 4 , 2 , 1 , 5 } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; longestSubsequence ( a , n , q , m ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int steps ( int N , int M ) { if ( N == 1 ) return 0 ; return M ; return 2 * M + ( N - 3 ) ; } int main ( ) { int N = 4 , M = 4 ; cout << steps ( N , M ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int DecreasingArray ( int a [ ] , int n ) { int sum = 0 , dif = 0 ; priority_queue < int , vector < int > , greater < int > > pq ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! pq . empty ( ) && pq . top ( ) < a [ i ] ) { dif = a [ i ] - pq . top ( ) ; sum += dif ; pq . pop ( ) ; } pq . push ( a [ i ] ) ; } return sum ; } int main ( ) { int a [ ] = { 3 , 1 , 2 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << DecreasingArray ( a , 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 solve ( int a [ ] , int b [ ] , int n ) { int i ; long long int s = 0 ; for ( i = 0 ; i < n ; i ++ ) s += ( a [ i ] + b [ i ] ) ; if ( n == 1 ) return a [ 0 ] + b [ 0 ] ; if ( s % n != 0 ) return -1 ; int x = s / n ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) return -1 ; if ( i > 0 ) { a [ i ] += b [ i - 1 ] ; b [ i - 1 ] = 0 ; } if ( a [ i ] == x ) continue ; int y = a [ i ] + b [ i ] ; if ( i + 1 < n ) y += b [ i + 1 ] ; if ( y == x ) { a [ i ] = y ; b [ i ] = b [ i + 1 ] = 0 ; continue ; } if ( a [ i ] + b [ i ] == x ) { a [ i ] += b [ i ] ; b [ i ] = 0 ; continue ; } if ( i + 1 < n && a [ i ] + b [ i + 1 ] == x ) { a [ i ] += b [ i + 1 ] ; b [ i + 1 ] = 0 ; continue ; } return -1 ; } for ( i = 0 ; i < n ; i ++ ) if ( b [ i ] != 0 ) return -1 ; return x ; } int main ( ) { int a [ ] = { 6 , 14 , 21 , 1 } ; int b [ ] = { 15 , 7 , 10 , 10 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << solve ( a , b , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, s, stdc, y
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void survival ( int S , int N , int M ) { if ( ( ( N * 6 ) < ( M * 7 ) && S > 6 ) M > N ) cout << " No STRNEWLINE " ; else { int days = ( M * S ) / N ; if ( ( ( M * S ) % N ) != 0 ) days ++ ; cout << " Yes ▁ " << days << endl ; } } int main ( ) { int S = 10 , N = 16 , M = 2 ; survival ( S , N , M ) ; return 0 ; }

Accumulator variables: days, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void subsequence ( char s [ ] , char t [ ] , int n , int k ) { int last = 0 , cnt = 0 , new_last = 0 , size = 0 ; for ( char ch = ' z ' ; ch >= ' a ' ; ch -- ) { cnt = 0 ; for ( int i = last ; i < n ; i ++ ) { if ( s [ i ] == ch ) cnt ++ ; } if ( cnt >= k ) { for ( int i = last ; i < n ; i ++ ) { if ( s [ i ] == ch ) { t [ size ++ ] = ch ; new_last = i ; } } last = new_last ; } } t [ size ] = ' \0' ; } int main ( ) { char s [ ] = " banana " ; int n = sizeof ( s ) ; int k = 2 ; char t [ n ] ; subsequence ( s , t , n - 1 , k ) ; cout << t << endl ; return 0 ; }

Index/key variables: i, n, size
Accumulator variables: ch, cnt, i, size, stdc
Iterator variables: ch, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int pageFaults ( int pages [ ] , int n , int capacity ) { unordered_set < int > s ; unordered_map < int , int > indexes ; int page_faults = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . size ( ) < capacity ) { if ( s . find ( pages [ i ] ) == s . end ( ) ) { s . insert ( pages [ i ] ) ; page_faults ++ ; } indexes [ pages [ i ] ] = i ; } else { if ( s . find ( pages [ i ] ) == s . end ( ) ) { int lru = INT_MAX , val ; for ( auto it = s . begin ( ) ; it != s . end ( ) ; it ++ ) { if ( indexes [ * it ] < lru ) { lru = indexes [ * it ] ; val = * it ; } } s . erase ( val ) ; s . insert ( pages [ i ] ) ; page_faults ++ ; } indexes [ pages [ i ] ] = i ; } } return page_faults ; } int main ( ) { int pages [ ] = { 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 } ; int n = sizeof ( pages ) / sizeof ( pages [ 0 ] ) ; int capacity = 4 ; cout << pageFaults ( pages , n , capacity ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, it, page_faults, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std ; void bestpermutation ( int arr [ ] , int k , int n ) { unordered_map < int , int > h ; for ( int i = 0 ; i < n ; i ++ ) { h . insert ( make_pair ( arr [ i ] , i ) ) ; } if ( n <= k ) { sort ( arr , arr + n , greater < int > ( ) ) ; } else { for ( int j = n ; j >= 1 ; j -- ) { if ( k > 0 ) { int initial_index = h [ j ] ; int best_index = n - j ; if ( initial_index != best_index ) { h [ j ] = best_index ; int element = arr [ best_index ] ; h [ element ] = initial_index ; swap ( arr [ best_index ] , arr [ initial_index ] ) ; k -- ; } } } } } int main ( ) { int arr [ ] = { 3 , 1 , 4 , 2 , 5 } ; int k = 10 ; int n = sizeof ( arr ) / sizeof ( int ) ; bestpermutation ( arr , k , n ) ; cout << " Largest ▁ possible ▁ permutation ▁ after ▁ " << k << " ▁ swaps ▁ is ▁ " ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: best_index, element, i, initial_index, j
Accumulator variables: i, j, k, stdc
Iterator variables: i, j