dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; using System . Collections . Generic ; class GFG { static int pageFaults ( int [ ] pages , int n , int capacity ) { HashSet < int > s = new HashSet < int > ( capacity ) ; Dictionary < int , int > indexes = new Dictionary < int , int > ( ) ; int page_faults = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . Count < capacity ) { if ( ! s . Contains ( pages [ i ] ) ) { s . Add ( pages [ i ] ) ; page_faults ++ ; } if ( indexes . ContainsKey ( pages [ i ] ) ) indexes [ pages [ i ] ] = i ; else indexes . Add ( pages [ i ] , i ) ; } else { if ( ! s . Contains ( pages [ i ] ) ) { int lru = int . MaxValue , val = int . MinValue ; foreach ( int itr in s ) { int temp = itr ; if ( indexes [ temp ] < lru ) { lru = indexes [ temp ] ; val = temp ; } } s . Remove ( val ) ; indexes . Remove ( val ) ; s . Add ( pages [ i ] ) ; page_faults ++ ; } if ( indexes . ContainsKey ( pages [ i ] ) ) indexes [ pages [ i ] ] = i ; else indexes . Add ( pages [ i ] , i ) ; } } return page_faults ; } public static void Main ( String [ ] args ) { int [ ] pages = { 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 } ; int capacity = 4 ; Console . WriteLine ( pageFaults ( pages , pages . Length , capacity ) ) ; } }

Index/key variables: i, temp
Accumulator variables: i, page_faults
Iterator variables: i, itr
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void bestpermutation ( List < int > arr , int k , int n ) { Dictionary < int , int > h = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { h . Add ( arr [ i ] , i ) ; } if ( n <= k ) { arr . Sort ( ) ; arr . Reverse ( ) ; } else { for ( int j = n ; j >= 1 ; j -- ) { if ( k > 0 ) { int initial_index = h [ j ] ; int best_index = n - j ; if ( initial_index != best_index ) { h [ j ] = best_index ; int element = arr [ best_index ] ; h [ element ] = initial_index ; int temp = arr [ best_index ] ; arr [ best_index ] = arr [ initial_index ] ; arr [ initial_index ] = temp ; k -- ; } } } } } static void Main ( ) { List < int > arr = new List < int > ( new int [ ] { 3 , 1 , 4 , 2 , 5 } ) ; int k = 10 ; int n = arr . Count ; bestpermutation ( arr , k , n ) ; Console . Write ( " Largest ▁ possible ▁ permutation ▁ after ▁ " + k + " ▁ swaps ▁ is ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: best_index, element, i, initial_index, j
Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static void bestFit ( int [ ] blockSize , int m , int [ ] processSize , int n ) { int [ ] allocation = new int [ n ] ; for ( int i = 0 ; i < allocation . Length ; i ++ ) allocation [ i ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int bestIdx = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { if ( bestIdx == - 1 ) bestIdx = j ; else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ; } } if ( bestIdx != - 1 ) { allocation [ i ] = bestIdx ; blockSize [ bestIdx ] -= processSize [ i ] ; } } Console . WriteLine ( " STRNEWLINE Process ▁ No . TABSYMBOL Process " + " ▁ Size TABSYMBOL Block ▁ no . " ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( " ▁ " + ( i + 1 ) + " TABSYMBOL TABSYMBOL " + processSize [ i ] + " TABSYMBOL TABSYMBOL " ) ; if ( allocation [ i ] != - 1 ) Console . Write ( allocation [ i ] + 1 ) ; else Console . Write ( " Not ▁ Allocated " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ ] blockSize = { 100 , 500 , 200 , 300 , 600 } ; int [ ] processSize = { 212 , 417 , 112 , 426 } ; int m = blockSize . Length ; int n = processSize . Length ; bestFit ( blockSize , m , processSize , n ) ; } }

Index/key variables: bestIdx, i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int bestFit ( int [ ] weight , int n , int c ) { int res = 0 ; int [ ] bin_rem = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j ; int min = c + 1 , bi = 0 ; for ( j = 0 ; j < res ; j ++ ) { if ( bin_rem [ j ] >= weight [ i ] && bin_rem [ j ] - weight [ i ] < min ) { bi = j ; min = bin_rem [ j ] - weight [ i ] ; } } if ( min == c + 1 ) { bin_rem [ res ] = c - weight [ i ] ; res ++ ; } else bin_rem [ bi ] -= weight [ i ] ; } return res ; } public static void Main ( String [ ] args ) { int [ ] weight = { 2 , 5 , 4 , 7 , 1 , 3 , 8 } ; int c = 10 ; int n = weight . Length ; Console . Write ( " Number ▁ of ▁ bins ▁ required ▁ in ▁ Best ▁ Fit ▁ : ▁ " + bestFit ( weight , n , c ) ) ; } }

