dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MOD = 1000000007 ; static List < int > MEM = new List < int > ( new int [ ] { 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 , 2048 , 4096 } ) ; static int mod_pow2 ( int n ) { while ( n >= MEM . Count ) MEM . Add ( ( MEM [ MEM . Count - 1 ] * 2 ) % MOD ) ; return MEM [ n ] ; } static int inversions ( char [ ] bstr ) { int total = 0 , zeros = 0 , questions = 0 ; Array . Reverse ( bstr ) ; foreach ( char x in bstr ) { int q ; if ( x == '1' ) { int z = zeros * mod_pow2 ( questions ) ; if ( questions == 0 ) q = 0 ; else q = questions * mod_pow2 ( questions - 1 ) ; total = ( total + z + q ) % MOD ; } else if ( x == '0' ) { zeros += 1 ; } else { total *= 2 ; int z = zeros * mod_pow2 ( questions ) ; if ( questions == 0 ) q = 0 ; else q = questions * mod_pow2 ( questions - 1 ) ; total = ( total + z + q ) % MOD ; questions += 1 ; } } return total ; } static void Main ( ) { char [ ] S = " ? 0 ? " . ToCharArray ( ) ; Console . WriteLine ( inversions ( S ) ) ; } }

Index/key variables: n
Accumulator variables: questions, total, zeros
Iterator variables: x
Class/struct names: GFG
C# program:
using System ; class GFG { public static int minRemovalsUtil ( int [ ] arr ) { int result = 0 ; if ( arr . Length < 3 ) { return - 1 ; } int [ ] leftIncreasing = new int [ arr . Length ] ; int [ ] rightIncreasing = new int [ arr . Length ] ; for ( int i = 1 ; i < arr . Length ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { leftIncreasing [ i ] = Math . Max ( leftIncreasing [ i ] , leftIncreasing [ j ] + 1 ) ; } } } for ( int i = arr . Length - 2 ; i >= 0 ; i -- ) { for ( int j = arr . Length - 1 ; j > i ; j -- ) { if ( arr [ j ] < arr [ i ] ) { rightIncreasing [ i ] = Math . Max ( rightIncreasing [ i ] , rightIncreasing [ j ] + 1 ) ; } } } for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( leftIncreasing [ i ] != 0 && rightIncreasing [ i ] != 0 ) { result = Math . Max ( result , leftIncreasing [ i ] + rightIncreasing [ i ] ) ; } } return arr . Length - ( result + 1 ) ; } public static void minRemovals ( int [ ] arr ) { int ans = minRemovalsUtil ( arr ) ; Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 1 , 5 , 6 , 2 , 3 , 1 } ; minRemovals ( arr ) ; } }

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 cntNum ( string X , int i , int sum , int tight ) { if ( i >= X . Length sum < 0 ) { if ( sum == 0 ) { return 1 ; } return 0 ; } int res = 0 ; int end = tight != 0 ? X [ i ] - '0' : 9 ; for ( int j = 0 ; j <= end ; j ++ ) { res += cntNum ( X , i + 1 , sum - j , ( tight > 0 & ( j == end ) ) == true ? 1 : 0 ) ; } return res ; } static int UtilCntNumRange ( int L , int R , int Y ) { if ( R == 0 && Y == 0 ) { return 1 ; } string str = R . ToString ( ) ; int cntR = cntNum ( str , 0 , Y , 1 ) ; str = ( L - 1 ) . ToString ( ) ; int cntL = cntNum ( str , 0 , Y , 1 ) ; return ( cntR - cntL ) ; } public static void Main ( string [ ] args ) { int L = 20 , R = 10000 , Y = 14 ; Console . WriteLine ( UtilCntNumRange ( L , R , Y ) ) ; } }

