dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; using System . Collections . Generic ; class GFG { static Dictionary < Tuple < int , int > , int > m = new Dictionary < Tuple < int , int > , int > ( ) ; static int findMinimum ( int [ ] arr , int N , int pos , int turn ) { Tuple < int , int > x = new Tuple < int , int > ( pos , turn ) ; if ( m . ContainsKey ( x ) ) { return m [ x ] ; } if ( pos >= N - 1 ) { return 0 ; } if ( turn == 0 ) { int ans = Math . Min ( findMinimum ( arr , N , pos + 1 , 1 ) + arr [ pos ] , findMinimum ( arr , N , pos + 2 , 1 ) + arr [ pos ] + arr [ pos + 1 ] ) ; Tuple < int , int > v = new Tuple < int , int > ( pos , turn ) ; m [ v ] = ans ; return ans ; } if ( turn != 0 ) { int ans = Math . Min ( findMinimum ( arr , N , pos + 1 , 0 ) , findMinimum ( arr , N , pos + 2 , 0 ) ) ; Tuple < int , int > v = new Tuple < int , int > ( pos , turn ) ; m [ v ] = ans ; return ans ; } return 0 ; } static int countPenality ( int [ ] arr , int N ) { int pos = 0 ; int turn = 0 ; return findMinimum ( arr , N , pos , turn ) + 1 ; } static void printAnswer ( int [ ] arr , int N ) { int a = countPenality ( arr , N ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } Console . WriteLine ( a ) ; } static void Main ( ) { int [ ] arr = { 1 , 0 , 1 , 1 , 0 , 1 , 1 , 1 } ; int N = 8 ; printAnswer ( arr , N ) ; } }

Index/key variables: i, pos, v, x
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 1000001 ; static int [ ] prime = new int [ MAX ] ; static void SieveOfEratosthenes ( ) { Array . Fill ( prime , 1 ) ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == 1 ) { for ( int i = p * p ; i <= MAX - 1 ; i += p ) prime [ i ] = 0 ; } } } static int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } static int getSumUtil ( int [ ] st , int ss , int se , int qs , int qe , int si ) { if ( qs <= ss && qe >= se ) return st [ si ] ; if ( se < qs ss > qe ) return 0 ; int mid = getMid ( ss , se ) ; return getSumUtil ( st , ss , mid , qs , qe , 2 * si + 1 ) + getSumUtil ( st , mid + 1 , se , qs , qe , 2 * si + 2 ) ; } static void updateValueUtil ( int [ ] st , int ss , int se , int i , int diff , int si ) { if ( i < ss i > se ) return ; st [ si ] = st [ si ] + diff ; if ( se != ss ) { int mid = getMid ( ss , se ) ; updateValueUtil ( st , ss , mid , i , diff , 2 * si + 1 ) ; updateValueUtil ( st , mid + 1 , se , i , diff , 2 * si + 2 ) ; } } static void updateValue ( int [ ] arr , int [ ] st , int n , int i , int new_val ) { if ( i < 0 i > n - 1 ) { Console . Write ( " - 1" ) ; return ; } int diff = new_val - arr [ i ] ; int prev_val = arr [ i ] ; arr [ i ] = new_val ; if ( ( prime [ new_val ] prime [ prev_val ] ) ! = 0 ) { if ( prime [ prev_val ] == 0 ) updateValueUtil ( st , 0 , n - 1 , i , new_val , 0 ) ; else if ( prime [ new_val ] == 0 ) updateValueUtil ( st , 0 , n - 1 , i , - prev_val , 0 ) ; else updateValueUtil ( st , 0 , n - 1 , i , diff , 0 ) ; } } static int getSum ( int [ ] st , int n , int qs , int qe ) { if ( qs < 0 qe > n - 1 qs > qe ) { Console . WriteLine ( " - 1" ) ; return - 1 ; } return getSumUtil ( st , 0 , n - 1 , qs , qe , 0 ) ; } static int constructSTUtil ( int [ ] arr , int ss , int se , int [ ] st , int si ) { if ( ss == se ) { if ( prime [ arr [ ss ] ] != 0 ) st [ si ] = arr [ ss ] ; else st [ si ] = 0 ; return st [ si ] ; } int mid = getMid ( ss , se ) ; st [ si ] = constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) + constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ; return st [ si ] ; } static int [ ] constructST ( int [ ] arr , int n ) { int x = ( int ) ( Math . Ceiling ( Math . Log ( n , 2 ) ) ) ; int max_size = 2 * ( int ) Math . Pow ( 2 , x ) - 1 ; int [ ] st = new int [ max_size ] ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } static void Main ( ) { int [ ] arr = { 1 , 3 , 5 , 7 , 9 , 11 } ; int n = arr . Length ; SieveOfEratosthenes ( ) ; int [ ] st = constructST ( arr , n ) ; Console . WriteLine ( getSum ( st , n , 1 , 3 ) ) ; updateValue ( arr , st , n , 1 , 10 ) ; Console . WriteLine ( getSum ( st , n , 1 , 3 ) ) ; } }

