dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isMatch ( text , pattern ) { if ( text == null pattern == null ) { return false ; } let N = text . length ; let M = pattern . length ; let dp = new Array ( N + 1 ) ; for ( let i = 0 ; i <= N ; i ++ ) { dp [ i ] = new Array ( M + 1 ) ; for ( let j = 0 ; j <= M ; j ++ ) { dp [ i ] [ j ] = false ; } } dp [ 0 ] [ 0 ] = true ; for ( let i = 0 ; i < M ; i ++ ) { if ( pattern [ i ] == ' ' && dp [ 0 ] [ i - 1 ] ) { dp [ 0 ] [ i + 1 ] = true ; } } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( pattern [ j ] == ' ' ) { dp [ i + 1 ] [ j + 1 ] = dp [ i ] [ j ] ; } if ( pattern [ j ] == text [ i ] ) { dp [ i + 1 ] [ j + 1 ] = dp [ i ] [ j ] ; } if ( pattern [ j ] == ' ' ) { if ( pattern [ j - 1 ] != text [ i ] && pattern [ j - 1 ] != ' ' ) { dp [ i + 1 ] [ j + 1 ] = dp [ i + 1 ] [ j - 1 ] ; } else { dp [ i + 1 ] [ j + 1 ] = ( dp [ i + 1 ] [ j ] dp [ i ] [ j + 1 ] dp [ i + 1 ] [ j - 1 ] ) ; } } } } return dp [ N ] [ M ] ; } let text = " " ; let pattern = " " ; if ( isMatch ( text , pattern ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function waysToPaint ( n ) { var same = 6 ; var diff = 6 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { var sameTmp = 3 * same + 2 * diff ; var diffTmp = 2 * same + 2 * diff ; same = sameTmp ; diff = diffTmp ; } document . write ( same + diff ) ; } var N = 2 ; waysToPaint ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let k , n , goal ; let dp ; let bits = [ ] ; function minimumIncompatibility ( A , K ) { n = A . length ; k = K ; goal = Math . floor ( n / k ) ; let map = new Map ( ) ; for ( let i = 0 ; i < A . length ; i ++ ) { if ( ! map . has ( A [ i ] ) ) map . set ( A [ i ] , 0 ) ; map . set ( A [ i ] , map . get ( A [ i ] ) + 1 ) ; if ( map . get ( A [ i ] ) > k ) return - 1 ; } let state = ( 1 << n ) - 1 ; for ( let i = 0 ; i <= state ; i ++ ) { if ( i . toString ( 2 ) . split ( ' ' ) . join ( ' ' ) . length == goal ) bits . push ( i ) ; } dp = new Array ( 1 << n ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( k ) ; for ( let j = 0 ; j < k ; j ++ ) dp [ i ] [ j ] = - 1 ; } return dfs ( A , state , 0 ) ; } function dfs ( A , state , index ) { if ( index >= k ) { return 0 ; } let res = 1000 ; if ( dp [ state ] [ index ] != - 1 ) { return dp [ state ] [ index ] ; } for ( let bit = 0 ; bit < bits . length ; bit ++ ) { if ( bits [ bit ] . toString ( 2 ) . split ( ' ' ) . join ( ' ' ) . length == goal ) { let newstate = state ; let mn = 100 , mx = - 1 ; let visit = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { visit [ i ] = false ; } let good = true ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( bits [ bit ] & ( 1 << j ) ) != 0 ) { if ( visit [ A [ j ] ] == true || ( state & ( 1 << j ) ) == 0 ) { good = false ; break ; } visit [ A [ j ] ] = true ; newstate = newstate ^ ( 1 << j ) ; mx = Math . max ( mx , A [ j ] ) ; mn = Math . min ( mn , A [ j ] ) ; } } if ( good ) { res = Math . min ( res , mx - mn + dfs ( A , newstate , index + 1 ) ) ; } } } dp [ state ] [ index ] = res ; return res ; } let arr = [ 1 , 2 , 1 , 4 ] ; let K = 2 ; document . write ( minimumIncompatibility ( arr , K ) )

