dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int sumArray ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } return sum ; } static int maximizeSum ( int [ ] arr , int n , int k ) { Array . Sort ( arr ) ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( k != 0 && arr [ i ] < 0 ) { arr [ i ] *= - 1 ; k -- ; continue ; } break ; } if ( i == n ) i -- ; if ( k == 0 k % 2 == 0 ) { return sumArray ( arr , n ) ; } if ( i != 0 && Math . Abs ( arr [ i ] ) >= Math . Abs ( arr [ i - 1 ] ) ) { i -- ; } arr [ i ] *= - 1 ; return sumArray ( arr , n ) ; } static public void Main ( ) { int n = 5 ; int k = 4 ; int [ ] arr = { - 3 , - 2 , - 1 , 5 , 6 } ; Console . Write ( maximizeSum ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, k, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int firstFit ( int [ ] weight , int n , int c ) { int res = 0 ; int [ ] bin_rem = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < res ; j ++ ) { if ( bin_rem [ j ] >= weight [ i ] ) { bin_rem [ j ] = bin_rem [ j ] - weight [ i ] ; break ; } } if ( j == res ) { bin_rem [ res ] = c - weight [ i ] ; res ++ ; } } 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 ▁ First ▁ Fit ▁ : ▁ " + firstFit ( weight , n , c ) ) ; } }

Index/key variables: 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 maxDiffSum ( int [ ] arr , int n ) { int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int maxVal = arr [ i ] , minVal = arr [ i ] ; for ( int j = i ; j >= 0 ; j -- ) { minVal = Math . Min ( minVal , arr [ j ] ) ; maxVal = Math . Max ( maxVal , arr [ j ] ) ; if ( j - 1 >= 0 ) dp [ i ] = Math . Max ( dp [ i ] , maxVal - minVal + dp [ j - 1 ] ) ; else dp [ i ] = Math . Max ( dp [ i ] , maxVal - minVal ) ; } } return dp [ n - 1 ] ; } public static void Main ( ) { int [ ] arr = { 8 , 1 , 7 , 9 , 2 } ; int N = arr . Length ; Console . WriteLine ( maxDiffSum ( arr , N ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { public static int MOD = 1000000007 ; public static long modPow ( long x , long y ) { long r = 1 , a = x ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) { r = ( r * a ) % MOD ; } a = ( a * a ) % MOD ; y /= 2 ; } return r ; } public static long modInverse ( long x ) { return modPow ( x , MOD - 2 ) ; } public static long modDivision ( long p , long q ) { return ( p * modInverse ( q ) ) % MOD ; } public static long C ( long n , int k ) { if ( k > n ) { return 0 ; } long p = 1 , q = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { q = ( q * i ) % MOD ; p = ( p * ( n - i + 1 ) ) % MOD ; } return modDivision ( p , q ) ; } public static long countArrays ( int N , int K ) { long res = 1 ; for ( int p = 2 ; p <= K / p ; p ++ ) { int c = 0 ; while ( K % p == 0 ) { K /= p ; c ++ ; } res = ( res * C ( N - 1 + c , c ) ) % MOD ; } if ( N > 1 ) { res = ( res * N ) % MOD ; } return res ; } static public void Main ( ) { int N = 3 , K = 5 ; Console . WriteLine ( countArrays ( N , K ) ) ; } }

Accumulator variables: K, c, i, p, y
Iterator variables: i, p
Class/struct names: GFG
C# program:
using System ; public class GFG { public static int minSessions ( int [ ] codeTime , int [ , ] dp , int ones , int n , int mask , int currTime , int WorkingSessionTime ) { if ( currTime > WorkingSessionTime ) return Int32 . MaxValue ; if ( mask == ones ) return 1 ; if ( dp [ mask , currTime ] != - 1 ) return dp [ mask , currTime ] ; int ans = Int32 . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( mask & ( 1 << i ) ) == 0 ) { int inc = minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , currTime + codeTime [ i ] , WorkingSessionTime ) ; int inc_next = 1 + minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , codeTime [ i ] , WorkingSessionTime ) ; ans = Math . Min ( ans , Math . Min ( inc , inc_next ) ) ; } } return dp [ mask , currTime ] = ans ; } public static int solve ( int [ ] codeTime , int n , int WorkingSessionTime ) { int [ , ] dp = new int [ ( 1 << 14 ) , 15 ] ; for ( int i = 0 ; i < 1 << 14 ; i ++ ) { for ( int j = 0 ; j < 15 ; j ++ ) { dp [ i , j ] = - 1 ; } } int ones = ( 1 << n ) - 1 ; int ans = minSessions ( codeTime , dp , ones , n , 0 , 0 , WorkingSessionTime ) ; if ( WorkingSessionTime < 6 ) { if ( ans % 2 == 0 ) ans = ans / 2 ; else ans = ( ans / 2 ) + 1 ; } return ans ; } static public void Main ( ) { int [ ] codeTime = { 1 , 2 , 3 , 1 , 1 , 3 } ; int n = codeTime . Length ; int WorkingSessionTime = 4 ; Console . WriteLine ( solve ( codeTime , n , WorkingSessionTime ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MAXN = 100005 ; static int [ , ] dp = new int [ MAXN , 10 ] ; static int solve ( int len , int gap ) { if ( dp [ len , gap ] != - 1 ) { return dp [ len , gap ] ; } if ( len == 0 gap == 0 ) { return 1 ; } if ( gap < 0 ) { return 0 ; } int ans = 0 ; for ( int i = 0 ; i <= gap ; i ++ ) { ans += solve ( len - 1 , gap - i ) ; } return dp [ len , gap ] = ans ; } static int countValidStrings ( string S ) { for ( int i = 0 ; i < MAXN ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { dp [ i , j ] = - 1 ; } } int N = S . Length ; int L = 1 , R = 9 ; int cnt = 0 ; int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ? ' ) { R = ( int ) S [ i ] - 48 ; ans *= solve ( cnt , R - L ) ; L = R ; R = 9 ; cnt = 0 ; } else { cnt ++ ; } } ans *= solve ( cnt , R - L ) ; return ans ; } public static void Main ( ) { string S = "1 ? ? ?2" ; Console . Write ( countValidStrings ( S ) ) ; } }

Index/key variables: i
Accumulator variables: ans, cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static string KthString ( int A , int B , long K , int [ , ] dp ) { if ( A == 0 ) { string ans = " " ; for ( int i = 0 ; i < B ; i ++ ) { ans += '1' ; } return ans ; } if ( B == 0 ) { string ans = " " ; for ( int i = 0 ; i < A ; i ++ ) { ans += '0' ; } return ans ; } if ( K <= dp [ A - 1 , B ] ) { return "0" + KthString ( A - 1 , B , K , dp ) ; } else { return "1" + KthString ( A , B - 1 , K - dp [ A - 1 , B ] , dp ) ; } } static int KthStringUtil ( int A , int B , int K ) { int [ , ] dp = new int [ A + 1 , B + 1 ] ; dp [ 0 , 0 ] = 1 ; for ( int i = 0 ; i <= A ; ++ i ) { for ( int j = 0 ; j <= B ; ++ j ) { if ( i > 0 ) { dp [ i , j ] += dp [ i - 1 , j ] ; } if ( j > 0 ) { dp [ i , j ] += dp [ i , j - 1 ] ; } } } Console . WriteLine ( KthString ( A , B , K , dp ) ) ; return 0 ; } public static void Main ( string [ ] args ) { int A = 3 , B = 3 , K = 7 ; KthStringUtil ( A , B , K ) ; } }

Accumulator variables: ans, i
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int combinationsPossible ( int N , int idx , int prev , int val , int K , int [ , , ] dp ) { if ( val > K ) { return 0 ; } if ( dp [ val , idx , prev ] != - 1 ) { return dp [ val , idx , prev ] ; } if ( idx == N - 1 ) { if ( val == K ) { return 1 ; } return 0 ; } int ans = 0 ; if ( prev == 1 ) { ans += combinationsPossible ( N , idx + 1 , 1 , val + 1 , K , dp ) ; ans += combinationsPossible ( N , idx + 1 , 0 , val , K , dp ) ; } else { ans += combinationsPossible ( N , idx + 1 , 1 , val , K , dp ) ; ans += combinationsPossible ( N , idx + 1 , 0 , val , K , dp ) ; } return dp [ val , idx , prev ] = ans ; } public static void Main ( ) { int N = 5 ; int K = 3 ; int [ , , ] dp = new int [ K + 1 , N + 1 , 2 ] ; for ( int i = 0 ; i < K + 1 ; i ++ ) for ( int j = 0 ; j < N + 1 ; j ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i , j , l ] = - 1 ; Console . WriteLine ( combinationsPossible ( N , 0 , 0 , 0 , K , dp ) + combinationsPossible ( N , 0 , 1 , 0 , K , dp ) ) ; } }

Accumulator variables: ans, i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; public class GFG { static int countOfWays ( int [ ] arr , int N ) { int [ ] pre = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { pre [ i + 1 ] = pre [ i ] + arr [ i ] ; } int [ , ] dp = new int [ N + 2 , N + 2 ] ; dp [ 1 , 0 ] ++ ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N ; j >= 1 ; j -- ) { dp [ j + 1 , pre [ i + 1 ] % ( j + 1 ) ] += dp [ j , pre [ i + 1 ] % j ] ; if ( i == N - 1 ) { ans += dp [ j , pre [ i + 1 ] % j ] ; } } } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int N = arr . Length ; Console . WriteLine ( countOfWays ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static readonly int MAX = 500 ; static int [ , ] lookup = new int [ MAX , MAX ] ; class Query { public int L , R ; public Query ( int l , int r ) { L = l ; R = r ; } } ; static void preprocess ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) lookup [ i , 0 ] = i ; for ( int j = 1 ; ( 1 << j ) <= n ; j ++ ) { for ( int i = 0 ; ( i + ( 1 << j ) - 1 ) < n ; i ++ ) { if ( arr [ lookup [ i , j - 1 ] ] < arr [ lookup [ i + ( 1 << ( j - 1 ) ) , j - 1 ] ] ) lookup [ i , j ] = lookup [ i , j - 1 ] ; else lookup [ i , j ] = lookup [ i + ( 1 << ( j - 1 ) ) , j - 1 ] ; } } } static int query ( int [ ] arr , int L , int R ) { int j = ( int ) Math . Log ( R - L + 1 ) ; if ( arr [ lookup [ L , j ] ] <= arr [ lookup [ R - ( 1 << j ) + 1 , j ] ] ) return arr [ lookup [ L , j ] ] ; else return arr [ lookup [ R - ( 1 << j ) + 1 , j ] ] ; } static void Min_difference ( int [ ] arr , int n , Query [ ] q , int m ) { preprocess ( arr , n ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; Console . WriteLine ( query ( arr , L , R - 1 ) ) ; } } static void minimumDifference ( int [ ] arr , Query [ ] q , int N , int m ) { int [ ] diff = new int [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) diff [ i ] = Math . Abs ( arr [ i ] - arr [ i + 1 ] ) ; Min_difference ( diff , N - 1 , q , m ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 6 , 1 , 8 , 3 , 4 } ; int N = arr . Length ; Query [ ] Q = { new Query ( 0 , 3 ) , new Query ( 1 , 5 ) , new Query ( 4 , 5 ) } ; int M = Q . Length ; minimumDifference ( arr , Q , N , M ) ; } }

