dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSub ( int arr [ ] , int n ) { int count [ 10 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = arr [ i ] - 1 ; j >= 0 ; j -- ) count [ arr [ i ] ] += count [ j ] ; count [ arr [ i ] ] ++ ; } int result = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) result += count [ i ] ; return result ; } int main ( ) { int arr [ ] = { 3 , 2 , 4 , 5 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSub ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, result, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int minimum ( int a , int b , int c ) { return min ( min ( a , b ) , c ) ; } int findMinSum ( int arr [ ] , int n ) { int sum [ n ] ; sum [ 0 ] = arr [ 0 ] ; sum [ 1 ] = arr [ 1 ] ; sum [ 2 ] = arr [ 2 ] ; for ( int i = 3 ; i < n ; i ++ ) sum [ i ] = arr [ i ] + minimum ( sum [ i - 3 ] , sum [ i - 2 ] , sum [ i - 1 ] ) ; return minimum ( sum [ n - 1 ] , sum [ n - 2 ] , sum [ n - 3 ] ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 20 , 2 , 10 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Min ▁ Sum ▁ is ▁ " << findMinSum ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define INF  1000000
using namespace std ; int MinimumCost ( int cost [ ] , int n , int W ) { vector < int > val , wt ; int size = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( cost [ i ] != -1 ) { val . push_back ( cost [ i ] ) ; wt . push_back ( i + 1 ) ; size ++ ; } } n = size ; int min_cost [ n + 1 ] [ W + 1 ] ; for ( int i = 0 ; i <= W ; i ++ ) min_cost [ 0 ] [ i ] = INF ; for ( int i = 1 ; i <= n ; i ++ ) min_cost [ i ] [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= W ; j ++ ) { if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ; else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ; } } return ( min_cost [ n ] [ W ] == INF ) ? -1 : min_cost [ n ] [ W ] ; } int main ( ) { int cost [ ] = { 1 , 2 , 3 , 4 , 5 } , W = 5 ; int n = sizeof ( cost ) / sizeof ( cost [ 0 ] ) ; cout << MinimumCost ( cost , n , W ) ; return 0 ; }

Index/key variables: W, i, j, n
Accumulator variables: i, j, size, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lcs ( char * X , char * Y , int m , int n ) { int L [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ 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 [ m ] [ n ] ; } int findMinCost ( char X [ ] , char Y [ ] , int costX , int costY ) { int m = strlen ( X ) , n = strlen ( Y ) ; int len_LCS = lcs ( X , Y , m , n ) ; return costX * ( m - len_LCS ) + costY * ( n - len_LCS ) ; } int main ( ) { char X [ ] = " ef " ; char Y [ ] = " gh " ; cout << " Minimum ▁ Cost ▁ to ▁ make ▁ two ▁ strings ▁ " << " ▁ identical ▁ is ▁ = ▁ " << findMinCost ( X , Y , 10 , 20 ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std ; struct Job { int start , finish , profit ; } ; int findSum ( vector < Job > arr ) { int sum = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) sum += arr [ i ] . profit ; return sum ; } int compare ( Job x , Job y ) { return x . start < y . start ; } void findMaxProfit ( vector < Job > & arr ) { sort ( arr . begin ( ) , arr . end ( ) , compare ) ; vector < vector < Job > > L ( arr . size ( ) ) ; L [ 0 ] . push_back ( arr [ 0 ] ) ; for ( int i = 1 ; i < arr . size ( ) ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] . finish <= arr [ i ] . start ) && ( findSum ( L [ j ] ) > findSum ( L [ i ] ) ) ) L [ i ] = L [ j ] ; } L [ i ] . push_back ( arr [ i ] ) ; } vector < Job > maxChain ; for ( int i = 0 ; i < L . size ( ) ; i ++ ) if ( findSum ( L [ i ] ) > findSum ( maxChain ) ) maxChain = L [ i ] ; for ( int i = 0 ; i < maxChain . size ( ) ; i ++ ) cout << " ( " << maxChain [ i ] . start << " , ▁ " << maxChain [ i ] . finish << " , ▁ " << maxChain [ i ] . profit << " ) ▁ " ; } int main ( ) { Job a [ ] = { { 3 , 10 , 20 } , { 1 , 2 , 50 } , { 6 , 19 , 100 } , { 2 , 100 , 200 } } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; vector < Job > arr ( a , a + n ) ; findMaxProfit ( arr ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: Job
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  100
int L [ N ] [ N ] ; set < string > findLCS ( string X , string Y , int m , int n ) { set < string > s ; if ( m == 0 n == 0 ) { s . insert ( " " ) ; return s ; } if ( X [ m - 1 ] == Y [ n - 1 ] ) { set < string > tmp = findLCS ( X , Y , m - 1 , n - 1 ) ; for ( string str : tmp ) s . insert ( str + X [ m - 1 ] ) ; } else { if ( L [ m - 1 ] [ n ] >= L [ m ] [ n - 1 ] ) s = findLCS ( X , Y , m - 1 , n ) ; if ( L [ m ] [ n - 1 ] >= L [ m - 1 ] [ n ] ) { set < string > tmp = findLCS ( X , Y , m , n - 1 ) ; s . insert ( tmp . begin ( ) , tmp . end ( ) ) ; } } return s ; } int LCS ( string X , string Y , int m , int n ) { for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ 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 [ m ] [ n ] ; } int main ( ) { string X = " AGTGATG " ; string Y = " GTTAG " ; int m = X . length ( ) ; int n = Y . length ( ) ; cout << " LCS ▁ length ▁ is ▁ " << LCS ( X , Y , m , n ) << endl ; set < string > s = findLCS ( X , Y , m , n ) ; for ( string str : s ) cout << str << endl ; return 0 ; }

Index/key variables: N, i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j, str
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countIntegralSolutions ( int n ) { int result = 0 ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n - i ; j ++ ) for ( int k = 0 ; k <= ( n - i - j ) ; k ++ ) if ( i + j + k == n ) result ++ ; return result ; } int main ( ) { int n = 3 ; cout << countIntegralSolutions ( n ) ; return 0 ; }

Accumulator variables: i, j, k, result, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countIntegralSolutions ( int n ) { return ( ( n + 1 ) * ( n + 2 ) ) / 2 ; } int main ( ) { int n = 3 ; cout << countIntegralSolutions ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxLeftSubArraySum ( int a [ ] , int size , int sum [ ] ) { int max_so_far = a [ 0 ] ; int curr_max = a [ 0 ] ; sum [ 0 ] = max_so_far ; for ( int i = 1 ; i < size ; i ++ ) { curr_max = max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = max ( max_so_far , curr_max ) ; sum [ i ] = max_so_far ; } return max_so_far ; } int maxRightSubArraySum ( int a [ ] , int n , int sum [ ] ) { int max_so_far = a [ n ] ; int curr_max = a [ n ] ; sum [ n ] = max_so_far ; for ( int i = n - 1 ; i >= 0 ; i -- ) { curr_max = max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = max ( max_so_far , curr_max ) ; sum [ i ] = max_so_far ; } return max_so_far ; } int findMaxAbsDiff ( int arr [ ] , int n ) { int leftMax [ n ] ; maxLeftSubArraySum ( arr , n , leftMax ) ; int rightMax [ n ] ; maxRightSubArraySum ( arr , n - 1 , rightMax ) ; int invertArr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) invertArr [ i ] = - arr [ i ] ; int leftMin [ n ] ; maxLeftSubArraySum ( invertArr , n , leftMin ) ; for ( int i = 0 ; i < n ; i ++ ) leftMin [ i ] = - leftMin [ i ] ; int rightMin [ n ] ; maxRightSubArraySum ( invertArr , n - 1 , rightMin ) ; for ( int i = 0 ; i < n ; i ++ ) rightMin [ i ] = - rightMin [ i ] ; int result = INT_MIN ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int absValue = max ( abs ( leftMax [ i ] - rightMin [ i + 1 ] ) , abs ( leftMin [ i ] - rightMax [ i + 1 ] ) ) ; if ( absValue > result ) result = absValue ; } return result ; } int main ( ) { int a [ ] = { -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << findMaxAbsDiff ( 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 ; #define M  4
#define N  4
struct Point { int x , y ; } ; list < Point > findPath ( int grid [ M ] [ N ] , int mat [ M ] [ N ] , int i , int j ) { list < Point > path ; Point pt = { i , j } ; path . push_front ( pt ) ; while ( grid [ i ] [ j ] != 0 ) { if ( i > 0 && grid [ i ] [ j ] - 1 == grid [ i - 1 ] [ j ] ) { pt = { i - 1 , j } ; path . push_front ( pt ) ; i -- ; } else if ( j > 0 && grid [ i ] [ j ] - 1 == grid [ i ] [ j - 1 ] ) { pt = { i , j - 1 } ; path . push_front ( pt ) ; j -- ; } } return path ; } void findSnakeSequence ( int mat [ M ] [ N ] ) { int lookup [ M ] [ N ] ; memset ( lookup , 0 , sizeof lookup ) ; int max_len = 0 ; int max_row = 0 ; int max_col = 0 ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i j ) { if ( i > 0 && abs ( mat [ i - 1 ] [ j ] - mat [ i ] [ j ] ) == 1 ) { lookup [ i ] [ j ] = max ( lookup [ i ] [ j ] , lookup [ i - 1 ] [ j ] + 1 ) ; if ( max_len < lookup [ i ] [ j ] ) { max_len = lookup [ i ] [ j ] ; max_row = i , max_col = j ; } } if ( j > 0 && abs ( mat [ i ] [ j - 1 ] - mat [ i ] [ j ] ) == 1 ) { lookup [ i ] [ j ] = max ( lookup [ i ] [ j ] , lookup [ i ] [ j - 1 ] + 1 ) ; if ( max_len < lookup [ i ] [ j ] ) { max_len = lookup [ i ] [ j ] ; max_row = i , max_col = j ; } } } } } cout << " Maximum ▁ length ▁ of ▁ Snake ▁ sequence ▁ is : ▁ " << max_len << endl ; list < Point > path = findPath ( lookup , mat , max_row , max_col ) ; cout << " Snake ▁ sequence ▁ is : " ; for ( auto it = path . begin ( ) ; it != path . end ( ) ; it ++ ) cout << endl << mat [ it -> x ] [ it -> y ] << " ▁ ( " << it -> x << " , ▁ " << it -> y << " ) " ; } int main ( ) { int mat [ M ] [ N ] = { { 9 , 6 , 5 , 2 } , { 8 , 7 , 6 , 5 } , { 7 , 3 , 1 , 6 } , { 1 , 1 , 1 , 7 } , } ; findSnakeSequence ( mat ) ; return 0 ; }