Index/key variables: MAX, i, max_size, new_val, p, prev_val, si, ss
Accumulator variables: i, p
Iterator variables: i, p
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int mod = 1000000007 ; static int [ , ] dp = new int [ 1000 , 1000 ] ; static int calculate ( int pos , int prev , String s , List < int > index ) { if ( pos == s . Length ) return 1 ; if ( dp [ pos , prev ] != - 1 ) return dp [ pos , prev ] ; int answer = 0 ; for ( int i = 0 ; i < index . Count ; i ++ ) { if ( index [ i ] . CompareTo ( prev ) >= 0 ) { answer = ( answer % mod + calculate ( pos + 1 , index [ i ] , s , index ) % mod ) % mod ; } } return dp [ pos , prev ] = answer ; } static int countWays ( List < String > a , String s ) { int n = a . Count ; List < int > [ ] index = new List < int > [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) index [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < a [ i ] . Length ; j ++ ) { index [ a [ i ] [ j ] - ' a ' ] . Add ( j + 1 ) ; } } for ( int i = 0 ; i < 1000 ; i ++ ) { for ( int j = 0 ; j < 1000 ; j ++ ) { dp [ i , j ] = - 1 ; } } return calculate ( 0 , 0 , s , index [ 0 ] ) ; } public static void Main ( String [ ] args ) { List < String > A = new List < String > ( ) ; A . Add ( " adc " ) ; A . Add ( " aec " ) ; A . Add ( " erg " ) ; String S = " ac " ; Console . Write ( countWays ( A , S ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 10005 ; static readonly int MOD = 1000000007 ; static int [ , , ] dp = new int [ MAX , 101 , 2 ] ; static int countNum ( int idx , int sum , int tight , List < int > num , int len , int k ) { if ( len == idx ) { if ( sum == 0 ) return 1 ; else return 0 ; } if ( dp [ idx , sum , tight ] != - 1 ) return dp [ idx , sum , tight ] ; int res = 0 , limit ; if ( tight == 0 ) { limit = num [ idx ] ; } else { limit = 9 ; } for ( int i = 0 ; i <= limit ; i ++ ) { int new_tight = tight ; if ( tight == 0 && i < limit ) new_tight = 1 ; res += countNum ( idx + 1 , ( sum + i ) % k , new_tight , num , len , k ) ; res %= MOD ; } if ( res < 0 ) res += MOD ; return dp [ idx , sum , tight ] = res ; } static List < int > process ( String s ) { List < int > num = new List < int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { num . Add ( s [ i ] - '0' ) ; } return num ; } public static void Main ( String [ ] args ) { String n = "98765432109876543210" ; int len = n . Length ; int k = 58 ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < 101 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) dp [ i , j , l ] = - 1 ; } } List < int > num = process ( n ) ; Console . Write ( countNum ( 0 , 0 , 0 , num , len , k ) ) ; } }

