dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define V  3
#define M  2
void dfs ( int v , int p , vector < int > adj [ ] , int ans [ ] , int vals [ ] ) { bool isLeaf = 1 ; ans [ v ] = INT_MIN ; for ( int u : adj [ v ] ) { if ( u == p ) continue ; isLeaf = 0 ; dfs ( u , v , adj , ans , vals ) ; ans [ v ] = max ( ans [ u ] + vals [ v ] , max ( ans [ u ] , vals [ u ] ) ) ; } if ( isLeaf ) { ans [ v ] = vals [ v ] ; } } void printAnswer ( int n , int edges [ V ] [ M ] , int values [ ] ) { vector < int > adj [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = edges [ i ] [ 0 ] - 1 ; int v = edges [ i ] [ 1 ] - 1 ; adj [ u ] . push_back ( v ) ; adj [ v ] . push_back ( u ) ; } int ans [ n ] ; dfs ( 0 , -1 , adj , ans , values ) ; for ( auto x : ans ) { cout << x << " ▁ " ; } } int main ( ) { int N = 4 ; int edges [ V ] [ M ] = { { 1 , 2 } , { 1 , 3 } , { 3 , 4 } } ; int values [ ] = { 1 , -1 , 0 , 1 } ; printAnswer ( N , edges , values ) ; }

Index/key variables: M, V, i, n, u, v
Accumulator variables: i, stdc
Iterator variables: i, u, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void noOfChars ( string s , char queries [ ] [ 3 ] , int q ) { int n = s . length ( ) ; int dp [ n + 1 ] [ 26 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i + 1 ] [ s [ i ] - ' a ' ] ++ ; for ( int j = 0 ; j < 26 ; j ++ ) { dp [ i + 1 ] [ j ] += dp [ i ] [ j ] ; } } for ( int i = 0 ; i < q ; i ++ ) { int l = ( int ) queries [ i ] [ 0 ] ; int r = ( int ) queries [ i ] [ 1 ] ; int c = queries [ i ] [ 2 ] - ' a ' ; cout << dp [ r ] - dp [ l - 1 ] << " ▁ " ; } } int main ( ) { string S = " aabv " ; char queries [ 2 ] [ 3 ] = { { 1 , 2 , ' a ' } , { 2 , 3 , ' b ' } } ; noOfChars ( S , queries , 2 ) ; return 0 ; }

Index/key variables: i, j, r
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findLCS ( int * nums , int N ) { int k = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int pos = lower_bound ( nums , nums + k , nums [ i ] ) - nums ; nums [ pos ] = nums [ i ] ; if ( k == pos ) { k = pos + 1 ; } } return k ; } int minimumCost ( int * A , int * B , int M , int N , int C ) { int nums [ 1000000 ] ; int index [ 1000000 ] ; memset ( index , -1 , sizeof ( index ) ) ; for ( int i = 0 ; i < N ; i ++ ) { index [ B [ i ] ] = i ; } int k = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( index [ A [ i ] ] != -1 ) { nums [ k ++ ] = index [ A [ i ] ] ; } } int lcs_length = findLCS ( nums , k ) ; int elements_to_be_added = N - lcs_length ; int min_cost = elements_to_be_added * C ; cout << min_cost ; } int main ( ) { int A [ ] = { 1 , 6 , 3 , 5 , 10 } ; int B [ ] = { 3 , 1 , 5 } ; int C = 2 ; int M = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int N = sizeof ( B ) / sizeof ( B [ 0 ] ) ; minimumCost ( A , B , M , N , C ) ; return 0 ; }

Index/key variables: i, pos
Accumulator variables: i, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxCount ( vector < int > arr , int m , int V ) { vector < int > table ( V + 1 ) ; table [ 0 ] = 0 ; for ( int i = 1 ; i <= V ; i ++ ) table [ i ] = -1 ; for ( int i = 1 ; i <= V ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( arr [ j ] <= i ) { int sub_res = table [ i - arr [ j ] ] ; if ( sub_res != -1 && sub_res + 1 > table [ i ] ) table [ i ] = sub_res + 1 ; } } } return table [ V ] ; } int main ( ) { vector < int > arr = { 25 , 10 , 5 } ; int m = arr . size ( ) ; int V = 30 ; cout << ( maxCount ( arr , m , V ) ) ; return 0 ; }

