dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int calculate ( int pos , int prev , int left , int k ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; int answer = 0 ; for ( int i = prev ; i <= left ; i ++ ) { answer += calculate ( pos + 1 , i , left - i , k ) ; } return answer ; } static int countWaystoDivide ( int n , int k ) { return calculate ( 0 , 1 , n , k ) ; } public static void Main ( String [ ] args ) { int N = 8 ; int K = 4 ; Console . Write ( countWaystoDivide ( N , K ) ) ; } }

Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , , ] dp = new int [ 50 , 50 , 50 ] ; static int calculate ( int pos , int prev , int left , int k ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; if ( dp [ pos , prev , left ] != - 1 ) return dp [ pos , prev , left ] ; int answer = 0 ; for ( int i = prev ; i <= left ; i ++ ) { answer += calculate ( pos + 1 , i , left - i , k ) ; } return dp [ pos , prev , left ] = answer ; } static int countWaystoDivide ( int n , int k ) { for ( int i = 0 ; i < 50 ; i ++ ) { for ( int j = 0 ; j < 50 ; j ++ ) { for ( int l = 0 ; l < 50 ; l ++ ) dp [ i , j , l ] = - 1 ; } } return calculate ( 0 , 1 , n , k ) ; } public static void Main ( String [ ] args ) { int N = 8 ; int K = 4 ; Console . Write ( countWaystoDivide ( N , K ) ) ; } }

Accumulator variables: answer, i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxScore ( int l , int r , int [ ] prefix_sum , int num ) { if ( l > r ) return 0 ; int current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= - 1 ; return current_sum + Math . Max ( maxScore ( l + 1 , r , prefix_sum , num + 1 ) , maxScore ( l , r - 1 , prefix_sum , num + 1 ) ) ; } static int findMaxScore ( int [ ] a , int n ) { int [ ] prefix_sum = new int [ n ] ; prefix_sum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + a [ i ] ; } return maxScore ( 0 , n - 1 , prefix_sum , 1 ) ; } public static void Main ( String [ ] args ) { int n = 6 ; int [ ] A = { 1 , 2 , 3 , 4 , 2 , 6 } ; Console . Write ( findMaxScore ( A , n ) ) ; } }

Index/key variables: i, n, r
Accumulator variables: current_sum, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Linq ; using System . Collections . Generic ; class GFG { static Dictionary < int , int > Map = new Dictionary < int , int > ( ) ; static void findPrimeFactors ( int N ) { int i ; Map . Clear ( ) ; while ( N % 2 == 0 ) { if ( Map . ContainsKey ( 2 ) ) Map [ 2 ] = Map [ 2 ] + 1 ; else Map . Add ( 2 , 1 ) ; N /= 2 ; } for ( i = 3 ; i <= Math . Sqrt ( N ) ; i += 2 ) { while ( N % i == 0 ) { if ( Map . ContainsKey ( i ) ) Map [ i ] = Map [ i ] + 1 ; else Map . Add ( i , 1 ) ; N /= i ; } } if ( N > 2 ) { if ( Map . ContainsKey ( N ) ) Map [ N ] = Map [ N ] + 1 ; else Map . Add ( N , 1 ) ; } } static int PowInFactN ( int N , int P ) { int ans = 0 ; int temp = P ; while ( temp <= N ) { ans += N / temp ; temp = temp * P ; } return ans ; } static int findPowers ( int N , int P ) { findPrimeFactors ( P ) ; List < int > Powers = new List < int > ( ) ; foreach ( KeyValuePair < int , int > it in Map ) { int primeFac = it . Key ; int facPow = it . Value ; int p = PowInFactN ( N , primeFac ) ; p /= facPow ; Powers . Add ( p ) ; } return Powers . Min ( ) ; } public static void Main ( String [ ] args ) { int N = 24 , P = 4 ; Console . Write ( findPowers ( N , P ) ) ; } }

