dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isPower ( m , y ) { let res1 = parseInt ( Math . log ( y ) / Math . log ( m ) ) ; let res2 = Math . log ( y ) / Math . log ( m ) ; return ( res1 == res2 ) ; } function numSub ( arr , n , m ) { let ans = 0 ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPower ( m , arr [ i ] ) ) { cnt ++ ; ans += parseInt ( ( cnt * ( cnt - 1 ) ) / 2 ) ; } else { cnt = 0 ; } } return ans ; } let arr = [ 1 , 1 , 1 , 3 ] ; let m = 3 ; let n = arr . length ; document . write ( numSub ( arr , n , m ) ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function cntPairs ( arr , N ) { var res = 0 ; var bit = Array ( 32 ) . fill ( 0 ) ; var i ; for ( i = 0 ; i < N ; i ++ ) { var pos = Math . ceil ( Math . log2 ( arr [ i ] ) ) ; bit [ pos ] += 1 ; } for ( i = 0 ; i < 32 ; i ++ ) { res += Math . ceil ( ( bit [ i ] * ( bit [ i ] - 1 ) ) / 2 ) ; } return res ; } arr = [ 1 , 2 , 3 , 4 ] ; N = arr . length ; document . write ( cntPairs ( arr , N ) ) ;

Index/key variables: i, pos
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function minimumMEX ( arr , N , K ) { let s = new Set ( ) ; for ( let i = 1 ; i <= N + 1 ; i ++ ) s . add ( i ) ; for ( let i = 0 ; i < K ; i ++ ) s . delete ( arr [ i ] ) ; let entry = s . entries ( ) ; let mex = 1 ; for ( let i = K ; i < N ; i ++ ) { s . delete ( arr [ i ] ) ; s . add ( arr [ i - K ] ) ; let firstElem = entry . next ( ) . value mex = Math . min ( mex , 1 ) ; } document . write ( mex + " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let K = 3 ; let N = arr . length ; minimumMEX ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function smallerNumbers ( arr , N ) { let hash = new Array ( 100000 ) ; hash . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) hash [ arr [ i ] ] ++ ; let sum = 0 ; for ( let i = 1 ; i < 100000 ; i ++ ) { hash [ i ] += hash [ i - 1 ] ; } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { document . write ( " " + " " ) ; continue ; } document . write ( hash [ arr [ i ] - 1 ] + " " ) ; } } let arr = [ 3 , 4 , 1 , 1 , 2 ] ; let N = arr . length ; smallerNumbers ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function average ( arr , N ) { var sum = 0 ; for ( var i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum > 2147483647 ) { sum = - 2147483647 + ( sum - 2147483649 ) } return parseInt ( sum / N ) ; } function mean ( arr , N ) { var avg = 0 ; for ( var i = 0 ; i < N ; i ++ ) { avg += parseFloat ( ( arr [ i ] - avg ) / ( i + 1 ) ) ; } return avg ; } var arr = [ 2147483647 , 1 , 2 ] ; var N = arr . length document . write ( " " + average ( arr , N ) . toFixed ( 10 ) + " " ) ; document . write ( " " + mean ( arr , N ) . toFixed ( 10 ) + " " ) ;

Index/key variables: i
Accumulator variables: avg, i, sum
Iterator variables: i
Javascript program:
function countPairs ( arr , N ) { var count = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { var val = 1.0 * arr [ i ] ; var idx = 1.0 * ( i + 1 ) ; count += mp . has ( val / idx ) ? mp . get ( val / idx ) : 0 if ( mp . has ( val / idx ) ) mp . set ( val / idx , mp . get ( val / idx ) + 1 ) else mp . set ( val / idx , 1 ) } document . write ( count ) ; } var arr = [ 1 , 3 , 5 , 6 , 5 ] ; var N = arr . length ; countPairs ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function add_edge ( adj , u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function dfs ( parent , adj , u , par = - 1 ) { parent [ u ] = par ; adj [ u ] . forEach ( child => { if ( child != par ) dfs ( parent , adj , child , u ) ; } ) ; } function countSmallerAncestors ( adj , n ) { var parent = Array ( 100000 ) . fill ( 0 ) ; dfs ( parent , adj , 1 ) ; for ( var i = 1 ; i <= n ; i ++ ) { var node = i ; var cnt = 0 ; while ( parent [ node ] != - 1 ) { if ( parent [ node ] < i ) cnt += 1 ; node = parent [ node ] ; } document . write ( cnt + " " ) ; } } var N = 6 ; var adj = Array . from ( Array ( 100000 ) , ( ) => Array ( ) ) ; add_edge ( adj , 1 , 5 ) ; add_edge ( adj , 1 , 4 ) ; add_edge ( adj , 4 , 6 ) ; add_edge ( adj , 5 , 3 ) ; add_edge ( adj , 5 , 2 ) ; countSmallerAncestors ( adj , N ) ;

Index/key variables: node, u, v
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function countSubsequences ( A ) { var odd = 0 ; var even = 0 ; for ( var e1 = 0 ; e1 < A . length ; e1 ++ ) { if ( A [ e1 ] % 2 == 1 ) odd ++ ; else even ++ ; } if ( odd == 0 ) document . write ( 0 ) ; else document . write ( ( 1 << ( A . length - 1 ) ) ) ; } var A = [ 1 , 3 , 4 ] ; countSubsequences ( A ) ;

Index/key variables: e1
Accumulator variables: e1, even, odd
Iterator variables: e1
Javascript program:
function maxModProdSubarr ( arr , n , M ) { var ans = 0 ; var length = n ; for ( i = 0 ; i < n ; i ++ ) { var product = 1 ; for ( j = i ; j < n ; j ++ ) { product = ( product * arr [ i ] ) % M ; if ( product > ans ) { ans = product ; if ( length > j - i + 1 ) { length = j - i + 1 ; } } } } document . write ( " " + ans + " " ) ; document . write ( " " + " " + length ) ; } var arr = [ 2 , 3 , 4 , 2 ] ; var N = arr . length ; var M = 5 ; maxModProdSubarr ( arr , N , M ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function GCD ( a , b ) { return b == 0 ? a : GCD ( b , a % b ) ; } function coprime ( a , b ) { if ( GCD ( a , b ) == 1 ) return true ; return false ; } function numOfPairs ( arr , N ) { let count = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( coprime ( parseInt ( arr [ i ] ) , parseInt ( arr [ j ] ) ) ) { count = count + 1 ; } } } return count ; } function noOfCoPrimePairs ( N , d1 , d2 ) { let l = [ ] ; l . push ( d1 . toString ( ) ) ; l . push ( d2 . toString ( ) ) ; l . sort ( ) ; if ( N < parseInt ( l [ 1 ] ) ) return ; let total = [ ... l ] ; let temp2 = [ ... l ] ; let flag = 0 ; let temp3 = [ ] ; while ( l [ 0 ] . length < 10 ) { for ( let i = 0 ; i < l . length ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { if ( parseInt ( l [ i ] + temp2 [ j ] ) > N ) { flag = 1 ; break ; } total . push ( l [ i ] + temp2 [ j ] ) ; temp3 . push ( l [ i ] + temp2 [ j ] ) ; } if ( flag == 1 ) break ; } if ( flag == 1 ) break ; l = [ ... temp3 ] ; temp3 = [ ] ; } let lenOfTotal = total . length ; let ans = numOfPairs ( total , lenOfTotal ) ; document . write ( ans ) ; } let N = 30 , d1 = 2 , d2 = 3 ; noOfCoPrimePairs ( N , d1 , d2 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function tile_placing ( grid , N ) { let dp = new Array ( N + 5 ) ; dp . fill ( 0 ) ; let orig_cost = 0 ; for ( let i = 0 ; i < 2 ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { orig_cost += grid [ i ] [ j ] ; } } dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( grid [ 0 ] [ 0 ] - grid [ 1 ] [ 0 ] ) ; for ( let i = 2 ; i <= N ; i ++ ) { dp [ i ] = Math . max ( dp [ i - 1 ] + Math . abs ( grid [ 0 ] [ i - 1 ] - grid [ 1 ] [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( grid [ 0 ] [ i - 2 ] - grid [ 0 ] [ i - 1 ] ) + Math . abs ( grid [ 1 ] [ i - 2 ] - grid [ 1 ] [ i - 1 ] ) ) ; } document . write ( ( orig_cost - dp [ N ] ) + " " ) ; } let M = [ [ 7 , 5 , 1 , 3 ] , [ 8 , 6 , 0 , 2 ] ] ; let N = M [ 0 ] . length ; tile_placing ( M , N ) ;

Index/key variables: N, i, j
Accumulator variables: i, j, orig_cost
Iterator variables: i, j
Javascript program:
function findSplit ( arr , N ) { for ( let l = 1 ; l <= N - 4 ; l ++ ) { for ( let r = l + 2 ; r <= N - 2 ; r ++ ) { let lsum = 0 , rsum = 0 , msum = 0 ; for ( let i = 0 ; i <= l - 1 ; i ++ ) { lsum += arr [ i ] ; } for ( let i = l + 1 ; i <= r - 1 ; i ++ ) { msum += arr [ i ] ; } for ( let i = r + 1 ; i < N ; i ++ ) { rsum += arr [ i ] ; } if ( lsum == rsum && rsum == msum ) { document . write ( l + " " + r + " " ) ; return ; } } } document . write ( - 1 ) ; } let arr = [ 2 , 5 , 12 , 7 , 19 , 4 , 3 ] ; let N = arr . length ; findSplit ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, l, lsum, msum, r, rsum
Iterator variables: i, l, r
Javascript program:
function solve ( A , n , Q , q ) { var one = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( A [ i ] == 1 ) one ++ ; var glows = 0 , count = 0 ; if ( one >= Math . ceil ( n / 2 ) ) glows = 1 ; for ( var i = 0 ; i < q ; i ++ ) { var prev = glows ; if ( A [ Q [ i ] - 1 ] == 1 ) one -- ; if ( A [ Q [ i ] - 1 ] == 0 ) one ++ ; A [ Q [ i ] - 1 ] ^= 1 ; if ( one >= Math . ceil ( n / 2.0 ) ) { glows = 1 ; } else { glows = 0 ; } if ( prev != glows ) count ++ ; } return count ; } var n = 3 ; var arr = [ 1 , 1 , 0 ] ; var q = 3 ; var Q = [ 3 , 2 , 1 ] ; document . write ( solve ( arr , n , Q , q ) ) ;

Index/key variables: i
Accumulator variables: count, i, one
Iterator variables: i
Javascript program:
function sumOfDigits ( N ) { let sum = 0 ; while ( N != 0 ) { sum += N % 10 ; N = parseInt ( N / 10 , 10 ) ; } return sum ; } function elementsHavingDigitSumK ( arr , N , K ) { let count = 0 ; for ( let i = 0 ; i < N ; ++ i ) { if ( sumOfDigits ( arr [ i ] ) == K ) { count ++ ; } } document . write ( count ) ; } let arr = [ 23 , 54 , 87 , 29 , 92 , 62 ] ; let K = 11 ; let N = arr . length ; elementsHavingDigitSumK ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i
Javascript program:
function calculateSpan ( price , n , S ) { S [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { S [ i ] = 1 ; for ( let j = i - 1 ; ( j >= 0 ) && ( price [ i ] >= price [ j ] ) ; j -- ) S [ i ] ++ ; } } function printArray ( arr ) { let result = arr . join ( " " ) ; document . write ( result ) ; } let price = [ 10 , 4 , 5 , 90 , 120 , 80 ] ; let n = price . length ; let S = new Array ( n ) ; S . fill ( 0 ) ; calculateSpan ( price , n , S ) ; printArray ( S ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printNGE ( arr , n ) { var next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = - 1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] ) { next = arr [ j ] ; break ; } } document . write ( arr [ i ] + " " + next ) ; document . write ( " " ) ; } } var arr = [ 11 , 13 , 21 , 3 ] ; var n = arr . length ; printNGE ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function no_NGN ( arr , n ) { var nxt = [ ] ; var s = [ ] ; nxt . push ( 0 ) ; s . push ( n - 1 ) ; for ( var i = n - 2 ; i >= 0 ; i -- ) { while ( s . length != 0 && arr [ i ] >= arr [ s [ s . length - 1 ] ] ) s . pop ( ) ; if ( s . length == 0 ) nxt . push ( 0 ) ; else nxt . push ( nxt [ n - s [ s . length - 1 ] - 1 ] + 1 ) ; s . push ( i ) ; } nxt . reverse ( ) ; return nxt ; } var n = 8 ; var arr = [ 3 , 4 , 2 , 7 , 5 , 8 , 10 , 6 ] ; var nxt = no_NGN ( arr , n ) ; document . write ( nxt [ 3 ] + " " ) ; document . write ( nxt [ 6 ] + " " ) ; document . write ( nxt [ 1 ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortStack ( input ) { var tmpStack = [ ] ; while ( input . length != 0 ) { var tmp = input [ input . length - 1 ] ; input . pop ( ) ; while ( tmpStack . length != 0 && tmpStack [ tmpStack . length - 1 ] < tmp ) { input . push ( tmpStack [ tmpStack . length - 1 ] ) ; tmpStack . pop ( ) ; } tmpStack . push ( tmp ) ; } return tmpStack ; } function sortArrayUsingStacks ( arr , n ) { var input = [ ] ; for ( var i = 0 ; i < n ; i ++ ) input . push ( arr [ i ] ) ; var tmpStack = sortStack ( input ) ; for ( var i = 0 ; i < n ; i ++ ) { arr [ i ] = tmpStack [ tmpStack . length - 1 ] ; tmpStack . pop ( ) ; } } var arr = [ 10 , 5 , 15 , 45 ] ; var n = arr . length ; sortArrayUsingStacks ( arr , n ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var arr = [ 10 , 20 , 30 , 50 , 10 , 70 , 30 ] ; function printMaxOfMin ( n ) { for ( k = 1 ; k <= n ; k ++ ) { var maxOfMin = Number . MIN_VALUE ; for ( i = 0 ; i <= n - k ; i ++ ) { var min = arr [ i ] ; for ( j = 1 ; j < k ; j ++ ) { if ( arr [ i + j ] < min ) min = arr [ i + j ] ; } if ( min > maxOfMin ) maxOfMin = min ; } document . write ( maxOfMin + " " ) ; } } printMaxOfMin ( arr . length ) ;

Index/key variables: i
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let arr = [ 10 , 20 , 30 , 50 , 10 , 70 , 30 ] ; function printMaxOfMin ( n ) { let s = [ ] ; let left = new Array ( n + 1 ) ; left . fill ( 0 ) ; let right = new Array ( n + 1 ) ; right . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { left [ i ] = - 1 ; right [ i ] = n ; } for ( let i = 0 ; i < n ; i ++ ) { while ( s . length > 0 && arr [ s [ s . length - 1 ] ] >= arr [ i ] ) { s . pop ( ) ; } if ( s . length > 0 ) { left [ i ] = s [ s . length - 1 ] ; } s . push ( i ) ; } while ( s . length > 0 ) { s . pop ( ) ; } for ( let i = n - 1 ; i >= 0 ; i -- ) { while ( s . length > 0 && arr [ s [ s . length - 1 ] ] >= arr [ i ] ) { s . pop ( ) ; } if ( s . length > 0 ) { right [ i ] = s [ s . length - 1 ] ; } s . push ( i ) ; } let ans = new Array ( n + 1 ) ; ans . fill ( 0 ) ; for ( let i = 0 ; i <= n ; i ++ ) { ans [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let len = right [ i ] - left [ i ] - 1 ; ans [ len ] = Math . max ( ans [ len ] , arr [ i ] ) ; } for ( let i = n - 1 ; i >= 1 ; i -- ) { ans [ i ] = Math . max ( ans [ i ] , ans [ i + 1 ] ) ; } for ( let i = 1 ; i <= n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } printMaxOfMin ( arr . length ) ;

Index/key variables: i, len
Accumulator variables: i
Iterator variables: i
Javascript program:
function nextGreater ( arr , next , order ) { let stack = [ ] ; for ( let i = arr . length - 1 ; i >= 0 ; i -- ) { while ( stack . length != 0 && ( ( order == ' ' ) ? arr [ stack [ stack . length - 1 ] ] <= arr [ i ] : arr [ stack [ stack . length - 1 ] ] >= arr [ i ] ) ) stack . pop ( ) ; if ( stack . length != 0 ) next [ i ] = stack [ stack . length - 1 ] ; else next [ i ] = - 1 ; stack . push ( i ) ; } } function nextSmallerOfNextGreater ( arr ) { let NG = new Array ( arr . length ) ; let RS = new Array ( arr . length ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { NG [ i ] = 0 ; RS [ i ] = 0 ; } nextGreater ( arr , NG , ' ' ) ; nextGreater ( arr , RS , ' ' ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( NG [ i ] != - 1 && RS [ NG [ i ] ] != - 1 ) document . write ( arr [ RS [ NG [ i ] ] ] + " " ) ; else document . write ( " " ) ; } } let arr = [ 5 , 1 , 9 , 2 , 5 , 1 , 7 ] ; nextSmallerOfNextGreater ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } ; function flipBinaryTree ( root ) { if ( root == null ) return root ; if ( root . left == null && root . right == null ) return root ; let flippedRoot = flipBinaryTree ( root . left ) ; root . left . left = root . right ; root . left . right = root ; root . left = root . right = null ; return flippedRoot ; } function printLevelOrder ( root ) { if ( root == null ) return ; let q = [ ] ; q . push ( root ) ; while ( true ) { let nodeCount = q . length ; if ( nodeCount == 0 ) break ; while ( nodeCount > 0 ) { let node = q . shift ( ) ; document . write ( node . data + " " ) ; if ( node . left != null ) q . push ( node . left ) ; if ( node . right != null ) q . push ( node . right ) ; nodeCount -- ; } document . write ( " " ) ; } } let root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . right . left = new Node ( 4 ) ; root . right . right = new Node ( 5 ) ; document . write ( " " ) ; printLevelOrder ( root ) ; root = flipBinaryTree ( root ) ; document . write ( " " ) ; printLevelOrder ( root ) ;

Accumulator variables: nodeCount
Class/struct names: Node
Javascript program:
function heapify ( arr , n , i ) { var largest = i ; var l = 2 * i + 1 ; var r = 2 * i + 2 ; if ( l < n && arr [ l ] > arr [ largest ] ) largest = l ; if ( r < n && arr [ r ] > arr [ largest ] ) largest = r ; if ( largest != i ) { var swap = arr [ i ] ; arr [ i ] = arr [ largest ] ; arr [ largest ] = swap ; heapify ( arr , n , largest ) ; } } function sort ( arr ) { var n = arr . length ; for ( var i = n / 2 - 1 ; i >= 0 ; i -- ) heapify ( arr , n , i ) ; for ( var i = n - 1 ; i > 0 ; i -- ) { var temp = arr [ 0 ] ; arr [ 0 ] = arr [ i ] ; arr [ i ] = temp ; heapify ( arr , i , 0 ) ; } } function printArray ( arr ) { var n = arr . length ; for ( var i = 0 ; i < n ; ++ i ) document . write ( arr [ i ] + " " ) ; } var arr = [ 12 , 11 , 13 , 5 , 6 , 7 ] ; var n = arr . length ; sort ( arr ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i, l, largest, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function isHeap ( arr , n ) { for ( let i = 0 ; i <= Math . floor ( ( n - 2 ) / 2 ) ; i ++ ) { if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ; if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ; } return true ; } let arr = [ 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 ] ; let n = arr . length ; if ( isHeap ( arr , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mergeKArrays ( arr , a , output ) { var c = 0 ; for ( i = 0 ; i < a ; i ++ ) { for ( j = 0 ; j < 4 ; j ++ ) output [ c ++ ] = arr [ i ] [ j ] ; } output . sort ( ( a , b ) => a - b ) ; } function printArray ( arr , size ) { for ( i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; } var arr = [ [ 2 , 6 , 12 , 34 ] , [ 1 , 9 , 20 , 1000 ] , [ 23 , 34 , 90 , 2000 ] ] ; var k = 4 ; var n = 3 ; var output = Array ( n * k ) . fill ( 0 ) ; mergeKArrays ( arr , n , output ) ; document . write ( " " ) ; printArray ( output , n * k ) ;

Index/key variables: i, j
Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
let n = 4 function mergeArrays ( arr1 , arr2 , n1 , n2 , arr3 ) { let i = 0 , j = 0 , k = 0 ; while ( i < n1 && j < n2 ) { if ( arr1 [ i ] < arr2 [ j ] ) arr3 [ k ++ ] = arr1 [ i ++ ] ; else arr3 [ k ++ ] = arr2 [ j ++ ] ; } while ( i < n1 ) arr3 [ k ++ ] = arr1 [ i ++ ] ; while ( j < n2 ) arr3 [ k ++ ] = arr2 [ j ++ ] ; } function printArray ( arr , size ) { for ( let i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; } function mergeKArrays ( arr , i , j , output ) { if ( i == j ) { for ( let p = 0 ; p < n ; p ++ ) output [ p ] = arr [ i ] [ p ] ; return ; } if ( j - i == 1 ) { mergeArrays ( arr [ i ] , arr [ j ] , n , n , output ) ; return ; } let out1 = new Array ( n * ( ( ( i + j ) / 2 ) - i + 1 ) ) let out2 = new Array ( n * ( j - ( ( i + j ) / 2 ) ) ) ; mergeKArrays ( arr , i , ( i + j ) / 2 , out1 ) ; mergeKArrays ( arr , ( i + j ) / 2 + 1 , j , out2 ) ; mergeArrays ( out1 , out2 , n * ( ( ( i + j ) / 2 ) - i + 1 ) , n * ( j - ( ( i + j ) / 2 ) ) , output ) ; } let arr = [ [ 2 , 6 , 12 , 34 ] , [ 1 , 9 , 20 , 1000 ] , [ 23 , 34 , 90 , 2000 ] ] ; let k = arr . length ; let output = new Array ( n * k ) ; mergeKArrays ( arr , 0 , 2 , output ) ; document . write ( " " + " " ) ; printArray ( output , n * k ) ;

Index/key variables: i, j, p
Accumulator variables: i, j, k, p
Iterator variables: i, p
Javascript program:
function generate_derangement ( N ) { let S = [ ] ; for ( let i = 1 ; i <= N ; i ++ ) S [ i ] = i ; let D = [ ] ; for ( let i = 1 ; i <= N ; i += 2 ) { if ( i == N ) { D [ N ] = S [ N - 1 ] ; D [ N - 1 ] = S [ N ] ; } else { D [ i ] = i + 1 ; D [ i + 1 ] = i ; } } for ( let i = 1 ; i <= N ; i ++ ) document . write ( D [ i ] + " " ) ; document . write ( " " ) ; } generate_derangement ( 10 ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MOD = ( 1e9 + 7 ) ; function powerLL ( x , n ) { let result = 1 ; while ( n > 0 ) { if ( n % 2 == 1 ) { result = result * x % MOD ; } n = Math . floor ( n / 2 ) ; x = x * x % MOD ; } return result ; } function powerStrings ( sa , sb ) { let a = 0 , b = 0 ; for ( let i = 0 ; i < sa . length ; i ++ ) { a = ( a * 10 + ( sa [ i ] - ' ' ) ) % MOD ; } for ( let i = 0 ; i < sb . length ; i ++ ) { b = ( b * 10 + ( sb [ i ] - ' ' ) ) % ( MOD - 1 ) ; } return powerLL ( a , b ) ; } let sa = " " , sb = " " ; document . write ( powerStrings ( sa , sb ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function complement ( num ) { var i , len = 0 , temp , comp ; temp = num ; while ( true ) { len ++ ; num = parseInt ( num / 10 ) ; if ( Math . abs ( num ) == 0 ) break ; } num = temp ; comp = parseInt ( Math . pow ( 10 , len ) - num ) ; return comp ; } document . write ( complement ( 25 ) + " " ) ; document . write ( complement ( 456 ) ) ;

Accumulator variables: len
Javascript program:
function countOddSum ( a , n ) { let c_odd = 0 , result = 0 ; let odd = false ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) { odd = ! odd ; } if ( odd ) { c_odd ++ ; } } for ( let i = 0 ; i < n ; i ++ ) { result += c_odd ; if ( a [ i ] % 2 == 1 ) { c_odd = ( n - i - c_odd ) ; } } return result ; } let ar = [ 5 , 4 , 4 , 5 , 1 , 3 ] ; let n = ar . length ; document . write ( " " + " " + countOddSum ( ar , n ) ) ;

Index/key variables: i
Accumulator variables: c_odd, i, result
Iterator variables: i
Boolean variables: odd
Javascript program:
function calculateSum ( n ) { let sum = 0 ; for ( let row = 0 ; row < n ; row ++ ) { sum = sum + ( 1 << row ) ; } return sum ; } let n = 10 ; document . write ( " " + calculateSum ( n ) ) ;

Accumulator variables: row
Iterator variables: row
Javascript program:
let N = 1000000 ; let phi = new Array ( N + 5 ) ; phi . fill ( 0 ) ; function computeTotient ( ) { for ( let i = 1 ; i <= N ; i ++ ) phi [ i ] = i ; for ( let p = 2 ; p <= N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( let i = 2 * p ; i <= N ; i += p ) { phi [ i ] = ( phi [ i ] / p ) * ( p - 1 ) ; } } } } function power ( x , y , p ) { while ( y > 0 ) { if ( ( y & 1 ) > 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function calculate ( x , k , mod ) { let arr = new Array ( N ) ; arr . fill ( 0 ) ; let count = 0 ; while ( mod > 1 ) { arr [ count ++ ] = mod ; mod = phi [ mod ] ; } let result = 1 ; let loop = count + 1 ; arr [ count ] = 1 ; for ( let i = Math . min ( k , loop ) - 1 ; i >= 0 ; i -- ) result = power ( x , result , arr [ i ] ) ; return result ; } computeTotient ( ) ; let x = 3 , k = 2 , m = 3 ; document . write ( calculate ( x , k , m ) ) ;

Index/key variables: count, i, mod, p
Accumulator variables: count, i, p
Iterator variables: i, p
Javascript program:
function countOnes ( n ) { let count = 1 ; let rem = 1 ; while ( rem != 0 ) { rem = ( rem * 10 + 1 ) % n ; count ++ ; } return count ; } let n = 13 ; document . write ( countOnes ( n ) ) ;

Accumulator variables: count
Javascript program:
let MAX = 1005 ; function SieveOfEratosthenes ( primes ) { let prime = new Array ( MAX ) ; for ( let i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } for ( let p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i < MAX ; i += p ) { prime [ i ] = false ; } } } for ( let p = 2 ; p < MAX ; p ++ ) { if ( prime [ p ] ) { primes . push ( p ) ; } } } function minimumSquareFreeDivisors ( N ) { let primes = [ ] ; SieveOfEratosthenes ( primes ) ; let max_count = 0 ; for ( let i = 0 ; i < primes . length && primes [ i ] * primes [ i ] <= N ; i ++ ) { if ( N % primes [ i ] == 0 ) { let tmp = 0 ; while ( N % primes [ i ] == 0 ) { tmp ++ ; N = parseInt ( N / primes [ i ] , 10 ) ; } max_count = Math . max ( max_count , tmp ) ; } } if ( max_count == 0 ) { max_count = 1 ; } return max_count ; } let N = 24 ; document . write ( " " + minimumSquareFreeDivisors ( N ) + " " ) ; N = 6 ; document . write ( " " + minimumSquareFreeDivisors ( N ) ) ;

Index/key variables: i, p
Accumulator variables: i, p, tmp
Iterator variables: i, p