dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { public static long repeatedSum ( long n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } public static long repeatedProduct ( long n ) { long prod = 1 ; while ( n > 0 prod > 9 ) { if ( n == 0 ) { n = prod ; prod = 1 ; } prod *= n % 10 ; n /= 10 ; } return prod ; } public static long maxSumProduct ( long N ) { if ( N < 10 ) return N ; return Math . Max ( repeatedSum ( N ) , repeatedProduct ( N ) ) ; } public static void Main ( ) { long n = 631 ; Console . WriteLine ( maxSumProduct ( n ) ) ; } }

Accumulator variables: n, prod
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > digits = new List < int > ( ) ; static bool [ ] vis = new bool [ 170 ] ; static int [ , , , ] dp = new int [ 19 , 19 , 2 , 170 ] ; static void ConvertIntoDigit ( int n ) { while ( n > 0 ) { int dig = n % 10 ; digits . Add ( dig ) ; n /= 10 ; } digits . Reverse ( ) ; } static int solve ( int idx , int k , int tight , int sum ) { if ( idx == digits . Count && k == 0 && sum % 2 == 1 ) { if ( ! vis [ sum ] ) { vis [ sum ] = true ; return 1 ; } return 0 ; } if ( idx > digits . Count ) { return 0 ; } if ( dp [ idx , k , tight , sum ] > 0 ) { return dp [ idx , k , tight , sum ] ; } int j ; if ( idx < digits . Count && tight == 0 ) { j = digits [ idx ] ; } else { j = 9 ; } int cnt = 0 ; for ( int i = ( k > 0 ? 0 : 1 ) ; i <= j ; i ++ ) { int newtight = tight ; if ( i < j ) { newtight = 1 ; } if ( i == 0 ) cnt += solve ( idx + 1 , k - 1 , newtight , sum ) ; else cnt += solve ( idx + 1 , k , newtight , sum + i ) ; } return dp [ idx , k , tight , sum ] = cnt ; } public static void Main ( String [ ] args ) { int N , k ; N = 169 ; k = 2 ; ConvertIntoDigit ( N ) ; k = digits . Count - k ; Console . Write ( solve ( 0 , k , 0 , 0 ) ) ; } }