Index/key variables: bit, i, index, j, state
Accumulator variables: bit, i, j
Iterator variables: bit, i, j
Boolean variables: good
Javascript program:
function FindMaxS ( X , Y , Z , n , A , B , C ) { if ( X < 0 Y < 0 Z < 0 ) return - 1000000000 ; if ( n < 0 ) return 0 ; var ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 , A , B , C ) ; var ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 , A , B , C ) ; var co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 , A , B , C ) ; var no = FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ; var maximum = Math . max ( ch , Math . max ( ca , Math . max ( co , no ) ) ) ; return maximum ; } var X = 1 ; var Y = 1 ; var Z = 1 ; var A = [ 10 , 0 , 5 ] ; var B = [ 5 , 10 , 0 ] ; var C = [ 0 , 5 , 10 ] ; var n = B . length ; document . write ( FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ) ;

Index/key variables: n
Javascript program:
function replace ( arr ) { let n = arr . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 == 0 && arr [ j ] % 2 != 0 ) { let tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } else if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 != 0 && arr [ j ] % 2 == 0 ) { let tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } } } for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = Math . abs ( arr [ i ] ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 3 , 2 , 4 ] ; replace ( arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minimumCostToMergeK ( arr , K , N ) { if ( ( N - 1 ) % ( K - 1 ) != 0 ) { return - 1 ; } var prefixSum = Array ( N + 1 ) . fill ( 0 ) ; for ( i = 1 ; i < ( N + 1 ) ; i ++ ) { prefixSum [ i ] = ( prefixSum [ i - 1 ] + arr [ i - 1 ] ) ; } var dp = Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) dp [ i ] = Array ( N ) . fill ( 0 ) ; for ( L = K ; L < ( N + 1 ) ; L ++ ) { for ( i = 0 ; i < ( N - L + 1 ) ; i ++ ) { var j = i + L - 1 ; if ( L > K ) { var temp = Number . MAX_VALUE ; for ( x = i ; x < j ; x += K - 1 ) { temp = Math . min ( temp , dp [ i ] [ x ] + dp [ x + 1 ] [ j ] ) ; } dp [ i ] [ j ] = temp ; } if ( ( L - 1 ) % ( K - 1 ) == 0 ) { dp [ i ] [ j ] += ( prefixSum [ j + 1 ] - prefixSum [ i ] ) ; } } } return dp [ 0 ] [ N - 1 ] ; } var arr = [ 3 , 5 , 1 , 2 , 6 ] ; var K = 3 ; var N = arr . length ; document . write ( minimumCostToMergeK ( arr , K , N ) ) ;

