dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <iostream>
using namespace std ; #define n  3
#define MAX  30
int dp [ n ] [ n ] [ MAX ] ; bool v [ n ] [ n ] [ MAX ] ; int findCount ( int mat [ ] [ n ] , int i , int j , int m ) { if ( i == 0 && j == 0 ) { if ( m == mat [ 0 ] [ 0 ] ) return 1 ; else return 0 ; } if ( m < 0 ) return 0 ; if ( i < 0 j < 0 ) return 0 ; if ( v [ i ] [ j ] [ m ] ) return dp [ i ] [ j ] [ m ] ; v [ i ] [ j ] [ m ] = true ; dp [ i ] [ j ] [ m ] = findCount ( mat , i - 1 , j , m - mat [ i ] [ j ] ) + findCount ( mat , i , j - 1 , m - mat [ i ] [ j ] ) ; return dp [ i ] [ j ] [ m ] ; } int main ( ) { int mat [ n ] [ n ] = { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ; int m = 5 ; cout << findCount ( mat , n - 1 , n - 1 , m ) ; return 0 ; }

Index/key variables: MAX, i, j, m, n
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define mod  1000000007
#define RUNMAX  300
#define BALLMAX  50
#define WICKETMAX  10
int CountWays ( int r , int b , int l , int R , int B , int W , int dp [ RUNMAX ] [ BALLMAX ] [ WICKETMAX ] ) { if ( l > W ) return 0 ; if ( r > R ) return 0 ; if ( b == B && r == R ) return 1 ; if ( b == B ) return 0 ; if ( dp [ r ] [ b ] [ l ] != -1 ) return dp [ r ] [ b ] [ l ] ; int ans = 0 ; ans += CountWays ( r , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 1 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 2 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 3 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 4 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 6 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r , b + 1 , l + 1 , R , B , W , dp ) ; ans = ans % mod ; return dp [ r ] [ b ] [ l ] = ans ; } int main ( ) { int R = 40 , B = 10 , W = 4 ; int dp [ RUNMAX ] [ BALLMAX ] [ WICKETMAX ] ; memset ( dp , -1 , sizeof dp ) ; cout << CountWays ( 0 , 0 , 0 , R , B , W , dp ) ; return 0 ; }

Index/key variables: BALLMAX, RUNMAX, WICKETMAX, b, l, r
Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 10 ; int findMinimumDeletion ( int l , int r , int dp [ N ] [ N ] , string s ) { if ( l > r ) return 0 ; if ( l == r ) return 1 ; if ( dp [ l ] [ r ] != -1 ) return dp [ l ] [ r ] ; int res = 1 + findMinimumDeletion ( l + 1 , r , dp , s ) ; for ( int i = l + 1 ; i <= r ; ++ i ) { if ( s [ l ] == s [ i ] ) res = min ( res , findMinimumDeletion ( l + 1 , i - 1 , dp , s ) + findMinimumDeletion ( i , r , dp , s ) ) ; } return dp [ l ] [ r ] = res ; } int main ( ) { string s = " abcddcba " ; int n = s . length ( ) ; int dp [ N ] [ N ] ; memset ( dp , -1 , sizeof dp ) ; cout << findMinimumDeletion ( 0 , n - 1 , dp , s ) ; return 0 ; }

Index/key variables: N, i, l, r
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define mp  make_pair
#define ll  long long
using namespace std ; const int mod = 1000000007 ; const int MAX = 100005 ; int minimumProductSubsequence ( int * arr , int n , int k ) { multiset < pair < double , int > > s ; ll dp [ MAX ] ; double p [ MAX ] ; dp [ 0 ] = arr [ 0 ] ; p [ 0 ] = log ( arr [ 0 ] ) ; s . insert ( mp ( p [ 0 ] , dp [ 0 ] ) ) ; for ( int i = 1 ; i < k ; i ++ ) { double l = ( s . begin ( ) ) -> first ; ll min = ( s . begin ( ) ) -> second ; p [ i ] = log ( arr [ i ] ) + l ; dp [ i ] = ( arr [ i ] * min ) % mod ; s . insert ( mp ( p [ i ] , dp [ i ] ) ) ; } for ( int i = k ; i < n ; i ++ ) { double l = ( s . begin ( ) ) -> first ; ll min = ( s . begin ( ) ) -> second ; p [ i ] = log ( arr [ i ] ) + l ; dp [ i ] = ( arr [ i ] * min ) % mod ; multiset < pair < double , int > > :: iterator it ; it = s . find ( mp ( p [ i - k ] , dp [ i - k ] ) ) ; s . erase ( it ) ; s . insert ( mp ( p [ i ] , dp [ i ] ) ) ; } return dp [ n - 1 ] ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; cout << minimumProductSubsequence ( arr , n , k ) ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int C [ 1000 ] [ 1000 ] ; void binomialCoeff ( int n ) { int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } } int numberOfWays ( int x , int y , int z ) { binomialCoeff ( max ( x , max ( y , z ) ) ) ; int sum = 0 ; for ( int i = 1 ; i <= z ; i ++ ) { sum = ( sum + C [ z ] [ i ] ) ; } int sum1 = 0 ; for ( int i = 1 ; i <= y ; i ++ ) { for ( int j = i + 1 ; j <= x ; j ++ ) { sum1 = ( sum1 + ( C [ y ] [ i ] * C [ x ] [ j ] ) ) ; } } sum1 = ( sum * sum1 ) ; return sum1 ; } int main ( ) { int x = 3 ; int y = 2 ; int z = 1 ; cout << numberOfWays ( x , y , z ) ; return 0 ; }

Index/key variables: i, j, x, y, z
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCost ( string str , int arr [ ] , int n ) { long long costofC = 0 , costofO = 0 , costofD = 0 , costofE = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' c ' ) costofC += arr [ i ] ; else if ( str [ i ] == ' o ' ) costofO = min ( costofC , costofO + arr [ i ] ) ; else if ( str [ i ] == ' d ' ) costofD = min ( costofO , costofD + arr [ i ] ) ; else if ( str [ i ] == ' e ' ) costofE = min ( costofD , costofE + arr [ i ] ) ; } return costofE ; } int main ( ) { string str = " geekcodergeeks " ; int arr [ ] = { 1 , 2 , 1 , 3 , 4 , 2 , 6 , 4 , 6 , 2 , 3 , 3 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findCost ( str , arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: costofC, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSubsequence ( int arr [ ] , int n ) { int len = 1 ; int tmp ; int i , j , d ; int dp [ n ] [ 10 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; int cnt [ 10 ] ; int locMax ; tmp = arr [ 0 ] ; while ( tmp > 0 ) { dp [ 0 ] [ tmp % 10 ] = 1 ; tmp /= 10 ; } for ( i = 1 ; i < n ; i ++ ) { tmp = arr [ i ] ; locMax = 1 ; memset ( cnt , 0 , sizeof ( cnt ) ) ; while ( tmp > 0 ) { cnt [ tmp % 10 ] = 1 ; tmp /= 10 ; } for ( d = 0 ; d <= 9 ; d ++ ) { if ( cnt [ d ] ) { dp [ i ] [ d ] = 1 ; for ( j = 0 ; j < i ; j ++ ) { dp [ i ] [ d ] = max ( dp [ i ] [ d ] , dp [ j ] [ d ] + 1 ) ; locMax = max ( dp [ i ] [ d ] , locMax ) ; } } } for ( d = 0 ; d <= 9 ; d ++ ) { if ( cnt [ d ] ) { dp [ i ] [ d ] = locMax ; } } len = max ( len , locMax ) ; } return len ; } int main ( ) { int arr [ ] = { 1 , 12 , 44 , 29 , 33 , 96 , 89 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findSubsequence ( arr , n ) ; return 0 ; }

Index/key variables: d, i, j, n
Accumulator variables: d, i, j, stdc, tmp
Iterator variables: d, i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int M = 18 ; int a , b , dp [ M ] [ 90 ] [ 90 ] [ 2 ] ; int prime [ ] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 } ; int count ( int pos , int even , int odd , int tight , vector < int > num ) { if ( pos == num . size ( ) ) { if ( num . size ( ) & 1 ) swap ( odd , even ) ; int d = even - odd ; for ( int i = 0 ; i < 24 ; i ++ ) if ( d == prime [ i ] ) return 1 ; return 0 ; } if ( dp [ pos ] [ even ] [ odd ] [ tight ] != -1 ) return dp [ pos ] [ even ] [ odd ] [ tight ] ; int ans = 0 ; int limit = ( tight ? 9 : num [ pos ] ) ; for ( int d = 0 ; d <= limit ; d ++ ) { int currF = tight , currEven = even ; int currOdd = odd ; if ( d < num [ pos ] ) currF = 1 ; if ( pos & 1 ) currOdd += d ; else currEven += d ; ans += count ( pos + 1 , currEven , currOdd , currF , num ) ; } return dp [ pos ] [ even ] [ odd ] [ tight ] = ans ; } int solve ( int x ) { vector < int > num ; while ( x ) { num . push_back ( x % 10 ) ; x /= 10 ; } reverse ( num . begin ( ) , num . end ( ) ) ; memset ( dp , -1 , sizeof ( dp ) ) ; return count ( 0 , 0 , 0 , 0 , num ) ; } int main ( ) { int L = 1 , R = 50 ; cout << solve ( R ) - solve ( L - 1 ) << endl ; L = 50 , R = 100 ; cout << solve ( R ) - solve ( L - 1 ) << endl ; return 0 ; }

Index/key variables: M, even, i, odd, pos, tight
Accumulator variables: ans, currEven, currOdd, d, i, stdc, x
Iterator variables: d, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  5005
int n , k ; vector < int > gr [ N ] ; int d [ N ] [ 505 ] ; int ans = 0 ; void Add_edge ( int x , int y ) { gr [ x ] . push_back ( y ) ; gr [ y ] . push_back ( x ) ; } void dfs ( int v , int par ) { d [ v ] [ 0 ] = 1 ; for ( auto i : gr [ v ] ) { if ( i != par ) { dfs ( i , v ) ; for ( int j = 1 ; j <= k ; j ++ ) ans += d [ i ] [ j - 1 ] * d [ v ] [ k - j ] ; for ( int j = 1 ; j <= k ; j ++ ) d [ v ] [ j ] += d [ i ] [ j - 1 ] ; } } } int main ( ) { n = 5 , k = 2 ; Add_edge ( 1 , 2 ) ; Add_edge ( 2 , 3 ) ; Add_edge ( 3 , 4 ) ; Add_edge ( 2 , 5 ) ; dfs ( 1 , 0 ) ; cout << ans ; return 0 ; }

Index/key variables: N, i, j, v, x, y
Accumulator variables: ans, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <vector>
using namespace std ; int findXorSum ( int arr [ ] , int n ) { int sum = 0 ; int mul = 1 ; for ( int i = 0 ; i < 30 ; i ++ ) { int c_odd = 0 ; bool odd = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & ( 1 << i ) ) > 0 ) odd = ( ! odd ) ; if ( odd ) c_odd ++ ; } for ( int j = 0 ; j < n ; j ++ ) { sum += ( mul * c_odd ) ; if ( ( arr [ j ] & ( 1 << i ) ) > 0 ) c_odd = ( n - j - c_odd ) ; } mul *= 2 ; } return sum ; } int main ( ) { int arr [ ] = { 3 , 8 , 13 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findXorSum ( arr , n ) ; return 0 ; }

Index/key variables: j
Accumulator variables: c_odd, i, j, mul, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int charVal ( string s , int i ) { if ( s [ i ] == '0' ) return 0 ; else if ( s [ i ] == '1' ) return 1 ; else return 2 ; } int countMinimalReplacements ( string s , int i , int prev , int dp [ ] [ 3 ] , int n ) { if ( i == n ) { return 0 ; } if ( dp [ i ] [ prev ] != -1 ) return dp [ i ] [ prev ] ; int val = charVal ( s , i ) ; int ans = INT_MAX ; if ( val == prev ) { int val = 0 ; for ( int cur = 0 ; cur <= 2 ; cur ++ ) { if ( cur == prev ) continue ; val = 1 + countMinimalReplacements ( s , i + 1 , cur , dp , n ) ; ans = min ( ans , val ) ; } } ans = countMinimalReplacements ( s , i + 1 , val , dp , n ) ; return dp [ i ] [ val ] = ans ; } int main ( ) { string s = "201220211" ; int n = s . length ( ) ; int dp [ n ] [ 3 ] ; memset ( dp , -1 , sizeof dp ) ; int val = charVal ( s , 0 ) ; cout << countMinimalReplacements ( s , 1 , val , dp , n ) ; return 0 ; }

Index/key variables: i, n, prev, val
Accumulator variables: cur, stdc
Iterator variables: cur
C++ program:
#include <iostream>
using namespace std ; #define MAX  50
bool hasPath ( int maze [ ] [ MAX ] , int sol [ ] [ MAX ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) sol [ i ] [ j ] = 0 ; bool * * CRF = new bool * [ N ] ; for ( int i = 0 ; i < N ; i ++ ) CRF [ i ] = new bool [ N ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) CRF [ i ] [ j ] = false ; CRF [ N - 1 ] [ N - 1 ] = true ; for ( int k = N - 1 ; k >= 0 ; k -- ) { for ( int j = k ; j >= 0 ; j -- ) { if ( ! ( k == N - 1 && j == N - 1 ) ) { for ( int a = 0 ; a <= maze [ k ] [ j ] ; a ++ ) { if ( ( j + a < N && CRF [ k ] [ j + a ] == true ) || ( k + a < N && CRF [ k + a ] [ j ] == true ) ) { CRF [ k ] [ j ] = true ; break ; } } for ( int a = 0 ; a <= maze [ j ] [ k ] ; a ++ ) { if ( ( k + a < N && CRF [ j ] [ k + a ] == true ) || ( j + a < N && CRF [ j + a ] [ k ] == true ) ) { CRF [ j ] [ k ] = true ; break ; } } } } } if ( CRF [ 0 ] [ 0 ] == false ) return false ; int i = 0 , j = 0 ; while ( ! ( i == N - 1 && j == N - 1 ) ) { sol [ i ] [ j ] = 1 ; if ( maze [ i ] [ j ] > 0 ) for ( int a = 1 ; a <= maze [ i ] [ j ] ; a ++ ) { if ( ( j + a < N && CRF [ i ] [ j + a ] == true ) ) { j = j + a ; break ; } else if ( ( i + a < N && CRF [ i + a ] [ j ] == true ) ) { i = i + a ; break ; } } } sol [ N - 1 ] [ N - 1 ] = 1 ; return true ; } void printMatrix ( int sol [ ] [ MAX ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) cout << sol [ i ] [ j ] << " ▁ " ; cout << " STRNEWLINE " ; } } int main ( ) { int maze [ ] [ MAX ] = { { 2 , 2 , 1 , 1 , 0 } , { 0 , 0 , 3 , 0 , 0 } , { 1 , 0 , 0 , 0 , 0 } , { 0 , 0 , 2 , 0 , 1 } , { 0 , 0 , 3 , 0 , 0 } } ; int N = sizeof ( maze ) / sizeof ( maze [ 0 ] ) ; int sol [ N ] [ MAX ] ; if ( hasPath ( maze , sol , N ) ) printMatrix ( sol , N ) ; else cout << " No ▁ path ▁ exists " ; return 0 ; }

Index/key variables: MAX, N, i, j, k
Accumulator variables: a, i, j, k
Iterator variables: a, i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkCombinations ( int a [ ] , int n ) { int pow_set_size = pow ( 2 , n ) ; int counter , j ; for ( counter = 0 ; counter < pow_set_size ; counter ++ ) { int sum = 0 ; for ( j = 0 ; j < n ; j ++ ) { if ( counter & ( 1 << j ) ) else } if ( sum % ( 24 * 60 ) == 0 ) return true ; } return false ; } int main ( ) { int a [ ] = { 60 , 60 , 120 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; if ( checkCombinations ( a , n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }

Accumulator variables: counter, j, stdc
Iterator variables: counter, j
C++ program:
#include <bits/stdc++.h>
#define n  4
#define m  4
using namespace std ; float calcProbability ( int M [ ] [ m ] , int k ) { float dp [ m ] [ n ] , sum [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { dp [ 0 ] [ j ] = M [ 0 ] [ j ] ; sum [ 0 ] += dp [ 0 ] [ j ] ; } for ( int i = 1 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] / sum [ i - 1 ] + M [ i ] [ j ] ; sum [ i ] += dp [ i ] [ j ] ; } } return dp [ n - 1 ] [ k - 1 ] / sum [ n - 1 ] ; } int main ( ) { int M [ m ] [ n ] = { { 1 , 1 , 0 , 3 } , { 2 , 3 , 2 , 3 } , { 9 , 3 , 0 , 2 } , { 2 , 3 , 2 , 2 } } ; int k = 3 ; cout << calcProbability ( M , k ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaximumNumbers ( string s ) { int n = s . length ( ) ; vector < int > remIndex ( 3 , -1 ) ; remIndex [ 0 ] = 0 ; vector < int > res ( n + 1 ) ; int r = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { r = ( r + s [ i - 1 ] - '0' ) % 3 ; res [ i ] = res [ i - 1 ] ; if ( remIndex [ r ] != -1 ) res [ i ] = max ( res [ i ] , res [ remIndex [ r ] ] + 1 ) ; remIndex [ r ] = i + 1 ; } return res [ n ] ; } int main ( ) { string s = "12345" ; cout << MaximumNumbers ( s ) ; return 0 ; }

Index/key variables: i, n, r
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define INF  99999
#define size  10
int findMinimumSteps ( int mat [ size ] [ size ] , int x , int y , int n ) { int dist [ n ] [ n ] , i , j , k ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 0 ) dist [ i ] [ j ] = INF ; else dist [ i ] [ j ] = 1 ; if ( i == j ) dist [ i ] [ j ] = 1 ; } } for ( k = 0 ; k < n ; k ++ ) { for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } if ( dist [ x ] [ y ] < INF ) return dist [ x ] [ y ] ; else return -1 ; } int main ( ) { int mat [ size ] [ size ] = { { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 } } ; int x = 2 , y = 3 ; cout << findMinimumSteps ( mat , x , y , size ) ; }

Index/key variables: i, j, k, n, size, x, y
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define max  4
#define c  2
int countPaths ( int sum , int get , int m , int n , int dp [ ] ) { if ( sum < 0 ) return 0 ; if ( sum == 0 ) return get ; if ( dp [ sum ] [ get ] != -1 ) return dp [ sum ] [ get ] ; int res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i == m ) res += countPaths ( sum - i , 1 , m , n , dp ) ; res += countPaths ( sum - i , get , m , n , dp ) ; } dp [ sum ] [ get ] = res ; return dp [ sum ] [ get ] ; } int main ( ) { int n = 3 , m = 2 , x = 3 ; int dp [ max + 1 ] ; for ( int i = 0 ; i <= max ; i ++ ) for ( int j = 0 ; j < 2 ; j ++ ) dp [ i ] [ j ] = -1 ; cout << countPaths ( x , 0 , m , n , dp ) ; }