Index/key variables: i, idx
Accumulator variables: i, j, l, res
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { public static int [ ] countSum ( int [ ] arr , int n ) { int [ ] countODD = new int [ n + 1 ] ; int [ ] countEVEN = new int [ n + 1 ] ; countODD [ 0 ] = 0 ; countEVEN [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] % 2 == 0 ) { countEVEN [ i ] = countEVEN [ i - 1 ] + countEVEN [ i - 1 ] + 1 ; countODD [ i ] = countODD [ i - 1 ] + countODD [ i - 1 ] ; } else { countEVEN [ i ] = countEVEN [ i - 1 ] + countODD [ i - 1 ] ; countODD [ i ] = countODD [ i - 1 ] + countEVEN [ i - 1 ] + 1 ; } } int [ ] ans = new int [ 2 ] ; ans [ 0 ] = countEVEN [ n ] ; ans [ 1 ] = countODD [ n ] ; return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 2 , 3 } ; int n = 4 ; int [ ] ans = countSum ( arr , n ) ; Console . WriteLine ( " EvenSum ▁ = ▁ " + ans [ 0 ] ) ; Console . WriteLine ( " OddSum ▁ = ▁ " + ans [ 1 ] ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxN = 31 ; static int maxW = 31 ; static int [ , , ] dp = new int [ maxN , maxW , maxW ] ; static int maxWeight ( int [ ] arr , int n , int w1_r , int w2_r , int i ) { if ( i == n ) return 0 ; if ( dp [ i , w1_r , w2_r ] != - 1 ) return dp [ i , w1_r , w2_r ] ; int fill_w1 = 0 , fill_w2 = 0 , fill_none = 0 ; if ( w1_r >= arr [ i ] ) fill_w1 = arr [ i ] + maxWeight ( arr , n , w1_r - arr [ i ] , w2_r , i + 1 ) ; if ( w2_r >= arr [ i ] ) fill_w2 = arr [ i ] + maxWeight ( arr , n , w1_r , w2_r - arr [ i ] , i + 1 ) ; fill_none = maxWeight ( arr , n , w1_r , w2_r , i + 1 ) ; dp [ i , w1_r , w2_r ] = Math . Max ( fill_none , Math . Max ( fill_w1 , fill_w2 ) ) ; return dp [ i , w1_r , w2_r ] ; } public static void Main ( ) { int [ ] arr = { 8 , 2 , 3 } ; for ( int i = 0 ; i < maxN ; i ++ ) for ( int j = 0 ; j < maxW ; j ++ ) for ( int k = 0 ; k < maxW ; k ++ ) dp [ i , j , k ] = - 1 ; int n = arr . Length ; int w1 = 10 , w2 = 3 ; Console . WriteLine ( maxWeight ( arr , n , w1 , w2 , 0 ) ) ; } }

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 n = 3 ; static void findPrefixCount ( int [ , ] p_arr , bool [ , ] set_bit ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = n - 1 ; j >= 0 ; j -- ) { if ( ! set_bit [ i , j ] ) continue ; if ( j != n - 1 ) p_arr [ i , j ] += p_arr [ i , j + 1 ] ; p_arr [ i , j ] += ( set_bit [ i , j ] ) ? 1 : 0 ; } } } public class pair { public int first , second ; public pair ( ) { } public pair ( int a , int b ) { first = a ; second = b ; } } static int matrixAllOne ( bool [ , ] set_bit ) { int [ , ] p_arr = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) p_arr [ i , j ] = 0 ; findPrefixCount ( p_arr , set_bit ) ; int ans = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int i = n - 1 ; Stack < pair > q = new Stack < pair > ( ) ; int to_sum = 0 ; while ( i >= 0 ) { int c = 0 ; while ( q . Count != 0 && q . Peek ( ) . first > p_arr [ i , j ] ) { to_sum -= ( q . Peek ( ) . second + 1 ) * ( q . Peek ( ) . first - p_arr [ i , j ] ) ; c += q . Peek ( ) . second + 1 ; q . Pop ( ) ; } to_sum += p_arr [ i , j ] ; ans += to_sum ; q . Push ( new pair ( p_arr [ i , j ] , c ) ) ; i -- ; } } return ans ; } static int sumAndMatrix ( int [ , ] arr ) { int sum = 0 ; int mul = 1 ; for ( int i = 0 ; i < 30 ; i ++ ) { bool [ , ] set_bit = new bool [ n , n ] ; for ( int R = 0 ; R < n ; R ++ ) for ( int C = 0 ; C < n ; C ++ ) set_bit [ R , C ] = ( ( arr [ R , C ] & ( 1 << i ) ) != 0 ) ; sum += ( mul * matrixAllOne ( set_bit ) ) ; mul *= 2 ; } return sum ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 9 , 7 , 4 } , { 8 , 9 , 2 } , { 11 , 11 , 5 } } ; Console . WriteLine ( sumAndMatrix ( arr ) ) ; } }

