dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int MAX = 100 ; static int [ , ] dp = new int [ MAX , MAX ] ; static int largestZigZagSumRec ( int [ , ] mat , int i , int j , int n ) { if ( dp [ i , j ] != - 1 ) return dp [ i , j ] ; if ( i == n - 1 ) return ( dp [ i , j ] = mat [ i , j ] ) ; int zzs = 0 ; for ( int k = 0 ; k < n ; k ++ ) if ( k != j ) zzs = Math . Max ( zzs , largestZigZagSumRec ( mat , i + 1 , k , n ) ) ; return ( dp [ i , j ] = ( zzs + mat [ i , j ] ) ) ; } static int largestZigZag ( int [ , ] mat , int n ) { for ( int i = 0 ; i < MAX ; i ++ ) for ( int k = 0 ; k < MAX ; k ++ ) dp [ i , k ] = - 1 ; int res = 0 ; for ( int j = 0 ; j < n ; j ++ ) res = Math . Max ( res , largestZigZagSumRec ( mat , 0 , j , n ) ) ; return res ; } public static void Main ( String [ ] args ) { int n = 3 ; int [ , ] mat = { { 4 , 2 , 1 } , { 3 , 9 , 6 } , { 11 , 3 , 15 } } ; Console . Write ( " Largest ▁ zigzag ▁ sum : ▁ " + largestZigZag ( mat , n ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; public class GFG { static int countSubsequences ( String s ) { int aCount = 0 ; int bCount = 0 ; int cCount = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == ' a ' ) aCount = ( 1 + 2 * aCount ) ; else if ( s [ i ] == ' b ' ) bCount = ( aCount + 2 * bCount ) ; else if ( s [ i ] == ' c ' ) cCount = ( bCount + 2 * cCount ) ; } return cCount ; } public static void Main ( ) { String s = " abbc " ; Console . Write ( countSubsequences ( s ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) { int [ ] maxRev = new int [ m + 1 ] ; for ( int i = 0 ; i < m + 1 ; i ++ ) maxRev [ i ] = 0 ; int nxtbb = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { if ( nxtbb < n ) { if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ; else { if ( i <= t ) maxRev [ i ] = Math . Max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ; else maxRev [ i ] = Math . Max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ; nxtbb ++ ; } } else maxRev [ i ] = maxRev [ i - 1 ] ; } return maxRev [ m ] ; } static void Main ( ) { int m = 20 ; int [ ] x = new int [ ] { 6 , 7 , 12 , 13 , 14 } ; int [ ] revenue = new int [ ] { 5 , 6 , 5 , 3 , 1 } ; int n = x . Length ; int t = 5 ; Console . Write ( maxRevenue ( m , x , revenue , n , t ) ) ; } }

Index/key variables: i, m, nxtbb
Accumulator variables: i, nxtbb
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int Row = 6 , Col = 6 ; static int largestKSubmatrix ( int [ , ] a ) { int [ , ] dp = new int [ Row , Col ] ; int result = 0 ; for ( int i = 0 ; i < Row ; i ++ ) { for ( int j = 0 ; j < Col ; j ++ ) { if ( i == 0 j == 0 ) dp [ i , j ] = 1 ; else { if ( a [ i , j ] == a [ i - 1 , j ] && a [ i , j ] == a [ i , j - 1 ] && a [ i , j ] == a [ i - 1 , j - 1 ] ) { dp [ i , j ] = ( dp [ i - 1 , j ] > dp [ i , j - 1 ] && dp [ i - 1 , j ] > dp [ i - 1 , j - 1 ] + 1 ) ? dp [ i - 1 , j ] : ( dp [ i , j - 1 ] > dp [ i - 1 , j ] && dp [ i , j - 1 ] > dp [ i - 1 , j - 1 ] + 1 ) ? dp [ i , j - 1 ] : dp [ i - 1 , j - 1 ] + 1 ; } else dp [ i , j ] = 1 ; } result = result > dp [ i , j ] ? result : dp [ i , j ] ; } } return result ; } public static void Main ( ) { int [ , ] a = { { 2 , 2 , 3 , 3 , 4 , 4 } , { 5 , 5 , 7 , 7 , 7 , 4 } , { 1 , 2 , 7 , 7 , 7 , 4 } , { 4 , 4 , 7 , 7 , 7 , 4 } , { 5 , 5 , 5 , 1 , 2 , 7 } , { 8 , 7 , 9 , 4 , 4 , 4 } } ; Console . Write ( largestKSubmatrix ( a ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countDivisibleSubseq ( string str , int n ) { int len = str . Length ; int [ , ] dp = new int [ len , n ] ; dp [ 0 , ( str [ 0 ] - '0' ) % n ] ++ ; for ( int i = 1 ; i < len ; i ++ ) { dp [ i , ( str [ i ] - '0' ) % n ] ++ ; for ( int j = 0 ; j < n ; j ++ ) { dp [ i , j ] += dp [ i - 1 , j ] ; dp [ i , ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 , j ] ; } } return dp [ len - 1 , 0 ] ; } public static void Main ( ) { String str = "1234" ; int n = 4 ; Console . Write ( countDivisibleSubseq ( str , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static double [ ] fact ; public static double probability ( int k , int n ) { double ans = 0 ; for ( int i = k ; i <= n ; ++ i ) ans += fact [ n ] / ( fact [ i ] * fact [ n - i ] ) ; ans = ans / ( 1 << n ) ; return ans ; } public static void precompute ( ) { fact [ 0 ] = fact [ 1 ] = 1 ; for ( int i = 2 ; i < 20 ; ++ i ) fact [ i ] = fact [ i - 1 ] * i ; } public static void Main ( ) { fact = new double [ 100 ] ; precompute ( ) ; Console . WriteLine ( probability ( 2 , 3 ) ) ; Console . WriteLine ( probability ( 3 , 6 ) ) ; Console . Write ( probability ( 12 , 18 ) ) ; } }

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

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

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int l = 3 ; static int m = 3 ; static int n = 3 ; static int min ( int x , int y , int z ) { return ( x < y ) ? ( ( x < z ) ? x : z ) : ( ( y < z ) ? y : z ) ; } static int minPathSum ( int [ , , ] arr ) { int i , j , k ; int [ , , ] tSum = new int [ l , m , n ] ; tSum [ 0 , 0 , 0 ] = arr [ 0 , 0 , 0 ] ; for ( i = 1 ; i < l ; i ++ ) tSum [ i , 0 , 0 ] = tSum [ i - 1 , 0 , 0 ] + arr [ i , 0 , 0 ] ; for ( j = 1 ; j < m ; j ++ ) tSum [ 0 , j , 0 ] = tSum [ 0 , j - 1 , 0 ] + arr [ 0 , j , 0 ] ; for ( k = 1 ; k < n ; k ++ ) tSum [ 0 , 0 , k ] = tSum [ 0 , 0 , k - 1 ] + arr [ 0 , 0 , k ] ; for ( i = 1 ; i < l ; i ++ ) for ( j = 1 ; j < m ; j ++ ) tSum [ i , j , 0 ] = min ( tSum [ i - 1 , j , 0 ] , tSum [ i , j - 1 , 0 ] , int . MaxValue ) + arr [ i , j , 0 ] ; for ( i = 1 ; i < l ; i ++ ) for ( k = 1 ; k < n ; k ++ ) tSum [ i , 0 , k ] = min ( tSum [ i - 1 , 0 , k ] , tSum [ i , 0 , k - 1 ] , int . MaxValue ) + arr [ i , 0 , k ] ; for ( k = 1 ; k < n ; k ++ ) for ( j = 1 ; j < m ; j ++ ) tSum [ 0 , j , k ] = min ( tSum [ 0 , j , k - 1 ] , tSum [ 0 , j - 1 , k ] , int . MaxValue ) + arr [ 0 , j , k ] ; for ( i = 1 ; i < l ; i ++ ) for ( j = 1 ; j < m ; j ++ ) for ( k = 1 ; k < n ; k ++ ) tSum [ i , j , k ] = min ( tSum [ i - 1 , j , k ] , tSum [ i , j - 1 , k ] , tSum [ i , j , k - 1 ] ) + arr [ i , j , k ] ; return tSum [ l - 1 , m - 1 , n - 1 ] ; } static public void Main ( ) { int [ , , ] arr = { { { 1 , 2 , 4 } , { 3 , 4 , 5 } , { 5 , 2 , 1 } } , { { 4 , 8 , 3 } , { 5 , 2 , 1 } , { 3 , 4 , 2 } } , { { 2 , 4 , 1 } , { 3 , 1 , 4 } , { 6 , 3 , 8 } } } ; Console . WriteLine ( minPathSum ( arr ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxPathSum ( int [ , ] tri , int m , int n ) { for ( int i = m - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( tri [ i + 1 , j ] > tri [ i + 1 , j + 1 ] ) tri [ i , j ] += tri [ i + 1 , j ] ; else tri [ i , j ] += tri [ i + 1 , j + 1 ] ; } } return tri [ 0 , 0 ] ; } public static void Main ( ) { int [ , ] tri = { { 1 , 0 , 0 } , { 4 , 8 , 0 } , { 1 , 5 , 3 } } ; Console . Write ( maxPathSum ( tri , 2 , 2 ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static int MaxDotProduct ( int [ ] A , int [ ] B , int m , int n ) { int [ , ] dp = new int [ n + 1 , m + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = i ; j <= m ; j ++ ) dp [ i , j ] = Math . Max ( ( dp [ i - 1 , j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i , j - 1 ] ) ; return dp [ n , m ] ; } public static void Main ( ) { int [ ] A = { 2 , 3 , 1 , 7 , 8 } ; int [ ] B = { 3 , 6 , 7 } ; int m = A . Length ; int n = B . Length ; Console . Write ( MaxDotProduct ( A , B , m , n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static string X = " AGGT12" ; static string Y = "12TXAYB " ; static string Z = "12XBA " ; static int [ , , ] dp = new int [ 100 , 100 , 100 ] ; static int lcsOf3 ( int i , int j , int k ) { if ( i == - 1 j == - 1 k == - 1 ) return 0 ; if ( dp [ i , j , k ] != - 1 ) return dp [ i , j , k ] ; if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i , j , k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ; else return dp [ i , j , k ] = Math . Max ( Math . Max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ; } static void Main ( ) { for ( int i = 0 ; i < 100 ; i ++ ) for ( int j = 0 ; j < 100 ; j ++ ) for ( int k = 0 ; k < 100 ; k ++ ) dp [ i , j , k ] = - 1 ; int m = X . Length ; int n = Y . Length ; int o = Z . Length ; Console . Write ( " Length ▁ of ▁ LCS ▁ is ▁ " + lcsOf3 ( m - 1 , n - 1 , o - 1 ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 102 ; static int countMin ( int [ ] arr , int [ , , ] dp , int n , int dec , int inc , int i ) { if ( dp [ dec , inc , i ] != - 1 ) return dp [ dec , inc , i ] ; if ( i == n ) return 0 ; if ( arr [ i ] < arr [ dec ] ) dp [ dec , inc , i ] = countMin ( arr , dp , n , i , inc , i + 1 ) ; if ( arr [ i ] > arr [ inc ] ) { if ( dp [ dec , inc , i ] == - 1 ) dp [ dec , inc , i ] = countMin ( arr , dp , n , dec , i , i + 1 ) ; else dp [ dec , inc , i ] = Math . Min ( countMin ( arr , dp , n , dec , i , i + 1 ) , dp [ dec , inc , i ] ) ; } if ( dp [ dec , inc , i ] == - 1 ) dp [ dec , inc , i ] = 1 + countMin ( arr , dp , n , dec , inc , i + 1 ) ; else dp [ dec , inc , i ] = Math . Min ( 1 + countMin ( arr , dp , n , dec , inc , i + 1 ) , dp [ dec , inc , i ] ) ; return dp [ dec , inc , i ] ; } static int wrapper ( int [ ] arr , int n ) { arr [ MAX - 2 ] = int . MaxValue ; arr [ MAX - 1 ] = int . MinValue ; int [ , , ] dp = new int [ MAX , MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) for ( int k = 0 ; k < MAX ; k ++ ) dp [ i , j , k ] = - 1 ; return countMin ( arr , dp , n , MAX - 2 , MAX - 1 , 0 ) ; } static void Main ( ) { int n = 12 ; int [ ] arr = new int [ MAX ] ; arr [ 0 ] = 7 ; arr [ 1 ] = 8 ; arr [ 2 ] = 1 ; arr [ 3 ] = 2 ; arr [ 4 ] = 4 ; arr [ 5 ] = 6 ; arr [ 6 ] = 3 ; arr [ 7 ] = 5 ; arr [ 8 ] = 2 ; arr [ 9 ] = 1 ; arr [ 10 ] = 8 ; arr [ 11 ] = 7 ; Console . Write ( wrapper ( arr , n ) ) ; } }

Index/key variables: MAX, dec, i, inc
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void distSumRec ( int [ ] arr , int n , int sum , int currindex , HashSet < int > s ) { if ( currindex > n ) return ; if ( currindex == n ) { s . Add ( sum ) ; return ; } distSumRec ( arr , n , sum + arr [ currindex ] , currindex + 1 , s ) ; distSumRec ( arr , n , sum , currindex + 1 , s ) ; } static void printDistSum ( int [ ] arr , int n ) { HashSet < int > s = new HashSet < int > ( ) ; distSumRec ( arr , n , 0 , 0 , s ) ; foreach ( int i in s ) Console . Write ( i + " ▁ " ) ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . Length ; printDistSum ( arr , n ) ; } }

Index/key variables: currindex
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void printDistSum ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; bool [ , ] dp = new bool [ n + 1 , sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i , 0 ] = true ; for ( int i = 1 ; i <= n ; i ++ ) { dp [ i , arr [ i - 1 ] ] = true ; for ( int j = 1 ; j <= sum ; j ++ ) { if ( dp [ i - 1 , j ] == true ) { dp [ i , j ] = true ; dp [ i , j + arr [ i - 1 ] ] = true ; } } } for ( int j = 0 ; j <= sum ; j ++ ) if ( dp [ n , j ] == true ) Console . Write ( j + " ▁ " ) ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . Length ; printDistSum ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int R = 4 ; static int C = 4 ; static int countPaths ( int [ , ] maze ) { if ( maze [ 0 , 0 ] == - 1 ) return 0 ; for ( int i = 0 ; i < R ; i ++ ) { if ( maze [ i , 0 ] == 0 ) maze [ i , 0 ] = 1 ; else break ; } for ( int i = 1 ; i < C ; i ++ ) { if ( maze [ 0 , i ] == 0 ) maze [ 0 , i ] = 1 ; else break ; } for ( int i = 1 ; i < R ; i ++ ) { for ( int j = 1 ; j < C ; j ++ ) { if ( maze [ i , j ] == - 1 ) continue ; if ( maze [ i - 1 , j ] > 0 ) maze [ i , j ] = ( maze [ i , j ] + maze [ i - 1 , j ] ) ; if ( maze [ i , j - 1 ] > 0 ) maze [ i , j ] = ( maze [ i , j ] + maze [ i , j - 1 ] ) ; } } return ( maze [ R - 1 , C - 1 ] > 0 ) ? maze [ R - 1 , C - 1 ] : 0 ; } public static void Main ( ) { int [ , ] maze = { { 0 , 0 , 0 , 0 } , { 0 , - 1 , 0 , 0 } , { - 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; Console . Write ( countPaths ( maze ) ) ; } }

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

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 4 ; static int maxDecimalValue ( int [ , ] mat , int i , int j , int p ) { if ( i >= N j >= N ) { return 0 ; } int result = Math . Max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ; if ( mat [ i , j ] == 1 ) { return ( int ) ( Math . Pow ( 2 , p ) + result ) ; } else { return result ; } } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 } , } ; Console . Write ( maxDecimalValue ( mat , 0 , 0 , 0 ) ) ; } }

Class/struct names: GFG
C# program:
using System ; public class GFG { readonly static int N = 4 ; static int MaximumDecimalValue ( int [ , ] mat , int n ) { int [ , ] dp = new int [ n , n ] ; if ( mat [ 0 , 0 ] == 1 ) { } for ( int i = 1 ; i < n ; i ++ ) { if ( mat [ 0 , i ] == 1 ) { dp [ 0 , i ] = ( int ) ( dp [ 0 , i - 1 ] + Math . Pow ( 2 , i ) ) ; else { dp [ 0 , i ] = dp [ 0 , i - 1 ] ; } } for ( int i = 1 ; i < n ; i ++ ) { if ( mat [ i , 0 ] == 1 ) { dp [ i , 0 ] = ( int ) ( dp [ i - 1 , 0 ] + Math . Pow ( 2 , i ) ) ; else { dp [ i , 0 ] = dp [ i - 1 , 0 ] ; } } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { if ( mat [ i , j ] == 1 ) { dp [ i , j ] = ( int ) ( Math . Max ( dp [ i , j - 1 ] , dp [ i - 1 , j ] ) + Math . Pow ( 2 , i + j ) ) ; } else { dp [ i , j ] = Math . Max ( dp [ i , j - 1 ] , dp [ i - 1 , j ] ) ; } } } return dp [ n - 1 , n - 1 ] ; } public static void Main ( ) { int [ , ] mat = { { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 } , } ; Console . Write ( MaximumDecimalValue ( mat , 4 ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static int CountPS ( char [ ] str , int n ) { int [ ] [ ] dp = RectangularArrays . ReturnRectangularIntArray ( n , n ) ; bool [ ] [ ] P = RectangularArrays . ReturnRectangularBoolArray ( n , n ) ; for ( int i = 0 ; i < n ; i ++ ) { P [ i ] [ i ] = true ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] == str [ i + 1 ] ) { P [ i ] [ i + 1 ] = true ; dp [ i ] [ i + 1 ] = 1 ; } } for ( int gap = 2 ; gap < n ; gap ++ ) { for ( int i = 0 ; i < n - gap ; i ++ ) { int j = gap + i ; if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) { P [ i ] [ j ] = true ; } if ( P [ i ] [ j ] == true ) { dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ; } else { dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ; } } } return dp [ 0 ] [ n - 1 ] ; } public static class RectangularArrays { public static int [ ] [ ] ReturnRectangularIntArray ( int size1 , int size2 ) { int [ ] [ ] newArray = new int [ size1 ] [ ] ; for ( int array1 = 0 ; array1 < size1 ; array1 ++ ) { newArray [ array1 ] = new int [ size2 ] ; } return newArray ; } public static bool [ ] [ ] ReturnRectangularBoolArray ( int size1 , int size2 ) { bool [ ] [ ] newArray = new bool [ size1 ] [ ] ; for ( int array1 = 0 ; array1 < size1 ; array1 ++ ) { newArray [ array1 ] = new bool [ size2 ] ; } return newArray ; } } public static void Main ( string [ ] args ) { string str = " abaab " ; Console . WriteLine ( CountPS ( str . ToCharArray ( ) , str . Length ) ) ; } }

Index/key variables: array1, i, j, size1, size2
Accumulator variables: array1, gap, i
Iterator variables: array1, gap, i
Class/struct names: GFG, RectangularArrays
C# program:
using System ; class GFG { static int maxSumWO3Consec ( int [ ] arr , int n ) { int [ ] sum = new int [ n ] ; if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ; if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ; if ( n > 2 ) sum [ 2 ] = Math . Max ( sum [ 1 ] , Math . Max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ; for ( int i = 3 ; i < n ; i ++ ) sum [ i ] = Math . Max ( Math . Max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ; return sum [ n - 1 ] ; } public static void Main ( ) { int [ ] arr = { 100 , 1000 , 100 , 1000 , 1 } ; int n = arr . Length ; Console . Write ( maxSumWO3Consec ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxSumPairWithDifferenceLessThanK ( int [ ] arr , int N , int K ) { Array . Sort ( arr ) ; int [ ] dp = new int [ N ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; if ( arr [ i ] - arr [ i - 1 ] < K ) { if ( i >= 2 ) dp [ i ] = Math . Max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ; else dp [ i ] = Math . Max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ; } } return dp [ N - 1 ] ; } public static void Main ( ) { int [ ] arr = { 3 , 5 , 10 , 15 , 17 , 12 , 9 } ; int N = arr . Length ; int K = 4 ; Console . WriteLine ( maxSumPairWithDifferenceLessThanK ( arr , N , K ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int lucas ( int n ) { if ( n == 0 ) return 2 ; if ( n == 1 ) return 1 ; return lucas ( n - 1 ) + lucas ( n - 2 ) ; } public static void Main ( ) { int n = 9 ; Console . WriteLine ( lucas ( n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int breakSum ( int n ) { if ( n == 0 n == 1 ) return n ; return Math . Max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ; } public static void Main ( ) { int n = 12 ; Console . WriteLine ( breakSum ( n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int countPS ( string str ) { int N = str . Length ; int [ , ] cps = new int [ N + 1 , N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) cps [ i , i ] = 1 ; for ( int L = 2 ; L <= N ; L ++ ) { for ( int i = 0 ; i <= N - L ; i ++ ) { int k = L + i - 1 ; if ( k < N ) { if ( str [ i ] == str [ k ] ) cps [ i , k ] = cps [ i , k - 1 ] + cps [ i + 1 , k ] + 1 ; else cps [ i , k ] = cps [ i , k - 1 ] + cps [ i + 1 , k ] - cps [ i + 1 , k - 1 ] ; } } } return cps [ 0 , N - 1 ] ; } public static void Main ( ) { string str = " abcb " ; Console . Write ( " Total ▁ palindromic ▁ " + " subsequence ▁ are ▁ : ▁ " + countPS ( str ) ) ; } }

Index/key variables: i, k
Accumulator variables: L, i
Iterator variables: L, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int n ; static int [ , ] dp = new int [ 1000 , 1000 ] ; static string str = " abcb " ; static int countPS ( int i , int j ) { if ( i > j ) return 0 ; if ( dp [ i , j ] != - 1 ) return dp [ i , j ] ; if ( i == j ) return dp [ i , j ] = 1 ; else if ( str [ i ] == str [ j ] ) return dp [ i , j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ; else return dp [ i , j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ; } static void Main ( ) { for ( int i = 0 ; i < 1000 ; i ++ ) for ( int j = 0 ; j < 1000 ; j ++ ) dp [ i , j ] = - 1 ; n = str . Length ; Console . Write ( " Total ▁ palindromic ▁ subsequence " + " are ▁ : ▁ " + countPS ( 0 , n - 1 ) ) ; } }

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 countSub ( int [ ] arr , int n ) { int [ ] count = new int [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = arr [ i ] - 1 ; j >= 0 ; j -- ) count [ arr [ i ] ] += count [ j ] ; count [ arr [ i ] ] ++ ; } int result = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) result += count [ i ] ; return result ; } public static void Main ( ) { int [ ] arr = { 3 , 2 , 4 , 5 , 4 } ; int n = arr . Length ; Console . WriteLine ( countSub ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int minimum ( int a , int b , int c ) { return Math . Min ( Math . Min ( a , b ) , c ) ; } static int findMinSum ( int [ ] arr , int n ) { int [ ] sum = new int [ n ] ; sum [ 0 ] = arr [ 0 ] ; sum [ 1 ] = arr [ 1 ] ; sum [ 2 ] = arr [ 2 ] ; for ( int i = 3 ; i < n ; i ++ ) sum [ i ] = arr [ i ] + minimum ( sum [ i - 3 ] , sum [ i - 2 ] , sum [ i - 1 ] ) ; return minimum ( sum [ n - 1 ] , sum [ n - 2 ] , sum [ n - 3 ] ) ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 20 , 2 , 10 , 1 } ; int n = arr . Length ; Console . WriteLine ( " Min ▁ Sum ▁ is ▁ " + findMinSum ( arr , n ) ) ; } }

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