Index/key variables: M, N, i, j
Accumulator variables: i, it, j, stdc
Iterator variables: i, it, j
Class/struct names: Point
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWays ( int p , int q , int r , int last ) { if ( p < 0 q < 0 r < 0 ) return 0 ; if ( p == 1 && q == 0 && r == 0 && last == 0 ) return 1 ; if ( p == 0 && q == 1 && r == 0 && last == 1 ) return 1 ; if ( p == 0 && q == 0 && r == 1 && last == 2 ) return 1 ; if ( last == 0 ) return countWays ( p - 1 , q , r , 1 ) + countWays ( p - 1 , q , r , 2 ) ; if ( last == 1 ) return countWays ( p , q - 1 , r , 0 ) + countWays ( p , q - 1 , r , 2 ) ; if ( last == 2 ) return countWays ( p , q , r - 1 , 0 ) + countWays ( p , q , r - 1 , 1 ) ; } int countUtil ( int p , int q , int r ) { } int main ( ) { int p = 1 , q = 1 , r = 1 ; printf ( " % d " , countUtil ( p , q , r ) ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinRec ( int arr [ ] , int i , int sumCalculated , int sumTotal ) { if ( i == 0 ) return abs ( ( sumTotal - sumCalculated ) - sumCalculated ) ; return min ( findMinRec ( arr , i - 1 , sumCalculated + arr [ i - 1 ] , sumTotal ) , findMinRec ( arr , i - 1 , sumCalculated , sumTotal ) ) ; } int findMin ( int arr [ ] , int n ) { int sumTotal = 0 ; for ( int i = 0 ; i < n ; i ++ ) sumTotal += arr [ i ] ; return findMinRec ( arr , n , 0 , sumTotal ) ; } int main ( ) { int arr [ ] = { 3 , 1 , 4 , 2 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " The ▁ minimum ▁ difference ▁ between ▁ two ▁ sets ▁ is ▁ " << findMin ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sumTotal
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int minDifference ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int y = sum / 2 + 1 ; bool dp [ y ] , dd [ y ] ; for ( int i = 0 ; i < y ; i ++ ) { dp [ i ] = dd [ i ] = false ; } dd [ 0 ] = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j + arr [ i ] < y ; j ++ ) { if ( dp [ j ] ) dd [ j + arr [ i ] ] = true ; } for ( int j = 0 ; j < y ; j ++ ) { if ( dd [ j ] ) dp [ j ] = true ; } } for ( int i = y - 1 ; i >= 0 ; i -- ) { if ( dp [ i ] ) return ( sum - 2 * i ) ; } } int main ( ) { int arr [ ] = { 1 , 6 , 11 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " The ▁ Minimum ▁ difference ▁ of ▁ 2 ▁ sets ▁ is ▁ " << minDifference ( arr , n ) << ' ' ; return 0 ; }

Index/key variables: i, j, y
Accumulator variables: i, j, sum
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int countP ( int n , int k ) { int dp [ n + 1 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( int i = 0 ; i <= k ; i ++ ) dp [ 0 ] [ k ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= i ; j ++ ) if ( j == 1 i == j ) dp [ i ] [ j ] = 1 ; else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ; return dp [ n ] [ k ] ; } int main ( ) { cout << countP ( 5 , 2 ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int printCountDP ( int dist ) { int ways [ 3 ] , n = dist ; ways [ 0 ] = 1 ; ways [ 1 ] = 1 ; ways [ 2 ] = 2 ; for ( int i = 3 ; i <= n ; i ++ ) ways [ i % 3 ] = ways [ ( i - 1 ) % 3 ] + ways [ ( i - 2 ) % 3 ] + ways [ ( i - 3 ) % 3 ] ; return ways [ n % 3 ] ; } int main ( ) { int dist = 4 ; cout << printCountDP ( dist ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool has4 ( int x ) ; int countNumbersWith4 ( int n ) { for ( int x = 1 ; x <= n ; x ++ ) result += has4 ( x ) ? 1 : 0 ; return result ; } bool has4 ( int x ) { while ( x != 0 ) { if ( x % 10 == 4 ) return true ; x = x / 10 ; } return false ; } int main ( ) { int n = 328 ; cout << " Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to ▁ " << n << " ▁ that ▁ have ▁ 4 ▁ as ▁ a ▁ a ▁ digit ▁ is ▁ " << countNumbersWith4 ( n ) << endl ; return 0 ; }

Accumulator variables: result, x
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countNumbersWith4 ( int n ) { if ( n < 4 ) return 0 ; int d = log10 ( n ) ; int * a = new int [ d + 1 ] ; a [ 0 ] = 0 , a [ 1 ] = 1 ; for ( int i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 9 + ceil ( pow ( 10 , i - 1 ) ) ; int p = ceil ( pow ( 10 , d ) ) ; int msd = n / p ; if ( msd == 4 ) return ( msd ) * a [ d ] + ( n % p ) + 1 ; if ( msd > 4 ) return ( msd - 1 ) * a [ d ] + p + countNumbersWith4 ( n % p ) ; return ( msd ) * a [ d ] + countNumbersWith4 ( n % p ) ; } int main ( ) { int n = 328 ; cout << " Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to ▁ " << n << " ▁ that ▁ have ▁ 4 ▁ as ▁ a ▁ a ▁ digit ▁ is ▁ " << countNumbersWith4 ( n ) << endl ; return 0 ; }

Index/key variables: d, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <climits>
using namespace std ; int minRemovalsDP ( int arr [ ] , int n ) { int longest_start = -1 , longest_end = 0 ; for ( int start = 0 ; start < n ; start ++ ) { int min = INT_MAX , max = INT_MIN ; for ( int end = start ; end < n ; end ++ ) { int val = arr [ end ] ; if ( val < min ) min = val ; if ( val > max ) max = val ; if ( 2 * min <= max ) break ; if ( end - start > longest_end - longest_start longest_start == -1 ) { longest_start = start ; longest_end = end ; } } } if ( longest_start == -1 ) return n ; return ( n - ( longest_end - longest_start + 1 ) ) ; } int main ( ) { int arr [ ] = { 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minRemovalsDP ( arr , n ) ; return 0 ; }

Index/key variables: end
Accumulator variables: end, start
Iterator variables: end, start
C++ program:
#include <bits/stdc++.h>
using namespace std ; int optimalStrategyOfGame ( int * arr , int n ) { int table [ n ] [ n ] ; for ( int gap = 0 ; gap < n ; ++ gap ) { for ( int i = 0 , j = gap ; j < n ; ++ i , ++ j ) { int x = ( ( i + 2 ) <= j ) ? table [ i + 2 ] [ j ] : 0 ; int y = ( ( i + 1 ) <= ( j - 1 ) ) ? table [ i + 1 ] [ j - 1 ] : 0 ; int z = ( i <= ( j - 2 ) ) ? table [ i ] [ j - 2 ] : 0 ; table [ i ] [ j ] = max ( arr [ i ] + min ( x , y ) , arr [ j ] + min ( y , z ) ) ; } } return table [ 0 ] [ n - 1 ] ; } int main ( ) { int arr1 [ ] = { 8 , 15 , 3 , 7 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; printf ( " % d STRNEWLINE " , optimalStrategyOfGame ( arr1 , n ) ) ; int arr2 [ ] = { 2 , 2 , 2 , 2 } ; n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; printf ( " % d STRNEWLINE " , optimalStrategyOfGame ( arr2 , n ) ) ; int arr3 [ ] = { 20 , 30 , 2 , 2 , 2 , 10 } ; n = sizeof ( arr3 ) / sizeof ( arr3 [ 0 ] ) ; printf ( " % d STRNEWLINE " , optimalStrategyOfGame ( arr3 , n ) ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: stdc
Iterator variables: gap, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSumIS ( int arr [ ] , int n ) { int i , j , max = 0 ; int msis [ n ] ; for ( i = 0 ; i < n ; i ++ ) msis [ i ] = arr [ i ] ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ; return max ; } int main ( ) { int arr [ ] = { 1 , 101 , 2 , 3 , 100 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Sum ▁ of ▁ maximum ▁ sum ▁ increasing ▁ " " subsequence ▁ is ▁ " << maxSumIS ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int _lis ( int arr [ ] , int n , int * max_ref ) { if ( n == 1 ) return 1 ; int res , max_ending_here = 1 ; for ( int i = 1 ; i < n ; i ++ ) { res = _lis ( arr , i , max_ref ) ; if ( arr [ i - 1 ] < arr [ n - 1 ] && res + 1 > max_ending_here ) max_ending_here = res + 1 ; } if ( * max_ref < max_ending_here ) * max_ref = max_ending_here ; return max_ending_here ; } int lis ( int arr [ ] , int n ) { int max = 1 ; _lis ( arr , n , & max ) ; return max ; } int main ( ) { int arr [ ] = { 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Length ▁ of ▁ lis ▁ is ▁ " << lis ( arr , n ) << " STRNEWLINE " ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printLeftPath ( int i , int j , int K ) { if ( K & 1 ) { for ( int p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { cout << i << " ▁ " ; } else { cout << j << " ▁ " ; } } } else { for ( int p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { cout << j << " ▁ " ; } else { cout << i << " ▁ " ; } } } } void printRightPath ( int j , int k , int K ) { if ( K & 1 ) { for ( int p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { cout << k << " ▁ " ; } else { cout << j << " ▁ " ; } } } else { for ( int p = 0 ; p < K ; p ++ ) { if ( p & 1 ) { cout << k << " ▁ " ; } else { cout << j << " ▁ " ; } } } } void constructPalindromicPath ( vector < pair < pair < int , int > , char > > edges , int n , int K ) { vector < vector < char > > adj ( n + 1 , vector < char > ( n + 1 ) ) ; for ( int i = 0 ; i < edges . size ( ) ; i ++ ) { adj [ edges [ i ] . first . first ] [ edges [ i ] . first . second ] = edges [ i ] . second ; } if ( K & 1 ) { cout << " YES " << endl ; for ( int i = 1 ; i <= K + 1 ; i ++ ) { cout << ( i & 1 ) + 1 << " ▁ " ; } return ; } bool found = 0 ; int idx1 , idx2 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( i == j ) { continue ; } if ( adj [ i ] [ j ] == adj [ j ] [ i ] ) { found = 1 ; idx1 = i , idx2 = j ; } } } if ( found ) { cout << " YES " << endl ; for ( int i = 1 ; i <= K + 1 ; i ++ ) { if ( i & 1 ) { cout << idx1 << " ▁ " ; } else { cout << idx2 << " ▁ " ; } } return ; } else { vector < int > mp1 [ n + 1 ] ; vector < int > mp2 [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( i == j ) { continue ; } if ( adj [ i ] [ j ] == '0' ) { mp1 [ i ] . push_back ( j ) ; } else { mp2 [ i ] . push_back ( j ) ; } } } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( j == i ) { continue ; } if ( adj [ i ] [ j ] == '0' ) { if ( mp1 [ j ] . size ( ) ) { int k = mp1 [ j ] [ 0 ] ; if ( k == i k == j ) { continue ; } cout << " YES " << endl ; K -= 2 ; K /= 2 ; printLeftPath ( i , j , K ) ; cout << i << " ▁ " << j << " ▁ " << k << " ▁ " ; printRightPath ( j , k , K ) ; return ; } } } } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( j == i ) { continue ; } if ( adj [ i ] [ j ] == '1' ) { if ( mp1 [ j ] . size ( ) ) { int k = mp1 [ j ] [ 0 ] ; if ( k == i k == j ) { continue ; } cout << " YES " << endl ; K -= 2 ; K /= 2 ; printLeftPath ( i , j , K ) ; cout << i << " ▁ " << j << " ▁ " << k << " ▁ " ; printRightPath ( j , k , K ) ; return ; } } } } } cout << " NO " ; } int main ( ) { int N = 3 , K = 4 ; vector < pair < pair < int , int > , char > > edges = { { { 1 , 2 } , '1' } , { { 1 , 3 } , '1' } , { { 2 , 1 } , '1' } , { { 2 , 3 } , '1' } , { { 3 , 1 } , '0' } , { { 3 , 2 } , '0' } } ; constructPalindromicPath ( edges , N , K ) ; }

Index/key variables: i, j
Accumulator variables: K, i, j, p, stdc
Iterator variables: i, j, p
C++ program:
#include <iostream>
using namespace std ; int checkArray ( int arr [ ] , int N , int k ) { if ( N < 3 ) return -1 ; int i , Sum = 0 , temp = 0 ; for ( i = 0 ; i < N ; i ++ ) Sum += arr [ i ] ; int R = ( k * k + k + 1 ) ; if ( Sum % R != 0 ) return 0 ; int Mid = k * ( Sum / R ) ; for ( i = 1 ; i < N - 1 ; i ++ ) { temp += arr [ i - 1 ] ; if ( arr [ i ] == Mid ) { if ( temp == Mid / k ) return i + 1 ; else return 0 ; } } return 0 ; } int main ( ) { int arr [ ] = { 5 , 1 , 4 , 20 , 6 , 15 , 9 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; cout << checkArray ( arr , N , K ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: Sum, i, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void encodeString ( string str ) { string res = " " ; int small [ 26 ] = { 0 } , capital [ 26 ] = { 0 } , num [ 10 ] = { 0 } ; int n = str . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] >= '0' && str [ i ] <= '9' ) { num [ str [ i ] - 48 ] = i ; } else if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) { small [ str [ i ] - 97 ] = i ; } else if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { capital [ str [ i ] - 65 ] = i ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) && small [ str [ i ] - 97 ] == i ) { int occ = str [ i ] - 96 ; while ( occ -- ) { res += str [ i ] ; } } else if ( ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) && capital [ str [ i ] - 65 ] == i ) { int occ = str [ i ] - 64 ; while ( occ -- ) { res += str [ i ] ; } } else if ( ( str [ i ] >= '0' && str [ i ] <= '9' ) && num [ str [ i ] - 48 ] == i ) { int occ = str [ i ] - 48 ; while ( occ -- ) { res += str [ i ] ; } } else { res += str [ i ] ; } } cout << res ; } int main ( ) { string str = " Ea2 , ▁ 0 , ▁ E " ; encodeString ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, occ, res, stdc
Iterator variables: i