dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function totalArrays ( N , M ) { var end_with_one = Array ( N + 1 ) ; var end_not_with_one = Array ( N + 1 ) ; end_with_one [ 0 ] = 1 ; end_not_with_one [ 0 ] = 0 ; end_with_one [ 1 ] = 0 ; end_not_with_one [ 1 ] = M - 1 ; for ( var i = 2 ; i < N ; i ++ ) { end_with_one [ i ] = end_not_with_one [ i - 1 ] ; end_not_with_one [ i ] = end_with_one [ i - 1 ] * ( M - 1 ) + end_not_with_one [ i - 1 ] * ( M - 2 ) ; } return end_with_one [ N - 1 ] ; } var N = 3 , M = 3 ; var temp = totalArrays ( N , M ) ; var ans = M * temp ; document . write ( ans + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function prodOfDigit ( N ) { let res = 1 ; while ( N ) { res = res * ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } return res ; } function cntNumRange ( L , R , K ) { let cnt = 0 ; for ( let i = L ; i <= R ; i ++ ) { if ( prodOfDigit ( i ) == K ) { cnt ++ ; } } return cnt ; } let L = 20 , R = 10000 , K = 14 ; document . write ( cntNumRange ( L , R , K ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function findMedXOR ( mat , N , M ) { let dp = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) dp [ i ] = new Array ( M ) ; let med = new Array ( N * M ) ; dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ; med [ 0 ] = dp [ 0 ] [ 0 ] ; let len = 1 ; for ( let i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ^ mat [ i ] [ 0 ] ; med [ len ++ ] = dp [ i ] [ 0 ] ; } for ( let i = 1 ; i < M ; i ++ ) { dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ^ mat [ 0 ] [ i ] ; med [ len ++ ] = dp [ 0 ] [ i ] ; } for ( let i = 1 ; i < N ; i ++ ) { for ( let j = 1 ; j < M ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ^ dp [ i ] [ j - 1 ] ^ dp [ i - 1 ] [ j - 1 ] ^ mat [ i ] [ j ] ; med [ len ++ ] = dp [ i ] [ j ] ; } } med . sort ( ) ; if ( len % 2 == 0 ) { return ( med [ parseInt ( len / 2 ) ] + med [ parseInt ( len / 2 ) - 1 ] ) / 2.0 ; } return med [ parseInt ( len / 2 ) ] ; } let mat = [ [ 1 , 2 ] , [ 2 , 3 ] ] ; let N = mat . length ; let M = 2 ; document . write ( findMedXOR ( mat , N , M ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, len
Iterator variables: i, j
Javascript program:
function countWaysToTileBoard ( N ) { let dp = [ ] ; dp [ 0 ] = 1 ; dp [ 1 ] = 2 ; for ( let i = 2 ; i <= N ; i ++ ) { dp [ i ] = ( 2 * dp [ i - 1 ] + dp [ i - 2 ] ) ; } document . write ( dp [ N ] ) ; } let N = 2 ; countWaysToTileBoard ( N ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function FindSub ( str , res , i ) { if ( i === str . length ) { if ( res . length > 0 ) { document . write ( res + " " ) ; } return ; } var ch = str [ i ] ; FindSub ( str , res , i + 1 ) ; FindSub ( str , res + ch , i + 1 ) ; FindSub ( str , res + ch . charCodeAt ( 0 ) , i + 1 ) ; } var str = " " ; var res = " " ; var N = str . length ; FindSub ( str , res , 0 ) ;

Index/key variables: i
Javascript program:
function maxProductPath ( grid ) { var n = grid . length ; var m = grid [ 0 ] . length ; var maxPath = Array . from ( Array ( n ) , ( ) => Array ( m ) . fill ( 0 ) ) ; var minPath = Array . from ( Array ( n ) , ( ) => Array ( m ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < m ; j ++ ) { var mn = 1000000000 ; var mx = - 1000000000 ; if ( i == 0 && j == 0 ) { mx = grid [ i ] [ j ] ; mn = grid [ i ] [ j ] ; } if ( i > 0 ) { var tempmx = Math . max ( ( maxPath [ i - 1 ] [ j ] * grid [ i ] [ j ] ) , ( minPath [ i - 1 ] [ j ] * grid [ i ] [ j ] ) ) ; mx = Math . max ( mx , tempmx ) ; var tempmn = Math . min ( ( maxPath [ i - 1 ] [ j ] * grid [ i ] [ j ] ) , ( minPath [ i - 1 ] [ j ] * grid [ i ] [ j ] ) ) ; mn = Math . min ( mn , tempmn ) ; } if ( j > 0 ) { var tempmx = Math . max ( ( maxPath [ i ] [ j - 1 ] * grid [ i ] [ j ] ) , ( minPath [ i ] [ j - 1 ] * grid [ i ] [ j ] ) ) ; mx = Math . max ( mx , tempmx ) ; var tempmn = Math . min ( ( maxPath [ i ] [ j - 1 ] * grid [ i ] [ j ] ) , ( minPath [ i ] [ j - 1 ] * grid [ i ] [ j ] ) ) ; mn = Math . min ( mn , tempmn ) ; } maxPath [ i ] [ j ] = mx ; minPath [ i ] [ j ] = mn ; } } if ( maxPath [ n - 1 ] [ m - 1 ] < 0 ) return - 1 ; else return ( maxPath [ n - 1 ] [ m - 1 ] ) ; } var mat = [ [ 1 , - 2 , 1 ] , [ 1 , - 2 , 1 ] , [ 3 , - 4 , 1 ] ] ; document . write ( maxProductPath ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function removeSmallestSubarray ( arr , S , n , k ) { var target_remainder = S % k ; var map1 = new Map ( ) ; map1 . set ( 0 , - 1 ) ; var curr_remainder = 0 ; var res = 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { curr_remainder = ( curr_remainder + arr [ i ] + k ) % k ; map1 . set ( curr_remainder , i ) ; var mod = ( curr_remainder - target_remainder + k ) % k ; if ( map1 . has ( mod ) ) { res = Math . min ( res , i - map1 . get ( mod ) ) ; } } if ( res == 1000000000 res == n ) { res = - 1 ; } return res ; } function smstSubmatDeleted ( mat , N , M , K ) { var S = 0 ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) S += mat [ i ] [ j ] ; } var min_area = N * M ; var left = 0 ; var right = 0 ; var width ; var area ; var prefixRowSum = Array ( N ) ; for ( left = 0 ; left < M ; left ++ ) { prefixRowSum = Array ( N ) . fill ( 0 ) ; for ( right = left ; right < M ; right ++ ) { for ( var i = 0 ; i < N ; i ++ ) { prefixRowSum [ i ] += mat [ i ] [ right ] ; } width = removeSmallestSubarray ( prefixRowSum , S , N , K ) ; if ( width != - 1 ) { area = ( right - left + 1 ) * ( width ) ; if ( area < min_area ) { min_area = area ; } } } } return min_area ; } var mat = [ [ 6 , 2 , 6 ] , [ 3 , 2 , 8 ] , [ 2 , 5 , 3 ] ] ; var K = 3 ; var N = mat . length ; var M = mat [ 0 ] . length ; document . write ( smstSubmatDeleted ( mat , N , M , K ) ) ;

Index/key variables: i, j, right
Accumulator variables: S, i, j, left, right
Iterator variables: i, j, left, right
Javascript program:
function countstrings ( n , start ) { if ( n == 0 ) { return 1 ; } let cnt = 0 ; for ( let i = start ; i < 5 ; i ++ ) { cnt += countstrings ( n - 1 , i ) ; } return cnt ; } function countVowelStrings ( n ) { return countstrings ( n , 0 ) ; } let n = 2 ; document . write ( countVowelStrings ( n ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
var mod = 1000000007 ; function findTotalPath ( X , n , dp ) { if ( X == 0 ) { return 1 ; } var ans = 0 ; if ( dp [ X ] != - 1 ) { return dp [ X ] ; } for ( var i = 1 ; i <= Math . min ( X , n ) ; ++ i ) { ans += findTotalPath ( X - i , n , dp ) % mod ; ans %= mod ; } return dp [ X ] = ans ; } var n = 3 , X = 2 ; var dp = Array ( X + 1 ) . fill ( - 1 ) ; document . write ( findTotalPath ( X , n , dp ) ) ;

Index/key variables: X
Accumulator variables: ans
Iterator variables: i
Javascript program:
var bin = Array . from ( Array ( 3000 ) , ( ) => Array ( 3000 ) . fill ( 0 ) ) ; function countWays ( arr ) { var mod = 1000000007 ; bin [ 0 ] [ 0 ] = 1 ; for ( var i = 1 ; i < 3000 ; i ++ ) { bin [ i ] [ 0 ] = 1 ; for ( var j = 1 ; j <= i ; j ++ ) { bin [ i ] [ j ] = ( bin [ i - 1 ] [ j ] + bin [ i - 1 ] [ j - 1 ] ) % mod ; } } var n = 0 ; for ( var x = 0 ; x < arr . length ; x ++ ) n += arr [ x ] ; var ways = Array ( n + 1 ) . fill ( 0 ) ; for ( var i = 1 ; i <= n ; i ++ ) { ways [ i ] = 1 ; for ( var j = 0 ; j < arr . length ; j ++ ) { ways [ i ] = ( ways [ i ] * bin [ arr [ j ] + i - 1 ] [ i - 1 ] ) % mod ; } for ( var j = 1 ; j < i ; j ++ ) { ways [ i ] = ( ( ways [ i ] - bin [ i ] [ j ] * ways [ j ] ) % mod + mod ) % mod ; } } var ans = 0 ; for ( var i = 1 ; i <= n ; i ++ ) ans = ( ans + ways [ i ] ) % mod ; document . write ( ans ) ; } var arr = [ 1 , 1 ] ; countWays ( arr ) ;

Index/key variables: i, j, x
Accumulator variables: i, j, n, x
Iterator variables: i, j, x
Javascript program:
let MAX = 100005 function SieveOfEratosthenes ( ) { let seive = new Array ( MAX ) ; seive . fill ( true ) for ( let p = 2 ; p * p < MAX ; p ++ ) { if ( seive [ p ] == true ) { for ( let i = p * p ; i < MAX ; i += p ) { seive [ i ] = false ; } } } let v = new Array ( ) ; for ( let p = 2 ; p < MAX ; p ++ ) { if ( seive [ p ] ) { v . push ( p ) ; } } return v ; } function build ( dp , arr , N ) { dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; let prime = SieveOfEratosthenes ( ) ; let pref = new Array ( N + 1 ) ; pref [ 0 ] = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { pref [ i ] = pref [ i - 1 ] + arr [ i - 1 ] ; } for ( let i = 2 ; i <= N ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; for ( let j = 0 ; j <= prime . length ; j ++ ) { let r = i - 1 ; let l = r - prime [ j ] + 1 ; if ( l < 0 ) break ; let temp = 0 ; temp = pref [ r + 1 ] - pref [ l ] ; if ( l - 2 >= 0 ) temp += dp [ l - 2 + 1 ] ; dp [ i ] = Math . max ( dp [ i ] , temp ) ; } } } function maxSumSubseq ( arr , N ) { let dp = new Array ( N + 1 ) ; build ( dp , arr , N ) ; document . write ( dp [ N ] ) ; } let arr = [ 10 , 10 , 7 , 10 , 10 , 10 ] ; let N = arr . length ; maxSumSubseq ( arr , N ) ;

Index/key variables: N, i, j, l, p
Accumulator variables: i, j, p, temp
Iterator variables: i, j, p
Javascript program:
function maxScore ( arr ) { var N = arr . length ; N ++ ; var dp = Array . from ( Array ( N + 1 ) , ( ) => Array ( 2 * N ) . fill ( - 10000000 ) ) ; dp [ 0 ] [ 0 ] = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { for ( var s = 1 ; s <= 2 * ( N - 1 ) ; s ++ ) { for ( var j = 1 ; j <= N - 1 && j <= s ; j ++ ) { dp [ i ] [ s ] = Math . max ( dp [ i ] [ s ] , arr [ j - 1 ] + dp [ i - 1 ] [ s - j ] ) ; } } } return dp [ N ] [ 2 * ( N - 1 ) ] ; } var arr = [ 1 , 3 , 0 ] ; document . write ( maxScore ( arr ) ) ;

Index/key variables: N, i, s
Accumulator variables: N, i, j, s
Iterator variables: i, j, s
Javascript program:
function minimumCost ( cost , n , x ) { let dp = [ ] ; dp [ 0 ] = cost [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( i == 1 ) dp [ i ] = cost [ i ] + dp [ i - 1 ] ; if ( i == 2 ) dp [ i ] = cost [ i ] + Math . min ( dp [ i - 1 ] , x + dp [ i - 2 ] ) ; if ( i >= 3 ) dp [ i ] = cost [ i ] + Math . min ( dp [ i - 1 ] , Math . min ( x + dp [ i - 2 ] , 2 * x + dp [ i - 3 ] ) ) ; } document . write ( dp [ n - 1 ] ) ; } let X = 4 ; let cost = [ 6 , 3 , 9 , 2 , 1 , 3 ] ; let N = cost . length ; minimumCost ( cost , N , X ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkStr ( str , P , Q ) { let N = str . length ; let prev = str [ 0 ] ; let cnt = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( str [ i ] == prev ) { cnt ++ ; } else { if ( prev == ' ' && cnt >= Q ) { return false ; } if ( prev == ' ' && cnt >= P ) { return false ; } cnt = 1 ; } prev = str [ i ] ; } if ( prev == ' ' && cnt >= Q ) { return false ; } if ( prev == ' ' && cnt >= P ) { return false ; } return true ; } function cntBinStr ( str , N , P , Q ) { let len = str . length ; if ( len == N ) { if ( checkStr ( str , P , Q ) ) return 1 ; return 0 ; } let X = cntBinStr ( str + ' ' , N , P , Q ) ; let Y = cntBinStr ( str + ' ' , N , P , Q ) ; return X + Y ; } let N = 5 , P = 2 , Q = 3 ; document . write ( cntBinStr ( " " , N , P , Q ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function binCoff ( N , R ) { var res = 1 ; if ( R > ( N - R ) ) { R = ( N - R ) ; } for ( i = 0 ; i < R ; i ++ ) { res *= ( N - i ) ; res /= ( i + 1 ) ; } return res ; } function cntPermutation ( N ) { var cntPerm ; var C_2N_N = binCoff ( 2 * N , N ) ; cntPerm = C_2N_N / ( N + 1 ) ; return cntPerm ; } var arr = [ 1 , 2 , 3 , 4 ] ; var N = arr . length ; document . write ( cntPermutation ( N / 2 ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function longestPalSubstr ( str ) { var n = str . length ; var maxLength = 1 , start = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { for ( var j = i ; j < str . length ; j ++ ) { var flag = 1 ; for ( var k = 0 ; k < ( j - i + 1 ) / 2 ; k ++ ) if ( str [ i + k ] != str [ j - k ] ) flag = 0 ; if ( flag && ( j - i + 1 ) > maxLength ) { start = i ; maxLength = j - i + 1 ; } } } return maxLength ; } var str = " " ; document . write ( longestPalSubstr ( str ) ) ;

Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let dp = new Array ( 101 ) ; for ( let i = 0 ; i < 101 ; i ++ ) { dp [ i ] = new Array ( 101 ) ; for ( let j = 0 ; j < 101 ; j ++ ) { dp [ i ] [ j ] = new Array ( 101 ) ; for ( let k = 0 ; k < 101 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } function helper ( arr , left , right , count , m ) { if ( left > right ) return 0 ; if ( dp [ left ] [ right ] [ count ] != - 1 ) { return dp [ left ] [ right ] [ count ] ; } let ans = ( count + 1 ) * m + helper ( arr , left + 1 , right , 0 , m ) ; for ( let i = left + 1 ; i <= right ; ++ i ) { if ( arr [ i ] == arr [ left ] ) { ans = Math . max ( ans , helper ( arr , left + 1 , i - 1 , 0 , m ) + helper ( arr , i , right , count + 1 , m ) ) ; } } dp [ left ] [ right ] [ count ] = ans ; return ans ; } function maxPoints ( arr , n , m ) { let len = arr . length ; return helper ( arr , 0 , len - 1 , 0 , m ) ; } let arr = [ 1 , 3 , 2 , 2 , 2 , 3 , 4 , 3 , 1 ] ; let M = 3 ; let N = arr . length ; document . write ( maxPoints ( arr , N , M ) ) ;

Index/key variables: count, i, j, k, left, right
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let inf = 1000000008 ; function minSteps ( m , n ) { if ( n == m ) return 0 ; if ( m > n ) return inf ; let min_cost = inf ; for ( let i = 2 ; i < m ; i += 2 ) { if ( m % i == 0 ) { min_cost = Math . min ( min_cost , m / i + minSteps ( m + i , n ) ) ; } } return min_cost ; } let M = 6 ; let N = 24 ; let minimum_cost = minSteps ( M , N ) ; minimum_cost = minimum_cost == inf ? - 1 : minimum_cost ; document . write ( minimum_cost ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function manipulation ( matrix , q ) { let x1 = q [ 0 ] , y1 = q [ 1 ] , x2 = q [ 2 ] , y2 = q [ 3 ] ; for ( let i = x1 - 1 ; i < x2 ; i ++ ) { for ( let j = y1 - 1 ; j < y2 ; j ++ ) { if ( matrix [ i ] [ j ] == 1 ) matrix [ i ] [ j ] = 0 ; else matrix [ i ] [ j ] = 1 ; } } } function queries_fxn ( matrix , queries ) { for ( let q of queries ) manipulation ( matrix , q ) ; } let matrix = [ [ 0 , 1 , 0 ] , [ 1 , 1 , 0 ] ] ; let queries = [ [ 1 , 1 , 2 , 3 ] , [ 1 , 1 , 1 , 1 ] , [ 1 , 2 , 2 , 3 ] ] ; queries_fxn ( matrix , queries ) ; document . write ( " " ) ; for ( let i = 0 ; i < matrix . length ; i ++ ) { document . write ( " " ) ; for ( let j = 0 ; j < matrix [ i ] . length ; j ++ ) { if ( j < matrix [ i ] . length - 1 ) { document . write ( matrix [ i ] [ j ] + " " ) ; } else { document . write ( matrix [ i ] [ j ] + " " ) ; } } if ( i == matrix . length - 1 ) document . write ( " " ) ; else document . write ( " " ) ; } document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j, q
Javascript program:
let INF = 1e7 ; function min_op ( cur , M ) { if ( cur > M ) return INF ; if ( cur == M ) return 0 ; let op = INF ; for ( let i = 2 ; i * i <= cur ; i ++ ) { if ( cur % i == 0 ) { if ( i % 2 == 0 ) { op = Math . min ( op , 1 + min_op ( cur + i , M ) ) ; } if ( ( cur / i ) != i && ( cur / i ) % 2 == 0 ) { op = Math . min ( op , 1 + min_op ( cur + ( cur / i ) , M ) ) ; } } } return op ; } function min_operations ( N , M ) { let op = min_op ( N , M ) ; if ( op >= INF ) document . write ( " " ) ; else document . write ( op + " " ) ; } let N = 6 , M = 24 ; min_operations ( N , M ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findPrimeFactors ( n ) { let primeFactors = new Array ( 9 ) . fill ( 0 ) ; let j = 0 ; if ( n % 2 == 0 ) { primeFactors [ j ++ ] = 2 ; while ( n % 2 == 0 ) n >>= 1 ; } for ( let i = 3 ; i * i <= n ; i += 2 ) { if ( n % i == 0 ) { primeFactors [ j ++ ] = i ; while ( n % i == 0 ) n /= i ; } } if ( n > 2 ) primeFactors [ j ++ ] = n ; let PrimeFactors = new Array ( j ) ; for ( let i = 0 ; i < j ; i ++ ) { PrimeFactors [ i ] = primeFactors [ i ] ; } return PrimeFactors ; } function findShortestSubsequence ( dp , a , index , primeFactors ) { let n = a . length ; for ( let j = index ; j < n ; j ++ ) { let bitmask = 0 ; for ( let p = 0 ; p < primeFactors . length ; p ++ ) { if ( ( a [ j ] % primeFactors [ p ] ) == 0 ) { bitmask ^= ( 1 << p ) ; } } for ( let i = 0 ; i < dp . length ; i ++ ) { if ( dp [ i ] == n + 1 ) continue ; dp [ bitmask & i ] = Math . min ( dp [ bitmask & i ] , dp [ i ] + 1 ) ; } } } function prletMinimumLength ( a ) { let Min = a . length + 1 ; for ( let i = 0 ; i < a . length - 1 ; i ++ ) { let primeFactors = findPrimeFactors ( a [ i ] ) ; let n = primeFactors . length ; let dp = new Array ( 1 << n ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = a . length + 1 } let setBits = ( 1 << n ) - 1 ; dp [ setBits ] = 1 ; findShortestSubsequence ( dp , a , i + 1 , primeFactors ) ; Min = Math . min ( dp [ 0 ] , Min ) ; } if ( Min == ( a . length + 1 ) ) document . write ( - 1 + " " ) ; else document . write ( Min + " " ) ; } let arr = [ 2 , 6 , 12 , 3 ] ; prletMinimumLength ( arr ) ;

Index/key variables: i, j, p, setBits
Accumulator variables: bitmask, i, j, n, p
Iterator variables: i, j, p
Javascript program:
function xorSum ( a , n , mask , dp ) { if ( dp [ mask ] != - 1 ) { return dp [ mask ] ; } var max_value = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( i != j && ( mask & ( 1 << i ) ) == 0 && ( mask & ( 1 << j ) ) == 0 ) { max_value = Math . max ( max_value , ( a [ i ] ^ a [ j ] ) + xorSum ( a , n , ( mask | ( 1 << i ) | ( 1 << j ) ) , dp ) ) ; } } } return dp [ mask ] = max_value ; } var n = 4 ; var arr = [ 1 , 2 , 3 , 4 ] ; var dp = Array ( ( 1 << n ) + 5 ) . fill ( - 1 ) ; document . write ( xorSum ( arr , n , 0 , dp ) ) ;

Index/key variables: i, j, mask
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var fib = Array ( 101 ) . fill ( 0 ) ; var dp1 = Array ( 101 ) . fill ( 0 ) ; var dp2 = Array ( 101 ) . fill ( 0 ) ; var v = Array ( 101 ) . fill ( 0 ) ; function fibonacci ( ) { fib [ 1 ] = 1 ; fib [ 2 ] = 2 ; for ( i = 3 ; i <= 87 ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } function find ( num ) { var cnt = 0 ; for ( i = 87 ; i > 0 ; i -- ) { if ( num >= fib [ i ] ) { v [ cnt ++ ] = i ; num -= fib [ i ] ; } } for ( i = 0 ; i < cnt / 2 ; i ++ ) { var t = v [ i ] ; v [ i ] = v [ cnt - i - 1 ] ; v [ cnt - i - 1 ] = t ; } dp1 [ 0 ] = 1 ; dp2 [ 0 ] = parseInt ( ( v [ 0 ] - 1 ) / 2 ) ; for ( i = 1 ; i < cnt ; i ++ ) { dp1 [ i ] = dp1 [ i - 1 ] + dp2 [ i - 1 ] ; dp2 [ i ] = parseInt ( ( v [ i ] - v [ i - 1 ] ) / 2 ) * dp2 [ i - 1 ] + parseInt ( ( v [ i ] - v [ i - 1 ] - 1 ) / 2 ) * dp1 [ i - 1 ] ; } return ( dp1 [ cnt - 1 ] + dp2 [ cnt - 1 ] ) ; } fibonacci ( ) ; var num = 13 ; document . write ( find ( num ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, num
Iterator variables: i
Javascript program:
function countNums ( N ) { let l = Math . floor ( Math . pow ( 10 , N - 1 ) ) ; let r = Math . floor ( Math . pow ( 10 , N ) ) - 1 ; let count = 0 ; for ( let i = l ; i <= r ; i ++ ) { let xorr = 0 , temp = i ; while ( temp > 0 ) { xorr = xorr ^ ( temp % 10 ) ; temp = Math . floor ( temp / 10 ) ; } if ( xorr <= 9 ) count ++ ; } document . write ( count ) ; } let N = 2 ; countNums ( N ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function main_fun ( arr , n ) { var dp = Array . from ( Array ( 4 ) , ( ) => Array ( n ) . fill ( 0 ) ) ; if ( arr [ 0 ] == 0 ) dp [ 0 ] [ 0 ] = 1 ; else dp [ 1 ] [ 0 ] = 1 ; for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 1 ; else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ; } for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) dp [ 1 ] [ i ] = Math . max ( dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ) ; else dp [ 1 ] [ i ] = dp [ 1 ] [ i - 1 ] ; } for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { dp [ 2 ] [ i ] = Math . max ( dp [ 2 ] [ i - 1 ] + 1 , Math . max ( dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ) ) ; } else dp [ 2 ] [ i ] = dp [ 2 ] [ i - 1 ] ; } for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) { dp [ 3 ] [ i ] = Math . max ( dp [ 3 ] [ i - 1 ] + 1 , Math . max ( dp [ 2 ] [ i - 1 ] + 1 , Math . max ( dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ) ) ) ; } else dp [ 3 ] [ i ] = dp [ 3 ] [ i - 1 ] ; } var ans = Math . max ( dp [ 2 ] [ n - 1 ] , Math . max ( dp [ 1 ] [ n - 1 ] , Math . max ( dp [ 0 ] [ n - 1 ] , dp [ 3 ] [ n - 1 ] ) ) ) ; document . write ( ans ) ; } var n = 4 ; var arr = [ 0 , 1 , 0 , 1 ] ; main_fun ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function SubarrayWithMaxSum ( nums ) { var endIndex , currMax = nums [ 0 ] ; var globalMax = nums [ 0 ] ; for ( var i = 1 ; i < nums . length ; ++ i ) { currMax = Math . max ( nums [ i ] , nums [ i ] + currMax ) ; if ( currMax > globalMax ) { globalMax = currMax ; endIndex = i ; } } var startIndex = endIndex ; while ( startIndex >= 0 ) { globalMax -= nums [ startIndex ] ; if ( globalMax == 0 ) break ; startIndex -- ; } for ( var i = startIndex ; i <= endIndex ; ++ i ) { document . write ( nums [ i ] + " " ) ; } } var arr = [ - 2 , - 5 , 6 , - 2 , - 3 , 1 , 5 , - 6 ] ; SubarrayWithMaxSum ( arr ) ;

Index/key variables: i, startIndex
Accumulator variables: globalMax, startIndex
Iterator variables: i
Javascript program:
let primes = new Array ( ) ; let M = 100005 ; function sieve ( ) { let mark = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) mark [ i ] = false ; for ( let i = 2 ; i < M ; i ++ ) mark [ i ] = true ; for ( let i = 2 ; i * i < M ; i ++ ) { if ( mark [ i ] ) { for ( let j = i * i ; j < M ; j += i ) mark [ j ] = false ; } } for ( let i = 2 ; i < M ; i ++ ) if ( mark [ i ] ) primes . push ( i ) ; } function countPrimonacci ( l , r ) { let dp = new Array ( ) ; dp . push ( 1 ) ; dp . push ( 1 ) ; let i = 2 ; let s = new Set ( ) ; while ( true ) { let x = 0 ; for ( let j = 0 ; j < primes . length ; j ++ ) { let p = primes [ j ] ; if ( p >= i ) break ; x += dp [ i - p ] ; } if ( x >= l && x <= r ) s . add ( x ) ; if ( x > r ) break ; dp . push ( x ) ; i ++ ; } document . write ( s . size ) ; } sieve ( ) ; let L = 1 , R = 10 ; countPrimonacci ( L , R ) ;

Index/key variables: i, j
Accumulator variables: i, j, x
Iterator variables: i, j
Javascript program:
let N = parseInt ( ( 1e5 + 5 ) ) ; let MOD = 1000000007 ; let dp = Array ( N ) . fill ( 0 ) ; function countStrings ( K , Q ) { dp [ 0 ] = 1 ; for ( let i = 1 ; i < N ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; if ( i >= K ) dp [ i ] = ( dp [ i ] + dp [ i - K ] ) % MOD ; } for ( let i = 1 ; i < N ; i ++ ) { dp [ i ] = ( dp [ i ] + dp [ i - 1 ] ) % MOD ; } for ( let i = 0 ; i < Q . length ; i ++ ) { var ans = dp [ Q [ i ] [ 1 ] ] - dp [ Q [ i ] [ 0 ] - 1 ] ; if ( ans < 0 ) ans = ans + MOD ; document . write ( ans + " " ) ; } } var K = 3 ; let Q = [ [ 1 , 4 ] , [ 3 , 7 ] ] ; countStrings ( K , Q ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSum ( n , num , price ) { let dp = Array . from ( { length : n } , ( _ , i ) => Number . MAX_VALUE ) ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( num [ j ] > num [ i ] ) { dp [ j ] = Math . min ( dp [ j ] , price [ i ] + price [ j ] ) ; ans = Math . min ( ans , dp [ i ] + price [ j ] ) ; } } } return ans != Number . MAX_VALUE ? ans : - 1 ; } let num = [ 2 , 4 , 6 , 7 , 8 ] ; let price = [ 10 , 20 , 100 , 20 , 40 ] ; let n = price . length ; document . write ( minSum ( n , num , price ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function binomialCoeff ( n , k ) { var res = 1 ; if ( k > n - k ) k = n - k ; for ( var i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function countStrings ( N ) { if ( N % 2 == 1 ) return 0 ; else { N /= 2 ; var c = binomialCoeff ( 2 * N , N ) ; return c / ( N + 1 ) ; } } var N = 6 ; document . write ( countStrings ( N ) + " " ) ;

Accumulator variables: N, res
Iterator variables: i