Index/key variables: N, i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Query
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MOD = 1000000007 ; static int numTilings ( int N ) { if ( N < 3 ) { return N ; } int [ , ] dp = new int [ N + 1 , 3 ] ; dp [ 0 , 0 ] = dp [ 1 , 0 ] = 1 ; dp [ 1 , 1 ] = dp [ 1 , 2 ] = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { dp [ i , 0 ] = ( dp [ i - 1 , 0 ] + dp [ i - 2 , 0 ] + dp [ i - 2 , 1 ] + dp [ i - 2 , 2 ] ) % MOD ; dp [ i , 1 ] = ( dp [ i - 1 , 0 ] + dp [ i - 1 , 2 ] ) % MOD ; dp [ i , 2 ] = ( dp [ i - 1 , 0 ] + dp [ i - 1 , 1 ] ) % MOD ; } return dp [ N , 0 ] ; } public static void Main ( ) { int N = 3 ; Console . Write ( numTilings ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static Dictionary < int , int > dp = new Dictionary < int , int > ( ) ; static int countStrings ( int N ) { if ( N == 1 ) return 0 ; if ( dp . ContainsKey ( N ) ) return dp [ N ] ; int ret = 0 ; for ( int div = 1 ; div <= Math . Sqrt ( N ) ; div ++ ) { if ( N % div == 0 ) { ret += ( 1 << div ) - countStrings ( div ) ; int div2 = N / div ; if ( div2 != div && div != 1 ) ret += ( 1 << div2 ) - countStrings ( div2 ) ; } } dp [ N ] = ret ; return ret ; } public static void Main ( ) { int N = 6 ; Console . Write ( countStrings ( N ) ) ; } }

Index/key variables: N
Accumulator variables: div, ret
Iterator variables: div
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int mod = 1000000007 ; static void countOfNumbers ( int N ) { int ans = 1 ; for ( int index = 1 ; index <= N ; ++ index ) { int choices = 0 ; for ( int digit = 1 ; digit <= 9 ; ++ digit ) { if ( index % digit == 0 ) { ++ choices ; } } ans = ( ans * choices ) % mod ; } Console . Write ( ans ) ; } public static void Main ( ) { int N = 5 ; countOfNumbers ( N ) ; } }

