dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool divisorGame ( int N , bool A , int dp [ ] [ 2 ] ) { if ( N == 1 or N == 3 ) return false ; if ( N == 2 ) return true ; if ( dp [ N ] [ A ] != -1 ) return dp [ N ] [ A ] ; int ans = ( A == 1 ) ? 0 : 1 ; for ( int i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { if ( A ) ans |= divisorGame ( N - i , 0 , dp ) ; else ans &= divisorGame ( N - i , 1 , dp ) ; } } return dp [ N ] [ A ] = ans ; } int main ( ) { int N = 3 ; int dp [ N + 1 ] [ 2 ] ; memset ( dp , -1 , sizeof ( dp ) ) ; if ( divisorGame ( N , 1 , dp ) == true ) cout << " Player ▁ A ▁ wins " ; else cout << " Player ▁ B ▁ wins " ; return 0 ; }

Index/key variables: A, N
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 100 ; int countMountains ( int a [ ] [ MAX ] , int n ) { int A [ n + 2 ] [ n + 2 ] ; int count = 0 ; for ( int i = 0 ; i < n + 2 ; i ++ ) { for ( int j = 0 ; j < n + 2 ; j ++ ) { if ( ( i == 0 ) || ( j == 0 ) || ( i == n + 1 ) || ( j == n + 1 ) ) { A [ i ] [ j ] = INT_MIN ; } else { A [ i ] [ j ] = a [ i - 1 ] [ j - 1 ] ; } } } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( ( A [ i ] [ j ] > A [ i - 1 ] [ j ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j ] ) && ( A [ i ] [ j ] > A [ i ] [ j - 1 ] ) && ( A [ i ] [ j ] > A [ i ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i - 1 ] [ j - 1 ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i - 1 ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j - 1 ] ) ) { count ++ ; } } } return count ; } int main ( ) { int a [ ] [ MAX ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int n = 3 ; cout << countMountains ( a , n ) ; return 0 ; }

Index/key variables: MAX, i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimalLength ( int a [ ] , int n ) { int dp [ n + 1 ] [ n + 1 ] , dp1 [ n ] ; int i , j , k ; memset ( dp , -1 , sizeof ( dp ) ) ; for ( int size = 1 ; size <= n ; size ++ ) { for ( i = 0 ; i < n - size + 1 ; i ++ ) { j = i + size - 1 ; if ( i == j ) dp [ i ] [ j ] = a [ i ] ; else { for ( k = i ; k < j ; k ++ ) { if ( dp [ i ] [ k ] != -1 && dp [ i ] [ k ] == dp [ k + 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i ] [ k ] + 1 ; } } } } for ( i = 0 ; i < n ; i ++ ) dp1 [ i ] = 1e7 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( dp [ j ] [ i ] != -1 ) { if ( j == 0 ) dp1 [ i ] = 1 ; else dp1 [ i ] = min ( dp1 [ i ] , dp1 [ j - 1 ] + 1 ) ; } } } return dp1 [ n - 1 ] ; } int main ( ) { int n = 7 ; int a [ n ] = { 3 , 3 , 4 , 4 , 4 , 3 , 3 } ; cout << minimalLength ( a , n ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, j, k, size, stdc
Iterator variables: i, j, k, size
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 100 ] [ 100 ] [ 100 ] ; int MaximumScoreDP ( int l , int r , int prefix_sum [ ] , int num ) { if ( l > r ) return 0 ; if ( dp [ l ] [ r ] [ num ] != -1 ) return dp [ l ] [ r ] [ num ] ; int current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= -1 ; dp [ l ] [ r ] [ num ] = current_sum + max ( MaximumScoreDP ( l + 1 , r , prefix_sum , num + 1 ) , MaximumScoreDP ( l , r - 1 , prefix_sum , num + 1 ) ) ; return dp [ l ] [ r ] [ num ] ; } int findMaxScore ( int a [ ] , int n ) { int prefix_sum [ n ] = { 0 } ; prefix_sum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + a [ i ] ; } memset ( dp , -1 , sizeof ( dp ) ) ; return MaximumScoreDP ( 0 , n - 1 , prefix_sum , 1 ) ; } int main ( ) { int n = 6 ; int A [ n ] = { 1 , 2 , 3 , 4 , 2 , 6 } ; cout << findMaxScore ( A , n ) ; return 0 ; }

