dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int cntIndexesToMakeBalance ( int [ ] arr , int n ) { if ( n == 1 ) { return 1 ; } if ( n == 2 ) return 0 ; int sumEven = 0 ; int sumOdd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { sumEven += arr [ i ] ; } else { sumOdd += arr [ i ] ; } } int currOdd = 0 ; int currEven = arr [ 0 ] ; int res = 0 ; int newEvenSum = 0 ; int newOddSum = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( i % 2 != 0 ) { currOdd += arr [ i ] ; newEvenSum = currEven + sumOdd - currOdd ; newOddSum = currOdd + sumEven - currEven - arr [ i ] ; } else { currEven += arr [ i ] ; newOddSum = currOdd + sumEven - currEven ; newEvenSum = currEven + sumOdd - currOdd - arr [ i ] ; } if ( newEvenSum == newOddSum ) { res ++ ; } } if ( sumOdd == sumEven - arr [ 0 ] ) { res ++ ; } if ( n % 2 == 1 ) { if ( sumOdd == sumEven - arr [ n - 1 ] ) { res ++ ; } } else { if ( sumEven == sumOdd - arr [ n - 1 ] ) { res ++ ; } } return res ; } public static void Main ( ) { int [ ] arr = { 1 , 1 , 1 } ; int n = arr . Length ; Console . WriteLine ( cntIndexesToMakeBalance ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: currEven, currOdd, i, res, sumEven, sumOdd
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void findNums ( int X , int Y ) { int A , B ; if ( X < Y ) { A = - 1 ; B = - 1 ; } else if ( ( ( Math . Abs ( X - Y ) ) & 1 ) != 0 ) { A = - 1 ; B = - 1 ; } else if ( X == Y ) { A = 0 ; B = Y ; } else { A = ( X - Y ) / 2 ; if ( ( A & Y ) == 0 ) { B = ( A + Y ) ; } else { A = - 1 ; B = - 1 ; } } Console . Write ( A + " ▁ " + B ) ; } public static void Main ( String [ ] args ) { int X = 17 , Y = 13 ; findNums ( X , Y ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static void checkCount ( int [ ] A , int [ , ] Q , int q ) { for ( int i = 0 ; i < q ; i ++ ) { int L = Q [ i , 0 ] ; int R = Q [ i , 1 ] ; L -- ; R -- ; if ( ( A [ L ] < A [ L + 1 ] ) != ( A [ R - 1 ] < A [ R ] ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } } public static void Main ( ) { int [ ] arr = { 11 , 13 , 12 , 14 } ; int [ , ] Q = { { 1 , 4 } , { 2 , 4 } } ; int q = Q . GetLength ( 0 ) ; checkCount ( arr , Q , q ) ; } }

Index/key variables: L, R
Accumulator variables: L, R, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static double pairProductMean ( int [ ] arr , int N ) { List < int > pairArray = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int pairProduct = arr [ i ] * arr [ j ] ; pairArray . Add ( pairProduct ) ; } } int length = pairArray . Count ; float sum = 0 ; for ( int i = 0 ; i < length ; i ++ ) sum += pairArray [ i ] ; float mean ; if ( length != 0 ) mean = sum / length ; else mean = 0 ; return mean ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 8 } ; int N = arr . Length ; Console . WriteLine ( " { 0 : F2 } " , pairProductMean ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void findPlayer ( string [ ] str , int n ) { int move_first = 0 ; int move_sec = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] [ 0 ] == str [ i ] [ str [ i ] . Length - 1 ] ) { if ( ( str [ i ] [ 0 ] ) == 48 ) move_first ++ ; else move_sec ++ ; } } if ( move_first <= move_sec ) { Console . Write ( " Player ▁ 2 ▁ wins " ) ; } else { Console . Write ( " Player ▁ 1 ▁ wins " ) ; } } public static void Main ( ) { string [ ] str = { "010" , "101" } ; int N = str . Length ; findPlayer ( str , N ) ; } }

Index/key variables: i
Accumulator variables: i, move_first, move_sec
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int find_next ( int n , int k ) { int M = n + 1 ; while ( true ) { if ( ( M & ( 1L << k ) ) > 0 ) break ; M ++ ; } return M ; } public static void Main ( String [ ] args ) { int N = 15 , K = 2 ; Console . Write ( find_next ( N , K ) ) ; } }

