dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int maxLen = 10 ; static int [ ] dp = new int [ maxLen ] ; static bool [ ] v = new bool [ maxLen ] ; static int [ ] prefix_sum = new int [ maxLen ] ; static void findPrefixSum ( int [ ] arr , int n ) { prefix_sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = arr [ i ] + prefix_sum [ i - 1 ] ; } } static int maxSum ( int [ ] arr , int i , int n , int k ) { if ( i + k > n ) { return 0 ; } if ( v [ i ] ) { return dp [ i ] ; } v [ i ] = true ; int x ; if ( i == 0 ) { x = prefix_sum [ k - 1 ] ; } else { x = prefix_sum [ i + k - 1 ] - prefix_sum [ i - 1 ] ; } dp [ i ] = Math . Max ( maxSum ( arr , i + 1 , n , k ) , x + maxSum ( arr , i + k + 1 , n , k ) ) ; return dp [ i ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 7 , 6 } ; int n = arr . Length ; int k = 1 ; findPrefixSum ( arr , n ) ; Console . Write ( maxSum ( arr , 0 , n , k ) ) ; } }

Index/key variables: i, maxLen
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 3 ; static int M = 3 ; static int findMaxSum ( int [ , ] arr ) { int sum = 0 ; int [ , ] b = new int [ N , M ] ; for ( int i = 0 ; i < N ; i ++ ) { b [ i , M - 1 ] = arr [ i , M - 1 ] ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = M - 2 ; j >= 0 ; j -- ) { b [ i , j ] = arr [ i , j ] + b [ i , j + 1 ] ; } } for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { sum = Math . Max ( sum , b [ i , j ] + b [ i - 1 , j ] ) ; b [ i , j ] = Math . Max ( b [ i , j ] , b [ i - 1 , j ] + arr [ i , j ] ) ; } } return sum ; } public static void Main ( ) { int [ , ] arr = { { 3 , 7 , 4 } , { 1 , 9 , 6 } , { 1 , 7 , 7 } } ; Console . WriteLine ( findMaxSum ( arr ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int mod = 3803 ; static int d = 26 ; static int hash_b ; static int [ ] hash_a ; static int [ ] mul ; static int mi ( int x ) { int p = mod - 2 ; int s = 1 ; while ( p != 1 ) { if ( p % 2 == 1 ) { s = ( s * x ) % mod ; } x = ( x * x ) % mod ; p /= 2 ; } return ( s * x ) % mod ; } static void genHash ( char [ ] a , char [ ] b ) { hash_a = new int [ a . Length ] ; mul = new int [ a . Length ] ; for ( int i = b . Length - 1 ; i >= 0 ; i -- ) { hash_b = ( hash_b * d + ( b [ i ] - 97 ) ) % mod ; } mul [ 0 ] = 1 ; hash_a [ 0 ] = ( a [ 0 ] - 97 ) % mod ; for ( int i = 1 ; i < a . Length ; i ++ ) { mul [ i ] = ( mul [ i - 1 ] * d ) % mod ; hash_a [ i ] = ( hash_a [ i - 1 ] + mul [ i ] * ( a [ i ] - 97 ) ) % mod ; } } static Boolean checkEqual ( int i , int len_a , int len_b ) { int x ; if ( i == 0 ) { x = hash_a [ len_b - 1 ] ; } else { x = ( hash_a [ i + len_b - 1 ] - hash_a [ i - 1 ] + 2 * mod ) % mod ; x = ( x * mi ( mul [ i ] ) ) % mod ; } if ( x == hash_b ) { return true ; } return false ; } public static void Main ( String [ ] args ) { String a = " abababababa " ; String b = " aba " ; genHash ( a . ToCharArray ( ) , b . ToCharArray ( ) ) ; int [ ] queries = { 0 , 1 , 2 , 3 } ; int q = queries . Length ; for ( int i = 0 ; i < q ; i ++ ) { if ( checkEqual ( queries [ i ] , a . Length , b . Length ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } } }

Index/key variables: i
Accumulator variables: i, p
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int max_size = 20 ; static int max_k = 20 ; static int [ , ] dp = new int [ max_size , max_k ] ; static Boolean [ , ] v = new Boolean [ max_size , max_k ] ; static int sum = 0 ; static void findSum ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; } static int cntWays ( int [ ] arr , int i , int ck , int k , int n , int curr_sum ) { if ( sum % k != 0 ) return 0 ; if ( i != n && ck == k + 1 ) return 0 ; if ( i == n ) { if ( ck == k + 1 ) return 1 ; else return 0 ; } if ( v [ i , ck ] ) return dp [ i , ck ] ; curr_sum += arr [ i ] ; v [ i , ck ] = true ; dp [ i , ck ] = cntWays ( arr , i + 1 , ck , k , n , curr_sum ) ; if ( curr_sum == ( sum / k ) * ck ) dp [ i , ck ] += cntWays ( arr , i + 1 , ck + 1 , k , n , curr_sum ) ; return dp [ i , ck ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , - 1 , 1 , - 1 , 1 , - 1 } ; int n = arr . Length ; int k = 2 ; findSum ( arr , n ) ; Console . WriteLine ( cntWays ( arr , 0 , 1 , k , n , 0 ) ) ; } }

Index/key variables: i
Accumulator variables: curr_sum, i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int arrSize = 51 ; static int [ ] dp = new int [ arrSize ] ; static bool [ ] v = new bool [ arrSize ] ; static int sumMax ( int i , int [ ] arr , int n ) { if ( i >= n - 1 ) return 0 ; if ( v [ i ] ) return dp [ i ] ; v [ i ] = true ; dp [ i ] = Math . Max ( arr [ i ] + arr [ i + 1 ] + sumMax ( i + 3 , arr , n ) , sumMax ( i + 1 , arr , n ) ) ; return dp [ i ] ; } public static void Main ( ) { int [ ] arr = { 1 , 1 , 1 , 1 } ; int n = arr . Length ; Console . WriteLine ( sumMax ( 0 , arr , n ) ) ; } }

Index/key variables: arrSize, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MaxIncreasingSub ( int [ ] arr , int n , int k ) { int [ , ] dp = new int [ n , k + 1 ] ; int ans = - 1 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < k + 1 ; j ++ ) dp [ i , j ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i , 1 ] = arr [ i ] ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { for ( int l = 1 ; l <= k - 1 ; l ++ ) { if ( dp [ j , l ] != - 1 ) { dp [ i , l + 1 ] = Math . Max ( dp [ i , l + 1 ] , dp [ j , l ] + arr [ i ] ) ; } } } } } for ( int i = 0 ; i < n ; i ++ ) { if ( ans < dp [ i , k ] ) ans = dp [ i , k ] ; } return ( ans == - 1 ) ? 0 : ans ; } public static void Main ( String [ ] args ) { int n = 8 , k = 3 ; int [ ] arr = { 8 , 5 , 9 , 10 , 5 , 6 , 21 , 8 } ; int ans = MaxIncreasingSub ( arr , n , k ) ; Console . WriteLine ( ans ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ ] dp = new int [ 200 ] ; static void print ( int idx ) { for ( int i = 1 ; i < idx ; i ++ ) { Console . Write ( dp [ i ] + " ▁ " ) ; } Console . WriteLine ( " " ) ; } static void solve ( int remSum , int maxVal , int idx , int count ) { if ( remSum == 0 ) { print ( idx ) ; count ++ ; return ; } for ( int i = maxVal ; i >= 1 ; i -- ) { if ( i > remSum ) { continue ; } else if ( i <= remSum ) { dp [ idx ] = i ; solve ( remSum - i , i , idx + 1 , count ) ; } } } public static void Main ( ) { int n = 4 , count = 0 ; solve ( n , n , 1 , count ) ; } }

