dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function count ( n ) { if ( n == 2 ) return 1 ; else if ( n == 4 ) return 2 ; else if ( n == 6 ) return 4 ; let table = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; let i ; for ( i = 0 ; i < n + 1 ; i ++ ) table [ i ] = 0 ; table [ 0 ] = 0 ; table [ 2 ] = 1 ; table [ 4 ] = 2 ; table [ 6 ] = 4 ; for ( i = 8 ; i <= n ; i = i + 2 ) { table [ i ] = table [ i - 2 ] + table [ i - 4 ] + table [ i - 6 ] ; } return table [ n ] ; } let n = 8 ; document . write ( count ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
let MOD = 1000000007 ; function isPrime ( number ) { let num = parseInt ( number ) ; for ( let i = 2 ; i * i <= num ; i ++ ) { if ( ( num % i ) == 0 ) return false ; } return num > 1 ? true : false ; } function countPrimeStrings ( number , i ) { if ( i == 0 ) return 1 ; let cnt = 0 ; for ( let j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number [ i - j ] != ' ' && isPrime ( number . substring ( i - j , i ) ) ) { cnt += countPrimeStrings ( number , i - j ) ; cnt %= MOD ; } } return cnt ; } let s1 = " " ; let l = s1 . length ; document . write ( countPrimeStrings ( s1 , l ) ) ;

Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
let MOD = 1000000007 ; let sieve = new Array ( 1000000 ) ; function buildSieve ( ) { for ( let i = 0 ; i < sieve . length ; i ++ ) { sieve [ i ] = true ; } sieve [ 0 ] = false ; sieve [ 1 ] = false ; for ( let p = 2 ; p * p <= 1000000 ; p ++ ) { if ( sieve [ p ] == true ) { for ( let i = p * p ; i < 1000000 ; i += p ) sieve [ i ] = false ; } } } function isPrime ( number ) { let num = parseInt ( number ) ; return sieve [ num ] ; } function rec ( number , i , dp ) { if ( dp [ i ] != - 1 ) return dp [ i ] ; let cnt = 0 ; for ( let j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number [ i - j ] != ' ' && isPrime ( number . substring ( i - j , i ) ) ) { cnt += rec ( number , i - j , dp ) ; cnt %= MOD ; } } return dp [ i ] = cnt ; } function countPrimeStrings ( number ) { let n = number . length ; let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { dp [ i ] = - 1 ; } dp [ 0 ] = 1 ; return rec ( number , n , dp ) ; } buildSieve ( ) ; let s1 = " " ; document . write ( countPrimeStrings ( s1 ) + " " ) ;

