dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; using System . Collections . Generic ; class GFG { static int N = 100005 ; static List < List < Tuple < int , int > > > v = new List < List < Tuple < int , int > > > ( ) ; static int [ ] dp = new int [ N ] ; static int [ ] leaves = new int [ N ] ; static void dfs ( int a , int par ) { bool leaf = true ; foreach ( Tuple < int , int > i in v [ a ] ) { if ( i . Item1 == par ) continue ; leaf = false ; dfs ( i . Item1 , a ) ; } if ( leaf == true ) { leaves [ a ] += 1 ; } else { foreach ( Tuple < int , int > i in v [ a ] ) { if ( i . Item1 == par ) continue ; leaves [ a ] += leaves [ i . Item1 ] ; dp [ a ] = ( dp [ a ] + dp [ i . Item1 ] + leaves [ i . Item1 ] * i . Item2 ) ; } } } static void dfs2 ( int a , int par ) { foreach ( Tuple < int , int > i in v [ a ] ) { if ( i . Item1 == par ) continue ; int leafOutside = leaves [ a ] - leaves [ i . Item1 ] ; dp [ i . Item1 ] += ( dp [ a ] - dp [ i . Item1 ] ) ; dp [ i . Item1 ] += i . Item2 * ( leafOutside - leaves [ i . Item1 ] ) ; leaves [ i . Item1 ] += leafOutside ; dfs2 ( i . Item1 , a ) ; } } static void answerQueries ( List < int > queries ) { dfs ( 1 , 0 ) ; dfs2 ( 1 , 0 ) ; for ( int i = 0 ; i < queries . Count ; i ++ ) Console . WriteLine ( dp [ queries [ i ] ] ) ; } static void Main ( ) { for ( int i = 0 ; i < N ; i ++ ) { v . Add ( new List < Tuple < int , int > > ( ) ) ; } v [ 1 ] . Add ( new Tuple < int , int > ( 4 , 4 ) ) ; v [ 4 ] . Add ( new Tuple < int , int > ( 1 , 4 ) ) ; v [ 1 ] . Add ( new Tuple < int , int > ( 2 , 2 ) ) ; v [ 2 ] . Add ( new Tuple < int , int > ( 1 , 2 ) ) ; v [ 2 ] . Add ( new Tuple < int , int > ( 3 , 3 ) ) ; v [ 3 ] . Add ( new Tuple < int , int > ( 2 , 3 ) ) ; v [ 2 ] . Add ( new Tuple < int , int > ( 5 , 5 ) ) ; v [ 5 ] . Add ( new Tuple < int , int > ( 2 , 5 ) ) ; List < int > queries = new List < int > { 1 , 3 , 5 } ; answerQueries ( queries ) ; } }

Index/key variables: N, a, i
Accumulator variables: i
Iterator variables: i
Boolean variables: leaf
Class/struct names: GFG
C# program:
using System ; class GFG { static int countChanges ( int [ , ] matrix , int n , int m ) { int i , j , dist = n + m - 1 ; int Max_element = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { Max_element = Math . Max ( Max_element , matrix [ i , j ] ) ; } } int [ , ] freq = new int [ dist , Max_element + 1 ] ; for ( i = 0 ; i < dist ; i ++ ) { for ( j = 0 ; j < Max_element + 1 ; j ++ ) freq [ i , j ] = 0 ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { freq [ i + j , matrix [ i , j ] ] ++ ; } } int min_changes_sum = 0 ; for ( i = 0 ; i < dist / 2 ; i ++ ) { int maximum = 0 ; int total_values = 0 ; for ( j = 0 ; j < Max_element + 1 ; j ++ ) { maximum = Math . Max ( maximum , freq [ i , j ] + freq [ n + m - 2 - i , j ] ) ; total_values += freq [ i , j ] + freq [ n + m - 2 - i , j ] ; } min_changes_sum += total_values - maximum ; } return min_changes_sum ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 7 , 0 , 3 , 1 , 8 , 1 , 3 } , { 0 , 4 , 0 , 1 , 0 , 4 , 0 } , { 3 , 1 , 8 , 3 , 1 , 0 , 7 } } ; int minChanges = countChanges ( mat , 3 , 7 ) ; Console . Write ( minChanges ) ; } }

