dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int findMinOperations ( String S ) { S = reverse ( S ) ; int n = S . Length ; int [ , ] dp = new int [ n + 1 , 2 ] ; if ( S [ 0 ] == '0' ) { dp [ 0 , 0 ] = 0 ; } else { dp [ 0 , 0 ] = 1 ; } dp [ 0 , 1 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( S [ i ] == '0' ) { dp [ i , 0 ] = dp [ i - 1 , 0 ] ; dp [ i , 1 ] = 1 + Math . Min ( dp [ i - 1 , 1 ] , dp [ i - 1 , 0 ] ) ; } else { dp [ i , 1 ] = dp [ i - 1 , 1 ] ; dp [ i , 0 ] = 1 + Math . Min ( dp [ i - 1 , 0 ] , dp [ i - 1 , 1 ] ) ; } } return dp [ n - 1 , 0 ] ; } 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 S = "100" ; Console . WriteLine ( findMinOperations ( S ) ) ; S = "111" ; Console . WriteLine ( findMinOperations ( S ) ) ; } }

Index/key variables: i, left, right
Accumulator variables: i, left, right
Iterator variables: i, left
Class/struct names: GFG
C# program:
using System ; class GFG { public static void solve ( int N , int K ) { int [ ] Array = new int [ N + 1 ] ; if ( N <= K ) { Console . WriteLine ( "1" ) ; return ; } int i = 0 ; int sum = K ; for ( i = 1 ; i <= K ; ++ i ) { Array [ i ] = 1 ; } Array [ i ] = sum ; for ( i = K + 2 ; i <= N ; ++ i ) { Array [ i ] = sum - Array [ i - K - 1 ] + Array [ i - 1 ] ; sum = Array [ i ] ; } Console . WriteLine ( Array [ N ] ) ; } public static void Main ( string [ ] args ) { int N = 4 , K = 2 ; solve ( N , K ) ; } }

