dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int findMax ( int [ ] arr , int n ) { int res = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) { int count = 0 ; for ( j = 0 ; j < i ; j ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) count += 1 ; } res = Math . Max ( count , res ) ; } return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = arr . Length ; Console . WriteLine ( findMax ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int findMax ( int [ ] arr , int n ) { bool [ ] divisible = new bool [ n ] ; int res = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { if ( divisible [ i ] ) continue ; int cnt = 0 ; for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] % arr [ i ] ) == 0 ) { divisible [ j ] = true ; cnt ++ ; } } res = Math . Max ( res , cnt ) ; } return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = arr . Length ; Console . WriteLine ( findMax ( arr , n ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 20 ; static int maxM = 10 ; static int [ , ] dp = new int [ maxN , maxM ] ; static bool [ , ] v = new bool [ maxN , maxM ] ; static int findCnt ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == 0 ) return 1 ; else return 0 ; } if ( v [ i , curr ] ) return dp [ i , curr ] ; v [ i , curr ] = true ; return dp [ i , curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr + arr [ i ] ) % m , n , m ) ; } public static void Main ( ) { int [ ] arr = { 3 , 3 , 3 , 3 } ; int n = arr . Length ; int m = 6 ; Console . WriteLine ( findCnt ( arr , 0 , 0 , n , m ) - 1 ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 20 ; static int maxM = 64 ; static int [ , ] dp = new int [ maxN , maxM ] ; static bool [ , ] v = new bool [ maxN , maxM ] ; static int findLen ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return - 1 ; } if ( v [ i , curr ] ) return dp [ i , curr ] ; v [ i , curr ] = true ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , curr arr [ i ] , n , m ) ; dp [ i , curr ] = l ; if ( r != - 1 ) dp [ i , curr ] = Math . Max ( dp [ i , curr ] , r + 1 ) ; return dp [ i , curr ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 7 , 2 , 3 } ; int n = arr . Length ; int m = 3 ; int ans = findLen ( arr , 0 , 0 , n , m ) ; if ( ans == - 1 ) Console . WriteLine ( 0 ) ; else Console . WriteLine ( ans ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 300 ; static int maxM = 300 ; static int [ , ] dp = new int [ maxN , maxM ] ; static bool [ , ] v = new bool [ maxN , maxM ] ; static int findLen ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return - 1 ; } if ( v [ i , curr ] ) return dp [ i , curr ] ; v [ i , curr ] = true ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , curr & arr [ i ] , n , m ) ; dp [ i , curr ] = l ; if ( r != - 1 ) dp [ i , curr ] = Math . Max ( dp [ i , curr ] , r + 1 ) ; return dp [ i , curr ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 7 , 2 , 3 } ; int n = arr . Length ; int m = 3 ; int ans = findLen ( arr , 0 , ( ( 1 << 8 ) - 1 ) , n , m ) ; if ( ans == - 1 ) Console . WriteLine ( 0 ) ; else Console . WriteLine ( ans ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 20 ; static int maxM = 64 ; static int [ , ] dp = new int [ maxN , maxM ] ; static Boolean [ , ] v = new Boolean [ maxN , maxM ] ; static int findLen ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == 0 ) return 0 ; else return - 1 ; } if ( v [ i , curr ] ) return dp [ i , curr ] ; v [ i , curr ] = true ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , ( curr + arr [ i ] ) % m , n , m ) ; dp [ i , curr ] = l ; if ( r != - 1 ) dp [ i , curr ] = Math . Max ( dp [ i , curr ] , r + 1 ) ; return dp [ i , curr ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 2 , 1 } ; int n = arr . Length ; int m = 3 ; Console . WriteLine ( findLen ( arr , 0 , 0 , n , m ) ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 20 ; static int maxSum = 50 ; static int minSum = 50 ; static int Base = 50 ; static int [ , ] dp = new int [ maxN , maxSum + minSum ] ; static Boolean [ , ] v = new Boolean [ maxN , maxSum + minSum ] ; static int findCnt ( int [ ] arr , int i , int required_sum , int n ) { if ( i == n ) { if ( required_sum == 0 ) return 1 ; else return 0 ; } if ( v [ i , required_sum + Base ] ) return dp [ i , required_sum + Base ] ; v [ i , required_sum + Base ] = true ; dp [ i , required_sum + Base ] = findCnt ( arr , i + 1 , required_sum , n ) + findCnt ( arr , i + 1 , required_sum - arr [ i ] , n ) ; return dp [ i , required_sum + Base ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 3 , 3 , 3 } ; int n = arr . Length ; int x = 6 ; Console . WriteLine ( findCnt ( arr , 0 , x , n ) ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 20 ; static int maxM = 64 ; static int [ , ] dp = new int [ maxN , maxM ] ; static Boolean [ , ] v = new Boolean [ maxN , maxM ] ; static int findCnt ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { return ( curr == m ? 1 : 0 ) ; } if ( v [ i , curr ] ) return dp [ i , curr ] ; v [ i , curr ] = true ; dp [ i , curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr arr [ i ] ) , n , m ) ; return dp [ i , curr ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 2 } ; int n = arr . Length ; int m = 3 ; Console . WriteLine ( findCnt ( arr , 0 , 0 , n , m ) ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 20 ; static int maxM = 64 ; static int [ , ] dp1 = new int [ maxN , maxM ] ; static bool [ , ] v1 = new bool [ maxN , maxM ] ; static int findCnt ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { return ( curr == m ? 1 : 0 ) ; } if ( v1 [ i , curr ] ) return dp1 [ i , curr ] ; v1 [ i , curr ] = true ; dp1 [ i , curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr & arr [ i ] ) , n , m ) ; return dp1 [ i , curr ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 0 , 0 , 0 } ; int n = arr . Length ; int m = 0 ; Console . WriteLine ( findCnt ( arr , 0 , ( ( 1 << 6 ) - 1 ) , n , m ) ) ; } }