Index/key variables: get, i, j, sum
Accumulator variables: i, j, res, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void addEdge ( vector < int > adj [ ] , int u , int v ) { adj [ u ] . push_back ( v ) ; adj [ v ] . push_back ( u ) ; } void printGraph ( vector < int > adj [ ] , int V ) { for ( int v = 0 ; v < V ; ++ v ) { cout << " Adjacency list of vertex " << v < < " head " for ( auto x : adj [ v ] ) cout << " - > ▁ " << x ; printf ( " STRNEWLINE " ) ; } } void findMinOperationUtil ( int dp [ ] [ 2 ] , vector < int > adj [ ] , int A [ ] , int src , int parent ) { dp [ src ] [ 0 ] = dp [ src ] [ 1 ] = 0 ; for ( auto V : adj [ src ] ) { if ( V == parent ) continue ; findMinOperationUtil ( dp , adj , A , V , src ) ; dp [ src ] [ 0 ] = max ( dp [ src ] [ 0 ] , dp [ V ] [ 0 ] ) ; dp [ src ] [ 1 ] = max ( dp [ src ] [ 1 ] , dp [ V ] [ 1 ] ) ; } A [ src - 1 ] += dp [ src ] [ 0 ] - dp [ src ] [ 1 ] ; if ( A [ src - 1 ] > 0 ) { dp [ src ] [ 1 ] += A [ src - 1 ] ; } else { dp [ src ] [ 0 ] += abs ( A [ src - 1 ] ) ; } } int findMinOperation ( vector < int > adj [ ] , int A [ ] , int V ) { int dp [ V + 1 ] [ 2 ] ; memset ( dp , 0 , sizeof dp ) ; findMinOperationUtil ( dp , adj , A , 1 , 0 ) ; int minOperations = dp [ 1 ] [ 0 ] + dp [ 1 ] [ 1 ] ; return minOperations ; } int main ( ) { int V = 5 ; vector < int > adj [ V + 1 ] ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 1 , 3 ) ; int A [ ] = { 1 , -1 , 1 } ; int minOperations = findMinOperation ( adj , A , V ) ; cout << minOperations ; return 0 ; }