Index/key variables: N, i
Accumulator variables: N, ans, i, p
Iterator variables: i, it
Class/struct names: GFG
C# program:
using System ; class GFG { static int FindMaxLength ( int [ ] A , int [ ] B , int n , int m ) { int [ , ] dp = new int [ n + 1 , m + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= m ; j ++ ) dp [ i , j ] = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( A [ i ] == B [ j ] ) dp [ j , i ] = dp [ j + 1 , i + 1 ] + 1 ; } } int maxm = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { maxm = Math . Max ( maxm , dp [ i , j ] ) ; } } return maxm ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 8 , 2 , 1 } ; int [ ] B = { 8 , 2 , 1 , 4 , 7 } ; int n = A . Length ; int m = B . Length ; Console . Write ( FindMaxLength ( A , B , n , m ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxLength ( int [ ] a , int n ) { int maximum = 1 ; int [ ] left = new int [ n ] ; int [ ] right = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { left [ i ] = 1 ; right [ i ] = 1 ; } for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] > a [ i + 1 ] ) { right [ i ] = right [ i + 1 ] + 1 ; } maximum = Math . Max ( maximum , right [ i ] ) ; } for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] < a [ i - 1 ] ) { left [ i ] = left [ i - 1 ] + 1 ; } } if ( n > 2 ) { for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i - 1 ] > a [ i + 1 ] ) { maximum = Math . Max ( maximum , left [ i - 1 ] + right [ i + 1 ] ) ; } } } return maximum ; } public static void Main ( String [ ] args ) { int [ ] arr = { 8 , 7 , 3 , 5 , 2 , 9 } ; int n = arr . Length ; Console . WriteLine ( maxLength ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int [ , ] LAS = new int [ 1000 , 2 ] ; static int solve ( int [ ] arr , int n , int i , int pos ) { if ( i == n ) return 0 ; if ( LAS [ i , pos ] == 1 ) return LAS [ i , pos ] ; int inc = 0 , exc = 0 ; if ( arr [ i ] > 0 && pos == 1 ) { pos = 0 ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } else if ( arr [ i ] < 0 && pos == 0 ) { pos = 1 ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } exc = solve ( arr , n , i + 1 , pos ) ; LAS [ i , pos ] = Math . Max ( inc , exc ) ; return LAS [ i , pos ] ; } public static void Main ( ) { int [ ] arr = { - 1 , 2 , 3 , 4 , 5 , - 6 , 8 , - 99 } ; int n = arr . Length ; Console . WriteLine ( Math . Max ( solve ( arr , n , 0 , 0 ) , solve ( arr , n , 0 , 1 ) ) ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int cntSubSeq ( int [ ] arr , int n ) { int pos_count = 0 ; int neg_count = 0 ; int result ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos_count ++ ; if ( arr [ i ] < 0 ) neg_count ++ ; } result = ( int ) Math . Pow ( 2 , pos_count ) ; if ( neg_count > 0 ) result *= ( int ) Math . Pow ( 2 , neg_count - 1 ) ; else result = 0 ; return result ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , - 4 , - 1 , 6 } ; int n = arr . Length ; Console . Write ( cntSubSeq ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, neg_count, pos_count, result
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int INT_MAX = int . MaxValue ; static int minSteps ( string str , int n , int k ) { if ( str [ n - 1 ] == '0' ) return - 1 ; if ( n == 1 ) return 0 ; if ( n < 4 ) return 1 ; int [ ] dp = new int [ n ] ; dp [ n - 1 ] = 0 ; dp [ n - 2 ] = 1 ; dp [ n - 3 ] = 1 ; for ( int i = n - 4 ; i >= 0 ; i -- ) { if ( str [ i ] == '0' ) continue ; int steps = INT_MAX ; if ( i + k < n && str [ i + k ] == '1' ) steps = Math . Min ( steps , dp [ i + k ] ) ; if ( str [ i + 1 ] == '1' ) steps = Math . Min ( steps , dp [ i + 1 ] ) ; if ( str [ i + 2 ] == '1' ) steps = Math . Min ( steps , dp [ i + 2 ] ) ; dp [ i ] = ( steps == INT_MAX ) ? steps : 1 + steps ; } if ( dp [ 0 ] == INT_MAX ) return - 1 ; return dp [ 0 ] ; } public static void Main ( ) { string str = "101000011" ; int n = str . Length ; int k = 5 ; Console . WriteLine ( minSteps ( str , n , k ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static Dictionary < string , int > dp = new Dictionary < string , int > ( ) ; static int solve ( char [ ] s , char c ) { if ( s . Length == 1 ) return 0 ; if ( s . Length == 2 ) { if ( s [ 0 ] == s [ 1 ] && s [ 0 ] == c ) return 1 ; else return 0 ; } if ( dp . ContainsKey ( new string ( s ) + " ▁ " + c ) ) return dp [ new string ( s ) + " ▁ " + c ] ; int ans = 0 ; if ( s [ 0 ] == s [ s . Length - 1 ] && s [ 0 ] == c ) { for ( char c1 = ' a ' ; c1 <= ' z ' ; c1 ++ ) if ( c1 != c ) { int len = s . Length - 2 ; char [ ] tmp = new char [ len ] ; Array . Copy ( s , 1 , tmp , 0 , len ) ; ans = Math . Max ( ans , 1 + solve ( tmp , c1 ) ) ; } } else { for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == c ) { for ( int j = s . Length - 1 ; j > i ; j -- ) if ( s [ j ] == c ) { if ( j == i ) break ; int len = j + 1 - i ; char [ ] tmp = new char [ len ] ; Array . Copy ( s , i , tmp , 0 , len ) ; ans = solve ( tmp , c ) ; break ; } break ; } } } dp [ new string ( s ) + " ▁ " + c ] = ans ; return dp [ new string ( s ) + " ▁ " + c ] ; } public static void Main ( string [ ] args ) { string s = " abscrcdba " ; int ma = 0 ; for ( char c1 = ' a ' ; c1 <= ' z ' ; c1 ++ ) ma = Math . Max ( ma , solve ( s . ToCharArray ( ) , c1 ) * 2 ) ; Console . Write ( ma + " STRNEWLINE " ) ; } }

Index/key variables: i, j, len
Accumulator variables: c1, i, j
Iterator variables: c1, i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int eggDrop ( int n , int k ) { int [ , ] dp = new int [ k + 1 , n + 1 ] ; int x = 0 ; while ( dp [ x , n ] < k ) { x ++ ; for ( int i = 1 ; i <= n ; i ++ ) dp [ x , i ] = dp [ x - 1 , i - 1 ] + dp [ x - 1 , i ] + 1 ; } return x ; } public static void Main ( String [ ] args ) { int n = 2 , k = 36 ; Console . WriteLine ( eggDrop ( n , k ) ) ; } }

Accumulator variables: i, x
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxIncSubarr ( int [ ] a , int n ) { int [ ] pre = new int [ n ] ; int [ ] pos = new int [ n ] ; pre [ 0 ] = 1 ; pos [ n - 1 ] = 1 ; int l = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) pre [ i ] = pre [ i - 1 ] + 1 ; else pre [ i ] = 1 ; } l = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] < a [ i + 1 ] ) pos [ i ] = pos [ i + 1 ] + 1 ; else pos [ i ] = 1 ; } int ans = 0 ; l = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) l ++ ; else l = 1 ; ans = Math . Max ( ans , l ) ; } for ( int i = 1 ; i <= n - 2 ; i ++ ) { if ( a [ i - 1 ] < a [ i + 1 ] ) ans = Math . Max ( pre [ i - 1 ] + pos [ i + 1 ] , ans ) ; } return ans ; } public static void Main ( ) { int [ ] arr = { 1 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxIncSubarr ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, l
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int n = 3 ; static int m = 3 ; static int countSquareMatrices ( int [ , ] a , int N , int M ) { int count = 0 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) { if ( a [ i , j ] == 0 ) continue ; a [ i , j ] = Math . Min ( Math . Min ( a [ i - 1 , j ] , a [ i , j - 1 ] ) , a [ i - 1 , j - 1 ] ) + 1 ; } } for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) count += a [ i , j ] ; return count ; } public static void Main ( ) { int [ , ] arr = { { 1 , 0 , 1 } , { 1 , 1 , 0 } , { 1 , 1 , 0 } } ; Console . WriteLine ( countSquareMatrices ( arr , n , m ) ) ; } }

Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int N = 10000 ; static int [ ] seg = new int [ 3 * N ] ; static int update ( int In , int l , int r , int up_in , int val ) { if ( r < up_in l > up_in ) return seg [ In ] ; if ( l == up_in && r == up_in ) return seg [ In ] = val ; int m = ( l + r ) / 2 ; return seg [ In ] = update ( 2 * In + 1 , l , m , up_in , val ) + update ( 2 * In + 2 , m + 1 , r , up_in , val ) ; } static int query ( int In , int l , int r , int l1 , int r1 ) { if ( l > r ) return 0 ; if ( r < l1 l > r1 ) return 0 ; if ( l1 <= l && r <= r1 ) return seg [ In ] ; int m = ( l + r ) / 2 ; return query ( 2 * In + 1 , l , m , l1 , r1 ) + query ( 2 * In + 2 , m + 1 , r , l1 , r1 ) ; } static int findCnt ( int [ ] arr , int n ) { int [ ] brr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; Array . Sort ( brr ) ; Dictionary < int , int > r = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) r . Add ( brr [ i ] , i + 1 ) ; int [ ] dp = new int [ n ] ; int ans = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int rank = r [ arr [ i ] ] ; dp [ i ] = 1 + query ( 0 , 0 , n - 1 , rank , n - 1 ) ; ans += dp [ i ] ; update ( 0 , 0 , n - 1 , rank - 1 , dp [ i ] + query ( 0 , 0 , n - 1 , rank - 1 , rank - 1 ) ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 10 , 9 } ; int n = arr . Length ; Console . Write ( findCnt ( arr , n ) ) ; } }