Index/key variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MOD = ( int ) ( 1e9 + 7 ) ; static int modulo_13 ( String s , int n ) { long [ , ] dp = new long [ n + 1 , 13 ] ; dp [ 0 , 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { int nxt = s [ i ] - '0' ; if ( s [ i ] == ' ? ' ) nxt = j ; for ( int k = 0 ; k < 13 ; k ++ ) { int rem = ( 10 * k + nxt ) % 13 ; dp [ i + 1 , rem ] += dp [ i , k ] ; dp [ i + 1 , rem ] %= MOD ; } if ( s [ i ] != ' ? ' ) break ; } } return ( int ) dp [ n , 5 ] ; } public static void Main ( String [ ] args ) { String s = " ? 44" ; int n = s . Length ; Console . WriteLine ( modulo_13 ( s , n ) ) ; } }

Index/key variables: i
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 int LISusingLCS ( List < int > seq ) { int n = seq . Count ; int [ , ] L = new int [ n + 1 , n + 1 ] ; List < int > sortedseq = new List < int > ( seq ) ; sortedseq . Sort ( ) ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i , j ] = 0 ; else if ( seq [ i - 1 ] == sortedseq [ 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 [ n , n ] ; } public static void Main ( String [ ] args ) { List < int > sequence = new List < int > ( ) ; sequence . Add ( 12 ) ; sequence . Add ( 34 ) ; sequence . Add ( 1 ) ; sequence . Add ( 5 ) ; sequence . Add ( 40 ) ; sequence . Add ( 80 ) ; Console . WriteLine ( LISusingLCS ( sequence ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int count_numbers ( int k , int n , bool flag ) { if ( n == 1 ) { if ( flag ) { return ( k - 1 ) ; } else { return 1 ; } } if ( flag ) return ( k - 1 ) * ( count_numbers ( k , n - 1 , false ) + count_numbers ( k , n - 1 , true ) ) ; else return count_numbers ( k , n - 1 , true ) ; } public static void Main ( String [ ] args ) { int n = 3 ; int k = 10 ; Console . Write ( count_numbers ( k , n , true ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int count_numbers ( int k , int n ) { int [ , ] dp = new int [ n + 1 , 2 ] ; dp [ 1 , 0 ] = 0 ; dp [ 1 , 1 ] = k - 1 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i , 0 ] = dp [ i - 1 , 1 ] ; dp [ i , 1 ] = ( dp [ i - 1 , 0 ] + dp [ i - 1 , 1 ] ) * ( k - 1 ) ; } return dp [ n , 0 ] + dp [ n , 1 ] ; } public static void Main ( String [ ] args ) { int k = 10 ; int n = 3 ; Console . WriteLine ( count_numbers ( k , n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int divideArray ( int [ ] arr , int n , int k ) { int [ , ] dp = new int [ 500 , 500 ] ; int i , j ; for ( i = 0 ; i < 500 ; i ++ ) for ( j = 0 ; j < 500 ; j ++ ) dp [ i , j ] = 0 ; k -= 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { for ( j = 0 ; j <= k ; j ++ ) { dp [ i , j ] = int . MaxValue ; int max_ = - 1 , sum = 0 ; for ( int l = i ; l < n ; l ++ ) { max_ = Math . Max ( max_ , arr [ l ] ) ; sum += arr [ l ] ; int diff = ( l - i + 1 ) * max_ - sum ; if ( j > 0 ) dp [ i , j ] = Math . Min ( dp [ i , j ] , diff + dp [ l + 1 , j - 1 ] ) ; else dp [ i , j ] = diff ; } } } return dp [ 0 , k ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 9 , 5 , 4 , 8 , 3 , 6 } ; int n = arr . Length ; int k = 2 ; Console . WriteLine ( divideArray ( arr , n , k ) ) ; } }

Index/key variables: l
Accumulator variables: i, j, k, l, sum
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int cntSubsets ( int [ ] arr , int n ) { int max = ( int ) Math . Pow ( 2 , n ) ; int result = 0 ; for ( int i = 0 ; i < max ; i ++ ) { int counter = i ; if ( ( counter & ( counter >> 1 ) ) > 0 ) continue ; result ++ ; } return result ; } static public void Main ( String [ ] arg ) { int [ ] arr = { 3 , 5 , 7 } ; int n = arr . Length ; Console . WriteLine ( cntSubsets ( arr , n ) ) ; } }

Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int cntSubsets ( int [ ] arr , int n ) { int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; a [ 0 ] = b [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i - 1 ] + b [ i - 1 ] ; b [ i ] = a [ i - 1 ] ; } int result = a [ n - 1 ] + b [ n - 1 ] ; return result ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 5 , 7 } ; int n = arr . Length ; Console . WriteLine ( cntSubsets ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void perfix_calculate ( int [ , ] A , int [ , ] row , int [ , ] col ) { int n = ( int ) A . GetLength ( 0 ) ; int m = ( int ) A . GetLength ( 1 ) ; for ( int i = 0 ; i < n ; ++ i ) { row [ i , 0 ] = A [ i , 0 ] ; } for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 1 ; j < m ; ++ j ) { row [ i , j ] = row [ i , j - 1 ] + A [ i , j ] ; } } for ( int i = 0 ; i < m ; ++ i ) { col [ 0 , i ] = A [ 0 , i ] ; } for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 1 ; j < n ; ++ j ) { col [ j , i ] = A [ j , i ] + col [ j - 1 , i ] ; } } } static int perimeter ( int i , int j , int k , int [ , ] row , int [ , ] col , int [ , ] A ) { int row_s , col_s ; if ( j == 0 ) row_s = 0 ; else row_s = row [ i , j - 1 ] ; if ( i == 0 ) col_s = 0 ; else col_s = col [ i - 1 , j ] ; int upper_row = row [ i , j + k ] - row_s ; int left_col = col [ i + k , j ] - col_s ; if ( j == 0 ) row_s = 0 ; else row_s = row [ i + k , j - 1 ] ; if ( i == 0 ) col_s = 0 ; else col_s = col [ i - 1 , j + k ] ; int lower_row = row [ i + k , j + k ] - row_s ; int right_col = col [ i + k , j + k ] - col_s ; int sum = upper_row + lower_row + left_col + right_col ; sum -= ( A [ i , j ] + A [ i + k , j ] + A [ i , j + k ] + A [ i + k , j + k ] ) ; return sum ; } static int maxPerimeter ( int [ , ] A ) { int n = ( int ) A . GetLength ( 0 ) ; int m = ( int ) A . GetLength ( 1 ) ; int [ , ] row = new int [ n , m ] ; int [ , ] col = new int [ n , m ] ; perfix_calculate ( A , row , col ) ; int maxPer = 0 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { for ( int k = 0 ; k < Math . Min ( n - i , m - j ) ; ++ k ) { int perimtr = perimeter ( i , j , k , row , col , A ) ; maxPer = Math . Max ( maxPer , perimtr ) ; } } } return maxPer ; } public static void Main ( String [ ] args ) { int [ , ] A = { { 1 , 1 , 0 } , { 1 , 1 , 1 } , { 0 , 1 , 1 } } ; Console . Write ( maxPerimeter ( A ) ) ; } }

