dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; long findNumUtil ( long res , int a , int aCount , int b , int bCount , int n ) { if ( res > 1e11 ) return 1e11 ; if ( aCount == bCount && res >= n ) return res ; return min ( findNumUtil ( res * 10 + a , a , aCount + 1 , b , bCount , n ) , findNumUtil ( res * 10 + b , a , aCount , b , bCount + 1 , n ) ) ; } int findNum ( int n , int a , int b ) { int result = 0 ; int aCount = 0 ; int bCount = 0 ; return findNumUtil ( result , a , aCount , b , bCount , n ) ; } int main ( ) { int N = 4500 ; int A = 4 ; int B = 7 ; cout << findNum ( N , A , B ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { int n = 7 , k = 3 ; if ( n % k == 0 ) cout << n / k << " ▁ " << n / k ; else cout << ( ( n - ( n % k ) ) / k ) << " ▁ " << ( ( ( n - ( n % k ) ) / k ) + 1 ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { float m = 50 , n = 5 , x = 67 , h = 2927 ; int z = ( ceil ( h / 60 * 1.0 ) ) ; if ( z <= n ) cout << z * m ; else cout << n * m + ( z - n ) * x ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; double sumProductDifference ( int a , int b , int c , int d , int e ) { double rootSum = ( double ) ( -1 * b ) / a ; double rootProduct = ( double ) e / a ; return abs ( rootSum - rootProduct ) ; } int main ( ) { cout << sumProductDifference ( 8 , 4 , 6 , 4 , 1 ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfSolutions ( int n ) { int c = 0 ; for ( int x = 0 ; x <= n ; ++ x ) if ( n == x + n ^ x ) ++ c ; return c ; } int main ( ) { int n = 3 ; cout << numberOfSolutions ( n ) ; return 0 ; }

Accumulator variables: stdc
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countNumbers ( int N ) { return ( pow ( 10 , N ) - pow ( 8 , N ) ) / 2 ; } int main ( ) { int n = 5 ; cout << countNumbers ( n ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 10000 ; int prefix [ MAX + 1 ] ; void buildPrefix ( ) { bool prime [ MAX + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } prefix [ 0 ] = prefix [ 1 ] = 0 ; for ( int p = 2 ; p <= MAX ; p ++ ) { prefix [ p ] = prefix [ p - 1 ] ; if ( prime [ p ] ) prefix [ p ] += p ; } } int sumPrimeRange ( int L , int R ) { buildPrefix ( ) ; return prefix [ R ] - prefix [ L - 1 ] ; } int main ( ) { int L = 10 , R = 20 ; cout << sumPrimeRange ( L , R ) << endl ; return 0 ; }

Index/key variables: R, i, p
Accumulator variables: i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateSum ( int n ) { return 2 * ( n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ) + n * ( n + 1 ) / 2 + 2 * ( n ) ; } int main ( ) { int n = 3 ; cout << " Sum ▁ = ▁ " << calculateSum ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long Bits ( int kilobytes ) { long Bits = 0 ; Bits = kilobytes * 8192 ; return Bits ; } long Bytes ( int kilobytes ) { long Bytes = 0 ; Bytes = kilobytes * 1024 ; return Bytes ; } int main ( ) { int kilobytes = 1 ; cout << kilobytes << " ▁ Kilobytes ▁ = ▁ " << Bytes ( kilobytes ) << " ▁ Bytes ▁ and ▁ " << Bits ( kilobytes ) << " ▁ Bits . " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
#define ll  long long int
using namespace std ; double findSum ( ll n ) { return sqrt ( 3 ) * ( n * ( n + 1 ) / 2 ) ; } int main ( ) { ll n = 10 ; cout << findSum ( n ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sum ( int x , int y , int n ) { int sum1 = ( pow ( x , 2 ) * ( pow ( x , 2 * n ) - 1 ) ) / ( pow ( x , 2 ) - 1 ) ; int sum2 = ( x * y * ( pow ( x , n ) * pow ( y , n ) - 1 ) ) / ( x * y - 1 ) ; return sum1 + sum2 ; } int main ( ) { int x = 2 , y = 2 , n = 2 ; cout << sum ( x , y , n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateSum ( int n ) { int a1 = 1 , a2 = 2 ; int r = 2 ; int d = 1 ; return ( n ) * ( 2 * a1 + ( n - 1 ) * d ) / 2 + a2 * ( pow ( r , n ) - 1 ) / ( r - 1 ) ; } int main ( ) { int n = 5 ; cout << " Sum ▁ = ▁ " << calculateSum ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long repeatedSum ( long n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } long repeatedProduct ( long n ) { long prod = 1 ; while ( n > 0 prod > 9 ) { if ( n == 0 ) { n = prod ; prod = 1 ; } prod *= n % 10 ; n /= 10 ; } return prod ; } long maxSumProduct ( long N ) { if ( N < 10 ) return N ; return max ( repeatedSum ( N ) , repeatedProduct ( N ) ) ; } int main ( ) { long n = 631 ; cout << maxSumProduct ( n ) << endl ; return 0 ; }

Accumulator variables: n, prod, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
int max_value ( int array [ ] [ 2 ] , int M , int K , int N ) { int time [ M ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { time [ array [ i ] [ 0 ] ] = array [ i ] [ 1 ] ; } int dp [ M ] [ 2 ] ; dp [ 0 ] [ 0 ] = 0 ; dp [ 0 ] [ 1 ] = time [ 0 ] ; for ( int i = 1 ; i < M ; i ++ ) { dp [ i ] [ 0 ] = max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) ; dp [ i ] [ 1 ] = time [ i ] ; if ( i - K >= 0 ) { dp [ i ] [ 1 ] += max ( dp [ i - K ] [ 0 ] , dp [ i - K ] [ 1 ] ) ; } } return max ( dp [ M - 1 ] [ 0 ] , dp [ M - 1 ] [ 1 ] ) ; } int main ( ) { int array [ ] [ 2 ] = { { 0 , 10 } , { 4 , 110 } , { 5 , 30 } } ; int N = 3 ; int K = 4 ; int M = 6 ; cout << max_value ( array , M , K , N ) ; }

Index/key variables: M, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > digits ; bool vis [ 170 ] = { false } ; int dp [ 19 ] [ 19 ] [ 2 ] [ 170 ] ; void ConvertIntoDigit ( int n ) { while ( n ) { int dig = n % 10 ; digits . push_back ( dig ) ; n /= 10 ; } reverse ( digits . begin ( ) , digits . end ( ) ) ; } int solve ( int idx , int k , int tight , int sum ) { if ( idx == digits . size ( ) && k == 0 && sum & 1 ) { if ( ! vis [ sum ] ) { vis [ sum ] = 1 ; return 1 ; } return 0 ; } if ( idx > digits . size ( ) ) { return 0 ; } if ( dp [ idx ] [ k ] [ tight ] [ sum ] ) { return dp [ idx ] [ k ] [ tight ] [ sum ] ; } int j ; if ( tight == 0 ) { j = digits [ idx ] ; } else { j = 9 ; } int cnt = 0 ; for ( int i = ( k ? 0 : 1 ) ; i <= j ; i ++ ) { int newtight = tight ; if ( i < j ) { newtight = 1 ; } if ( i == 0 ) cnt += solve ( idx + 1 , k - 1 , newtight , sum ) ; else cnt += solve ( idx + 1 , k , newtight , sum + i ) ; } return dp [ idx ] [ k ] [ tight ] [ sum ] = cnt ; } int main ( ) { int N , k ; N = 169 , k = 2 ; ConvertIntoDigit ( N ) ; k = digits . size ( ) - k ; cout << solve ( 0 , k , 0 , 0 ) ; }

Index/key variables: idx, k, sum, tight
Accumulator variables: cnt, i, n, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubsets ( int N ) { if ( N <= 2 ) return N ; if ( N == 3 ) return 2 ; int DP [ N + 1 ] = { 0 } ; DP [ 0 ] = 0 , DP [ 1 ] = 1 , DP [ 2 ] = 2 , DP [ 3 ] = 2 ; for ( int i = 4 ; i <= N ; i ++ ) { DP [ i ] = DP [ i - 2 ] + DP [ i - 3 ] ; } return DP [ N ] ; } int main ( ) { int N = 20 ; cout << countSubsets ( 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 dp [ 500 ] [ 500 ] ; int CountSets ( int x , int pos ) { if ( x <= 0 ) { if ( pos == 0 ) return 1 ; else return 0 ; } if ( pos == 0 ) return 1 ; if ( dp [ x ] [ pos ] != -1 ) return dp [ x ] [ pos ] ; int answer = CountSets ( x - 1 , pos ) + CountSets ( x - 2 , pos - 1 ) ; return dp [ x ] [ pos ] = answer ; } int CountOrderedSets ( int n ) { int factorial [ 10000 ] ; factorial [ 0 ] = 1 ; for ( int i = 1 ; i < 10000 ; i ++ ) factorial [ i ] = factorial [ i - 1 ] * i ; int answer = 0 ; memset ( dp , -1 , sizeof ( dp ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { int sets = CountSets ( n , i ) * factorial [ i ] ; answer = answer + sets ; } return answer ; } int main ( ) { int N = 3 ; cout << CountOrderedSets ( N ) ; return 0 ; }

Index/key variables: i, pos, x
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfArithmeticSequences ( int L [ ] , int N ) { if ( N <= 2 ) return 0 ; int count = 0 ; int res = 0 ; for ( int i = 2 ; i < N ; ++ i ) { if ( L [ i ] - L [ i - 1 ] == L [ i - 1 ] - L [ i - 2 ] ) { ++ count ; } else { count = 0 ; } res += count ; } return res ; } int main ( ) { int L [ ] = { 1 , 3 , 5 , 6 , 7 , 8 } ; int N = sizeof ( L ) / sizeof ( L [ 0 ] ) ; cout << numberOfArithmeticSequences ( L , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountOfTriplets ( int a [ ] , int n ) { int answer = 0 ; int x = 0 ; int count [ 100005 ] = { 0 } ; int ways [ 100005 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { x ^= a [ i ] ; answer += count [ x ] * i - ways [ x ] ; count [ x ] ++ ; ways [ x ] += ( i + 1 ) ; } return answer ; } int main ( ) { int Arr [ ] = { 3 , 6 , 12 , 8 , 6 , 2 , 1 , 5 } ; int N = sizeof ( Arr ) / sizeof ( Arr [ 0 ] ) ; cout << CountOfTriplets ( Arr , N ) ; return 0 ; }

Index/key variables: i, x
Accumulator variables: answer, i, stdc, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 5000 ] [ ( 1 << 10 ) + 5 ] ; int getmask ( int val ) { int mask = 0 ; if ( val == 0 ) return 1 ; while ( val ) { int d = val % 10 ; mask |= ( 1 << d ) ; val /= 10 ; } return mask ; } int countWays ( int pos , int mask , int a [ ] , int n ) { if ( pos == n ) return ( mask > 0 ? 1 : 0 ) ; if ( dp [ pos ] [ mask ] != -1 ) return dp [ pos ] [ mask ] ; int count = 0 ; count = count + countWays ( pos + 1 , mask , a , n ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { int new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; count = count + countWays ( pos + 1 , new_mask , a , n ) ; } return dp [ pos ] [ mask ] = count ; } int numberOfSubarrays ( int a [ ] , int n ) { memset ( dp , -1 , sizeof ( dp ) ) ; return countWays ( 0 , 0 , a , n ) ; } int main ( ) { int N = 4 ; int A [ ] = { 1 , 12 , 23 , 34 } ; cout << numberOfSubarrays ( A , N ) ; return 0 ; }

Index/key variables: mask, pos
Accumulator variables: mask, stdc, val
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > fib ; struct node { struct node * left ; int data ; struct node * right ; } ; node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } int height ( node * root ) { int ht = 0 ; if ( root == NULL ) return 0 ; return ( max ( height ( root -> left ) , height ( root -> right ) ) + 1 ) ; } void FibonacciSeries ( int n ) { fib . push_back ( 0 ) ; fib . push_back ( 1 ) ; for ( int i = 2 ; i < n ; i ++ ) fib . push_back ( fib [ i - 1 ] + fib [ i - 2 ] ) ; } int CountPathUtil ( node * root , int i , int count ) { if ( root == NULL || ! ( fib [ i ] == root -> data ) ) { return count ; } if ( ! root -> left && ! root -> right ) { count ++ ; } count = CountPathUtil ( root -> left , i + 1 , count ) ; return CountPathUtil ( root -> right , i + 1 , count ) ; } void CountPath ( node * root ) { int ht = height ( root ) ; FibonacciSeries ( ht ) ; cout << CountPathUtil ( root , 0 , 0 ) ; } int main ( ) { node * root = newNode ( 0 ) ; root -> left = newNode ( 1 ) ; root -> right = newNode ( 1 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 4 ) ; root -> right -> right = newNode ( 1 ) ; root -> right -> right -> left = newNode ( 2 ) ; CountPath ( root ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int M = 18 ; int a , b , dp [ M ] [ 90 ] [ 90 ] [ 2 ] ; set < int > fib ; void fibonacci ( ) { int prev = 0 , curr = 1 ; fib . insert ( prev ) ; fib . insert ( curr ) ; while ( curr <= 100 ) { int temp = curr + prev ; fib . insert ( temp ) ; prev = curr ; curr = temp ; } } 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 ; if ( fib . find ( d ) != fib . end ( ) ) 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 ( ) { fibonacci ( ) ; 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, odd, pos, tight
Accumulator variables: ans, currEven, currOdd, d, stdc, x
Iterator variables: d
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumOccurrence ( string s ) { int n = s . length ( ) ; int freq [ 26 ] = { 0 } ; int dp [ 26 ] [ 26 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { int c = ( s [ i ] - ' a ' ) ; for ( int j = 0 ; j < 26 ; j ++ ) dp [ j ] += freq [ j ] ; freq ++ ; } int answer = INT_MIN ; for ( int i = 0 ; i < 26 ; i ++ ) answer = max ( answer , freq [ i ] ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { answer = max ( answer , dp [ i ] [ j ] ) ; } } return answer ; } int main ( ) { string s = " xxxyy " ; cout << maximumOccurrence ( s ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: freq, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int mod = 1000000007 ; int dp [ 1005 ] [ 105 ] [ 2 ] ; int powers [ 1005 ] ; int powersModk [ 1005 ] ; int calculate ( int pos , int rem , int z , int k , int n ) { if ( rem == 0 && z ) { if ( pos != n ) return ( powers [ n - pos - 1 ] * 9 ) % mod ; else return 1 ; } if ( pos == n ) return 0 ; if ( dp [ pos ] [ rem ] [ z ] != -1 ) return dp [ pos ] [ rem ] [ z ] ; int count = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( i == 0 ) count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , z , k , n ) ) ) % mod ; else count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , 1 , k , n ) ) ) % mod ; } return dp [ pos ] [ rem ] [ z ] = count ; } int countNumbers ( int n , int k ) { int st = 1 ; for ( int i = 0 ; i <= n ; i ++ ) { powers [ i ] = st ; st *= 10 ; st %= mod ; } st = 1 ; for ( int i = 0 ; i <= n ; i ++ ) { powersModk [ i ] = st ; st *= 10 ; st %= mod ; } memset ( dp , -1 , sizeof ( dp ) ) ; return calculate ( 0 , 0 , 0 , k , n ) ; } int main ( ) { int N = 2 ; int K = 2 ; cout << countNumbers ( N , K ) ; return 0 ; }

Index/key variables: i, pos, rem, z
Accumulator variables: i, st, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define inf  100000000
using namespace std ; double smPath ( int s , int d , vector < pair < pair < int , int > , int > > ed , int n , int k ) { int dis [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dis [ i ] = inf ; dis [ s ] = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int dis1 [ n + 1 ] ; for ( int j = 0 ; j <= n ; j ++ ) dis1 [ j ] = inf ; for ( auto it : ed ) dis1 [ it . first . second ] = min ( dis1 [ it . first . second ] , dis [ it . first . first ] + it . second ) ; for ( int i = 0 ; i <= n ; i ++ ) dis [ i ] = dis1 [ i ] ; } if ( dis [ d ] == inf ) return -1 ; else return dis [ d ] ; } int main ( ) { int n = 4 ; vector < pair < pair < int , int > , int > > ed ; ed = { { { 0 , 1 } , 10 } , { { 0 , 2 } , 3 } , { { 0 , 3 } , 2 } , { { 1 , 3 } , 7 } , { { 2 , 3 } , 7 } } ; int s = 0 , d = 3 ; int k = 2 ; cout << smPath ( s , d , ed , n , k ) ; }

Index/key variables: d, i, j, s
Accumulator variables: i, j, stdc
Iterator variables: i, it, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; double inf = std :: numeric_limits < double > :: infinity ( ) ; double bellman ( int s , int d , vector < pair < pair < int , int > , double > > ed , int n ) { if ( s == d ) return 0 ; double dis [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dis [ i ] = inf ; dis [ s ] = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( auto it : ed ) dis [ it . first . second ] = min ( dis [ it . first . second ] , dis [ it . first . first ] * it . second ) ; for ( auto it : ed ) { if ( dis [ it . first . second ] > dis [ it . first . first ] * it . second ) return -2 ; } if ( dis [ d ] == inf ) return -1 ; else return dis [ d ] ; } int main ( ) { int n = 3 ; vector < pair < pair < int , int > , double > > ed ; ed = { { { 1 , 2 } , 0.5 } , { { 1 , 3 } , 1.9 } , { { 2 , 3 } , 3 } } ; int s = 1 , d = 3 ; double get = bellman ( s , d , ed , n ) ; if ( get == -2 ) cout << " Cycle ▁ Detected " ; else cout << get ; }

Index/key variables: d, i, s
Accumulator variables: i, stdc
Iterator variables: i, it
C++ program:
#include <iostream>
using namespace std ; int maxLengthSquare ( int row , int column , int arr [ ] [ 4 ] , int k ) { int sum [ row + 1 ] [ column + 1 ] ; for ( int i = 1 ; i <= row ; i ++ ) for ( int j = 0 ; j <= column ; j ++ ) sum [ i ] [ j ] = 0 ; int cur_max = 1 ; int max = 0 ; for ( int i = 1 ; i <= row ; i ++ ) { for ( int j = 1 ; j <= column ; j ++ ) { sum [ i ] [ j ] = sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] + arr [ i - 1 ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ] ; if ( i >= cur_max && j >= cur_max && sum [ i ] [ j ] - sum [ i - cur_max ] [ j ] - sum [ i ] [ j - cur_max ] + sum [ i - cur_max ] [ j - cur_max ] <= k ) { max = cur_max ++ ; } } } return max ; } int main ( ) { int row = 4 , column = 4 ; int matrix [ 4 ] [ 4 ] = { { 1 , 1 , 1 , 1 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } } ; int k = 6 ; int ans = maxLengthSquare ( row , column , matrix , k ) ; cout << ans ; return 0 ; }

Index/key variables: i, j
Accumulator variables: cur_max, i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 101 ; const int mod = 1e9 + 7 ; int exactsum [ N ] [ N ] [ N ] ; int exactnum [ N ] [ N ] [ N ] ; int getSum ( int x , int y , int z ) { int ans = 0 ; exactnum [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i <= x ; ++ i ) { for ( int j = 0 ; j <= y ; ++ j ) { for ( int k = 0 ; k <= z ; ++ k ) { if ( i > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i - 1 ] [ j ] [ k ] * 10 + 4 * exactnum [ i - 1 ] [ j ] [ k ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i - 1 ] [ j ] [ k ] % mod ; } if ( j > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i ] [ j - 1 ] [ k ] * 10 + 5 * exactnum [ i ] [ j - 1 ] [ k ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i ] [ j - 1 ] [ k ] % mod ; } if ( k > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i ] [ j ] [ k - 1 ] * 10 + 6 * exactnum [ i ] [ j ] [ k - 1 ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i ] [ j ] [ k - 1 ] % mod ; } ans += exactsum [ i ] [ j ] [ k ] % mod ; ans %= mod ; } } } return ans ; } int main ( ) { int x = 1 , y = 1 , z = 1 ; cout << ( getSum ( x , y , z ) % mod ) ; return 0 ; }

Index/key variables: N, i, j, k
Accumulator variables: ans, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMax ( int a [ ] , int n ) { int dp [ n ] [ 2 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] [ 0 ] = a [ 0 ] + a [ 1 ] ; dp [ 0 ] [ 1 ] = a [ 0 ] * a [ 1 ] ; for ( int i = 1 ; i <= n - 2 ; i ++ ) { dp [ i ] [ 0 ] = max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + a [ i + 1 ] ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] - a [ i ] + a [ i ] * a [ i + 1 ] ; } cout << max ( dp [ n - 2 ] [ 0 ] , dp [ n - 2 ] [ 1 ] ) ; } int main ( ) { int arr [ ] = { 5 , -1 , -5 , -3 , 2 , 9 , -4 } ; findMax ( arr , 7 ) ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
ll sum ( int arr [ ] , int l , int r ) { ll s = 0 ; for ( int i = l ; i <= r ; i ++ ) { s += arr [ i ] ; } return s ; } ll dp [ 101 ] [ 101 ] [ 101 ] = { 0 } ; ll solve ( int arr [ ] , int l , int r , int k ) { if ( r - l + 1 <= k ) return sum ( arr , l , r ) ; if ( dp [ l ] [ r ] [ k ] ) return dp [ l ] [ r ] [ k ] ; ll sum_ = sum ( arr , l , r ) ; ll len_r = ( r - l + 1 ) - k ; ll len = ( r - l + 1 ) ; ll ans = 0 ; for ( int i = 0 ; i < len - len_r + 1 ; i ++ ) { ll sum_sub = sum ( arr , i + l , i + l + len_r - 1 ) ; ans = max ( ans , ( sum_ - sum_sub ) + ( sum_sub - solve ( arr , i + l , i + l + len_r - 1 , k ) ) ) ; } dp [ l ] [ r ] [ k ] = ans ; return ans ; } int main ( ) { int arr [ ] = { 10 , 15 , 20 , 9 , 2 , 5 } , k = 2 ; int n = sizeof ( arr ) / sizeof ( int ) ; memset ( dp , 0 , sizeof ( dp ) ) ; cout << solve ( arr , 0 , n - 1 , k ) ; return 0 ; }

Index/key variables: i, k, l, r
Accumulator variables: i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAXI  50
int dp [ MAXI ] [ MAXI ] [ MAXI * MAXI ] ; int n , m ; int minDifference ( int x , int y , int k , vector < vector < int > > b , vector < vector < int > > c ) { if ( x >= n or y >= m ) return INT_MAX ; if ( x == n - 1 and y == m - 1 ) { int diff = b [ x ] [ y ] - c [ x ] [ y ] ; return min ( abs ( k - diff ) , abs ( k + diff ) ) ; } int & ans = dp [ x ] [ y ] [ k ] ; if ( ans != -1 ) return ans ; ans = INT_MAX ; int diff = b [ x ] [ y ] - c [ x ] [ y ] ; ans = min ( ans , minDifference ( x + 1 , y , abs ( k + diff ) , b , c ) ) ; ans = min ( ans , minDifference ( x , y + 1 , abs ( k + diff ) , b , c ) ) ; ans = min ( ans , minDifference ( x + 1 , y , abs ( k - diff ) , b , c ) ) ; ans = min ( ans , minDifference ( x , y + 1 , abs ( k - diff ) , b , c ) ) ; return ans ; } int main ( ) { n = 2 , m = 2 ; vector < vector < int > > b = { { 1 , 4 } , { 2 , 4 } } ; vector < vector < int > > c = { { 3 , 2 } , { 3 , 1 } } ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << minDifference ( 0 , 0 , 0 , b , c ) ; return 0 ; }

Index/key variables: MAXI, k, x, y
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longest_subseq ( int n , int k , string s ) { vector < int > dp ( n , 0 ) ; int max_length [ 26 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { int curr = s [ i ] - ' a ' ; int lower = max ( 0 , curr - k ) ; int upper = min ( 25 , curr + k ) ; for ( int j = lower ; j < upper + 1 ; j ++ ) { dp [ i ] = max ( dp [ i ] , max_length [ j ] + 1 ) ; } max_length [ curr ] = max ( dp [ i ] , max_length [ curr ] ) ; } int ans = 0 ; for ( int i : dp ) ans = max ( i , ans ) ; return ans ; } int main ( ) { string s = " geeksforgeeks " ; int n = s . size ( ) ; int k = 3 ; cout << ( longest_subseq ( n , k , s ) ) ; return 0 ; }

Index/key variables: curr, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j