Iterator variables: digit, index
Class/struct names: GFG
C# program:
using System ; class GFG { public static int dfs ( int [ ] arr , int left , int K ) { int q = 0 ; if ( left == 0 ) { for ( int i = 1 ; i < K ; ++ i ) { if ( arr [ i ] > 0 ) { arr [ i ] -- ; q = Math . Max ( q , 1 + dfs ( arr , K - i , K ) ) ; arr [ i ] ++ ; } } } else { for ( int i = 1 ; i < K ; ++ i ) { if ( arr [ i ] > 0 ) { arr [ i ] -- ; int nleft = ( i <= left ? left - i : K + left - i ) ; q = Math . Max ( q , dfs ( arr , nleft , K ) ) ; arr [ i ] ++ ; } } } return q ; } public static int maxGroups ( int K , int [ ] arr ) { int [ ] V = new int [ K ] ; foreach ( int x in arr ) V [ x % K ] ++ ; int ans = V [ 0 ] + dfs ( V , 0 , K ) ; return ans ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; int K = 3 ; Console . WriteLine ( maxGroups ( K , arr ) ) ; } }

Index/key variables: K, i
Iterator variables: i, x
Class/struct names: GFG
C# program:
using System ; class GFG { static void findMaxJumps ( int [ ] arr , int N ) { int [ ] dp = new int [ N ] ; int ans = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { dp [ i ] = arr [ i ] ; int j = i + arr [ i ] ; if ( j < N ) { dp [ i ] = dp [ i ] + dp [ j ] ; } ans = Math . Max ( ans , dp [ i ] ) ; } Console . Write ( ans ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 3 , 5 , 7 , 9 } ; int N = arr . Length ; findMaxJumps ( arr , N ) ; } }