Accumulator variables: i, j, min_changes_sum, total_values
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , , , ] dp = new int [ 1002 , 10 , 2 , 2 ] ; static int possibleNumbers ( int pos , int previous , int tight , int start , String N , int K ) { if ( pos == N . Length ) return 1 ; if ( dp [ pos , previous , tight , start ] != - 1 ) return dp [ pos , previous , tight , start ] ; int res = 0 ; int upper_limit = ( tight == 1 ) ? ( N [ pos ] - '0' ) : 9 ; int new_tight ; if ( start == 0 ) { res = possibleNumbers ( pos + 1 , previous , 0 , 0 , N , K ) ; for ( int i = 1 ; i <= upper_limit ; i ++ ) { new_tight = ( tight > 0 && i == upper_limit ) ? 1 : 0 ; res += possibleNumbers ( pos + 1 , i , new_tight , 1 , N , K ) ; } } else { for ( int i = 0 ; i <= upper_limit ; i ++ ) { new_tight = ( tight > 0 && i == upper_limit ) ? 1 : 0 ; if ( Math . Abs ( i - previous ) <= K ) res += possibleNumbers ( pos + 1 , i , new_tight , 1 , N , K ) ; } } dp [ pos , previous , tight , start ] = res ; return dp [ pos , previous , tight , start ] ; } public static void Main ( String [ ] args ) { String N = "20" ; int K = 2 ; for ( int i = 0 ; i < 1002 ; i ++ ) for ( int j = 0 ; j < 10 ; j ++ ) for ( int k = 0 ; k < 2 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i , j , k , l ] = - 1 ; Console . Write ( possibleNumbers ( 0 , 0 , 1 , 0 , N , K ) + " STRNEWLINE " ) ; } }

Index/key variables: pos
Accumulator variables: i, j, k, l, res
Iterator variables: i, j, k, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int mergeTwoNumbers ( int [ ] numbers ) { int len , i , j , k ; int n = numbers . Length ; if ( numbers . Length == 0 ) { return 0 ; } int [ ] prefixSum = new int [ n + 1 ] ; for ( i = 1 ; i <= n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + numbers [ i - 1 ] ; } int [ , ] dp = new int [ n + 1 , n + 1 ] ; for ( len = 2 ; len <= n ; len ++ ) { for ( i = 1 ; i <= n - len + 1 ; i ++ ) { j = i + len - 1 ; int sum = prefixSum [ j ] - prefixSum [ i - 1 ] ; dp [ i , j ] = int . MaxValue ; for ( k = i ; k < j ; k ++ ) { dp [ i , j ] = Math . Min ( dp [ i , j ] , dp [ i , k ] + dp [ k + 1 , j ] + sum ) ; } } } return dp [ 1 , n ] ; } public static void Main ( String [ ] args ) { int [ ] arr1 = { 6 , 4 , 4 , 6 } ; Console . Write ( mergeTwoNumbers ( arr1 ) + " STRNEWLINE " ) ; } }