Index/key variables: idx, sum
Accumulator variables: cnt, i, n
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int countSubsets ( int N ) { if ( N <= 2 ) return N ; if ( N == 3 ) return 2 ; int [ ] DP = new int [ N + 1 ] ; DP [ 0 ] = 0 ; DP [ 1 ] = 1 ; DP [ 2 ] = 2 ; DP [ 3 ] = 2 ; for ( int i = 4 ; i <= N ; i ++ ) { DP [ i ] = DP [ i - 2 ] + DP [ i - 3 ] ; } return DP [ N ] ; } public static void Main ( String [ ] args ) { int N = 20 ; Console . Write ( countSubsets ( N ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp = new int [ 500 , 500 ] ; static int CountSets ( int x , int pos ) { if ( x <= 0 ) { if ( pos == 0 ) return 1 ; else return 0 ; } if ( pos == 0 ) return 1 ; if ( dp [ x , pos ] != - 1 ) return dp [ x , pos ] ; int answer = CountSets ( x - 1 , pos ) + CountSets ( x - 2 , pos - 1 ) ; return dp [ x , pos ] = answer ; } static int CountOrderedSets ( int n ) { int [ ] factorial = new int [ 10000 ] ; factorial [ 0 ] = 1 ; for ( int i = 1 ; i < 10000 ; i ++ ) factorial [ i ] = factorial [ i - 1 ] * i ; int answer = 0 ; for ( int i = 0 ; i < 500 ; i ++ ) { for ( int j = 0 ; j < 500 ; j ++ ) { dp [ i , j ] = - 1 ; } } for ( int i = 1 ; i <= n ; i ++ ) { int sets = CountSets ( n , i ) * factorial [ i ] ; answer = answer + sets ; } return answer ; } public static void Main ( String [ ] args ) { int N = 3 ; Console . Write ( CountOrderedSets ( N ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int numberOfArithmeticSequences ( int [ ] L , int N ) { if ( N <= 2 ) return 0 ; int count = 0 ; int res = 0 ; for ( int i = 2 ; i < N ; ++ i ) { if ( L [ i ] - L [ i - 1 ] == L [ i - 1 ] - L [ i - 2 ] ) { ++ count ; } else { count = 0 ; } res += count ; } return res ; } public static void Main ( String [ ] args ) { int [ ] L = { 1 , 3 , 5 , 6 , 7 , 8 } ; int N = L . Length ; Console . Write ( numberOfArithmeticSequences ( L , N ) ) ; } }

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int CountOfTriplets ( int [ ] a , int n ) { int answer = 0 ; int x = 0 ; int [ ] count = new int [ 100005 ] ; int [ ] ways = new int [ 100005 ] ; for ( int i = 0 ; i < n ; i ++ ) { x ^= a [ i ] ; answer += count [ x ] * i - ways [ x ] ; count [ x ] ++ ; ways [ x ] += ( i + 1 ) ; } return answer ; } public static void Main ( String [ ] args ) { int [ ] Arr = { 3 , 6 , 12 , 8 , 6 , 2 , 1 , 5 } ; int N = Arr . Length ; Console . Write ( CountOfTriplets ( Arr , N ) ) ; } }

Index/key variables: i, x
Accumulator variables: answer, i, x
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int [ , ] dp = new int [ 5000 , ( 1 << 10 ) + 5 ] ; static int getmask ( int val ) { int mask = 0 ; if ( val == 0 ) return 1 ; while ( val > 0 ) { int d = val % 10 ; mask |= ( 1 << d ) ; val /= 10 ; } return mask ; } static int countWays ( int pos , int mask , int [ ] a , int n ) { if ( pos == n ) return ( mask > 0 ? 1 : 0 ) ; if ( dp [ pos , mask ] != - 1 ) return dp [ pos , mask ] ; int count = 0 ; count = count + countWays ( pos + 1 , mask , a , n ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { int new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; count = count + countWays ( pos + 1 , new_mask , a , n ) ; } return dp [ pos , mask ] = count ; } static int numberOfSubarrays ( int [ ] a , int n ) { for ( int i = 0 ; i < 5000 ; i ++ ) { for ( int j = 0 ; j < ( 1 << 10 ) + 5 ; j ++ ) { dp [ i , j ] = - 1 ; } } return countWays ( 0 , 0 , a , n ) ; } public static void Main ( String [ ] args ) { int N = 4 ; int [ ] A = { 1 , 12 , 23 , 34 } ; Console . Write ( numberOfSubarrays ( A , N ) ) ; } }

Index/key variables: pos
Accumulator variables: i, j, mask, val
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > fib = new List < int > ( ) ; class node { public node left ; public int data ; public node right ; } ; static node newNode ( int data ) { node temp = new node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } static int height ( node root ) { if ( root == null ) return 0 ; return ( Math . Max ( height ( root . left ) , height ( root . right ) ) + 1 ) ; } static void FibonacciSeries ( int n ) { fib . Add ( 0 ) ; fib . Add ( 1 ) ; for ( int i = 2 ; i < n ; i ++ ) fib . Add ( fib [ i - 1 ] + fib [ i - 2 ] ) ; } static int CountPathUtil ( node root , int i , int count ) { if ( root == null || ! ( fib [ i ] == root . data ) ) { return count ; } if ( root . left != null && root . right != null ) { count ++ ; } count = CountPathUtil ( root . left , i + 1 , count ) ; return CountPathUtil ( root . right , i + 1 , count ) ; } static void CountPath ( node root ) { int ht = height ( root ) ; FibonacciSeries ( ht ) ; Console . Write ( CountPathUtil ( root , 0 , 0 ) ) ; } public static void Main ( String [ ] args ) { node root = newNode ( 0 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 1 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 4 ) ; root . right . right = newNode ( 1 ) ; root . right . right . left = newNode ( 2 ) ; CountPath ( root ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG, node
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int M = 18 ; static int a , b ; static int [ , , , ] dp = new int [ M , 90 , 90 , 2 ] ; static HashSet < int > fib = new HashSet < int > ( ) ; static void fibonacci ( ) { int prev = 0 , curr = 1 ; fib . Add ( prev ) ; fib . Add ( curr ) ; while ( curr <= 100 ) { int temp = curr + prev ; fib . Add ( temp ) ; prev = curr ; curr = temp ; } } static int count ( int pos , int even , int odd , int tight , List < int > num ) { if ( pos == num . Count ) { if ( num . Count % 2 == 1 ) { odd = odd + even ; even = odd - even ; odd = odd - even ; } int d = even - odd ; if ( fib . Contains ( d ) ) return 1 ; return 0 ; } if ( dp [ pos , even , odd , tight ] != - 1 ) return dp [ pos , even , odd , tight ] ; int ans = 0 ; int limit = ( tight == 1 ? 9 : num [ pos ] ) ; for ( int d = 0 ; d <= limit ; d ++ ) { int currF = tight , currEven = even ; int currOdd = odd ; if ( d < num [ pos ] ) currF = 1 ; if ( pos % 2 == 1 ) currOdd += d ; else currEven += d ; ans += count ( pos + 1 , currEven , currOdd , currF , num ) ; } return dp [ pos , even , odd , tight ] = ans ; } static int solve ( int x ) { List < int > num = new List < int > ( ) ; while ( x > 0 ) { num . Add ( x % 10 ) ; x /= 10 ; } num . Reverse ( ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < 90 ; j ++ ) { for ( int l = 0 ; l < 90 ; l ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { dp [ i , j , l , k ] = - 1 ; } } } } return count ( 0 , 0 , 0 , 0 , num ) ; } public static void Main ( String [ ] args ) { fibonacci ( ) ; int L = 1 , R = 50 ; Console . Write ( solve ( R ) - solve ( L - 1 ) + " STRNEWLINE " ) ; L = 50 ; R = 100 ; Console . Write ( solve ( R ) - solve ( L - 1 ) + " STRNEWLINE " ) ; } }

Index/key variables: pos
Accumulator variables: ans, currEven, currOdd, d, i, j, k, l, x
Iterator variables: d, i, j, k, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int maximumOccurrence ( string s ) { int n = s . Length ; int [ ] freq = new int [ 26 ] ; int [ , ] dp = new int [ 26 , 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = ( s [ i ] - ' a ' ) ; for ( int j = 0 ; j < 26 ; j ++ ) dp [ x , j ] += freq [ j ] ; freq [ x ] ++ ; } int answer = int . MinValue ; for ( int i = 0 ; i < 26 ; i ++ ) answer = Math . Max ( answer , freq [ i ] ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { answer = Math . Max ( answer , dp [ i , j ] ) ; } } return answer ; } public static void Main ( string [ ] args ) { string s = " xxxyy " ; Console . Write ( maximumOccurrence ( s ) ) ; } }

Index/key variables: i, j, x
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int mod = 1000000007 ; static int [ , , ] dp = new int [ 1005 , 105 , 2 ] ; static int [ ] powers = new int [ 1005 ] ; static int [ ] powersModk = new int [ 1005 ] ; static int calculate ( int pos , int rem , int z , int k , int n ) { if ( rem == 0 && z != 0 ) { if ( pos != n ) return ( powers [ n - pos - 1 ] * 9 ) % mod ; else return 1 ; } if ( pos == n ) return 0 ; if ( dp [ pos , rem , z ] != - 1 ) return dp [ pos , rem , z ] ; int count = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( i == 0 ) count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , z , k , n ) ) ) % mod ; else count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , 1 , k , n ) ) ) % mod ; } return dp [ pos , rem , z ] = count ; } static int countNumbers ( int n , int k ) { int st = 1 ; int i ; for ( i = 0 ; i <= n ; i ++ ) { powers [ i ] = st ; st *= 10 ; st %= mod ; } st = 1 ; for ( i = 0 ; i <= n ; i ++ ) { powersModk [ i ] = st ; st *= 10 ; st %= mod ; } for ( i = 0 ; i < 1005 ; i ++ ) { for ( int j = 0 ; j < 105 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) dp [ i , j , l ] = - 1 ; } } return calculate ( 0 , 0 , 0 , k , n ) ; } public static void Main ( String [ ] args ) { int N = 2 ; int K = 2 ; Console . Write ( countNumbers ( N , K ) ) ; } }

