dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static bool canVote ( int [ ] a , int n , int x ) { int [ , ] dp = new int [ n + 1 , x + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < x + 1 ; j ++ ) { dp [ i , j ] = 0 ; } } int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j <= x ; j ++ ) if ( a [ i ] <= j ) dp [ i , j ] = Math . Max ( dp [ i - 1 , j ] , a [ i ] + dp [ i - 1 , j - a [ i ] ] ) ; else dp [ i , j ] = dp [ i - 1 , j ] ; return ( sum - dp [ n , x ] >= x ) ; } static void Main ( ) { int n = 3 , x = 4 ; int [ ] a = { 2 , 4 , 2 } ; if ( canVote ( a , n , x ) ) { Console . Write ( " YES " ) ; } else { Console . Write ( " NO " ) ; } } }

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

Index/key variables: i, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Linq ; class GFG { static int minSum ( int [ ] ar , int n ) { if ( n <= 4 ) return ar . Min ( ) ; int [ ] sum = new int [ n ] ; sum [ 0 ] = ar [ 0 ] ; sum [ 1 ] = ar [ 1 ] ; sum [ 2 ] = ar [ 2 ] ; sum [ 3 ] = ar [ 3 ] ; int [ ] tempArr ; for ( int i = 4 ; i < n ; i ++ ) { tempArr = new int [ 4 ] ; Array . Copy ( sum , i - 4 , tempArr , 0 , 4 ) ; sum [ i ] = ar [ i ] + tempArr . Min ( ) ; } tempArr = new int [ 4 ] ; Array . Copy ( sum , n - 4 , tempArr , 0 , 4 ) ; return tempArr . Min ( ) ; } public static void Main ( String [ ] args ) { int [ ] ar = { 2 , 4 , 1 , 5 , 2 , 3 , 6 , 1 , 2 , 4 } ; int n = ar . Length ; Console . WriteLine ( " Minimum ▁ sum ▁ = ▁ " + minSum ( ar , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxAlternateSum ( int [ ] arr , int n ) { if ( n == 1 ) return arr [ 0 ] ; int min = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( min > arr [ i ] ) min = arr [ i ] ; } if ( min == arr [ 0 ] ) { return arr [ 0 ] ; } int [ ] dec = new int [ n ] ; int [ ] inc = new int [ n ] ; dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ; int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) { dec [ i ] = Math . Max ( dec [ i ] , inc [ j ] + arr [ i ] ) ; flag = 1 ; } else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . Max ( inc [ i ] , dec [ j ] + arr [ i ] ) ; } } int result = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( result < inc [ i ] ) result = inc [ i ] ; if ( result < dec [ i ] ) result = dec [ i ] ; } return result ; } public static void Main ( ) { int [ ] arr = { 8 , 2 , 3 , 5 , 7 , 9 , 10 } ; Console . Write ( " Maximum ▁ sum ▁ = ▁ " + maxAlternateSum ( arr , arr . Length ) ) ; } }

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 pad ( int n ) { int pPrevPrev = 1 , pPrev = 1 , pCurr = 1 , pNext = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { pNext = pPrevPrev + pPrev ; pPrevPrev = pPrev ; pPrev = pCurr ; pCurr = pNext ; } return pNext ; } public static void Main ( ) { int n = 12 ; Console . WriteLine ( pad ( n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int ROW , COL , count ; static Boolean isSafe ( int [ , ] M , int row , int col , Boolean [ , ] visited ) { return ( ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ( M [ row , col ] == 1 && ! visited [ row , col ] ) ) ; } static void DFS ( int [ , ] M , int row , int col , Boolean [ , ] visited ) { int [ ] rowNbr = { - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 } ; int [ ] colNbr = { - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 } ; visited [ row , col ] = true ; for ( int k = 0 ; k < 8 ; k ++ ) { if ( isSafe ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited ) ) { count ++ ; DFS ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited ) ; } } } static int largestRegion ( int [ , ] M ) { Boolean [ , ] visited = new Boolean [ ROW , COL ] ; int result = 0 ; for ( int i = 0 ; i < ROW ; i ++ ) { for ( int j = 0 ; j < COL ; j ++ ) { if ( M [ i , j ] == 1 && ! visited [ i , j ] ) { count = 1 ; DFS ( M , i , j , visited ) ; result = Math . Max ( result , count ) ; } } } return result ; } public static void Main ( String [ ] args ) { int [ , ] M = { { 0 , 0 , 1 , 1 , 0 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 } } ; ROW = 4 ; COL = 5 ; Console . WriteLine ( largestRegion ( M ) ) ; } }

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

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int breakSum ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) dp [ i ] = Math . Max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ; return dp [ n ] ; } public static void Main ( ) { int n = 24 ; Console . WriteLine ( breakSum ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static String longestRepeatedSubstring ( String str ) { int n = str . Length ; int [ , ] LCSRe = new int [ n + 1 , n + 1 ] ; int i , index = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { if ( str [ i - 1 ] == str [ j - 1 ] && LCSRe [ i - 1 , j - 1 ] < ( j - i ) ) { LCSRe [ i , j ] = LCSRe [ i - 1 , j - 1 ] + 1 ; if ( LCSRe [ i , j ] > res_length ) { res_length = LCSRe [ i , j ] ; index = Math . Max ( i , index ) ; } } else { LCSRe [ i , j ] = 0 ; } } } if ( res_length > 0 ) { for ( i = index - res_length + 1 ; i <= index ; i ++ ) { res += str [ i - 1 ] ; } } return res ; } public static void Main ( ) { String str = " geeksforgeeks " ; Console . WriteLine ( longestRepeatedSubstring ( str ) ) ; } }

Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int minCost ( int [ ] cost , int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int min_cost = Int32 . MaxValue ; for ( int j = 0 ; j < i ; j ++ ) if ( j < n && cost [ j ] != - 1 ) min_cost = Math . Min ( min_cost , cost [ j ] + dp [ i - j - 1 ] ) ; dp [ i ] = min_cost ; } return dp [ n ] ; } static void Main ( ) { int [ ] cost = { 20 , 10 , 4 , 50 , 100 } ; int W = cost . Length ; Console . Write ( minCost ( cost , W ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int findSum ( List < int > arr ) { int sum = 0 ; foreach ( int i in arr ) sum += i ; return sum ; } static void printMaxSumIs ( int [ ] arr , int n ) { List < int > [ ] L = new List < int > [ n ] ; for ( int i = 0 ; i < n ; i ++ ) L [ i ] = new List < int > ( ) ; L [ 0 ] . Add ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] > arr [ j ] ) && ( findSum ( L [ i ] ) < findSum ( L [ j ] ) ) ) { foreach ( int k in L [ j ] ) if ( ! L [ i ] . Contains ( k ) ) L [ i ] . Add ( k ) ; } } L [ i ] . Add ( arr [ i ] ) ; } List < int > res = new List < int > ( L [ 0 ] ) ; foreach ( List < int > x in L ) if ( findSum ( x ) > findSum ( res ) ) res = x ; foreach ( int i in res ) Console . Write ( i + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 6 , 4 , 5 , 1 } ; int n = arr . Length ; printMaxSumIs ( arr , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j, k, x
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void printLIS ( List < int > arr ) { foreach ( int x in arr ) { Console . Write ( x + " ▁ " ) ; } Console . WriteLine ( ) ; } static void constructPrintLIS ( int [ ] arr , int n ) { List < List < int > > L = new List < List < int > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { L . Add ( new List < int > ( ) ) ; } L [ 0 ] . Add ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] > arr [ j ] ) && ( L [ i ] . Count < L [ j ] . Count + 1 ) ) L [ i ] = L [ j ] ; } L [ i ] . Add ( arr [ i ] ) ; } List < int > max = L [ 0 ] ; foreach ( List < int > x in L ) { if ( x . Count > max . Count ) { max = x ; } } printLIS ( max ) ; } static void Main ( ) { int [ ] arr = { 3 , 2 , 4 , 5 , 1 } ; int n = arr . Length ; constructPrintLIS ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j, x
Class/struct names: GFG
C# program:
using System ; class GFG { static int lcs ( String X , String Y , int m , int n ) { int [ , ] L = new int [ m + 1 , n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i , j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { L [ i , j ] = L [ i - 1 , j - 1 ] + 1 ; } else { L [ i , j ] = Math . Max ( L [ i - 1 , j ] , L [ i , j - 1 ] ) ; } } } return L [ m , n ] ; } static bool isKPal ( String str , int k ) { int n = str . Length ; str = reverse ( str ) ; int lps = lcs ( str , str , n , n ) ; return ( n - lps <= k ) ; } static String reverse ( String input ) { char [ ] temparray = input . ToCharArray ( ) ; int left , right = 0 ; right = temparray . Length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . Join ( " " , temparray ) ; } public static void Main ( String [ ] args ) { String str = " abcdeca " ; int k = 2 ; if ( isKPal ( str , k ) ) { Console . WriteLine ( " Yes " ) ; } else Console . WriteLine ( " No " ) ; } }

