dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  1005
struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ( ) ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } int dp [ N ] [ 5 ] [ 5 ] ; int minDominatingSet ( Node * root , int covered , int compulsory ) { if ( ! root ) return 0 ; if ( ! root -> left and ! root -> right and ! covered ) compulsory = true ; if ( dp [ root -> data ] [ covered ] [ compulsory ] != -1 ) return dp [ root -> data ] [ covered ] [ compulsory ] ; if ( compulsory ) { return dp [ root -> data ] [ covered ] [ compulsory ] = 1 + minDominatingSet ( root -> left , 1 , 0 ) + minDominatingSet ( root -> right , 1 , 0 ) ; } if ( covered ) { return dp [ root -> data ] [ covered ] [ compulsory ] = min ( 1 + minDominatingSet ( root -> left , 1 , 0 ) + minDominatingSet ( root -> right , 1 , 0 ) , minDominatingSet ( root -> left , 0 , 0 ) + minDominatingSet ( root -> right , 0 , 0 ) ) ; } int ans = 1 + minDominatingSet ( root -> left , 1 , 0 ) + minDominatingSet ( root -> right , 1 , 0 ) ; if ( root -> left ) { ans = min ( ans , minDominatingSet ( root -> left , 0 , 1 ) + minDominatingSet ( root -> right , 0 , 0 ) ) ; } if ( root -> right ) { ans = min ( ans , minDominatingSet ( root -> left , 0 , 0 ) + minDominatingSet ( root -> right , 0 , 1 ) ) ; } return dp [ root -> data ] [ covered ] [ compulsory ] = ans ; } signed main ( ) { memset ( dp , -1 , sizeof ( dp ) ) ; Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 4 ) ; root -> left -> left -> left = newNode ( 5 ) ; root -> left -> left -> left -> left = newNode ( 6 ) ; root -> left -> left -> left -> right = newNode ( 7 ) ; root -> left -> left -> left -> right -> right = newNode ( 10 ) ; root -> left -> left -> left -> left -> left = newNode ( 8 ) ; root -> left -> left -> left -> left -> right = newNode ( 9 ) ; cout << minDominatingSet ( root , 0 , 0 ) << endl ; return 0 ; }

Index/key variables: N, compulsory, covered
Accumulator variables: stdc
Boolean variables: compulsory
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
#define maxSum  100
#define arrSize  51
using namespace std ; int dp [ arrSize ] [ maxSum ] ; bool visit [ arrSize ] [ maxSum ] ; int SubsetCnt ( int i , int s , int arr [ ] , int n ) { if ( i == n ) { if ( s == 0 ) return 1 ; else return 0 ; } if ( visit [ i ] [ s + maxSum ] ) return dp [ i ] [ s + maxSum ] ; visit [ i ] [ s + maxSum ] = 1 ; dp [ i ] [ s + maxSum ] = SubsetCnt ( i + 1 , s + arr [ i ] , arr , n ) + SubsetCnt ( i + 1 , s , arr , n ) ; return dp [ i ] [ s + maxSum ] ; } int main ( ) { int arr [ ] = { 2 , 2 , 2 , -4 , -4 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << SubsetCnt ( 0 , 0 , arr , n ) ; }

Index/key variables: arrSize, i, maxSum
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1000
int waysToKAdjacentSetBits ( int dp [ ] [ MAX ] [ 2 ] , int n , int k , int currentIndex , int adjacentSetBits , int lastBit ) { if ( currentIndex == n ) { if ( adjacentSetBits == k ) return 1 ; return 0 ; } if ( dp [ currentIndex ] [ adjacentSetBits ] [ lastBit ] != -1 ) { return dp [ currentIndex ] [ adjacentSetBits ] [ lastBit ] ; } int noOfWays = 0 ; if ( lastBit == 1 ) { noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits + 1 , 1 ) ; noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } else if ( ! lastBit ) { noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits , 1 ) ; noOfWays += waysToKAdjacentSetBits ( dp , n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } dp [ currentIndex ] [ adjacentSetBits ] [ lastBit ] = noOfWays ; return noOfWays ; } int main ( ) { int n = 5 , k = 2 ; int dp [ MAX ] [ MAX ] [ 2 ] ; memset ( dp , -1 , sizeof ( dp ) ) ; int totalWays = waysToKAdjacentSetBits ( dp , n , k , 1 , 0 , 1 ) + waysToKAdjacentSetBits ( dp , n , k , 1 , 0 , 0 ) ; cout << " Number ▁ of ▁ ways ▁ = ▁ " << totalWays << " STRNEWLINE " ; return 0 ; }