Index/key variables: i
Accumulator variables: j, res
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static int findMaxGCD ( int [ ] arr , int N ) { int high = 0 ; for ( int i = 0 ; i < N ; i ++ ) { high = Math . Max ( high , arr [ i ] ) ; } int [ ] count = new int [ high + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { count [ arr [ i ] ] += 1 ; } int counter = 0 ; for ( int i = high ; i > 0 ; i -- ) { int j = i ; while ( j <= high ) { if ( count [ j ] > 0 ) counter += count [ j ] ; j += i ; if ( counter == 2 ) return i ; } counter = 0 ; } return 0 ; } static int maxlen ( int i , int j , int [ ] arr , int [ ] arr1 , int N , int maxgcd ) { int a = 1 ; if ( i >= N j >= N ) return 0 ; if ( __gcd ( arr [ i ] , arr1 [ j ] ) == maxgcd && arr [ i ] != arr1 [ j ] ) { a = Math . Max ( a , 1 + maxlen ( i , j + 1 , arr , arr1 , N , maxgcd ) ) ; return a ; } return Math . Max ( maxlen ( i + 1 , j , arr , arr1 , N , maxgcd ) , maxlen ( i , j + 1 , arr , arr1 , N , maxgcd ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 8 , 5 , 6 } ; int [ ] arr1 = { 1 , 2 , 8 , 5 , 6 } ; int n = arr . Length ; Array . Sort ( arr ) ; int maxgcd = findMaxGCD ( arr , n ) ; Console . Write ( maxlen ( 0 , 0 , arr , arr1 , n , maxgcd ) ) ; } }

Index/key variables: i, j
Accumulator variables: counter, i, j
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 100000 ; static int [ ] dp = new int [ MAX + 1 ] ; static List < int > denomination = new List < int > ( ) ; static int countMinCoins ( int n , int [ ] C , int m ) { if ( n == 0 ) { dp [ 0 ] = 0 ; return 0 ; } if ( dp [ n ] != - 1 ) return dp [ n ] ; int ret = int . MaxValue ; for ( int i = 0 ; i < m ; i ++ ) { if ( C [ i ] <= n ) { int x = countMinCoins ( n - C [ i ] , C , m ) ; if ( x != int . MaxValue ) ret = Math . Min ( ret , 1 + x ) ; } } dp [ n ] = ret ; return ret ; } static void findSolution ( int n , int [ ] C , int m ) { if ( n == 0 ) { foreach ( int it in denomination ) { Console . Write ( it + " ▁ " ) ; } return ; } for ( int i = 0 ; i < m ; i ++ ) { if ( n - C [ i ] >= 0 && dp [ n - C [ i ] ] + 1 == dp [ n ] ) { denomination . Add ( C [ i ] ) ; findSolution ( n - C [ i ] , C , m ) ; break ; } } } static void countMinCoinsUtil ( int X , int [ ] C , int N ) { for ( int i = 0 ; i < dp . Length ; i ++ ) dp [ i ] = - 1 ; int isPossible = countMinCoins ( X , C , N ) ; if ( isPossible == int . MaxValue ) { Console . Write ( " - 1" ) ; } else { findSolution ( X , C , N ) ; } } public static void Main ( String [ ] args ) { int X = 21 ; int [ ] arr = { 2 , 3 , 4 , 5 } ; int N = arr . Length ; countMinCoinsUtil ( X , arr , N ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i, it
Class/struct names: GFG
C# program:
using System ; class GFG { static int binCoff ( int n , int r ) { int val = 1 ; int i ; if ( r > ( n - r ) ) { r = ( n - r ) ; } for ( i = 0 ; i < r ; i ++ ) { val *= ( n - i ) ; val /= ( i + 1 ) ; } return val ; } static int findWays ( int n ) { n -- ; int a , b , ans ; a = binCoff ( 2 * n , n ) ; b = a / ( n + 1 ) ; ans = 2 * b ; return ans ; } public static void Main ( String [ ] args ) { int n = 4 ; Console . Write ( findWays ( n ) ) ; } }

Accumulator variables: i, n, val
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp = new int [ 1010 , 1010 ] ; static int solve ( String s , String t ) { int n = s . Length ; int r = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i , j ] = 0 ; if ( i > 0 ) { dp [ i , j ] = Math . Max ( dp [ i - 1 , j ] , dp [ i , j ] ) ; } if ( s [ i ] == t [ j ] ) { int ans = 1 ; if ( i > 0 && j > 0 ) { ans = 1 + dp [ i - 1 , j - 1 ] ; } dp [ i , j ] = Math . Max ( dp [ i , j ] , ans ) ; r = Math . Max ( r , dp [ i , j ] ) ; } } } return ( n - r ) ; } public static void Main ( String [ ] args ) { String s = " abcde " ; String t = " edacb " ; Console . Write ( solve ( s , t ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System . Collections . Generic ; using System ; class GFG { static int longestSubstring ( string s , int n ) { Dictionary < int , int > index = new Dictionary < int , int > ( ) ; int answer = 0 ; int mask = 0 ; index [ mask ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int temp = ( int ) s [ i ] - 97 ; mask ^= ( 1 << temp ) ; if ( index . ContainsKey ( mask ) == true ) { answer = Math . Max ( answer , i - index [ mask ] ) ; } else index [ mask ] = i ; for ( int j = 0 ; j < 26 ; j ++ ) { int mask2 = mask ^ ( 1 << j ) ; if ( index . ContainsKey ( mask2 ) == true ) { answer = Math . Max ( answer , i - index [ mask2 ] ) ; } } } return answer ; } public static void Main ( ) { string s = " adbabd " ; int n = s . Length ; Console . WriteLine ( longestSubstring ( s , n ) ) ; } }

Index/key variables: i, mask, mask2
Accumulator variables: i, j, mask
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static void countNums ( int N ) { int [ , ] dp = new int [ N , 16 ] ; for ( int i = 1 ; i <= 9 ; i ++ ) dp [ 0 , i ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { for ( int k = 0 ; k < 16 ; k ++ ) { int xor = j ^ k ; dp [ i , xor ] += dp [ i - 1 , k ] ; } } } int count = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) count += dp [ N - 1 , i ] ; Console . Write ( count ) ; } public static void Main ( string [ ] args ) { int N = 1 ; countNums ( N ) ; } }

Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static void SubarrayWithMaxSum ( List < int > nums ) { int currMax = nums [ 0 ] , globalMax = nums [ 0 ] ; int endIndex = 0 ; int startIndex = 0 , globalMaxStartIndex = 0 ; for ( int i = 1 ; i < nums . Count ; ++ i ) { if ( nums [ i ] > nums [ i ] + currMax ) { currMax = nums [ i ] ; } else if ( nums [ i ] < nums [ i ] + currMax ) { currMax = nums [ i ] + currMax ; } if ( currMax > globalMax ) { globalMax = currMax ; endIndex = i ; globalMaxStartIndex = startIndex ; } } for ( int i = globalMaxStartIndex ; i <= endIndex ; ++ i ) { Console . Write ( nums [ i ] + " ▁ " ) ; } } static public void Main ( ) { List < int > arr = new List < int > ( ) ; arr . Add ( - 2 ) ; arr . Add ( - 5 ) ; arr . Add ( 6 ) ; arr . Add ( - 2 ) ; arr . Add ( - 3 ) ; arr . Add ( 1 ) ; arr . Add ( 5 ) ; arr . Add ( - 6 ) ; SubarrayWithMaxSum ( arr ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int count ( int [ ] a , int M , int N ) { int cnt = 0 ; for ( int i = 1 ; i <= M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i % a [ j ] == 0 ) { cnt ++ ; break ; } } } return cnt ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 5 , 7 } ; int m = 100 ; int n = arr . Length ; Console . Write ( count ( arr , m , n ) ) ; } }