Index/key variables: left, right
Accumulator variables: i, j, left, right
Iterator variables: i, j, left
Class/struct names: GFG
C# program:
using System ; class GFG { static Boolean strmatch ( String str , String pattern , int n , int m ) { if ( m == 0 ) return ( n == 0 ) ; Boolean [ , ] lookup = new Boolean [ n + 1 , m + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) for ( int j = 0 ; j < m + 1 ; j ++ ) lookup [ i , j ] = false ; lookup [ 0 , 0 ] = true ; for ( int j = 1 ; j <= m ; j ++ ) if ( pattern [ j - 1 ] == ' * ' ) lookup [ 0 , j ] = lookup [ 0 , j - 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { if ( pattern [ j - 1 ] == ' * ' ) lookup [ i , j ] = lookup [ i , j - 1 ] || lookup [ i - 1 , j ] ; else if ( pattern [ j - 1 ] == ' ? ' str [ i - 1 ] == pattern [ j - 1 ] ) lookup [ i , j ] = lookup [ i - 1 , j - 1 ] ; else lookup [ i , j ] = false ; } } return lookup [ n , m ] ; } public static void Main ( String [ ] args ) { String str = " baaabab " ; String pattern = " * * * * * ba * * * * * ab " ; if ( strmatch ( str , pattern , str . Length , pattern . Length ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int isKPalRec ( String str1 , String str2 , int m , int n ) { if ( m == 0 ) { return n ; } if ( n == 0 ) { return m ; } if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) { return isKPalRec ( str1 , str2 , m - 1 , n - 1 ) ; } } static bool isKPal ( String str , int k ) { String revStr = str ; revStr = reverse ( revStr ) ; int len = str . Length ; return ( isKPalRec ( str , revStr , len , len ) <= k * 2 ) ; } static String reverse ( String input ) { char [ ] temparray = input . ToCharArray ( ) ; int left , right = 0 ; right = temparray . Length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . Join ( " " , temparray ) ; } public static void Main ( String [ ] args ) { String str = " acdcb " ; int k = 2 ; if ( isKPal ( str , k ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }

Index/key variables: left, right
Accumulator variables: left, right
Iterator variables: left
Class/struct names: GFG
C# program:
using System ; class GFG { static int minTime ( int [ ] arr , int n ) { if ( n <= 0 ) return 0 ; int incl = arr [ 0 ] ; int excl = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int incl_new = arr [ i ] + Math . Min ( excl , incl ) ; int excl_new = incl ; incl = incl_new ; excl = excl_new ; } return Math . Min ( incl , excl ) ; } public static void Main ( ) { int [ ] arr1 = { 10 , 5 , 2 , 7 , 10 } ; int n1 = arr1 . Length ; Console . WriteLine ( minTime ( arr1 , n1 ) ) ; int [ ] arr2 = { 10 , 5 , 7 , 10 } ; int n2 = arr2 . Length ; Console . WriteLine ( minTime ( arr2 , n2 ) ) ; int [ ] arr3 = { 10 , 5 , 2 , 4 , 8 , 6 , 7 , 10 } ; int n3 = arr3 . Length ; Console . WriteLine ( minTime ( arr3 , n3 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void multiply ( int [ , ] a , int [ , ] b ) { int [ , ] mul = new int [ 3 , 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { mul [ i , j ] = 0 ; for ( int k = 0 ; k < 3 ; k ++ ) mul [ i , j ] += a [ i , k ] * b [ k , j ] ; } } for ( int i = 0 ; i < 3 ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) a [ i , j ] = mul [ i , j ] ; } static int power ( int [ , ] F , int n ) { int [ , ] M = { { 1 , 1 , 1 } , { 1 , 0 , 0 } , { 0 , 1 , 0 } } ; if ( n == 1 ) return F [ 0 , 0 ] + F [ 0 , 1 ] ; power ( F , n / 2 ) ; multiply ( F , F ) ; if ( n % 2 != 0 ) multiply ( F , M ) ; return F [ 0 , 0 ] + F [ 0 , 1 ] ; } static int findNthTerm ( int n ) { int [ , ] F = { { 1 , 1 , 1 } , { 1 , 0 , 0 } , { 0 , 1 , 0 } } ; return power ( F , n - 2 ) ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( " F ( 5 ) ▁ is ▁ " + findNthTerm ( n ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int count ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i >= 1 && i <= 3 ) dp [ i ] = 1 ; else if ( i == 4 ) dp [ i ] = 2 ; else { dp [ i ] = dp [ i - 1 ] + dp [ i - 4 ] ; } } return dp [ n ] ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( " Count ▁ of ▁ ways ▁ is : ▁ " + count ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int nCrModp ( int n , int r , int p ) { if ( r > n - r ) r = n - r ; int [ ] C = new int [ r + 1 ] ; for ( int i = 0 ; i < r + 1 ; i ++ ) C [ i ] = 0 ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . Min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ; } return C [ r ] ; } public static void Main ( ) { int n = 10 , r = 2 , p = 13 ; Console . Write ( " Value ▁ of ▁ nCr ▁ % ▁ p ▁ is ▁ " + nCrModp ( n , r , p ) ) ; } }

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countDer ( int n ) { if ( n == 1 n == 2 ) { return n - 1 ; } int a = 0 ; int b = 1 ; for ( int i = 3 ; i <= n ; ++ i ) { int cur = ( i - 1 ) * ( a + b ) ; a = b ; b = cur ; } return b ; } public static void Main ( ) { Console . Write ( " Count ▁ of ▁ Dearrangements ▁ is ▁ " + countDer ( 4 ) ) ; } }

Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int bellNumber ( int n ) { int [ , ] bell = new int [ n + 1 , n + 1 ] ; bell [ 0 , 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { bell [ i , 0 ] = bell [ i - 1 , i - 1 ] ; for ( int j = 1 ; j <= i ; j ++ ) bell [ i , j ] = bell [ i - 1 , j - 1 ] + bell [ i , j - 1 ] ; } return bell [ n , 0 ] ; } public static void Main ( ) { for ( int n = 0 ; n <= 5 ; n ++ ) Console . WriteLine ( " Bell ▁ Number ▁ " + n + " ▁ is ▁ " + bellNumber ( n ) ) ; } }

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

Index/key variables: dist, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int countSeq ( int n ) { int nCr = 1 , res = 1 ; for ( int r = 1 ; r <= n ; r ++ ) { nCr = ( nCr * ( n + 1 - r ) ) / r ; res += nCr * nCr ; } return res ; } public static void Main ( ) { int n = 2 ; Console . Write ( " Count ▁ of ▁ sequences ▁ is ▁ " ) ; Console . Write ( countSeq ( n ) ) ; } }

Accumulator variables: r, res
Iterator variables: r
Class/struct names: GFG
C# program:
using System ; public class GFG { static int min ( int a , int b ) { return ( a < b ) ? a : b ; } static int min ( int [ ] arr , int l , int h ) { int mn = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) { if ( mn > arr [ i ] ) { mn = arr [ i ] ; } } return mn ; } static int max ( int [ ] arr , int l , int h ) { int mx = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) { if ( mx < arr [ i ] ) { mx = arr [ i ] ; } } return mx ; } static int minRemovalsDP ( int [ ] arr , int n ) { int [ , ] table = new int [ n , n ] ; int gap , i , j , mn , mx ; for ( gap = 0 ; gap < n ; ++ gap ) { for ( i = 0 , j = gap ; j < n ; ++ i , ++ j ) { mn = min ( arr , i , j ) ; mx = max ( arr , i , j ) ; table [ i , j ] = ( 2 * mn > mx ) ? 0 : min ( table [ i , j - 1 ] + 1 , table [ i + 1 , j ] + 1 ) ; } } return table [ 0 , n - 1 ] ; } public static void Main ( ) { int [ ] arr = { 20 , 4 , 1 , 3 } ; int n = arr . Length ; Console . WriteLine ( minRemovalsDP ( arr , n ) ) ; } }

Index/key variables: i, l
Accumulator variables: i
Iterator variables: gap, i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int numberOfPaths ( int m , int n ) { if ( m == 1 n == 1 ) return 1 ; return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ; } static public void Main ( ) { Console . WriteLine ( numberOfPaths ( 3 , 3 ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int numberOfPaths ( int m , int n ) { int path = 1 ; for ( int i = n ; i < ( m + n - 1 ) ; i ++ ) { path *= i ; path /= ( i - n + 1 ) ; } return path ; } public static void Main ( ) { Console . WriteLine ( numberOfPaths ( 3 , 3 ) ) ; } }

Accumulator variables: i, path
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int lenghtOfLongestAP ( int [ ] set , int n ) { if ( n <= 2 ) return n ; int [ , ] L = new int [ n , n ] ; int llap = 2 ; for ( int i = 0 ; i < n ; i ++ ) L [ i , n - 1 ] = 2 ; for ( int j = n - 2 ; j >= 1 ; j -- ) { int i = j - 1 , k = j + 1 ; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ; else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) { L [ i , j ] = 2 ; i -- ; } else { L [ i , j ] = L [ j , k ] + 1 ; llap = Math . Max ( llap , L [ i , j ] ) ; i -- ; k ++ ; } } while ( i >= 0 ) { L [ i , j ] = 2 ; i -- ; } } return llap ; } static public void Main ( ) { int [ ] set1 = { 1 , 7 , 10 , 13 , 14 , 19 } ; int n1 = set1 . Length ; Console . WriteLine ( lenghtOfLongestAP ( set1 , n1 ) ) ; int [ ] set2 = { 1 , 7 , 10 , 15 , 27 , 29 } ; int n2 = set2 . Length ; Console . WriteLine ( lenghtOfLongestAP ( set2 , n2 ) ) ; int [ ] set3 = { 2 , 4 , 6 , 8 , 10 } ; int n3 = set3 . Length ; Console . WriteLine ( lenghtOfLongestAP ( set3 , n3 ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int optCost ( int [ ] freq , int i , int j ) { if ( j < i ) return 0 ; if ( j == i ) return freq [ i ] ; int fsum = sum ( freq , i , j ) ; int min = int . MaxValue ; for ( int r = i ; r <= j ; ++ r ) { int cost = optCost ( freq , i , r - 1 ) + optCost ( freq , r + 1 , j ) ; if ( cost < min ) min = cost ; } return min + fsum ; } static int optimalSearchTree ( int [ ] keys , int [ ] freq , int n ) { return optCost ( freq , 0 , n - 1 ) ; } static int sum ( int [ ] freq , int i , int j ) { int s = 0 ; for ( int k = i ; k <= j ; k ++ ) s += freq [ k ] ; return s ; } public static void Main ( ) { int [ ] keys = { 10 , 12 , 20 } ; int [ ] freq = { 34 , 8 , 50 } ; int n = keys . Length ; Console . Write ( " Cost ▁ of ▁ Optimal ▁ BST ▁ is ▁ " + optimalSearchTree ( keys , freq , n ) ) ; } }

Index/key variables: i, k
Accumulator variables: k, s
Iterator variables: k, r
Class/struct names: GFG
C# program:
using System ; public class GFG { static int MAX = int . MaxValue ; static int printSolution ( int [ ] p , int n ) { int k ; if ( p [ n ] == 1 ) k = 1 ; else k = printSolution ( p , p [ n ] - 1 ) + 1 ; Console . WriteLine ( " Line ▁ number " + " ▁ " + k + " : ▁ From ▁ word ▁ no . " + " ▁ " + p [ n ] + " ▁ " + " to " + " ▁ " + n ) ; return k ; } static void solveWordWrap ( int [ ] l , int n , int M ) { int [ , ] extras = new int [ n + 1 , n + 1 ] ; int [ , ] lc = new int [ n + 1 , n + 1 ] ; int [ ] c = new int [ n + 1 ] ; int [ ] p = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { extras [ i , i ] = M - l [ i - 1 ] ; for ( int j = i + 1 ; j <= n ; j ++ ) extras [ i , j ] = extras [ i , j - 1 ] - l [ j - 1 ] - 1 ; } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i ; j <= n ; j ++ ) { if ( extras [ i , j ] < 0 ) lc [ i , j ] = MAX ; else if ( j == n && extras [ i , j ] >= 0 ) lc [ i , j ] = 0 ; else lc [ i , j ] = extras [ i , j ] * extras [ i , j ] ; } } c [ 0 ] = 0 ; for ( int j = 1 ; j <= n ; j ++ ) { c [ j ] = MAX ; for ( int i = 1 ; i <= j ; i ++ ) { if ( c [ i - 1 ] != MAX && lc [ i , j ] != MAX && ( c [ i - 1 ] + lc [ i , j ] < c [ j ] ) ) { c [ j ] = c [ i - 1 ] + lc [ i , j ] ; p [ j ] = i ; } } } printSolution ( p , n ) ; } public static void Main ( ) { int [ ] l = { 3 , 2 , 2 , 5 } ; int n = l . Length ; int M = 6 ; solveWordWrap ( l , n , M ) ; } }

Index/key variables: j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static bool isPalindrome ( string String , int i , int j ) { while ( i < j ) { if ( String [ i ] != String [ j ] ) return false ; i ++ ; j -- ; } return true ; } static int minPalPartion ( string String , int i , int j ) { if ( i >= j || isPalindrome ( String , i , j ) ) return 0 ; int ans = Int32 . MaxValue , count ; for ( int k = i ; k < j ; k ++ ) { count = minPalPartion ( String , i , k ) + minPalPartion ( String , k + 1 , j ) + 1 ; ans = Math . Min ( ans , count ) ; } return ans ; } static public void Main ( ) { string str = " ababbbabbababa " ; Console . WriteLine ( " Min ▁ cuts ▁ needed ▁ for ▁ " + " Palindrome ▁ Partitioning ▁ is ▁ " + minPalPartion ( str , 0 , str . Length - 1 ) ) ; } }

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