Index/key variables: In, i, n
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int minCost ( int n , int x , int y , int z ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { if ( i % 2 == 1 ) { dp [ i ] = Math . Min ( dp [ ( i + 1 ) / 2 ] + x + z , dp [ i - 1 ] + y ) ; } else { dp [ i ] = Math . Min ( dp [ i / 2 ] + x , dp [ i - 1 ] + y ) ; } } return dp [ n ] ; } public static void Main ( String [ ] args ) { int n = 5 , x = 2 , y = 1 , z = 3 ; Console . Write ( minCost ( n , x , y , z ) + " STRNEWLINE " ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 1000005 ; static int maximum_set ( int [ ] a , int n ) { int [ ] dp = new int [ N ] ; for ( int i = 0 ; i < n ; i ++ ) dp [ a [ i ] ] = 1 ; int ans = 1 ; for ( int i = N - 1 ; i >= 1 ; i -- ) { if ( dp [ i ] != 0 ) { for ( int j = 2 * i ; j < N ; j += i ) { dp [ i ] = Math . Max ( dp [ i ] , 1 + dp [ j ] ) ; ans = Math . Max ( ans , dp [ i ] ) ; } } } return ans ; } public static void Main ( ) { int [ ] arr = { 3 , 4 , 6 , 8 , 10 , 18 , 21 , 24 } ; int n = arr . Length ; Console . WriteLine ( maximum_set ( arr , n ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int N = 100 ; static int [ , ] dp = new int [ N , 3 ] ; static int [ , ] v = new int [ N , 3 ] ; static int findCnt ( String s , int i , int r ) { if ( i == s . Length ) { if ( r == 0 ) return 1 ; else return 0 ; } if ( v [ i , r ] == 1 ) return dp [ i , r ] ; v [ i , r ] = 1 ; dp [ i , r ] = findCnt ( s , i + 1 , ( r * 2 + ( s [ i ] - '0' ) ) % 3 ) + findCnt ( s , i + 1 , r ) ; return dp [ i , r ] ; } public static void Main ( String [ ] args ) { String s = "11" ; Console . Write ( findCnt ( s , 0 , 0 ) - 1 ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int minCount ( int [ ] arr , int n , int k ) { int ans = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; sum -= k ; int l = 0 ; int r = 0 ; int tot = 0 ; while ( l < n ) { if ( tot <= sum ) { ans = Math . Max ( ans , r - l ) ; if ( r == n ) break ; tot += arr [ r ++ ] ; } else { tot -= arr [ l ++ ] ; } } return ( n - ans ) ; } public static void Main ( ) { int [ ] arr = { 1 , 11 , 5 , 5 } ; int n = arr . Length ; int k = 11 ; Console . WriteLine ( minCount ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, l, r, sum, tot
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int N = 401 ; static int [ , ] dp = new int [ N , N ] ; static bool [ , ] v = new bool [ N , N ] ; static int minMergeCost ( int i , int j , int [ ] arr ) { if ( i == j ) return 0 ; if ( v [ i , j ] ) return dp [ i , j ] ; v [ i , j ] = true ; int x = dp [ i , j ] ; x = int . MaxValue ; int tot = 0 ; for ( int k = i ; k <= j ; k ++ ) tot += arr [ k ] ; for ( int k = i + 1 ; k <= j ; k ++ ) { x = Math . Min ( x , tot + minMergeCost ( i , k - 1 , arr ) + minMergeCost ( k , j , arr ) ) ; } return x ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 7 } ; int n = arr . Length ; Console . Write ( minMergeCost ( 0 , n - 1 , arr ) ) ; } }

Index/key variables: k
Accumulator variables: k, tot
Iterator variables: k
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxSize = 50 ; static double [ ] dp = new double [ maxSize ] ; static int [ ] v = new int [ maxSize ] ; static double expectedSteps ( int x ) { if ( x == 0 ) return 0 ; if ( x <= 5 ) return 6 ; if ( v [ x ] == 1 ) return dp [ x ] ; v [ x ] = 1 ; dp [ x ] = 1 + ( expectedSteps ( x - 1 ) + expectedSteps ( x - 2 ) + expectedSteps ( x - 3 ) + expectedSteps ( x - 4 ) + expectedSteps ( x - 5 ) + expectedSteps ( x - 6 ) ) / 6 ; return dp [ x ] ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( expectedSteps ( n - 1 ) ) ; } }

Index/key variables: maxSize, x
Class/struct names: GFG
C# program:
using System ; class GFG { static int countSubSeq ( string str , int len ) { int ans = 0 ; int mul = 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) ans += mul ; mul *= 2 ; } return ans ; } static public void Main ( ) { string str = "10010" ; int len = str . Length ; Console . WriteLine ( countSubSeq ( str , len ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, mul
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int V_SUM_MAX = 1000 ; static readonly int N_MAX = 100 ; static readonly int W_MAX = 10000000 ; static int [ , ] dp = new int [ V_SUM_MAX + 1 , N_MAX ] ; static bool [ , ] v = new bool [ V_SUM_MAX + 1 , N_MAX ] ; static int solveDp ( int r , int i , int [ ] w , int [ ] val , int n ) { if ( r <= 0 ) return 0 ; if ( i == n ) return W_MAX ; if ( v [ r , i ] ) return dp [ r , i ] ; v [ r , i ] = true ; dp [ r , i ] = Math . Min ( solveDp ( r , i + 1 , w , val , n ) , w [ i ] + solveDp ( r - val [ i ] , i + 1 , w , val , n ) ) ; return dp [ r , i ] ; } static int maxWeight ( int [ ] w , int [ ] val , int n , int c ) { for ( int i = V_SUM_MAX ; i >= 0 ; i -- ) { if ( solveDp ( i , 0 , w , val , n ) <= c ) { return i ; } } return 0 ; } public static void Main ( String [ ] args ) { int [ ] w = { 3 , 4 , 5 } ; int [ ] val = { 30 , 50 , 60 } ; int n = w . Length ; int C = 8 ; Console . WriteLine ( maxWeight ( w , val , n , C ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int sz = 100005 ; static int n ; static ArrayList [ ] tree = new ArrayList [ sz ] ; static int [ ] subtree_size = new int [ sz ] ; static int [ ] vis = new int [ sz ] ; static void addEdge ( int a , int b ) { tree [ a ] . Add ( b ) ; tree [ b ] . Add ( a ) ; } static int dfs ( int node ) { vis [ node ] = 1 ; subtree_size [ node ] = 1 ; foreach ( int child in tree [ node ] ) { if ( vis [ child ] == 0 ) { subtree_size [ node ] += dfs ( child ) ; } } return subtree_size [ node ] ; } static void contribution ( int node , ref int ans ) { vis [ node ] = 1 ; foreach ( int child in tree [ node ] ) { if ( vis [ child ] == 0 ) { ans += ( subtree_size [ child ] * ( n - subtree_size [ child ] ) ) ; contribution ( child , ref ans ) ; } } } static int getSum ( ) { Array . Fill ( vis , 0 ) ; dfs ( 0 ) ; int ans = 0 ; Array . Fill ( vis , 0 ) ; contribution ( 0 , ref ans ) ; return ans ; } public static void Main ( ) { n = 5 ; for ( int i = 0 ; i < sz ; i ++ ) { tree [ i ] = new ArrayList ( ) ; } addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 1 , 4 ) ; Console . Write ( getSum ( ) ) ; } }

Index/key variables: a, b, child, i, node, sz
Accumulator variables: ans, i
Iterator variables: child, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 3 ; static int numberOfCells ( int [ , ] mat ) { bool [ , ] row = new bool [ N , N ] ; bool [ , ] col = new bool [ N , N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j >= 0 ; j -- ) { if ( mat [ i , j ] == 1 ) { row [ i , j ] = ( j + 1 < N ) ? row [ i , j + 1 ] : true ; } else { row [ i , j ] = false ; } } } for ( int j = 0 ; j < N ; j ++ ) { for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( mat [ i , j ] == 1 ) { col [ i , j ] = ( i + 1 < N ) ? col [ i + 1 , j ] : true ; } else { col [ i , j ] = false ; } } } int cnt = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( row [ i , j ] && col [ i , j ] ) { cnt ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { if ( col [ i , N - 1 ] ) cnt ++ ; } for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( row [ N - 1 , j ] ) cnt ++ ; } return cnt ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 0 , 1 , 1 } , { 0 , 1 , 1 } , { 0 , 1 , 1 } } ; Console . Write ( numberOfCells ( mat ) ) ; } }

Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MaxGCD ( int [ ] a , int n ) { int [ ] Prefix = new int [ n + 2 ] ; int [ ] Suffix = new int [ n + 2 ] ; Prefix [ 1 ] = a [ 0 ] ; for ( int i = 2 ; i <= n ; i += 1 ) { Prefix [ i ] = __gcd ( Prefix [ i - 1 ] , a [ i - 1 ] ) ; } Suffix [ n ] = a [ n - 1 ] ; for ( int i = n - 1 ; i >= 1 ; i -= 1 ) { Suffix [ i ] = __gcd ( Suffix [ i + 1 ] , a [ i - 1 ] ) ; } int ans = Math . Max ( Suffix [ 2 ] , Prefix [ n - 1 ] ) ; for ( int i = 2 ; i < n ; i += 1 ) { ans = Math . Max ( ans , __gcd ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) ) ; } return ans ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int [ ] a = { 6 , 7 , 8 } ; int n = a . Length ; Console . WriteLine ( MaxGCD ( a , n ) ) ; } }

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

Accumulator variables: cur_sum, i, j, temp_sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int subsequence ( int [ ] S , int [ ] T , int n , int m ) { int [ , ] dp = new int [ n + 1 , m + 1 ] ; int mod = 1000000007 ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i , 0 ] = 1 ; for ( int j = 0 ; j <= m ; j ++ ) dp [ 0 , j ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= m ; ++ j ) { dp [ i , j ] = dp [ i - 1 , j ] + dp [ i , j - 1 ] - dp [ i - 1 , j - 1 ] ; if ( S [ i - 1 ] == T [ j - 1 ] ) dp [ i , j ] += dp [ i - 1 , j - 1 ] ; dp [ i , j ] += mod ; dp [ i , j ] %= mod ; } } return dp [ n , m ] ; } public static void Main ( ) { int [ ] S = { 1 , 1 } ; int n = S . Length ; int [ ] T = { 1 , 1 } ; int m = T . Length ; Console . WriteLine ( subsequence ( S , T , n , m ) ) ; } }

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