dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 1005 ] [ 1005 ] ; int maximumSumUtil ( int a [ ] , int index , int count , int n ) { if ( index > n count > n + 1 ) { return 0 ; } if ( dp [ index ] [ count ] != -1 ) return dp [ index ] [ count ] ; int ans1 = maximumSumUtil ( a , index + 1 , count + 1 , n ) + a [ index ] * count ; int ans2 = maximumSumUtil ( a , index + 1 , count , n ) ; return ( dp [ index ] [ count ] = max ( ans1 , ans2 ) ) ; } int maximumSum ( int arr [ ] , int N ) { memset ( dp , -1 , sizeof ( dp ) ) ; cout << maximumSumUtil ( arr , 0 , 1 , N - 1 ) ; } int main ( ) { int arr [ ] = { -1 , 2 , -10 , 4 , -20 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maximumSum ( arr , N ) ; return 0 ; }

Index/key variables: count, index
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void rearrange ( int arr [ ] , int n , int x ) { multimap < int , int > m ; multimap < int , int > :: iterator it ; for ( int i = 0 ; i < n ; i ++ ) m . insert ( make_pair ( abs ( x - arr [ i ] ) , arr [ i ] ) ) ; int i = 0 ; for ( it = m . begin ( ) ; it != m . end ( ) ; it ++ ) arr [ i ++ ] = ( * it ) . second ; } void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 10 , 5 , 3 , 9 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int x = 7 ; rearrange ( arr , n , x ) ; printArray ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, it, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > find_sequence ( int n ) { if ( n == 1 ) return { 1 , -1 } ; auto arr = find_sequence ( n - 1 ) ; vector < int > ans = { arr [ 0 ] + 1 , n - 1 } ; if ( n % 2 == 0 ) { vector < int > div_by_2 = find_sequence ( n / 2 ) ; if ( div_by_2 [ 0 ] < ans [ 0 ] ) ans = { div_by_2 [ 0 ] + 1 , n / 2 } ; } if ( n % 3 == 0 ) { vector < int > div_by_3 = find_sequence ( n / 3 ) ; if ( div_by_3 [ 0 ] < ans [ 0 ] ) vector < int > ans = { div_by_3 [ 0 ] + 1 , n / 3 } ; } return ans ; } vector < int > find_solution ( int n ) { auto a = find_sequence ( n ) ; cout << a [ 0 ] << endl ; vector < int > sequence ; sequence . push_back ( n ) ; while ( a [ 1 ] != -1 ) { sequence . push_back ( a [ 1 ] ) ; auto arr = find_sequence ( a [ 1 ] ) ; a [ 1 ] = arr [ 1 ] ; } reverse ( sequence . begin ( ) , sequence . end ( ) ) ; return sequence ; } int main ( ) { int n = 5 ; auto i = find_solution ( n ) ; for ( int j : i ) cout << j << " ▁ " ; }

Accumulator variables: stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int n , t ; int FindNoOfFullVessels ( int n , int t ) { double Matrix [ n ] [ n ] ; Matrix [ 0 ] [ 0 ] = t * 1.0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { double exceededwater = Matrix [ i ] [ j ] - 1.0 ; if ( exceededwater < 0 ) continue ; ans ++ ; if ( i + 1 < n ) Matrix [ i + 1 ] [ j ] += exceededwater / 2 ; if ( i + 1 < n && j + 1 < n ) Matrix [ i + 1 ] [ j + 1 ] += exceededwater / 2 ; } } return ans ; } int main ( ) { int N = 3 ; int T = 4 ; cout << FindNoOfFullVessels ( N , T ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <algorithm>
using namespace std ; void swap ( int * x , int * y ) { int temp = * x ; * x = * y ; * y = temp ; } void sortInWave ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; for ( int i = 0 ; i < n - 1 ; i += 2 ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ; } int main ( ) { int arr [ ] = { 10 , 90 , 49 , 2 , 1 , 5 , 23 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortInWave ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaxTimes ( string S ) { long long int arr [ 26 ] ; long long int dp [ 26 ] [ 26 ] ; memset ( arr , 0 , sizeof ( arr ) ) ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 0 ; i < S . size ( ) ; i ++ ) { int now = S [ i ] - ' a ' ; for ( int j = 0 ; j < 26 ; j ++ ) { dp [ j ] [ now ] += arr [ j ] ; } arr [ now ] ++ ; } long long int ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) ans = max ( ans , arr [ i ] ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { ans = max ( ans , dp [ i ] [ j ] ) ; } } return ans ; } int main ( ) { string S = " ddee " ; cout << findMaxTimes ( S ) ; return 0 ; }

Index/key variables: i, j, now
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void swap ( int * x , int * y ) { int temp = * x ; * x = * y ; * y = temp ; } void sortInWave ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i += 2 ) { if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ; if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ; } } int main ( ) { int arr [ ] = { 10 , 90 , 49 , 2 , 1 , 5 , 23 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortInWave ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } void print ( struct Node * root ) { if ( root != NULL ) { print ( root -> left ) ; cout << root -> data << " ▁ " ; print ( root -> right ) ; } } struct Node * prune ( struct Node * root , int sum ) { if ( root == NULL ) return NULL ; root -> left = prune ( root -> left , sum - root -> data ) ; root -> right = prune ( root -> right , sum - root -> data ) ; if ( root -> left == NULL && root -> right == NULL ) { if ( root -> data < sum ) { free ( root ) ; return NULL ; } } return root ; } int main ( ) { int k = 45 ; struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 8 ) ; root -> left -> left -> right = newNode ( 9 ) ; root -> left -> right -> left = newNode ( 12 ) ; root -> right -> right -> left = newNode ( 10 ) ; root -> right -> right -> left -> right = newNode ( 11 ) ; root -> left -> left -> right -> left = newNode ( 13 ) ; root -> left -> left -> right -> right = newNode ( 14 ) ; root -> left -> left -> right -> right -> left = newNode ( 15 ) ; cout << " Tree ▁ before ▁ truncation STRNEWLINE " ; print ( root ) ; root = prune ( root , k ) ; cout << " Tree after truncation " ; print ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_unique_sum ( int n ) { int i , ar [ n + 1 ] , fsum [ n + 1 ] ; int rsum [ n + 1 ] , ans = 1 ; memset ( fsum , 0 , sizeof fsum ) ; memset ( rsum , 0 , sizeof rsum ) ; for ( i = 0 ; i <= n ; i ++ ) { ar [ i ] = i ; } fsum [ 0 ] = ar [ 0 ] ; rsum [ n ] = ar [ n ] ; for ( i = 1 ; i <= n ; i ++ ) { fsum [ i ] = ar [ i ] + fsum [ i - 1 ] ; } for ( i = n - 1 ; i >= 0 ; i -- ) { rsum [ i ] = ar [ i ] + rsum [ i + 1 ] ; } for ( int k = 2 ; k <= n ; k ++ ) { ans += 1 + rsum [ n + 1 - k ] - fsum [ k - 1 ] ; } return ans ; } int main ( ) { int N = 4 ; cout << count_unique_sum ( N ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: ans, i, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define NA  -1
void moveToEnd ( int mPlusN [ ] , int size ) { int j = size - 1 ; for ( int i = size - 1 ; i >= 0 ; i -- ) if ( mPlusN [ i ] != NA ) { mPlusN [ j ] = mPlusN [ i ] ; j -- ; } } int merge ( int mPlusN [ ] , int N [ ] , int m , int n ) { int i = n ; int j = 0 ; int k = 0 ; while ( k < ( m + n ) ) { if ( ( j == n ) || ( i < ( m + n ) && mPlusN [ i ] <= N [ j ] ) ) { mPlusN [ k ] = mPlusN [ i ] ; k ++ ; i ++ ; } else { mPlusN [ k ] = N [ j ] ; k ++ ; j ++ ; } } } void printArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } int main ( ) { int mPlusN [ ] = { 2 , 8 , NA , NA , NA , 13 , NA , 15 , 20 } ; int N [ ] = { 5 , 7 , 9 , 25 } ; int n = sizeof ( N ) / sizeof ( N [ 0 ] ) ; int m = sizeof ( mPlusN ) / sizeof ( mPlusN [ 0 ] ) - n ; moveToEnd ( mPlusN , m + n ) ; merge ( mPlusN , N , m , n ) ; printArray ( mPlusN , m + n ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max ( int num1 , int num2 ) { return ( num1 > num2 ) ? num1 : num2 ; } int min ( int num1 , int num2 ) { return ( num1 > num2 ) ? num2 : num1 ; } int getCount ( int n , int k ) { if ( n == 1 ) return 10 ; int dp [ 11 ] = { 0 } ; int next [ 11 ] = { 0 } ; for ( int i = 1 ; i <= 9 ; i ++ ) dp [ i ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { int l = max ( 0 , ( j - k ) ) ; int r = min ( 9 , ( j + k ) ) ; next [ l ] += dp [ j ] ; next [ r + 1 ] -= dp [ j ] ; } for ( int j = 1 ; j <= 9 ; j ++ ) next [ j ] += next [ j - 1 ] ; for ( int j = 0 ; j < 10 ; j ++ ) { dp [ j ] = next [ j ] ; next [ j ] = 0 ; } } int count = 0 ; for ( int i = 0 ; i <= 9 ; i ++ ) count += dp [ i ] ; return count ; } int main ( ) { int n = 2 , k = 1 ; cout << getCount ( n , k ) ; return 0 ; }

Index/key variables: i, j, l
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) { int i , j ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] ) { j = i ; while ( B [ j ] ) j ++ ; sort ( A + i , A + 1 + j ) ; i = j ; } } for ( i = 0 ; i < n ; i ++ ) { if ( A [ i ] != i + 1 ) return false ; } return true ; } int main ( ) { int A [ ] = { 1 , 2 , 5 , 3 , 4 , 6 } ; bool B [ ] = { 0 , 1 , 1 , 1 , 0 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( sortedAfterSwap ( A , B , n ) ) cout << " A ▁ can ▁ be ▁ sorted STRNEWLINE " ; else cout << " A ▁ can ▁ not ▁ be ▁ sorted STRNEWLINE " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Edge { int src , dest , weight ; } ; struct Graph { int V , E ; struct Edge * edge ; } ; struct Graph * createGraph ( int V , int E ) { struct Graph * graph = new Graph ; graph -> V = V ; graph -> E = E ; graph -> edge = new Edge [ graph -> E ] ; return graph ; } void NegCycleBellmanFord ( struct Graph * graph , int src ) { int V = graph -> V ; int E = graph -> E ; int dist [ V ] ; int parent [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { dist [ i ] = INT_MAX ; parent [ i ] = -1 ; } dist [ src ] = 0 ; for ( int i = 1 ; i <= V - 1 ; i ++ ) { for ( int j = 0 ; j < E ; j ++ ) { int u = graph -> edge [ j ] . src ; int v = graph -> edge [ j ] . dest ; int weight = graph -> edge [ j ] . weight ; if ( dist [ u ] != INT_MAX && dist [ u ] + weight < dist [ v ] ) { dist [ v ] = dist [ u ] + weight ; parent [ v ] = u ; } } } int C = -1 ; for ( int i = 0 ; i < E ; i ++ ) { int u = graph -> edge [ i ] . src ; int v = graph -> edge [ i ] . dest ; int weight = graph -> edge [ i ] . weight ; if ( dist [ u ] != INT_MAX && dist [ u ] + weight < dist [ v ] ) { C = v ; break ; } } if ( C != -1 ) { for ( int i = 0 ; i < V ; i ++ ) C = parent [ C ] ; vector < int > cycle ; for ( int v = C ; ; v = parent [ v ] ) { cycle . push_back ( v ) ; if ( v == C && cycle . size ( ) > 1 ) break ; } reverse ( cycle . begin ( ) , cycle . end ( ) ) ; for ( int v : cycle ) cout << v << ' ▁ ' ; cout << endl ; } else cout << " - 1" << endl ; } int main ( ) { int V = 5 ; int E = 5 ; struct Graph * graph = createGraph ( V , E ) ; graph -> edge [ 0 ] . src = 0 ; graph -> edge [ 0 ] . dest = 1 ; graph -> edge [ 0 ] . weight = 1 ; graph -> edge [ 1 ] . src = 1 ; graph -> edge [ 1 ] . dest = 2 ; graph -> edge [ 1 ] . weight = 2 ; graph -> edge [ 2 ] . src = 2 ; graph -> edge [ 2 ] . dest = 3 ; graph -> edge [ 2 ] . weight = 3 ; graph -> edge [ 3 ] . src = 3 ; graph -> edge [ 3 ] . dest = 4 ; graph -> edge [ 3 ] . weight = -3 ; graph -> edge [ 4 ] . src = 4 ; graph -> edge [ 4 ] . dest = 1 ; graph -> edge [ 4 ] . weight = -3 ; NegCycleBellmanFord ( graph , 0 ) ; return 0 ; }

Index/key variables: C, V, i, j, src, u, v
Accumulator variables: i, j, stdc
Iterator variables: i, j, v
Class/struct names: Edge, Graph
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] ) { if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] != i + 1 ) return false ; } return true ; } int main ( ) { int A [ ] = { 1 , 2 , 5 , 3 , 4 , 6 } ; bool B [ ] = { 0 , 1 , 1 , 1 , 0 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( sortedAfterSwap ( A , B , n ) ) cout << " A ▁ can ▁ be ▁ sorted STRNEWLINE " ; else cout << " A ▁ can ▁ not ▁ be ▁ sorted STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void segregate0and1 ( int arr [ ] , int n ) { int type0 = 0 ; int type1 = n - 1 ; while ( type0 < type1 ) { if ( arr [ type0 ] == 1 ) { swap ( arr [ type0 ] , arr [ type1 ] ) ; type1 -- ; } else { type0 ++ ; } } } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; segregate0and1 ( arr , n ) ; for ( int a : arr ) cout << a << " ▁ " ; }

Index/key variables: type0, type1
Accumulator variables: stdc, type0, type1
Iterator variables: a
C++ program:
#include <bits/stdc++.h>
using namespace std ; int printpentaRec ( int n ) { if ( n == 0 n == 1 n == 2 n == 3 n == 4 ) return 0 ; else if ( n == 5 ) return 1 ; else return ( printpentaRec ( n - 1 ) + printpentaRec ( n - 2 ) + printpentaRec ( n - 3 ) + printpentaRec ( n - 4 ) + printpentaRec ( n - 5 ) ) ; } void printPenta ( int n ) { cout << printpentaRec ( n ) << " STRNEWLINE " ; } int main ( ) { int n = 10 ; printPenta ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getInvCount ( int arr [ ] , int n ) { int inv_count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ; return inv_count ; } int main ( ) { int arr [ ] = { 1 , 20 , 6 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " ▁ Number ▁ of ▁ inversions ▁ are ▁ " << getInvCount ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, inv_count, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > adj ; void addEdge ( int v , int w ) { adj [ v ] . push_back ( w ) ; adj [ w ] . push_back ( v ) ; } bool isReachable ( int s , int d ) { if ( s == d ) return true ; int n = ( int ) adj . size ( ) ; vector < bool > visited ( n , false ) ; queue < int > q ; visited [ s ] = true ; q . push ( s ) ; while ( ! q . empty ( ) ) { s = q . front ( ) ; q . pop ( ) ; for ( auto x : adj [ s ] ) { if ( x == d ) return true ; if ( ! visited [ x ] ) { visited [ x ] = true ; q . push ( x ) ; } } } return false ; } int main ( ) { int n = 4 ; adj = vector < vector < int > > ( n ) ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 2 ) ; addEdge ( 2 , 0 ) ; addEdge ( 2 , 3 ) ; addEdge ( 3 , 3 ) ; int u = 1 , v = 3 ; if ( isReachable ( u , v ) ) cout << " There is a path from " ▁ < < ▁ u ▁ < < ▁ " to " ▁ < < ▁ v ; STRNEWLINE TABSYMBOL else STRNEWLINE TABSYMBOL TABSYMBOL cout ▁ < < ▁ " There is no path from " ▁ < < ▁ u ▁ < < ▁ " to " return 0 ; }

Index/key variables: s, v, w, x
Accumulator variables: stdc
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Query { int L , R ; } ; int findResultUtil ( int arr [ ] , int L , int R ) { int result = 0 ; bool flag = false ; for ( int i = L ; i <= R ; i ++ ) { if ( flag == false ) { result = result + arr [ i ] ; flag = true ; } else { result = result - arr [ i ] ; flag = false ; } } return result ; } void findResult ( int arr [ ] , int n , Query q [ ] , int m ) { for ( int i = 0 ; i < m ; i ++ ) { cout << findResultUtil ( arr , q [ i ] . L , q [ i ] . R ) << " ▁ " ; } } int main ( ) { int arr [ ] = { 10 , 13 , 15 , 2 , 45 , 31 , 22 , 3 , 27 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Query q [ ] = { { 2 , 5 } , { 6 , 8 } , { 1 , 7 } , { 4 , 8 } , { 0 , 5 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; findResult ( arr , n , q , m ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: flag
Class/struct names: Query
C++ program:
# include <bits/stdc++.h>
# include <stdlib.h>
# include <math.h>
using namespace std ; void minAbsSumPair ( int arr [ ] , int arr_size ) { int inv_count = 0 ; int l , r , min_sum , sum , min_l , min_r ; if ( arr_size < 2 ) { cout << " Invalid ▁ Input " ; return ; } min_l = 0 ; min_r = 1 ; min_sum = arr [ 0 ] + arr [ 1 ] ; for ( l = 0 ; l < arr_size - 1 ; l ++ ) { for ( r = l + 1 ; r < arr_size ; r ++ ) { sum = arr [ l ] + arr [ r ] ; if ( abs ( min_sum ) > abs ( sum ) ) { min_sum = sum ; min_l = l ; min_r = r ; } } } cout << " The ▁ two ▁ elements ▁ whose ▁ sum ▁ is ▁ minimum ▁ are ▁ " << arr [ min_l ] << " ▁ and ▁ " << arr [ min_r ] ; } int main ( ) { int arr [ ] = { 1 , 60 , -10 , 70 , -80 , 85 } ; minAbsSumPair ( arr , 6 ) ; return 0 ; }

Index/key variables: l, min_l, min_r, r
Accumulator variables: l, r, stdc
Iterator variables: l, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumSum ( int S , int M , int N , vector < vector < int > > & stacks ) { int dp [ S + 1 ] [ N + 1 ] ; memset ( dp , INT_MIN , sizeof ( dp ) ) ; for ( int i = 0 ; i < S ; i ++ ) { for ( int j = 0 ; j <= N ; j ++ ) { for ( int k = 0 ; k <= min ( j , M ) ; k ++ ) { dp [ i + 1 ] [ j ] = max ( dp [ i + 1 ] [ j ] , stacks [ i ] [ k ] + dp [ i ] [ j - k ] ) ; } } } int result = INT_MIN ; for ( int i = 0 ; i <= N ; i ++ ) { result = max ( result , dp [ S ] [ i ] ) ; } return result ; } int main ( ) { int S = 2 ; int M = 4 ; vector < vector < int > > stacks = { { 2 , 6 , 4 , 5 } , { 1 , 6 , 15 , 10 } } ; int N = 3 ; cout << maximumSum ( S , M , N , stacks ) ; return 0 ; }

Index/key variables: S, i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compare ( int x , int y ) { return abs ( x ) < abs ( y ) ; } void findMinSum ( int arr [ ] , int n ) { sort ( arr , arr + n , compare ) ; int min = INT_MAX , x , y ; for ( int i = 1 ; i < n ; i ++ ) { if ( abs ( arr [ i - 1 ] + arr [ i ] ) <= min ) { min = abs ( arr [ i - 1 ] + arr [ i ] ) ; x = i - 1 ; y = i ; } } cout << " The ▁ two ▁ elements ▁ whose ▁ sum ▁ is ▁ minimum ▁ are ▁ " << arr [ x ] << " ▁ and ▁ " << arr [ y ] ; } int main ( ) { int arr [ ] = { 1 , 60 , -10 , 70 , -80 , 85 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findMinSum ( arr , n ) ; return 0 ; }

Index/key variables: i, x, y
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int mod = 1e9 + 7 ; #define MAX  301
#define MAXP  3
#define MAXK  600
#define MAXPREV  4
int dp [ MAX ] [ MAXP + 1 ] [ MAXK ] [ MAXPREV + 1 ] ; bool vis [ MAX ] ; int helper ( int col , int prevCol , int painted , int prev , int N , int P , int K ) { if ( painted >= K ) { int continuousCol = 0 ; int maxContinuousCol = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( vis [ i ] == false ) continuousCol ++ ; else { maxContinuousCol = max ( maxContinuousCol , continuousCol ) ; continuousCol = 0 ; } } maxContinuousCol = max ( maxContinuousCol , continuousCol ) ; if ( maxContinuousCol < P ) return 1 ; return 0 ; } if ( col >= N ) return 0 ; if ( dp [ col ] [ prevCol ] [ painted ] [ prev ] != -1 ) return dp [ col ] [ prevCol ] [ painted ] [ prev ] ; int res = 0 ; if ( prev == 0 ) { vis [ col ] = true ; res += ( helper ( col + 1 , 0 , painted + 1 , 1 , N , P , K ) ) % mod ; res += ( helper ( col + 1 , 0 , painted + 1 , 2 , N , P , K ) ) % mod ; res += ( helper ( col + 1 , 0 , painted + 1 , 3 , N , P , K ) ) % mod ; if ( painted + 2 <= K ) { res += ( helper ( col + 1 , 0 , painted + 2 , 4 , N , P , K ) ) % mod ; } vis [ col ] = false ; if ( prevCol + 1 < P ) { res += ( helper ( col + 1 , prevCol + 1 , painted , 0 , N , P , K ) ) % mod ; } } else if ( prev == 1 ) { vis [ col ] = true ; res += ( helper ( col + 1 , 0 , painted + 1 , 2 , N , P , K ) ) % mod ; res += ( helper ( col + 1 , 0 , painted + 1 , 3 , N , P , K ) ) % mod ; vis [ col ] = false ; if ( prevCol + 1 < P ) { res += ( helper ( col + 1 , prevCol + 1 , painted , 0 , N , P , K ) ) % mod ; } } else if ( prev == 2 ) { vis [ col ] = true ; res += ( helper ( col + 1 , 0 , painted + 1 , 1 , N , P , K ) ) % mod ; res += ( helper ( col + 1 , 0 , painted + 1 , 3 , N , P , K ) ) % mod ; if ( painted + 2 <= K ) { res += ( helper ( col + 1 , 0 , painted + 2 , 4 , N , P , K ) ) % mod ; } vis [ col ] = false ; if ( prevCol + 1 < P ) { res += ( helper ( col + 1 , prevCol + 1 , painted , 0 , N , P , K ) ) % mod ; } } else if ( prev == 3 ) { vis [ col ] = true ; res += ( helper ( col + 1 , 0 , painted + 1 , 1 , N , P , K ) ) % mod ; res += ( helper ( col + 1 , 0 , painted + 1 , 2 , N , P , K ) ) % mod ; vis [ col ] = false ; if ( prevCol + 1 < P ) { res += ( helper ( col + 1 , prevCol + 1 , painted , 0 , N , P , K ) ) % mod ; } } else { vis [ col ] = true ; res += ( helper ( col + 1 , 0 , painted + 1 , 2 , N , P , K ) ) % mod ; vis [ col ] = false ; if ( prevCol + 1 < P ) { res += ( helper ( col + 1 , prevCol + 1 , painted , 0 , N , P , K ) ) % mod ; } } return dp [ col ] [ prevCol ] [ painted ] [ prev ] = res % mod ; } int solve ( int n , int p , int k ) { memset ( dp , -1 , sizeof ( dp ) ) ; memset ( vis , false , sizeof ( vis ) ) ; return helper ( 0 , 0 , 0 , 0 , n , p , k ) ; } int main ( ) { int N = 2 , K = 2 , P = 2 ; cout << solve ( N , P , K ) << endl ; return 0 ; }

Index/key variables: MAX, MAXK, col, i, painted, prev, prevCol
Accumulator variables: continuousCol, i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void dicesSum ( int n ) { vector < map < int , double > > dp ( n + 1 ) ; dp [ 1 ] = { { 1 , 1 / 6.0 } , { 2 , 1 / 6.0 } , { 3 , 1 / 6.0 } , { 4 , 1 / 6.0 } , { 5 , 1 / 6.0 } , { 6 , 1 / 6.0 } } ; for ( int i = 2 ; i <= n ; i ++ ) { for ( auto a1 : dp [ i - 1 ] ) { for ( auto a2 : dp [ 1 ] ) { dp [ i ] [ a1 . first + a2 . first ] += a1 . second * a2 . second ; } } } for ( auto a : dp [ n ] ) { cout << a . first << " ▁ " << setprecision ( 2 ) << a . second << endl ; } } int main ( ) { int n = 2 ; dicesSum ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: a, a1, a2, i