Index/key variables: N, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int MAX_VAL = 10000000 ; public static int [ , ] dp = new int [ 100 , 100 ] ; public static int find ( int index , int openbrk , int n , int [ , ] adj ) { if ( openbrk < 0 ) return MAX_VAL ; if ( index == n ) { if ( openbrk == 0 ) { return 0 ; } return MAX_VAL ; } if ( dp [ index , openbrk ] != - 1 ) return dp [ index , openbrk ] ; dp [ index , openbrk ] = Math . Min ( adj [ index , 1 ] + find ( index + 1 , openbrk + 1 , n , adj ) , adj [ index , 0 ] + find ( index + 1 , openbrk - 1 , n , adj ) ) ; return dp [ index , openbrk ] ; } static void Main ( ) { int n = 4 ; int [ , ] adj = new int [ , ] { { 5000 , 3000 } , { 6000 , 2000 } , { 8000 , 1000 } , { 9000 , 6000 } } ; for ( int i = 0 ; i < 100 ; i ++ ) for ( int j = 0 ; j < 100 ; j ++ ) dp [ i , j ] = - 1 ; Console . Write ( find ( 1 , 1 , n , adj ) + adj [ 0 , 1 ] + " STRNEWLINE " ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class getWays { static long getNumberOfWays ( long N , long [ ] Coins ) { long [ ] ways = new long [ ( int ) N + 1 ] ; ways [ 0 ] = 1 ; for ( int i = 0 ; i < Coins . Length ; i ++ ) { for ( int j = 0 ; j < ways . Length ; j ++ ) { if ( Coins [ i ] <= j ) { ways [ j ] += ways [ ( int ) ( j - Coins [ i ] ) ] ; } } } return ways [ ( int ) N ] ; } static void printArray ( long [ ] coins ) { foreach ( long i in coins ) Console . WriteLine ( i ) ; } public static void Main ( String [ ] args ) { long [ ] Coins = { 1 , 5 , 10 } ; Console . WriteLine ( " The ▁ Coins ▁ Array : " ) ; printArray ( Coins ) ; Console . WriteLine ( " Solution : " ) ; Console . WriteLine ( getNumberOfWays ( 12 , Coins ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: getWays
C# program:
using System ; class GFG { static int find ( int m , int n , int [ ] adj ) { int [ ] sweet = new int [ n + 1 ] ; int [ , , ] dp = new int [ n + 1 , n + 1 , n + 1 ] ; sweet [ 0 ] = 0 ; for ( int i = 1 ; i <= m ; ++ i ) sweet [ i ] = adj [ i - 1 ] ; for ( int i = 0 ; i <= m ; ++ i ) { for ( int k = 0 ; k <= n ; ++ k ) dp [ i , 0 , k ] = 0 ; for ( int k = 1 ; k <= n ; ++ k ) dp [ i , k , 0 ] = - 1 ; } for ( int i = 0 ; i <= m ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { for ( int k = 1 ; k <= n ; ++ k ) { dp [ i , j , k ] = - 1 ; if ( i > 0 && j >= k && sweet [ k ] > 0 && dp [ i - 1 , j - k , k ] != - 1 ) dp [ i , j , k ] = dp [ i - 1 , j - k , k ] + sweet [ k ] ; if ( dp [ i , j , k ] == - 1 || ( dp [ i , j , k - 1 ] != - 1 && dp [ i , j , k ] > dp [ i , j , k - 1 ] ) ) dp [ i , j , k ] = dp [ i , j , k - 1 ] ; } } } if ( dp [ m , n , n ] == - 1 ) return 0 ; else return dp [ m , n , n ] ; } public static void Main ( ) { int m = 3 ; int [ ] adj = { 2 , 1 , 3 , 0 , 4 , 10 } ; int n = adj . Length ; Console . Write ( find ( m , n , adj ) ) ; } }

Index/key variables: i, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { public static int find ( int start , string adj , int n , int [ ] dp ) { if ( start == n ) return 0 ; if ( dp [ start ] != - 1 ) return dp [ start ] ; dp [ start ] = 0 ; int one = 0 , zero = 0 , k ; for ( k = start ; k < n ; k ++ ) { if ( adj [ k ] == '1' ) one ++ ; else zero ++ ; if ( one > zero ) dp [ start ] = Math . Max ( dp [ start ] , find ( k + 1 , adj , n , dp ) + k - start + 1 ) ; else dp [ start ] = Math . Max ( dp [ start ] , find ( k + 1 , adj , n , dp ) ) ; } return dp [ start ] ; } static void Main ( ) { string adj = "100110001010001" ; int n = adj . Length ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] = - 1 ; Console . Write ( find ( 0 , adj , n , dp ) + " STRNEWLINE " ) ; } }

Index/key variables: i, k, start
Accumulator variables: i, k, one, zero
Iterator variables: i, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return 1 ; return 0 ; } static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static int lcs ( String X , String Y , int m , int n ) { int [ , ] L = new int [ m + 1 , n + 1 ] ; int i , j ; for ( i = 0 ; i <= m ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i , j ] = 0 ; else if ( ( X [ i - 1 ] == Y [ j - 1 ] ) && isVowel ( X [ i - 1 ] ) == 1 ) L [ i , j ] = L [ i - 1 , j - 1 ] + 1 ; else L [ i , j ] = max ( L [ i - 1 , j ] , L [ i , j - 1 ] ) ; } } return L [ m , n ] ; } static public void Main ( String [ ] args ) { String X = " aieef " ; String Y = " klaief " ; int m = X . Length ; int n = Y . Length ; Console . WriteLine ( " Length ▁ of ▁ LCS ▁ = ▁ " + lcs ( X , Y , m , n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static Boolean check ( int i , int val ) { if ( i - val < 0 ) return false ; else return true ; } static double MinimumPrimes ( int n ) { double [ ] dp ; dp = new double [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i ] = 1e9 ; dp [ 0 ] = dp [ 2 ] = dp [ 3 ] = dp [ 5 ] = dp [ 7 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( check ( i , 2 ) ) dp [ i ] = Math . Min ( dp [ i ] , 1 + dp [ i - 2 ] ) ; if ( check ( i , 3 ) ) dp [ i ] = Math . Min ( dp [ i ] , 1 + dp [ i - 3 ] ) ; if ( check ( i , 5 ) ) dp [ i ] = Math . Min ( dp [ i ] , 1 + dp [ i - 5 ] ) ; if ( check ( i , 7 ) ) dp [ i ] = Math . Min ( dp [ i ] , 1 + dp [ i - 7 ] ) ; } if ( dp [ n ] == ( 1e9 ) ) return - 1 ; else return dp [ n ] ; } public static void Main ( String [ ] args ) { int n = 12 ; int minimal = ( int ) MinimumPrimes ( n ) ; if ( minimal != - 1 ) Console . WriteLine ( " Minimum ▁ number ▁ of ▁ single ▁ " + " digit ▁ primes ▁ required : ▁ " + minimal ) ; else Console . WriteLine ( " Not ▁ Possible " ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void subsetSum ( int [ ] arr , int n , int maxSum ) { bool [ ] dp = new bool [ maxSum + 1 ] ; Array . Fill ( dp , false ) ; dp [ arr [ 0 ] ] = true ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = maxSum ; j >= 1 ; j -- ) { if ( arr [ i ] <= j ) { if ( arr [ i ] == j || dp [ j ] || dp [ ( j - arr [ i ] ) ] ) dp [ j ] = true ; else dp [ j ] = false ; } } } Console . Write ( 0 + " ▁ " ) ; for ( int j = 0 ; j < maxSum + 1 ; j ++ ) { if ( dp [ j ] == true ) Console . Write ( j + " ▁ " ) ; } Console . Write ( "21" ) ; } static void printDistinct ( int [ ] a , int n ) { int maxSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { maxSum += a [ i ] ; } subsetSum ( a , n , maxSum ) ; } static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . Length ; printDistinct ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, maxSum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int size = 1000 ; public static int maxCost ( int [ , ] a , int m , int n ) { if ( n < 0 m < 0 ) return - 1 ; else if ( m == 0 && n == 0 ) return 0 ; else { int num = m + n ; if ( ( num & ( num - 1 ) ) == 0 ) return a [ m , n ] + maxCost ( a , m - 1 , n - 1 ) ; else return a [ m , n ] + Math . Max ( maxCost ( a , m - 1 , n ) , maxCost ( a , m , n - 1 ) ) ; } } public static int answer ( int [ , ] a , int n ) { return maxCost ( a , n - 1 , n - 1 ) ; } static void Main ( ) { int [ , ] a = new int [ , ] { { 1 , 2 , 3 , 1 } , { 4 , 5 , 6 , 1 } , { 7 , 8 , 9 , 1 } , { 1 , 1 , 1 , 1 } } ; int n = 4 ; Console . Write ( answer ( a , n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int maximum = 1000 ; static int lcs ( String X , String Y , int m , int n , int [ , ] dp ) { if ( m == 0 n == 0 ) { return 0 ; } if ( dp [ m - 1 , n - 1 ] != - 1 ) { return dp [ m - 1 , n - 1 ] ; } if ( X [ m - 1 ] == Y [ n - 1 ] ) { dp [ m - 1 , n - 1 ] = 1 + lcs ( X , Y , m - 1 , n - 1 , dp ) ; return dp [ m - 1 , n - 1 ] ; } else { dp [ m - 1 , n - 1 ] = Math . Max ( lcs ( X , Y , m , n - 1 , dp ) , lcs ( X , Y , m - 1 , n , dp ) ) ; return dp [ m - 1 , n - 1 ] ; } } public static void Main ( String [ ] args ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; int m = X . Length ; int n = Y . Length ; int [ , ] dp = new int [ m , maximum ] ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < maximum ; j ++ ) { dp [ i , j ] = - 1 ; } } Console . WriteLine ( " Length ▁ of ▁ LCS : ▁ " + lcs ( X , Y , m , n , dp ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static void dfs ( int n , int m , int stepNum ) { if ( stepNum <= m && stepNum >= n ) Console . Write ( stepNum + " ▁ " ) ; if ( stepNum == 0 stepNum > m ) return ; int lastDigit = stepNum % 10 ; int stepNumA = stepNum * 10 + ( lastDigit - 1 ) ; int stepNumB = stepNum * 10 + ( lastDigit + 1 ) ; if ( lastDigit == 0 ) dfs ( n , m , stepNumB ) ; else if ( lastDigit == 9 ) dfs ( n , m , stepNumA ) ; else { dfs ( n , m , stepNumA ) ; dfs ( n , m , stepNumB ) ; } } public static void displaySteppingNumbers ( int n , int m ) { for ( int i = 0 ; i <= 9 ; i ++ ) dfs ( n , m , i ) ; } static public void Main ( ) { int n = 0 , m = 21 ; displaySteppingNumbers ( n , m ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { public static int [ , ] arr = new int [ 1000 , 1000 ] ; public static int lcs ( String X , String Y , int m , int n ) { if ( m == 0 n == 0 ) return 0 ; if ( arr [ m - 1 , n - 1 ] != - 1 ) return arr [ m - 1 , n - 1 ] ; if ( X [ m - 1 ] == Y [ n - 1 ] ) { arr [ m - 1 , n - 1 ] = 1 + lcs ( X , Y , m - 1 , n - 1 ) ; return arr [ m - 1 , n - 1 ] ; } else { arr [ m - 1 , n - 1 ] = max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ; return arr [ m - 1 , n - 1 ] ; } } public static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static public void Main ( ) { for ( int i = 0 ; i < 1000 ; i ++ ) { for ( int j = 0 ; j < 1000 ; j ++ ) { arr [ i , j ] = - 1 ; } } String X = " AGGTAB " ; String Y = " GXTXAYB " ; int m = X . Length ; int n = Y . Length ; Console . WriteLine ( " Length ▁ of ▁ LCS ▁ is ▁ " + lcs ( X , Y , m , n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int numberOfBST ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 1 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { dp [ i ] = dp [ i ] + ( dp [ i - j ] * dp [ j - 1 ] ) ; } } return dp [ n ] ; } public static void Main ( ) { int n = 3 ; Console . Write ( " Number ▁ of ▁ structurally ▁ " + " Unique ▁ BST ▁ with ▁ " + n + " ▁ keys ▁ are ▁ : ▁ " + numberOfBST ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isPowerOf ( long val , int b ) { while ( val > 1 ) { if ( val % b != 0 ) val /= b ; } return true ; } static int numberOfPartitions ( string binaryNo ) { int i , j , n = binaryNo . Length ; long val ; int [ ] dp = new int [ n ] ; dp [ n - 1 ] = ( ( ( binaryNo [ n - 1 ] - '0' ) == 0 ) ? - 1 : 1 ) ; for ( i = n - 2 ; i >= 0 ; i -- ) { val = 0 ; if ( ( binaryNo [ i ] - '0' ) == 0 ) { dp [ i ] = - 1 ; continue ; } dp [ i ] = int . MaxValue ; for ( j = i ; j < n ; j ++ ) { val = ( val * 2 ) + ( long ) ( binaryNo [ j ] - '0' ) ; if ( isPowerOf ( val , 4 ) || isPowerOf ( val , 6 ) ) { if ( j == n - 1 ) { dp [ i ] = 1 ; } else { if ( dp [ j + 1 ] != - 1 ) dp [ i ] = Math . Min ( dp [ i ] , dp [ j + 1 ] + 1 ) ; } } } if ( dp [ i ] == int . MaxValue ) dp [ i ] = - 1 ; } return dp [ 0 ] ; } public static void Main ( ) { string binaryNo = "100110110" ; Console . Write ( numberOfPartitions ( binaryNo ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, val
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int summation ( int n ) { return n << ( n - 1 ) ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( summation ( n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MAX = 1000 ; static double [ , ] memo = new double [ MAX , MAX ] ; public static double score ( int n , List < int > A , int k ) { if ( memo [ n , k ] > 0 ) return memo [ n , k ] ; double sum = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { sum += A [ i ] ; memo [ n , k ] = Math . Max ( memo [ n , k ] , score ( i , A , k - 1 ) + sum / ( n - i ) ) ; } return memo [ n , k ] ; } public static double largestSumOfAverages ( List < int > A , int K ) { int n = A . Count ; double sum = 0 ; for ( int i = 0 ; i < memo . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < memo . GetLength ( 1 ) ; j ++ ) memo [ i , j ] = 0.0 ; } for ( int i = 0 ; i < n ; i ++ ) { sum += A [ i ] ; memo [ i + 1 , 1 ] = sum / ( i + 1 ) ; } return score ( n , A , K ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 9 , 1 , 2 , 3 , 9 } ; List < int > A = new List < int > ( arr ) ; int K = 3 ; } Console . WriteLine ( largestSumOfAverages ( A , K ) ) ; }

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 findMaxProduct ( int [ ] arr , int n ) { int i ; int ans = Int32 . MinValue ; until current . ' ' ' int minval = 1 ; int prevMax ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { maxval = maxval * arr [ i ] ; minval = Math . Min ( 1 , minval * arr [ i ] ) ; } else if ( arr [ i ] == 0 ) { minval = 1 ; maxval = 0 ; } else if ( arr [ i ] < 0 ) { prevMax = maxval ; maxval = minval * arr [ i ] ; minval = prevMax * arr [ i ] ; } ans = Math . Max ( ans , maxval ) ; if ( maxval <= 0 ) { maxval = 1 ; } } return ans ; } public static void Main ( ) { int [ ] arr = { 0 , - 4 , 0 , - 2 } ; int n = arr . Length ; Console . WriteLine ( findMaxProduct ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static double INF = 1e9 ; static int MAX = 50 ; static void minMaxValues ( int [ ] arr , int n , int m ) { int sum = 0 ; for ( int i = 0 ; i < ( n + m ) ; i ++ ) { sum += arr [ i ] ; arr [ i ] += 50 ; } bool [ , ] dp = new bool [ MAX + 1 , MAX * MAX + 1 ] ; dp [ 0 , 0 ] = true ; for ( int i = 0 ; i < ( n + m ) ; i ++ ) { for ( int k = Math . Min ( n , i + 1 ) ; k >= 1 ; k -- ) { for ( int j = 0 ; j < MAX * MAX + 1 ; j ++ ) { if ( dp [ k - 1 , j ] ) dp [ k , j + arr [ i ] ] = true ; } } } double max_value = - 1 * INF , min_value = INF ; for ( int i = 0 ; i < MAX * MAX + 1 ; i ++ ) { if ( dp [ n , i ] ) { int temp = i - 50 * n ; max_value = Math . Max ( max_value , temp * ( sum - temp ) ) ; min_value = Math . Min ( min_value , temp * ( sum - temp ) ) ; } } Console . WriteLine ( " Maximum ▁ Value : ▁ " + max_value + " STRNEWLINE " + " Minimum ▁ Value : ▁ " + min_value + " STRNEWLINE " ) ; } public static void Main ( ) { int n = 2 , m = 2 ; int [ ] arr = { 1 , 2 , 3 , 4 } ; minMaxValues ( arr , n , m ) ; } }

Index/key variables: i
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 1000 ; static Boolean isPossible ( int n , int index , int sum , int M , int [ ] arr , int [ , ] dp ) { if ( index == n ) { if ( ( sum % M ) == 0 ) return true ; return false ; } else if ( sum < 0 sum >= MAX ) return false ; if ( dp [ index , sum ] != - 1 ) { if ( dp [ index , sum ] == 0 ) return false ; return true ; } Boolean placeAdd = isPossible ( n , index + 1 , sum + arr [ index ] , M , arr , dp ) ; Boolean placeMinus = isPossible ( n , index + 1 , sum - arr [ index ] , M , arr , dp ) ; Boolean res = ( placeAdd placeMinus ) ; dp [ index , sum ] = ( res ) ? 1 : 0 ; return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 6 } ; int n = arr . Length ; int M = 4 ; int [ , ] dp = new int [ n + 1 , MAX ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) dp [ i , j ] = - 1 ; Boolean res ; res = isPossible ( n , 0 , 0 , M , arr , dp ) ; Console . WriteLine ( ( res ? " True " : " False " ) ) ; } }

Index/key variables: index
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int MAX_NODES = 100 ; static int [ ] In = new int [ MAX_NODES ] ; static int [ ] Out = new int [ MAX_NODES ] ; static void dfs1 ( List < List < int > > v , int u , int parent ) { In [ u ] = 0 ; for ( int j = 0 ; j < v [ u ] . Count ; j ++ ) { int child = v [ u ] [ j ] ; if ( child == parent ) continue ; dfs1 ( v , child , u ) ; In [ u ] = Math . Max ( In [ u ] , 1 + In [ child ] ) ; } } static void dfs2 ( List < List < int > > v , int u , int parent ) { int mx1 = - 1 , mx2 = - 1 ; for ( int j = 0 ; j < v [ u ] . Count ; j ++ ) { int child = v [ u ] [ j ] ; if ( child == parent ) continue ; if ( In [ child ] >= mx1 ) { mx2 = mx1 ; mx1 = In [ child ] ; } else if ( In [ child ] > mx2 ) mx2 = In [ child ] ; } for ( int j = 0 ; j < v [ u ] . Count ; j ++ ) { int child = v [ u ] [ j ] ; if ( child == parent ) continue ; int longest = mx1 ; if ( mx1 == In [ child ] ) longest = mx2 ; Out [ child ] = 1 + Math . Max ( Out [ u ] , 1 + longest ) ; dfs2 ( v , child , u ) ; } } static void addEdge ( List < List < int > > adj , int u , int v ) { adj [ u ] . Add ( v ) ; adj [ v ] . Add ( u ) ; } static void printHeights ( List < List < int > > v , int n ) { dfs1 ( v , 1 , 0 ) ; dfs2 ( v , 1 , 0 ) ; for ( int i = 1 ; i < n ; i ++ ) Console . WriteLine ( " The ▁ maximum ▁ height ▁ when ▁ node ▁ " + i + " ▁ is ▁ considered ▁ as ▁ root ▁ is ▁ " + Math . Max ( In [ i ] , Out [ i ] ) ) ; } static public void Main ( ) { int V = 12 ; List < List < int > > adj = new List < List < int > > ( ) ; for ( int i = 0 ; i < V ; i ++ ) adj . Add ( new List < int > ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 1 , 4 ) ; addEdge ( adj , 2 , 5 ) ; addEdge ( adj , 2 , 6 ) ; addEdge ( adj , 3 , 7 ) ; addEdge ( adj , 7 , 10 ) ; addEdge ( adj , 7 , 11 ) ; addEdge ( adj , 4 , 8 ) ; addEdge ( adj , 4 , 9 ) ; printHeights ( adj , V ) ; } }

Index/key variables: MAX_NODES, child, i, j, u, v
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int findGolomb ( int n ) { if ( n == 1 ) return 1 ; return 1 + findGolomb ( n - findGolomb ( findGolomb ( n - 1 ) ) ) ; } static void printGolomb ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( findGolomb ( i ) + " ▁ " ) ; } public static void Main ( ) { int n = 9 ; printGolomb ( n ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static void printknapSack ( int W , int [ ] wt , int [ ] val , int n ) { int i , w ; int [ , ] K = new int [ n + 1 , W + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) { for ( w = 0 ; w <= W ; w ++ ) { if ( i == 0 w == 0 ) K [ i , w ] = 0 ; else if ( wt [ i - 1 ] <= w ) K [ i , w ] = Math . Max ( val [ i - 1 ] + K [ i - 1 , w - wt [ i - 1 ] ] , K [ i - 1 , w ] ) ; else K [ i , w ] = K [ i - 1 , w ] ; } } int res = K [ n , W ] ; Console . WriteLine ( res ) ; w = W ; for ( i = n ; i > 0 && res > 0 ; i -- ) { if ( res == K [ i - 1 , w ] ) continue ; else { Console . Write ( wt [ i - 1 ] + " ▁ " ) ; res = res - val [ i - 1 ] ; w = w - wt [ i - 1 ] ; } } } public static void Main ( ) { int [ ] val = { 60 , 100 , 120 } ; int [ ] wt = { 10 , 20 , 30 } ; int W = 50 ; int n = val . Length ; printknapSack ( W , wt , val , n ) ; } }

Accumulator variables: i, w
Iterator variables: i, w
Class/struct names: GFG
C# program:
using System ; class GFG { static int removals ( int [ ] arr , int n , int k ) { Array . Sort ( arr ) ; int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = - 1 ; int ans = n - 1 ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = i ; int j = dp [ i - 1 ] ; while ( j != i && arr [ i ] - arr [ j ] > k ) { j ++ ; } dp [ i ] = Math . Min ( dp [ i ] , j ) ; ans = Math . Min ( ans , ( n - ( i - j + 1 ) ) ) ; } return ans ; } static public void Main ( ) { int [ ] a = { 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 } ; int n = a . Length ; int k = 4 ; Console . Write ( removals ( a , n , k ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maximumSegments ( int n , int a , int b , int c ) { int [ ] dp = new int [ n + 10 ] ; for ( int i = 0 ; i < n + 10 ; i ++ ) dp [ i ] = - 1 ; dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dp [ i ] != - 1 ) { dp [ i + a ] = Math . Max ( dp [ i ] + 1 , dp [ i + a ] ) ; dp [ i + b ] = Math . Max ( dp [ i ] + 1 , dp [ i + b ] ) ; dp [ i + c ] = Math . Max ( dp [ i ] + 1 , dp [ i + c ] ) ; } } return dp [ n ] ; } public static void Main ( ) { int n = 7 , a = 5 , b = 2 , c = 5 ; Console . Write ( maximumSegments ( n , a , b , c ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Linq ; class GFG { static int getMaximumSum ( int [ ] arr ) { int n = arr . Length ; int max = arr . Max ( ) ; int [ ] freq = new int [ max + 1 ] ; for ( int j = 0 ; j < n ; j ++ ) { freq [ arr [ j ] ] ++ ; } int ans = 0 , i = max ; while ( i > 0 ) { if ( freq [ i ] > 0 ) { ans += i ; freq [ i - 1 ] -- ; freq [ i ] -- ; } else { i -- ; } } return ans ; } public static void Main ( string [ ] args ) { int [ ] a = { 1 , 2 , 3 } ; Console . Write ( getMaximumSum ( a ) ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class GFG { public static void sequence ( int n ) { int [ ] f = new int [ n + 1 ] ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; f [ 2 ] = 1 ; Console . Write ( f [ 1 ] + " ▁ " + f [ 2 ] + " ▁ " ) ; for ( int i = 3 ; i <= n ; i ++ ) { f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ; Console . Write ( f [ i ] + " ▁ " ) ; } } public static void Main ( ) { int n = 13 ; sequence ( n ) ; } }

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