Index/key variables: i, l, n, num, r
Accumulator variables: current_sum, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int memo [ 32 ] [ 2 ] [ 2 ] ; int dp ( int pos , int fl , int pr , string & bin ) { if ( pos == bin . length ( ) ) return 1 ; if ( memo [ pos ] [ fl ] [ pr ] != -1 ) return memo [ pos ] [ fl ] [ pr ] ; int val = 0 ; if ( bin [ pos ] == '0' ) val = val + dp ( pos + 1 , fl , 0 , bin ) ; else if ( bin [ pos ] == '1' ) val = val + dp ( pos + 1 , 1 , 0 , bin ) ; if ( pr == 0 ) { if ( fl == 1 ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } else if ( bin [ pos ] == '1' ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } } return memo [ pos ] [ fl ] [ pr ] = val ; } int findIntegers ( int num ) { string bin ; while ( num > 0 ) { if ( num % 2 ) bin += "1" ; else bin += "0" ; num /= 2 ; } reverse ( bin . begin ( ) , bin . end ( ) ) ; memset ( memo , -1 , sizeof ( memo ) ) ; return dp ( 0 , 0 , 0 , bin ) ; } int main ( ) { int N = 12 ; cout << findIntegers ( N ) ; return 0 ; }

Index/key variables: fl, pos, pr
Accumulator variables: bin, num, stdc, val
C++ program:
#include " bits / stdc + + . h "
using namespace std ; int TotalWays ( int n , int s , int k ) { int dp [ n ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ s - 1 ] = 1 ; for ( int i = s ; i < n ; i ++ ) { int idx = max ( s - 1 , i - k ) ; for ( int j = idx ; j < i ; j ++ ) { dp [ i ] += dp [ j ] ; } } return dp [ n - 1 ] ; } int main ( ) { int n = 5 ; int k = 2 ; int s = 2 ; cout << " Total ▁ Ways ▁ = ▁ " << TotalWays ( n , s , k ) ; }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max_sum ( int arr [ ] , int n , int k ) { int dp [ n ] ; dp [ 0 ] = maxi ( 0 , arr [ 0 ] ) ; int i = 1 ; while ( i < k ) { dp [ i ] = maxi ( dp [ i - 1 ] , arr [ i ] ) ; i ++ ; } i = k ; while ( i < n ) { dp [ i ] = maxi ( dp [ i - 1 ] , arr [ i ] + dp [ i - k ] ) ; i ++ ; } return dp [ n - 1 ] ; } int main ( ) { int arr [ ] = { 1 , 2 , -2 , 4 , 3 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 4 ; cout << max_sum ( arr , n , k ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const long MOD = 1000000007 ; long countStr ( long N ) { long dp [ N + 1 ] [ 3 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 1 ] [ 0 ] = 1 ; dp [ 1 ] [ 1 ] = 1 ; dp [ 1 ] [ 2 ] = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] + dp [ i - 1 ] [ 2 ] ) % MOD ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] % MOD ; dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] % MOD ; } long ans = ( dp [ N ] [ 0 ] + dp [ N ] [ 1 ] + dp [ N ] [ 2 ] ) % MOD ; return ans ; } int main ( ) { long N = 8 ; cout << countStr ( N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountOfOddSum ( int a [ ] [ 2 ] , int n ) { int dp [ n ] [ 2 ] , cnt [ n ] [ 2 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { if ( a [ i ] [ j ] % 2 == 0 ) { cnt [ i ] [ 0 ] ++ ; } else { cnt [ i ] [ 1 ] ++ ; } } } dp [ 0 ] [ 0 ] = cnt [ 0 ] [ 0 ] , dp [ 0 ] [ 1 ] = cnt [ 0 ] [ 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] * cnt [ i ] [ 0 ] + dp [ i - 1 ] [ 1 ] * cnt [ i ] [ 1 ] ) ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] * cnt [ i ] [ 1 ] + dp [ i - 1 ] [ 1 ] * cnt [ i ] [ 0 ] ) ; } return dp [ n - 1 ] [ 1 ] ; } int main ( ) { int a [ ] [ 2 ] = { { 1 , 2 } , { 3 , 6 } } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int ans = CountOfOddSum ( a , n ) ; cout << ans << " STRNEWLINE " ; 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 LongestConsSeq ( int arr [ ] , int N ) { int maxval = 1 ; for ( int i = 0 ; i < N ; i += 1 ) { maxval = max ( maxval , arr [ i ] ) ; } int dp [ maxval + 1 ] [ 2 ] = { 0 } ; int ans = 1 ; for ( int i = 0 ; i < N ; i += 1 ) { dp [ arr [ i ] ] [ 0 ] = ( 1 + dp [ arr [ i ] - 1 ] [ 0 ] ) ; if ( arr [ i ] >= 2 ) dp [ arr [ i ] ] [ 1 ] = max ( 1 + dp [ arr [ i ] - 1 ] [ 1 ] , 2 + dp [ arr [ i ] - 2 ] [ 0 ] ) ; else dp [ arr [ i ] ] [ 1 ] = 1 ; ans = max ( ans , dp [ arr [ i ] ] [ 1 ] ) ; } return ans ; } int main ( ) { int arr [ ] = { 2 , 1 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << LongestConsSeq ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isStepNum ( int n ) { int prevDigit = -1 ; while ( n ) { int curDigit = n % 10 ; if ( prevDigit == -1 ) prevDigit = curDigit ; else { if ( abs ( prevDigit - curDigit ) != 1 ) return false ; } prevDigit = curDigit ; n /= 10 ; } return true ; } void displaySteppingNumbers ( int n , int m ) { for ( int i = n ; i <= m ; i ++ ) if ( isStepNum ( i ) ) cout << i << " ▁ " ; } int main ( ) { int n = 0 , m = 21 ; displaySteppingNumbers ( n , m ) ; return 0 ; }

Accumulator variables: i, n, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define int  long long
using namespace std ; vector < int > v ; int dp [ 18 ] [ 180 ] [ 180 ] [ 2 ] ; int memo ( int index , int evenSum , int oddSum , int tight ) { if ( index == v . size ( ) ) { if ( evenSum > oddSum ) return 1 ; else return 0 ; } if ( dp [ index ] [ evenSum ] [ oddSum ] [ tight ] != -1 ) return dp [ index ] [ evenSum ] [ oddSum ] [ tight ] ; int limit = ( tight ) ? v [ index ] : 9 ; int ans = 0 ; for ( int d = 0 ; d <= limit ; d ++ ) { int currTight = 0 ; if ( d == v [ index ] ) currTight = tight ; if ( d % 2 != 0 ) ans += memo ( index + 1 , evenSum , oddSum + d , currTight ) ; else ans += memo ( index + 1 , evenSum + d , oddSum , currTight ) ; } dp [ index ] [ evenSum ] [ oddSum ] [ tight ] = ans ; return ans ; } int CountNum ( int n ) { v . clear ( ) ; while ( n ) { v . push_back ( n % 10 ) ; n = n / 10 ; } reverse ( v . begin ( ) , v . end ( ) ) ; memset ( dp , -1 , sizeof ( dp ) ) ; return memo ( 0 , 0 , 0 , 1 ) ; } int32_t main ( ) { int L , R ; L = 2 ; R = 10 ; cout << CountNum ( R ) - CountNum ( L - 1 ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: evenSum, index, oddSum, tight
Accumulator variables: ans, d, stdc
Iterator variables: d
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCount ( int K ) { int memo [ 100 ] ; for ( int i = 0 ; i < 100 ; i ++ ) { memo [ i ] = INT_MAX ; } memo [ 0 ] = 0 ; for ( int i = 1 ; i < 100 ; i ++ ) { memo [ i ] = min ( memo [ i - 1 ] + 1 , memo [ i ] ) ; } for ( int i = 10 ; i < 100 ; i ++ ) { memo [ i ] = min ( memo [ i - 10 ] + 1 , memo [ i ] ) ; } for ( int i = 25 ; i < 100 ; i ++ ) { memo [ i ] = min ( memo [ i - 25 ] + 1 , memo [ i ] ) ; } long min_count = 0 ; while ( K > 0 ) { min_count += memo [ K % 100 ] ; K /= 100 ; } return min_count ; } int main ( ) { int K = 69 ; cout << minCount ( K ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: K, i, min_count, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 10000 ; int count_required_sequence ( int n , int arr [ ] ) { int total_required_subsequence = 0 ; int total_n_required_subsequence = 0 ; int dp [ N ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { int turn_required = 0 ; for ( int j = -1 ; j <= 1 ; j ++ ) turn_required += dp [ arr [ i ] + j ] [ 0 ] ; int required_end_i = ( total_required_subsequence + turn_required ) ; int n_required_end_i = ( 1 + total_n_required_subsequence - turn_required ) ; total_required_subsequence += required_end_i ; total_n_required_subsequence += n_required_end_i ; dp [ arr [ i ] ] [ 1 ] += required_end_i ; dp [ arr [ i ] ] [ 0 ] += n_required_end_i ; } return total_required_subsequence ; } int main ( ) { int arr [ ] = { 1 , 6 , 2 , 1 , 9 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << count_required_sequence ( n , arr ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, j, stdc, total_n_required_subsequence, total_required_subsequence, turn_required
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; class Combination { private : int * Indices ; int N ; int R ; bool * Flags ; int Start ; int End ; public : Combination ( int * arr , int n , int r ) { this -> Indices = arr ; this -> N = n ; this -> R = r ; this -> Flags = nullptr ; } ~ Combination ( ) { if ( this -> Flags != nullptr ) { delete [ ] this -> Flags ; } } void GetFirst ( ) { this -> Flags = new bool [ N ] ; for ( int i = 0 ; i < this -> N ; ++ i ) { if ( i < this -> R ) { Flags [ i ] = true ; } else { Flags [ i ] = false ; } } this -> Start = 0 ; this -> End = this -> R - 1 ; this -> Output ( ) ; } bool HasNext ( ) { return End < ( this -> N - 1 ) ; } void Next ( ) { if ( this -> Start == this -> End ) { this -> Flags [ this -> End ] = false ; this -> Flags [ this -> End + 1 ] = true ; this -> Start += 1 ; this -> End += 1 ; while ( this -> End + 1 < this -> N && this -> Flags [ this -> End + 1 ] ) { ++ this -> End ; } } else { if ( this -> Start == 0 ) { Flags [ this -> End ] = false ; Flags [ this -> End + 1 ] = true ; this -> End -= 1 ; } else { Flags [ this -> End + 1 ] = true ; for ( int i = this -> Start ; i <= this -> End ; ++ i ) { Flags [ i ] = false ; } for ( int i = 0 ; i < this -> End - this -> Start ; ++ i ) { Flags [ i ] = true ; } this -> End = this -> End - this -> Start - 1 ; this -> Start = 0 ; } } this -> Output ( ) ; } private : void Output ( ) { for ( int i = 0 , count = 0 ; i < this -> N && count < this -> R ; ++ i ) { if ( Flags [ i ] ) { cout << Indices [ i ] << " ▁ " ; ++ count ; } } cout << endl ; } } ; int main ( ) { int arr [ ] = { 0 , 1 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int r = 3 ; Combination com ( arr , n , r ) ; com . GetFirst ( ) ; while ( com . HasNext ( ) ) { com . Next ( ) ; } return 0 ; }

Index/key variables: N, i
Accumulator variables: End, Start
Iterator variables: i
Class/struct names: Combination
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX_INDEX  51
#define MAX_SUM  2505
int dp [ MAX_INDEX ] [ MAX_SUM ] [ MAX_INDEX ] ; int waysutil ( int index , int sum , int count , vector < int > & arr , int K ) { if ( index < 0 ) return 0 ; if ( index == 0 ) { if ( count == 0 ) return 0 ; int remainder = sum % count ; if ( remainder != 0 ) return 0 ; int average = sum / count ; if ( average == K ) return 1 ; } if ( dp [ index ] [ sum ] [ count ] != -1 ) return dp [ index ] [ sum ] [ count ] ; int dontpick = waysutil ( index - 1 , sum , count , arr , K ) ; int pick = waysutil ( index - 1 , sum + arr [ index ] , count + 1 , arr , K ) ; int total = pick + dontpick ; dp [ index ] [ sum ] [ count ] = total ; return total ; } int ways ( int N , int K , int * arr ) { vector < int > Arr ; Arr . push_back ( -1 ) ; for ( int i = 0 ; i < N ; ++ i ) { Arr . push_back ( arr [ i ] ) ; } memset ( dp , -1 , sizeof dp ) ; int answer = waysutil ( N , 0 , 0 , Arr , K ) ; return answer ; } int main ( ) { int arr [ ] = { 3 , 6 , 2 , 8 , 7 , 6 , 5 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 5 ; cout << ways ( N , K , arr ) ; return 0 ; }

Index/key variables: MAX_INDEX, MAX_SUM, count, i, index, sum
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define arrSize  51
#define maxSum  201
#define MAX  100
#define inf  999999
int dp [ arrSize ] [ maxSum ] ; bool visit [ arrSize ] [ maxSum ] ; int RetClose ( int a , int b , int s ) { if ( abs ( a - s ) < abs ( b - s ) ) return a ; else return b ; } int MinDiff ( int i , int sum , int arr [ ] , int n ) { if ( i == n ) return 0 ; if ( visit [ i ] [ sum + MAX ] ) return dp [ i ] [ sum + MAX ] ; visit [ i ] [ sum + MAX ] = 1 ; dp [ i ] [ sum + MAX ] = RetClose ( arr [ i ] + MinDiff ( i + 1 , sum + arr [ i ] , arr , n ) , MinDiff ( i + 1 , sum , arr , n ) , -1 * sum ) ; return dp [ i ] [ sum + MAX ] ; } void FindClose ( int arr [ ] , int n ) { int ans = inf ; for ( int i = 1 ; i <= n ; i ++ ) ans = RetClose ( arr [ i - 1 ] + MinDiff ( i , arr [ i - 1 ] , arr , n ) , ans , 0 ) ; cout << ans << endl ; } int main ( ) { int arr [ ] = { 25 , -9 , -10 , -4 , -7 , -33 } ; int n = sizeof ( arr ) / sizeof ( int ) ; FindClose ( arr , n ) ; return 0 ; }

Index/key variables: arrSize, i, maxSum
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define COL  5
#define ROW  5
using namespace std ; int totalPaths ( int i , int j , int n , int grid [ ] [ COL ] , int dp [ ] [ COL ] ) { if ( i < 0 j < 0 i > = n j > = n ) return 0 ; if ( dp [ i ] [ j ] == -1 ) { if ( grid [ i ] [ j ] == 1 ) dp [ i ] [ j ] = totalPaths ( i , j + 1 , n , grid , dp ) ; else if ( grid [ i ] [ j ] == 2 ) dp [ i ] [ j ] = totalPaths ( i + 1 , j , n , grid , dp ) ; else dp [ i ] [ j ] = totalPaths ( i , j + 1 , n , grid , dp ) + totalPaths ( i + 1 , j , n , grid , dp ) ; } return dp [ i ] [ j ] ; } int maxSumPath ( int i , int j , int n , int grid [ ROW ] [ COL ] , int dp [ ROW ] [ COL ] ) { if ( i < 0 j < 0 i > = n j > = n ) return 0 ; if ( dp [ i ] [ j ] == -1 ) { if ( grid [ i ] [ j ] == 1 ) dp [ i ] [ j ] = grid [ i ] [ j ] + maxSumPath ( i , j + 1 , n , grid , dp ) ; else if ( grid [ i ] [ j ] == 2 ) dp [ i ] [ j ] = grid [ i ] [ j ] + maxSumPath ( i + 1 , j , n , grid , dp ) ; else dp [ i ] [ j ] = grid [ i ] [ j ] + max ( maxSumPath ( i , j + 1 , n , grid , dp ) , maxSumPath ( i + 1 , j , n , grid , dp ) ) ; } return dp [ i ] [ j ] ; } int main ( ) { int grid [ ROW ] [ COL ] = { { 1 , 1 , 3 , 2 , 1 } , { 3 , 2 , 2 , 1 , 2 } , { 1 , 3 , 3 , 1 , 3 } , { 1 , 2 , 3 , 1 , 2 } , { 1 , 1 , 1 , 3 , 1 } } ; int n = ROW ; int dp [ ROW ] [ COL ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) dp [ i ] [ j ] = -1 ; } dp [ n - 1 ] [ n - 1 ] = 1 ; cout << " Total ▁ paths : ▁ " << totalPaths ( 0 , 0 , n , grid , dp ) << endl ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) dp [ i ] [ j ] = -1 ; } dp [ n - 1 ] [ n - 1 ] = grid [ n - 1 ] [ n - 1 ] ; cout << " Maximum ▁ sum : ▁ " << maxSumPath ( 0 , 0 , n , grid , dp ) << endl ; return 0 ; }

Index/key variables: COL, ROW, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define MAX  100000
#define bitscount  32
using namespace std ; int prefix_count [ bitscount ] [ MAX ] ; void findPrefixCount ( int arr [ ] , int n ) { for ( int i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( int j = 1 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefix_count [ i ] [ j ] += prefix_count [ i ] [ j - 1 ] ; } } } int rangeOr ( int l , int r ) { int ans = 0 ; for ( int i = 0 ; i < bitscount ; i ++ ) { int x ; if ( l == 0 ) x = prefix_count [ i ] [ r ] ; else x = prefix_count [ i ] [ r ] - prefix_count [ i ] [ l - 1 ] ; if ( x != 0 ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } int main ( ) { int arr [ ] = { 7 , 5 , 3 , 5 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; findPrefixCount ( arr , n ) ; int queries [ ] [ 2 ] = { { 1 , 3 } , { 4 , 5 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) cout << rangeOr ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) << endl ; return 0 ; }

Index/key variables: MAX, bitscount, i, j, r
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int palindromeSubStrs ( string s ) { int dp [ s . size ( ) ] [ s . size ( ) ] ; int st , end , i , j , len ; map < string , bool > m ; for ( i = 0 ; i < s . size ( ) ; i ++ ) { dp [ i ] [ i ] = 1 ; m [ string ( s . begin ( ) + i , s . begin ( ) + i + 1 ) ] = 1 ; } for ( i = 0 ; i < s . size ( ) - 1 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { dp [ i ] [ i + 1 ] = 1 ; m [ string ( s . begin ( ) + i , s . begin ( ) + i + 2 ) ] = 1 ; } else { dp [ i ] [ i + 1 ] = 0 ; } } for ( len = 3 ; len <= s . size ( ) ; len ++ ) { for ( st = 0 ; st <= s . size ( ) - len ; st ++ ) { end = st + len - 1 ; if ( s [ st ] == s [ end ] && dp [ st + 1 ] [ end - 1 ] ) { dp [ st ] [ end ] = 1 ; m [ string ( s . begin ( ) + st , s . begin ( ) + end + 1 ) ] = 1 ; } else dp [ st ] [ end ] = 0 ; } } return m . size ( ) ; } int main ( ) { string s = " abaaa " ; cout << palindromeSubStrs ( s ) ; return 0 ; }

Index/key variables: end, i, st
Accumulator variables: i, len, st, stdc
Iterator variables: i, len, st
C++ program:
#include <bits/stdc++.h>
using namespace std ; int n = 4 , m = 4 ; int arr [ 4 ] [ 4 ] = { { 1 , 0 , 3 , -1 } , { 3 , 5 , 1 , -2 } , { -2 , 0 , 1 , 1 } , { 2 , 1 , -1 , 1 } } ; int cache [ 5 ] [ 5 ] [ 5 ] ; int sum ( int i1 , int j1 , int i2 , int j2 ) { if ( i1 == i2 && j1 == j2 ) { return arr [ i1 ] [ j1 ] ; } return arr [ i1 ] [ j1 ] + arr [ i2 ] [ j2 ] ; } int maxSumPath ( int i1 , int j1 , int i2 ) { int j2 = i1 + j1 - i2 ; if ( i1 >= n i2 >= n j1 >= m j2 >= m ) { return 0 ; } if ( cache [ i1 ] [ j1 ] [ i2 ] != -1 ) { return cache [ i1 ] [ j1 ] [ i2 ] ; } int ans = INT_MIN ; ans = max ( ans , maxSumPath ( i1 + 1 , j1 , i2 + 1 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = max ( ans , maxSumPath ( i1 , j1 + 1 , i2 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = max ( ans , maxSumPath ( i1 , j1 + 1 , i2 + 1 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = max ( ans , maxSumPath ( i1 + 1 , j1 , i2 ) + sum ( i1 , j1 , i2 , j2 ) ) ; cache [ i1 ] [ j1 ] [ i2 ] = ans ; return ans ; } int main ( ) { memset ( cache , -1 , sizeof ( cache ) ) ; cout << maxSumPath ( 0 , 0 , 0 ) ; return 0 ; }

Index/key variables: i1, i2, j1, j2
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void BellmanFord ( int graph [ ] [ 3 ] , int V , int E , int src ) { int dis [ V ] ; for ( int i = 0 ; i < V ; i ++ ) dis [ i ] = INT_MAX ; dis [ src ] = 0 ; for ( int i = 0 ; i < V - 1 ; i ++ ) { for ( int j = 0 ; j < E ; j ++ ) { if ( dis [ graph [ j ] [ 0 ] ] != INT_MAX && dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] < dis [ graph [ j ] [ 1 ] ] ) dis [ graph [ j ] [ 1 ] ] = dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] ; } } for ( int i = 0 ; i < E ; i ++ ) { int x = graph [ i ] [ 0 ] ; int y = graph [ i ] [ 1 ] ; int weight = graph [ i ] [ 2 ] ; if ( dis [ x ] != INT_MAX && dis [ x ] + weight < dis [ y ] ) cout << " Graph ▁ contains ▁ negative " " ▁ weight ▁ cycle " << endl ; } cout << " Vertex ▁ Distance ▁ from ▁ Source " << endl ; for ( int i = 0 ; i < V ; i ++ ) cout << i << " TABSYMBOL TABSYMBOL " << dis [ i ] << endl ; } int main ( ) { int graph [ ] [ 3 ] = { { 0 , 1 , -1 } , { 0 , 2 , 4 } , { 1 , 2 , 3 } , { 1 , 3 , 2 } , { 1 , 4 , 2 } , { 3 , 2 , 5 } , { 3 , 1 , 1 } , { 4 , 3 , -3 } } ; BellmanFord ( graph , V , E , 0 ) ; return 0 ; }

Index/key variables: V, i, j, src, x, y
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int m [ 1000 ] , x [ 22 ] ; int a [ 1000 ] [ 22 ] ; vector < vector < int > > g ; int ans = 0 ; void dfs ( int u , int p ) { for ( int i = 0 ; i < g [ u ] . size ( ) ; i ++ ) { int v = g [ u ] [ i ] ; if ( v != p ) { dfs ( v , u ) ; for ( int i = 0 ; i < 22 ; i ++ ) a [ u ] [ i ] += a [ v ] [ i ] ; } } int pp = 0 ; for ( int i = 0 ; i < 22 ; i ++ ) { if ( ! ( ( a [ u ] [ i ] > 0 && x [ i ] - a [ u ] [ i ] > 0 ) || ( a [ u ] [ i ] == 0 && x [ i ] == 0 ) ) ) { pp = 1 ; break ; } } if ( pp == 0 ) ans ++ ; } int main ( ) { int n = 4 ; g . resize ( n + 1 ) ; m [ 1 ] = 1 ; m [ 2 ] = 3 ; m [ 3 ] = 2 ; m [ 4 ] = 3 ; for ( int i = 1 ; i <= n ; i ++ ) { int y = m [ i ] ; int k = 0 ; while ( y != 0 ) { int p = y % 2 ; if ( p == 1 ) { x [ k ] ++ ; a [ i ] [ k ] ++ ; } y = y / 2 ; k ++ ; } } g [ 1 ] . push_back ( 2 ) ; g [ 2 ] . push_back ( 1 ) ; g [ 1 ] . push_back ( 3 ) ; g [ 3 ] . push_back ( 1 ) ; g [ 1 ] . push_back ( 4 ) ; g [ 4 ] . push_back ( 1 ) ; dfs ( 1 , 0 ) ; cout << ( ans ) ; }

Index/key variables: i, k, u, v
Accumulator variables: ans, i, k, stdc
Iterator variables: i