Accumulator variables: M
Class/struct names: GFG
C# program:
using System ; class GFG { static int find_next ( int n , int k ) { int ans = 0 ; if ( ( n & ( 1L << k ) ) == 0 ) { int cur = 0 ; for ( int i = 0 ; i < k ; i ++ ) { if ( ( n & ( 1L << i ) ) > 0 ) cur += ( int ) 1L << i ; } ans = ( int ) ( n - cur + ( 1L << k ) ) ; } else { int first_unset_bit = - 1 , cur = 0 ; for ( int i = 0 ; i < 64 ; i ++ ) { if ( ( n & ( 1L << i ) ) == 0 ) { first_unset_bit = i ; break ; } else cur += ( int ) ( 1L << i ) ; } ans = ( int ) ( n - cur + ( 1L << first_unset_bit ) ) ; if ( ( ans & ( 1L << k ) ) == 0 ) ans += ( int ) ( 1L << k ) ; } return ans ; } public static void Main ( String [ ] args ) { int N = 15 , K = 2 ; Console . Write ( find_next ( N , K ) ) ; } }

Accumulator variables: ans, cur, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static String largestString ( String num , int k ) { String ans = " " ; foreach ( char i in num . ToCharArray ( ) ) { while ( ans . Length > 0 && ans [ ans . Length - 1 ] < i && k > 0 ) { ans = ans . Substring ( 0 , ans . Length - 1 ) ; k -- ; } ans += i ; } while ( ans . Length > 0 && k -- > 0 ) { ans = ans . Substring ( 0 , ans . Length - 1 ) ; } return ans ; } public static void Main ( String [ ] args ) { String str = " zyxedcba " ; int k = 1 ; Console . Write ( largestString ( str , k ) + " STRNEWLINE " ) ; } }

Accumulator variables: ans, k
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void maxLengthSubArray ( int [ ] A , int N ) { int [ ] forward = new int [ N ] ; int [ ] backward = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 A [ i ] != A [ i - 1 ] ) { forward [ i ] = 1 ; } else forward [ i ] = forward [ i - 1 ] + 1 ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( i == N - 1 A [ i ] != A [ i + 1 ] ) { backward [ i ] = 1 ; } else backward [ i ] = backward [ i + 1 ] + 1 ; } int ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] != A [ i + 1 ] ) ans = Math . Max ( ans , Math . Min ( forward [ i ] , backward [ i + 1 ] ) * 2 ) ; } Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 4 , 4 , 6 , 6 , 6 , 9 } ; int N = arr . Length ; maxLengthSubArray ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void minNum ( int n ) { if ( n < 3 ) Console . WriteLine ( - 1 ) ; else Console . WriteLine ( 210 * ( ( int ) ( Math . Pow ( 10 , n - 1 ) / 210 ) + 1 ) ) ; } public static void Main ( String [ ] args ) { int n = 5 ; minNum ( n ) ; } }