Index/key variables: N, i, j
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void longestSubsequence ( int [ ] arr , int N ) { int [ , ] dp = new int [ N , N + 1 ] ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N + 1 ; ++ j ) { dp [ i , j ] = - 1 ; } } for ( int i = 0 ; i < N ; ++ i ) { dp [ i , 0 ] = 0 ; } dp [ 0 , 1 ] = ( arr [ 0 ] >= 0 ? arr [ 0 ] : - 1 ) ; for ( int i = 1 ; i < N ; ++ i ) { for ( int j = 1 ; j <= ( i + 1 ) ; ++ j ) { if ( dp [ i - 1 , j ] != - 1 ) { dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j ] ) ; } if ( dp [ i - 1 , j - 1 ] >= 0 && dp [ i - 1 , j - 1 ] + arr [ i ] >= 0 ) { dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j - 1 ] + arr [ i ] ) ; } } } int ans = 0 ; for ( int j = 0 ; j <= N ; ++ j ) { if ( dp [ N - 1 , j ] >= 0 ) { ans = j ; } } Console . Write ( ans ) ; } public static void Main ( ) { int [ ] arr = { 4 , - 4 , 1 , - 3 , 1 , - 3 } ; int N = arr . Length ; longestSubsequence ( arr , N ) ; } }