Index/key variables: i, j
Accumulator variables: i, k, len
Iterator variables: i, k, len
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int [ ] dp1 = new int [ 100005 ] ; static int [ ] dp2 = new int [ 100005 ] ; static void dfs1 ( int u , int par , List < List < int > > g , int [ ] weight ) { dp1 [ u ] = weight [ u ] ; for ( int c = 0 ; c < g [ u ] . Count ; c ++ ) { if ( g [ u ] != par ) { dfs1 ( g [ u ] , u , g , weight ) ; dp1 [ u ] += Math . Max ( 0 , dp1 [ g [ u ] ] ) ; } } } static void dfs2 ( int u , int par , List < List < int > > g , int [ ] weight ) { if ( par != 0 ) { int maxSumAncestors = dp2 [ par ] - Math . Max ( 0 , dp1 [ u ] ) ; dp2 [ u ] = dp1 [ u ] + Math . Max ( 0 , maxSumAncestors ) ; } for ( int c = 0 ; c < g [ u ] . Count ; c ++ ) { if ( g [ u ] != par ) { dfs2 ( g [ u ] , u , g , weight ) ; } } } static void addEdge ( int u , int v , List < List < int > > g ) { g [ u ] . Add ( v ) ; g [ v ] . Add ( u ) ; } static void maxSumSegments ( List < List < int > > g , int [ ] weight , int n ) { dfs1 ( 1 , 0 , g , weight ) ; for ( int i = 1 ; i < n + 1 ; i ++ ) dp2 [ i ] = dp1 [ i ] ; dfs2 ( 1 , 0 , g , weight ) ; } static void printAns ( int n ) { for ( int i = 1 ; i < n ; i ++ ) Console . Write ( dp2 [ i ] + " ▁ " ) ; } static void Main ( ) { int n = 7 ; List < List < int > > g = new List < List < int > > ( ) ; for ( int i = 0 ; i < 100005 ; i ++ ) { g . Add ( new List < int > ( ) ) ; } addEdge ( 1 , 2 , g ) ; addEdge ( 1 , 3 , g ) ; addEdge ( 2 , 4 , g ) ; addEdge ( 2 , 5 , g ) ; addEdge ( 3 , 6 , g ) ; addEdge ( 4 , 7 , g ) ; int [ ] weight = new int [ n + 1 ] ; weight [ 1 ] = - 8 ; weight [ 2 ] = 9 ; weight [ 3 ] = 7 ; weight [ 4 ] = - 4 ; weight [ 5 ] = 5 ; weight [ 6 ] = - 10 ; weight [ 7 ] = - 6 ; maxSumSegments ( g , weight , n ) ; printAns ( n ) ; } }