Index/key variables: i, idx
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int bitscount = 32 ; static int n = 3 ; static int [ , , ] prefix_count = new int [ bitscount , n , n ] ; static void findPrefixCount ( int [ , ] arr ) { for ( int i = 0 ; i < bitscount ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { prefix_count [ i , j , 0 ] = ( ( arr [ j , 0 ] >> i ) & 1 ) ; for ( int k = 1 ; k < n ; k ++ ) { prefix_count [ i , j , k ] = ( ( arr [ j , k ] >> i ) & 1 ) ; prefix_count [ i , j , k ] += prefix_count [ i , j , k - 1 ] ; } } } for ( int i = 0 ; i < bitscount ; i ++ ) for ( int j = 1 ; j < n ; j ++ ) for ( int k = 0 ; k < n ; k ++ ) prefix_count [ i , j , k ] += prefix_count [ i , j - 1 , k ] ; } static int rangeOr ( int x1 , int y1 , int x2 , int y2 ) { int ans = 0 ; for ( int i = 0 ; i < bitscount ; i ++ ) { int p ; if ( x1 == 0 && y1 == 0 ) p = prefix_count [ i , x2 , y2 ] ; else if ( x1 == 0 ) p = prefix_count [ i , x2 , y2 ] - prefix_count [ i , x2 , y1 - 1 ] ; else if ( y1 == 0 ) p = prefix_count [ i , x2 , y2 ] - prefix_count [ i , x1 - 1 , y2 ] ; else p = prefix_count [ i , x2 , y2 ] - prefix_count [ i , x1 - 1 , y2 ] - prefix_count [ i , x2 , y1 - 1 ] + prefix_count [ i , x1 - 1 , y1 - 1 ] ; if ( p != 0 ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; findPrefixCount ( arr ) ; int [ , ] queries = { { 1 , 1 , 1 , 1 } , { 1 , 2 , 2 , 2 } } ; int q = queries . GetLength ( 0 ) ; for ( int i = 0 ; i < q ; i ++ ) Console . WriteLine ( rangeOr ( queries [ i , 0 ] , queries [ i , 1 ] , queries [ i , 2 ] , queries [ i , 3 ] ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int bitscount = 32 ; static int n = 3 ; static int [ , , ] prefix_count = new int [ bitscount , n , n ] ; static void findPrefixCount ( int [ , ] arr ) { for ( int i = 0 ; i < bitscount ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { prefix_count [ i , j , 0 ] = ( ( arr [ j , 0 ] >> i ) & 1 ) ; for ( int k = 1 ; k < n ; k ++ ) { prefix_count [ i , j , k ] = ( ( arr [ j , k ] >> i ) & 1 ) ; prefix_count [ i , j , k ] += prefix_count [ i , j , k - 1 ] ; } } } for ( int i = 0 ; i < bitscount ; i ++ ) for ( int j = 1 ; j < n ; j ++ ) for ( int k = 0 ; k < n ; k ++ ) prefix_count [ i , j , k ] += prefix_count [ i , j - 1 , k ] ; } static int rangeAnd ( int x1 , int y1 , int x2 , int y2 ) { int ans = 0 ; for ( int i = 0 ; i < bitscount ; i ++ ) { int p ; if ( x1 == 0 && y1 == 0 ) p = prefix_count [ i , x2 , y2 ] ; else if ( x1 == 0 ) p = prefix_count [ i , x2 , y2 ] - prefix_count [ i , x2 , y1 - 1 ] ; else if ( y1 == 0 ) p = prefix_count [ i , x2 , y2 ] - prefix_count [ i , x1 - 1 , y2 ] ; else p = prefix_count [ i , x2 , y2 ] - prefix_count [ i , x1 - 1 , y2 ] - prefix_count [ i , x2 , y1 - 1 ] + prefix_count [ i , x1 - 1 , y1 - 1 ] ; if ( p == ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; findPrefixCount ( arr ) ; int [ , ] queries = { { 1 , 1 , 1 , 1 } , { 1 , 2 , 2 , 2 } } ; int q = queries . GetLength ( 0 ) ; for ( int i = 0 ; i < q ; i ++ ) Console . WriteLine ( rangeAnd ( queries [ i , 0 ] , queries [ i , 1 ] , queries [ i , 2 ] , queries [ i , 3 ] ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxLen = 10 ; static int [ ] dp = new int [ maxLen ] ; static bool [ ] v = new bool [ maxLen ] ; static int maxSum ( int [ ] arr , int i , int n ) { if ( i >= n ) return 0 ; if ( v [ i ] ) return dp [ i ] ; v [ i ] = true ; dp [ i ] = Math . Max ( maxSum ( arr , i + 1 , n ) , arr [ i ] + maxSum ( arr , i + 2 , n ) ) ; return dp [ i ] ; } public static void Main ( ) { int [ ] arr = { 12 , 9 , 7 , 33 } ; int n = arr . Length ; Console . Write ( maxSum ( arr , 0 , n ) ) ; } }

Index/key variables: i, maxLen
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static int [ , ] memo = new int [ MAX , MAX ] ; static int oSRec ( int [ ] arr , int i , int j , int sum ) { if ( j == i + 1 ) return Math . Max ( arr [ i ] , arr [ j ] ) ; if ( memo [ i , j ] != - 1 ) return memo [ i , j ] ; memo [ i , j ] = Math . Max ( ( sum - oSRec ( arr , i + 1 , j , sum - arr [ i ] ) ) , ( sum - oSRec ( arr , i , j - 1 , sum - arr [ j ] ) ) ) ; return memo [ i , j ] ; } static int accumulate ( int [ ] arr , int start , int end ) { int sum = 0 ; for ( int i = 0 ; i < arr . Length ; i ++ ) sum += arr [ i ] ; return sum ; } static int optimalStrategyOfGame ( int [ ] arr , int n ) { int sum = 0 ; sum = accumulate ( arr , 0 , n ) ; for ( int j = 0 ; j < MAX ; j ++ ) { for ( int k = 0 ; k < MAX ; k ++ ) memo [ j , k ] = - 1 ; } return oSRec ( arr , 0 , n - 1 , sum ) ; } public static void Main ( String [ ] args ) { int [ ] arr1 = { 8 , 15 , 3 , 7 } ; int n = arr1 . Length ; Console . Write ( " { 0 } STRNEWLINE " , optimalStrategyOfGame ( arr1 , n ) ) ; int [ ] arr2 = { 2 , 2 , 2 , 2 } ; n = arr2 . Length ; Console . Write ( " { 0 } STRNEWLINE " , optimalStrategyOfGame ( arr2 , n ) ) ; int [ ] arr3 = { 20 , 30 , 2 , 2 , 2 , 10 } ; n = arr3 . Length ; Console . Write ( " { 0 } STRNEWLINE " , optimalStrategyOfGame ( arr3 , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 5 ; static int func ( int idx , int cur , int [ ] a , int [ , ] dp , int n , int x ) { if ( idx == n ) { return 0 ; } if ( dp [ idx , cur ] != - 1 ) { return dp [ idx , cur ] ; } int ans = 0 ; if ( cur == 0 ) { ans = Math . Max ( ans , a [ idx ] + func ( idx + 1 , 0 , a , dp , n , x ) ) ; ans = Math . Max ( ans , x * a [ idx ] + func ( idx + 1 , 1 , a , dp , n , x ) ) ; } else if ( cur == 1 ) { ans = Math . Max ( ans , x * a [ idx ] + func ( idx + 1 , 1 , a , dp , n , x ) ) ; ans = Math . Max ( ans , a [ idx ] + func ( idx + 1 , 2 , a , dp , n , x ) ) ; } { ans = Math . Max ( ans , a [ idx ] + func ( idx + 1 , 2 , a , dp , n , x ) ) ; } return dp [ idx , cur ] = ans ; } static int getMaximumSum ( int [ ] a , int n , int x ) { int [ , ] dp = new int [ n , 3 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { dp [ i , j ] = - 1 ; } } int maxi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { maxi = Math . Max ( maxi , func ( i , 0 , a , dp , n , x ) ) ; } return maxi ; } public static void Main ( String [ ] args ) { int [ ] a = { - 3 , 8 , - 2 , 1 , - 6 } ; int n = a . Length ; int x = - 1 ; Console . WriteLine ( getMaximumSum ( a , n , x ) ) ; } }

Index/key variables: idx
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 100 ; static void pre_process ( bool [ , ] dp , char [ ] s ) { int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i , j ] = false ; } } for ( int j = 1 ; j <= n ; j ++ ) { for ( int i = 0 ; i <= n - j ; i ++ ) { if ( j <= 2 ) { if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i , i + j - 1 ] = true ; } } else if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i , i + j - 1 ] = dp [ i + 1 , i + j - 2 ] ; } } } } static int countPairs ( String s ) { bool [ , ] dp = new bool [ N , N ] ; pre_process ( dp , s . ToCharArray ( ) ) ; int n = s . Length ; int [ ] left = new int [ n ] ; int [ ] right = new int [ n ] ; left [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( dp [ j , i ] == true ) { left [ i ] ++ ; } } } right [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { right [ i ] = right [ i + 1 ] ; for ( int j = n - 1 ; j >= i ; j -- ) { if ( dp [ i , j ] == true ) { right [ i ] ++ ; } } } int ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans += left [ i ] * right [ i + 1 ] ; } return ans ; } public static void Main ( String [ ] args ) { String s = " abacaba " ; Console . Write ( countPairs ( s ) ) ; } }

Index/key variables: i, n
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 100 ; static void pre_process ( bool [ , ] dp , char [ ] s ) { int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i , j ] = false ; } } for ( int j = 1 ; j <= n ; j ++ ) { for ( int i = 0 ; i <= n - j ; i ++ ) { if ( j <= 2 ) { if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i , i + j - 1 ] = true ; } } else if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i , i + j - 1 ] = dp [ i + 1 , i + j - 2 ] ; } } } } static void answerQuery ( int l , int r , bool [ , ] dp ) { if ( dp [ l , r ] ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } public static void Main ( ) { string s = " abaaab " ; bool [ , ] dp = new bool [ N , N ] ; pre_process ( dp , s . ToCharArray ( ) ) ; int [ , ] queries = { { 0 , 1 } , { 1 , 5 } } ; int q = queries . Length ; for ( int i = 0 ; i < q ; i ++ ) { answerQuery ( queries [ i , 0 ] , queries [ i , 1 ] , dp ) ; } } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 100005 ; static int LIS ( int [ ] a , int n ) { int [ ] dp = new int [ N ] ; int [ ] d = new int [ N ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { dp [ a [ i ] ] = 1 ; for ( int j = 2 ; j * j <= a [ i ] ; j ++ ) { if ( a [ i ] % j == 0 ) { dp [ a [ i ] ] = Math . Max ( dp [ a [ i ] ] , dp [ d [ j ] ] + 1 ) ; dp [ a [ i ] ] = Math . Max ( dp [ a [ i ] ] , dp [ d [ a [ i ] / j ] ] + 1 ) ; d [ j ] = a [ i ] ; d [ a [ i ] / j ] = a [ i ] ; } } ans = Math . Max ( ans , dp [ a [ i ] ] ) ; d [ a [ i ] ] = a [ i ] ; } return ans ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = a . Length ; Console . WriteLine ( LIS ( a , 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 bool check ( String s ) { int n = s . Length ; for ( int i = 2 ; i < n ; i ++ ) { if ( s [ i ] == '1' && s [ i - 1 ] == '1' && s [ i - 2 ] == '1' ) return true ; } return false ; } static int countStr ( int i , String s ) { if ( i < 0 ) { if ( check ( s ) ) return 1 ; return 0 ; } char [ ] myNameChars = s . ToCharArray ( ) ; myNameChars [ i ] = '0' ; s = String . Join ( " " , myNameChars ) ; int ans = countStr ( i - 1 , s ) ; char [ ] myChar = s . ToCharArray ( ) ; myChar [ i ] = '1' ; s = String . Join ( " " , myChar ) ; ans += countStr ( i - 1 , s ) ; char [ ] myChar1 = s . ToCharArray ( ) ; myChar1 [ i ] = '0' ; s = String . Join ( " " , myChar1 ) ; return ans ; } public static void Main ( String [ ] args ) { int N = 4 ; String s = "0000" ; Console . WriteLine ( countStr ( N - 1 , s ) ) ; } }

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

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
class GFG { static int findSum ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 1 ] = 1 ; dp [ 0 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] = ( 4 * ( i * i ) ) - 6 * ( i - 1 ) + dp [ i - 2 ] ; } return dp [ n ] ; } static void Main ( ) { int n = 4 ; System . Console . WriteLine ( findSum ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; class GFG { public static void dfs ( int node , int parent , int [ ] dp1 , int [ ] dp2 , ArrayList [ ] adj , int [ ] tree ) { int sum1 = 0 , sum2 = 0 ; foreach ( int i in adj [ node ] ) { if ( i == parent ) continue ; dfs ( i , node , dp1 , dp2 , adj , tree ) ; sum1 += dp2 [ i ] ; sum2 += Math . Max ( dp1 [ i ] , dp2 [ i ] ) ; } dp1 [ node ] = tree [ node ] + sum1 ; dp2 [ node ] = sum2 ; } public static void Main ( string [ ] arg ) { int n = 5 ; ArrayList [ ] adj = new ArrayList [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { adj [ i ] = new ArrayList ( ) ; } adj [ 1 ] . Add ( 2 ) ; adj [ 2 ] . Add ( 1 ) ; adj [ 1 ] . Add ( 3 ) ; adj [ 3 ] . Add ( 1 ) ; adj [ 2 ] . Add ( 4 ) ; adj [ 4 ] . Add ( 2 ) ; adj [ 2 ] . Add ( 5 ) ; adj [ 5 ] . Add ( 2 ) ; int [ ] tree = new int [ n + 1 ] ; tree [ 1 ] = 10 ; tree [ 2 ] = 5 ; tree [ 3 ] = 11 ; tree [ 4 ] = 6 ; tree [ 5 ] = 8 ; int [ ] dp1 = new int [ n + 1 ] ; int [ ] dp2 = new int [ n + 1 ] ; Array . Fill ( dp1 , 0 ) ; Array . Fill ( dp2 , 0 ) ; dfs ( 1 , 1 , dp1 , dp2 , adj , tree ) ; Console . Write ( " Maximum ▁ sum : ▁ " + Math . Max ( dp1 [ 1 ] , dp2 [ 1 ] ) ) ; } }

Index/key variables: i, node
Accumulator variables: i, sum1, sum2
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int n = 3 ; static int MAX = 30 ; static int [ , , ] dp = new int [ n , n , MAX ] ; static bool [ , , ] v = new bool [ n , n , MAX ] ; static int findCount ( int [ , ] mat , int i , int j , int m ) { if ( i == 0 && j == 0 ) { if ( m == mat [ 0 , 0 ] ) return 1 ; else return 0 ; } if ( m < 0 ) return 0 ; if ( i < 0 j < 0 ) return 0 ; if ( v [ i , j , m ] ) return dp [ i , j , m ] ; v [ i , j , m ] = true ; dp [ i , j , m ] = findCount ( mat , i - 1 , j , m - mat [ i , j ] ) + findCount ( mat , i , j - 1 , m - mat [ i , j ] ) ; return dp [ i , j , m ] ; } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ; int m = 5 ; Console . WriteLine ( findCount ( mat , n - 1 , n - 1 , m ) ) ; } }

Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static int mod = 1000000007 ; static int RUNMAX = 300 ; static int BALLMAX = 50 ; static int WICKETMAX = 10 ; static int CountWays ( int r , int b , int l , int R , int B , int W , int [ , , ] dp ) { if ( l > W ) return 0 ; if ( r > R ) return 0 ; if ( b == B && r == R ) return 1 ; if ( b == B ) return 0 ; if ( dp [ r , b , l ] != - 1 ) return dp [ r , b , l ] ; int ans = 0 ; ans += CountWays ( r , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 1 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 2 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 3 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 4 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 6 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r , b + 1 , l + 1 , R , B , W , dp ) ; ans = ans % mod ; return dp [ r , b , l ] = ans ; } static void Main ( ) { int R = 40 , B = 10 , W = 4 ; int [ , , ] dp = new int [ RUNMAX , BALLMAX , WICKETMAX ] ; for ( int i = 0 ; i < RUNMAX ; i ++ ) for ( int j = 0 ; j < BALLMAX ; j ++ ) for ( int k = 0 ; k < WICKETMAX ; k ++ ) dp [ i , j , k ] = - 1 ; Console . WriteLine ( CountWays ( 0 , 0 , 0 , R , B , W , dp ) ) ; } }

Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 10 ; static int findMinimumDeletion ( int l , int r , int [ , ] dp , String s ) { if ( l > r ) { return 0 ; } if ( l == r ) { return 1 ; } if ( dp [ l , r ] != - 1 ) { return dp [ l , r ] ; } int res = 1 + findMinimumDeletion ( l + 1 , r , dp , s ) ; for ( int i = l + 1 ; i <= r ; ++ i ) { if ( s [ l ] == s [ i ] ) { res = Math . Min ( res , findMinimumDeletion ( l + 1 , i - 1 , dp , s ) + findMinimumDeletion ( i , r , dp , s ) ) ; } } return dp [ l , r ] = res ; } public static void Main ( String [ ] args ) { String s = " abcddcba " ; int n = s . Length ; int [ , ] dp = new int [ N , N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { dp [ i , j ] = - 1 ; } } Console . WriteLine ( findMinimumDeletion ( 0 , n - 1 , dp , s ) ) ; } }

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