Class/struct names: GFG
C# program:
using System ; using System . Text ; using System . Collections ; class GFG { static string helper ( int d , int s ) { StringBuilder ans = new StringBuilder ( ) ; for ( int i = 0 ; i < d ; i ++ ) { ans . Append ( "0" ) ; } for ( int i = d - 1 ; i >= 0 ; i -- ) { if ( s >= 9 ) { ans [ i ] = '9' ; s -= 9 ; } else { char c = ( char ) ( s + ( int ) '0' ) ; ans [ i ] = c ; s = 0 ; } } return ans . ToString ( ) ; } static string findMin ( int x , int Y ) { string y = Y . ToString ( ) ; int n = y . Length ; ArrayList p = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) { p . Add ( 0 ) ; } for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = ( int ) ( ( int ) y [ i ] - ( int ) '0' ) ; if ( i > 0 ) { p [ i ] = ( int ) p [ i ] + ( int ) p [ i - 1 ] ; } } for ( int i = n - 1 , k = 0 ; ; i -- , k ++ ) { int d = 0 ; if ( i >= 0 ) { d = ( int ) y [ i ] - ( int ) '0' ; } for ( int j = d + 1 ; j <= 9 ; j ++ ) { int r = j ; if ( i > 0 ) { r += ( int ) p [ i - 1 ] ; } if ( x - r >= 0 && x - r <= 9 * k ) { string suf = helper ( k , x - r ) ; string pre = " " ; if ( i > 0 ) pre = y . Substring ( 0 , i ) ; char cur = ( char ) ( j + ( int ) '0' ) ; pre += cur ; return pre + suf ; } } } } public static void Main ( string [ ] arg ) { int x = 18 ; int y = 99 ; Console . Write ( findMin ( x , y ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, k, pre, r, s
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static void largestNumber ( int n , int X , int Y ) { int maxm = Math . Max ( X , Y ) ; Y = X + Y - maxm ; X = maxm ; int Xs = 0 ; int Ys = 0 ; while ( n > 0 ) { if ( n % Y == 0 ) { Xs += n ; n = 0 ; } else { n -= X ; Ys += X ; } } if ( n == 0 ) { while ( Xs -- > 0 ) Console . Write ( X ) ; while ( Ys -- > 0 ) Console . Write ( Y ) ; } else Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { int n = 19 , X = 7 , Y = 5 ; largestNumber ( n , X , Y ) ; } }

Accumulator variables: Xs, Ys, n
Class/struct names: GFG
C# program:
using System ; class GFG { static int minChanges ( String str , int N ) { int res ; int count0 = 0 , count1 = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == '0' ) count0 ++ ; } res = count0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == '0' ) count0 -- ; if ( str [ i ] == '1' ) count1 ++ ; res = Math . Min ( res , count1 + count0 ) ; } return res ; } public static void Main ( ) { int N = 9 ; String str = "000101001" ; Console . Write ( minChanges ( str , N ) ) ; } }

Index/key variables: i
Accumulator variables: count0, count1, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int missingnumber ( int n , int [ ] arr ) { int mn = Int32 . MaxValue , mx = Int32 . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( i > 0 && arr [ i ] == - 1 && arr [ i - 1 ] != - 1 ) { mn = Math . Min ( mn , arr [ i - 1 ] ) ; mx = Math . Max ( mx , arr [ i - 1 ] ) ; } if ( i < ( n - 1 ) && arr [ i ] == - 1 && arr [ i + 1 ] != - 1 ) { mn = Math . Min ( mn , arr [ i + 1 ] ) ; mx = Math . Max ( mx , arr [ i + 1 ] ) ; } } int res = ( mx + mn ) / 2 ; return res ; } public static void Main ( ) { int n = 5 ; int [ ] arr = new int [ ] { - 1 , 10 , - 1 , 12 , - 1 } ; int res = missingnumber ( n , arr ) ; Console . WriteLine ( res ) ; } }

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 int lcsubtr ( char [ ] a , char [ ] b , int length1 , int length2 ) { int [ , ] dp = new int [ length1 + 1 , length2 + 1 ] ; int max = 0 ; for ( int i = 0 ; i <= length1 ; ++ i ) { for ( int j = 0 ; j <= length2 ; ++ j ) { if ( i == 0 j == 0 ) { dp [ i , j ] = 0 ; } else if ( a [ i - 1 ] == b [ j - 1 ] ) { dp [ i , j ] = dp [ i - 1 , j - 1 ] + 1 ; max = Math . Max ( dp [ i , j ] , max ) ; } else { dp [ i , j ] = 0 ; } } } return max ; } public static void Main ( ) { string m = "0110" ; string n = "1101" ; char [ ] m1 = m . ToCharArray ( ) ; char [ ] m2 = n . ToCharArray ( ) ; Console . Write ( lcsubtr ( m1 , m2 , m1 . Length , m2 . Length ) ) ; } }

