dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std ; int policeThief ( char arr [ ] , int n , int k ) { int res = 0 ; vector < int > thi ; vector < int > pol ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == ' P ' ) pol . push_back ( i ) ; else if ( arr [ i ] == ' T ' ) thi . push_back ( i ) ; } int l = 0 , r = 0 ; while ( l < thi . size ( ) && r < pol . size ( ) ) { if ( abs ( thi [ l ] - pol [ r ] ) <= k ) { res ++ ; l ++ ; r ++ ; } else if ( thi [ l ] < pol [ r ] ) l ++ ; else r ++ ; } return res ; } int main ( ) { int k , n ; char arr1 [ ] = { ' P ' , ' T ' , ' T ' , ' P ' , ' T ' } ; k = 2 ; n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << " Maximum ▁ thieves ▁ caught : ▁ " << policeThief ( arr1 , n , k ) << endl ; char arr2 [ ] = { ' T ' , ' T ' , ' P ' , ' P ' , ' T ' , ' P ' } ; k = 2 ; n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << " Maximum ▁ thieves ▁ caught : ▁ " << policeThief ( arr2 , n , k ) << endl ; char arr3 [ ] = { ' P ' , ' T ' , ' P ' , ' T ' , ' T ' , ' P ' } ; k = 3 ; n = sizeof ( arr3 ) / sizeof ( arr3 [ 0 ] ) ; cout << " Maximum ▁ thieves ▁ caught : ▁ " << policeThief ( arr3 , n , k ) << endl ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: i, l, r, res
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minRotation ( int input , int unlock_code ) { int rotation = 0 ; int input_digit , code_digit ; while ( input unlock_code ) { input_digit = input % 10 ; code_digit = unlock_code % 10 ; rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ; input /= 10 ; unlock_code /= 10 ; } return rotation ; } int main ( ) { int input = 28756 ; int unlock_code = 98234 ; cout << " Minimum ▁ Rotation ▁ = ▁ " << minRotation ( input , unlock_code ) ; return 0 ; }

Accumulator variables: input, rotation, stdc, unlock_code
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkJobs ( int startin [ ] , int endin [ ] , int n ) { vector < pair < int , int > > a ; for ( int i = 0 ; i < n ; i ++ ) a . push_back ( make_pair ( startin [ i ] , endin [ i ] ) ) ; sort ( a . begin ( ) , a . end ( ) ) ; long long tv1 = a [ 0 ] . second , tv2 = a [ 1 ] . second ; for ( int i = 2 ; i < n ; i ++ ) { if ( a [ i ] . first >= tv1 ) { tv1 = tv2 ; tv2 = a [ i ] . second ; } else if ( a [ i ] . first >= tv2 ) tv2 = a [ i ] . second ; else return false ; } return true ; } int main ( ) { int n = sizeof ( startin ) / sizeof ( startin [ 0 ] ) ; cout << checkJobs ( startin , endin , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void preprocess ( int coin [ ] , int n ) { sort ( coin , coin + n ) ; for ( int i = 1 ; i <= n - 1 ; i ++ ) coin [ i ] += coin [ i - 1 ] ; } int minCost ( int coin [ ] , int n , int k ) { int coins_needed = ceil ( 1.0 * n / ( k + 1 ) ) ; return coin [ coins_needed - 1 ] ; } int main ( ) { int coin [ ] = { 8 , 5 , 3 , 10 , 2 , 1 , 15 , 25 } ; int n = sizeof ( coin ) / sizeof ( coin [ 0 ] ) ; preprocess ( coin , n ) ; int k = 3 ; cout << minCost ( coin , n , k ) << endl ; k = 7 ; cout << minCost ( coin , n , k ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) { int allocation [ n ] ; memset ( allocation , -1 , sizeof ( allocation ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int wstIdx = -1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { if ( wstIdx == -1 ) wstIdx = j ; else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ; } } if ( wstIdx != -1 ) { allocation [ i ] = wstIdx ; blockSize [ wstIdx ] -= processSize [ i ] ; } } cout << " Process No . Process Size Block no . " ; for ( int i = 0 ; i < n ; i ++ ) { cout << " ▁ " << i + 1 << " TABSYMBOL TABSYMBOL " << processSize [ i ] << " TABSYMBOL TABSYMBOL " ; if ( allocation [ i ] != -1 ) cout << allocation [ i ] + 1 ; else cout << " Not ▁ Allocated " ; cout << endl ; } } int main ( ) { int blockSize [ ] = { 100 , 500 , 200 , 300 , 600 } ; int processSize [ ] = { 212 , 417 , 112 , 426 } ; int m = sizeof ( blockSize ) / sizeof ( blockSize [ 0 ] ) ; int n = sizeof ( processSize ) / sizeof ( processSize [ 0 ] ) ; worstFit ( blockSize , m , processSize , n ) ; return 0 ; }

Index/key variables: i, j, n, wstIdx
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumSum ( int arr [ ] , int n , int k ) { for ( int i = 1 ; i <= k ; i ++ ) { int min = INT_MAX ; int index = -1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] < min ) { min = arr [ j ] ; index = j ; } } if ( min == 0 ) break ; arr [ index ] = - arr [ index ] ; } int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } int main ( ) { int arr [ ] = { -2 , 0 , 5 , -1 , 2 } ; int k = 4 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximumSum ( arr , n , k ) ; return 0 ; }

Index/key variables: i, index, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sol ( int arr [ ] , int n , int k ) { int sum = 0 ; int i = 0 ; sort ( arr , arr + n ) ; while ( k > 0 ) { if ( arr [ i ] >= 0 ) k = 0 ; else { arr [ i ] = ( -1 ) * arr [ i ] ; k = k - 1 ; } i ++ ; } for ( int j = 0 ; j < n ; j ++ ) { sum += arr [ j ] ; } return sum ; } int main ( ) { int arr [ ] = { -2 , 0 , 5 , -1 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << sol ( arr , n , 4 ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: j
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; long long int sumArray ( long long int * arr , int n ) { long long int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } return sum ; } long long int maximizeSum ( long long int arr [ ] , int n , int k ) { sort ( arr , arr + n ) ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( k && arr [ i ] < 0 ) { arr [ i ] *= -1 ; k -- ; continue ; } break ; } if ( i == n ) i -- ; if ( k == 0 k % 2 == 0 ) { return sumArray ( arr , n ) ; } if ( i != 0 && abs ( arr [ i ] ) >= abs ( arr [ i - 1 ] ) ) { i -- ; } arr [ i ] *= -1 ; return sumArray ( arr , n ) ; } int main ( ) { int n = 5 ; int k = 4 ; long long int arr [ 5 ] = { -3 , -2 , -1 , 5 , 6 } ; cout << maximizeSum ( arr , n , k ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, k, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int firstFit ( int weight [ ] , int n , int c ) { int res = 0 ; int bin_rem [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < res ; j ++ ) { if ( bin_rem [ j ] >= weight [ i ] ) { bin_rem [ j ] = bin_rem [ j ] - weight [ i ] ; break ; } } if ( j == res ) { bin_rem [ res ] = c - weight [ i ] ; res ++ ; } } return res ; } int main ( ) { int weight [ ] = { 2 , 5 , 4 , 7 , 1 , 3 , 8 } ; int c = 10 ; int n = sizeof ( weight ) / sizeof ( weight [ 0 ] ) ; cout << " Number ▁ of ▁ bins ▁ required ▁ in ▁ First ▁ Fit ▁ : ▁ " << firstFit ( weight , n , c ) ; return 0 ; }

Index/key variables: i, j, n, res
Accumulator variables: i, j, res, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMinOperations ( int A , int B , int prevA , int prevB , vector < vector < int > > & dp ) { if ( A == prevA and B == prevB ) { return INT_MAX ; } if ( A == 0 and B == 0 ) { return 0 ; } if ( dp [ A ] [ B ] != -1 ) { return dp [ A ] [ B ] ; } int ans1 = getMinOperations ( A / 2 , B , A , B , dp ) ; if ( ans1 != INT_MAX ) { ans1 += 1 ; } int ans2 = getMinOperations ( A , B / 2 , A , B , dp ) ; if ( ans2 != INT_MAX ) { ans2 += 1 ; } int ans3 = getMinOperations ( sqrt ( A * B ) , sqrt ( A * B ) , A , B , dp ) ; if ( ans3 != INT_MAX ) { ans3 += 2 ; } return dp [ A ] [ B ] = min ( { ans1 , ans2 , ans3 } ) ; } int main ( ) { int A = 53 , B = 16 ; int mx = max ( A , B ) ; vector < vector < int > > dp ( mx + 1 , vector < int > ( mx + 1 , -1 ) ) ; cout << getMinOperations ( A , B , -1 , -1 , dp ) ; }

Index/key variables: A, B
Accumulator variables: ans1, ans2, ans3, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void dfs ( int src , vector < bool > & visited , vector < vector < int > > & graph , vector < int > & component , int N ) { visited [ src ] = true ; component . push_back ( src ) ; for ( int dest = 0 ; dest < N ; dest ++ ) { if ( graph [ src ] [ dest ] != INT_MAX ) { if ( ! visited [ dest ] ) dfs ( dest , visited , graph , component , N ) ; } } } void floydWarshall ( vector < vector < int > > & graph , int N ) { for ( int k = 0 ; k < N ; k ++ ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( graph [ i ] [ k ] != INT_MAX && graph [ k ] [ j ] != INT_MAX ) { if ( graph [ i ] [ k ] + graph [ k ] [ j ] < graph [ i ] [ j ] ) graph [ i ] [ j ] = graph [ i ] [ k ] + graph [ k ] [ j ] ; } } } } } int maxInThisComponent ( vector < int > & component , vector < vector < int > > & graph ) { int maxDistance = INT_MIN ; int n = component . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { maxDistance = max ( maxDistance , graph [ component [ i ] ] [ component [ j ] ] ) ; } } return ( maxDistance == INT_MIN ? 0 : maxDistance ) ; } vector < int > maximumShortesDistances ( vector < vector < int > > & graph , int N ) { vector < bool > visited ( N , false ) ; vector < vector < int > > components ; vector < int > temp ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! visited [ i ] ) { temp . clear ( ) ; dfs ( i , visited , graph , temp , N ) ; components . push_back ( temp ) ; } } floydWarshall ( graph , N ) ; vector < int > result ; int numOfComp = components . size ( ) ; int maxDistance ; for ( int i = 0 ; i < numOfComp ; i ++ ) { maxDistance = maxInThisComponent ( components [ i ] , graph ) ; result . push_back ( maxDistance ) ; } return result ; } int main ( ) { int N = 8 ; const int inf = INT_MAX ; vector < vector < int > > graph1 = { { 0 , inf , 9 , inf , inf , inf , 3 , inf } , { inf , 0 , inf , 10 , 1 , 8 , inf , inf } , { 9 , inf , 0 , inf , inf , inf , 11 , inf } , { inf , 10 , inf , 0 , 5 , 13 , inf , inf } , { inf , 1 , inf , 5 , 0 , 3 , inf , inf } , { 8 , inf , inf , 13 , 3 , 0 , inf , inf } , { 3 , inf , 11 , inf , inf , inf , 0 , inf } , { inf , inf , inf , inf , inf , inf , inf , 0 } , } ; vector < int > result1 = maximumShortesDistances ( graph1 , N ) ; for ( int mx1 : result1 ) cout << mx1 << ' ▁ ' ; return 0 ; }