Index/key variables: i, j, x
Accumulator variables: L, i, x
Iterator variables: L, i, x
Javascript program:
let N = 8 ; function check ( memo , i , j , A ) { if ( i == N - 1 ) return 1 ; if ( memo [ i ] [ j ] != - 1 ) return memo [ i ] [ j ] ; let flag = 0 , k ; for ( k = i + 1 ; k < N ; k ++ ) { if ( A [ k ] - A [ i ] > j + 1 ) break ; if ( A [ k ] - A [ i ] >= j - 1 && A [ k ] - A [ i ] <= j + 1 ) flag = check ( memo , k , A [ k ] - A [ i ] , A ) ; if ( flag != 0 ) break ; } memo [ i ] [ j ] = flag ; return memo [ i ] [ j ] ; } function checkEndReach ( A , K ) { let memo = new Array ( N ) ; for ( var i = 0 ; i < memo . length ; i ++ ) { memo [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { memo [ i ] [ j ] = - 1 ; } } let startIndex = 1 ; if ( check ( memo , startIndex , K , A ) != 0 ) document . write ( " " ) ; else document . write ( " " ) ; } let A = [ 0 , 1 , 3 , 5 , 6 , 8 , 12 , 17 ] ; let K = 1 ; checkEndReach ( A , K ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function Max_Sum ( arr , K , N ) { var dp = Array ( N + 1 ) . fill ( 0 ) ; var prefix = Array ( N + 1 ) ; prefix [ 0 ] = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ] ; } dp [ 0 ] = 0 ; for ( var i = 1 ; i < K ; i ++ ) { dp [ i ] = prefix [ i ] ; } for ( var i = K ; i <= N ; ++ i ) { for ( var j = i ; j >= ( i - K + 1 ) ; j -- ) { dp [ i ] = Math . max ( dp [ i ] , dp [ j - 1 ] + prefix [ i ] - prefix [ j ] ) ; } } return dp [ N ] ; } var arr = [ 4 , 12 , 22 , 18 , 34 , 12 , 25 ] ; var N = arr . length ; var K = 5 ; document . write ( Max_Sum ( arr , K , N ) ) ;

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function binomialCoeff ( n , k ) { let C = new Array ( n + 1 ) ; for ( let i = 0 ; i < C . length ; i ++ ) { C [ i ] = new Array ( 2 ) ; } let i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } function waysToSplitN ( k , n , P ) { let new_N = n - k * P ; return binomialCoeff ( new_N + k - 1 , new_N ) ; } let K = 3 , N = 8 , P = 2 ; document . write ( waysToSplitN ( K , N , P ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function solve ( a ) { let n = a . length ; let dp = new Array ( n + 1 ) . fill ( 0 ) ; let val = new Array ( n + 1 ) . fill ( 0 ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let sum = a [ i ] ; let j = i ; while ( j + 1 < n && sum < val [ j + 1 ] ) { j ++ ; sum += a [ j ] ; } dp [ i ] = ( j - i ) + dp [ j + 1 ] ; val [ i ] = sum ; } return dp [ 0 ] ; } let arr = [ 1 , 5 , 3 , 9 , 1 ] ; document . write ( solve ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i
Javascript program:
function distinctSimilarSubstrings ( str ) { var n = str . length ; if ( n <= 1 ) { return 0 ; } var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( n + 1 ) . fill ( 0 ) ) ; var substrings = new Set ( ) ; for ( var j = n - 1 ; j >= 0 ; j -- ) { for ( var i = j - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == str [ j ] ) { dp [ i ] [ j ] = dp [ i + 1 ] [ j + 1 ] + 1 ; } else { dp [ i ] [ j ] = 0 ; } if ( dp [ i ] [ j ] >= j - i ) { substrings . add ( str . substring ( i , j ) ) ; } } } return substrings . size ; } var str = " " ; document . write ( distinctSimilarSubstrings ( str ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAXN = 100 ; let INF = 1e7 ; let dis = new Array ( MAXN ) ; let Next = new Array ( MAXN ) ; for ( let i = 0 ; i < MAXN ; i ++ ) { dis [ i ] = new Array ( MAXN ) ; Next [ i ] = new Array ( MAXN ) ; } function initialise ( V , graph ) { for ( let i = 0 ; i < V ; i ++ ) { for ( let j = 0 ; j < V ; j ++ ) { dis [ i ] [ j ] = graph [ i ] [ j ] ; if ( graph [ i ] [ j ] == INF ) Next [ i ] [ j ] = - 1 ; else Next [ i ] [ j ] = j ; } } } function constructPath ( u , v ) { if ( Next [ u ] [ v ] == - 1 ) return null ; let path = [ ] ; path . push ( u ) ; while ( u != v ) { u = Next [ u ] [ v ] ; path . push ( u ) ; } return path ; } function floydWarshall ( V ) { for ( let k = 0 ; k < V ; k ++ ) { for ( let i = 0 ; i < V ; i ++ ) { for ( let j = 0 ; j < V ; j ++ ) { if ( dis [ i ] [ k ] == INF dis [ k ] [ j ] == INF ) continue ; if ( dis [ i ] [ j ] > dis [ i ] [ k ] + dis [ k ] [ j ] ) { dis [ i ] [ j ] = dis [ i ] [ k ] + dis [ k ] [ j ] ; Next [ i ] [ j ] = Next [ i ] [ k ] ; } } } } } function printPath ( path ) { let n = path . length ; for ( let i = 0 ; i < n - 1 ; i ++ ) document . write ( path [ i ] + " " ) ; document . write ( path [ n - 1 ] + " " ) ; } let V = 4 ; let graph = [ [ 0 , 3 , INF , 7 ] , [ 8 , 0 , 2 , INF ] , [ 5 , INF , 0 , 1 ] , [ 2 , INF , INF , 0 ] ] ; initialise ( V , graph ) ; floydWarshall ( V ) ; let path ; document . write ( " " ) ; path = constructPath ( 1 , 3 ) ; printPath ( path ) ; document . write ( " " ) ; path = constructPath ( 0 , 2 ) ; printPath ( path ) ; document . write ( " " ) ; path = constructPath ( 3 , 2 ) ; printPath ( path ) ;

Index/key variables: i, j, k, u, v
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let vp = new Array ( 2009 ) ; function finding_factors ( n ) { let i , a ; for ( i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i == n ) { vp [ n ] . push ( i ) ; } else { vp [ n ] . push ( i ) ; vp [ n ] . push ( n / i ) ; } } } } function countSeq ( N , K ) { let i , j , k ; let dp = new Array ( 109 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( i = 1 ; i <= N ; i ++ ) { finding_factors ( i ) ; dp [ 0 ] [ i ] = 0 ; dp [ 1 ] [ i ] = 1 ; } for ( i = 2 ; i <= K ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { let sum = 0 ; for ( k = 0 ; k < vp [ j ] . length ; k ++ ) { sum = ( sum + dp [ i - 1 ] [ vp [ j ] [ k ] ] ) ; } dp [ i ] [ j ] = sum ; } } let ans = 0 ; for ( j = 1 ; j <= N ; j ++ ) { ans = ( ans + dp [ K ] [ j ] ) ; } return ans ; } let N , K ; N = 3 ; K = 2 ; for ( let i = 0 ; i < vp . length ; i ++ ) vp [ i ] = [ ] ; document . write ( countSeq ( N , K ) + " " ) ;

Index/key variables: K, i, j, k, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function MAX_value ( arr ) { var row = arr . length ; var col = arr [ 0 ] . length ; var dp = Array ( row ) ; for ( var i = 0 ; i < row ; i ++ ) dp [ i ] = Array ( col ) . fill ( 0 ) ; var i = 0 , j = 0 ; var c = arr [ 0 ] [ 0 ] , p = 0 ; var d = row ; for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( c < arr [ i ] [ j ] ) { c = arr [ i ] [ j ] ; } if ( i == 0 j == 0 ) { dp [ i ] [ j ] = 1 ; } else { if ( arr [ i - 1 ] [ j - 1 ] == arr [ i ] [ j ] && arr [ i - 1 ] [ j ] == arr [ i ] [ j ] && arr [ i ] [ j - 1 ] == arr [ i ] [ j ] ) { dp [ i ] [ j ] = Math . min ( dp [ i - 1 ] [ j - 1 ] , Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ) + 1 ; } else { dp [ i ] [ j ] = 1 ; } } } } for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( arr [ i ] [ j ] == c ) { if ( p < dp [ i ] [ j ] ) { p = dp [ i ] [ j ] ; } } } } return p * p ; } var arr = [ [ 9 , 9 , 3 , 3 , 4 , 4 ] , [ 9 , 9 , 7 , 7 , 7 , 4 ] , [ 1 , 2 , 7 , 7 , 7 , 4 ] , [ 4 , 4 , 7 , 7 , 7 , 4 ] , [ 5 , 5 , 1 , 1 , 2 , 7 ] , [ 2 , 7 , 1 , 1 , 4 , 4 ] ] ; document . write ( MAX_value ( arr ) + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function smallestNum ( n ) { res = 1 ; for ( var i = 2 ; ; i *= 2 ) { var length = parseInt ( Math . log ( i ) / Math . log ( 10 ) ) + 1 ; if ( length == n ) return parseInt ( Math . log ( i ) / Math . log ( 2 ) ) ; } } n = 4 ; document . write ( smallestNum ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 100005 ; let level = new Array ( N ) ; level . fill ( 0 ) ; let LG = 20 ; let dp = new Array ( LG ) ; for ( let i = 0 ; i < LG ; i ++ ) { dp [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { dp [ i ] [ j ] = 0 ; } } let mx = new Array ( LG ) ; for ( let i = 0 ; i < LG ; i ++ ) { mx [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { mx [ i ] [ j ] = 0 ; } } let v = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { v . push ( [ ] ) ; } let n = 0 ; function dfs_lca ( a , par , lev ) { dp [ 0 ] [ a ] = par ; level [ a ] = lev ; for ( let i = 0 ; i < 2 ; i ++ ) { if ( v [ a ] [ 0 ] == par ) continue ; mx [ 0 ] [ v [ a ] [ 0 ] ] = v [ a ] [ 1 ] ; dfs_lca ( v [ a ] [ 0 ] , a , lev + 1 ) ; } } function find_ancestor ( ) { for ( let i = 1 ; i < 16 ; i ++ ) { for ( let j = 1 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ; mx [ i ] [ j ] = Math . max ( mx [ i - 1 ] [ j ] , mx [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ) ; } } } function getMax ( a , b ) { if ( level [ b ] < level [ a ] ) { let temp = a ; a = b ; b = temp ; } let ans = 0 ; let diff = level [ b ] - level [ a ] ; while ( diff > 0 ) { let log = parseInt ( Math . log ( diff ) / Math . log ( 2 ) , 10 ) ; ans = Math . max ( ans , mx [ log ] [ b ] ) ; b = dp [ log ] [ b ] ; diff -= ( 1 << log ) ; } while ( a == b ) { i = parseInt ( Math . log ( level [ a ] ) / Math . log ( 2 ) , 10 ) ; while ( i > 0 && dp [ i ] [ a ] == dp [ i ] [ b ] ) { i -= 1 ; } ans = Math . max ( ans , mx [ i ] [ a ] ) ; ans = Math . max ( ans , mx [ i ] [ b ] ) ; a = dp [ i ] [ a ] ; b = dp [ i ] [ b ] ; } return ans * 2 + 1 ; } function compute_lca ( ) { dfs_lca ( 1 , 0 , 0 ) ; find_ancestor ( ) ; } n = 5 ; v [ 1 ] . push ( 2 ) ; v [ 1 ] . push ( 2 ) ; v [ 2 ] . push ( 1 ) ; v [ 2 ] . push ( 2 ) ; v [ 1 ] . push ( 3 ) ; v [ 1 ] . push ( 5 ) ; v [ 3 ] . push ( 1 ) ; v [ 3 ] . push ( 5 ) ; v [ 3 ] . push ( 4 ) ; v [ 3 ] . push ( 3 ) ; v [ 4 ] . push ( 3 ) ; v [ 4 ] . push ( 4 ) ; v [ 3 ] . push ( 5 ) ; v [ 3 ] . push ( 1 ) ; v [ 5 ] . push ( 3 ) ; v [ 5 ] . push ( 1 ) ; compute_lca ( ) ; let queries = [ [ 3 , 5 ] , [ 2 , 3 ] , [ 2 , 4 ] ] ; let q = 3 ; for ( let i = 0 ; i < q ; i ++ ) { let max_edge = getMax ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ; document . write ( max_edge + " " ) ; }

Index/key variables: a, b, i, j, log
Accumulator variables: diff, i, j
Iterator variables: i, j
Javascript program:
function countDecodingDP ( digits , n ) { if ( digits [ 0 ] == ' ' ) return 0 ; var count0 = 1 , count1 = 1 , count2 ; for ( var i = 2 ; i <= n ; i ++ ) { count2 = ( ( digits [ i - 1 ] != ' ' ) * count1 ) + ( ( digits [ i - 2 ] == ' ' ) || ( digits [ i - 2 ] == ' ' && digits [ i - 1 ] < ' ' ) ) * count0 ; count0 = count1 ; count1 = count2 ; } return count1 ; } var digits = " " ; var n = digits . length ; document . write ( countDecodingDP ( digits , n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findCost ( cost_mat , N , M ) { var dp = Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) dp [ i ] = Array ( M ) . fill ( 0 ) ; for ( i = 0 ; i < M ; i ++ ) dp [ 0 ] [ i ] = cost_mat [ 0 ] [ i ] ; for ( row = 1 ; row < N ; row ++ ) { for ( curr_col = 0 ; curr_col < M ; curr_col ++ ) { var val = 999999999 ; for ( prev_col = 0 ; prev_col < M ; prev_col ++ ) { if ( curr_col != prev_col ) val = Math . min ( val , dp [ row - 1 ] [ prev_col ] ) ; } dp [ row ] [ curr_col ] = val + cost_mat [ row ] [ curr_col ] ; } } var ans = Number . MAX_VALUE ; for ( i = 0 ; i < M ; i ++ ) ans = Math . min ( ans , dp [ N - 1 ] [ i ] ) ; return ans ; } var N = 4 ; var M = 4 ; var cost_mat = [ [ 4 , 5 , 3 , 2 ] , [ 6 , 2 , 8 , 1 ] , [ 6 , 2 , 2 , 1 ] , [ 0 , 5 , 5 , 1 ] ] ; document . write ( findCost ( cost_mat , N , M ) ) ;

Index/key variables: curr_col, i, prev_col, row
Accumulator variables: curr_col, i, prev_col, row
Iterator variables: curr_col, i, prev_col, row
Javascript program:
function getPrimesFromSeive ( primes ) { let prime = new Array ( 1000001 ) ; for ( let i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( let i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) { for ( let j = i * i ; j <= 1000000 ; j += i ) prime [ j ] = false ; } } for ( let i = 2 ; i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) primes . add ( ( i ) . toString ( ) ) ; } } function splitIntoPrimes ( number ) { let numLen = number . length ; let splitDP = new Array ( numLen + 1 ) ; for ( let i = 0 ; i < splitDP . length ; i ++ ) { splitDP [ i ] = - 1 ; } let primes = new Set ( ) ; getPrimesFromSeive ( primes ) ; for ( let i = 1 ; i <= numLen ; i ++ ) { if ( i <= 6 && ( primes . has ( number . substring ( 0 , i ) ) ) ) splitDP [ i ] = 1 ; if ( splitDP [ i ] != - 1 ) { for ( let j = 1 ; j <= 6 && i + j <= numLen ; j ++ ) { if ( primes . has ( number . substring ( i , i + j ) ) ) { if ( splitDP [ i + j ] == - 1 ) splitDP [ i + j ] = 1 + splitDP [ i ] ; else splitDP [ i + j ] = Math . min ( splitDP [ i + j ] , 1 + splitDP [ i ] ) ; } } } } return splitDP [ numLen ] ; } document . write ( splitIntoPrimes ( " " ) + " " ) ; document . write ( splitIntoPrimes ( " " ) + " " ) ;

Index/key variables: i, j, numLen
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MOD = 1000000007 ; function modInv ( a ) { let p = MOD - 2 ; let s = 1 ; while ( p != 1 ) { if ( p % 2 == 1 ) s = ( s * a ) % MOD ; a = ( a * a ) % MOD ; p = parseInt ( p / 2 , 10 ) ; } return ( a * s ) % MOD ; } function findCnt ( x , y ) { let ans = 0 ; let fact = new Array ( y . length + 1 ) ; fact . fill ( 0 ) ; for ( let i = 0 ; i < y . length + 1 ; i ++ ) fact [ i ] = 1 ; for ( let i = 1 ; i <= y . length ; i ++ ) fact [ i ] = ( fact [ i - 1 ] * i ) % MOD ; for ( let i = 0 ; i < y . length ; i ++ ) { if ( y [ i ] == x ) { ans += ( modInv ( fact [ i ] ) * modInv ( fact [ y . length - i - 1 ] ) ) % MOD ; ans %= MOD ; } } ans *= fact [ ( y . length - 1 ) ] * 0 ; ans = ( ans + 6 ) % MOD ; return ans ; } let x = ' ' ; let y = " " ; document . write ( findCnt ( x , y ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findSubSeq ( arr , n ) { arr . sort ( ) ; var count = new Array ( n ) ; var prev = new Array ( n ) ; count . fill ( 1 ) ; prev . fill ( - 1 ) ; var max = 0 ; var maxprev = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i - 1 ; j >= 0 ; j -- ) { if ( arr [ i ] % arr [ j ] == 0 && count [ j ] + 1 > count [ i ] ) { count [ i ] = count [ j ] + 1 ; prev [ i ] = j ; } } if ( max < count [ i ] ) { max = count [ i ] ; maxprev = i ; } } var i = maxprev ; while ( i >= 0 ) { if ( arr [ i ] != - 1 ) document . write ( arr [ i ] + " " ) ; i = prev [ i ] ; } } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; findSubSeq ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function solve ( str , K ) { let n = str . length ; let dp = new Array ( K ) ; for ( let i = 0 ; i < K ; i ++ ) { dp [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = 0 ; } } if ( n < K ) return - 1 ; else if ( n == K ) return 0 ; let zeroes = 0 , ones = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) zeroes ++ ; else ones ++ ; dp [ 0 ] [ i ] = ones * zeroes ; } for ( let s = 1 ; s < K ; s ++ ) { for ( let i = 0 ; i < n ; i ++ ) { dp [ s ] [ i ] = Number . MAX_VALUE ; ones = 0 ; zeroes = 0 ; for ( let k = i ; k >= 0 ; k -- ) { if ( str [ k ] == ' ' ) zeroes ++ ; else ones ++ ; dp [ s ] [ i ] = Math . min ( dp [ s ] [ i ] , + ( ( k - 1 >= 0 ) ? ones * zeroes + dp [ s - 1 ] [ k - 1 ] : Number . MAX_VALUE ) ) ; } } } return ( dp [ K - 1 ] [ n - 1 ] == Number . MAX_VALUE ) ? - 1 : dp [ K - 1 ] [ n - 1 ] ; } let S = " " ; let K = 2 ; document . write ( solve ( S , K ) ) ;

Index/key variables: i, j, k, s
Accumulator variables: i, j, k, ones, s, zeroes
Iterator variables: i, j, k, s
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 rangeAnd ( 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 == r - l + 1 ) 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 ( rangeAnd ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ;

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function dfs ( node , adj , dp , vis ) { vis [ node ] = true ; for ( var i = 0 ; i < adj [ node ] . length ; i ++ ) { if ( ! vis [ adj [ node ] [ i ] ] ) dfs ( adj [ node ] [ i ] , adj , dp , vis ) ; dp [ node ] = Math . max ( dp [ node ] , 1 + dp [ adj [ node ] [ i ] ] ) ; } } function addEdge ( adj , u , v ) { adj [ u ] . push ( v ) ; } function findLongestPath ( adj , n ) { var dp = Array ( n + 1 ) . fill ( 0 ) ; var vis = Array ( n + 1 ) . fill ( false ) ; for ( var i = 1 ; i <= n ; i ++ ) { if ( ! vis [ i ] ) dfs ( i , adj , dp , vis ) ; } var ans = 0 ; for ( var i = 1 ; i <= n ; i ++ ) { ans = Math . max ( ans , dp [ i ] ) ; } return ans ; } var n = 5 ; var adj = Array . from ( Array ( n + 1 ) , ( ) => Array ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 3 , 2 ) ; addEdge ( adj , 2 , 4 ) ; addEdge ( adj , 3 , 4 ) ; document . write ( findLongestPath ( adj , n ) ) ;

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