Index/key variables: i, num, p
Accumulator variables: cnt, i, j, p
Iterator variables: i, j, p
Javascript program:
function squareOfZeroes ( matrix ) { var lastIdx = matrix . length - 1 ; var cache = new Map ( ) ; return hasSquareOfZeroes ( matrix , 0 , 0 , lastIdx , lastIdx , cache ) ; } function hasSquareOfZeroes ( matrix , r1 , c1 , r2 , c2 , cache ) { if ( r1 >= r2 c1 >= c2 ) return false ; var key = ( r1 . toString ( ) ) + ' ' + ( c1 . toString ( ) ) + ' ' + ( r2 . toString ( ) ) + ' ' + ( c2 . toString ( ) ) ; if ( cache . has ( key ) ) return cache . get ( key ) ; cache [ key ] = isSquareOfZeroes ( matrix , r1 , c1 , r2 , c2 ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 - 1 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 + 1 , r2 - 1 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 , r2 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 , r2 - 1 , c2 - 1 , cache ) ; return cache [ key ] ; } function isSquareOfZeroes ( matrix , r1 , c1 , r2 , c2 ) { for ( var row = r1 ; row < r2 + 1 ; row ++ ) { if ( matrix [ row ] [ c1 ] != 0 matrix [ row ] [ c2 ] != 0 ) return false ; } for ( var col = c1 ; col < c2 + 1 ; col ++ ) { if ( matrix [ r1 ] [ col ] != 0 matrix [ r2 ] [ col ] != 0 ) return false ; } return true ; } var matrix = [ [ 1 , 1 , 1 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 0 , 0 , 1 ] ] ; var ans ; ans = squareOfZeroes ( matrix ) ; if ( ans == 1 ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: c1, c2, col, key, r1, r2, row
Accumulator variables: col, row
Iterator variables: col, row
Javascript program:
function CountWays ( a , b , c ) { let x = b + c + 1 ; let arr = new Array ( x ) ; arr . fill ( 0 ) ; for ( let i = a ; i <= b ; i ++ ) { for ( let j = b ; j <= c ; j ++ ) { arr [ i + j ] ++ ; } } for ( let i = 1 ; i < x ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let a = 1 ; let b = 2 ; let c = 2 ; CountWays ( a , b , c ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function CountWays ( a , b , c ) { let x = b + c + 2 ; let arr = new Array ( x ) ; arr . fill ( 0 ) ; for ( let i = 1 ; i <= b ; i ++ ) { arr [ i + b ] ++ ; arr [ i + c + 1 ] -- ; } for ( let i = 1 ; i < x - 1 ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; document . write ( arr [ i ] + " " ) ; } document . write ( " " ) ; } let a = 1 ; let b = 2 ; let c = 2 ; CountWays ( a , b , c ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function differentStrings ( s ) { var n = s . length ; var dp = Array ( n + 1 ) ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( var i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] && ( s [ i ] == ' ' s [ i ] == ' ' ) ) dp [ i + 1 ] = dp [ i ] + dp [ i - 1 ] ; else dp [ i + 1 ] = dp [ i ] ; } document . write ( dp [ n ] + " " ) ; } var S = " " ; differentStrings ( S ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
var Col = 3 ; function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function fact ( n ) { var res = 1 ; for ( var i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function sumPathCost ( grid , m , n ) { var sum = 0 , count ; for ( var i = 0 ; i <= m ; i ++ ) { for ( var j = 0 ; j <= n ; j ++ ) { count = nCr ( i + j , i ) * nCr ( m + n - i - j , m - i ) ; sum += count * grid [ i ] [ j ] ; } } return sum ; } var m = 2 ; var n = 2 ; var grid = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; document . write ( sumPathCost ( grid , m , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
var K ; var N ; var v = [ ] ; var dp = Array . from ( Array ( 20 ) ) ; function init ( x ) { for ( var i = 0 ; i < 20 ; i ++ ) { dp [ i ] = Array . from ( Array ( 1000 ) , ( ) => Array ( 10 ) ) ; for ( var j = 0 ; j < 1000 ; j ++ ) { for ( var k = 0 ; k < 10 ; k ++ ) { dp [ i ] [ j ] [ k ] = Array . from ( Array ( 2 ) , ( ) => Array ( 2 ) . fill ( - 1 ) ) ; } } } v = [ ] ; while ( x > 0 ) { v . push ( x % 10 ) ; x = parseInt ( x / 10 ) ; } v . reverse ( ) ; N = v . length ; } function fun ( pos , sum , st , check , f ) { if ( pos == N ) { return ( sum == 0 && check == 1 ) ? 1 : 0 ; } if ( dp [ pos ] [ sum ] [ st ] [ check ] [ f ] != - 1 ) return dp [ pos ] [ sum ] [ st ] [ check ] [ f ] ; var lmt = 9 ; if ( f == 0 ) lmt = v [ pos ] ; var ans = 0 ; for ( var digit = 0 ; digit <= lmt ; digit ++ ) { var nf = f ; var new_sum = ( sum + digit ) % K ; var new_check = check ; var new_st = st ; if ( f == 0 && digit < lmt ) nf = 1 ; if ( check == 0 && digit != 0 ) { new_st = digit ; new_check = 1 ; } if ( pos == N - 1 && new_st == digit ) continue ; ans += fun ( pos + 1 , new_sum , new_st , new_check , nf ) ; } return dp [ pos ] [ sum ] [ st ] [ check ] [ f ] = ans ; } function findCount ( L , R , K ) { init ( R ) ; var r_ans = fun ( 0 , 0 , 0 , 0 , 0 ) ; init ( L - 1 ) ; var l_ans = fun ( 0 , 0 , 0 , 0 , 0 ) ; document . write ( r_ans - l_ans ) ; } var L = 10 ; var R = 20 ; K = 2 ; findCount ( L , R , K ) ;

Index/key variables: check, f, i, j, k, pos, st, sum
Accumulator variables: ans, digit, i, j, k
Iterator variables: digit, i, j, k
Javascript program:
function minSumProd ( S , K ) { let len = S . length ; if ( K > len ) return - 1 ; if ( K == len ) return 0 ; let dp = new Array ( len ) ; let count_zero = 0 , count_one = 0 ; for ( let j = 0 ; j < len ; j ++ ) { ( S [ j ] == ' ' ) ? count_zero ++ : count_one ++ ; dp [ j ] = count_zero * count_one ; } for ( let i = 1 ; i < K ; i ++ ) { for ( let j = len ; j >= i ; j -- ) { count_zero = 0 , count_one = 0 ; dp [ j ] = Number . MAX_SAFE_INTEGER ; for ( let k = j ; k >= i ; k -- ) { ( S [ k ] == ' ' ) ? count_zero ++ : count_one ++ ; dp [ j ] = Math . min ( dp [ j ] , count_zero * count_one + dp [ k - 1 ] ) ; } } } return dp [ len - 1 ] ; } let S = " " ; let K = 5 ; document . write ( minSumProd ( S , K ) ) ;

Index/key variables: j, k
Accumulator variables: count_one, count_zero, i, j, k
Iterator variables: i, j, k
Javascript program:
function minPrizes ( arr , n ) { let dpLeft = new Array ( n ) ; dpLeft [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { dpLeft [ i ] = dpLeft [ i - 1 ] + 1 ; } else { dpLeft [ i ] = 1 ; } } let dpRight = new Array ( n ) ; dpRight [ n - 1 ] = 1 ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) { dpRight [ i ] = dpRight [ i + 1 ] + 1 ; } else { dpRight [ i ] = 1 ; } } let totalPrizes = 0 ; for ( let i = 0 ; i < n ; i ++ ) { totalPrizes += Math . max ( dpLeft [ i ] , dpRight [ i ] ) ; } document . write ( totalPrizes + " " ) ; return 0 ; } let arr = [ 1 , 2 , 2 , 3 ] ; let n = arr . length ; minPrizes ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, totalPrizes
Iterator variables: i
Javascript program:
function get_max_sum ( arr , n ) { var freq = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( freq . has ( arr [ i ] ) ) freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) else freq . set ( arr [ i ] , 1 ) } var dp = Array ( 100001 ) . fill ( 0 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = ( freq . has ( 0 ) ? freq . get ( 0 ) : 0 ) ; for ( var i = 2 ; i <= 100000 ; i ++ ) { dp [ i ] = Math . max ( dp [ i - 1 ] , dp [ i - 2 ] + i * ( freq . has ( i ) ? freq . get ( i ) : 0 ) ) ; } return dp [ 100000 ] ; } var N = 3 ; var arr = [ 2 , 2 , 3 ] ; document . write ( get_max_sum ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minFlip ( a ) { let n = a . length ; let dp = new Array ( n + 2 ) . fill ( 0 ) . map ( ( t ) => new Array ( 2 ) . fill ( 0 ) ) if ( a . charAt ( 0 ) == ' ' ) { dp [ 0 ] [ 0 ] = 1 ; } else dp [ 0 ] [ 0 ] = 0 ; if ( a . charAt ( 0 ) == ' ' ) dp [ 0 ] [ 1 ] = 1 ; else dp [ 0 ] [ 1 ] = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a . charAt ( i ) == ' ' ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 1 ; } else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ; if ( a . charAt ( i ) == ' ' ) { dp [ i ] [ 1 ] = Math . min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + 1 ; } else dp [ i ] [ 1 ] = Math . min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) ; } let answer = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { answer = Math . min ( answer , dp [ i ] [ 1 ] + dp [ n - 1 ] [ 0 ] - dp [ i ] [ 0 ] ) ; } return Math . min ( answer , dp [ n - 1 ] [ 0 ] ) ; } let s = " " ; document . write ( minFlip ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function LIIDS ( arr , N ) { let dp = [ ] ; let ans = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { dp [ i ] = 1 ; } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = i + i ; j <= N ; j += i ) { if ( j < arr . length && arr [ j ] > arr [ i ] ) { dp [ j ] = Math . max ( dp [ j ] , dp [ i ] + 1 ) ; } } ans = Math . max ( ans , dp [ i ] ) ; } return ans ; } let arr = [ 1 , 2 , 3 , 7 , 9 , 10 ] ; let N = arr . length ; document . write ( LIIDS ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPerfectSquare ( x ) { let sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function findSubarraySum ( arr , n , k ) { let prevSum = new Map ( ) ; let res = 0 ; let currsum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { currsum += arr [ i ] ; if ( currsum == K ) { res ++ ; } if ( prevSum . has ( currsum - K ) ) res += ( prevSum . get ( currsum - K ) ) ; prevSum . set ( currsum , prevSum . get ( currsum ) == null ? 1 : prevSum . get ( currsum ) + 1 ) ; } return res ; } function countSubarray ( arr , n , k ) { for ( let i = 0 ; i < n ; i ++ ) { if ( isPerfectSquare ( arr [ i ] ) ) { arr [ i ] = 1 ; } else { arr [ i ] = 0 ; } } document . write ( findSubarraySum ( arr , n , K ) ) ; } let arr = [ 2 , 4 , 9 , 2 ] ; let K = 2 ; let N = arr . length ; countSubarray ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: currsum, i, res
Iterator variables: i
Javascript program:
var mod = 1000000007 ; function calculate ( pos , left , k , L , R ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; var answer = 0 ; for ( var i = L ; i <= R ; i ++ ) { if ( i > left ) break ; answer = ( answer + calculate ( pos + 1 , left - i , k , L , R ) ) % mod ; } return answer ; } function countWaystoDivide ( n , k , L , R ) { return calculate ( 0 , n , k , L , R ) ; } var N = 12 ; var K = 3 ; var L = 1 ; var R = 5 ; document . write ( countWaystoDivide ( N , K , L , R ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function PossibleSum ( n , m , v , k ) { var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( k + 1 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= k ; j ++ ) { if ( dp [ i ] [ j ] == 1 ) { for ( var d = 0 ; d < m ; d ++ ) { if ( ( j + v [ i ] [ d ] ) <= k ) { dp [ i + 1 ] [ j + v [ i ] [ d ] ] = 1 ; } } } } } if ( dp [ n ] [ k ] == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } var N = 2 , M = 10 , K = 5 ; var arr = [ [ 4 , 0 , 15 , 3 , 2 , 20 , 10 , 1 , 5 , 4 ] , [ 4 , 0 , 10 , 3 , 2 , 25 , 4 , 1 , 5 , 4 ] ] ; PossibleSum ( N , M , arr , K ) ;

Index/key variables: d, i, j, k, n
Accumulator variables: d, i, j
Iterator variables: d, i, j
Javascript program:
dp = Array ( 1 << 20 ) . fill ( 0 ) ; function isprime ( n ) { if ( n == 1 ) return false ; for ( var i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } function solve ( arr , curr , mask , n ) { if ( isprime ( curr ) ) { if ( mask == ( 1 << n ) - 1 ) { return true ; } curr = 0 ; } if ( mask == ( 1 << n ) - 1 ) { if ( ! isprime ( curr ) ) { return false ; } } if ( dp [ mask ] ) return dp [ mask ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( ! ( mask & 1 << i ) ) { if ( solve ( arr , curr + arr [ i ] , mask 1 << i , n ) ) { return true ; } } } return dp [ mask ] = false ; } var arr = [ 3 , 6 , 7 , 13 ] var n = arr . length if ( solve ( arr , 0 , 0 , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, mask
Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = [ ] ; function maxSum ( i , subarr ) { if ( i >= subarr . length ) return 0 ; if ( dp [ i ] != - 1 ) return dp [ i ] ; dp [ i ] = Math . max ( maxSum ( i + 1 , subarr ) , subarr [ i ] + maxSum ( i + 2 , subarr ) ) ; return dp [ i ] ; } function Func ( arr ) { let subarr = arr ; subarr . pop ( ) ; dp = new Array ( subarr . length ) ; for ( let i = 0 ; i < subarr . length ; i ++ ) { dp [ i ] = - 1 ; } let max1 = maxSum ( 0 , subarr ) ; subarr = arr ; subarr . shift ( ) ; dp = [ ] ; dp = new Array ( subarr . length ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = - 1 ; } let max2 = maxSum ( 0 , subarr ) ; document . write ( Math . max ( max1 , max2 ) + " " ) ; } let arr = [ 1 , 2 , 3 , 1 ] ; Func ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var dim = 5 ; function createTable ( mtrx , k , p , dp ) { dp [ 0 ] [ 0 ] = mtrx [ 0 ] [ 0 ] ; for ( var j = 1 ; j < dim ; j ++ ) { dp [ 0 ] [ j ] = mtrx [ 0 ] [ j ] + dp [ 0 ] [ j - 1 ] ; } for ( var i = 1 ; i < dim ; i ++ ) { dp [ i ] [ 0 ] = mtrx [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ; } for ( var i = 1 ; i < dim ; i ++ ) { for ( var j = 1 ; j < dim ; j ++ ) { dp [ i ] [ j ] = mtrx [ i ] [ j ] + dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] ; } } } function countSubMatrixUtil ( dp , k , p ) { var count = 0 ; var subMatSum = 0 ; for ( var i = k - 1 ; i < dim ; i ++ ) { for ( var j = k - 1 ; j < dim ; j ++ ) { if ( i == ( k - 1 ) || j == ( k - 1 ) ) { if ( i == ( k - 1 ) && j == ( k - 1 ) ) { subMatSum = dp [ i ] [ j ] ; } else if ( i == ( k - 1 ) ) { subMatSum = dp [ i ] [ j ] - dp [ i ] [ j - k ] ; } else { subMatSum = dp [ i ] [ j ] - dp [ i - k ] [ j ] ; } } else { subMatSum = dp [ i ] [ j ] - dp [ i - k ] [ j ] - dp [ i ] [ j - k ] + dp [ i - k ] [ j - k ] ; } if ( subMatSum >= p ) { count ++ ; } } } return count ; } function countSubMatrix ( mtrx , k , p ) { var dp = Array . from ( Array ( dim ) , ( ) => Array ( dim ) ) ; for ( var i = 0 ; i < dim ; i ++ ) { for ( var j = 0 ; j < dim ; j ++ ) { dp [ i ] [ j ] = 0 ; } } createTable ( mtrx , k , p , dp ) ; return countSubMatrixUtil ( dp , k , p ) ; } var mtrx = [ [ 1 , 7 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 , 2 ] , [ 3 , 9 , 6 , 7 , 3 ] , [ 4 , 3 , 2 , 4 , 5 ] , [ 5 , 1 , 5 , 3 , 1 ] ] ; var k = 3 ; var p = 35 ; document . write ( countSubMatrix ( mtrx , k , p ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function canMakePaliQueries ( str , Q ) { let n = str . length ; let dp = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { dp [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( let i = 0 ; i < 26 ; i ++ ) { let currentChar = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; for ( let j = 0 ; j < n ; j ++ ) { if ( j == 0 ) { dp [ i ] [ j ] = ( str [ j ] == currentChar ) ? 1 : 0 ; } else { dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + ( ( str [ j ] == currentChar ) ? 1 : 0 ) ; } } } for ( let query of Q . values ( ) ) { let left = query [ 0 ] ; let right = query [ 1 ] ; let k = query [ 2 ] ; let unMatchedCount = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { let occurrence = dp [ i ] [ right ] - dp [ i ] [ left ] + ( str [ left ] == ( i + ' ' . charCodeAt ( 0 ) ) ? 1 : 0 ) ; if ( occurrence % 2 == 1 ) unMatchedCount ++ ; } let ans = unMatchedCount / 2 ; if ( ans <= k ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } let str = " " ; let Q = [ [ 1 , 5 , 3 ] , [ 5 , 7 , 0 ] , [ 8 , 11 , 3 ] , [ 3 , 10 , 5 ] , [ 0 , 9 , 5 ] ] ; canMakePaliQueries ( str , Q ) ;

Index/key variables: i, j, left, right
Accumulator variables: i, j, unMatchedCount
Iterator variables: i, j, query
Javascript program:
const MAX = 100 ; let dp = [ ] for ( let i = 0 ; i < 1000 ; i ++ ) { let temp1 = [ ] ; for ( let j = 0 ; j < MAX ; j ++ ) { let temp2 = [ ] ; for ( let k = 0 ; k < MAX ; k ++ ) { temp2 . push ( 0 ) } temp1 . push ( temp2 ) } dp . push ( temp1 ) } function productDigitSum ( x , y ) { let sumx = 0 ; while ( x ) { sumx += ( x % 10 ) ; x = Math . floor ( x / 10 ) ; } let sumy = 0 ; while ( y ) { sumy += ( y % 10 ) ; y = Math . floor ( y / 10 ) ; } return ( sumx * sumy ) ; } function solve ( arr , i , len , prev , n , k ) { if ( len == k ) return 0 ; if ( i == n ) return Number . MIN_SAFE_INTEGER ; if ( dp [ i ] [ len ] [ prev ] ) return dp [ i ] [ len ] [ prev ] ; let inc = 0 , exc = 0 ; if ( len & 1 ) { inc = productDigitSum ( arr [ prev ] , arr [ i ] ) + solve ( arr , i + 1 , len + 1 , 0 , n , k ) ; } else { inc = solve ( arr , i + 1 , len + 1 , i , n , k ) ; } exc = solve ( arr , i + 1 , len , prev , n , k ) ; return dp [ i ] [ len ] [ prev ] = Math . max ( inc , exc ) ; } let arr = [ 10 , 5 , 9 , 101 , 24 , 2 , 20 , 14 ] ; let n = arr . length ; let k = 6 ; document . write ( solve ( arr , 0 , 0 , 0 , n , k ) ) ;

Index/key variables: i, len, prev
Accumulator variables: i, j, k, sumx, sumy
Iterator variables: i, j, k
Javascript program:
let factors = new Array ( ) ; let dp = new Array ( 100005 ) ; for ( let i = 0 ; i < 100005 ; i ++ ) { factors . push ( new Array ( ) ) ; } function precompute ( ) { for ( let i = 1 ; i <= 100000 ; i ++ ) { for ( let j = i ; j <= 100000 ; j += i ) { factors [ j ] . push ( i ) ; } } } function solve ( arr , k , n ) { if ( k == n - 1 ) { return 0 ; } if ( k >= n ) { return Number . MAX_SAFE_INTEGER ; } if ( dp [ k ] ) { return dp [ k ] ; } let ans = Number . MAX_SAFE_INTEGER ; for ( let j of factors [ arr [ k ] ] ) { let res = solve ( arr , k + j , n ) ; if ( res != Number . MAX_SAFE_INTEGER ) { ans = Math . min ( ans , res + 1 ) ; } } return dp [ k ] = ans ; } precompute ( ) ; let arr = [ 2 , 8 , 16 , 55 , 99 , 100 ] ; let n = arr . length ; document . write ( solve ( arr , 0 , n ) ) ;

Index/key variables: j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var mod = parseInt ( 1e9 + 7 ) ; var dp ; function f ( n , k ) { if ( n < k ) return 0 ; if ( n == k ) return 1 ; if ( k == 1 ) return 1 ; if ( dp [ n ] [ k ] != - 1 ) return dp [ n ] [ k ] ; return dp [ n ] [ k ] = ( ( k * f ( n - 1 , k ) ) % mod + ( f ( n - 1 , k - 1 ) ) % mod ) % mod ; } function operation ( n ) { dp = Array ( n + 1 ) . fill ( ) . map ( ( ) => Array ( n + 1 ) . fill ( 0 ) ) ; for ( i = 0 ; i < n + 1 ; i ++ ) { for ( j = 0 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } var ans = 0 , fac = 1 ; for ( k = 1 ; k <= n ; k ++ ) { fac *= k ; ans = ( ans + ( fac * f ( n , k ) ) % mod ) % mod ; } return ans ; } var n = 5 ; document . write ( operation ( n ) + " " ) ;

Index/key variables: i, j, k, n
Accumulator variables: fac, i, j, k
Iterator variables: i, j, k
Javascript program:
function CountSets ( x , pos ) { if ( x <= 0 ) { if ( pos == 0 ) return 1 ; else return 0 ; } if ( pos == 0 ) return 1 ; var answer = CountSets ( x - 1 , pos ) + CountSets ( x - 2 , pos - 1 ) ; return answer ; } function CountOrderedSets ( n ) { var factorial = Array ( 10000 ) . fill ( 0 ) ; factorial [ 0 ] = 1 ; for ( i = 1 ; i < 10000 ; i ++ ) factorial [ i ] = factorial [ i - 1 ] * i ; var answer = 0 ; for ( i = 1 ; i <= n ; i ++ ) { var sets = CountSets ( n , i ) * factorial [ i ] ; answer = answer + sets ; } return answer ; } var N = 3 ; document . write ( CountOrderedSets ( N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function MaximumSum ( a , n ) { let dp = [ ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) dp . push ( Array ( n + 1 ) ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { for ( let j = 0 ; j < n + 1 ; j ++ ) dp [ i ] [ j ] = - 10000 ; } for ( let i = 0 ; i < n + 1 ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= i ; j ++ ) { let val = - 10000 ; if ( ( i - 2 >= 0 && dp [ i - 2 , j - 1 ] != - 10000 ) i - 2 < 0 ) { val = a [ i - 1 ] + ( i - 2 >= 0 ? dp [ i - 2 ] [ j - 1 ] : 0 ) ; } if ( i - 1 >= j ) { val = Math . max ( val , dp [ i - 1 ] [ j ] ) ; } dp [ i ] [ j ] = val ; } } return dp [ n ] [ n / 2 ] } let A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let N = A . length ; document . write ( MaximumSum ( A , N ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var kPowKform = new Set ( ) ; function func ( n ) { if ( n <= 0 ) return 0 ; if ( kPowKform . has ( n ) ) return 1 ; var answer = 0 ; var x = n ; while ( x > 0 ) { var d = x % 10 ; if ( d != 0 ) { if ( func ( n - d * d ) ) { answer = 1 ; break ; } } x = parseInt ( x / 10 ) ; } return answer ; } function canBeConverted ( n ) { if ( func ( n ) ) document . write ( " " ) ; else document . write ( " " ) ; } var N = 90 ; for ( var i = 1 ; i <= 8 ; i ++ ) { var val = 1 ; for ( var j = 1 ; j <= i ; j ++ ) val *= i ; kPowKform . add ( val ) ; } canBeConverted ( N ) ;

Accumulator variables: i, j, val
Iterator variables: i, j
Javascript program:
function check ( v ) { let digits = new Set ( ) ; for ( let i = 0 ; i < v . length ; i ++ ) { let d = new Set ( ) ; while ( v [ i ] ) { d . add ( v [ i ] % 10 ) ; v [ i ] = Math . floor ( v [ i ] / 10 ) ; } for ( let it of d ) { if ( digits . has ( it ) ) return false ; } for ( let it of d ) digits . add ( it ) ; } return true ; } function numberOfSubarrays ( a , n ) { let answer = 0 ; for ( let i = 1 ; i < ( 1 << n ) ; i ++ ) { let temp = new Array ( ) ; for ( let j = 0 ; j < n ; j ++ ) { if ( i & ( 1 << j ) ) temp . push ( a [ j ] ) ; } if ( check ( temp ) ) answer ++ ; } return answer ; } let N = 4 ; let A = [ 1 , 12 , 23 , 34 ] ; document . write ( numberOfSubarrays ( A , N ) ) ;

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, it, j