Index/key variables: i, pos
Accumulator variables: i, j, l, st
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { public static int maxLengthSquare ( int row , int column , int [ , ] arr , int k ) { int [ , ] sum = new int [ row + 1 , column + 1 ] ; int cur_max = 1 ; int max = 0 ; for ( int i = 1 ; i <= row ; i ++ ) { for ( int j = 1 ; j <= column ; j ++ ) { sum [ i , j ] = sum [ i - 1 , j ] + sum [ i , j - 1 ] + arr [ i - 1 , j - 1 ] - sum [ i - 1 , j - 1 ] ; if ( i >= cur_max && j >= cur_max && sum [ i , j ] - sum [ i - cur_max , j ] - sum [ i , j - cur_max ] + sum [ i - cur_max , j - cur_max ] <= k ) { max = cur_max ++ ; } } } return max ; } public static void Main ( ) { int row = 4 , column = 4 ; int [ , ] matrix = { { 1 , 1 , 1 , 1 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } } ; int k = 6 ; int ans = maxLengthSquare ( row , column , matrix , k ) ; Console . WriteLine ( ans ) ; } }

Accumulator variables: cur_max, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 101 ; static int mod = ( int ) 1e9 + 7 ; static int [ , , ] exactsum = new int [ N , N , N ] ; static int [ , , ] exactnum = new int [ N , N , N ] ; static int getSum ( int x , int y , int z ) { int ans = 0 ; exactnum [ 0 , 0 , 0 ] = 1 ; for ( int i = 0 ; i <= x ; ++ i ) { for ( int j = 0 ; j <= y ; ++ j ) { for ( int k = 0 ; k <= z ; ++ k ) { if ( i > 0 ) { exactsum [ i , j , k ] += ( exactsum [ i - 1 , j , k ] * 10 + 4 * exactnum [ i - 1 , j , k ] ) % mod ; exactnum [ i , j , k ] += exactnum [ i - 1 , j , k ] % mod ; } if ( j > 0 ) { exactsum [ i , j , k ] += ( exactsum [ i , j - 1 , k ] * 10 + 5 * exactnum [ i , j - 1 , k ] ) % mod ; exactnum [ i , j , k ] += exactnum [ i , j - 1 , k ] % mod ; } if ( k > 0 ) { exactsum [ i , j , k ] += ( exactsum [ i , j , k - 1 ] * 10 + 6 * exactnum [ i , j , k - 1 ] ) % mod ; exactnum [ i , j , k ] += exactnum [ i , j , k - 1 ] % mod ; } ans += exactsum [ i , j , k ] % mod ; ans %= mod ; } } } return ans ; } public static void Main ( ) { int x = 1 , y = 1 , z = 1 ; Console . WriteLine ( getSum ( x , y , z ) % mod ) ; } }