Accumulator variables: sum
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public static int minJumps ( int [ ] arr , int N ) { int MAX = 1000000 ; int [ ] fib = new int [ 30 ] ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( int i = 2 ; i < 30 ; i ++ ) fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; int [ ] DP = new int [ N + 2 ] ; DP [ 0 ] = 0 ; for ( int i = 1 ; i <= N + 1 ; i ++ ) DP [ i ] = MAX ; for ( int i = 1 ; i <= N + 1 ; i ++ ) { for ( int j = 1 ; j < 30 ; j ++ ) { if ( ( i == N + 1 arr [ i - 1 ] == 1 ) && i - fib [ j ] >= 0 ) DP [ i ] = Math . Min ( DP [ i ] , 1 + DP [ i - fib [ j ] ] ) ; } } if ( DP [ N + 1 ] != MAX ) return DP [ N + 1 ] ; else return - 1 ; } public static void Main ( String [ ] args ) { int [ ] arr = new int [ ] { 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 } ; int n = 11 ; int ans = minJumps ( arr , n ) ; Console . WriteLine ( ans ) ; } }

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 MAX = 100 ; static int recur ( int ind , int cnt , int last , int [ ] a , int n , int k , int [ , ] dp ) { if ( cnt == k ) return 0 ; if ( ind == n ) return ( int ) - 1e9 ; if ( dp [ ind , cnt ] != - 1 ) return dp [ ind , cnt ] ; int ans = 0 ; for ( int i = ind ; i < n ; i ++ ) { if ( cnt % 2 == 0 ) ans = Math . Max ( ans , recur ( i + 1 , cnt + 1 , i , a , n , k , dp ) ) ; else ans = Math . Max ( ans , __gcd ( a [ last ] , a [ i ] ) + recur ( i + 1 , cnt + 1 , 0 , a , n , k , dp ) ) ; } return dp [ ind , cnt ] = ans ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int [ ] a = { 4 , 5 , 3 , 7 , 8 , 10 , 9 , 8 } ; int n = a . Length ; int k = 4 ; int [ , ] dp = new int [ n , MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = - 1 ; } } Console . WriteLine ( recur ( 0 , 0 , 0 , a , n , k , dp ) ) ; } }