Index/key variables: V, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SZ  100
void pathSum ( const int mat [ SZ ] [ SZ ] , int N , int M ) { int dp [ N ] [ M ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ; } for ( int j = 1 ; j < M ; j ++ ) { dp [ 0 ] [ j ] = mat [ 0 ] [ j ] + dp [ 0 ] [ j - 1 ] ; } for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) { dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { cout << dp [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { int mat [ SZ ] [ SZ ] = { { 3 , 2 , 1 } , { 6 , 5 , 4 } , { 7 , 8 , 9 } } ; int N = 3 ; int M = 3 ; pathSum ( mat , N , M ) ; }

Index/key variables: M, N, SZ, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestPalSubstr ( string str ) { int n = str . size ( ) ; bool table [ n ] [ n ] ; memset ( table , 0 , sizeof ( table ) ) ; int maxLength = 1 ; for ( int i = 0 ; i < n ; ++ i ) table [ i ] [ i ] = true ; int start = 0 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { if ( str [ i ] == str [ i + 1 ] ) { table [ i ] [ i + 1 ] = true ; start = i ; maxLength = 2 ; } } for ( int k = 3 ; k <= n ; ++ k ) { for ( int i = 0 ; i < n - k + 1 ; ++ i ) { int j = i + k - 1 ; if ( table [ i + 1 ] [ j - 1 ] && str [ i ] == str [ j ] ) { table [ i ] [ j ] = true ; if ( k > maxLength ) { start = i ; maxLength = k ; } } } } return maxLength ; } int main ( ) { string str = " forgeeksskeegfor " ; cout << longestPalSubstr ( str ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSumFlip ( int a [ ] , int n ) { int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) total_sum += a [ i ] ; int max_sum = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; int flip_sum = 0 ; for ( int j = i ; j < n ; j ++ ) { sum += a [ j ] ; max_sum = max ( max_sum , total_sum - 2 * sum ) ; } } return max ( max_sum , total_sum ) ; } int main ( ) { int arr [ ] = { -2 , 3 , -1 , -4 , -2 } ; int N = sizeof ( arr ) / sizeof ( int ) ; cout << maxSumFlip ( arr , N ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum, total_sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int INF = 1e7 ; const int max_size = 100007 ; int dp [ max_size ] ; int min_op ( int cur , int M ) { if ( cur > M ) return INF ; if ( cur == M ) return 0 ; if ( dp [ cur ] != -1 ) return dp [ cur ] ; int op = INF ; for ( int i = 2 ; i * i <= cur ; i ++ ) { if ( cur % i == 0 ) { if ( i % 2 == 0 ) { op = min ( op , 1 + min_op ( cur + i , M ) ) ; } if ( ( cur / i ) != i && ( cur / i ) % 2 == 0 ) { op = min ( op , 1 + min_op ( cur + ( cur / i ) , M ) ) ; } } } return dp [ cur ] = op ; } int min_operations ( int N , int M ) { for ( int i = N ; i <= M ; i ++ ) { dp [ i ] = -1 ; } return min_op ( N , M ) ; } int main ( ) { int N = 6 , M = 24 ; int op = min_operations ( N , M ) ; if ( op >= INF ) cout << " - 1" ; else cout << op << " STRNEWLINE " ; return 0 ; }

Index/key variables: cur, i, max_size
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int k = 1 ; const int m = 4 ; int maxValue ( int a [ ] , int n , int pos , int moves , int left , int dp [ ] [ k + 1 ] ) { if ( moves == 0 || ( pos > n - 1 pos < 0 ) ) return 0 ; if ( dp [ pos ] [ left ] != -1 ) return dp [ pos ] [ left ] ; int value = 0 ; if ( left > 0 && pos >= 1 ) value = max ( value , a [ pos ] + maxValue ( a , n , pos - 1 , moves - 1 , left - 1 , dp ) ) ; if ( pos <= n - 1 ) value = max ( value , a [ pos ] + maxValue ( a , n , pos + 1 , moves - 1 , left , dp ) ) ; return dp [ pos ] [ left ] = value ; } int main ( ) { int n = 5 ; int a [ ] = { 1 , 5 , 4 , 3 , 2 } ; int dp [ n + 1 ] [ k + 1 ] ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << ( a [ 0 ] + maxValue ( a , n , 1 , m , k , dp ) ) << endl ; }

Index/key variables: left, pos
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 6 ; int maximumSum ( int a [ ] , int count , int index , int n , int dp [ N ] [ N ] ) { if ( index == n ) return 0 ; if ( dp [ index ] [ count ] != -1 ) return dp [ index ] [ count ] ; int take_element = a [ index ] * count + maximumSum ( a , count + 1 , index + 1 , n , dp ) ; int dont_take = maximumSum ( a , count , index + 1 , n , dp ) ; return dp [ index ] [ count ] = max ( take_element , dont_take ) ; } int main ( ) { int n = 5 ; int a [ ] = { -1 , -9 , 0 , 5 , -7 } ; int dp [ N ] [ N ] ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << ( maximumSum ( a , 1 , 0 , n , dp ) ) ; }

Index/key variables: N, count, index
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 1e5 + 5 ; vector < vector < pair < int , int > > > v ( N ) ; vector < int > dp ( N ) ; vector < int > leaves ( N ) ; int n ; void dfs ( int a , int par ) { bool leaf = 1 ; for ( auto & i : v [ a ] ) { if ( i . first == par ) continue ; leaf = 0 ; dfs ( i . first , a ) ; } if ( leaf == 1 ) { leaves [ a ] += 1 ; } else { for ( auto & i : v [ a ] ) { if ( i . first == par ) continue ; leaves [ a ] += leaves [ i . first ] ; dp [ a ] = dp [ a ] + dp [ i . first ] + leaves [ i . first ] * i . second ; } } } void dfs2 ( int a , int par ) { for ( auto & i : v [ a ] ) { if ( i . first == par ) continue ; int leafOutside = leaves [ a ] - leaves [ i . first ] ; dp [ i . first ] += ( dp [ a ] - dp [ i . first ] ) ; dp [ i . first ] += i . second * ( leafOutside - leaves [ i . first ] ) ; leaves [ i . first ] += leafOutside ; dfs2 ( i . first , a ) ; } } void answerQueries ( vector < int > queries ) { dfs ( 1 , 0 ) ; dfs2 ( 1 , 0 ) ; for ( int i = 0 ; i < queries . size ( ) ; i ++ ) { cout << dp [ queries [ i ] ] << endl ; } } int main ( ) { n = 5 ; v [ 1 ] . push_back ( make_pair ( 4 , 4 ) ) ; v [ 4 ] . push_back ( make_pair ( 1 , 4 ) ) ; v [ 1 ] . push_back ( make_pair ( 2 , 2 ) ) ; v [ 2 ] . push_back ( make_pair ( 1 , 2 ) ) ; v [ 2 ] . push_back ( make_pair ( 3 , 3 ) ) ; v [ 3 ] . push_back ( make_pair ( 2 , 3 ) ) ; v [ 2 ] . push_back ( make_pair ( 5 , 5 ) ) ; v [ 5 ] . push_back ( make_pair ( 2 , 5 ) ) ; vector < int > queries = { 1 , 3 , 5 } ; answerQueries ( queries ) ; }

Index/key variables: a, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  7
int countChanges ( int matrix [ ] [ N ] , int n , int m ) { int dist = n + m - 1 ; int Max_element = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { Max_element = max ( Max_element , matrix [ i ] [ j ] ) ; } } int freq [ dist ] [ Max_element + 1 ] ; for ( int i = 0 ; i < dist ; i ++ ) { for ( int j = 0 ; j < Max_element + 1 ; j ++ ) freq [ i ] [ j ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { freq [ i + j ] [ matrix [ i ] [ j ] ] ++ ; } } int min_changes_sum = 0 ; for ( int i = 0 ; i < dist / 2 ; i ++ ) { int maximum = 0 ; int total_values = 0 ; for ( int j = 0 ; j < Max_element + 1 ; j ++ ) { maximum = max ( maximum , freq [ i ] [ j ] + freq [ n + m - 2 - i ] [ j ] ) ; total_values += freq [ i ] [ j ] + freq [ n + m - 2 - i ] [ j ] ; } min_changes_sum += total_values - maximum ; } return min_changes_sum ; } int main ( ) { int mat [ ] [ N ] = { { 7 , 0 , 3 , 1 , 8 , 1 , 3 } , { 0 , 4 , 0 , 1 , 0 , 4 , 0 } , { 3 , 1 , 8 , 3 , 1 , 0 , 7 } } ; int minChanges = countChanges ( mat , 3 , 7 ) ; cout << minChanges ; return 0 ; }

Index/key variables: N, dist, i, j
Accumulator variables: i, j, min_changes_sum, stdc, total_values
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long dp [ 1002 ] [ 10 ] [ 2 ] [ 2 ] ; long long possibleNumbers ( int pos , int previous , bool tight , bool start , string N , int K ) { if ( pos == N . length ( ) ) return 1 ; if ( dp [ pos ] [ previous ] [ tight ] [ start ] != -1 ) return dp [ pos ] [ previous ] [ tight ] [ start ] ; int res = 0 ; int upper_limit = ( tight ) ? ( N [ pos ] - '0' ) : 9 ; int new_tight ; if ( ! start ) { res = possibleNumbers ( pos + 1 , previous , false , false , N , K ) ; for ( int i = 1 ; i <= upper_limit ; i ++ ) { new_tight = ( tight && i == upper_limit ) ? 1 : 0 ; res += possibleNumbers ( pos + 1 , i , new_tight , true , N , K ) ; } } else { for ( int i = 0 ; i <= upper_limit ; i ++ ) { new_tight = ( tight && i == upper_limit ) ? 1 : 0 ; if ( abs ( i - previous ) <= K ) res += possibleNumbers ( pos + 1 , i , new_tight , true , N , K ) ; } } dp [ pos ] [ previous ] [ tight ] [ start ] = res ; return dp [ pos ] [ previous ] [ tight ] [ start ] ; } int main ( void ) { string N = "20" ; int K = 2 ; memset ( dp , -1 , sizeof dp ) ; cout << possibleNumbers ( 0 , 0 , true , false , N , K ) << endl ; }

Index/key variables: pos, previous, start, tight
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int mergeTwoNumbers ( vector < int > & numbers ) { int len , i , j , k ; int n = numbers . size ( ) ; if ( numbers . size ( ) == 0 ) { return 0 ; } vector < int > prefixSum ( n + 1 , 0 ) ; for ( int i = 1 ; i <= n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + numbers [ i - 1 ] ; } vector < vector < int > > dp ( n + 1 , vector < int > ( n + 1 ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { dp [ i ] [ i ] = 0 ; } for ( len = 2 ; len <= n ; len ++ ) { for ( i = 1 ; i <= n - len + 1 ; i ++ ) { j = i + len - 1 ; int sum = prefixSum [ j ] - prefixSum [ i - 1 ] ; dp [ i ] [ j ] = INT_MAX ; for ( k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] + sum ) ; } } } return dp [ 1 ] [ n ] ; } int main ( ) { vector < int > arr1 = { 6 , 4 , 4 , 6 } ; cout << mergeTwoNumbers ( arr1 ) << endl ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, k, len, stdc
Iterator variables: i, k, len
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp1 [ 100005 ] ; int dp2 [ 100005 ] ; void dfs1 ( int u , int par , vector < int > g [ ] , int weight [ ] ) { dp1 [ u ] = weight [ u ] ; for ( auto c : g [ u ] ) { if ( c != par ) { dfs1 ( c , u , g , weight ) ; dp1 [ u ] += max ( 0 , dp1 ) ; } } } void dfs2 ( int u , int par , vector < int > g [ ] , int weight [ ] ) { if ( par != 0 ) { int maxSumAncestors = dp2 [ par ] - max ( 0 , dp1 [ u ] ) ; dp2 [ u ] = dp1 [ u ] + max ( 0 , maxSumAncestors ) ; } for ( auto c : g [ u ] ) { if ( c != par ) { dfs2 ( c , u , g , weight ) ; } } } void addEdge ( int u , int v , vector < int > g [ ] ) { g [ u ] . push_back ( v ) ; g [ v ] . push_back ( u ) ; } void maxSumSegments ( vector < int > g [ ] , int weight [ ] , int n ) { dfs1 ( 1 , 0 , g , weight ) ; for ( int i = 1 ; i <= n ; i ++ ) { dp2 [ i ] = dp1 [ i ] ; } dfs2 ( 1 , 0 , g , weight ) ; } void printAns ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { cout << dp2 [ i ] << " ▁ " ; } } int main ( ) { int n = 6 ; int u , v ; vector < int > g [ 100005 ] ; addEdge ( 1 , 2 , g ) ; addEdge ( 1 , 3 , g ) ; addEdge ( 2 , 4 , g ) ; addEdge ( 2 , 5 , g ) ; addEdge ( 3 , 6 , g ) ; addEdge ( 4 , 7 , g ) ; int weight [ n + 1 ] ; weight [ 1 ] = -8 ; weight [ 2 ] = 9 ; weight [ 3 ] = 7 ; weight [ 4 ] = -4 ; weight [ 5 ] = 5 ; weight [ 6 ] = -10 ; weight [ 7 ] = -6 ; maxSumSegments ( g , weight , n ) ; printAns ( n ) ; return 0 ; }

Index/key variables: i, par, u, v
Accumulator variables: i, stdc
Iterator variables: c, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairs ( int arr [ ] , int N ) { int maxm = * max_element ( arr , arr + N ) ; int i , k ; int bitscount [ maxm + 1 ] = { 0 } ; for ( i = 1 ; i <= maxm ; i *= 2 ) bitscount [ i ] = 1 ; for ( i = 1 ; i <= maxm ; i ++ ) { if ( bitscount [ i ] == 1 ) k = i ; if ( bitscount [ i ] == 0 ) { bitscount [ i ] = bitscount [ k ] + bitscount [ i - k ] ; } } map < int , int > setbits ; for ( int i = 0 ; i < N ; i ++ ) { setbits [ bitscount [ arr [ i ] ] ] ++ ; } int ans = 0 ; for ( auto it : setbits ) { ans += it . second * ( it . second - 1 ) / 2 ; } return ans ; } int main ( ) { int N = 12 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } ; cout << countPairs ( arr , N ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: ans, i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; void depthFirst ( int v , vector < int > graph [ ] , vector < bool > & visited , vector < int > & storeChain ) { visited [ v ] = true ; storeChain . push_back ( v ) ; for ( auto i : graph [ v ] ) { if ( visited [ i ] == false ) { depthFirst ( i , graph , visited , storeChain ) ; } } } int subarraySum ( int arr [ ] , int n ) { int maxSubarraySum = arr [ 0 ] ; int currentMax = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { currentMax = max ( arr [ i ] , arr [ i ] + currentMax ) ; maxSubarraySum = max ( maxSubarraySum , currentMax ) ; } return maxSubarraySum ; } void maxSubarraySum ( vector < int > graph [ ] , int vertices , vector < int > values ) { vector < bool > visited ( 1001 , false ) ; int maxSum = INT_MIN ; for ( int i = 1 ; i <= vertices ; i ++ ) { if ( visited [ i ] == false ) { int sizeChain ; int tempSum ; vector < int > storeChain ; depthFirst ( i , graph , visited , storeChain ) ; sizeChain = storeChain . size ( ) ; int chainValues [ sizeChain + 1 ] ; for ( int i = 0 ; i < sizeChain ; i ++ ) { int temp = values [ storeChain [ i ] - 1 ] ; chainValues [ i ] = temp ; } tempSum = subarraySum ( chainValues , sizeChain ) ; if ( tempSum > maxSum ) { maxSum = tempSum ; } } } cout << " Maximum ▁ subarray ▁ sum ▁ among ▁ all ▁ " ; cout << " connected ▁ components ▁ = ▁ " ; cout << maxSum ; } int main ( ) { vector < int > graph [ 1001 ] ; int E , V ; E = 4 ; V = 7 ; vector < int > values ; values . push_back ( 3 ) ; values . push_back ( 2 ) ; values . push_back ( 4 ) ; values . push_back ( -2 ) ; values . push_back ( 0 ) ; values . push_back ( -1 ) ; values . push_back ( -5 ) ; graph [ 1 ] . push_back ( 2 ) ; graph [ 2 ] . push_back ( 1 ) ; graph [ 3 ] . push_back ( 4 ) ; graph [ 4 ] . push_back ( 3 ) ; graph [ 4 ] . push_back ( 5 ) ; graph [ 5 ] . push_back ( 4 ) ; graph [ 6 ] . push_back ( 7 ) ; graph [ 7 ] . push_back ( 6 ) ; maxSubarraySum ( graph , V , values ) ; return 0 ; }

Index/key variables: i, v
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 1000 ] [ 1000 ] ; int solve ( int n , int k , int m ) { if ( n == 0 && k == 0 ) return 1 ; if ( n == 0 && k != 0 ) return 0 ; if ( n != 0 && k == 0 ) return 0 ; if ( n < 0 k < 0 ) return 0 ; if ( dp [ n ] [ k ] ) return dp [ n ] [ k ] ; int ans = 0 ; for ( int j = 1 ; j <= m ; j ++ ) { ans += solve ( n - j , k - 1 , m ) ; } return dp [ n ] [ k ] = ans ; } int main ( ) { int N = 7 , K = 4 , M = 3 ; cout << solve ( N , K , M ) ; }

Index/key variables: k, n
Accumulator variables: ans, j, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printMatrix ( vector < vector < int > > A ) { for ( int i = 0 ; i < A . size ( ) ; i ++ ) { for ( int j = 0 ; j < A [ 0 ] . size ( ) ; j ++ ) cout << A [ i ] [ j ] << ' ▁ ' ; cout << ' ' ; } } vector < vector < int > > getMaxNeighbour ( vector < vector < int > > & A , int K ) { vector < vector < int > > ans = A ; for ( int q = 1 ; q <= K ; q ++ ) { for ( int i = 0 ; i < A . size ( ) ; i ++ ) { for ( int j = 0 ; j < A [ 0 ] . size ( ) ; j ++ ) { int maxi = ans [ i ] [ j ] ; if ( i > 0 ) maxi = max ( maxi , ans [ i - 1 ] [ j ] ) ; if ( j > 0 ) maxi = max ( maxi , ans [ i ] [ j - 1 ] ) ; if ( i < A . size ( ) - 1 ) maxi = max ( maxi , ans [ i + 1 ] [ j ] ) ; if ( j < A [ 0 ] . size ( ) - 1 ) maxi = max ( maxi , ans [ i ] [ j + 1 ] ) ; A [ i ] [ j ] = maxi ; } } ans = A ; } return ans ; } int main ( ) { vector < vector < int > > B = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; printMatrix ( getMaxNeighbour ( B , 2 ) ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, q, stdc
Iterator variables: i, j, q
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > prime ; bool isprime [ 1000 ] ; int dp [ 200 ] [ 20 ] [ 1000 ] ; void sieve ( ) { memset ( isprime , true , sizeof ( isprime ) ) ; for ( int i = 2 ; i * i <= 1000 ; i ++ ) { if ( isprime [ i ] ) { for ( int j = i * i ; j <= 1000 ; j += i ) { isprime [ j ] = false ; } } } for ( int i = 2 ; i <= 1000 ; i ++ ) { if ( isprime [ i ] ) { prime . push_back ( i ) ; } } } int CountWays ( int i , int j , int sum , int n , int k ) { if ( i > prime . size ( ) sum > n ) { return 0 ; } if ( sum == n ) { if ( j == k ) { return 1 ; } return 0 ; } if ( j == k ) return 0 ; if ( dp [ i ] [ j ] [ sum ] ) return dp [ i ] [ j ] [ sum ] ; int inc = 0 , exc = 0 ; inc = CountWays ( i + 1 , j + 1 , sum + prime [ i ] , n , k ) ; exc = CountWays ( i + 1 , j , sum , n , k ) ; return dp [ i ] [ j ] [ sum ] = inc + exc ; } int main ( ) { sieve ( ) ; int N = 100 , K = 5 ; cout << CountWays ( 0 , 0 , 0 , N , K ) ; }

Index/key variables: i, j, sum
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > factors [ 100005 ] ; int dp [ 100005 ] ; void precompute ( ) { for ( int i = 1 ; i <= 100000 ; i ++ ) { for ( int j = i ; j <= 100000 ; j += i ) factors [ j ] . push_back ( i ) ; } } int solve ( int arr [ ] , int n ) { for ( int i = 0 ; i <= 100005 ; i ++ ) { dp [ i ] = INT_MAX ; } dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( auto j : factors [ arr [ i ] ] ) { if ( i + j < n ) dp [ i + j ] = min ( dp [ i + j ] , 1 + dp [ i ] ) ; } } return dp [ n - 1 ] ; } int main ( ) { precompute ( ) ; int arr [ ] = { 2 , 8 , 16 , 55 , 99 , 100 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << solve ( arr , n ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 5000 ] [ ( 1 << 10 ) + 5 ] ; int getmask ( int val ) { int mask = 0 ; int prime [ 15 ] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 } ; for ( int i = 0 ; i < 15 ; i ++ ) { if ( val % prime [ i ] == 0 ) { mask = mask | ( 1 << i ) ; } } return mask ; } int calculate ( int pos , int mask , int a [ ] , int n ) { if ( pos == n || mask == ( 1 << n - 1 ) ) return 0 ; if ( dp [ pos ] [ mask ] != -1 ) return dp [ pos ] [ mask ] ; int size = 0 ; size = max ( size , calculate ( pos + 1 , mask , a , n ) ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { int new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; size = max ( size , 1 + calculate ( pos + 1 , new_mask , a , n ) ) ; } return dp [ pos ] [ mask ] = size ; } int largestSubset ( int a [ ] , int n ) { memset ( dp , -1 , sizeof ( dp ) ) ; return calculate ( 0 , 0 , a , n ) ; } int main ( ) { int A [ ] = { 2 , 3 , 13 , 5 , 14 , 6 , 7 , 11 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << largestSubset ( A , N ) ; return 0 ; }

Index/key variables: i, mask, pos
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaximumSum ( int a [ ] , int n ) { int dp [ n + 1 ] [ 2 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 2 ] [ 1 ] = a [ 1 ] ; dp [ 2 ] [ 0 ] = a [ 0 ] ; for ( int i = 3 ; i < n + 1 ; i ++ ) { if ( i & 1 ) { int temp = max ( { dp [ i - 3 ] [ 1 ] , dp [ i - 3 ] [ 0 ] , dp [ i - 2 ] [ 1 ] , dp [ i - 2 ] [ 0 ] } ) ; dp [ i ] [ 1 ] = a [ i - 1 ] + temp ; dp [ i ] [ 0 ] = max ( { a [ i - 2 ] + dp [ i - 2 ] [ 0 ] , a [ i - 2 ] + dp [ i - 3 ] [ 1 ] , a [ i - 2 ] + dp [ i - 3 ] [ 0 ] , a [ i - 3 ] + dp [ i - 3 ] [ 0 ] } ) ; } else { dp [ i ] [ 1 ] = a [ i - 1 ] + max ( { dp [ i - 2 ] [ 1 ] , dp [ i - 2 ] [ 0 ] , dp [ i - 1 ] [ 0 ] } ) ; dp [ i ] [ 0 ] = a [ i - 2 ] + dp [ i - 2 ] [ 0 ] ; } } return max ( dp [ n ] [ 1 ] , dp [ n ] [ 0 ] ) ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << MaximumSum ( A , N ) ; return 0 ; }

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