Accumulator variables: ans
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static void findMax ( int [ ] a , int n ) { int [ , ] dp = new int [ n , 2 ] ; int i , j ; for ( i = 0 ; i < n ; i ++ ) for ( j = 0 ; j < 2 ; j ++ ) dp [ i , j ] = 0 ; dp [ 0 , 0 ] = a [ 0 ] + a [ 1 ] ; dp [ 0 , 1 ] = a [ 0 ] * a [ 1 ] ; for ( i = 1 ; i <= n - 2 ; i ++ ) { dp [ i , 0 ] = Math . Max ( dp [ i - 1 , 0 ] , dp [ i - 1 , 1 ] ) + a [ i + 1 ] ; dp [ i , 1 ] = dp [ i - 1 , 0 ] - a [ i ] + a [ i ] * a [ i + 1 ] ; } Console . WriteLine ( Math . Max ( dp [ n - 2 , 0 ] , dp [ n - 2 , 1 ] ) ) ; } public static void Main ( ) { int [ ] arr = { 5 , - 1 , - 5 , - 3 , 2 , 9 , - 4 } ; findMax ( arr , 7 ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int sum ( int [ ] arr , int l , int r ) { int s = 0 ; for ( int i = l ; i <= r ; i ++ ) { s += arr [ i ] ; } return s ; } static int [ , , ] dp = new int [ 101 , 101 , 101 ] ; static int solve ( int [ ] arr , int l , int r , int k ) { if ( r - l + 1 <= k ) return sum ( arr , l , r ) ; if ( dp [ l , r , k ] != 0 ) return dp [ l , r , k ] ; int sum_ = sum ( arr , l , r ) ; int len_r = ( r - l + 1 ) - k ; int len = ( r - l + 1 ) ; int ans = 0 ; for ( int i = 0 ; i < len - len_r + 1 ; i ++ ) { int sum_sub = sum ( arr , i + l , i + l + len_r - 1 ) ; ans = Math . Max ( ans , ( sum_ - sum_sub ) + ( sum_sub - solve ( arr , i + l , i + l + len_r - 1 , k ) ) ) ; } dp [ l , r , k ] = ans ; return ans ; } public static void Main ( ) { int [ ] arr = { 10 , 15 , 20 , 9 , 2 , 5 } ; int k = 2 ; int n = arr . Length ; Console . WriteLine ( solve ( arr , 0 , n - 1 , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAXI = 50 ; static int [ , , ] dp = new int [ MAXI , MAXI , MAXI * MAXI ] ; static int n , m ; static int INT_MAX = int . MaxValue ; static int minDifference ( int x , int y , int k , int [ , ] b , int [ , ] c ) { int diff = 0 ; if ( x >= n y >= m ) return INT_MAX ; if ( x == n - 1 && y == m - 1 ) { diff = b [ x , y ] - c [ x , y ] ; return Math . Min ( Math . Abs ( k - diff ) , Math . Abs ( k + diff ) ) ; } int ans = dp [ x , y , k ] ; if ( ans != - 1 ) return ans ; ans = INT_MAX ; diff = b [ x , y ] - c [ x , y ] ; ans = Math . Min ( ans , minDifference ( x + 1 , y , Math . Abs ( k + diff ) , b , c ) ) ; ans = Math . Min ( ans , minDifference ( x , y + 1 , Math . Abs ( k + diff ) , b , c ) ) ; ans = Math . Min ( ans , minDifference ( x + 1 , y , Math . Abs ( k - diff ) , b , c ) ) ; ans = Math . Min ( ans , minDifference ( x , y + 1 , Math . Abs ( k - diff ) , b , c ) ) ; return ans ; } public static void Main ( ) { n = 2 ; m = 2 ; int [ , ] b = { { 1 , 4 } , { 2 , 4 } } ; int [ , ] c = { { 3 , 2 } , { 3 , 1 } } ; for ( int i = 0 ; i < MAXI ; i ++ ) { for ( int j = 0 ; j < MAXI ; j ++ ) { for ( int k = 0 ; k < MAXI * MAXI ; k ++ ) { dp [ i , j , k ] = - 1 ; } } } Console . WriteLine ( minDifference ( 0 , 0 , 0 , b , c ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int longest_subseq ( int n , int k , String s ) { int [ ] dp = new int [ n ] ; int [ ] max_length = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int curr = s [ i ] - ' a ' ; int lower = Math . Max ( 0 , curr - k ) ; int upper = Math . Min ( 25 , curr + k ) ; for ( int j = lower ; j < upper + 1 ; j ++ ) { dp [ i ] = Math . Max ( dp [ i ] , max_length [ j ] + 1 ) ; } max_length [ curr ] = Math . Max ( dp [ i ] , max_length [ curr ] ) ; } int ans = 0 ; foreach ( int i in dp ) ans = Math . Max ( i , ans ) ; return ans ; } public static void Main ( String [ ] args ) { String s = " geeksforgeeks " ; int n = s . Length ; int k = 3 ; Console . Write ( longest_subseq ( n , k , s ) ) ; } }

Index/key variables: curr, i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System . Collections . Generic ; using System ; class GFG { static bool areAllNegative ( int [ ] arr ) { int n = arr . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) return false ; } return true ; } static int [ ] getRightToLeftKadane ( int [ ] arr ) { int max_so_far = 0 , max_ending_here = 0 ; int size = arr . Length ; int [ ] new_arr = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) new_arr [ i ] = arr [ i ] ; for ( int i = size - 1 ; i >= 0 ; i -- ) { max_ending_here = max_ending_here + new_arr [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; new_arr [ i ] = max_so_far ; } return new_arr ; } static int [ ] getPrefixSum ( int [ ] arr ) { int n = arr . Length ; int [ ] new_arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) new_arr [ i ] = arr [ i ] ; for ( int i = 1 ; i < n ; i ++ ) new_arr [ i ] = new_arr [ i - 1 ] + new_arr [ i ] ; return new_arr ; } static int maxSumSubArr ( int [ ] a ) { int max_so_far = 0 , max_ending_here = 0 ; int n = a . Length ; for ( int i = 0 ; i < n ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; } static int maxSumSubWithOp ( int [ ] arr ) { int [ ] kadane_r_to_l = getRightToLeftKadane ( arr ) ; int size = arr . Length ; int [ ] prefixSum = getPrefixSum ( arr ) ; for ( int i = 1 ; i < size ; i ++ ) { prefixSum [ i ] = Math . Max ( prefixSum [ i - 1 ] , prefixSum [ i ] ) ; } int max_subarray_sum = 0 ; for ( int i = 0 ; i < size - 1 ; i ++ ) { max_subarray_sum = Math . Max ( max_subarray_sum , prefixSum [ i ] + kadane_r_to_l [ i + 1 ] ) ; } return max_subarray_sum ; } static int maxSum ( int [ ] arr , int size ) { if ( areAllNegative ( arr ) ) { int mx = - 1000000000 ; for ( int i = 0 ; i < size ; i ++ ) { if ( arr [ i ] > mx ) mx = arr [ i ] ; } return mx ; } int resSum = maxSumSubArr ( arr ) ; resSum = Math . Max ( resSum , maxSumSubWithOp ( arr ) ) ; int [ ] reverse_arr = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) reverse_arr [ size - 1 - i ] = arr [ i ] ; resSum = Math . Max ( resSum , maxSumSubWithOp ( reverse_arr ) ) ; return resSum ; } public static void Main ( ) { int [ ] arr = { - 9 , 21 , 24 , 24 , - 51 , - 6 , 17 , - 42 , - 39 , 33 } ; int size = arr . Length ; Console . Write ( maxSum ( arr , size ) ) ; } }

Index/key variables: i, n, size
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int max_sum ( int [ ] a , int n ) { int [ , ] dp = new int [ n + 1 , 2 ] ; dp [ 0 , 0 ] = 0 ; dp [ 0 , 1 ] = - 999999 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { dp [ i + 1 , 0 ] = Math . Max ( dp [ i , 0 ] + a [ i ] , dp [ i , 1 ] - a [ i ] ) ; dp [ i + 1 , 1 ] = Math . Max ( dp [ i , 0 ] - a [ i ] , dp [ i , 1 ] + a [ i ] ) ; } return dp [ n , 0 ] ; } public static void Main ( String [ ] args ) { int [ ] a = { - 10 , 5 , - 4 } ; int n = a . Length ; Console . WriteLine ( max_sum ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int MOD = 1000000007 ; static int number_of_ways ( int [ ] arr , int n , int k ) { if ( k == 1 ) return 1 ; int [ ] dp = new int [ k + 1 ] ; int i ; for ( i = 0 ; i < k + 1 ; i ++ ) dp [ i ] = - 1 ; for ( i = 0 ; i < n ; i ++ ) dp [ arr [ i ] ] = 0 ; dp [ 0 ] = 1 ; dp [ 1 ] = ( dp [ 1 ] == - 1 ) ? 1 : dp [ 1 ] ; for ( i = 2 ; i <= k ; ++ i ) { if ( dp [ i ] == 0 ) continue ; dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ; dp [ i ] %= MOD ; } return dp [ k ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 } ; int n = arr . Length ; int k = 6 ; Console . WriteLine ( number_of_ways ( arr , n , k ) ) ; } }

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int findCount ( int n ) { return ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) + 1 ; } public static void Main ( ) { int N = 10 ; Console . Write ( findCount ( N ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int count ( int n ) { int count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } static void findSetBits ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) Console . Write ( count ( i ) + " ▁ " ) ; } public static void Main ( String [ ] args ) { int n = 5 ; findSetBits ( n ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int countWays ( int n ) { List < int > a = new List < int > ( ) ; int i = 1 ; while ( i <= n ) a . Add ( i ++ ) ; int ways = 0 ; do { bool flag = ( a [ 0 ] == 1 ) ; for ( int j = 1 ; j < n ; j ++ ) { if ( Math . Abs ( a [ j ] - a [ j - 1 ] ) > 2 ) flag = false ; } if ( flag ) ways ++ ; } while ( next_permutation ( a ) ) ; return ways ; } static bool next_permutation ( List < int > p ) { for ( int a = p . Count - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( int b = p . Count - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { int t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . Count - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } public static void Main ( String [ ] args ) { int n = 6 ; Console . Write ( countWays ( n ) ) ; } }

Index/key variables: a, b, j
Accumulator variables: i, j, ways
Iterator variables: a, b, j
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; class GFG { static int countWays ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { dp [ i ] = dp [ i - 1 ] + dp [ i - 3 ] + 1 ; } return dp [ n ] ; } public static void Main ( ) { int n = 6 ; Console . WriteLine ( countWays ( n ) ) ; } }

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