Index/key variables: MAX, adjacentSetBits, currentIndex, lastBit
Accumulator variables: noOfWays, stdc
C++ program:
#include <iostream>
using namespace std ; void printTetra ( int n ) { if ( n < 0 ) return ; int first = 0 , second = 1 ; int third = 1 , fourth = 2 ; int curr ; if ( n == 0 ) cout << first ; else if ( n == 1 n == 2 ) cout << second ; else if ( n == 3 ) cout << fourth ; else { for ( int i = 4 ; i <= n ; i ++ ) { curr = first + second + third + fourth ; first = second ; second = third ; third = fourth ; fourth = curr ; } cout << curr ; } } int main ( ) { int n = 10 ; printTetra ( n ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countWays ( int n ) { int res [ n + 1 ] ; res [ 0 ] = 1 ; res [ 1 ] = 1 ; res [ 2 ] = 2 ; for ( int i = 3 ; i <= n ; i ++ ) res [ i ] = res [ i - 1 ] + res [ i - 2 ] + res [ i - 3 ] ; return res [ n ] ; } int main ( ) { int n = 4 ; cout << countWays ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countWays ( int n ) { int a = 1 , b = 2 , c = 4 ; int d = 0 ; if ( n == 0 n == 1 n == 2 ) return n ; if ( n == 3 ) return c ; for ( int i = 4 ; i <= n ; i ++ ) { d = c + b + a ; a = b ; b = c ; c = d ; } return d ; } int main ( ) { int n = 4 ; cout << countWays ( n ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool isPossible ( int elements [ ] , int sum , int n ) { int dp [ sum + 1 ] ; dp [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = sum ; j >= elements [ i ] ; j -- ) { if ( dp [ j - elements [ i ] ] == 1 ) dp [ j ] = 1 ; } } if ( dp [ sum ] == 1 ) return true ; return false ; } int main ( ) { int elements [ ] = { 6 , 2 , 5 } ; int n = sizeof ( elements ) / sizeof ( elements [ 0 ] ) ; int sum = 7 ; if ( isPossible ( elements , sum , n ) ) cout << ( " YES " ) ; else cout << ( " NO " ) ; return 0 ; }

Index/key variables: i, j, sum
Accumulator variables: i, j
Iterator variables: i, j
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 nCr ( int n , int r ) { if ( r > n ) return 0 ; if ( r > n - r ) r = n - r ; int mod = 1000000007 ; int arr [ r ] ; for ( int i = n - r + 1 ; i <= n ; i ++ ) { arr [ i + r - n - 1 ] = i ; } long int ans = 1 ; for ( int k = 1 ; k < r + 1 ; k ++ ) { int j = 0 , i = k ; while ( j < r ) { int x = gcd ( i , arr [ j ] ) ; if ( x > 1 ) { arr [ j ] /= x ; i /= x ; } if ( i == 1 ) break ; j += 1 ; } } for ( int i : arr ) ans = ( ans * i ) % mod ; return ( int ) ans ; } int main ( ) { int n = 5 , r = 2 ; cout << " Value ▁ of ▁ C ( " << n << " , ▁ " << r << " ) ▁ is ▁ " << nCr ( n , r ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: j, r
Accumulator variables: i, j, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; char FindKthChar ( string str , long long K , int X ) { char ans ; int sum = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int digit = str [ i ] - '0' ; int range = pow ( digit , X ) ; sum += range ; if ( K <= sum ) { ans = str [ i ] ; break ; } } return ans ; } int main ( ) { string str = "123" ; long long K = 9 ; int X = 3 ; char ans = FindKthChar ( str , K , X ) ; cout << ans << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int totalPairs ( string s1 , string s2 ) { int count = 0 ; int arr1 [ 7 ] , arr2 [ 7 ] ; for ( int i = 1 ; i <= 6 ; i ++ ) { arr1 [ i ] = 0 ; arr2 [ i ] = 0 ; } for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { int set_bits = __builtin_popcount ( ( int ) s1 [ i ] ) ; arr1 [ set_bits ] ++ ; } for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) { int set_bits = __builtin_popcount ( ( int ) s2 [ i ] ) ; arr2 [ set_bits ] ++ ; } for ( int i = 1 ; i <= 6 ; i ++ ) count += ( arr1 [ i ] * arr2 [ i ] ) ; return count ; } int main ( ) { string s1 = " geeks " ; string s2 = " forgeeks " ; cout << totalPairs ( s1 , s2 ) ; return 0 ; }

Index/key variables: i, set_bits
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubstr ( string str , int n , char x , char y ) { int tot_count = 0 ; int count_x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == x ) count_x ++ ; if ( str [ i ] == y ) tot_count += count_x ; } return tot_count ; } int main ( ) { string str = " abbcaceghcak " ; int n = str . size ( ) ; char x = ' a ' , y = ' c ' ; cout << " Count ▁ = ▁ " << countSubstr ( str , n , x , y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count_x, i, stdc, tot_count
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define OUT  0
#define IN  1
unsigned countWords ( char * str ) { int state = OUT ; unsigned wc = 0 ; while ( * str ) { if ( * str == ' ▁ ' * str == ' ' * str == ' TABSYMBOL ' ) state = OUT ; else if ( state == OUT ) { state = IN ; ++ wc ; } ++ str ; } return wc ; } int main ( void ) { char str [ ] = " One ▁ two TABSYMBOL three STRNEWLINE ▁ four TABSYMBOL five ▁ " ; cout << " No ▁ of ▁ words ▁ : ▁ " << countWords ( str ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nthEnneadecagonal ( long int n ) { return ( 17 * n * n - 15 * n ) / 2 ; } int main ( ) { long int n = 6 ; cout << n << " th ▁ Enneadecagonal ▁ number ▁ : " << nthEnneadecagonal ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int itemType ( int n ) { int count = 0 ; int day = 1 ; while ( count + day * ( day + 1 ) / 2 < n ) { count += day * ( day + 1 ) / 2 ; day ++ ; } for ( int type = day ; type > 0 ; type -- ) { count += type ; if ( count >= n ) { return type ; } } } int main ( ) { int N = 10 ; cout << itemType ( N ) ; return 0 ; }

Accumulator variables: count, day, stdc, type
Iterator variables: type
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * next ; } ; bool isSortedDesc ( struct Node * head ) { if ( head == NULL ) return true ; for ( Node * t = head ; t -> next != NULL ; t = t -> next ) if ( t -> data <= t -> next -> data ) return false ; return true ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> next = NULL ; temp -> data = data ; } int main ( ) { struct Node * head = newNode ( 7 ) ; head -> next = newNode ( 5 ) ; head -> next -> next = newNode ( 4 ) ; head -> next -> next -> next = newNode ( 3 ) ; isSortedDesc ( head ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxLength ( string str , int n , char c , int k ) { int ans = -1 ; int cnt = 0 ; int left = 0 ; for ( int right = 0 ; right < n ; right ++ ) { if ( str [ right ] == c ) { cnt ++ ; } while ( cnt > k ) { if ( str [ left ] == c ) { cnt -- ; } left ++ ; } ans = max ( ans , right - left + 1 ) ; } return ans ; } int maxConsecutiveSegment ( string S , int K ) { int N = S . length ( ) ; return max ( maxLength ( S , N , '0' , K ) , maxLength ( S , N , '1' , K ) ) ; } int main ( ) { string S = "1001" ; int K = 1 ; cout << maxConsecutiveSegment ( S , K ) ; return 0 ; }

Index/key variables: left, right
Accumulator variables: cnt, left, right, stdc
Iterator variables: right
C++ program:
#include <bits/stdc++.h>
using namespace std ; void find ( int N ) { int T , F , O ; F = int ( ( N - 4 ) / 5 ) ; if ( ( ( N - 5 * F ) % 2 ) == 0 ) { O = 2 ; } else { O = 1 ; } T = floor ( ( N - 5 * F - O ) / 2 ) ; cout << " Count ▁ of ▁ 5 ▁ valueds ▁ coins : ▁ " << F << endl ; cout << " Count ▁ of ▁ 2 ▁ valueds ▁ coins : ▁ " << T << endl ; cout << " Count ▁ of ▁ 1 ▁ valueds ▁ coins : ▁ " << O << endl ; } int main ( ) { int N = 8 ; find ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMaxOccurence ( string str , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ? ' ) { str [ i ] = '0' ; } } cout << str << endl ; } int main ( ) { string str = "10?0?11" ; int N = str . length ( ) ; findMaxOccurence ( str , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void checkInfinite ( string s ) { bool flag = 1 ; int N = s . length ( ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( s [ i ] == char ( int ( s [ i + 1 ] ) + 1 ) ) { continue ; } else if ( s [ i ] == ' a ' && s [ i + 1 ] == ' z ' ) { continue ; } else { flag = 0 ; break ; } } if ( flag == 0 ) cout << " NO " ; else cout << " YES " ; } int main ( ) { string s = " ecbaz " ; checkInfinite ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minChangeInLane ( int barrier [ ] , int n ) { int dp [ ] = { 1 , 0 , 1 } ; for ( int j = 0 ; j < n ; j ++ ) { int val = barrier [ j ] ; if ( val > 0 ) { dp [ val - 1 ] = 1e6 ; } for ( int i = 0 ; i < 3 ; i ++ ) { if ( val != i + 1 ) { dp [ i ] = min ( dp [ i ] , min ( dp [ ( i + 1 ) % 3 ] , dp [ ( i + 2 ) % 3 ] ) + 1 ) ; } } } return min ( dp [ 0 ] , min ( dp [ 1 ] , dp [ 2 ] ) ) ; } int main ( ) { int barrier [ ] = { 0 , 1 , 2 , 3 , 0 } ; int N = sizeof ( barrier ) / sizeof ( barrier [ 0 ] ) ; cout << minChangeInLane ( barrier , N ) ; 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 ; void numWays ( int ratings [ n ] [ k ] , int queries [ ] [ 2 ] ) { int dp [ n ] [ 10000 + 2 ] ; for ( int i = 0 ; i < k ; i ++ ) dp [ 0 ] [ ratings [ 0 ] [ i ] ] += 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int sum = 0 ; sum <= 10000 ; sum ++ ) { for ( int j = 0 ; j < k ; j ++ ) { if ( sum >= ratings [ i ] [ j ] ) dp [ i ] [ sum ] += dp [ i - 1 ] [ sum - ratings [ i ] [ j ] ] ; } } } for ( int sum = 1 ; sum <= 10000 ; sum ++ ) { dp [ n - 1 ] [ sum ] += dp [ n - 1 ] [ sum - 1 ] ; } for ( int q = 0 ; q < 2 ; q ++ ) { int a = queries [ q ] [ 0 ] ; int b = queries [ q ] [ 1 ] ; cout << dp [ n - 1 ] [ b ] - dp [ n - 1 ] [ a - 1 ] << " ▁ " ; } } int main ( ) { #define n  2
#define k  3
int ratings [ n ] [ k ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } } ; int queries [ ] [ 2 ] = { { 6 , 6 } , { 1 , 6 } } ; numWays ( ratings , queries ) ; return 0 ; }

Index/key variables: b, i, j, k, n, q, sum
Accumulator variables: i, j, q, stdc, sum
Iterator variables: i, j, q, sum
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfPermWithKInversion ( int N , int K ) { int dp [ 2 ] [ K + 1 ] ; int mod = 1000000007 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= K ; j ++ ) { if ( i == 1 ) dp [ i % 2 ] [ j ] = ( j == 0 ) ; else if ( j == 0 ) dp [ i % 2 ] [ j ] = 1 ; else dp [ i % 2 ] [ j ] = ( dp [ i % 2 ] [ j - 1 ] % mod + ( dp [ 1 - i % 2 ] [ j ] - ( ( max ( j - ( i - 1 ) , 0 ) == 0 ) ? 0 : dp [ 1 - i % 2 ] [ max ( j - ( i - 1 ) , 0 ) - 1 ] ) + mod ) % mod ) % mod ; ; } } cout << dp [ N % 2 ] [ K ] ; } int main ( ) { int N = 3 , K = 2 ; numberOfPermWithKInversion ( N , K ) ; return 0 ; }

Index/key variables: K, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  100
int n , m ; int a [ N ] [ N ] ; vector < vector < int > > dp ( N , vector < int > ( N ) ) , visited ( N , vector < int > ( N ) ) ; int current_sum = 0 ; int total_sum = 0 ; void inputMatrix ( ) { n = 3 ; m = 3 ; a [ 0 ] [ 0 ] = 500 ; a [ 0 ] [ 1 ] = 100 ; a [ 0 ] [ 2 ] = 230 ; a [ 1 ] [ 0 ] = 1000 ; a [ 1 ] [ 1 ] = 300 ; a [ 1 ] [ 2 ] = 100 ; a [ 2 ] [ 0 ] = 200 ; a [ 2 ] [ 1 ] = 1000 ; a [ 2 ] [ 2 ] = 200 ; } int maximum_sum_path ( int i , int j ) { if ( i == n - 1 && j == m - 1 ) return a [ i ] [ j ] ; if ( visited [ i ] [ j ] ) return dp [ i ] [ j ] ; visited [ i ] [ j ] = 1 ; int & total_sum = dp [ i ] [ j ] ; if ( i < n - 1 & j < m - 1 ) { int current_sum = max ( maximum_sum_path ( i , j + 1 ) , max ( maximum_sum_path ( i + 1 , j + 1 ) , maximum_sum_path ( i + 1 , j ) ) ) ; total_sum = a [ i ] [ j ] + current_sum ; } else if ( i == n - 1 ) total_sum = a [ i ] [ j ] + maximum_sum_path ( i , j + 1 ) ; else total_sum = a [ i ] [ j ] + maximum_sum_path ( i + 1 , j ) ; return dp [ i ] [ j ] = total_sum ; } int main ( ) { inputMatrix ( ) ; int maximum_sum = maximum_sum_path ( 0 , 0 ) ; cout << maximum_sum ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaxProfit ( int treasure [ ] , int color [ ] , int n , int k , int col , int A , int B ) { int sum = 0 ; if ( k == n ) return 0 ; if ( col == color [ k ] ) sum += max ( A * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) ) ; else sum += max ( B * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) ) ; return sum ; } int main ( ) { int A = -5 , B = 7 ; int treasure [ ] = { 4 , 8 , 2 , 9 } ; int color [ ] = { 2 , 2 , 6 , 2 } ; int n = sizeof ( color ) / sizeof ( color [ 0 ] ) ; cout << MaxProfit ( treasure , color , n , 0 , 0 , A , B ) ; return 0 ; }

Index/key variables: k
Accumulator variables: stdc, sum
C++ program:
#include <iostream>
using namespace std ; int sum = 0 ; void Combination ( int a [ ] , int combi [ ] , int n , int r , int depth , int index ) { if ( index == r ) { int product = 1 ; for ( int i = 0 ; i < r ; i ++ ) product = product * combi [ i ] ; sum += product ; return ; } for ( int i = depth ; i < n ; i ++ ) { combi [ index ] = a [ i ] ; Combination ( a , combi , n , r , i + 1 , index + 1 ) ; } } void allCombination ( int a [ ] , int n ) { for ( int i = 1 ; i <= n ; i ++ ) { int * combi = new int [ i ] ; Combination ( a , combi , n , i , 0 , 0 ) ; cout << " f ( " << i << " ) ▁ - - > ▁ " << sum << " STRNEWLINE " ; sum = 0 ; free ( combi ) ; } } int main ( ) { int n = 5 ; int * a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = i + 1 ; allCombination ( a , n ) ; return 0 ; }

Index/key variables: i, index, n
Accumulator variables: i, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int max ( int x , int y ) { return ( x > y ? x : y ) ; } int maxTasks ( int high [ ] , int low [ ] , int n ) { int task_dp [ n + 1 ] ; task_dp [ 0 ] = 0 ; task_dp [ 1 ] = high [ 0 ] ; for ( int i = 2 ; i <= n ; i ++ ) task_dp [ i ] = max ( high [ i - 1 ] + task_dp [ i - 2 ] , low [ i - 1 ] + task_dp [ i - 1 ] ) ; return task_dp [ n ] ; } int main ( ) { int n = 5 ; int high [ ] = { 3 , 6 , 8 , 7 , 6 } ; int low [ ] = { 1 , 5 , 4 , 5 , 3 } ; cout << maxTasks ( high , low , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int PermutationCoeff ( int n , int k ) { int P = 1 ; for ( int i = 0 ; i < k ; i ++ ) P *= ( n - i ) ; return P ; } int main ( ) { int n = 10 , k = 2 ; cout << " Value ▁ of ▁ P ( " << n << " , ▁ " << k << " ) ▁ is ▁ " << PermutationCoeff ( n , k ) ; return 0 ; }

Accumulator variables: P, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool findPartiion ( int arr [ ] , int n ) { int sum = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; bool part [ sum / 2 + 1 ] [ n + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) part [ 0 ] [ i ] = true ; for ( i = 1 ; i <= sum / 2 ; i ++ ) part [ i ] [ 0 ] = false ; for ( i = 1 ; i <= sum / 2 ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { part [ i ] [ j ] = part [ i ] [ j - 1 ] ; if ( i >= arr [ j - 1 ] ) part [ i ] [ j ] = part [ i ] [ j ] || part [ i - arr [ j - 1 ] ] [ j - 1 ] ; } } return part [ sum / 2 ] [ n ] ; } int main ( ) { int arr [ ] = { 3 , 1 , 1 , 2 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( findPartiion ( arr , n ) == true ) cout << " Can ▁ be ▁ divided ▁ into ▁ two ▁ subsets ▁ of ▁ equal ▁ " " sum " ; else cout << " Can ▁ not ▁ be ▁ divided ▁ into " << " ▁ two ▁ subsets ▁ of ▁ equal ▁ sum " ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int minimumOperations ( string orig_str , int m , int n ) { string orig = orig_str ; int turn = 1 ; int j = 1 ; for ( auto i : orig_str ) { string m_cut = orig_str . substr ( orig_str . length ( ) - m ) ; orig_str . erase ( orig_str . length ( ) - m ) ; orig_str = m_cut + orig_str ; j = j + 1 ; if ( orig != orig_str ) { turn = turn + 1 ; string n_cut = orig_str . substr ( orig_str . length ( ) - n ) ; orig_str . erase ( orig_str . length ( ) - n ) ; orig_str = n_cut + orig_str ; j = j + 1 ; } if ( orig == orig_str ) { break ; } turn = turn + 1 ; } cout << turn ; } int main ( ) { string S = " GeeksforGeeks " ; int X = 5 , Y = 3 ; minimumOperations ( S , X , Y ) ; return 0 ; }

Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void computeLPSArray ( char * pat , int M , int * lps ) ; int KMPSearch ( char * pat , char * txt ) { int M = strlen ( pat ) ; int N = strlen ( txt ) ; int lps [ M ] ; computeLPSArray ( pat , M , lps ) ; int i = 0 ; int j = 0 ; while ( i < N ) { if ( pat [ j ] == txt [ i ] ) { j ++ ; i ++ ; } if ( j == M ) { return i - j ; j = lps [ j - 1 ] ; } else if ( i < N && pat [ j ] != txt [ i ] ) { if ( j != 0 ) j = lps [ j - 1 ] ; else i = i + 1 ; } } } void computeLPSArray ( char * pat , int M , int * lps ) { int len = 0 ; lps [ 0 ] = 0 ; int i = 1 ; while ( i < M ) { if ( pat [ i ] == pat [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } } int countRotations ( string s ) { string s1 = s . substr ( 1 , s . size ( ) - 1 ) + s ; char pat [ s . length ( ) ] , text [ s1 . length ( ) ] ; strcpy ( pat , s . c_str ( ) ) ; strcpy ( text , s1 . c_str ( ) ) ; return 1 + KMPSearch ( pat , text ) ; } int main ( ) { string s1 = " geeks " ; cout << countRotations ( s1 ) ; return 0 ; }

Index/key variables: M, i, j, len
Accumulator variables: i, j, len, stdc
C++ program:
#include <iostream>
using namespace std ; int dfa = 0 ; void start ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; } void state1 ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; else if ( c == ' h ' c == ' H ' ) dfa = 2 ; else dfa = 0 ; } void state2 ( char c ) { if ( c == ' e ' c == ' E ' ) dfa = 3 ; else if ( c == ' t ' c == ' T ' ) dfa = 1 ; else dfa = 0 ; } void state3 ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; else dfa = 0 ; } bool isAccepted ( string str ) { int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( dfa == 0 ) start ( str [ i ] ) ; else if ( dfa == 1 ) state1 ( str [ i ] ) ; else if ( dfa == 2 ) state2 ( str [ i ] ) ; else state3 ( str [ i ] ) ; } return ( dfa != 3 ) ; } int main ( ) { string str = " forTHEgeeks " ; if ( isAccepted ( str ) == true ) cout << " ACCEPTED STRNEWLINE " ; else cout << " NOT ▁ ACCEPTED STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i