Index/key variables: i, last
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int find ( string s ) { if ( s . Length == 0 ) return 0 ; int c = 1 ; string d = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { d += s [ i ] ; string s2 = " " ; if ( i + d . Length < s . Length ) { s2 = s . Substring ( i + 1 , d . Length ) ; } if ( s2 == d ) { c = 1 + find ( s . Substring ( i + 1 ) ) ; break ; } } return c ; } public static void Main ( string [ ] args ) { string s = " abababab " ; Console . Write ( find ( s ) ) ; } }

Index/key variables: i
Accumulator variables: d, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 10 ; public static int maximizeSum ( int [ ] a , int n , int ind , int k , int [ ] dp ) { if ( k == 0 ) { if ( ind == n ) return 0 ; else return - 1000000000 ; } else if ( ind == n ) return - 1000000000 ; else if ( dp [ ind , k ] != - 1 ) return dp [ ind , k ] ; else { int ans = 0 ; int mini = a [ ind ] ; for ( int i = ind ; i < n ; i ++ ) { mini = Math . Min ( mini , a [ i ] ) ; ans = Math . Max ( ans , maximizeSum ( a , n , i + 1 , k - 1 , dp ) + mini ) ; } return dp [ ind , k ] = ans ; } } public static void Main ( String [ ] args ) { int [ ] a = { 5 , 7 , 4 , 2 , 8 , 1 , 6 } ; int k = 3 ; int n = a . Length ; int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) dp [ i , j ] = - 1 ; } Console . WriteLine ( maximizeSum ( a , n , 0 , k , dp ) ) ; } }

