dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 3 ; int numberOfCells ( int mat [ ] [ N ] ) { bool row [ N ] [ N ] = { { false } } ; bool col [ N ] [ N ] = { { false } } ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j >= 0 ; j -- ) { if ( mat [ i ] [ j ] == 1 ) { row [ i ] [ j ] = ( j + 1 < N ) ? row [ i ] [ j + 1 ] : true ; } else { row [ i ] [ j ] = false ; } } } for ( int j = 0 ; j < N ; j ++ ) { for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( mat [ i ] [ j ] == 1 ) { col [ i ] [ j ] = ( i + 1 < N ) ? col [ i + 1 ] [ j ] : true ; } else { col [ i ] [ j ] = false ; } } } int cnt = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( row [ i ] [ j ] && col [ i ] [ j ] ) { cnt ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { if ( col [ i ] [ N - 1 ] ) cnt ++ ; } for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( row [ N - 1 ] [ j ] ) cnt ++ ; } return cnt ; } int main ( ) { int mat [ ] [ N ] = { { 0 , 1 , 1 } , { 0 , 1 , 1 } , { 0 , 1 , 1 } } ; cout << numberOfCells ( mat ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSumSubarray ( vector < int > arr , int size ) { int max_so_far = INT_MIN , max_ending_here = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + arr [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } void getUpdatedArray ( vector < int > & arr , vector < int > & copy , int i ) { for ( int j = 0 ; j <= ( i / 2 ) ; j ++ ) { copy [ j ] = arr [ i - j ] ; copy [ i - j ] = arr [ j ] ; } return ; } int maxSum ( vector < int > arr , int size ) { int resSum = INT_MIN ; resSum = max ( resSum , maxSumSubarray ( arr , size ) ) ; vector < int > copyArr = arr ; for ( int i = 1 ; i < size ; i ++ ) { getUpdatedArray ( arr , copyArr , i ) ; resSum = max ( resSum , maxSumSubarray ( copyArr , size ) ) ; } reverse ( arr . begin ( ) , arr . end ( ) ) ; copyArr = arr ; for ( int i = 1 ; i < size ; i ++ ) { getUpdatedArray ( arr , copyArr , i ) ; resSum = max ( resSum , maxSumSubarray ( copyArr , size ) ) ; } return resSum ; } int main ( ) { vector < int > arr { -9 , 21 , 24 , 24 , -51 , -6 , 17 , -42 , -39 , 33 } ; int size = arr . size ( ) ; cout << maxSum ( arr , size ) ; 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 ; int MaxGCD ( int a [ ] , int n ) { int Prefix [ n + 2 ] ; int Suffix [ n + 2 ] ; Prefix [ 1 ] = a [ 0 ] ; for ( int i = 2 ; i <= n ; i += 1 ) { Prefix [ i ] = __gcd ( Prefix [ i - 1 ] , a [ i - 1 ] ) ; } Suffix [ n ] = a [ n - 1 ] ; for ( int i = n - 1 ; i >= 1 ; i -= 1 ) { Suffix [ i ] = __gcd ( Suffix [ i + 1 ] , a [ i - 1 ] ) ; } int ans = max ( Suffix [ 2 ] , Prefix [ n - 1 ] ) ; for ( int i = 2 ; i < n ; i += 1 ) { ans = max ( ans , __gcd ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) ) ; } return ans ; } int main ( ) { int a [ ] = { 6 , 7 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << MaxGCD ( a , n ) ; return 0 ; }

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

Index/key variables: i, j
Accumulator variables: cur_sum, i, j, stdc, temp_sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define mod  (int)(1e9 + 7)
int subsequence ( int S [ ] , int T [ ] , int n , int m ) { int dp [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 1 ; for ( int j = 0 ; j <= m ; j ++ ) dp [ 0 ] [ j ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= m ; ++ j ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] ; if ( S [ i - 1 ] == T [ j - 1 ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] ; dp [ i ] [ j ] += mod ; dp [ i ] [ j ] %= mod ; } } return dp [ n ] [ m ] ; } int main ( ) { int S [ ] = { 1 , 1 } ; int n = sizeof ( S ) / sizeof ( S [ 0 ] ) ; int T [ ] = { 1 , 1 } ; int m = sizeof ( T ) / sizeof ( T [ 0 ] ) ; cout << subsequence ( S , T , n , m ) ; 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 findMax ( int arr [ ] , int n ) { int res = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) { int count = 0 ; for ( j = 0 ; j < i ; j ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) count += 1 ; } res = max ( count , res ) ; } return res ; } int main ( ) { int arr [ ] = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findMax ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMax ( int arr [ ] , int n ) { bool divisible [ n ] = { false } ; int res = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { if ( divisible [ i ] ) continue ; int cnt = 0 ; for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] % arr [ i ] ) == 0 ) { divisible [ j ] = true ; cnt ++ ; } } res = max ( res , cnt ) ; } return res ; } int main ( ) { int arr [ ] = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findMax ( arr , n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxM  10
int dp [ maxN ] [ maxM ] ; bool v [ maxN ] [ maxM ] ; int findCnt ( int * arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; return dp [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr + arr [ i ] ) % m , n , m ) ; } int main ( ) { int arr [ ] = { 3 , 3 , 3 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int m = 6 ; cout << findCnt ( arr , 0 , 0 , n , m ) - 1 ; return 0 ; }

Index/key variables: curr, i, maxM, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxM  64
int dp [ maxN ] [ maxM ] ; bool v [ maxN ] [ maxM ] ; int findLen ( int * arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return -1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , curr arr [ i ] , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != -1 ) dp [ i ] [ curr ] = max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } int main ( ) { int arr [ ] = { 3 , 7 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int m = 3 ; int ans = findLen ( arr , 0 , 0 , n , m ) ; if ( ans == -1 ) cout << 0 ; else cout << ans ; return 0 ; }

Index/key variables: curr, i, maxM, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxM  64
int dp [ maxN ] [ maxM ] ; bool v [ maxN ] [ maxM ] ; int findLen ( int * arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return -1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , curr & arr [ i ] , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != -1 ) dp [ i ] [ curr ] = max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } int main ( ) { int arr [ ] = { 3 , 7 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int m = 3 ; int ans = findLen ( arr , 0 , ( ( 1 << 8 ) - 1 ) , n , m ) ; if ( ans == -1 ) cout << 0 ; else cout << ans ; return 0 ; }

Index/key variables: curr, i, maxM, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxM  64
int dp [ maxN ] [ maxM ] ; bool v [ maxN ] [ maxM ] ; int findLen ( int * arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( ! curr ) return 0 ; else return -1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , ( curr + arr [ i ] ) % m , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != -1 ) dp [ i ] [ curr ] = max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } int main ( ) { int arr [ ] = { 3 , 2 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int m = 3 ; cout << findLen ( arr , 0 , 0 , n , m ) ; return 0 ; }

Index/key variables: curr, i, maxM, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxSum  50
#define minSum  50
#define base  50
int dp [ maxN ] [ maxSum + minSum ] ; bool v [ maxN ] [ maxSum + minSum ] ; int findCnt ( int * arr , int i , int required_sum , int n ) { if ( i == n ) { if ( required_sum == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ required_sum + base ] ) return dp [ i ] [ required_sum + base ] ; v [ i ] [ required_sum + base ] = 1 ; dp [ i ] [ required_sum + base ] = findCnt ( arr , i + 1 , required_sum , n ) + findCnt ( arr , i + 1 , required_sum - arr [ i ] , n ) ; return dp [ i ] [ required_sum + base ] ; } int main ( ) { int arr [ ] = { 3 , 3 , 3 , 3 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int x = 6 ; cout << findCnt ( arr , 0 , x , n ) ; return 0 ; }

Index/key variables: i, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxM  64
int dp [ maxN ] [ maxM ] ; bool v [ maxN ] [ maxM ] ; int findCnt ( int * arr , int i , int curr , int n , int m ) { if ( i == n ) { return ( curr == m ) ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; dp [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr arr [ i ] ) , n , m ) ; return dp [ i ] [ curr ] ; } int main ( ) { int arr [ ] = { 2 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int m = 3 ; cout << findCnt ( arr , 0 , 0 , n , m ) ; return 0 ; }

Index/key variables: curr, i, maxM, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
#define maxM  64
int dp1 [ maxN ] [ maxM ] ; bool v1 [ maxN ] [ maxM ] ; int findCnt ( int * arr , int i , int curr , int n , int m ) { if ( i == n ) { return ( curr == m ) ; } if ( v1 [ i ] [ curr ] ) return dp1 [ i ] [ curr ] ; v1 [ i ] [ curr ] = 1 ; dp1 [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr & arr [ i ] ) , n , m ) ; return dp1 [ i ] [ curr ] ; } int main ( ) { int arr [ ] = { 0 , 0 , 0 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int m = 0 ; cout << findCnt ( arr , 0 , ( ( 1 << 6 ) - 1 ) , n , m ) ; return 0 ; }

Index/key variables: curr, i, maxM, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  (int)(1e9 + 7)
int modulo_13 ( string s , int n ) { long long dp [ n + 1 ] [ 13 ] = { { 0 } } ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { int nxt = s [ i ] - '0' ; if ( s [ i ] == ' ? ' ) nxt = j ; for ( int k = 0 ; k < 13 ; k ++ ) { int rem = ( 10 * k + nxt ) % 13 ; dp [ i + 1 ] [ rem ] += dp [ i ] [ k ] ; dp [ i + 1 ] [ rem ] %= MOD ; } if ( s [ i ] != ' ? ' ) break ; } } return ( int ) dp [ n ] [ 5 ] ; } int main ( ) { string s = " ? 44" ; int n = s . size ( ) ; cout << modulo_13 ( s , n ) ; return 0 ; }

Index/key variables: i, k, n, rem
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LISusingLCS ( vector < int > & seq ) { int n = seq . size ( ) ; vector < vector < int > > L ( n + 1 , vector < int > ( n + 1 ) ) ; vector < int > sortedseq ( seq ) ; sort ( sortedseq . begin ( ) , sortedseq . end ( ) ) ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( seq [ i - 1 ] == sortedseq [ j - 1 ] ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ n ] [ n ] ; } int main ( ) { vector < int > sequence { 12 , 34 , 1 , 5 , 40 , 80 } ; cout << LISusingLCS ( sequence ) << endl ; 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 count_numbers ( int k , int n , bool flag ) { if ( n == 1 ) { if ( flag ) { return ( k - 1 ) ; } else { return 1 ; } } if ( flag ) return ( k - 1 ) * ( count_numbers ( k , n - 1 , 0 ) + count_numbers ( k , n - 1 , 1 ) ) ; else return count_numbers ( k , n - 1 , 1 ) ; } int main ( ) { int n = 3 ; int k = 10 ; cout << count_numbers ( k , n , true ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_numbers ( int k , int n ) { int dp [ n + 1 ] [ 2 ] ; dp [ 1 ] [ 0 ] = 0 ; dp [ 1 ] [ 1 ] = k - 1 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] ) * ( k - 1 ) ; } return dp [ n ] [ 0 ] + dp [ n ] [ 1 ] ; } int main ( ) { int k = 10 ; int n = 3 ; cout << count_numbers ( k , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int divideArray ( int arr [ ] , int n , int k ) { int dp [ 500 ] [ 500 ] = { 0 } ; k -= 1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j <= k ; j ++ ) { dp [ i ] [ j ] = INT_MAX ; int max_ = -1 , sum = 0 ; for ( int l = i ; l < n ; l ++ ) { max_ = max ( max_ , arr [ l ] ) ; sum += arr [ l ] ; int diff = ( l - i + 1 ) * max_ - sum ; if ( j > 0 ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , diff + dp [ l + 1 ] [ j - 1 ] ) ; else dp [ i ] [ j ] = diff ; } } } return dp [ 0 ] [ k ] ; } int main ( ) { int arr [ ] = { 2 , 9 , 5 , 4 , 8 , 3 , 6 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int k = 2 ; cout << divideArray ( arr , n , k ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l, stdc, sum
Iterator variables: i, j, l
C++ program:
#include <iostream>
#include <math.h>
using namespace std ; int cntSubsets ( int * arr , int n ) { unsigned int max = pow ( 2 , n ) ; int result = 0 ; for ( int i = 0 ; i < max ; i ++ ) { int counter = i ; if ( counter & ( counter >> 1 ) ) continue ; result ++ ; } return result ; } int main ( ) { int arr [ ] = { 3 , 5 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << cntSubsets ( arr , n ) ; return 0 ; }

Accumulator variables: i, result
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int cntSubsets ( int * arr , int n ) { int a [ n ] , b [ n ] ; a [ 0 ] = b [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i - 1 ] + b [ i - 1 ] ; b [ i ] = a [ i - 1 ] ; } int result = a [ n - 1 ] + b [ n - 1 ] ; return result ; } int main ( ) { int arr [ ] = { 3 , 5 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << cntSubsets ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void perfix_calculate ( vector < vector < int > > & A , vector < vector < int > > & row , vector < vector < int > > & col ) { int n = ( int ) A . size ( ) ; int m = ( int ) A [ 0 ] . size ( ) ; for ( int i = 0 ; i < n ; ++ i ) { row [ i ] [ 0 ] = A [ i ] [ 0 ] ; } for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 1 ; j < m ; ++ j ) { row [ i ] [ j ] = row [ i ] [ j - 1 ] + A [ i ] [ j ] ; } } for ( int i = 0 ; i < m ; ++ i ) { col [ 0 ] [ i ] = A [ 0 ] [ i ] ; } for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 1 ; j < n ; ++ j ) { col [ j ] [ i ] = A [ j ] [ i ] + col [ j - 1 ] [ i ] ; } } } int perimeter ( int i , int j , int k , vector < vector < int > > & row , vector < vector < int > > & col , vector < vector < int > > & A ) { int row_s , col_s ; if ( j == 0 ) row_s = 0 ; else row_s = row [ i ] [ j - 1 ] ; if ( i == 0 ) col_s = 0 ; else col_s = col [ i - 1 ] [ j ] ; int upper_row = row [ i ] [ j + k ] - row_s ; int left_col = col [ i + k ] [ j ] - col_s ; if ( j == 0 ) row_s = 0 ; else row_s = row [ i + k ] [ j - 1 ] ; if ( i == 0 ) col_s = 0 ; else col_s = col [ i - 1 ] [ j + k ] ; int lower_row = row [ i + k ] [ j + k ] - row_s ; int right_col = col [ i + k ] [ j + k ] - col_s ; int sum = upper_row + lower_row + left_col + right_col ; sum -= ( A [ i ] [ j ] + A [ i + k ] [ j ] + A [ i ] [ j + k ] + A [ i + k ] [ j + k ] ) ; return sum ; } int maxPerimeter ( vector < vector < int > > & A ) { int n = ( int ) A . size ( ) ; int m = ( int ) A [ 0 ] . size ( ) ; vector < vector < int > > row ( n , vector < int > ( m , 0 ) ) ; vector < vector < int > > col ( n , vector < int > ( m , 0 ) ) ; perfix_calculate ( A , row , col ) ; int maxPer = 0 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { for ( int k = 0 ; k < min ( n - i , m - j ) ; ++ k ) { int perimtr = perimeter ( i , j , k , row , col , A ) ; maxPer = max ( maxPer , perimtr ) ; } } } return maxPer ; } int main ( ) { vector < vector < int > > A = { { 1 , 1 , 0 } , { 1 , 1 , 1 } , { 0 , 1 , 1 } } ; cout << maxPerimeter ( A ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc, sum
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; pair < int , string > maxScore ( vector < int > money , int beg , int ed ) { int totalTurns = money . size ( ) ; int turnsTillNow = beg + ( ( totalTurns - 1 ) - ed ) ; if ( beg == ed ) { if ( turnsTillNow % 2 == 0 ) return { money [ beg ] , " L " } ; else return { 0 , " L " } ; } pair < int , string > scoreOne = maxScore ( money , beg + 1 , ed ) ; pair < int , string > scoreTwo = maxScore ( money , beg , ed - 1 ) ; if ( turnsTillNow % 2 == 0 ) { if ( money [ beg ] + scoreOne . first > money [ ed ] + scoreTwo . first ) { return { money [ beg ] + scoreOne . first , " L " + scoreOne . second } ; } else return { money [ ed ] + scoreTwo . first , " R " + scoreTwo . second } ; } else { if ( scoreOne . first < scoreTwo . first ) return { scoreOne . first , " L " + scoreOne . second } ; else return { scoreTwo . first , " R " + scoreTwo . second } ; } } int main ( ) { int ar [ ] = { 10 , 80 , 90 , 30 } ; int arraySize = sizeof ( ar ) / sizeof ( int ) ; vector < int > bags ( ar , ar + arraySize ) ; pair < int , string > ans = maxScore ( bags , 0 , bags . size ( ) - 1 ) ; cout << ans . first << " ▁ " << ans . second << endl ; return 0 ; }

Index/key variables: beg, ed
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1e9
int minJumps ( int arr [ ] , int N ) { int fib [ 30 ] ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( int i = 2 ; i < 30 ; i ++ ) fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; int DP [ N + 2 ] ; DP [ 0 ] = 0 ; for ( int i = 1 ; i <= N + 1 ; i ++ ) DP [ i ] = MAX ; for ( int i = 1 ; i <= N + 1 ; i ++ ) { for ( int j = 1 ; j < 30 ; j ++ ) { if ( ( arr [ i - 1 ] == 1 i == N + 1 ) && i - fib [ j ] >= 0 ) DP [ i ] = min ( DP [ i ] , 1 + DP [ i - fib [ j ] ] ) ; } } if ( DP [ N + 1 ] != MAX ) return DP [ N + 1 ] ; else return -1 ; } int main ( ) { int arr [ ] = { 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minJumps ( arr , 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 ; const int MAX = 100 ; int recur ( int ind , int cnt , int last , int a [ ] , int n , int k , int dp [ ] [ MAX ] ) { if ( cnt == k ) return 0 ; if ( ind == n ) return -1e9 ; if ( dp [ ind ] [ cnt ] != -1 ) return dp [ ind ] [ cnt ] ; int ans = 0 ; for ( int i = ind ; i < n ; i ++ ) { if ( cnt % 2 == 0 ) ans = max ( ans , recur ( i + 1 , cnt + 1 , i , a , n , k , dp ) ) ; else ans = max ( ans , __gcd ( a [ last ] , a [ i ] ) + recur ( i + 1 , cnt + 1 , 0 , a , n , k , dp ) ) ; } return dp [ ind ] [ cnt ] = ans ; } int main ( ) { int a [ ] = { 4 , 5 , 3 , 7 , 8 , 10 , 9 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int k = 4 ; int dp [ n ] [ MAX ] ; memset ( dp , -1 , sizeof dp ) ; cout << recur ( 0 , 0 , 0 , a , n , k , dp ) ; }

Index/key variables: MAX, cnt, i, ind, last, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find ( string s ) { if ( s . length ( ) == 0 ) return 0 ; int c = 1 ; string d = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { d += s [ i ] ; string s2 = s . substr ( i + 1 , d . length ( ) ) ; if ( s2 == d ) { c = 1 + find ( s . substr ( i + 1 ) ) ; break ; } } return c ; } int main ( ) { string s = " abababab " ; cout << find ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: d, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void addEdge ( vector < pair < int , int > > & edges , list < int > * tree , int x , int y ) { edges . push_back ( { x , y } ) ; tree [ x ] . push_back ( y ) ; tree [ y ] . push_back ( x ) ; } void dfs ( vector < pair < int , int > > & edges , list < int > * tree , int node , int parent , int dp [ ] ) { dp [ node ] = 1 ; for ( auto it : tree [ node ] ) { if ( it != parent ) { dfs ( edges , tree , it , node , dp ) ; dp [ node ] += dp [ it ] ; } } } int maximizeSum ( int a [ ] , vector < pair < int , int > > & edges , list < int > * tree , int n ) { int dp [ n + 1 ] = { 0 } ; dfs ( edges , tree , 1 , 0 , dp ) ; sort ( a , a + ( n - 1 ) ) ; vector < int > ans ; for ( auto it : edges ) { int x = it . first ; int y = it . second ; if ( dp [ x ] < dp [ y ] ) { int fi = dp [ x ] ; int sec = n - dp [ x ] ; ans . push_back ( fi * sec ) ; } else { int fi = dp [ y ] ; int sec = n - dp [ y ] ; ans . push_back ( fi * sec ) ; } } sort ( ans . begin ( ) , ans . end ( ) ) ; int res = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { res += ans [ i ] * a [ i ] ; } return res ; } int main ( ) { int n = 5 ; vector < pair < int , int > > edges ; list < int > * tree = new list < int > [ n + 1 ] ; addEdge ( edges , tree , 1 , 2 ) ; addEdge ( edges , tree , 1 , 3 ) ; addEdge ( edges , tree , 3 , 4 ) ; addEdge ( edges , tree , 3 , 5 ) ; int a [ ] = { 6 , 3 , 1 , 9 , 3 } ; cout << maximizeSum ( a , edges , tree , n ) ; }

Index/key variables: i, it, node, x, y
Accumulator variables: i, res, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 10 ; int maximizeSum ( int a [ ] , int n , int ind , int k , int dp [ MAX ] [ MAX ] ) { if ( k == 0 ) { if ( ind == n ) return 0 ; else return -1e9 ; } else if ( ind == n ) return -1e9 ; else if ( dp [ ind ] [ k ] != -1 ) return dp [ ind ] [ k ] ; else { int ans = 0 ; int mini = a [ ind ] ; for ( int i = ind ; i < n ; i ++ ) { mini = min ( mini , a [ i ] ) ; ans = max ( ans , maximizeSum ( a , n , i + 1 , k - 1 , dp ) + mini ) ; } return dp [ ind ] [ k ] = ans ; } } int main ( ) { int a [ ] = { 5 , 7 , 4 , 2 , 8 , 1 , 6 } ; int k = 3 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int dp [ MAX ] [ MAX ] ; memset ( dp , -1 , sizeof dp ) ; cout << maximizeSum ( a , n , 0 , k , dp ) ; return 0 ; }

Index/key variables: MAX, i, ind, k
Accumulator variables: i, stdc
Iterator variables: i