Index/key variables: i
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class MyClass { static int [ , , ] dp = new int [ 100 , 10 , 2 ] ; static int solve ( int i , int n , int prev , int sign ) { if ( i == n ) { return 1 ; } int val = dp [ i , prev , sign ] ; if ( val != - 1 ) return val ; val = 0 ; if ( i == 0 ) { for ( int digit = ( n == 1 ? 0 : 1 ) ; digit <= 9 ; ++ digit ) { val += solve ( i + 1 , n , digit , sign ) ; } } else if ( i == 1 ) { for ( int digit = 0 ; digit <= 9 ; ++ digit ) { if ( digit != prev ) { val += solve ( i + 1 , n , digit , ( ( digit > prev ) ? 1 : 0 ) ) ; } } } else { if ( sign == 1 ) { for ( int digit = prev - 1 ; digit >= 0 ; -- digit ) { val += solve ( i + 1 , n , digit , 0 ) ; } } else { for ( int digit = prev + 1 ; digit <= 9 ; ++ digit ) { val += solve ( i + 1 , n , digit , 1 ) ; } } } return val ; } static void countNdigitNumber ( int N ) { for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) dp [ i , j , k ] = - 1 ; } } Console . WriteLine ( solve ( 0 , N , 0 , 0 ) ) ; } public static void Main ( String [ ] args ) { int N = 3 ; countNdigitNumber ( N ) ; } }

Accumulator variables: i, j, k, val
Iterator variables: digit, i, j, k
Class/struct names: MyClass
C# program:
using System ; class GFG { static int Count ( int N , int L , int R ) { int [ , ] dp = new int [ N , R - L + 1 ] ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { dp [ i , 0 ] = 1 ; } for ( int i = 1 ; i < dp . GetLength ( 1 ) ; i ++ ) { dp [ 0 , i ] = dp [ 0 , i - 1 ] + 1 ; } ans = dp [ 0 , R - L ] ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < dp . GetLength ( 1 ) ; j ++ ) { dp [ i , j ] = dp [ i - 1 , j ] + dp [ i , j - 1 ] ; } ans += dp [ i , R - L ] ; } return ans ; } public static void Main ( ) { int N = 3 ; int L = 6 ; int R = 9 ; Console . Write ( Count ( N , L , R ) ) ; } }

Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int largestCommonSubarray ( int [ , ] arr , int n , int m ) { int [ , ] dp = new int [ n , m + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { dp [ i , arr [ i , j ] ] = j ; } } int ans = 1 ; int len = 1 ; for ( int i = 1 ; i < m ; i ++ ) { bool check = true ; for ( int j = 1 ; j < n ; j ++ ) { if ( dp [ j , arr [ 0 , i - 1 ] ] + 1 != dp [ j , arr [ 0 , i ] ] ) { check = false ; break ; } } if ( check == true ) { len ++ ; ans = Math . Max ( ans , len ) ; } else { len = 1 ; } } return ans ; } public static void Main ( ) { int [ , ] arr = { { 4 , 5 , 1 , 2 , 3 , 6 , 7 } , { 1 , 2 , 4 , 5 , 7 , 6 , 3 } , { 2 , 7 , 3 , 4 , 5 , 1 , 6 } } ; int N = 3 ; int M = 7 ; Console . Write ( largestCommonSubarray ( arr , N , M ) ) ; } }