Index/key variables: bi, i, j, n, res
Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int worstFit ( int [ ] weight , int n , int c ) { int res = 0 ; int [ ] bin_rem = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j ; int mx = - 1 , wi = 0 ; for ( j = 0 ; j < res ; j ++ ) { if ( bin_rem [ j ] >= weight [ i ] && bin_rem [ j ] - weight [ i ] > mx ) { wi = j ; mx = bin_rem [ j ] - weight [ i ] ; } } if ( mx == - 1 ) { bin_rem [ res ] = c - weight [ i ] ; res ++ ; } bin_rem [ wi ] -= weight [ i ] ; } return res ; } public static void Main ( String [ ] args ) { int [ ] weight = { 2 , 5 , 4 , 7 , 1 , 3 , 8 } ; int c = 10 ; int n = weight . Length ; Console . Write ( " Number ▁ of ▁ bins ▁ required ▁ in ▁ Worst ▁ Fit ▁ : ▁ " + worstFit ( weight , n , c ) ) ; } }

Index/key variables: i, j, n, res, wi
Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int getMax ( int [ ] arr , int n ) { int result = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > result ) result = arr [ i ] ; return result ; } static bool isPossible ( int time , int K , int [ ] job , int n ) { int cnt = 1 ; int curr_time = 0 ; for ( int i = 0 ; i < n ; ) { if ( curr_time + job [ i ] > time ) { curr_time = 0 ; cnt ++ ; } else { curr_time += job [ i ] ; i ++ ; } } return ( cnt <= K ) ; } static int findMinTime ( int K , int T , int [ ] job , int n ) { int end = 0 , start = 0 ; for ( int i = 0 ; i < n ; ++ i ) end += job [ i ] ; int ans = end ; int job_max = getMax ( job , n ) ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( mid >= job_max && isPossible ( mid , K , job , n ) ) { ans = Math . Min ( ans , mid ) ; end = mid - 1 ; } else start = mid + 1 ; } return ( ans * T ) ; } public static void Main ( ) { int [ ] job = { 10 , 7 , 8 , 12 , 6 , 8 } ; int n = job . Length ; int k = 4 , T = 5 ; Console . WriteLine ( findMinTime ( k , T , job , n ) ) ; } }