Index/key variables: i, par, u, v
Accumulator variables: c, i
Iterator variables: c, i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; using System . Text ; class GFG { static int countPairs ( int [ ] arr , int N ) { int maxm = - int . MaxValue ; for ( int j = 0 ; j < N ; j ++ ) { if ( maxm < arr [ j ] ) { maxm = arr [ j ] ; } } int i , k = 0 ; int [ ] bitscount = new int [ maxm + 1 ] ; Array . Fill ( bitscount , 0 ) ; for ( i = 1 ; i <= maxm ; i *= 2 ) bitscount [ i ] = 1 ; for ( i = 1 ; i <= maxm ; i ++ ) { if ( bitscount [ i ] == 1 ) k = i ; if ( bitscount [ i ] == 0 ) { bitscount [ i ] = bitscount [ k ] + bitscount [ i - k ] ; } } Dictionary < int , int > setbits = new Dictionary < int , int > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( setbits . ContainsKey ( bitscount [ arr [ j ] ] ) ) { setbits [ bitscount [ arr [ j ] ] ] ++ ; } else { setbits [ bitscount [ arr [ j ] ] ] = 1 ; } } int ans = 0 ; foreach ( KeyValuePair < int , int > it in setbits ) { ans += it . Value * ( it . Value - 1 ) / 2 ; } return ans ; } public static void Main ( string [ ] args ) { int N = 12 ; int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } ; Console . Write ( countPairs ( arr , N ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: ans, i, j
Iterator variables: i, it, j
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void depthFirst ( int v , List < List < int > > graph , bool [ ] visited , List < int > storeChain ) { visited [ v ] = true ; storeChain . Add ( v ) ; foreach ( int i in graph [ v ] ) { if ( visited [ i ] == false ) { depthFirst ( i , graph , visited , storeChain ) ; } } } static int subarraySum ( int [ ] arr , int n ) { int maxSubarraySum = arr [ 0 ] ; int currentMax = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { currentMax = Math . Max ( arr [ i ] , arr [ i ] + currentMax ) ; maxSubarraySum = Math . Max ( maxSubarraySum , currentMax ) ; } return maxSubarraySum ; } static void maxSubarraySum ( List < List < int > > graph , int vertices , List < int > values ) { bool [ ] visited = new bool [ 1001 ] ; int maxSum = - 1000000 ; for ( int i = 1 ; i <= vertices ; i ++ ) { if ( visited [ i ] == false ) { int sizeChain ; int tempSum ; List < int > storeChain = new List < int > ( ) ; depthFirst ( i , graph , visited , storeChain ) ; sizeChain = storeChain . Count ; int [ ] chainValues = new int [ sizeChain + 1 ] ; for ( int j = 0 ; j < sizeChain ; j ++ ) { int temp = values [ storeChain [ j ] - 1 ] ; chainValues [ j ] = temp ; } tempSum = subarraySum ( chainValues , sizeChain ) ; if ( tempSum > maxSum ) { maxSum = tempSum ; } } } Console . Write ( " Maximum ▁ subarray ▁ sum ▁ among ▁ all ▁ " ) ; Console . Write ( " connected ▁ components ▁ = ▁ " ) ; Console . Write ( maxSum ) ; } public static void Main ( string [ ] args ) { List < List < int > > graph = new List < List < int > > ( ) ; for ( int i = 0 ; i < 1001 ; i ++ ) graph . Add ( new List < int > ( ) ) ; int V = 7 ; List < int > values = new List < int > ( ) ; values . Add ( 3 ) ; values . Add ( 2 ) ; values . Add ( 4 ) ; values . Add ( - 2 ) ; values . Add ( 0 ) ; values . Add ( - 1 ) ; values . Add ( - 5 ) ; graph [ 1 ] . Add ( 2 ) ; graph [ 2 ] . Add ( 1 ) ; graph [ 3 ] . Add ( 4 ) ; graph [ 4 ] . Add ( 3 ) ; graph [ 4 ] . Add ( 5 ) ; graph [ 5 ] . Add ( 4 ) ; graph [ 6 ] . Add ( 7 ) ; graph [ 7 ] . Add ( 6 ) ; maxSubarraySum ( graph , V , values ) ; } }

Index/key variables: i, j, v
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp = new int [ 1000 , 1000 ] ; static int solve ( int n , int k , int m ) { if ( n == 0 && k == 0 ) return 1 ; if ( n == 0 && k != 0 ) return 0 ; if ( n != 0 && k == 0 ) return 0 ; if ( n < 0 k < 0 ) return 0 ; if ( dp [ n , k ] > 0 ) return dp [ n , k ] ; int ans = 0 ; for ( int j = 1 ; j <= m ; j ++ ) { ans += solve ( n - j , k - 1 , m ) ; } return dp [ n , k ] = ans ; } public static void Main ( String [ ] args ) { int N = 7 , K = 4 , M = 3 ; Console . Write ( solve ( N , K , M ) ) ; } }

Accumulator variables: ans, j
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class GFG { static void printMatrix ( int [ , ] A ) { for ( int i = 0 ; i < A . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < A . GetLength ( 1 ) ; j ++ ) Console . Write ( A [ i , j ] + " ▁ " ) ; Console . Write ( ' STRNEWLINE ' ) ; } } static int [ , ] getMaxNeighbour ( int [ , ] A , int K ) { int [ , ] ans = A ; for ( int q = 1 ; q <= K ; q ++ ) { for ( int i = 0 ; i < A . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < A . GetLength ( 1 ) ; j ++ ) { int maxi = ans [ i , j ] ; if ( i > 0 ) maxi = Math . Max ( maxi , ans [ i - 1 , j ] ) ; if ( j > 0 ) maxi = Math . Max ( maxi , ans [ i , j - 1 ] ) ; if ( i < A . GetLength ( 0 ) - 1 ) maxi = Math . Max ( maxi , ans [ i + 1 , j ] ) ; if ( j < A . GetLength ( 0 ) - 1 ) maxi = Math . Max ( maxi , ans [ i , j + 1 ] ) ; A [ i , j ] = maxi ; } } ans = A ; } return ans ; } public static void Main ( String [ ] args ) { int [ , ] B = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; printMatrix ( getMaxNeighbour ( B , 2 ) ) ; } }