Iterator variables: i, j
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 bool [ , ] v = new bool [ 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 ] ; } static void countSubsets ( int [ ] arr , int K , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } int S1 = ( sum + K ) / 2 ; Console . Write ( findCnt ( arr , 0 , S1 , n ) ) ; } static void Main ( ) { int [ ] arr = { 1 , 1 , 2 , 3 } ; int N = arr . Length ; int K = 1 ; countSubsets ( arr , K , N ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static float [ , ] dp = new float [ 105 , 605 ] ; static float find ( int N , int sum ) { if ( N < 0 sum < 0 ) return 0 ; if ( dp [ N , sum ] > 0 ) return dp [ N , sum ] ; if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return ( float ) ( 1.0 / 6 ) ; else return 0 ; } for ( int i = 1 ; i <= 6 ; i ++ ) dp [ N , sum ] = dp [ N , sum ] + find ( N - 1 , sum - i ) / 6 ; return dp [ N , sum ] ; } public static void Main ( String [ ] args ) { int N = 4 , a = 13 , b = 17 ; float probability = 0.0f ; for ( int sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; Console . Write ( " { 0 : F6 } " , probability ) ; } }

Accumulator variables: i, sum
Iterator variables: i, sum
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int count ( int n ) { Dictionary < int , int > dp = new Dictionary < int , int > ( ) ; dp . Add ( 0 , 0 ) ; dp . Add ( 1 , 1 ) ; if ( ! dp . ContainsKey ( n ) ) dp . Add ( n , 1 + Math . Min ( n % 2 + count ( n / 2 ) , n % 3 + count ( n / 3 ) ) ) ; return dp [ n ] ; } public static void Main ( String [ ] args ) { int N = 6 ; Console . WriteLine ( String . Join ( " " , ( count ( N ) ) ) ) ; } }

Index/key variables: n
Class/struct names: GFG
C# program:
using System ; class GFG { static void find_minimum_operations ( int n , int [ ] b , int k ) { int [ ] d = new int [ n + 1 ] ; int i , operations = 0 , need ; for ( i = 0 ; i < n ; i ++ ) { if ( i > 0 ) { d [ i ] += d [ i - 1 ] ; } if ( b [ i ] > d [ i ] ) { operations += b [ i ] - d [ i ] ; need = b [ i ] - d [ i ] ; d [ i ] += need ; if ( i + k <= n ) { d [ i + k ] -= need ; } } } Console . Write ( operations ) ; } public static void Main ( string [ ] args ) { int n = 5 ; int [ ] b = { 1 , 2 , 3 , 4 , 5 } ; int k = 2 ; find_minimum_operations ( n , b , k ) ; } }

Index/key variables: i
Accumulator variables: i, operations
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int ways ( int [ , ] arr , int K ) { int R = arr . GetLength ( 0 ) ; int C = arr . GetLength ( 1 ) ; int [ , ] preSum = new int [ R , C ] ; for ( int r = R - 1 ; r >= 0 ; r -- ) { for ( int c = C - 1 ; c >= 0 ; c -- ) { preSum [ r , c ] = arr [ r , c ] ; if ( r + 1 < R ) preSum [ r , c ] += preSum [ r + 1 , c ] ; if ( c + 1 < C ) preSum [ r , c ] += preSum [ r , c + 1 ] ; if ( r + 1 < R && c + 1 < C ) preSum [ r , c ] -= preSum [ r + 1 , c + 1 ] ; } } int [ , , ] dp = new int [ K + 1 , R , C ] ; for ( int k = 1 ; k <= K ; k ++ ) { for ( int r = R - 1 ; r >= 0 ; r -- ) { for ( int c = C - 1 ; c >= 0 ; c -- ) { if ( k == 1 ) { dp [ k , r , c ] = ( preSum [ r , c ] > 0 ) ? 1 : 0 ; } else { dp [ k , r , c ] = 0 ; for ( int r1 = r + 1 ; r1 < R ; r1 ++ ) { if ( preSum [ r , c ] - preSum [ r1 , c ] > 0 ) dp [ k , r , c ] += dp [ k - 1 , r1 , c ] ; } for ( int c1 = c + 1 ; c1 < C ; c1 ++ ) { if ( preSum [ r , c ] - preSum [ r , c1 ] > 0 ) dp [ k , r , c ] += dp [ k - 1 , r , c1 ] ; } } } } } return dp [ K , 0 , 0 ] ; } public static void Main ( string [ ] args ) { int [ , ] arr = { { 1 , 0 , 0 } , { 1 , 1 , 1 } , { 0 , 0 , 0 } } ; int k = 3 ; Console . WriteLine ( ways ( arr , k ) ) ; } }

