dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var dp = Array . from ( Array ( 5000 ) , ( ) => Array ( ( 1 << 10 ) + 5 ) ) ; function getmask ( val ) { var mask = 0 ; var prime = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 ] ; for ( var i = 0 ; i < 15 ; i ++ ) { if ( val % prime [ i ] == 0 ) { mask = mask | ( 1 << i ) ; } } return mask ; } function calculate ( pos , mask , a , n ) { if ( pos == n || mask == ( 1 << n - 1 ) ) return 0 ; if ( dp [ pos ] [ mask ] != - 1 ) return dp [ pos ] [ mask ] ; var size = 0 ; size = Math . max ( size , calculate ( pos + 1 , mask , a , n ) ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { var new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; size = Math . max ( size , 1 + calculate ( pos + 1 , new_mask , a , n ) ) ; } return dp [ pos ] [ mask ] = size ; } function largestSubset ( a , n ) { dp = Array . from ( Array ( 5000 ) , ( ) => Array ( ( 1 << 10 ) + 5 ) . fill ( - 1 ) ) ; return calculate ( 0 , 0 , a , n ) ; } var A = [ 2 , 3 , 13 , 5 , 14 , 6 , 7 , 11 ] ; var N = A . length ; document . write ( largestSubset ( A , N ) ) ;

Index/key variables: i, mask, pos
Accumulator variables: i
Iterator variables: i
Javascript program:
function MaximumSum ( a , n ) { var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( 2 ) . fill ( 0 ) ) ; dp [ 2 ] [ 1 ] = a [ 1 ] ; dp [ 2 ] [ 0 ] = a [ 0 ] ; for ( var i = 3 ; i < n + 1 ; i ++ ) { if ( i & 1 ) { var temp = ( [ dp [ i - 3 ] [ 1 ] , dp [ i - 3 ] [ 0 ] , dp [ i - 2 ] [ 1 ] , dp [ i - 2 ] [ 0 ] ] . reduce ( ( a , b ) => Math . max ( a , b ) ) ) ; dp [ i ] [ 1 ] = a [ i - 1 ] + temp ; dp [ i ] [ 0 ] = ( [ a [ i - 2 ] + dp [ i - 2 ] [ 0 ] , a [ i - 2 ] + dp [ i - 3 ] [ 1 ] , a [ i - 2 ] + dp [ i - 3 ] [ 0 ] , a [ i - 3 ] + dp [ i - 3 ] [ 0 ] ] . reduce ( ( a , b ) => Math . max ( a , b ) ) ) ; } else { dp [ i ] [ 1 ] = a [ i - 1 ] + ( [ dp [ i - 2 ] [ 1 ] , dp [ i - 2 ] [ 0 ] , dp [ i - 1 ] [ 0 ] ] . reduce ( ( a , b ) => Math . max ( a , b ) ) ) ; dp [ i ] [ 0 ] = a [ i - 2 ] + dp [ i - 2 ] [ 0 ] ; } } return Math . max ( dp [ n ] [ 1 ] , dp [ n ] [ 0 ] ) ; } var A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; var N = A . length ; document . write ( MaximumSum ( A , N ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function divisorGame ( N , A , dp ) { if ( N == 1 N == 3 ) return false ; if ( N == 2 ) return true ; if ( dp [ N ] [ A ] != - 1 ) return dp [ N ] [ A ] ; let ans = ( A == 1 ) ? 0 : 1 ; for ( let i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { if ( A ) ans |= divisorGame ( N - i , 0 , dp ) ; else ans &= divisorGame ( N - i , 1 , dp ) ; } } return dp [ N ] [ A ] = ans ; } let N = 3 ; let dp = [ ] ; for ( let i = 0 ; i < N + 1 ; i ++ ) { let temp = [ - 1 ] for ( let j = 0 ; j < 2 ; j ++ ) { temp . push ( [ - 1 ] ) } dp . push ( temp ) } if ( divisorGame ( N , 1 , dp ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: A, N
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countMountains ( a , n ) { var A = new Array ( n + 2 ) . fill ( 0 ) . map ( ( ) => new Array ( n + 2 ) . fill ( 0 ) ) ; var count = 0 ; for ( var i = 0 ; i < n + 2 ; i ++ ) { for ( var j = 0 ; j < n + 2 ; j ++ ) { if ( ( i == 0 ) || ( j == 0 ) || ( i == n + 1 ) || ( j == n + 1 ) ) { A [ i ] [ j ] = Number . MIN_VALUE ; } else { A [ i ] [ j ] = a [ i - 1 ] [ j - 1 ] ; } } } for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { if ( ( A [ i ] [ j ] > A [ i - 1 ] [ j ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j ] ) && ( A [ i ] [ j ] > A [ i ] [ j - 1 ] ) && ( A [ i ] [ j ] > A [ i ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i - 1 ] [ j - 1 ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i - 1 ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j - 1 ] ) ) { count ++ ; } } } return count ; } var a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; var n = 3 ; document . write ( countMountains ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function minimalLength ( a , n ) { var i , j , k ; var dp = Array ( n + 1 ) . fill ( Array ( n + 1 ) . fill ( - 1 ) ) ; var dp1 = Array ( n ) . fill ( 0 ) ; for ( var size = 1 ; size <= n ; size ++ ) { for ( i = 0 ; i < n - size + 1 ; i ++ ) { j = i + size - 1 ; if ( i == j ) dp [ i ] [ j ] = a [ i ] ; else { for ( k = i ; k < j ; k ++ ) { if ( dp [ i ] [ k ] != - 1 && dp [ i ] [ k ] == dp [ k + 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i ] [ k ] + 1 ; } } } } for ( i = 0 ; i < n ; i ++ ) dp1 [ i ] = 1000000000 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( dp [ j ] [ i ] != - 1 ) { if ( j == 0 ) dp1 [ i ] = 2 ; else dp1 [ i ] = Math . min ( dp1 [ i ] , dp1 [ j - 1 ] + 1 ) ; } } } return dp1 [ n - 1 ] ; } var n = 7 ; var a = [ 3 , 3 , 4 , 4 , 4 , 3 , 3 ] ; document . write ( minimalLength ( a , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, size
Iterator variables: i, j, k, size
Javascript program:
let dp = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { dp [ i ] = new Array ( 100 ) ; for ( let j = 0 ; j < 100 ; j ++ ) { dp [ i ] [ j ] = new Array ( 100 ) ; for ( let k = 0 ; k < 100 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } function MaximumScoreDP ( l , r , prefix_sum , num ) { if ( l > r ) return 0 ; if ( dp [ l ] [ r ] [ num ] != - 1 ) return dp [ l ] [ r ] [ num ] ; let current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= - 1 ; dp [ l ] [ r ] [ num ] = current_sum + Math . max ( MaximumScoreDP ( l + 1 , r , prefix_sum , num + 1 ) , MaximumScoreDP ( l , r - 1 , prefix_sum , num + 1 ) ) ; return dp [ l ] [ r ] [ num ] ; } function findMaxScore ( a , n ) { let prefix_sum = new Array ( n ) ; prefix_sum [ 0 ] = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + a [ i ] ; } return MaximumScoreDP ( 0 , n - 1 , prefix_sum , 1 ) ; } let n = 6 ; let A = [ 1 , 2 , 3 , 4 , 2 , 6 ] ; document . write ( findMaxScore ( A , n ) ) ;

Index/key variables: i, j, k, l, num, r
Accumulator variables: current_sum, i, j, k
Iterator variables: i, j, k
Javascript program:
var memo = Array . from ( Array ( 32 ) , ( ) => Array ( 2 ) ) ; for ( var i = 0 ; i < 32 ; i ++ ) { for ( var j = 0 ; j < 2 ; j ++ ) { memo [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; } } function dp ( pos , fl , pr , bin ) { if ( pos == bin . length ) return 1 ; if ( memo [ pos ] [ fl ] [ pr ] != - 1 ) return memo [ pos ] [ fl ] [ pr ] ; var val = 0 ; if ( bin [ pos ] == ' ' ) val = val + dp ( pos + 1 , fl , 0 , bin ) ; else if ( bin [ pos ] == ' ' ) val = val + dp ( pos + 1 , 1 , 0 , bin ) ; if ( pr == 0 ) { if ( fl == 1 ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } else if ( bin [ pos ] == ' ' ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } } return memo [ pos ] [ fl ] [ pr ] = val ; } function findIntegers ( num ) { var bin = " " ; while ( num > 0 ) { if ( num % 2 ) bin += " " ; else bin += " " ; num = parseInt ( num / 2 ) ; } bin = bin . split ( ' ' ) . reverse ( ) . join ( ' ' ) return dp ( 0 , 0 , 0 , bin ) ; } var N = 12 ; document . write ( findIntegers ( N ) ) ;

Index/key variables: fl, i, j, pos, pr
Accumulator variables: bin, i, j, val
Iterator variables: i, j
Javascript program:
function TotalWays ( n , s , k ) { let dp = new Array ( n ) ; dp . fill ( 0 ) ; dp [ s - 1 ] = 1 ; for ( let i = s ; i < n ; i ++ ) { let idx = Math . max ( s - 1 , i - k ) ; for ( let j = idx ; j < i ; j ++ ) { dp [ i ] += dp [ j ] ; } } return dp [ n - 1 ] ; } let n = 5 ; let k = 2 ; let s = 2 ; document . write ( " " + TotalWays ( n , s , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function max_sum ( arr , n , k ) { var dp = Array . from ( { length : n } , ( _ , i ) => 0 ) ; dp [ 0 ] = Math . max ( 0 , arr [ 0 ] ) ; var i = 1 ; while ( i < k ) { dp [ i ] = Math . max ( dp [ i - 1 ] , arr [ i ] ) ; i ++ ; } i = k ; while ( i < n ) { dp [ i ] = Math . max ( dp [ i - 1 ] , arr [ i ] + dp [ i - k ] ) ; i ++ ; } return dp [ n - 1 ] ; } var arr = [ 1 , 2 , - 2 , 4 , 3 , 1 ] ; var n = arr . length ; var k = 4 ; document . write ( max_sum ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
var MOD = 1000000007 ; function countStr ( N ) { var dp = Array . from ( Array ( N + 1 ) , ( ) => Array ( 3 ) . fill ( 0 ) ) ; dp [ 1 ] [ 0 ] = 1 ; dp [ 1 ] [ 1 ] = 1 ; dp [ 1 ] [ 2 ] = 0 ; for ( var i = 2 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] + dp [ i - 1 ] [ 2 ] ) % MOD ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] % MOD ; dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] % MOD ; } var ans = ( dp [ N ] [ 0 ] + dp [ N ] [ 1 ] + dp [ N ] [ 2 ] ) % MOD ; return ans ; } var N = 8 ; document . write ( countStr ( N ) ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function CountOfOddSum ( a , n ) { let dp = new Array ( n ) , cnt = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] = new Array ( 2 ) . fill ( 0 ) ; cnt [ i ] = new Array ( 2 ) . fill ( 0 ) ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { if ( a [ i ] [ j ] % 2 == 0 ) { cnt [ i ] [ 0 ] ++ ; } else { cnt [ i ] [ 1 ] ++ ; } } } dp [ 0 ] [ 0 ] = cnt [ 0 ] [ 0 ] , dp [ 0 ] [ 1 ] = cnt [ 0 ] [ 1 ] ; for ( let i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] * cnt [ i ] [ 0 ] + dp [ i - 1 ] [ 1 ] * cnt [ i ] [ 1 ] ) ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] * cnt [ i ] [ 1 ] + dp [ i - 1 ] [ 1 ] * cnt [ i ] [ 0 ] ) ; } return dp [ n - 1 ] [ 1 ] ; } let a = [ [ 1 , 2 ] , [ 3 , 6 ] ] ; let n = a . length ; let ans = CountOfOddSum ( a , n ) ; document . write ( ans ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function LongestConsSeq ( arr , N ) { let maxval = 1 ; for ( let i = 0 ; i < N ; i += 1 ) { maxval = Math . max ( maxval , arr [ i ] ) ; } let dp = new Array ( maxval + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; for ( let j = 0 ; j < 2 ; j ++ ) dp [ i ] [ j ] = 0 ; } let ans = 1 ; for ( let i = 0 ; i < N ; i += 1 ) { dp [ arr [ i ] ] [ 0 ] = ( 1 + dp [ arr [ i ] - 1 ] [ 0 ] ) ; if ( arr [ i ] >= 2 ) dp [ arr [ i ] ] [ 1 ] = Math . max ( 1 + dp [ arr [ i ] - 1 ] [ 1 ] , 2 + dp [ arr [ i ] - 2 ] [ 0 ] ) ; else dp [ arr [ i ] ] [ 1 ] = 1 ; ans = Math . max ( ans , dp [ arr [ i ] ] [ 1 ] ) ; } return ans ; } let arr = [ 2 , 1 , 4 , 5 ] ; let N = arr . length ; document . write ( LongestConsSeq ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isStepNum ( n ) { let prevDigit = - 1 ; while ( n > 0 ) { let curDigit = n % 10 ; if ( prevDigit == - 1 ) prevDigit = curDigit ; else { if ( Math . abs ( prevDigit - curDigit ) != 1 ) return false ; } prevDigit = curDigit ; n = parseInt ( n / 10 , 10 ) ; } return true ; } function displaySteppingNumbers ( n , m ) { for ( let i = n ; i <= m ; i ++ ) if ( isStepNum ( i ) ) document . write ( i + " " ) ; } let n = 0 , m = 21 ; displaySteppingNumbers ( n , m ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minCount ( K ) { let memo = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { memo [ i ] = Number . MAX_VALUE ; } memo [ 0 ] = 0 ; for ( let i = 1 ; i < 100 ; i ++ ) { memo [ i ] = Math . min ( memo [ i - 1 ] + 1 , memo [ i ] ) ; } for ( let i = 10 ; i < 100 ; i ++ ) { memo [ i ] = Math . min ( memo [ i - 10 ] + 1 , memo [ i ] ) ; } for ( let i = 25 ; i < 100 ; i ++ ) { memo [ i ] = Math . min ( memo [ i - 25 ] + 1 , memo [ i ] ) ; } let min_count = 0 ; while ( K > 0 ) { min_count += memo [ K % 100 ] ; K = parseInt ( K / 100 , 10 ) ; } return min_count ; } let K = 69 ; document . write ( minCount ( K ) ) ;

Index/key variables: i
Accumulator variables: i, min_count
Iterator variables: i
Javascript program:
var N = 10000 ; function count_required_sequence ( n , arr ) { var total_required_subsequence = 0 ; var total_n_required_subsequence = 0 ; var dp = Array . from ( Array ( N ) , ( ) => Array ( 2 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n ; i ++ ) { var turn_required = 0 ; for ( var j = - 1 ; j <= 1 ; j ++ ) turn_required += dp [ arr [ i ] + j ] [ 0 ] ; var required_end_i = ( total_required_subsequence + turn_required ) ; var n_required_end_i = ( 1 + total_n_required_subsequence - turn_required ) ; total_required_subsequence += required_end_i ; total_n_required_subsequence += n_required_end_i ; dp [ arr [ i ] ] [ 1 ] += required_end_i ; dp [ arr [ i ] ] [ 0 ] += n_required_end_i ; } return total_required_subsequence ; } var arr = [ 1 , 6 , 2 , 1 , 9 ] ; var n = arr . length ; document . write ( count_required_sequence ( n , arr ) + " " ) ;

Index/key variables: i
Accumulator variables: i, j, total_n_required_subsequence, total_required_subsequence, turn_required
Iterator variables: i, j
Javascript program:
var MAX_INDEX = 51 ; var MAX_SUM = 2505 ; var dp = Array ( MAX_INDEX ) . fill ( ) . map ( ( ) => Array ( MAX_SUM ) . fill ( ) . map ( ( ) => Array ( MAX_INDEX ) . fill ( 0 ) ) ) ; ; function waysutil ( index , sum , count , arr , K ) { if ( index < 0 ) { return 0 ; } if ( index == 0 ) { if ( count == 0 ) { return 0 ; } var remainder = sum % count ; if ( remainder != 0 ) { return 0 ; } var average = sum / count ; if ( average == K ) { return 1 ; } } if ( dp [ index ] [ sum ] [ count ] != - 1 ) { return dp [ index ] [ sum ] [ count ] ; } var dontpick = waysutil ( index - 1 , sum , count , arr , K ) ; var pick = waysutil ( index - 1 , sum + arr [ index ] , count + 1 , arr , K ) ; var total = pick + dontpick ; dp [ index ] [ sum ] [ count ] = total ; return total ; } function ways ( N , K , arr ) { var Arr = [ ] ; Arr . push ( - 1 ) ; for ( i = 0 ; i < N ; ++ i ) { Arr . push ( arr [ i ] ) ; } for ( i = 0 ; i < MAX_INDEX ; i ++ ) { for ( j = 0 ; j < MAX_SUM ; j ++ ) { for ( l = 0 ; l < MAX_INDEX ; l ++ ) { dp [ i ] [ j ] [ l ] = - 1 ; } } } var answer = waysutil ( N , 0 , 0 , Arr , K ) ; return answer ; } var arr = [ 3 , 6 , 2 , 8 , 7 , 6 , 5 , 9 ] ; var N = arr . length ; var K = 5 ; document . write ( ways ( N , K , arr ) ) ;

Index/key variables: count, i, index, j, l, sum
Accumulator variables: i, j, l
Iterator variables: i, j, l
Javascript program:
let arrSize = 51 ; let maxSum = 201 ; let MAX = 100 ; let inf = 999999 ; let dp = new Array ( arrSize ) ; let visit = new Array ( arrSize ) ; for ( let i = 0 ; i < arrSize ; i ++ ) { dp [ i ] = new Array ( maxSum ) ; visit [ i ] = new Array ( maxSum ) ; for ( let j = 0 ; j < maxSum ; j ++ ) { dp [ i ] [ j ] = 0 ; visit [ i ] [ j ] = 0 ; } } function RetClose ( a , b , s ) { if ( Math . abs ( a - s ) < Math . abs ( b - s ) ) return a ; else return b ; } function MinDiff ( i , sum , arr , n ) { if ( i == n ) return 0 ; if ( visit [ i ] [ sum + MAX ] > 0 ) return dp [ i ] [ sum + MAX ] ; visit [ i ] [ sum + MAX ] = 1 ; dp [ i ] [ sum + MAX ] = RetClose ( arr [ i ] + MinDiff ( i + 1 , sum + arr [ i ] , arr , n ) , MinDiff ( i + 1 , sum , arr , n ) , - 1 * sum ) ; return dp [ i ] [ sum + MAX ] ; } function FindClose ( arr , n ) { let ans = inf ; for ( let i = 1 ; i <= n ; i ++ ) ans = RetClose ( arr [ i - 1 ] + MinDiff ( i , arr [ i - 1 ] , arr , n ) , ans , 0 ) ; document . write ( ans ) ; } let arr = [ 25 , - 9 , - 10 , - 4 , - 7 , - 33 ] ; let n = arr . length ; FindClose ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 100000 ; let bitscount = 32 ; let prefix_count = new Array ( bitscount ) ; for ( let i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { prefix_count [ i ] [ j ] = 0 ; } } function findPrefixCount ( arr , n ) { for ( let i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( let j = 1 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefix_count [ i ] [ j ] += prefix_count [ i ] [ j - 1 ] ; } } } function rangeOr ( l , r ) { let ans = 0 ; for ( let i = 0 ; i < bitscount ; i ++ ) { let x ; if ( l == 0 ) x = prefix_count [ i ] [ r ] ; else x = prefix_count [ i ] [ r ] - prefix_count [ i ] [ l - 1 ] ; if ( x != 0 ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } let arr = [ 7 , 5 , 3 , 5 , 2 , 3 ] ; let n = arr . length ; findPrefixCount ( arr , n ) ; let queries = [ [ 1 , 3 ] , [ 4 , 5 ] ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) document . write ( rangeOr ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ;

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function palindromeSubStrs ( s ) { let dp = new Array ( s . length ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < dp . length ; i ++ ) { for ( let j = 0 ; j < dp . length ; j ++ ) { dp [ i ] [ j ] = 0 ; } } let st , end , i , len ; let m = new Map ( ) ; for ( i = 0 ; i < s . length ; i ++ ) { dp [ i ] [ i ] = 1 ; m . set ( s . substr ( i , i + 1 ) , true ) ; } for ( i = 0 ; i < s . length - 1 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { dp [ i ] [ i + 1 ] = 1 ; m . set ( s . substr ( i , i + 2 ) , true ) ; } else dp [ i ] [ i + 1 ] = 0 ; } for ( len = 3 ; len <= s . length ; len ++ ) { for ( st = 0 ; st <= s . length - len ; st ++ ) { end = st + len - 1 ; if ( s [ st ] == s [ end ] && dp [ st + 1 ] [ end - 1 ] == 1 ) { dp [ st ] [ end ] = 1 ; m . set ( s . substr ( st , end + 1 ) , true ) ; } else dp [ st ] [ end ] = 0 ; } } return m . size ; } let s = " " ; document . write ( palindromeSubStrs ( s ) ) ;

Index/key variables: end, i, j, st
Accumulator variables: i, j, len, st
Iterator variables: i, j, len, st
Javascript program:
let n = 4 , m = 4 ; let arr = [ [ 1 , 0 , 3 , - 1 ] , [ 3 , 5 , 1 , - 2 ] , [ - 2 , 0 , 1 , 1 ] , [ 2 , 1 , - 1 , 1 ] ] ; let cache = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { cache [ i ] = new Array ( 5 ) ; for ( let j = 0 ; j < 5 ; j ++ ) { cache [ i ] [ j ] = new Array ( 5 ) ; for ( let k = 0 ; k < 5 ; k ++ ) { cache [ i ] [ j ] [ k ] = - 1 ; } } } function sum ( i1 , j1 , i2 , j2 ) { if ( i1 == i2 && j1 == j2 ) { return arr [ i1 ] [ j1 ] ; } return arr [ i1 ] [ j1 ] + arr [ i2 ] [ j2 ] ; } function maxSumPath ( i1 , j1 , i2 ) { let j2 = i1 + j1 - i2 ; if ( i1 >= n i2 >= n j1 >= m j2 >= m ) { return 0 ; } if ( cache [ i1 ] [ j1 ] [ i2 ] != - 1 ) { return cache [ i1 ] [ j1 ] [ i2 ] ; } let ans = Number . MIN_VALUE ; ans = Math . max ( ans , maxSumPath ( i1 + 1 , j1 , i2 + 1 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = Math . max ( ans , maxSumPath ( i1 , j1 + 1 , i2 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = Math . max ( ans , maxSumPath ( i1 , j1 + 1 , i2 + 1 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = Math . max ( ans , maxSumPath ( i1 + 1 , j1 , i2 ) + sum ( i1 , j1 , i2 , j2 ) ) ; cache [ i1 ] [ j1 ] [ i2 ] = ans ; return ans ; } document . write ( maxSumPath ( 0 , 0 , 0 ) ) ;

Index/key variables: i, i1, i2, j, j1, j2, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function BellmanFord ( graph , V , E , src ) { var dis = Array ( V ) . fill ( 1000000000 ) ; dis [ src ] = 0 ; for ( var i = 0 ; i < V - 1 ; i ++ ) { for ( var j = 0 ; j < E ; j ++ ) { if ( ( dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] ) < dis [ graph [ j ] [ 1 ] ] ) dis [ graph [ j ] [ 1 ] ] = dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] ; } } for ( var i = 0 ; i < E ; i ++ ) { var x = graph [ i ] [ 0 ] ; var y = graph [ i ] [ 1 ] ; var weight = graph [ i ] [ 2 ] ; if ( ( dis [ x ] != 1000000000 ) && ( dis [ x ] + weight < dis [ y ] ) ) document . write ( " " + " " ) ; } document . write ( " " ) ; for ( var i = 0 ; i < V ; i ++ ) document . write ( i + " " + dis [ i ] + " " ) ; } var graph = [ [ 0 , 1 , - 1 ] , [ 0 , 2 , 4 ] , [ 1 , 2 , 3 ] , [ 1 , 3 , 2 ] , [ 1 , 4 , 2 ] , [ 3 , 2 , 5 ] , [ 3 , 1 , 1 ] , [ 4 , 3 , - 3 ] ] ; BellmanFord ( graph , V , E , 0 ) ;

Index/key variables: i, j, src, x, y
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var m = [ ] ; var a = [ ] ; var x = [ ] ; var g = [ ] ; var ans = 0 ; function dfs ( u , p ) { for ( var v of g [ u ] ) { if ( v != p ) { dfs ( v , u ) ; for ( var i = 0 ; i < 22 ; i ++ ) a [ u ] [ i ] += a [ v ] [ i ] ; } } var pp = 0 ; for ( var i = 0 ; i < 22 ; i ++ ) { if ( ! ( ( a [ u ] [ i ] > 0 && x [ i ] - a [ u ] [ i ] > 0 ) || ( a [ u ] [ i ] == 0 && x [ i ] == 0 ) ) ) { pp = 1 ; break ; } } if ( pp == 0 ) ans ++ ; } var n = 4 ; g = Array . from ( Array ( n + 1 ) , ( ) => Array ( ) . fill ( 0 ) ) ; m = Array ( n + 1 ) ; m [ 1 ] = 1 ; m [ 2 ] = 3 ; m [ 3 ] = 2 ; m [ 4 ] = 3 ; a = Array . from ( Array ( n + 1 ) , ( ) => Array ( 22 ) . fill ( 0 ) ) ; x = Array ( 22 ) . fill ( 0 ) ; for ( var i = 1 ; i <= n ; i ++ ) { g [ i ] = [ ] ; var y = m [ i ] ; var k = 0 ; while ( y != 0 ) { var p = y % 2 ; if ( p == 1 ) { x [ k ] ++ ; a [ i ] [ k ] ++ ; } y = parseInt ( y / 2 ) ; k ++ ; } } g [ 1 ] . push ( 2 ) ; g [ 2 ] . push ( 1 ) ; g [ 1 ] . push ( 3 ) ; g [ 3 ] . push ( 1 ) ; g [ 1 ] . push ( 4 ) ; g [ 4 ] . push ( 1 ) ; dfs ( 1 , 0 ) ; document . write ( ans ) ;

Index/key variables: i, k, u, v
Accumulator variables: ans, i, k
Iterator variables: i, v
Javascript program:
let maxn = 16 ; function precompute ( ) { let dp = new Array ( maxn ) ; let arr = [ 4 , 6 , 9 ] ; for ( let i = 0 ; i < maxn ; i ++ ) dp [ i ] = - 1 ; dp [ 0 ] = 0 ; for ( let i = 1 ; i < maxn ; ++ i ) { for ( let k = 0 ; k < 3 ; k ++ ) { let j = arr [ k ] ; if ( i >= j && dp [ i - j ] != - 1 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - j ] + 1 ) ; } } } return dp ; } function Maximum_Summands ( dp , n ) { if ( n < maxn ) return dp [ n ] ; else { let t = parseInt ( ( n - maxn ) / 4 , 10 ) + 1 ; return t + dp [ n - 4 * t ] ; } } let n = 12 ; $n = 12 ; let dp = precompute ( ) ; document . write ( Maximum_Summands ( dp , n ) ) ;

Index/key variables: i, k, n
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function min ( a , b ) { return ( a > b ) ? b : a ; } function minCostJumpsDP ( A , k ) { let size = A . length ; let x = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) x [ i ] = Number . MAX_VALUE ; x [ 0 ] = 0 ; for ( let i = 0 ; i < size ; i ++ ) { for ( let j = i + 1 ; j < i + k + 1 && j < size ; j ++ ) { x [ j ] = min ( x [ j ] , x [ i ] + Math . abs ( A [ i ] - A [ j ] ) ) ; } } return x [ size - 1 ] ; } let input = [ 83 , 26 , 37 , 35 , 33 , 35 , 56 ] ; document . write ( minCostJumpsDP ( input , 3 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let diameter = - 1 ; function dfs ( node , parent , dp1 , dp2 , adj ) { let firstmax = - 1 ; let secondmax = - 1 ; for ( let i = 0 ; i < adj [ node ] . length ; ++ i ) { if ( adj [ node ] [ i ] == parent ) continue ; dfs ( adj [ node ] [ i ] , node , dp1 , dp2 , adj ) ; if ( firstmax == - 1 ) { firstmax = dp1 [ adj [ node ] [ i ] ] ; } else if ( dp1 [ adj [ node ] [ i ] ] >= firstmax ) { secondmax = firstmax ; firstmax = dp1 [ adj [ node ] [ i ] ] ; } else if ( dp1 [ adj [ node ] [ i ] ] > secondmax ) { secondmax = dp1 [ adj [ node ] [ i ] ] ; } } dp1 [ node ] = 1 ; dp1 [ node ] += firstmax ; if ( secondmax != - 1 ) dp2 [ node ] = 1 + firstmax + secondmax ; return Math . max ( dp1 [ node ] , dp2 [ node ] ) ; } let n = 5 ; let adj = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { adj [ i ] = [ ] ; } adj [ 1 ] . push ( 2 ) ; adj [ 2 ] . push ( 1 ) ; adj [ 1 ] . push ( 3 ) ; adj [ 3 ] . push ( 1 ) ; adj [ 2 ] . push ( 4 ) ; adj [ 4 ] . push ( 2 ) ; adj [ 2 ] . push ( 5 ) ; adj [ 5 ] . push ( 2 ) ; let dp1 = new Array ( n + 1 ) ; let dp2 = new Array ( n + 1 ) ; dp1 . fill ( 0 ) ; dp2 . fill ( 0 ) ; document . write ( " " + dfs ( 1 , 1 , dp1 , dp2 , adj ) ) ;

Index/key variables: i, node
Accumulator variables: i
Iterator variables: i