Index/key variables: i, ind
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 10 ; static int getCount ( int n ) { int [ ] [ ] list = new int [ MAX ] [ ] ; list [ 0 ] = new int [ ] { 0 , 8 } ; list [ 1 ] = new int [ ] { 1 , 2 , 4 } ; list [ 2 ] = new int [ ] { 2 , 1 , 3 , 5 } ; list [ 3 ] = new int [ ] { 3 , 6 , 2 } ; list [ 4 ] = new int [ ] { 4 , 1 , 7 , 5 } ; list [ 5 ] = new int [ ] { 5 , 4 , 6 , 2 , 8 } ; list [ 6 ] = new int [ ] { 6 , 3 , 5 , 9 } ; list [ 7 ] = new int [ ] { 7 , 4 , 8 } ; list [ 8 ] = new int [ ] { 8 , 5 , 0 , 7 , 9 } ; list [ 9 ] = new int [ ] { 9 , 6 , 8 } ; int [ ] Arr = new int [ ] { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } ; for ( int i = 2 ; i <= n ; i ++ ) { int [ ] Arr2 = new int [ MAX ] ; for ( int j = 0 ; j < MAX ; j ++ ) { for ( int x = 0 ; x < list [ j ] . Length ; x ++ ) { Arr2 [ list [ j ] [ x ] ] += Arr [ j ] ; } } for ( int j = 0 ; j < MAX ; j ++ ) Arr [ j ] = Arr2 [ j ] ; } int sum = 0 ; for ( int i = 0 ; i < MAX ; i ++ ) sum += Arr [ i ] ; return sum ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( getCount ( n ) ) ; } }