Accumulator variables: i, j, len
Iterator variables: i, j
Boolean variables: check
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MaximumSum ( int [ ] a , int [ ] b , int n ) { int [ , ] dp = new int [ n , 2 ] ; dp [ 0 , 0 ] = a [ 0 ] ; dp [ 0 , 1 ] = b [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i , 0 ] = Math . Max ( dp [ i - 1 , 0 ] , dp [ i - 1 , 1 ] ) + a [ i ] ; dp [ i , 1 ] = Math . Max ( dp [ i - 1 , 0 ] , dp [ i - 1 , 1 ] ) ; if ( i - 2 >= 0 ) { dp [ i , 1 ] = Math . Max ( dp [ i , 1 ] , Math . Max ( dp [ i - 2 , 0 ] , dp [ i - 2 , 1 ] ) + b [ i ] ) ; } else { dp [ i , 1 ] = Math . Max ( dp [ i , 1 ] , b [ i ] ) ; } } return Math . Max ( dp [ n - 1 , 0 ] , dp [ n - 1 , 1 ] ) ; } public static void Main ( ) { int [ ] A = { 10 , 1 , 10 , 10 } ; int [ ] B = { 5 , 50 , 1 , 5 } ; int N = A . Length ; Console . Write ( MaximumSum ( A , B , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 30 ; static void findNumString ( int X , int Y , int [ , ] dp ) { for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = 0 ; } } dp [ 0 , 0 ] = 1 ; for ( int i = 0 ; i <= X ; ++ i ) { for ( int j = 0 ; j <= Y ; ++ j ) { if ( i > 0 ) { dp [ i , j ] += dp [ i - 1 , j ] ; } if ( j > 0 ) { dp [ i , j ] += dp [ i , j - 1 ] ; } } } } static string kthString ( int X , int Y , int K , int [ , ] dp ) { string x1 = " " ; string y1 = " " ; for ( int i = 0 ; i < Y ; i ++ ) { x1 += ' b ' ; } for ( int i = 0 ; i < X ; i ++ ) { y1 += ' a ' ; } if ( X == 0 ) return x1 ; if ( Y == 0 ) return y1 ; if ( K <= dp [ X - 1 , Y ] ) { return ( " a " + kthString ( X - 1 , Y , K , dp ) ) ; } else { return ( " b " + kthString ( X , Y - 1 , K - dp [ X - 1 , Y ] , dp ) ) ; } } static void kthStringUtil ( int X , int Y , int K ) { int [ , ] dp = new int [ MAX , MAX ] ; findNumString ( X , Y , dp ) ; Console . WriteLine ( kthString ( X , Y , K , dp ) ) ; } static void Main ( ) { int X = 4 ; int Y = 3 ; int K = 4 ; kthStringUtil ( X , Y , K ) ; } }