Accumulator variables: c, c1, k, r, r1
Iterator variables: c, c1, k, r, r1
Class/struct names: GFG
C# program:
using System ; class GFG { static int p = 1000000007 ; static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static void nCr ( int n , int p , int [ , ] f , int m ) { for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { if ( j > i ) { f [ i , j ] = 0 ; } else if ( j == 0 j == i ) { f [ i , j ] = 1 ; } else { f [ i , j ] = ( f [ i - 1 , j ] + f [ i - 1 , j - 1 ] ) % p ; } } } } static void ProductOfSubsets ( int [ ] arr , int n , int m ) { int [ , ] f = new int [ n + 1 , 100 ] ; nCr ( n , p - 1 , f , m ) ; Array . Sort ( arr ) ; long ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int x = 0 ; for ( int j = 1 ; j <= m ; j ++ ) { if ( m % j == 0 ) { x = ( x + ( f [ n - i - 1 , m - j ] * f [ i , j - 1 ] ) % ( p - 1 ) ) % ( p - 1 ) ; } } ans = ( ( ans * power ( arr [ i ] , x , p ) ) % p ) ; } Console . Write ( ans + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 5 , 7 , 9 , 3 } ; int K = 4 ; int N = arr . Length ; ProductOfSubsets ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countWays ( int n , int m ) { int [ , ] dp = new int [ m + 1 , n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { dp [ 1 , i ] = 1 ; } int sum ; for ( int i = 2 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { sum = 0 ; for ( int k = 0 ; k <= j ; k ++ ) { sum += dp [ i - 1 , k ] ; } dp [ i , j ] = sum ; } } return dp [ m , n ] ; } public static void Main ( String [ ] args ) { int N = 2 , K = 3 ; Console . Write ( countWays ( N , K ) ) ; } }

Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int countWays ( int n , int m ) { int [ , ] dp = new int [ m + 1 , n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { dp [ 1 , i ] = 1 ; if ( i != 0 ) { dp [ 1 , i ] += dp [ 1 , i - 1 ] ; } } for ( int i = 2 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( j == 0 ) { dp [ i , j ] = dp [ i - 1 , j ] ; } else { dp [ i , j ] = dp [ i - 1 , j ] ; if ( i == m && j == n ) { return dp [ i , j ] ; } dp [ i , j ] += dp [ i , j - 1 ] ; } } } return Int32 . MinValue ; } public static void Main ( ) { int N = 2 , K = 3 ; Console . Write ( countWays ( N , K ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public static void SieveOfEratosthenes ( int MAX , List < int > primes ) { Boolean [ ] prime = new Boolean [ MAX + 1 ] ; for ( int i = 0 ; i < MAX + 1 ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } for ( int i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] ) primes . Add ( i ) ; } } public static int findLongest ( int [ ] A , int n ) { Dictionary < int , int > mpp = new Dictionary < int , int > ( ) ; List < int > primes = new List < int > ( ) ; SieveOfEratosthenes ( A [ n - 1 ] , primes ) ; int [ ] dp = new int [ n ] ; dp [ n - 1 ] = 1 ; mpp . Add ( A [ n - 1 ] , n - 1 ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int num = A [ i ] ; dp [ i ] = 1 ; foreach ( int it in primes ) { int xx = num * it ; if ( xx > A [ n - 1 ] ) break ; else if ( mpp . ContainsKey ( xx ) && mpp [ xx ] != 0 ) { dp [ i ] = Math . Max ( dp [ i ] , 1 + dp [ mpp [ xx ] ] ) ; } } if ( mpp . ContainsKey ( A [ i ] ) ) mpp [ A [ i ] ] = i ; else mpp . Add ( A [ i ] , i ) ; } int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) ans = Math . Max ( ans , dp [ i ] ) ; return ans ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 5 , 6 , 12 , 35 , 60 , 385 } ; int n = a . Length ; Console . WriteLine ( findLongest ( a , n ) ) ; } }