Index/key variables: j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static int [ , ] dp = new int [ 15 , 10 ] ; public static int solve ( int n , int last , int k ) { if ( n == 1 ) { if ( last == k ) { return ( k - 1 ) ; } else { return 1 ; } } if ( dp [ n , last ] == 1 ) return dp [ n , last ] ; if ( last == k ) { return dp [ n , last ] = ( k - 1 ) * solve ( n - 1 , k , k ) + ( k - 1 ) * solve ( n - 1 , 1 , k ) ; } else { return dp [ n , last ] = solve ( n - 1 , k , k ) ; } } public static void Main ( string [ ] args ) { int n = 2 , k = 3 ; int x = solve ( n , k , k ) + solve ( n , 1 , k ) ; Console . WriteLine ( x ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static void print ( int [ ] occ , String s ) { for ( int i = 1 ; i <= s . Length - 1 ; i ++ ) { Console . Write ( s . Substring ( 0 , i ) + " ▁ occurs ▁ " + occ [ i ] + " ▁ times . " + " STRNEWLINE " ) ; } } static int [ ] prefix_function ( String s ) { int [ ] LPS = new int [ s . Length ] ; LPS [ 0 ] = 0 ; for ( int i = 1 ; i < s . Length ; i ++ ) { int j = LPS [ i - 1 ] ; while ( j > 0 && s [ i ] != s [ j ] ) { j = LPS [ j - 1 ] ; } if ( s [ i ] == s [ j ] ) { LPS [ i ] = j + 1 ; } else { LPS [ i ] = 0 ; } } return LPS ; } static void count_occurence ( String s ) { int n = s . Length ; int [ ] LPS = prefix_function ( s ) ; int [ ] occ = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { occ [ LPS [ i ] ] ++ ; } for ( int i = n - 1 ; i > 0 ; i -- ) { occ [ LPS [ i - 1 ] ] += occ [ i ] ; } for ( int i = 0 ; i <= n ; i ++ ) occ [ i ] ++ ; print ( occ , s ) ; } public static void Main ( String [ ] args ) { String A = " ABACABA " ; count_occurence ( A ) ; } }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maximumSum ( int [ ] A , int [ ] B , int length , int X , int Y ) { int l = length ; int l1 = Math . Min ( length , X ) ; int l2 = Math . Min ( length , Y ) ; int [ , ] dp = new int [ l1 + 1 , l2 + 1 ] ; int max_sum = int . MinValue ; for ( int i = 1 ; i <= l1 ; i ++ ) { dp [ i , 0 ] = dp [ i - 1 , 0 ] + A [ i - 1 ] ; max_sum = Math . Max ( max_sum , dp [ i , 0 ] ) ; } for ( int i = 1 ; i <= l2 ; i ++ ) { dp [ 0 , i ] = dp [ 0 , i - 1 ] + B [ i - 1 ] ; max_sum = Math . Max ( max_sum , dp [ 0 , i ] ) ; } for ( int i = 1 ; i <= l1 ; i ++ ) { for ( int j = 1 ; j <= l2 ; j ++ ) { if ( i + j <= l ) dp [ i , j ] = Math . Max ( dp [ i - 1 , j ] + A [ i + j - 1 ] , dp [ i , j - 1 ] + B [ i + j - 1 ] ) ; max_sum = Math . Max ( dp [ i , j ] , max_sum ) ; } } return max_sum ; } public static void Main ( String [ ] args ) { int [ ] A = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int [ ] B = new int [ ] { 5 , 4 , 3 , 2 , 1 } ; int X = 3 , Y = 2 ; int N = A . Length ; Console . WriteLine ( maximumSum ( A , B , N , X , Y ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int reduceZero ( int N ) { int [ ] dp = new int [ N + 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) dp [ i ] = ( int ) 1e9 ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { foreach ( char c in String . Join ( " " , i ) . ToCharArray ( ) ) { dp [ i ] = Math . Min ( dp [ i ] , dp [ i - ( c - '0' ) ] + 1 ) ; } } return dp [ N ] ; } public static void Main ( String [ ] args ) { int N = 25 ; Console . Write ( reduceZero ( N ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: c, i
Class/struct names: GFG
C# program:
using System ; class GFG { static void printpenta ( int n ) { if ( n < 0 ) return ; int first = 0 ; int second = 0 ; int third = 0 ; int fourth = 0 ; int fifth = 1 ; int curr = 0 ; if ( n == 0 n == 1 n == 2 n == 3 ) Console . Write ( first + " STRNEWLINE " ) ; else if ( n == 5 ) Console . Write ( fifth + " STRNEWLINE " ) ; else { for ( int i = 5 ; i < n ; i ++ ) { curr = first + second + third + fourth + fifth ; first = second ; second = third ; third = fourth ; fourth = fifth ; fifth = curr ; } Console . Write ( curr + " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int n = 10 ; printpenta ( n ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , , ] dp = new int [ 100001 , 20 , 2 ] ; static int possibleBinaries ( int pos , int ones , int sum , int k ) { if ( ones == k ) return 0 ; if ( pos == 0 ) return ( sum == 0 ) ? 1 : 0 ; if ( dp [ pos , ones , sum ] != - 1 ) return dp [ pos , ones , sum ] ; int ret = possibleBinaries ( pos - 1 , ones + 1 , ( sum + 1 ) % 2 , k ) + possibleBinaries ( pos - 1 , 0 , sum , k ) ; dp [ pos , ones , sum ] = ret ; return dp [ pos , ones , sum ] ; } public static void Main ( String [ ] args ) { int N = 3 ; int K = 2 ; for ( int i = 0 ; i < 100001 ; i ++ ) { for ( int j = 0 ; j < 20 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) dp [ i , j , l ] = - 1 ; } } Console . Write ( possibleBinaries ( N , 0 , 0 , K ) ) ; } }

Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , , ] dp = new int [ 101 , 101 , 101 ] ; static int N , M , K ; static int MOD = 1000000007 ; public static void Initialize ( ) { for ( int i = 0 ; i <= 100 ; i ++ ) for ( int j = 0 ; j <= 100 ; j ++ ) for ( int z = 0 ; z <= 100 ; z ++ ) dp [ i , j , z ] = - 1 ; } public static int CountWays ( int i , int j , int k ) { if ( i >= N i < 0 j >= M j < 0 k < 0 ) return 0 ; if ( i == 0 && j == 0 && k == 0 ) return 1 ; if ( dp [ i , j , k ] != - 1 ) return dp [ i , j , k ] ; else dp [ i , j , k ] = ( CountWays ( i + 1 , j , k - 1 ) % MOD + CountWays ( i - 1 , j , k - 1 ) % MOD + CountWays ( i , j - 1 , k - 1 ) % MOD + CountWays ( i , j + 1 , k - 1 ) % MOD + CountWays ( i , j , k - 1 ) % MOD ) % MOD ; return dp [ i , j , k ] ; } public static void Main ( String [ ] args ) { N = 3 ; M = 3 ; K = 4 ; Initialize ( ) ; Console . WriteLine ( CountWays ( 0 , 0 , K ) ) ; } }

Accumulator variables: i, j, z
Iterator variables: i, j, z
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static bool [ ] prime = new bool [ 100001 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < prime . Length ; i ++ ) prime [ i ] = true ; prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p * p < 100000 ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= 100000 ; i += p ) prime [ i ] = false ; } } } static int distinctPrimeSubSeq ( int [ ] a , int n , int k ) { SieveOfEratosthenes ( ) ; List < int > primes = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ a [ i ] ] ) primes . Add ( a [ i ] ) ; } int l = primes . Count ; primes . Sort ( ) ; List < int > b = new List < int > ( ) ; List < int > dp = new List < int > ( ) ; int sum = 0 ; for ( int i = 0 ; i < l ; ) { int count = 1 , x = a [ i ] ; i ++ ; while ( i < l && a [ i ] == x ) { count ++ ; i ++ ; } b . Add ( count ) ; dp . Add ( count ) ; sum += count ; } int of_length = 2 ; int len = dp . Count ; int ans = 0 ; while ( of_length <= k ) { int freq = 0 ; int prev = 0 ; for ( int i = 0 ; i < ( len ) ; i ++ ) { freq += dp [ i ] ; int j = sum - freq ; int subseq = b [ i ] * j ; ans += subseq ; dp [ i ] = subseq ; prev += dp [ i ] ; } len -- ; sum = prev ; of_length ++ ; } ans += ( l + 1 ) ; return ans ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 2 , 3 , 3 , 4 , 5 } ; int n = a . Length ; int k = 3 ; Console . Write ( distinctPrimeSubSeq ( a , n , k ) ) ; } }