Accumulator variables: i, j, q
Iterator variables: i, j, q
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > prime = new List < int > ( ) ; static bool [ ] isprime = new bool [ 1000 ] ; static int [ , , ] dp = new int [ 200 , 20 , 1000 ] ; static void sieve ( ) { for ( int i = 0 ; i < 1000 ; i ++ ) isprime [ i ] = true ; for ( int i = 2 ; i * i < 1000 ; i ++ ) { if ( isprime [ i ] ) { for ( int j = i * i ; j < 1000 ; j += i ) { isprime [ j ] = false ; } } } for ( int i = 2 ; i < 1000 ; i ++ ) { if ( isprime [ i ] ) { prime . Add ( i ) ; } } } static int CountWays ( int i , int j , int sum , int n , int k ) { if ( i >= prime . Count - 1 sum > n ) { return 0 ; } if ( sum == n ) { if ( j == k ) { return 1 ; } return 0 ; } if ( j == k ) return 0 ; if ( dp [ i , j , sum ] != 0 ) return dp [ i , j , sum ] ; int inc = 0 , exc = 0 ; inc = CountWays ( i + 1 , j + 1 , sum + prime [ i ] , n , k ) ; exc = CountWays ( i + 1 , j , sum , n , k ) ; return dp [ i , j , sum ] = inc + exc ; } static public void Main ( ) { sieve ( ) ; int N = 100 , K = 5 ; Console . WriteLine ( CountWays ( 0 , 0 , 0 , N , K ) ) ; } }

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 List < List < int > > factors = new List < List < int > > ( ) ; static int [ ] dp ; static void precompute ( ) { for ( int i = 1 ; i <= 100000 ; i ++ ) { for ( int j = i ; j <= 100000 ; j += i ) factors [ j ] . Add ( i ) ; } } static int solve ( int [ ] arr , int n ) { for ( int i = 0 ; i < 100005 ; i ++ ) { dp [ i ] = int . MaxValue ; } dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { foreach ( int j in factors [ arr [ i ] ] ) { if ( i + j < n ) dp [ i + j ] = Math . Min ( dp [ i + j ] , 1 + dp [ i ] ) ; } } return dp [ n - 1 ] ; } static public void Main ( ) { for ( int i = 0 ; i < 100005 ; i ++ ) factors . Add ( new List < int > ( ) ) ; dp = new int [ 100005 ] ; precompute ( ) ; int [ ] arr = { 2 , 8 , 16 , 55 , 99 , 100 } ; int n = arr . Length ; Console . Write ( solve ( arr , n ) ) ; } }

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 [ , ] dp = new int [ 5000 , 1029 ] ; static int getmask ( int val ) { int mask = 0 ; int [ ] prime = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 } ; for ( int i = 0 ; i < 15 ; i ++ ) { if ( val % prime [ i ] == 0 ) { mask = mask | ( 1 << i ) ; } } return mask ; } static int calculate ( int pos , int mask , int [ ] a , int n ) { if ( pos == n || mask == ( int ) ( 1 << n - 1 ) ) return 0 ; if ( dp [ pos , mask ] != - 1 ) return dp [ pos , mask ] ; int size = 0 ; size = Math . Max ( size , calculate ( pos + 1 , mask , a , n ) ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { int new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; size = Math . Max ( size , 1 + calculate ( pos + 1 , new_mask , a , n ) ) ; } return dp [ pos , mask ] = size ; } static int largestSubset ( int [ ] a , int n ) { for ( int i = 0 ; i < 5000 ; i ++ ) { for ( int j = 0 ; j < 1029 ; j ++ ) dp [ i , j ] = - 1 ; } return calculate ( 0 , 0 , a , n ) ; } public static void Main ( ) { int [ ] A = { 2 , 3 , 13 , 5 , 14 , 6 , 7 , 11 } ; int N = A . Length ; Console . WriteLine ( largestSubset ( A , N ) ) ; } }