Index/key variables: MAX, i, j, x
Accumulator variables: i, j, sum, x
Iterator variables: i, j, x
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp ; static int solveUtil ( int start , int bucket , string str , int K ) { int N = str . Length ; if ( start == N ) { if ( bucket == K ) { return 0 ; } return Int32 . MaxValue ; } if ( bucket == K ) { return Int32 . MaxValue ; } if ( dp [ start , bucket ] != - 1 ) { return dp [ start , bucket ] ; } int zeroes = 0 ; int ones = 0 ; int ans = Int32 . MaxValue ; for ( int i = start ; i < N ; ++ i ) { if ( str [ i ] == '1' ) { ones ++ ; } else { zeroes ++ ; } if ( ones * zeroes > ans ) { break ; } int temp = solveUtil ( i + 1 , bucket + 1 , str , K ) ; if ( temp != Int32 . MaxValue ) { ans = Math . Min ( ans , temp + ( ones * zeroes ) ) ; } } return dp [ start , bucket ] = ans ; } static int solve ( string str , int K ) { int N = str . Length ; dp = new int [ N , K ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < K ; j ++ ) { dp [ i , j ] = - 1 ; } } int ans = solveUtil ( 0 , 0 , str , K ) ; return ans == Int32 . MaxValue ? - 1 : ans ; } static void Main ( ) { string S = "0101" ; int K = 2 ; Console . WriteLine ( solve ( S , K ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, ones, zeroes
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static double Probability ( double [ ] p , int n ) { double [ , ] dp = new double [ n + 1 , n + 1 ] ; dp [ 0 , 0 ] = 1.0 ; for ( int i = 1 ; i <= n ; i += 1 ) { for ( int j = 0 ; j <= i ; j += 1 ) { if ( j == 0 ) dp [ i , j ] = dp [ i - 1 , j ] * ( 1.0 - p [ i ] ) ; else dp [ i , j ] = dp [ i - 1 , j ] * ( 1.0 - p [ i ] ) + dp [ i - 1 , j - 1 ] * p [ i ] ; } } double ans = 0.0 ; for ( int i = ( n + 1 ) / 2 ; i <= n ; i += 1 ) ans += dp [ n , i ] ; return ans ; } static public void Main ( ) { double [ ] p = { 0.0 , 0.3 , 0.4 , 0.7 } ; int n = p . Length - 1 ; Console . Write ( Probability ( p , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp = new int [ 55 , 55 ] ; static int NoofWays ( int face , int throwsVal , int sum ) { if ( sum == 0 && throwsVal == 0 ) { return 1 ; } if ( sum < 0 throwsVal == 0 ) { return 0 ; } if ( dp [ throwsVal , sum ] != - 1 ) { return dp [ throwsVal , sum ] ; } int ans = 0 ; for ( int i = 1 ; i <= face ; i ++ ) { ans += NoofWays ( face , throwsVal - 1 , sum - i ) ; } return dp [ throwsVal , sum ] = ans ; } static public void Main ( ) { int faces = 6 , throwsVal = 3 , sum = 12 ; for ( int i = 0 ; i < 55 ; i ++ ) { for ( int j = 0 ; j < 55 ; j ++ ) { dp [ i , j ] = - 1 ; } } Console . WriteLine ( NoofWays ( faces , throwsVal , sum ) ) ; } }

Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxHappiness ( int A , int N , String [ ] v ) { String str ; int [ ] val = new int [ N ] ; int [ ] wt = new int [ N ] ; int c = 0 ; for ( int i = 0 ; i < N ; i ++ ) { str = v [ i ] ; c = 0 ; for ( int j = 0 ; j < str . Length ; j ++ ) { if ( str [ j ] == ' c ' ) c += 4 ; else if ( str [ j ] == ' w ' ) c += 3 ; else if ( str [ j ] == ' m ' ) c += 2 ; else c ++ ; } c *= str . Length ; val [ i ] = c ; wt [ i ] = str . Length ; } int [ , ] k = new int [ N + 1 , A + 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int w = 0 ; w <= A ; 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 ] ; } } } return k [ N , A ] ; } public static void Main ( ) { int A = 5 ; String [ ] v = { " mmo " , " oo " , " cmw " , " cc " , " c " } ; int N = v . Length ; Console . WriteLine ( maxHappiness ( A , N , v ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: c, i, j, w
Iterator variables: i, j, w
Class/struct names: GFG
C# program:
using System ; class GFG { static int C_MAX = 30 ; static int max_arr_len = 10 ; static int [ , ] dp = new int [ max_arr_len , C_MAX + 1 ] ; static bool [ , ] v = new bool [ max_arr_len , C_MAX + 1 ] ; static int findMax ( int i , int r , int [ ] w , int n ) { if ( r < 0 ) return Int32 . MaxValue ; if ( i == n ) return 0 ; if ( v [ i , r ] ) return dp [ i , r ] ; v [ i , r ] = true ; dp [ i , r ] = Math . Max ( w [ i ] + findMax ( i + 1 , r - w [ i ] , w , n ) , findMax ( i + 1 , r , w , n ) ) ; return dp [ i , r ] ; } static void preCompute ( int [ ] w , int n ) { for ( int i = C_MAX ; i >= 0 ; i -- ) findMax ( 0 , i , w , n ) ; } static int ansQuery ( int w ) { return dp [ 0 , w ] ; } public static void Main ( ) { int [ ] w = { 3 , 8 , 9 } ; int n = w . Length ; preCompute ( w , n ) ; int [ ] queries = { 11 , 10 , 4 } ; int q = queries . Length ; for ( int i = 0 ; i < q ; i ++ ) Console . WriteLine ( ansQuery ( queries [ i ] ) ) ; } }

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