Index/key variables: i
Accumulator variables: cnt, curr_time, end, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int LongestOddEvenSubarray ( int [ ] A , int N ) { int [ ] dp = new int [ N ] ; dp [ 0 ] = 1 ; int ans = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( ( A [ i ] % 2 == 0 && A [ i - 1 ] % 2 == 0 ) || ( A [ i ] % 2 != 0 && A [ i - 1 ] % 2 != 0 ) ) { dp [ i ] = dp [ i - 1 ] + 1 ; } else dp [ i ] = 1 ; } for ( int i = 0 ; i < N ; i ++ ) ans = Math . Max ( ans , dp [ i ] ) ; return ans ; } public static void Main ( ) { int [ ] A = { 2 , 5 , 7 , 2 , 4 , 6 , 8 , 3 } ; int N = A . Length ; Console . Write ( LongestOddEvenSubarray ( A , N ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int totalSubarrays ( int [ ] arr , int n , int k ) { int ans = 0 , i = 0 ; while ( i < n ) { if ( arr [ i ] > k ) { i ++ ; continue ; } int count = 0 ; while ( i < n && arr [ i ] <= k ) { i ++ ; count ++ ; } ans += ( ( count * ( count + 1 ) ) / 2 ) ; } return ans ; } static int countSubarrays ( int [ ] arr , int n , int k ) { int count1 = totalSubarrays ( arr , n , k - 1 ) ; int count2 = totalSubarrays ( arr , n , k ) ; int ans = count2 - count1 ; return ans ; } static void Main ( ) { int n = 4 , k = 3 ; int [ ] arr = { 2 , 1 , 3 , 4 } ; Console . WriteLine ( countSubarrays ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: ans, count, i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int maxSumWO3Consec ( int [ ] A , int N ) { if ( N == 1 ) return A [ 0 ] ; if ( N == 2 ) return A [ 0 ] + A [ 1 ] ; int third = A [ 0 ] ; int second = third + A [ 1 ] ; int first = Math . Max ( second , A [ 1 ] + A [ 2 ] ) ; int sum = Math . Max ( Math . Max ( third , second ) , first ) ; for ( int i = 3 ; i < N ; i ++ ) { sum = Math . Max ( Math . Max ( first , second + A [ i ] ) , third + A [ i ] + A [ i - 1 ] ) ; third = second ; second = first ; first = sum ; } return sum ; } public static void Main ( ) { int [ ] A = { 3000 , 2000 , 1000 , 3 , 10 } ; int N = A . Length ; int res = maxSumWO3Consec ( A , N ) ; Console . Write ( res ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int findMinOperations ( int n ) { int i ; int [ ] dp = new int [ n + 1 ] ; for ( i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] = 999999 ; } dp [ 2 ] = 0 ; for ( i = 2 ; i < n + 1 ; i ++ ) { if ( i * 5 <= n ) { dp [ i * 5 ] = Math . Min ( dp [ i * 5 ] , dp [ i ] + 1 ) ; } if ( i + 3 <= n ) { dp [ i + 3 ] = Math . Min ( dp [ i + 3 ] , dp [ i ] + 1 ) ; } } return dp [ n ] ; } public static void Main ( ) { int n = 28 ; int m = findMinOperations ( n ) ; if ( m != 9999 ) Console . Write ( m ) ; else Console . Write ( - 1 ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int countSortedArrays ( int n , int m ) { int [ ] dp = new int [ ( m + 1 ) ] ; dp [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { dp [ j ] = dp [ j - 1 ] + dp [ j ] ; } } return dp [ m ] ; } public static void Main ( ) { int n = 2 , m = 3 ; Console . WriteLine ( countSortedArrays ( n , m ) ) ; } }

Index/key variables: j, m
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int getValue ( int [ ] arr , int N ) { int [ ] dp = new int [ N ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < N ; i ++ ) { int min = arr [ i ] ; int max = arr [ i ] ; for ( int j = i ; j >= 0 ; j -- ) { min = Math . Min ( arr [ j ] , min ) ; max = Math . Max ( arr [ j ] , max ) ; dp [ i ] = Math . Max ( dp [ i ] , max - min + ( ( j >= 1 ) ? dp [ j - 1 ] : 0 ) ) ; } } return dp [ N - 1 ] ; } static public void Main ( ) { int [ ] arr = { 8 , 1 , 7 , 9 , 2 } ; int N = arr . Length ; Console . Write ( getValue ( arr , N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int count0 ( string s ) { int count = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == '0' ) { count ++ ; } } return count ; } static int solve ( List < string > vec , int A , int B , int idx ) { if ( idx == vec . Count A + B == 0 ) { return 0 ; } int zero = count0 ( vec [ idx ] ) ; int one = vec [ idx ] . Length - zero ; int inc = 0 ; if ( zero <= A && one <= B ) { inc = 1 + solve ( vec , A - zero , B - one , idx + 1 ) ; } int exc = solve ( vec , A , B , idx + 1 ) ; return Math . Max ( inc , exc ) ; } static int MaxSubsetlength ( List < string > arr , int A , int B ) { return solve ( arr , A , B , 0 ) ; } public static void Main ( ) { List < string > arr = new List < string > { "1" , "0" , "10" } ; int A = 1 , B = 1 ; Console . WriteLine ( MaxSubsetlength ( arr , A , B ) ) ; } }

Index/key variables: i, idx
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static bool isUnique ( string s ) { HashSet < char > set = new HashSet < char > ( ) ; foreach ( char c in s ) set . Add ( c ) ; return set . Count == 1 ; } static int maxScore ( string s , int [ ] a ) { int n = s . Length ; if ( n == 0 ) return 0 ; if ( n == 1 ) return a [ 0 ] ; int mx = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { string sub = s . Substring ( i , j + 1 - i ) ; if ( isUnique ( sub ) ) mx = Math . Max ( mx , a [ sub . Length - 1 ] + maxScore ( s . Substring ( 0 , i ) + s . Substring ( j + 1 ) , a ) ) ; } } return mx ; } static void Main ( ) { string s = "011" ; int [ ] a = { 1 , 3 , 1 } ; Console . Write ( maxScore ( s , a ) ) ; } }

Accumulator variables: i, j
Iterator variables: c, i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static Dictionary < string , int > dp = new Dictionary < string , int > ( ) ; static int maxScore ( string s , int [ ] a ) { if ( dp . ContainsKey ( s ) ) return dp [ s ] ; int n = s . Length ; if ( n == 0 ) return 0 ; if ( n == 1 ) return a [ 0 ] ; int head = 0 ; int mx = - 1 ; while ( head < n ) { int tail = head ; while ( tail < n ) { if ( s [ tail ] != s [ head ] ) { head = tail ; break ; } string sub = s . Substring ( head , tail + 1 - head ) ; mx = Math . Max ( mx , a [ sub . Length - 1 ] + maxScore ( s . Substring ( 0 , head ) + s . Substring ( tail + 1 , s . Length - tail - 1 ) , a ) ) ; tail += 1 ; } if ( tail == n ) break ; } dp . Add ( s , mx ) ; return mx ; } static public void Main ( ) { string s = " abb " ; int [ ] a = { 1 , 3 , 1 } ; Console . WriteLine ( ( maxScore ( s , a ) ) ) ; } }

Index/key variables: head, s, tail
Accumulator variables: tail
Class/struct names: GFG
C# program:
using System ; class GFG { static int size = 100 ; static int [ , ] ans = new int [ size , size ] ; static void initialize ( ) { for ( int i = 0 ; i < size ; i ++ ) { for ( int j = 0 ; j < size ; j ++ ) { ans [ i , j ] = 0 ; } } } static int numberOfUniqueOutcomes ( int n , int s ) { if ( s < n ) ans [ n , s ] = 0 ; else if ( n == 1 n == s ) ans [ n , s ] = 1 ; else if ( ans [ n , s ] == 0 ) { ans [ n , s ] = numberOfUniqueOutcomes ( n - 1 , s - 1 ) + numberOfUniqueOutcomes ( n - 1 , s - 2 ) ; } return ans [ n , s ] ; } public static void Main ( string [ ] args ) { initialize ( ) ; int N = 5 , S = 8 ; Console . WriteLine ( numberOfUniqueOutcomes ( N , S ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static void printMinimumRemovals ( string str , string X ) { int N = str . Length ; int M = X . Length ; int [ , ] dp = new int [ N , M ] ; for ( int j = 0 ; j < M ; j ++ ) { if ( str [ 0 ] == X [ j ] ) { dp [ 0 , j ] = 1 ; } } for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( str [ i ] == X [ j ] ) { dp [ i , j ] = dp [ i - 1 , j ] + 1 ; if ( j != 0 ) dp [ i , j ] = Math . Min ( dp [ i , j ] , dp [ i - 1 , j - 1 ] ) ; } else { dp [ i , j ] = dp [ i - 1 , j ] ; } } } Console . WriteLine ( dp [ N - 1 , M - 1 ] ) ; } public static void Main ( String [ ] args ) { string str = " btagd " ; string X = " bad " ; printMinimumRemovals ( str , X ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int maxSubarraySum ( int [ ] sum , int k , int row ) { int curSum = 0 , curMax = Int32 . MinValue ; HashSet < int > sumSet = new HashSet < int > ( ) ; sumSet . Add ( 0 ) ; for ( int r = 0 ; r < row ; ++ r ) { curSum += sum [ r ] ; List < int > list = new List < int > ( ) ; list . AddRange ( sumSet ) ; int it = list . LastIndexOf ( curSum - k ) ; if ( it > - 1 ) { curMax = Math . Max ( curMax , curSum - it ) ; } sumSet . Add ( curSum ) ; } return curMax ; } static void maxSumSubmatrix ( int [ , ] matrix , int k ) { int row = matrix . GetLength ( 0 ) ; int col = matrix . GetLength ( 1 ) ; int ret = Int32 . MinValue ; for ( int i = 0 ; i < col ; ++ i ) { int [ ] sum = new int [ row ] ; for ( int j = i ; j < col ; ++ j ) { for ( int r = 0 ; r < row ; ++ r ) { sum [ r ] += matrix [ r , j ] ; } int curMax = maxSubarraySum ( sum , k , row ) ; ret = Math . Max ( ret , curMax ) ; } } Console . Write ( ret ) ; } static public void Main ( ) { int [ , ] matrix = { { 1 , 0 , 1 } , { 0 , - 2 , 3 } } ; int K = 2 ; maxSumSubmatrix ( matrix , K ) ; } }

Index/key variables: r, row
Accumulator variables: curSum
Iterator variables: i, j, r
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void binaryStrings ( int N ) { int [ ] dp = new int [ N + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; int [ ] power = new int [ N + 1 ] ; power [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { power [ i ] = 2 * power [ i - 1 ] ; } for ( int i = 2 ; i <= N ; i ++ ) { dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + power [ i - 2 ] ; } Console . WriteLine ( dp [ N ] ) ; } public static void Main ( ) { int N = 12 ; binaryStrings ( N ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int kadane ( List < int > v ) { int currSum = 0 ; int maxSum = int . MinValue ; for ( int i = 0 ; i < ( int ) v . Count ; i ++ ) { currSum += v [ i ] ; if ( currSum > maxSum ) { maxSum = currSum ; } if ( currSum < 0 ) { currSum = 0 ; } } return maxSum ; } static void maxSubmatrixSum ( int [ , ] A ) { int r = A . GetLength ( 0 ) ; int c = A . GetLength ( 1 ) ; int [ , ] prefix = new int [ r , c ] ; for ( int i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) { prefix [ i , j ] = 0 ; } } for ( int i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) { if ( j == 0 ) prefix [ i , j ] = A [ i , j ] ; else prefix [ i , j ] = A [ i , j ] + prefix [ i , j - 1 ] ; } } int maxSum = int . MinValue ; for ( int i = 0 ; i < c ; i ++ ) { for ( int j = i ; j < c ; j ++ ) { List < int > v = new List < int > ( ) ; for ( int k = 0 ; k < r ; k ++ ) { int el = 0 ; if ( i == 0 ) el = prefix [ k , j ] ; else el = prefix [ k , j ] - prefix [ k , i - 1 ] ; v . Add ( el ) ; } maxSum = Math . Max ( maxSum , kadane ( v ) ) ; } } Console . Write ( maxSum + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ , ] matrix = { { 0 , - 2 , - 7 , 0 } , { 9 , 2 , - 6 , 2 } , { - 4 , 1 , - 4 , 1 } , { - 1 , 8 , 0 , - 2 } } ; maxSubmatrixSum ( matrix ) ; } }

Index/key variables: i
Accumulator variables: currSum, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int minCost ( List < List < int > > costs , int N ) { if ( N == 0 ) return 0 ; List < int > temp = new List < int > ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) temp . Add ( 0 ) ; List < List < int > > dp = new List < List < int > > ( ) ; for ( int i = 0 ; i < N ; i ++ ) dp . Add ( temp ) ; dp [ 0 ] [ 0 ] = costs [ 0 ] [ 0 ] ; dp [ 0 ] [ 1 ] = costs [ 0 ] [ 1 ] ; dp [ 0 ] [ 2 ] = costs [ 0 ] [ 2 ] ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = Math . Min ( dp [ i - 1 ] [ 1 ] , dp [ i - 1 ] [ 2 ] ) + costs [ i ] [ 0 ] ; dp [ i ] [ 1 ] = Math . Min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 2 ] ) + costs [ i ] [ 1 ] ; dp [ i ] [ 2 ] = Math . Min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + costs [ i ] [ 2 ] ; } return ( Math . Min ( dp [ N - 1 ] [ 0 ] , Math . Min ( dp [ N - 1 ] [ 1 ] , dp [ N - 1 ] [ 2 ] ) ) ) - 11 ; } public static void Main ( ) { List < List < int > > costs = new List < List < int > > ( ) ; costs . Add ( new List < int > ( ) { 14 , 2 , 11 } ) ; costs . Add ( new List < int > ( ) { 11 , 14 , 5 } ) ; costs . Add ( new List < int > ( ) { 14 , 3 , 10 } ) ; int N = 3 ; Console . WriteLine ( ( int ) ( minCost ( costs , N ) ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int [ , ] dp = new int [ 2001 , 2001 ] ; static int solve ( int [ ] A , int i , int sum , int N ) { int res = 2001 ; if ( sum < 0 || ( i == N && sum != 0 ) ) { return 2001 ; } if ( sum == 0 i >= N ) { return dp [ i , sum ] = 0 ; } if ( dp [ i , sum ] != - 1 ) { return dp [ i , sum ] ; } res = Math . Min ( solve ( A , i + 1 , sum - A [ i ] , N ) + 1 , solve ( A , i + 1 , sum , N ) ) ; return dp [ i , sum ] = res ; } static void minOp ( int [ ] A , int N ) { int sum = 0 ; foreach ( int it in A ) { sum += it ; } if ( sum % 2 == 0 ) { for ( int i = 0 ; i < 2001 ; i ++ ) { for ( int j = 0 ; j < 2001 ; j ++ ) { dp [ i , j ] = - 1 ; } } int ans = solve ( A , 0 , sum / 2 , N ) ; if ( ans < 0 ans > N ) { Console . Write ( " - 1" + " STRNEWLINE " ) ; } else { Console . Write ( ans + " STRNEWLINE " ) ; } } else { Console . Write ( " - 1" + " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 3 , 1 , 4 } ; int N = A . Length ; minOp ( A , N ) ; } }

Index/key variables: i
Accumulator variables: i, j, sum
Iterator variables: i, it, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static int [ , , ] dp = new int [ 101 , 101 , 1001 ] ; static int countAverage ( int n , int K , int [ ] arr ) { dp [ 0 , 0 , 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int k = 0 ; k < n ; k ++ ) { for ( int s = 0 ; s <= 100 ; s ++ ) { dp [ i + 1 , k + 1 , s + arr [ i ] ] += dp [ i , k , s ] ; dp [ i + 1 , k , s ] += dp [ i , k , s ] ; } } } int cnt = 0 ; for ( int j = 1 ; j <= n ; j ++ ) { cnt += dp [ n , j , K * j ] ; } return cnt ; } public static void Main ( String [ ] args ) { int [ ] arr = { 9 , 7 , 8 , 9 } ; int K = 8 ; int N = arr . Length ; Console . Write ( countAverage ( N , K , arr ) ) ; } }

Index/key variables: i
Accumulator variables: cnt, i, j, k, s
Iterator variables: i, j, k, s
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void numberofpairs ( List < List < int > > v , int k ) { int n = v . Count ; if ( n % 2 == 1 ) { Console . Write ( 0 ) ; return ; } int ans = 0 ; int [ , ] dp = new int [ k , 2 ] ; for ( int i = 0 ; i < k ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { dp [ i , j ] = 0 ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( ( i + j ) % 2 == 0 ) dp [ v [ i ] [ j ] - 1 , 0 ] ++ ; else dp [ v [ i ] [ j ] - 1 , 1 ] ++ ; } } for ( int i = 0 ; i < k ; i ++ ) { for ( int j = i + 1 ; j < k ; j ++ ) { ans += dp [ i , 0 ] * dp [ j , 1 ] ; ans += dp [ i , 1 ] * dp [ j , 0 ] ; } } Console . Write ( ans ) ; } static void Main ( ) { List < List < int > > mat = new List < List < int > > ( ) ; mat . Add ( new List < int > ( new int [ ] { 1 , 2 } ) ) ; mat . Add ( new List < int > ( new int [ ] { 3 , 4 } ) ) ; int K = 4 ; numberofpairs ( mat , K ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , , , ] dp = new int [ 50 , 50 , 50 , 50 ] ; static int FindMaxS ( int X , int Y , int Z , int n , int [ ] A , int [ ] B , int [ ] C ) { if ( X < 0 Y < 0 Z < 0 ) return Int32 . MinValue ; if ( n < 0 ) return 0 ; if ( dp [ n , X , Y , Z ] != - 1 ) { return dp [ n , X , Y , Z ] ; } int ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 , A , B , C ) ; int ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 , A , B , C ) ; int co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 , A , B , C ) ; int no = FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ; int maximum = Math . Max ( ch , Math . Max ( ca , Math . Max ( co , no ) ) ) ; return dp [ n , X , Y , Z ] = maximum ; } public static void Main ( string [ ] args ) { int X = 1 ; int Y = 1 ; int Z = 1 ; int [ ] A = { 10 , 0 , 5 } ; int [ ] B = { 5 , 10 , 0 } ; int [ ] C = { 0 , 5 , 10 } ; int n = B . Length ; for ( int i = 0 ; i < 50 ; i ++ ) for ( int j = 0 ; j < 50 ; j ++ ) for ( int k = 0 ; k < 50 ; k ++ ) for ( int l = 0 ; l < 50 ; l ++ ) dp [ i , j , k , l ] = - 1 ; Console . Write ( FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ) ; } }

Index/key variables: n
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Class/struct names: GFG