Index/key variables: i, pos
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MaximumSum ( int [ ] a , int n ) { int [ , ] dp = new int [ n + 1 , 2 ] ; dp [ 2 , 1 ] = a [ 1 ] ; dp [ 2 , 0 ] = a [ 0 ] ; for ( int i = 3 ; i < n + 1 ; i ++ ) { if ( i % 2 == 1 ) { int temp = Math . Max ( ( Math . Max ( dp [ i - 3 , 1 ] , dp [ i - 3 , 0 ] ) ) , Math . Max ( dp [ i - 2 , 1 ] , dp [ i - 2 , 0 ] ) ) ; dp [ i , 1 ] = a [ i - 1 ] + temp ; dp [ i , 0 ] = Math . Max ( ( Math . Max ( a [ i - 2 ] + dp [ i - 2 , 0 ] , a [ i - 2 ] + dp [ i - 3 , 1 ] ) ) , Math . Max ( a [ i - 2 ] + dp [ i - 3 , 0 ] , a [ i - 3 ] + dp [ i - 3 , 0 ] ) ) ; } else { dp [ i , 1 ] = a [ i - 1 ] + ( Math . Max ( ( Math . Max ( dp [ i - 2 , 1 ] , dp [ i - 2 , 0 ] ) ) , dp [ i - 1 , 0 ] ) ) ; dp [ i , 0 ] = a [ i - 2 ] + dp [ i - 2 , 0 ] ; } } return Math . Max ( dp [ n , 1 ] , dp [ n , 0 ] ) ; } static int max ( int [ ] arr ) { return 1 ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = A . Length ; Console . Write ( MaximumSum ( A , N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int divisorGame ( int N , int A , int [ , ] dp ) { if ( N == 1 N == 3 ) return 0 ; if ( N == 2 ) return 1 ; if ( dp [ N , A ] != - 1 ) return dp [ N , A ] ; int ans = ( A == 1 ) ? 0 : 1 ; for ( int i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { if ( A == 1 ) ans |= divisorGame ( N - i , 0 , dp ) ; else ans &= divisorGame ( N - i , 1 , dp ) ; } } return dp [ N , A ] = ans ; } public static void Main ( String [ ] args ) { int N = 3 ; int [ , ] dp = new int [ N + 1 , 2 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { dp [ i , j ] = - 1 ; } } if ( divisorGame ( N , 1 , dp ) == 1 ) { Console . Write ( " Player ▁ A ▁ wins " ) ; } else { Console . Write ( " Player ▁ B ▁ wins " ) ; } } }

Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static int countMountains ( int [ , ] a , int n ) { int [ , ] A = new int [ n + 2 , n + 2 ] ; int count = 0 ; for ( int i = 0 ; i < n + 2 ; i ++ ) { for ( int j = 0 ; j < n + 2 ; j ++ ) { if ( ( i == 0 ) || ( j == 0 ) || ( i == n + 1 ) || ( j == n + 1 ) ) { A [ i , j ] = int . MinValue ; } else { A [ i , j ] = a [ i - 1 , j - 1 ] ; } } } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( ( A [ i , j ] > A [ i - 1 , j ] ) && ( A [ i , j ] > A [ i + 1 , j ] ) && ( A [ i , j ] > A [ i , j - 1 ] ) && ( A [ i , j ] > A [ i , j + 1 ] ) && ( A [ i , j ] > A [ i - 1 , j - 1 ] ) && ( A [ i , j ] > A [ i + 1 , j + 1 ] ) && ( A [ i , j ] > A [ i - 1 , j + 1 ] ) && ( A [ i , j ] > A [ i + 1 , j - 1 ] ) ) { count ++ ; } } } return count ; } public static void Main ( string [ ] args ) { int [ , ] a = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int n = 3 ; Console . WriteLine ( countMountains ( a , n ) ) ; } }

Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int minimalLength ( int [ ] a , int n ) { int [ , ] dp = new int [ n + 1 , n + 1 ] ; int [ ] dp1 = new int [ n ] ; int i , j , k ; for ( i = 0 ; i < n + 1 ; i ++ ) { for ( j = 0 ; j < n + 1 ; j ++ ) { dp [ i , j ] = - 1 ; } } for ( int size = 1 ; size <= n ; size ++ ) { for ( i = 0 ; i < n - size + 1 ; i ++ ) { j = i + size - 1 ; if ( i == j ) dp [ i , j ] = a [ i ] ; else { for ( k = i ; k < j ; k ++ ) { if ( dp [ i , k ] != - 1 && dp [ i , k ] == dp [ k + 1 , j ] ) dp [ i , j ] = dp [ i , k ] + 1 ; } } } } for ( i = 0 ; i < n ; i ++ ) dp1 [ i ] = ( int ) 1e7 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( dp [ j , i ] != - 1 ) { if ( j == 0 ) dp1 [ i ] = 1 ; else dp1 [ i ] = Math . Min ( dp1 [ i ] , dp1 [ j - 1 ] + 1 ) ; } } } return dp1 [ n - 1 ] ; } public static void Main ( string [ ] args ) { int n = 7 ; int [ ] a = { 3 , 3 , 4 , 4 , 4 , 3 , 3 } ; Console . Write ( minimalLength ( a , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, j, k, size
Iterator variables: i, j, k, size
Class/struct names: GFG
C# program:
using System ; public class GFG { static int [ , , ] dp = new int [ 100 , 100 , 100 ] ; static int MaximumScoreDP ( int l , int r , int [ ] prefix_sum , int num ) { if ( l > r ) return 0 ; if ( dp [ l , r , num ] != - 1 ) return dp [ l , r , num ] ; int current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= - 1 ; dp [ l , r , num ] = current_sum + Math . Max ( MaximumScoreDP ( l + 1 , r , prefix_sum , num + 1 ) , MaximumScoreDP ( l , r - 1 , prefix_sum , num + 1 ) ) ; return dp [ l , r , num ] ; } 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 ] ; } for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { for ( int l = 0 ; l < 100 ; l ++ ) dp [ i , j , l ] = - 1 ; } } return MaximumScoreDP ( 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, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; public class GFG { static int [ , , ] memo = new int [ 32 , 2 , 2 ] ; static int dp ( int pos , int fl , int pr , String bin ) { if ( pos == bin . Length ) return 1 ; if ( memo [ pos , fl , pr ] != - 1 ) return memo [ pos , fl , pr ] ; int val = 0 ; if ( bin [ pos ] == '0' ) val = val + dp ( pos + 1 , fl , 0 , bin ) ; else if ( bin [ pos ] == '1' ) val = val + dp ( pos + 1 , 1 , 0 , bin ) ; if ( pr == 0 ) { if ( fl == 1 ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } else if ( bin [ pos ] == '1' ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } } return memo [ pos , fl , pr ] = val ; } static int findints ( int num ) { String bin = " " ; while ( num > 0 ) { if ( num % 2 == 1 ) bin += "1" ; else bin += "0" ; num /= 2 ; } bin = reverse ( bin ) ; for ( int i = 0 ; i < 32 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) memo [ i , j , l ] = - 1 ; } } return dp ( 0 , 0 , 0 , bin ) ; } static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { int N = 12 ; Console . Write ( findints ( N ) ) ; } }

Index/key variables: l, pos, r
Accumulator variables: bin, i, j, l, num, r, val
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int TotalWays ( int n , int s , int k ) { int [ ] dp = new int [ n ] ; dp [ s - 1 ] = 1 ; for ( int i = s ; i < n ; i ++ ) { int idx = Math . Max ( s - 1 , i - k ) ; for ( int j = idx ; j < i ; j ++ ) { dp [ i ] += dp [ j ] ; } } return dp [ n - 1 ] ; } public static void Main ( string [ ] args ) { int n = 5 ; int k = 2 ; int s = 2 ; Console . Write ( " Total ▁ Ways ▁ = ▁ " + TotalWays ( n , s , k ) ) ; } }

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

Index/key variables: i, n
Accumulator variables: i
Class/struct names: GFG