Accumulator variables: C, R, ans, c, i, j, mul, sum, to_sum
Iterator variables: C, R, i, j
Class/struct names: GFG, pair
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int CountWays ( int n ) { int [ ] noOfWays = new int [ n + 3 ] ; noOfWays [ 0 ] = 1 ; noOfWays [ 1 ] = 1 ; noOfWays [ 2 ] = 1 + 1 ; for ( int i = 3 ; i < n + 1 ; i ++ ) { noOfWays [ i ] = noOfWays [ 3 - 1 ] + noOfWays [ 3 - 3 ] ; noOfWays [ 0 ] = noOfWays [ 1 ] ; noOfWays [ 1 ] = noOfWays [ 2 ] ; noOfWays [ 2 ] = noOfWays [ i ] ; } return noOfWays [ n ] ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( CountWays ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int MAX = 105 ; static void sieve ( int [ ] prime ) { for ( int i = 2 ; i * i < MAX ; i ++ ) { if ( prime [ i ] == 0 ) { for ( int j = i * i ; j < MAX ; j += i ) prime [ j ] = 1 ; } } } class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void dfs ( int i , int j , int k , ref int q , int n , int m , int [ , ] mappedMatrix , int [ , ] mark , pair [ ] ans ) { if ( ( mappedMatrix [ i , j ] == 0 ? true : false ) || ( i > n ? true : false ) || ( j > m ? true : false ) || ( mark [ i , j ] != 0 ? true : false ) || ( q != 0 ? true : false ) ) return ; mark [ i , j ] = 1 ; ans [ k ] = new pair ( i , j ) ; if ( i == n && j == m ) { ( q ) = k ; return ; } dfs ( i + 1 , j + 1 , k + 1 , ref q , n , m , mappedMatrix , mark , ans ) ; dfs ( i + 1 , j , k + 1 , ref q , n , m , mappedMatrix , mark , ans ) ; dfs ( i , j + 1 , k + 1 , ref q , n , m , mappedMatrix , mark , ans ) ; } static void lexicographicalPath ( int n , int m , int [ , ] mappedMatrix ) { int q = 0 ; pair [ ] ans = new pair [ MAX ] ; int [ , ] mark = new int [ MAX , MAX ] ; dfs ( 1 , 1 , 1 , ref q , n , m , mappedMatrix , mark , ans ) ; for ( int i = 1 ; i <= q ; i ++ ) Console . WriteLine ( ans [ i ] . first + " ▁ " + ans [ i ] . second ) ; } static void countPrimePath ( int [ , ] mappedMatrix , int n , int m ) { int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = 0 ; } } dp [ 1 , 1 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { if ( i == 1 && j == 1 ) continue ; dp [ i , j ] = ( dp [ i - 1 , j ] + dp [ i , j - 1 ] + dp [ i - 1 , j - 1 ] ) ; if ( mappedMatrix [ i , j ] == 0 ) dp [ i , j ] = 0 ; } } Console . WriteLine ( dp [ n , m ] ) ; } static void preprocessMatrix ( int [ , ] mappedMatrix , int [ , ] a , int n , int m ) { int [ ] prime = new int [ MAX ] ; sieve ( prime ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( prime [ a [ i , j ] ] == 0 ) mappedMatrix [ i + 1 , j + 1 ] = 1 ; else mappedMatrix [ i + 1 , j + 1 ] = 0 ; } } } public static void Main ( string [ ] args ) { int n = 3 ; int m = 3 ; int [ , ] a = new int [ 3 , 3 ] { { 2 , 3 , 7 } , { 5 , 4 , 2 } , { 3 , 7 , 11 } } ; int [ , ] mappedMatrix = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { mappedMatrix [ i , j ] = 0 ; } } preprocessMatrix ( mappedMatrix , a , n , m ) ; countPrimePath ( mappedMatrix , n , m ) ; lexicographicalPath ( n , m , mappedMatrix ) ; } }