Index/key variables: V, src, u, v
Accumulator variables: stdc
Iterator variables: V, v, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_K = 15 ; long long unsigned int fac [ MAX_K ] ; void factorial ( int k ) { fac [ 0 ] = 1 ; for ( int i = 1 ; i <= k + 1 ; i ++ ) { fac [ i ] = ( i * fac [ i - 1 ] ) ; } } long long unsigned int bin ( int a , int b ) { long long unsigned int ans = ( ( fac [ a ] ) / ( fac [ a - b ] * fac [ b ] ) ) ; return ans ; } long int sumofn ( int n , int k ) { int p = 0 ; long long unsigned int num1 , temp , arr [ 1000 ] ; for ( int j = 1 ; j <= k ; j ++ ) { if ( j == 1 ) { num1 = ( n * ( n + 1 ) ) / 2 ; arr [ p ++ ] = num1 ; temp = num1 ; } else { temp = ( pow ( n + 1 , j + 1 ) - 1 - n ) ; for ( int s = 1 ; s < j ; s ++ ) { temp = temp - ( arr [ j - s - 1 ] * bin ( j + 1 , s + 1 ) ) ; } temp = temp / ( j + 1 ) ; arr [ p ++ ] = temp ; } } temp = arr [ p - 1 ] ; return temp ; } int main ( ) { int n = 5 , k = 2 ; factorial ( k ) ; cout << sumofn ( n , k ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: MAX_K, a, b, i
Accumulator variables: i, j, p, s, stdc
Iterator variables: i, j, s
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define max  4
int countWays ( int index , int cnt , int dp [ ] [ max ] , int n , int m , int k ) { if ( index == n ) { if ( cnt == k ) return 1 ; else return 0 ; } if ( dp [ index ] [ cnt ] != -1 ) return dp [ index ] [ cnt ] ; int ans = 0 ; ans += countWays ( index + 1 , cnt , dp , n , m , k ) ; ans += ( m - 1 ) * countWays ( index + 1 , cnt + 1 , dp , n , m , k ) ; return dp [ index ] [ cnt ] = ans ; } int main ( ) { int n = 3 , m = 3 , k = 2 ; int dp [ n + 1 ] [ max ] ; memset ( dp , -1 , sizeof dp ) ; cout << m * countWays ( 1 , 0 , dp , n , m , k ) ; }

Index/key variables: cnt, index, max
Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef long long int lli ; const int MAX = 300 ; int checkFunc ( int i , int j , string st ) { if ( st [ i ] == ' ( ' && st [ j ] == ' ) ' ) return 1 ; if ( st [ i ] == ' ( ' && st [ j ] == ' ? ' ) return 1 ; if ( st [ i ] == ' ? ' && st [ j ] == ' ) ' ) return 1 ; if ( st [ i ] == ' [ ' && st [ j ] == ' ] ' ) return 1 ; if ( st [ i ] == ' [ ' && st [ j ] == ' ? ' ) return 1 ; if ( st [ i ] == ' ? ' && st [ j ] == ' ] ' ) return 1 ; if ( st [ i ] == ' { ' && st [ j ] == ' } ' ) return 1 ; if ( st [ i ] == ' { ' && st [ j ] == ' ? ' ) return 1 ; if ( st [ i ] == ' ? ' && st [ j ] == ' } ' ) return 1 ; return 0 ; } int countRec ( int start , int end , int dp [ ] [ MAX ] , string st ) { int sum = 0 ; if ( start > end ) return 1 ; if ( dp [ start ] [ end ] != -1 ) return dp [ start ] [ end ] ; lli i , r = 0 ; for ( i = start + 1 ; i <= end ; i += 2 ) { if ( checkFunc ( start , i , st ) ) { sum = sum + countRec ( start + 1 , i - 1 , dp , st ) * countRec ( i + 1 , end , dp , st ) ; } else if ( st [ start ] == ' ? ' && st [ i ] == ' ? ' ) { sum = sum + countRec ( start + 1 , i - 1 , dp , st ) * countRec ( i + 1 , end , dp , st ) * 3 ; } } return dp [ start ] [ end ] = sum ; } int countWays ( string st ) { int n = st . length ( ) ; if ( n % 2 == 1 ) return 0 ; int dp [ MAX ] [ MAX ] ; memset ( dp , -1 , sizeof ( dp ) ) ; return countRec ( 0 , n - 1 , dp , st ) ; } int main ( ) { string st = " ( ? ( [ ? ) ] ? } ? " ; cout << countWays ( st ) ; return 0 ; }

Index/key variables: MAX, end, i, j, start
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 64 ] [ 64 ] [ 64 ] [ 2 ] ; int func ( int third , int seta , int setb , int carry , int number ) { if ( dp [ third ] [ seta ] [ setb ] [ carry ] != -1 ) return dp [ third ] [ seta ] [ setb ] [ carry ] ; int shift = ( number >> third ) ; if ( shift == 0 and seta == 0 and setb == 0 and carry == 0 ) return 1 ; if ( shift == 0 or seta < 0 or setb < 0 ) return 0 ; int mask = shift & 1 ; dp [ third ] [ seta ] [ setb ] [ carry ] = 0 ; if ( ( mask ) && carry ) { dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta , setb , 0 , number ) + func ( third + 1 , seta - 1 , setb - 1 , 1 , number ) ; } else if ( mask && ! carry ) { dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta - 1 , setb , 0 , number ) + func ( third + 1 , seta , setb - 1 , 0 , number ) ; } else if ( ! mask && carry ) { dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta - 1 , setb , 1 , number ) + func ( third + 1 , seta , setb - 1 , 1 , number ) ; } else if ( ! mask && ! carry ) { dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta , setb , 0 , number ) + func ( third + 1 , seta - 1 , setb - 1 , 1 , number ) ; } return dp [ third ] [ seta ] [ setb ] [ carry ] ; } int possibleSwaps ( int a , int b , int c ) { memset ( dp , -1 , sizeof ( dp ) ) ; int ans = func ( 0 , a , b , 0 , c ) ; return ans ; } int main ( ) { int x = 2 , y = 2 , c = 20 ; cout << possibleSwaps ( x , y , c ) ; return 0 ; }

Index/key variables: carry, seta, setb, third
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateEvenSum ( int n ) { if ( n <= 0 ) return 0 ; int fibo [ 2 * n + 1 ] ; fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ; int sum = 0 ; for ( int i = 2 ; i <= 2 * n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; if ( i % 2 == 0 ) sum += fibo [ i ] ; } return sum ; } int main ( ) { int n = 8 ; cout << " Even ▁ indexed ▁ Fibonacci ▁ Sum ▁ upto ▁ " << n << " ▁ terms : ▁ " << calculateEvenSum ( n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i