Accumulator variables: i, j, x1, y1
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int KvisibleFromLeft ( int N , int K ) { if ( N == K ) return 1 ; if ( K == 1 ) { int ans = 1 ; for ( int i = 1 ; i < N ; i ++ ) ans *= i ; return ans ; } return KvisibleFromLeft ( N - 1 , K - 1 ) + ( N - 1 ) * KvisibleFromLeft ( N - 1 , K ) ; } public static void Main ( String [ ] args ) { int N = 5 , K = 2 ; Console . Write ( KvisibleFromLeft ( N , K ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int minimumDeletions ( int [ ] A , int N ) { int ans = Int32 . MaxValue ; for ( int i = 1 ; i < ( 1 << N ) ; i ++ ) { List < int > temp = new List < int > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) { temp . Add ( A [ j ] ) ; } } int flag = 0 ; for ( int j = 1 ; j < temp . Count ; j ++ ) if ( temp [ j ] < temp [ j - 1 ] ) flag = 1 ; for ( int j = 1 ; j < temp . Count - 1 ; j ++ ) if ( temp [ j ] - temp [ j - 1 ] > temp [ j + 1 ] - temp [ j ] ) flag = 1 ; if ( flag == 0 ) { ans = Math . Min ( ans , N - temp . Count ) ; } } return ans ; } public static void Main ( ) { int [ ] A = { 1 , 4 , 5 , 7 , 20 , 21 } ; int N = A . Length ; Console . Write ( minimumDeletions ( A , N ) ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100001 ; static int minimumDeletions ( int [ ] A , int N ) { int [ , ] dp = new int [ N , MAX ] ; int [ , ] pref = new int [ N , MAX ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = 0 ; pref [ i , j ] = 0 ; } } for ( int i = 0 ; i < N ; i ++ ) { dp [ i , 0 ] = 1 ; for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( A [ i ] >= A [ j ] ) { int diff = A [ i ] - A [ j ] ; dp [ i , diff ] = Math . Max ( dp [ i , diff ] , pref [ j , diff ] + 1 ) ; } } pref [ i , 0 ] = dp [ i , 0 ] ; for ( int j = 1 ; j < MAX ; j ++ ) pref [ i , j ] = Math . Max ( dp [ i , j ] , pref [ i , j - 1 ] ) ; } int maxSetSize = - 1 ; for ( int i = 0 ; i < MAX ; i ++ ) maxSetSize = Math . Max ( maxSetSize , dp [ N - 1 , i ] ) ; return N - maxSetSize ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 4 , 5 , 7 , 20 , 21 } ; int N = A . Length ; Console . Write ( minimumDeletions ( A , N ) ) ; } }

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 maximumSum ( List < int > A , int N , int K , int D ) { int ans = 0 ; for ( int i = 0 ; i < ( 1 << N ) ; i ++ ) { int sum = 0 ; int c = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( ( i >> j & 1 ) != 0 ) { sum += A [ j ] ; c ++ ; } } if ( sum % D == 0 && c <= K ) ans = Math . Max ( ans , sum ) ; } return ans ; } public static void Main ( ) { int N = 5 , K = 3 , D = 7 ; List < int > A = new List < int > ( ) { 1 , 11 , 5 , 5 , 18 } ; Console . Write ( maximumSum ( A , N , K , D ) ) ; } }

Index/key variables: j
Accumulator variables: c, i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static string longestSubsequence ( string X , string Y ) { int i , j ; int n = X . Length ; int m = Y . Length ; int [ , ] mat = new int [ n + 1 , m + 1 ] ; for ( i = 0 ; i < n + 1 ; i ++ ) { for ( j = 0 ; j < m + 1 ; j ++ ) { if ( i == 0 j == 0 ) mat [ i , j ] = 0 ; } } for ( i = 1 ; i < n + 1 ; i ++ ) { for ( j = 1 ; j < m + 1 ; j ++ ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { mat [ i , j ] = 1 + mat [ i - 1 , j - 1 ] ; } else { mat [ i , j ] = mat [ i - 1 , j ] ; } } } int len = 0 , col = 0 ; for ( i = 0 ; i < m + 1 ; i ++ ) { if ( mat [ n , i ] > len ) { len = mat [ n , i ] ; col = i ; } } string res = " " ; i = n ; j = col ; while ( len > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { res = X [ i - 1 ] + res ; i -- ; j -- ; len -- ; } else { i -- ; } } return res ; } public static void Main ( ) { string X = " ABCD " ; string Y = " ACDBDCD " ; Console . Write ( longestSubsequence ( X , Y ) ) ; } }

Accumulator variables: i, j, len
Iterator variables: i, j
Class/struct names: GFG