dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isDudeney ( n ) { let cube_rt = parseInt ( Math . round ( ( Math . pow ( n , 1.0 / 3.0 ) ) ) ) ; if ( cube_rt * cube_rt * cube_rt != n ) return false ; let dig_sum = 0 ; let temp = n ; while ( temp > 0 ) { let rem = temp % 10 ; dig_sum += rem ; temp = parseInt ( temp / 10 ) ; } if ( cube_rt != dig_sum ) return false ; return true ; } let n = 17576 ; if ( isDudeney ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: dig_sum
Javascript program:
function countTriangles ( a , n ) { var cnt = 0 ; var pairs = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { pairs += a [ i ] / 2 ; if ( a [ i ] % 2 == 1 && pairs > 0 ) { cnt += 1 ; pairs -= 1 ; } } cnt += parseInt ( ( 2 * pairs ) / 3 ) ; return cnt ; } var a = [ 1 , 2 , 2 , 2 , 2 ] ; var n = a . length ; document . write ( countTriangles ( a , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, pairs
Iterator variables: i
Javascript program:
function getHCF ( x , y ) { var minimum = Math . min ( x , y ) ; if ( x % minimum == 0 && y % minimum == 0 ) return minimum ; for ( var i = minimum / 2 ; i >= 2 ; i -- ) { if ( x % i == 0 && y % i == 0 ) return i ; } return 1 ; } var x = 16 , y = 32 ; document . write ( getHCF ( x , y ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function isDivisible ( n ) { if ( isPrime ( n + 1 ) ) return false ; return true ; } var n = 6 ; if ( isDivisible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Iterator variables: i
Javascript program:
var R = 5 ; var C = 5 ; function findMaxCock ( ar ) { if ( R < 3 C < 3 ) return - 1 ; var max_sum = - 1000000000 ; for ( var i = 0 ; i < R - 2 ; i ++ ) { for ( var j = 0 ; j < C - 2 ; j ++ ) { var sum = ( ar [ i ] [ j ] + ar [ i ] [ j + 2 ] ) + ( ar [ i + 1 ] [ j + 1 ] ) + ( ar [ i + 2 ] [ j ] + ar [ i + 2 ] [ j + 1 ] + ar [ i + 2 ] [ j + 2 ] ) ; max_sum = Math . max ( max_sum , sum ) ; } } return max_sum ; } ar = [ [ 0 , 3 , 0 , 6 , 0 ] , [ 0 , 1 , 1 , 0 , 0 ] , [ 1 , 1 , 1 , 0 , 0 ] , [ 0 , 0 , 2 , 0 , 1 ] , [ 0 , 2 , 0 , 1 , 3 ] ] ; document . write ( findMaxCock ( ar ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function segments ( n , p , m ) { var c = new Map ( ) ; c . set ( 0 , 1 ) ; var hs = false ; var sum = 0 ; var ans = 0 ; var r ; for ( r = 0 ; r < n ; r ++ ) { if ( p [ r ] < m ) sum -- ; else if ( p [ r ] > m ) sum ++ ; if ( p [ r ] == m ) hs = true ; if ( hs ) { if ( c . has ( sum ) && c . has ( sum - 1 ) ) ans += c . get ( sum ) + c . get ( sum - 1 ) ; else if ( c . has ( sum ) ) ans += c . get ( sum ) ; else if ( c . has ( sum - 1 ) ) ans += c . get ( sum - 1 ) ; } else { if ( c . has ( sum ) ) c . set ( sum , c . get ( sum ) + 1 ) ; else c . set ( sum , 1 ) ; } } return ans ; } var a = [ 2 , 4 , 5 , 3 , 1 ] ; var n = a . length ; var m = 4 ; document . write ( segments ( n , a , m ) ) ;

Index/key variables: r
Accumulator variables: ans, r, sum
Iterator variables: r
Boolean variables: hs
Javascript program:
function oddDays ( N ) { var hund1 = N / 100 ; var hund4 = N / 400 ; var leap = N >> 2 ; var ord = N - leap ; if ( hund1 > 0 ) { ord += hund1 ; leap -= hund1 ; } if ( hund4 > 0 ) { ord -= hund4 ; leap += hund4 ; } var days = ord + leap * 2 ; var odd = days % 7 ; return odd ; } var N = 100 ; document . write ( oddDays ( N ) . toFixed ( ) ) ;

Accumulator variables: leap, ord
Javascript program:
function minOperations ( arr , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) } else { mp . set ( arr [ i ] , 1 ) } } let maxFreq = Number . MIN_SAFE_INTEGER ; for ( let x of mp ) maxFreq = Math . max ( maxFreq , x [ 1 ] ) ; return ( n - maxFreq ) ; } let arr = [ 2 , 4 , 6 ] ; let n = arr . length ; document . write ( minOperations ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, x
Javascript program:
function CntDivbyX ( arr , n , x ) { let number = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { number = number * 2 + arr [ i ] ; if ( ( number % x == 0 ) ) count += 1 ; } return count ; } let arr = [ 1 , 0 , 1 , 0 , 1 , 1 , 0 ] ; let n = arr . length ; let x = 2 ; document . write ( CntDivbyX ( arr , n , x ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countCon ( ar , n ) { let cnt = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( ar [ i ] == ar [ i + 1 ] ) cnt ++ ; } return cnt ; } let ar = [ 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 5 , 5 ] ; let n = ar . length ; document . write ( countCon ( ar , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
let maxlen = 100 ; function generateSubStrings ( s , mpp ) { let l = s . length ; for ( let i = 0 ; i < l ; i ++ ) { let temp = " " ; for ( let j = i ; j < l ; j ++ ) { temp += s [ j ] ; if ( mpp . has ( temp ) ) { let x = mpp . get ( temp ) ; mpp . set ( temp , ++ x ) ; } else mpp . set ( temp , 1 ) ; } } } function binomialCoeff ( C ) { let i , j ; for ( i = 1 ; i < 100 ; i ++ ) { for ( j = 0 ; j < 100 ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } } function answerQuery ( mpp , C , k ) { let ans = 0 ; for ( let [ key , value ] of mpp . entries ( ) ) { if ( value >= k ) ans += C [ value ] [ k ] ; } return ans ; } let s = " " ; let mpp = new Map ( ) ; generateSubStrings ( s , mpp ) ; let C = new Array ( maxlen ) ; for ( let i = 0 ; i < maxlen ; i ++ ) { C [ i ] = new Array ( maxlen ) ; for ( let j = 0 ; j < maxlen ; j ++ ) C [ i ] [ j ] = 0 ; } binomialCoeff ( C ) ; let queries = [ 2 , 3 , 4 ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) document . write ( answerQuery ( mpp , C , queries [ i ] ) + " " ) ;

Index/key variables: i, j, k, value
Accumulator variables: ans, i, j, temp
Iterator variables: i, j
Javascript program:
function isPossible ( n ) { var fac = new Array ( 10 ) ; fac [ 0 ] = fac [ 1 ] = 1 ; for ( var i = 2 ; i < 10 ; i ++ ) fac [ i ] = fac [ i - 1 ] * i ; var sum = 0 ; var x = n ; while ( x != 0 ) { sum += fac [ x % 10 ] ; x = parseInt ( x / 10 ) ; } if ( sum % n == 0 ) return true ; return false ; } var n = 19 ; if ( isPossible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findSubsequence ( arr , n , k ) { let M = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( M . has ( arr [ i ] ) ) { M . set ( arr [ i ] , M . get ( arr [ i ] ) + 1 ) } else { M . set ( arr [ i ] , 1 ) } } let numCount = new Array ( k + 1 ) ; for ( let i = 0 ; i <= k ; ++ i ) numCount [ i ] = 0 ; for ( let p of M ) { if ( p [ 0 ] <= k ) { for ( let i = 1 ; ; ++ i ) { if ( p [ 0 ] * i > k ) break ; numCount [ p [ 0 ] * i ] += p [ 1 ] ; } } else break ; } let lcm = 0 , length = 0 ; for ( let i = 1 ; i <= k ; ++ i ) { if ( numCount [ i ] > length ) { length = numCount [ i ] ; lcm = i ; } } if ( lcm == 0 ) document . write ( - 1 + " " ) ; else { document . write ( " " + lcm + " " + length + " " ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; ++ i ) if ( lcm % arr [ i ] == 0 ) document . write ( i + " " ) ; } } let k = 14 ; let arr = [ 2 , 3 , 4 , 5 ] ; let n = arr . length ; findSubsequence ( arr , n , k ) ;

Index/key variables: i
Iterator variables: i, p
Javascript program:
function msb ( x ) { let ret = 0 ; while ( ( x >> ( ret + 1 ) ) != 0 ) ret ++ ; return ret ; } function xorRange ( l , r ) { let max_bit = msb ( r ) ; let mul = 2 ; let ans = 0 ; for ( let i = 1 ; i <= max_bit ; i ++ ) { if ( ( parseInt ( l / mul ) * mul ) == ( parseInt ( r / mul ) * mul ) ) { if ( ( ( l & ( 1 << i ) ) != 0 ) && ( r - l + 1 ) % 2 == 1 ) ans += mul ; mul *= 2 ; continue ; } let odd_c = 0 ; if ( ( ( l & ( 1 << i ) ) != 0 ) && l % 2 == 1 ) odd_c = ( odd_c ^ 1 ) ; if ( ( ( r & ( 1 << i ) ) != 0 ) && r % 2 == 0 ) odd_c = ( odd_c ^ 1 ) ; if ( odd_c ) ans += mul ; mul *= 2 ; } let zero_bit_cnt = parseInt ( ( r - l + 1 ) / 2 ) ; if ( l % 2 == 1 && r % 2 == 1 ) zero_bit_cnt ++ ; if ( zero_bit_cnt % 2 == 1 ) ans ++ ; return ans ; } let l = 1 , r = 4 ; document . write ( xorRange ( l , r ) ) ;

Accumulator variables: ans, i, mul, ret, zero_bit_cnt
Iterator variables: i
Javascript program:
function checkfact ( N , countprime , prime ) { var countfact = 0 ; if ( prime == 2 prime == 3 ) countfact ++ ; var divide = prime ; while ( N / divide != 0 ) { countfact += N / divide ; divide = divide * divide ; } if ( countfact >= countprime ) return true ; else return false ; } function check ( N ) { var sumsquares = ( N + 1 ) * ( 2 * N + 1 ) ; var countprime = 0 ; for ( i = 2 ; i <= Math . sqrt ( sumsquares ) ; i ++ ) { var flag = 0 ; while ( sumsquares % i == 0 ) { flag = 1 ; countprime ++ ; sumsquares /= i ; } if ( flag == 1 ) { if ( ! checkfact ( N - 1 , countprime , i ) ) return false ; countprime = 0 ; } } if ( sumsquares != 1 ) if ( ! checkfact ( N - 1 , 1 , sumsquares ) ) return false ; return true ; } var N = 5 ; if ( check ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: countfact, countprime, i, sumsquares
Iterator variables: i
Javascript program:
function countNonIncreasing ( arr , n ) { var cnt = 0 ; var len = 1 ; for ( var i = 0 ; i < n - 1 ; ++ i ) { if ( arr [ i + 1 ] <= arr [ i ] ) len ++ ; else { cnt += parseInt ( ( ( len + 1 ) * len ) / 2 ) ; len = 1 ; } } if ( len > 1 ) cnt += parseInt ( ( ( len + 1 ) * len ) / 2 ) ; return cnt ; } var arr = [ 5 , 2 , 3 , 7 , 1 , 1 ] ; var n = arr . length ; document . write ( countNonIncreasing ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, len
Iterator variables: i
Javascript program:
function recamanGenerator ( arr , n ) { arr [ 0 ] = 0 ; for ( var i = 1 ; i <= n ; i ++ ) { var temp = arr [ i - 1 ] - i ; var j ; for ( j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] == temp ) temp < 0 ) { temp = arr [ i - 1 ] + i ; break ; } } arr [ i ] = temp ; } } function recamanArray ( arr , n ) { var s = [ ] ; var recaman = Array ( n ) . fill ( 0 ) ; recamanGenerator ( recaman , n ) ; for ( var i = 0 ; i < n ; i ++ ) s . push ( recaman [ i ] ) ; s . sort ( ( a , b ) => b - a ) for ( var i = 0 ; i < n ; i ++ ) { if ( s . includes ( arr [ i ] ) ) { s . splice ( s . indexOf ( arr [ i ] ) , 1 ) ; } } return s . length ; } var arr = [ 7 , 11 , 20 , 4 , 2 , 1 , 8 , 6 ] ; var n = arr . length ; document . write ( recamanArray ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPerfectSquare ( arr , n ) { let umap = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { umap [ arr [ i ] ] ++ ; if ( umap . has ( arr [ i ] ) ) { umap . set ( arr [ i ] , umap . get ( arr [ i ] ) + 1 ) } else { umap . set ( arr [ i ] , 1 ) } } for ( let itr of umap ) if ( ( itr [ 1 ] ) % 2 == 1 ) return false ; return true ; } let arr = [ 2 , 2 , 7 , 7 ] ; let n = arr . length ; if ( isPerfectSquare ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, itr
Javascript program:
function printPermutation ( n ) { if ( n % 2 != 0 ) document . write ( - 1 ) ; else for ( let i = 1 ; i <= Math . floor ( n / 2 ) ; i ++ ) document . write ( ( 2 * i ) + " " + ( ( 2 * i ) - 1 ) + " " ) ; } let n = 4 ; printPermutation ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( n , m ) { if ( m % n != 0 ) return - 1 ; var minOperations = 0 ; var q = m / n ; while ( q % 2 == 0 ) { q = q / 2 ; minOperations ++ ; } while ( q % 3 == 0 ) { q = q / 3 ; minOperations ++ ; } if ( q == 1 ) return minOperations ; return - 1 ; } var n = 120 , m = 51840 ; document . write ( minOperations ( n , m ) ) ;

Accumulator variables: minOperations
Javascript program:
function fib ( n ) { var phi = ( 1 + Math . sqrt ( 5 ) ) / 2 ; return parseInt ( Math . round ( Math . pow ( phi , n ) / Math . sqrt ( 5 ) ) ) ; } function calculateSum ( l , r ) { var sum = 0 ; for ( i = l ; i <= r ; i ++ ) sum += fib ( i ) ; return sum ; } var l = 4 , r = 8 ; document . write ( calculateSum ( l , r ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countSubarrays ( arr , n , K ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { let product = 1 ; for ( let x = i ; x <= j ; x ++ ) product *= arr [ x ] ; if ( product % K == 0 ) count ++ ; } } return count ; } let arr = [ 6 , 2 , 8 ] ; let n = arr . length ; let K = 4 ; document . write ( countSubarrays ( arr , n , K ) ) ;

Index/key variables: x
Accumulator variables: count, i, j, product, x
Iterator variables: i, j, x
Javascript program:
let MAX = 100002 ; let tree = new Array ( 4 * MAX ) ; function build ( node , start , end , arr , k ) { if ( start == end ) { tree [ node ] = ( 1 * arr [ start ] ) % k ; return ; } let mid = ( start + end ) >> 1 ; build ( 2 * node , start , mid , arr , k ) ; build ( 2 * node + 1 , mid + 1 , end , arr , k ) ; tree [ node ] = ( tree [ 2 * node ] * tree [ 2 * node + 1 ] ) % k ; } function query ( node , start , end , l , r , k ) { if ( start > end start > r end < l ) { return 1 ; } if ( start >= l && end <= r ) { return tree [ node ] % k ; } let mid = ( start + end ) >> 1 ; let q1 = query ( 2 * node , start , mid , l , r , k ) ; let q2 = query ( 2 * node + 1 , mid + 1 , end , l , r , k ) ; return ( q1 * q2 ) % k ; } function countSubarrays ( arr , n , k ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { let product_mod_k = query ( 1 , 0 , n - 1 , i , j , k ) ; if ( product_mod_k == 0 ) { count ++ ; } } } return count ; } let arr = [ 6 , 2 , 8 ] ; let n = arr . length ; let k = 4 ; build ( 1 , 0 , n - 1 , arr , k ) ; document . write ( countSubarrays ( arr , n , k ) ) ;

Index/key variables: node, start
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function printMaxValPair ( v , n ) { v . sort ( ( a , b ) => a - b ) var N = v [ n - 1 ] ; if ( N % 2 == 1 ) { var first_maxima = N / 2 ; var second_maxima = first_maxima + 1 ; var ans1 = 3000000000000000000 , ans2 = 3000000000000000000 ; var from_left = - 1 , from_right = - 1 ; var from = - 1 ; for ( var i = 0 ; i < n ; ++ i ) { if ( v [ i ] > first_maxima ) { from = i ; break ; } else { var diff = first_maxima - v [ i ] ; if ( diff < ans1 ) { ans1 = diff ; from_left = v [ i ] ; } } } from_right = v [ from ] ; var diff1 = first_maxima - from_left ; var diff2 = from_right - second_maxima ; if ( diff1 < diff2 ) document . write ( N + " " + from_left ) ; else document . write ( N + " " + from_right ) ; } else { var maxima = parseInt ( N / 2 ) ; var ans1 = 3000000000000000000 ; var R = - 1 ; for ( var i = 0 ; i < n - 1 ; ++ i ) { var diff = Math . abs ( v [ i ] - maxima ) ; if ( diff < ans1 ) { ans1 = diff ; R = v [ i ] ; } } document . write ( N + " " + R ) ; } } var v = [ 1 , 1 , 2 , 3 , 6 , 1 ] ; var n = v . length ; printMaxValPair ( v , n ) ;

Index/key variables: from, i
Iterator variables: i
Javascript program:
function Permutations ( n , k ) { var ans = 1 ; if ( k >= 2 ) ans += ( n ) * ( n - 1 ) / 2 ; if ( k >= 3 ) ans += ( n ) * ( n - 1 ) * ( n - 2 ) * 2 / 6 ; if ( k >= 4 ) ans += ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) * 9 / 24 ; return ans ; } var n = 5 , k = 2 ; document . write ( Permutations ( n , k ) ) ;

Accumulator variables: ans
Javascript program:
function power ( a , n ) { if ( n == 0 ) return 1 ; var p = power ( a , parseInt ( n / 2 ) ) ; p = p * p ; if ( n % 2 == 1 ) p = p * a ; return p ; } function countIntegers ( l , r ) { var ans = 0 , i = 1 ; var v = power ( 2 , i ) ; while ( v <= r ) { while ( v <= r ) { if ( v >= l ) ans ++ ; v = v * 3 ; } i ++ ; v = power ( 2 , i ) ; } if ( l == 1 ) ans ++ ; return parseInt ( ans ) ; } var l = 12 , r = 21 ; document . write ( countIntegers ( l , r ) ) ;

Accumulator variables: ans, i
Javascript program:
function findPairCount ( N , K ) { var count = 0 ; var rem = Array . from ( { length : K } , ( _ , i ) => 0 ) ; rem [ 0 ] = parseInt ( N / K ) ; for ( i = 1 ; i < K ; i ++ ) rem [ i ] = parseInt ( ( N - i ) / K + 1 ) ; if ( K % 2 == 0 ) { count += parseInt ( ( rem [ 0 ] * ( rem [ 0 ] - 1 ) ) / 2 ) ; for ( i = 1 ; i < K / 2 ; i ++ ) count += rem [ i ] * rem [ K - i ] ; count += ( rem [ K / 2 ] * ( rem [ K / 2 ] - 1 ) ) / 2 ; } else { count += ( rem [ 0 ] * ( rem [ 0 ] - 1 ) ) / 2 ; for ( i = 1 ; i <= K / 2 ; i ++ ) count += rem [ i ] * rem [ K - i ] ; } return count ; } var N = 10 , K = 4 ; document . write ( findPairCount ( N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
let N = 1000005 ; let prime = new Array ( N ) ; function sieve ( ) { for ( let i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } prime [ 1 ] = false ; prime [ 0 ] = false ; for ( let i = 2 ; i < N ; i ++ ) { if ( prime [ i ] ) { for ( let j = i * 2 ; j < N ; j += i ) { prime [ j ] = false ; } } } } function sumTruncatablePrimes ( n ) { let sum = 0 ; for ( let i = 2 ; i < n ; i ++ ) { let num = i ; let flag = true ; while ( num > 0 ) { if ( ! prime [ num ] ) { flag = false ; break ; } num = Math . floor ( num / 10 ) ; } num = i ; let power = 10 ; while ( num / power > 0 ) { if ( ! prime [ num % power ] ) { flag = false ; break ; } power *= 10 ; } if ( flag ) { sum += i ; } } return sum ; } let n = 25 ; sieve ( ) ; document . write ( sumTruncatablePrimes ( n ) ) ;

Index/key variables: i, j, num
Accumulator variables: i, j, power, sum
Iterator variables: i, j
Boolean variables: flag
Javascript program:
var N = 3 ; function MaxTraceSub ( mat ) { var max_trace = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { var r = i , s = j , trace = 0 ; while ( r < N && s < N ) { trace += mat [ r ] [ s ] ; r ++ ; s ++ ; max_trace = Math . max ( trace , max_trace ) ; } } } return max_trace ; } var mat = [ [ 10 , 2 , 5 ] , [ 6 , 10 , 4 ] , [ 2 , 7 , - 10 ] ] ; document . write ( MaxTraceSub ( mat ) ) ;

Index/key variables: r, s
Accumulator variables: i, j, r, s, trace
Iterator variables: i, j
Javascript program:
var n = 3 var m = 3 function check ( a , b ) { for ( var i = 0 ; i < n ; i ++ ) { var v1 = [ ] , v2 = [ ] ; var r = i ; var col = 0 ; while ( r >= 0 && col < m ) { v1 . push ( a [ r ] [ col ] ) ; v2 . push ( b [ r ] [ col ] ) ; r -- ; col ++ ; } v1 . sort ( ) ; v2 . sort ( ) ; for ( var i = 0 ; i < v1 . length ; i ++ ) { if ( v1 [ i ] != v2 [ i ] ) return false ; } } for ( var j = 1 ; j < m ; j ++ ) { var v1 = [ ] , v2 = [ ] ; var r = n - 1 ; var col = j ; while ( r >= 0 && col < m ) { v1 . push ( a [ r ] [ col ] ) ; v2 . push ( b [ r ] [ col ] ) ; r -- ; col ++ ; } v1 . sort ( ) ; v2 . sort ( ) ; for ( var i = 0 ; i < v1 . length ; i ++ ) { if ( v1 [ i ] != v2 [ i ] ) return false ; } } return true ; } var a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; var b = [ [ 1 , 4 , 7 ] , [ 2 , 5 , 6 ] , [ 3 , 8 , 9 ] ] ; if ( check ( a , b ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: col, i, r
Accumulator variables: col, i, j, r
Iterator variables: i, j
Javascript program:
function countDigits ( a , b ) { var count = 0 ; var p = Math . abs ( parseInt ( a / b ) ) ; if ( p == 0 ) return 1 ; while ( p > 0 ) { count ++ ; p = parseInt ( p / 10 ) ; } return count ; } var a = 100 ; var b = 10 ; document . write ( countDigits ( a , b ) ) ;

Accumulator variables: count
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function maxProfit ( n , a , b , x , y ) { let res = x * Math . floor ( n / a ) ; res += y * Math . floor ( n / b ) ; res -= Math . min ( x , y ) * ( n / ( ( a * b ) / __gcd ( a , b ) ) ) ; return res ; } let n = 6 , a = 6 , b = 2 , x = 8 , y = 2 ; document . write ( maxProfit ( n , a , b , x , y ) ) ;

Accumulator variables: res
Javascript program:
function kthOdd ( arr , n , k ) { for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) k -- ; if ( k == 0 ) return arr [ i ] ; } return - 1 ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; var k = 2 ; document . write ( kthOdd ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function lastFiveDigits ( n ) { n = ( Math . floor ( n / 10000 ) ) * 10000 + ( Math . floor ( n / 100 ) % 10 ) * 1000 + ( n % 10 ) * 100 + ( Math . floor ( n / 10 ) % 10 ) * 10 + Math . floor ( n / 1000 ) % 10 ; let ans = 1 ; for ( let i = 0 ; i < 5 ; i ++ ) { ans *= n ; ans %= 100000 ; } document . write ( ans ) ; } let n = 12345 ; lastFiveDigits ( n ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let mod = 1000000007 ; function power ( a , n ) { if ( n == 0 ) { return 1 ; } let p = power ( a , n / 2 ) % mod ; p = ( p * p ) % mod ; if ( n == 1 ) { p = ( p * a ) % mod ; } return p ; } function computeSum ( arr , n ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let maxs = ( power ( 2 , i ) - 1 + mod ) % mod ; maxs = ( maxs * arr [ i ] ) % mod ; let mins = ( power ( 2 , n - 1 - i ) - 1 + mod ) % mod ; mins = ( mins * arr [ i ] ) % mod ; let V = ( maxs - mins + mod ) % mod ; sum = ( sum + V ) % mod ; } return sum ; } let arr = [ 4 , 3 , 1 ] ; let n = arr . length ; document . write ( computeSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( n ) { var cnt = 0 ; var p = 1 ; while ( p <= n ) { cnt ++ ; p *= 2 ; } return cnt ; } var n = 7 ; document . write ( count ( n ) ) ;

Accumulator variables: cnt, p
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function findMinimum ( n , m ) { var mini = m ; for ( var i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { var sec = n / i ; if ( __gcd ( m , i ) > 1 ) { return i ; } else if ( __gcd ( sec , m ) > 1 ) { mini = Math . min ( sec , mini ) ; } } } if ( mini == m ) return - 1 ; else return mini ; } var n = 8 , m = 10 ; document . write ( findMinimum ( n , m ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function nthTerm ( N ) { let nth = 0 , i ; for ( i = N ; i > 0 ; i -- ) { nth += Math . pow ( i , i ) ; } return nth ; } let N = 3 ; document . write ( nthTerm ( N ) ) ;

Accumulator variables: i, nth
Iterator variables: i
Javascript program:
function findMinRemoval ( arr , n ) { var temp , value = 0 ; var maximum = 0 ; if ( n == 1 ) return 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( i != 0 && i != n - 1 ) { value = value + Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; temp = Math . abs ( arr [ i ] - arr [ i + 1 ] ) + Math . abs ( arr [ i ] - arr [ i - 1 ] ) - Math . abs ( arr [ i - 1 ] - arr [ i + 1 ] ) ; } else if ( i == 0 ) { value = value + Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; temp = Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; } else temp = Math . abs ( arr [ i ] - arr [ i - 1 ] ) ; maximum = Math . max ( maximum , temp ) ; } return ( value - maximum ) ; } var arr = [ 1 , 5 , 3 , 2 , 10 ] ; var n = arr . length ; document . write ( findMinRemoval ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function LucasSum ( N ) { var sum = 0 ; var a = 2 , b = 1 , c ; sum += a ; while ( b <= N ) { sum += b ; var c = a + b ; a = b ; b = c ; } return sum ; } var N = 20 ; document . write ( LucasSum ( N ) ) ;

Accumulator variables: sum
Javascript program:
function findMinSum ( arr , n ) { var occ = n - 1 , sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] * Math . pow ( 2 , occ ) ; occ -- ; } return sum ; } var arr = [ 1 , 2 , 4 , 5 ] ; var n = arr . length ; document . write ( findMinSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, occ, sum
Iterator variables: i