Index/key variables: i, n, p, xx
Accumulator variables: i, p
Iterator variables: i, it, p
Class/struct names: GFG
C# program:
using System ; class GFG { static int waysToKAdjacentSetBits ( int n , int k , int currentIndex , int adjacentSetBits , int lastBit ) { if ( currentIndex == n ) { if ( adjacentSetBits == k ) return 1 ; return 0 ; } int noOfWays = 0 ; if ( lastBit == 1 ) { noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits + 1 , 1 ) ; noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } else if ( lastBit != 1 ) { noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits , 1 ) ; noOfWays += waysToKAdjacentSetBits ( n , k , currentIndex + 1 , adjacentSetBits , 0 ) ; } return noOfWays ; } public static void Main ( ) { int n = 5 , k = 2 ; int totalWays = waysToKAdjacentSetBits ( n , k , 1 , 0 , 1 ) + waysToKAdjacentSetBits ( n , k , 1 , 0 , 0 ) ; Console . WriteLine ( " Number ▁ of ▁ ways ▁ = ▁ " + totalWays ) ; } }

Accumulator variables: noOfWays
Class/struct names: GFG
C# program:
using System ; class GFG { static void postfix ( int [ ] a , int n ) { for ( int i = n - 1 ; i > 0 ; i -- ) { a [ i - 1 ] = a [ i - 1 ] + a [ i ] ; } } static void modify ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i - 1 ] = i * a [ i ] ; } } static void allCombination ( int [ ] a , int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sum += i ; } Console . WriteLine ( " f ( 1 ) ▁ - - > ▁ " + sum ) ; for ( int i = 1 ; i < n ; i ++ ) { postfix ( a , n - i + 1 ) ; sum = 0 ; for ( int j = 1 ; j <= n - i ; j ++ ) { sum += ( j * a [ j ] ) ; } Console . WriteLine ( " f ( " + ( i + 1 ) + " ) ▁ - - > ▁ " + sum ) ; modify ( a , n ) ; } } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = i + 1 ; } allCombination ( a , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GfG { public static int findStep ( int n ) { if ( n == 1 n == 0 ) return 1 ; else if ( n == 2 ) return 2 ; else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( findStep ( n ) ) ; } }

Class/struct names: GfG
C# program:
using System ; class GFG { static bool isSubsetSum ( int [ ] arr , int n , int sum ) { if ( sum == 0 ) return true ; if ( n == 0 && sum != 0 ) return false ; if ( arr [ n - 1 ] > sum ) return isSubsetSum ( arr , n - 1 , sum ) ; return isSubsetSum ( arr , n - 1 , sum ) || isSubsetSum ( arr , n - 1 , sum - arr [ n - 1 ] ) ; } static bool findPartition ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; return isSubsetSum ( arr , n , sum / 2 ) ; } public static void Main ( ) { int [ ] arr = { 3 , 1 , 5 , 9 , 12 } ; int n = arr . Length ; if ( findPartition ( arr , n ) == true ) Console . Write ( " Can ▁ be ▁ divided ▁ into ▁ two ▁ " + " subsets ▁ of ▁ equal ▁ sum " ) ; else Console . Write ( " Can ▁ not ▁ be ▁ divided ▁ into ▁ " + " two ▁ subsets ▁ of ▁ equal ▁ sum " ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int gcd ( int a , int b ) { if ( a < b ) { int t = a ; a = b ; b = t ; } if ( a % b == 0 ) return b ; return gcd ( b , a % b ) ; } static void printAnswer ( int x , int y ) { int val = gcd ( x , y ) ; if ( ( val & ( val - 1 ) ) == 0 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int x = 4 ; int y = 7 ; printAnswer ( x , y ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int getElement ( int N , int r , int c ) { if ( r > c ) return 0 ; if ( r == 1 ) { return c ; } int a = ( r + 1 ) * ( int ) ( Math . Pow ( 2 , ( r - 2 ) ) ) ; int d = ( int ) ( Math . Pow ( 2 , ( r - 1 ) ) ) ; c = c - r ; int element = a + d * c ; return element ; } public static void Main ( String [ ] args ) { int N = 4 , R = 3 , C = 4 ; Console . WriteLine ( getElement ( N , R , C ) ) ; } }

Class/struct names: GFG