Index/key variables: dest, i, j, k, src
Accumulator variables: dest, i, j, k, stdc
Iterator variables: dest, i, j, k, mx1
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxScoreSum ( vector < vector < int > > & a , vector < vector < int > > & b ) { int maxSum = 0 ; vector < int > pos ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { pos . push_back ( i ) ; } do { int curSum = 0 ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { for ( int j = 0 ; j < a [ pos [ i ] ] . size ( ) ; j ++ ) { curSum += ( a [ pos [ i ] ] [ j ] == b [ i ] [ j ] ) ; maxSum = max ( maxSum , curSum ) ; } } } while ( next_permutation ( pos . begin ( ) , pos . end ( ) ) ) ; cout << maxSum ; } int main ( ) { int N = 3 , M = 3 ; vector < vector < int > > a = { { 1 , 1 , 0 } , { 1 , 0 , 1 } , { 0 , 0 , 1 } } ; vector < vector < int > > b = { { 1 , 0 , 0 } , { 0 , 0 , 1 } , { 1 , 1 , 0 } } ; maxScoreSum ( a , b ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: curSum, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxScoreSum ( vector < vector < int > > & a , vector < vector < int > > & b , int row , int mask , vector < int > & dp ) { if ( row >= a . size ( ) ) { return 0 ; } if ( dp [ mask ] != -1 ) { return dp [ mask ] ; } int ans = 0 ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { if ( mask & ( 1 << i ) ) { int newMask = mask ^ ( 1 << i ) ; int curSum = 0 ; for ( int j = 0 ; j < a [ i ] . size ( ) ; j ++ ) { if ( a [ row ] [ j ] == b [ i ] [ j ] ) { curSum ++ ; } } ans = max ( ans , curSum + maxScoreSum ( a , b , row + 1 , newMask , dp ) ) ; } } return dp [ mask ] = ans ; } int maxScoreSumUtil ( vector < vector < int > > & a , vector < vector < int > > & b , int N , int M ) { int row = 0 ; int mask = pow ( 2 , M ) - 1 ; vector < int > dp ( mask + 1 , -1 ) ; return maxScoreSum ( a , b , row , mask , dp ) ; } int main ( ) { int N = 3 , M = 3 ; vector < vector < int > > a = { { 1 , 1 , 0 } , { 1 , 0 , 1 } , { 0 , 0 , 1 } } ; vector < vector < int > > b = { { 1 , 0 , 0 } , { 0 , 0 , 1 } , { 1 , 1 , 0 } } ; cout << maxScoreSumUtil ( a , b , N , M ) ; return 0 ; }

Index/key variables: i, j, mask, row
Accumulator variables: curSum, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDiffSum ( int arr [ ] , int n ) { int dp [ n ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int maxVal = arr [ i ] , minVal = arr [ i ] ; for ( int j = i ; j >= 0 ; j -- ) { minVal = min ( minVal , arr [ j ] ) ; maxVal = max ( maxVal , arr [ j ] ) ; if ( j - 1 >= 0 ) dp [ i ] = max ( dp [ i ] , maxVal - minVal + dp [ j - 1 ] ) ; else dp [ i ] = max ( dp [ i ] , maxVal - minVal ) ; } } return dp [ n - 1 ] ; } int main ( ) { int arr [ ] = { 8 , 1 , 7 , 9 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxDiffSum ( arr , N ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MOD = 1000000007 ; long modPow ( long x , long y ) { long r = 1 , a = x ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) { r = ( r * a ) % MOD ; } a = ( a * a ) % MOD ; y /= 2 ; } return r ; } long modInverse ( long x ) { return modPow ( x , MOD - 2 ) ; } long modDivision ( long p , long q ) { return ( p * modInverse ( q ) ) % MOD ; } long C ( long n , int k ) { if ( k > n ) { return 0 ; } long p = 1 , q = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { q = ( q * i ) % MOD ; p = ( p * ( n - i + 1 ) ) % MOD ; } return modDivision ( p , q ) ; } int countArrays ( int N , int K ) { long res = 1 ; for ( int p = 2 ; p <= K / p ; p ++ ) { int c = 0 ; while ( K % p == 0 ) { K /= p ; c ++ ; } res = ( res * C ( N - 1 + c , c ) ) % MOD ; } if ( N > 1 ) { res = ( res * N ) % MOD ; } return res ; } int main ( ) { int N = 3 , K = 5 ; cout << countArrays ( N , K ) ; return 0 ; }

Accumulator variables: K, c, i, p, stdc, y
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSessions ( vector < int > & codeTime , vector < vector < int > > & dp , int ones , int n , int mask , int currTime , int WorkingSessionTime ) { if ( currTime > WorkingSessionTime ) return INT_MAX ; if ( mask == ones ) return 1 ; if ( dp [ mask ] [ currTime ] != -1 ) return dp [ mask ] [ currTime ] ; int ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( mask & ( 1 << i ) ) == 0 ) { int inc = minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , currTime + codeTime [ i ] , WorkingSessionTime ) ; int inc_next = 1 + minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , codeTime [ i ] , WorkingSessionTime ) ; ans = min ( { ans , inc , inc_next } ) ; } } return dp [ mask ] [ currTime ] = ans ; } int solve ( vector < int > codeTime , int n , int WorkingSessionTime ) { vector < vector < int > > dp ( ( 1 << 14 ) , vector < int > ( 15 , -1 ) ) ; int ones = ( 1 << n ) - 1 ; int ans = minSessions ( codeTime , dp , ones , n , 0 , 0 , WorkingSessionTime ) ; if ( WorkingSessionTime < 6 ) { if ( ans % 2 == 0 ) ans = ans / 2 ; else ans = ( ans / 2 ) + 1 ; } return ans ; } int main ( ) { vector < int > codeTime = { 1 , 2 , 3 , 1 , 1 , 3 } ; int n = codeTime . size ( ) ; int WorkingSessionTime = 4 ; cout << solve ( codeTime , n , WorkingSessionTime ) << endl ; return 0 ; }