Index/key variables: i, p
Accumulator variables: ans, count, freq, i, len, of_length, p, prev, sum
Iterator variables: i, p
Class/struct names: GFG
C# program:
using System ; class GFG { static int findMinPrizes ( int [ ] arr , int n ) { int totalPrizes = 0 , j , x , y ; for ( int i = 0 ; i < n ; i ++ ) { x = 1 ; j = i ; while ( j > 0 && arr [ j ] > arr [ j - 1 ] ) { x ++ ; j -- ; } j = i ; y = 1 ; while ( j < n - 1 && arr [ j ] > arr [ j + 1 ] ) { y ++ ; j ++ ; } totalPrizes += Math . Max ( x , y ) ; } Console . Write ( totalPrizes + " STRNEWLINE " ) ; return 0 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 2 , 3 } ; int n = arr . Length ; findMinPrizes ( arr , n ) ; } }

Index/key variables: j
Accumulator variables: i, j, totalPrizes, x, y
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int mod = 1000000007 ; static int [ , ] dp = new int [ 1000 , 1000 ] ; static int calculate ( int pos , int left , int k , int L , int R ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; if ( dp [ pos , left ] != - 1 ) return dp [ pos , left ] ; int answer = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( i > left ) break ; answer = ( answer + calculate ( pos + 1 , left - i , k , L , R ) ) % mod ; } return dp [ pos , left ] = answer ; } static int countWaystoDivide ( int n , int k , int L , int R ) { for ( int i = 0 ; i < 1000 ; i ++ ) { for ( int j = 0 ; j < 1000 ; j ++ ) { dp [ i , j ] = - 1 ; } } return calculate ( 0 , n , k , L , R ) ; } public static void Main ( ) { int N = 12 ; int K = 3 ; int L = 1 ; int R = 5 ; Console . Write ( countWaystoDivide ( N , K , L , R ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > minSqrNum ( int n ) { int [ ] arr = new int [ n + 1 ] ; int k = 0 ; int [ ] sqrNum = new int [ n + 1 ] ; List < int > v = new List < int > ( ) ; arr [ 0 ] = 0 ; sqrNum [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { arr [ i ] = arr [ i - 1 ] + 1 ; sqrNum [ i ] = 1 ; k = 1 ; while ( k * k <= i ) { if ( arr [ i ] > arr [ i - k * k ] + 1 ) { arr [ i ] = arr [ i - k * k ] + 1 ; sqrNum [ i ] = k * k ; } k ++ ; } } while ( n > 0 ) { v . Add ( sqrNum [ n ] ) ; n -= sqrNum [ n ] ; } return v ; } public static void Main ( String [ ] args ) { int n = 10 ; List < int > v ; v = minSqrNum ( n ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { Console . Write ( v [ i ] ) ; if ( i + 1 != v . Count ) Console . Write ( " ▁ + ▁ " ) ; } } }

Index/key variables: i, n
Accumulator variables: i, k, n
Iterator variables: i
Class/struct names: GFG
Javascript program:
function maxPresum ( a , b ) { let X = Math . max ( a [ 0 ] , 0 ) ; for ( let i = 1 ; i < a . length ; i ++ ) { a [ i ] += a [ i - 1 ] ; X = Math . max ( X , a [ i ] ) ; } let Y = Math . max ( b [ 0 ] , 0 ) ; for ( let i = 1 ; i < b . length ; i ++ ) { b [ i ] += b [ i - 1 ] ; Y = Math . max ( Y , b [ i ] ) ; } return X + Y ; } let A = [ 2 , - 1 , 4 , - 5 ] ; let B = [ 4 , - 3 , 12 , 4 , - 3 ] ; document . write ( maxPresum ( A , B ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfTwoCubes ( n ) { var lo = 1 , hi = ( n ) ; while ( lo <= hi ) { var curr = ( lo * lo * lo + hi * hi * hi ) ; if ( curr == n ) return true ; if ( curr < n ) lo ++ ; else hi -- ; } return false ; } var N = 28 ; if ( sumOfTwoCubes ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: hi, lo
Javascript program:
function findNthNumber ( N ) { let result = 0 ; let p = 1 ; while ( N > 0 ) { result += ( p * ( N % 9 ) ) ; N = parseInt ( N / 9 , 10 ) ; p = p * 10 ; } return result ; } let N = 9 ; document . write ( findNthNumber ( N ) ) ;

Accumulator variables: result
Javascript program:
function sameProductQuadruples ( nums , N ) { var umap = new Array ( 10000 ) . fill ( 0 ) ; var res = 0 ; for ( var i = 0 ; i < N ; ++ i ) { for ( var j = i + 1 ; j < N ; ++ j ) { var prod = nums [ i ] * nums [ j ] ; res += 8 * umap [ prod ] ; ++ umap [ prod ] ; } } document . write ( res ) ; } var arr = [ 2 , 3 , 4 , 6 ] ; var N = arr . length ; sameProductQuadruples ( arr , N ) ;

Index/key variables: i, j, prod
Accumulator variables: res
Iterator variables: i, j
Javascript program:
function isCycleExists ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let arr = [ 1 , 3 , 2 , 4 , 5 ] ; let N = arr . length ; isCycleExists ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getMax ( arr , N , K ) { for ( i = 1 ; i < N ; i ++ ) { var cur_val = arr [ i ] ; while ( K >= i ) { if ( cur_val > 0 ) { arr [ 0 ] = arr [ 0 ] + 1 ; cur_val = cur_val - 1 ; K = K - i ; } else break ; } } document . write ( arr [ 0 ] ) ; } var arr = [ 1 , 0 , 3 , 2 ] ; var N = arr . length ; var K = 5 ; getMax ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSwaps ( b ) { var n = b . length ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( ( b [ 0 ] [ 0 ] ^ b [ 0 ] [ j ] ^ b [ i ] [ 0 ] ^ b [ i ] [ j ] ) == 1 ) { return - 1 ; } } } var rowSum = 0 ; var colSum = 0 ; var rowSwap = 0 ; var colSwap = 0 ; for ( i = 0 ; i < n ; i ++ ) { rowSum += b [ i ] [ 0 ] ; colSum += b [ 0 ] [ i ] ; var cond1 = 0 ; var cond2 = 0 ; if ( b [ i ] [ 0 ] == i % 2 ) cond1 = 1 ; if ( b [ 0 ] [ i ] == i % 2 ) cond2 = 1 ; rowSwap += cond1 ; colSwap += cond2 ; } if ( rowSum != n / 2 && rowSum != ( n + 1 ) / 2 ) return - 1 ; if ( colSum != n / 2 && colSum != ( n + 1 ) / 2 ) return - 1 ; if ( n % 2 == 1 ) { if ( ( colSwap % 2 ) == 1 ) colSwap = n - colSwap ; if ( ( rowSwap % 2 ) == 1 ) rowSwap = n - rowSwap ; } else { colSwap = Math . min ( colSwap , n - colSwap ) ; rowSwap = Math . min ( rowSwap , n - rowSwap ) ; } return ( rowSwap + colSwap ) / 2 ; } var M = [ [ 0 , 1 , 1 , 0 ] , [ 0 , 1 , 1 , 0 ] , [ 1 , 0 , 0 , 1 ] , [ 1 , 0 , 0 , 1 ] ] ; var ans = minSwaps ( M ) ; document . write ( ans ) ;

Index/key variables: i, j
Accumulator variables: colSum, colSwap, i, j, rowSum, rowSwap
Iterator variables: i, j