Index/key variables: MAX, i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, pair
C# program:
using System ; class sumofSub { static int isSubsetSum ( int [ ] set , int n , int sum ) { bool [ , ] subset = new bool [ sum + 1 , n + 1 ] ; int [ , ] count = new int [ sum + 1 , n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { subset [ 0 , i ] = true ; count [ 0 , i ] = 0 ; } for ( int i = 1 ; i <= sum ; i ++ ) { subset [ i , 0 ] = false ; count [ i , 0 ] = - 1 ; } for ( int i = 1 ; i <= sum ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { subset [ i , j ] = subset [ i , j - 1 ] ; count [ i , j ] = count [ i , j - 1 ] ; if ( i >= set [ j - 1 ] ) { subset [ i , j ] = subset [ i , j ] || subset [ i - set [ j - 1 ] , j - 1 ] ; if ( subset [ i , j ] ) count [ i , j ] = Math . Max ( count [ i , j - 1 ] , count [ i - set [ j - 1 ] , j - 1 ] + 1 ) ; } } } return count [ sum , n ] ; } public static void Main ( ) { int [ ] set = { 2 , 3 , 5 , 10 } ; int sum = 20 ; int n = set . Length ; Console . WriteLine ( isSubsetSum ( set , n , sum ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: sumofSub
C# program:
using System ; class GFG { static int MAX = 100 ; static int lcslen = 0 ; static int [ , ] dp = new int [ MAX , MAX ] ; static int lcs ( string str1 , string str2 , int len1 , int len2 , int i , int j ) { int ret = dp [ i , j ] ; if ( i == len1 j == len2 ) return ret = 0 ; if ( ret != - 1 ) return ret ; ret = 0 ; if ( str1 [ i ] == str2 [ j ] ) ret = 1 + lcs ( str1 , str2 , len1 , len2 , i + 1 , j + 1 ) ; else ret = Math . Max ( lcs ( str1 , str2 , len1 , len2 , i + 1 , j ) , lcs ( str1 , str2 , len1 , len2 , i , j + 1 ) ) ; return ret ; } static void printAll ( string str1 , string str2 , int len1 , int len2 , char [ ] data , int indx1 , int indx2 , int currlcs ) { if ( currlcs == lcslen ) { data [ currlcs ] = ' \0' ; Console . WriteLine ( new string ( data ) ) ; return ; } if ( indx1 == len1 indx2 == len2 ) return ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { bool done = false ; for ( int i = indx1 ; i < len1 ; i ++ ) { if ( ch == str1 [ i ] ) { for ( int j = indx2 ; j < len2 ; j ++ ) { if ( ch == str2 [ j ] && lcs ( str1 , str2 , len1 , len2 , i , j ) == lcslen - currlcs ) { data [ currlcs ] = ch ; printAll ( str1 , str2 , len1 , len2 , data , i + 1 , j + 1 , currlcs + 1 ) ; done = true ; break ; } } } if ( done ) break ; } } } static void prinlAllLCSSorted ( string str1 , string str2 ) { int len1 = str1 . Length , len2 = str2 . Length ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = - 1 ; } } lcslen = lcs ( str1 , str2 , len1 , len2 , 0 , 0 ) ; char [ ] data = new char [ MAX ] ; printAll ( str1 , str2 , len1 , len2 , data , 0 , 0 , 0 ) ; } static void Main ( ) { string str1 = " abcabcaa " , str2 = " acbacba " ; prinlAllLCSSorted ( str1 , str2 ) ; } }

Index/key variables: MAX, currlcs, i, j
Accumulator variables: ch, i, j
Iterator variables: ch, i, j
Boolean variables: done
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isMajority ( int [ ] arr , int n , int x ) { int i , last_index = 0 ; last_index = ( n % 2 == 0 ) ? n / 2 : n / 2 + 1 ; for ( i = 0 ; i < last_index ; i ++ ) { if ( arr [ i ] == x && arr [ i + n / 2 ] == x ) return true ; } return false ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 4 , 4 , 4 } ; int n = arr . Length ; int x = 4 ; if ( isMajority ( arr , n , x ) == true ) Console . Write ( x + " ▁ appears ▁ more ▁ than ▁ " + n / 2 + " ▁ times ▁ in ▁ arr [ ] " ) ; else Console . Write ( x + " ▁ does ▁ not ▁ appear ▁ more ▁ than ▁ " + n / 2 + " ▁ times ▁ in ▁ arr [ ] " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int _binarySearch ( int [ ] arr , int low , int high , int x ) { if ( high >= low ) { int mid = ( low + high ) / 2 ; if ( ( mid == 0 x > arr [ mid - 1 ] ) && ( arr [ mid ] == x ) ) return mid ; else if ( x > arr [ mid ] ) return _binarySearch ( arr , ( mid + 1 ) , high , x ) ; else return _binarySearch ( arr , low , ( mid - 1 ) , x ) ; } return - 1 ; } static bool isMajority ( int [ ] arr , int n , int x ) { int i = _binarySearch ( arr , 0 , n - 1 , x ) ; if ( i == - 1 ) return false ; if ( ( ( i + n / 2 ) <= ( n - 1 ) ) && arr [ i + n / 2 ] == x ) return true ; else return false ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 3 , 3 , 3 , 10 } ; int n = arr . Length ; int x = 3 ; if ( isMajority ( arr , n , x ) == true ) Console . Write ( x + " ▁ appears ▁ more ▁ than ▁ " + n / 2 + " ▁ times ▁ in ▁ arr [ ] " ) ; else Console . Write ( x + " ▁ does ▁ not ▁ appear ▁ more ▁ than ▁ " + n / 2 + " ▁ times ▁ in ▁ arr [ ] " ) ; } }

Index/key variables: mid
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isMajorityElement ( int [ ] arr , int n , int key ) { if ( arr [ n / 2 ] == key ) return true ; else return false ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 3 , 3 , 3 , 10 } ; int n = arr . Length ; int x = 3 ; if ( isMajorityElement ( arr , n , x ) ) Console . Write ( x + " ▁ appears ▁ more ▁ than ▁ " + n / 2 + " ▁ times ▁ in ▁ [ ] arr " ) ; else Console . Write ( x + " ▁ does ▁ not ▁ appear ▁ more ▁ " + " than ▁ " + n / 2 + " ▁ times ▁ in ▁ arr [ ] " ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int cutRod ( int [ ] price , int n ) { int [ ] val = new int [ n + 1 ] ; val [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int max_val = int . MinValue ; for ( int j = 0 ; j < i ; j ++ ) max_val = Math . Max ( max_val , price [ j ] + val [ i - j - 1 ] ) ; val [ i ] = max_val ; } return val [ n ] ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int size = arr . Length ; Console . WriteLine ( " Maximum ▁ Obtainable ▁ Value ▁ is ▁ " + cutRod ( arr , size ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static bool isPossible ( int [ ] target ) { int max = 0 ; int index = 0 ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( max < target [ i ] ) { max = target [ i ] ; index = i ; } } if ( max == 1 ) return true ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( i != index ) { max -= target [ i ] ; if ( max <= 0 ) return false ; } } target [ index ] = max ; return isPossible ( target ) ; } static public void Main ( ) { int [ ] target = { 9 , 3 , 5 } ; bool res = isPossible ( target ) ; if ( res ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }

Index/key variables: i, index
Accumulator variables: i, max
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int nCr ( int n , int r ) { int res = 1 ; if ( r > n - r ) r = n - r ; for ( int i = 0 ; i < r ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } public static void Main ( ) { int n = 3 , m = 2 , k = 2 ; Console . Write ( nCr ( n + m , k ) ) ; } }

Accumulator variables: res
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void Is_possible ( long N ) { long C = 0 ; long D = 0 ; while ( N % 10 == 0 ) { N = N / 10 ; C += 1 ; } if ( Math . Pow ( 2 , ( long ) ( Math . Log ( N ) / ( Math . Log ( 2 ) ) ) ) == N ) { D = ( long ) ( Math . Log ( N ) / ( Math . Log ( 2 ) ) ) ; if ( C >= D ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } else Console . WriteLine ( " NO " ) ; } public static void Main ( ) { long N = 2000000000000L ; Is_possible ( N ) ; } }

Accumulator variables: C
Class/struct names: GFG
C# program:
using System ; class GFG { static void findNthTerm ( int n ) { Console . Write ( n * n - n + 1 ) ; } public static void Main ( ) { int N = 4 ; findNthTerm ( N ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int rev ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } static int divSum ( int num ) { int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += rev ( i ) ; else result += ( rev ( i ) + rev ( num / i ) ) ; } } return ( result + 1 ) ; } static Boolean isAntiPerfect ( int n ) { return divSum ( n ) == n ; } public static void Main ( String [ ] args ) { int N = 244 ; if ( isAntiPerfect ( N ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }

Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void printSeries ( int n , int a , int b , int c ) { int d ; if ( n == 1 ) { Console . Write ( a + " ▁ " ) ; return ; } if ( n == 2 ) { Console . Write ( a + " ▁ " + b + " ▁ " ) ; return ; } Console . Write ( a + " ▁ " + b + " ▁ " + c + " ▁ " ) ; for ( int i = 4 ; i <= n ; i ++ ) { d = a + b + c ; Console . Write ( d + " ▁ " ) ; a = b ; b = c ; c = d ; } } public static void Main ( ) { int N = 7 , a = 1 , b = 3 ; int c = 4 ; printSeries ( N , a , b , c ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int diameter ( int n ) { int L , H ; L = 1 ; H = 0 ; if ( n == 1 ) { return 1 ; } if ( n == 2 ) { return 2 ; } if ( n == 3 ) { return 3 ; } while ( L * 2 <= n ) { L *= 2 ; H ++ ; } if ( n >= L * 2 - 1 ) return 2 * H + 1 ; else if ( n >= L + ( L / 2 ) - 1 ) return 2 * H ; return 2 * H - 1 ; } public static void Main ( String [ ] args ) { int n = 15 ; Console . WriteLine ( diameter ( n ) ) ; } }

Accumulator variables: H, L
Class/struct names: GFG