Index/key variables: currTime, i, mask
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAXN  100005
int dp [ MAXN ] [ 10 ] ; int solve ( int len , int gap ) { if ( dp [ len ] [ gap ] != -1 ) { return dp [ len ] [ gap ] ; } if ( len == 0 gap == 0 ) { return 1 ; } if ( gap < 0 ) { return 0 ; } int ans = 0 ; for ( int i = 0 ; i <= gap ; i ++ ) { ans += solve ( len - 1 , gap - i ) ; } return dp [ len ] [ gap ] = ans ; } int countValidStrings ( string S ) { memset ( dp , -1 , sizeof ( dp ) ) ; int N = S . length ( ) ; int L = 1 , R = 9 ; int cnt = 0 ; int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ? ' ) { R = S [ i ] - '0' ; ans *= solve ( cnt , R - L ) ; L = R ; R = 9 ; cnt = 0 ; } else { cnt ++ ; } } ans *= solve ( cnt , R - L ) ; return ans ; } int main ( ) { string S = "1 ? ? ?2" ; cout << countValidStrings ( S ) ; return 0 ; }

Index/key variables: MAXN, gap, i, len
Accumulator variables: ans, cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string KthString ( int A , int B , long long K , vector < vector < int > > & dp ) { if ( A == 0 ) { return string ( B , '1' ) ; } if ( B == 0 ) { return string ( A , '0' ) ; } if ( K <= dp [ A - 1 ] [ B ] ) { return "0" + KthString ( A - 1 , B , K , dp ) ; } else { return "1" + KthString ( A , B - 1 , K - dp [ A - 1 ] [ B ] , dp ) ; } } int KthStringUtil ( int A , int B , int K ) { vector < vector < int > > dp ( A + 1 , vector < int > ( B + 1 ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i <= A ; ++ i ) { for ( int j = 0 ; j <= B ; ++ j ) { if ( i > 0 ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ; } if ( j > 0 ) { dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } } } cout << KthString ( A , B , K , dp ) ; return 0 ; } int main ( ) { int A = 3 , B = 3 , K = 7 ; KthStringUtil ( A , B , K ) ; return 0 ; }

Index/key variables: B, i, j
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int combinationsPossible ( int N , int idx , int prev , int val , int K , vector < vector < vector < int > > > & dp ) { if ( val > K ) { return 0 ; } if ( dp [ val ] [ idx ] [ prev ] != -1 ) { return dp [ val ] [ idx ] [ prev ] ; } if ( idx == N - 1 ) { if ( val == K ) { return 1 ; } return 0 ; } int ans = 0 ; if ( prev == 1 ) { ans += combinationsPossible ( N , idx + 1 , 1 , val + 1 , K , dp ) ; ans += combinationsPossible ( N , idx + 1 , 0 , val , K , dp ) ; } else { ans += combinationsPossible ( N , idx + 1 , 1 , val , K , dp ) ; ans += combinationsPossible ( N , idx + 1 , 0 , val , K , dp ) ; } return dp [ val ] [ idx ] [ prev ] = ans ; } int main ( ) { int N = 5 ; int K = 3 ; vector < vector < vector < int > > > dp ( K + 1 , vector < vector < int > > ( N + 1 , vector < int > ( 2 , -1 ) ) ) ; cout << ( combinationsPossible ( N , 0 , 0 , 0 , K , dp ) + combinationsPossible ( N , 0 , 1 , 0 , K , dp ) ) ; }

Index/key variables: idx, prev, val
Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countOfWays ( int arr [ ] , int N ) { int pre [ N + 1 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { pre [ i + 1 ] = pre [ i ] + arr [ i ] ; } int dp [ N + 1 ] [ N + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 1 ] [ 0 ] ++ ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N ; j >= 1 ; j -- ) { dp [ j + 1 ] [ pre [ i + 1 ] % ( j + 1 ) ] += dp [ j ] [ pre [ i + 1 ] % j ] ; if ( i == N - 1 ) { ans += dp [ j ] [ pre [ i + 1 ] % j ] ; } } } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countOfWays ( 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 ; #define MAX  500
int lookup [ MAX ] [ MAX ] ; struct Query { int L , R ; } ; void preprocess ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) lookup [ i ] [ 0 ] = i ; for ( int j = 1 ; ( 1 << j ) <= n ; j ++ ) { for ( int i = 0 ; ( i + ( 1 << j ) - 1 ) < n ; i ++ ) { if ( arr [ lookup [ i ] [ j - 1 ] ] < arr [ lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ] ) lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ] ; else lookup [ i ] [ j ] = lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ; } } } int query ( int arr [ ] , int L , int R ) { int j = ( int ) log2 ( R - L + 1 ) ; if ( arr [ lookup [ L ] [ j ] ] <= arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ) return arr [ lookup [ L ] [ j ] ] ; else return arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ; } void Min_difference ( int arr [ ] , int n , Query q [ ] , int m ) { preprocess ( arr , n ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; cout << query ( arr , L , R - 1 ) << ' ' ; } } void minimumDifference ( int arr [ ] , Query q [ ] , int N , int m ) { int diff [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) diff [ i ] = abs ( arr [ i ] - arr [ i + 1 ] ) ; Min_difference ( diff , N - 1 , q , m ) ; } int main ( ) { int arr [ ] = { 2 , 6 , 1 , 8 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Query Q [ ] = { { 0 , 3 } , { 1 , 5 } , { 4 , 5 } } ; int M = sizeof ( Q ) / sizeof ( Q [ 0 ] ) ; minimumDifference ( arr , Q , N , M ) ; return 0 ; }

Index/key variables: L, MAX, N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; const long long MOD = 1e9 + 7 ; int numTilings ( int N ) { if ( N < 3 ) { return N ; } vector < vector < long long > > dp ( N + 1 , vector < long long > ( 3 , 0 ) ) ; dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ; dp [ 1 ] [ 1 ] = dp [ 1 ] [ 2 ] = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 2 ] [ 0 ] + dp [ i - 2 ] [ 1 ] + dp [ i - 2 ] [ 2 ] ) % MOD ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 2 ] ) % MOD ; dp [ i ] [ 2 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] ) % MOD ; } return dp [ N ] [ 0 ] ; } int main ( ) { int N = 3 ; cout << numTilings ( N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; map < int , int > dp ; int countStrings ( int N ) { if ( N == 1 ) return 0 ; if ( dp . find ( N ) != dp . end ( ) ) return dp [ N ] ; int ret = 0 ; for ( int div = 1 ; div <= sqrt ( N ) ; div ++ ) { if ( N % div == 0 ) { ret += ( 1 << div ) - countStrings ( div ) ; int div2 = N / div ; if ( div2 != div and div != 1 ) ret += ( 1 << div2 ) - countStrings ( div2 ) ; } } dp [ N ] = ret ; return ret ; } int main ( ) { int N = 6 ; cout << countStrings ( N ) << endl ; }

Index/key variables: N
Accumulator variables: div, ret, stdc
Iterator variables: div
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int mod = 1e9 + 7 ; void countOfNumbers ( int N ) { int ans = 1 ; for ( int index = 1 ; index <= N ; ++ index ) { int choices = 0 ; for ( int digit = 1 ; digit <= 9 ; ++ digit ) { if ( index % digit == 0 ) { ++ choices ; } } ans = ( ans * 1LL * choices ) % mod ; } cout << ans << endl ; } int main ( ) { int N = 5 ; countOfNumbers ( N ) ; return 0 ; }

Accumulator variables: stdc
Iterator variables: digit, index
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dfs ( int arr [ ] , int left , int K ) { int q = 0 ; if ( left == 0 ) { for ( int i = 1 ; i < K ; ++ i ) { if ( arr [ i ] > 0 ) { arr [ i ] -- ; q = max ( q , 1 + dfs ( arr , K - i , K ) ) ; arr [ i ] ++ ; } } } else { for ( int i = 1 ; i < K ; ++ i ) { if ( arr [ i ] > 0 ) { arr [ i ] -- ; int nleft = ( i <= left ? left - i : K + left - i ) ; q = max ( q , dfs ( arr , nleft , K ) ) ; arr [ i ] ++ ; } } } return q ; } int maxGroups ( int K , int arr [ ] , int n ) { int V [ K ] = { 0 } ; for ( int x = 0 ; x < n ; x ++ ) V [ arr [ x ] % K ] ++ ; int ans = V [ 0 ] + dfs ( V , 0 , K ) ; return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << maxGroups ( K , arr , n ) ; return 0 ; }

Index/key variables: K, i, x
Accumulator variables: stdc, x
Iterator variables: i, x