dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function CountPairs ( arr , N ) { var res = 0 ; var mp = new Map ( ) ; for ( var 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 ) ; } } mp . forEach ( ( value , key ) => { var x = key ; var y = value ; if ( x == 1 ) { res += N - 1 ; } res += parseInt ( ( y * ( y - 1 ) ) / 2 ) ; for ( var j = 2 ; j <= parseInt ( Math . sqrt ( x ) ) ; j ++ ) { if ( x % j == 0 ) { res += mp . get ( j ) ; if ( j != parseInt ( x / j ) ) res += mp . get ( parseInt ( x / j ) ) ; } } } ) ; return res ; } var arr = [ 2 , 3 , 1 , 2 ] ; var N = arr . length ; document . write ( CountPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function countbits ( n ) { let count = 0 ; while ( n != 0 ) { if ( ( n & 1 ) != 0 ) count ++ ; n = Math . floor ( n / 2 ) ; } return count ; } function BitProduct ( arr , N ) { let product = 1 ; for ( let i = 0 ; i < N ; i ++ ) { let bits = countbits ( arr [ i ] ) ; product *= bits ; } return product ; } let arr = [ 3 , 2 , 4 , 1 , 5 ] ; let N = arr . length ; document . write ( BitProduct ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i, product
Iterator variables: i
Javascript program:
function getMid ( s , e ) { return s + Math . floor ( ( e - s ) / 2 ) ; } function getSumUtil ( st , ss , se , qs , qe , si ) { if ( qs <= ss && qe >= se ) return st [ si ] ; if ( se < qs ss > qe ) return 0 ; let mid = getMid ( ss , se ) ; return getSumUtil ( st , ss , mid , qs , qe , 2 * si + 1 ) + getSumUtil ( st , mid + 1 , se , qs , qe , 2 * si + 2 ) ; } function getSum ( st , n , qs , qe ) { if ( qs < 0 qe > n - 1 qs > qe ) { document . write ( " " ) ; return - 1 ; } return getSumUtil ( st , 0 , n - 1 , qs , qe , 0 ) ; } function constructSTUtil ( arr , ss , se , st , si ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return arr [ ss ] ; } let mid = getMid ( ss , se ) ; st [ si ] = constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) + constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ; return st [ si ] ; } function constructST ( arr , n ) { let x = ( Math . ceil ( Math . log ( n ) / Math . log ( 2 ) ) ) ; let max_size = 2 * Math . pow ( 2 , x ) - 1 ; let st = new Array ( max_size ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } function OddDivisorsSum ( n , q , arr , Query ) { for ( let i = 0 ; i < n ; i ++ ) { let sq = Math . sqrt ( arr [ i ] ) ; if ( sq * sq != arr [ i ] ) arr [ i ] = 0 ; } let st = constructST ( arr , n ) ; for ( let i = 0 ; i < q ; i ++ ) { let l = Query [ i ] [ 0 ] ; let r = Query [ i ] [ 1 ] ; document . write ( getSum ( st , n , l , r ) + " " ) ; } } let arr = [ 2 , 4 , 5 , 6 , 9 ] ; let N = arr . length ; let Q = 3 ; let Query = [ [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] ] ; OddDivisorsSum ( N , Q , arr , Query ) ;

Index/key variables: i, si, ss
Accumulator variables: i
Iterator variables: i
Javascript program:
function OddDivisorsSum ( n , q , a , Query ) { let DP = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { DP [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let x = Math . floor ( Math . sqrt ( a [ i ] ) ) ; if ( x * x == a [ i ] ) DP [ i ] = a [ i ] ; } for ( let i = 1 ; i < n ; i ++ ) { DP [ i ] = DP [ i - 1 ] + DP [ i ] ; } for ( let i = 0 ; i < q ; i ++ ) { let l = Query [ i ] [ 0 ] ; let r = Query [ i ] [ 1 ] ; if ( l == 0 ) { document . write ( DP [ r ] + " " ) ; } else { document . write ( DP [ r ] - DP [ l - 1 ] + " " ) ; } } } let arr = [ 2 , 4 , 5 , 6 , 9 ] ; let N = arr . length ; let Q = 3 let Query = [ [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] ] ; OddDivisorsSum ( N , Q , arr , Query ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSubset ( arr ) { var N = arr . length ; var mp = new Map ( ) ; var totSum = 0 ; var s = 0 ; var flag = 0 ; var ans = [ ] ; for ( var i = 0 ; i < arr . length ; i ++ ) { totSum += arr [ i ] ; if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) ; } arr . sort ( ( a , b ) => a - b ) var i = N - 1 ; while ( i >= 0 ) { var frq = mp . get ( arr [ i ] ) ; if ( ( frq + ans . length ) < ( N - ( frq + ans . length ) ) ) { for ( var k = 0 ; k < frq ; k ++ ) { ans . push ( arr [ i ] ) ; totSum -= arr [ i ] ; s += arr [ i ] ; i -- ; } } else { i -= frq ; } if ( s > totSum ) { flag = 1 ; break ; } } if ( flag == 1 ) { for ( i = ans . length - 1 ; i >= 0 ; i -- ) { document . write ( ans [ i ] + " " ) ; } } else { document . write ( - 1 ) ; } } var arr = [ 5 , 3 , 2 , 4 , 1 , 2 ] ; findSubset ( arr ) ;

Index/key variables: i
Accumulator variables: i, k, s, totSum
Iterator variables: i, k
Javascript program:
function minStepK ( arr , N , K ) { var E = 0 ; var S = 0 ; for ( var i = 0 ; i < N ; i ++ ) { S += arr [ i ] ; if ( arr [ i ] % 2 === 0 ) E += 1 ; } if ( S >= K ) return 0 ; else if ( S + E < K ) return - 1 ; else return K - S ; } var arr = [ 0 , 1 , 1 , 0 , 1 ] ; var N = arr . length ; var K = 4 ; document . write ( minStepK ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: E, S, i
Iterator variables: i
Javascript program:
function Rotate ( n , f ) { let temp = n ; let maxi = n ; let mini = n ; for ( let idx = 0 ; idx < 7 ; idx ++ ) { if ( temp % 2 == 1 ) { temp >>= 1 ; temp += Math . pow ( 2 , 7 ) ; } else temp >>= 1 ; mini = Math . min ( mini , temp ) ; maxi = Math . max ( maxi , temp ) ; } if ( f == 1 ) return ( maxi ) ; else return ( mini ) ; } function calcMinDiff ( arr , n ) { let caseOne = 0 ; let sumOfodd = 0 ; let sumOfeven = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) sumOfodd += Rotate ( arr [ i ] , 0 ) ; else sumOfeven += Rotate ( arr [ i ] , 1 ) ; } caseOne = Math . abs ( sumOfodd - sumOfeven ) ; let caseTwo = 0 ; sumOfodd = 0 ; sumOfeven = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) sumOfodd += Rotate ( arr [ i ] , 1 ) ; else sumOfeven += Rotate ( arr [ i ] , 0 ) ; } caseTwo = Math . abs ( sumOfodd - sumOfeven ) ; return Math . max ( caseOne , caseTwo ) ; } let arr = [ 123 , 86 , 234 , 189 ] ; let n = arr . length ; document . write ( ( calcMinDiff ( arr , n ) ) ) ;

Index/key variables: i
Accumulator variables: i, idx, sumOfeven, sumOfodd, temp
Iterator variables: i, idx
Javascript program:
function minimumDiff ( arr , N ) { let res = arr [ 0 ] , sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; let min_diff = sum ; for ( let i = 0 ; i < N ; i ++ ) { if ( Math . abs ( sum - ( arr [ i ] * N ) ) < min_diff ) { min_diff = Math . abs ( sum - ( arr [ i ] * N ) ) ; res = arr [ i ] ; } } document . write ( res ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; minimumDiff ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function sum ( arr , N , K ) { var sum = 0 ; var i ; var v = [ ] ; for ( i = 0 ; i < N ; i ++ ) { v . push ( arr [ i ] ) ; } var flag = 0 ; for ( i = 0 ; i < v . length ; i ++ ) { if ( ! flag && v [ i ] % K == 0 ) v . push ( v [ i ] / K ) ; else { flag = 1 ; } sum = sum + v [ i % N ] ; } return sum ; } var arr = [ 4 , 6 , 8 , 2 ] ; var K = 2 ; var N = arr . length ; document . write ( sum ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function primeDivisors ( arr , N ) { var K = arr [ 0 ] ; var i , j ; for ( i = 1 ; i < N ; i ++ ) { K = Math . max ( K , arr [ i ] ) ; } var prime = Array ( K + 1 ) . fill ( 0 ) ; prime [ 0 ] = 1 ; prime [ 1 ] = 1 ; for ( i = 2 ; i < K + 1 ; i ++ ) { if ( prime [ i ] == 0 ) { for ( j = 2 * i ; j < K + 1 ; j += i ) { prime [ j ] = 1 ; } } } var factor = Array ( K + 1 ) . fill ( 0 ) ; factor [ 0 ] = 0 ; factor [ 1 ] = 1 ; for ( i = 2 ; i < K + 1 ; i ++ ) { factor [ i ] += 1 ; for ( j = i ; j < K + 1 ; j += i ) { factor [ j ] += 1 ; } } var count = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( prime [ factor [ arr [ i ] ] ] == 0 ) count ++ ; } return count ; } var arr = [ 10 , 13 , 17 , 25 ] ; var N = arr . length ; document . write ( primeDivisors ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function SieveOfEratosthenes ( n , prime ) { prime [ 0 ] = 0 ; prime [ 1 ] = 0 ; for ( var p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == Boolean ( true ) ) { for ( var i = p * p ; i <= n ; i += p ) { prime [ i ] = Boolean ( false ) ; } } } } function countPrime ( n ) { var prime = new Array ( n + 1 ) ; var x = new Boolean ( true ) ; prime . fill ( x ) ; SieveOfEratosthenes ( n , prime ) ; var dp = new Array ( n + 1 ) ; dp . fill ( 0 ) ; dp [ 1 ] = 0 ; for ( var i = 2 ; i <= n ; i ++ ) { dp [ i ] += dp [ i - 1 ] ; if ( prime [ i ] == Boolean ( true ) && prime [ i - 2 ] == Boolean ( true ) ) { dp [ i ] ++ ; } } document . write ( dp [ n ] ) ; } var n = 6 ; countPrime ( n ) ;

Index/key variables: i, n, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function findMinSum ( mat , N ) { var sum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var res = 0 ; for ( var j = 0 ; j < N ; j ++ ) { if ( i != j ) { res |= mat [ i ] [ j ] ; } } sum += res ; } return sum ; } var mat = [ [ - 1 , 2 , 3 ] , [ 9 , - 1 , 7 ] , [ 4 , 5 , - 1 ] ] ; var N = mat . length ; document . write ( findMinSum ( mat , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res, sum
Iterator variables: i, j
Javascript program:
function findGCD ( a , b ) { if ( b == 0 ) return a ; return findGCD ( b , a % b ) ; } function findLCM ( a , b ) { return ( a * b ) / findGCD ( a , b ) ; } function uniqueElementsLCM ( arr , N ) { var freq = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . set ( arr [ i ] , 1 ) ; } } var lcm = 1 ; freq . forEach ( ( value , key ) => { if ( value == 1 ) { lcm = findLCM ( lcm , key ) ; } } ) ; if ( lcm == 1 ) lcm = - 1 ; document . write ( lcm ) ; } var arr = [ 1 , 2 , 1 , 3 , 3 , 4 ] ; var N = arr . length ; uniqueElementsLCM ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxAdjacentDifference ( A ) { let diff = 0 ; for ( let i = 1 ; i < A . length ; i ++ ) { diff = Math . max ( diff , A [ i ] - A [ i - 1 ] ) ; } return diff ; } function MinimumValue ( arr , N ) { let MinValue = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let new_arr = [ ] ; for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; new_arr . push ( arr [ j ] ) ; } MinValue = Math . min ( MinValue , maxAdjacentDifference ( new_arr ) ) ; } return MinValue ; } let arr = [ 1 , 3 , 7 , 8 ] ; let N = arr . length ; document . write ( MinimumValue ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countPairs ( arr , N ) { let even = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; } if ( N - even >= 1 ) { document . write ( even ) ; return ; } document . write ( 0 ) ; } let arr = [ 5 , 4 , 7 , 2 ] ; let N = arr . length ; countPairs ( arr , N ) ;

Index/key variables: i
Accumulator variables: even, i
Iterator variables: i
Javascript program:
function distribute ( N , K , M , arr ) { let distribution = new Array ( N ) for ( let i = 0 ; i < N ; i ++ ) { distribution [ i ] = 0 } let ptr = K - 1 ; let rem = M ; while ( rem > 0 ) { if ( rem >= arr [ ptr ] ) { distribution [ ptr ] += arr [ ptr ] ; rem -= arr [ ptr ] ; } else { distribution [ ptr ] += rem ; rem = 0 ; } ptr = ( ptr + 1 ) % N ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( distribution [ i ] + " " ) } } let arr = [ 2 , 3 , 2 , 1 , 4 ] ; let M = 11 , S = 2 ; let N = arr . length distribute ( N , S , M , arr ) ;

Index/key variables: i, ptr
Accumulator variables: i, rem
Iterator variables: i
Javascript program:
function sumOfSquaredDifferences ( arr , N ) { let ans = 0 ; let sumA = 0 , sumB = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sumA += ( arr [ i ] * arr [ i ] ) ; sumB += arr [ i ] ; } sumA = N * sumA ; sumB = ( sumB * sumB ) ; ans = sumA - sumB ; document . write ( ans ) ; } let arr = [ 2 , 8 , 4 ] ; let N = arr . length ; sumOfSquaredDifferences ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sumA, sumB
Iterator variables: i
Javascript program:
function waysToRemove ( n , m ) { var ans = 0 ; if ( m == 1 ) { document . write ( n ) ; return ; } for ( var d = 0 ; d >= 0 ; d ++ ) { var len = m + ( m - 1 ) * d ; if ( len > n ) break ; ans += ( n - len ) + 1 ; } document . write ( ans ) ; } var N = 5 , M = 3 ; waysToRemove ( N , M ) ;

Accumulator variables: ans, d
Iterator variables: d
Javascript program:
function countStairs ( n , x , a , b ) { var vis = Array ( n + 1 ) . fill ( 0 ) ; var moves = [ + a , - a , + b , - b ] ; var q = [ ] ; q . push ( x ) ; vis [ x ] = 1 ; while ( q . length != 0 ) { var currentStair = q [ 0 ] ; q . shift ( ) ; for ( var j = 0 ; j < 4 ; j ++ ) { var newStair = currentStair + moves [ j ] ; if ( newStair > 0 && newStair <= n && ! vis [ newStair ] ) { q . push ( newStair ) ; vis [ newStair ] = 1 ; } } } var cnt = 0 ; for ( var i = 1 ; i <= n ; i ++ ) if ( vis [ i ] == 1 ) cnt ++ ; document . write ( cnt ) ; } var N = 10 , S = 2 , A = 5 , B = 7 ; countStairs ( N , S , A , B ) ;

Index/key variables: i, j, newStair, x
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function smallerNumbers ( arr , N ) { var i ; for ( i = 0 ; i < N ; i ++ ) { var count = 0 ; for ( j = 0 ; j < N ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { count += 1 ; } } document . write ( count + " " ) ; } } var arr = [ 3 , 4 , 1 , 1 , 2 ] var N = arr . length ; smallerNumbers ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } function minimumOperations ( X , Y ) { var GCD = gcd ( X , Y ) ; X = X / GCD ; Y = Y / GCD ; var count = 0 ; while ( X != Y ) { if ( Y > X ) { var t = X ; X = Y ; Y = t ; } if ( X % 2 == 0 ) { X = X / 2 ; } else if ( X % 3 == 0 ) { X = X / 3 ; } else if ( X % 5 == 0 ) { X = X / 5 ; } else { document . write ( " " ) ; return ; } count += 1 ; } document . write ( count ) ; } var X = 15 , Y = 20 ; minimumOperations ( X , Y ) ;

Accumulator variables: count
Javascript program:
function minOperations ( a , n ) { var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { ans += a [ i ] ; } ans -= n ; for ( x = 1 ; ; x ++ ) { var curPow = 1 , curCost = 0 ; for ( i = 0 ; i < n ; i ++ ) { curCost += Math . abs ( a [ i ] - curPow ) ; curPow *= x ; } if ( curPow / x > ans + a [ n - 1 ] ) break ; ans = Math . min ( ans , curCost ) ; } return ans ; } var arr = [ 1 , 5 , 7 ] ; var N = arr . length ; document . write ( minOperations ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: ans, curCost, curPow, i, x
Iterator variables: i, x
Javascript program:
function printArray ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function nearestPowerDiff ( arr , N , a , b ) { for ( let i = 0 ; i < N ; i ++ ) { let log_a = Math . floor ( Math . log ( arr [ i ] ) / Math . log ( a ) ) ; let A = Math . floor ( Math . pow ( a , log_a ) ) ; let B = Math . floor ( Math . pow ( a , log_a + 1 ) ) ; if ( ( arr [ i ] - A ) < ( B - arr [ i ] ) ) log_a = A ; else log_a = B ; let log_b = Math . floor ( Math . log ( arr [ i ] ) / Math . log ( b ) ) ; A = Math . floor ( Math . pow ( b , log_b ) ) ; B = Math . floor ( Math . pow ( b , log_b + 1 ) ) ; if ( ( arr [ i ] - A ) < ( B - arr [ i ] ) ) log_b = A ; else log_b = B ; arr [ i ] = Math . abs ( log_a - log_b ) ; } printArray ( arr , N ) ; } let arr = [ 5 , 12 , 25 ] ; let A = 2 , B = 3 ; let N = arr . length ; nearestPowerDiff ( arr , N , A , B ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function bitOr ( arr , N ) { var count = 0 ; var length = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { length ++ ; } else { if ( length != 0 ) { count += Math . floor ( ( length ) * ( length + 1 ) / 2 ) ; } length = 0 ; } } count += Math . floor ( ( length ) * ( length + 1 ) / 2 ) ; return count ; } var arr = [ 1 , 5 , 4 , 2 , 6 ] var N = arr . length ; document . write ( bitOr ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function ValidPairs ( X , K ) { var count = 0 ; for ( A = - 1000 ; A <= 1000 ; A ++ ) { for ( B = - 1000 ; B <= 1000 ; B ++ ) { if ( Math . pow ( A , K ) - Math . pow ( B , K ) == X ) { count ++ ; document . write ( A + " " + B + " " ) ; } } } if ( count == 0 ) { document . write ( " " ) ; } } var X = 33 ; var K = 5 ; ValidPairs ( X , K ) ;

Accumulator variables: A, B, count
Iterator variables: A, B
Javascript program:
function maximumAND ( arr , n , m ) { let tot = 1 << n ; let mx = 0 ; for ( let bm = 0 ; bm < tot ; bm ++ ) { let andans = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( ( ( bm >> i ) & 1 ) != 0 ) { if ( count == 0 ) { andans = arr [ i ] ; } else { andans = andans & arr [ i ] ; } count ++ ; } } if ( count == ( m + 1 ) ) { mx = Math . max ( mx , andans ) ; } } return mx ; } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; let M = 2 ; document . write ( maximumAND ( arr , N , M ) ) ;

Index/key variables: i
Accumulator variables: bm, count
Iterator variables: bm, i
Javascript program:
function findTotalSum ( ops ) { if ( ops . length == 0 ) { document . write ( 0 ) ; return ; } var pts = [ ] ; var ans = 0 ; for ( var i = 0 ; i < ops . length ; i ++ ) { if ( ops [ i ] == " " ) { ans -= pts [ pts . length - 1 ] ; pts . pop ( ) ; } else if ( ops [ i ] == " " ) { pts . push ( pts [ pts . length - 1 ] * 2 ) ; ans += pts [ pts . length - 1 ] ; } else if ( ops [ i ] == " " ) { var a = pts [ pts . length - 1 ] ; pts . pop ( ) ; var b = pts [ pts . length - 1 ] ; pts . push ( a ) ; ans += ( a + b ) ; pts . push ( a + b ) ; } else { var n = parseInt ( ops [ i ] ) ; ans += n ; pts . push ( n ) ; } } document . write ( ans ) ; } var arr = [ " " , " " , " " , " " , " " ] ; findTotalSum ( arr ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findXOR ( mat , N ) { let XOR = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { for ( let k = 0 ; k < N ; k ++ ) { if ( ( i == j && j == k ) ) { XOR ^= mat [ i ] [ j ] [ k ] ; XOR ^= mat [ i ] [ j ] [ N - k - 1 ] ; } } } } document . write ( XOR ) ; } let mat = [ [ [ 1 , 2 ] , [ 3 , 4 ] ] , [ [ 5 , 6 ] , [ 7 , 8 ] ] ] ; let N = mat . length ; findXOR ( mat , N ) ;

Index/key variables: i, j, k
Accumulator variables: XOR, i, j, k
Iterator variables: i, j, k
Javascript program:
function findXOR ( mat , N ) { let XOR = 0 ; for ( let i = 0 ; i < N ; i ++ ) { XOR ^= mat [ i ] [ i ] [ i ] ; XOR ^= mat [ i ] [ i ] [ N - i - 1 ] ; } document . write ( XOR ) ; } let mat = [ [ [ 1 , 2 ] , [ 3 , 4 ] ] , [ [ 5 , 6 ] , [ 7 , 8 ] ] ] ; let N = mat . length ; findXOR ( mat , N ) ; ;

Index/key variables: i
Accumulator variables: XOR, i
Iterator variables: i
Javascript program:
var MAX = 300004 ; var graph = Array . from ( Array ( MAX ) , ( ) => new Array ( ) ) ; var mod = 1000000007 ; var ans = 0 ; function countSubtreesUtil ( cur , par ) { var res = 1 ; for ( var i = 0 ; i < graph [ cur ] . length ; i ++ ) { var v = graph [ cur ] [ i ] ; if ( v == par ) continue ; res = ( res * ( countSubtreesUtil ( v , cur ) + 1 ) ) % mod ; } ans = ( ans + res ) % mod ; return res ; } function countSubtrees ( N , adj ) { for ( var i = 0 ; i < N - 1 ; i ++ ) { var a = adj [ i ] [ 0 ] ; var b = adj [ i ] [ 1 ] ; graph [ a ] . push ( b ) ; graph [ b ] . push ( a ) ; } countSubtreesUtil ( 1 , 1 ) ; document . write ( ans + 1 ) ; } var N = 3 ; var adj = [ [ 0 , 1 ] , [ 1 , 2 ] ] ; countSubtrees ( N , adj ) ;

Index/key variables: a, b, cur, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkWinner ( arr , N ) { let diff = 0 ; for ( let i = 0 ; i < N ; i ++ ) { diff -= arr [ i ] ; } if ( diff % 2 == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let arr = [ 1 , 2 ] ; let N = arr . length ; checkWinner ( arr , N ) ;

Index/key variables: i
Accumulator variables: diff, i
Iterator variables: i
Javascript program:
function constructArray ( N ) { var ans = [ ] ; for ( var i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { ans . push ( i ) ; if ( N != ( i * i ) ) { ans . push ( N / i ) ; } } } document . write ( ans ) ; } var N = 12 ; constructArray ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let MOD = 998244353 ; function findConvolution ( a , b ) { let n = a . length , m = b . length ; let c = [ ] ; for ( let i = 0 ; i < n + m - 1 ; ++ i ) { c [ i ] = 0 ; } for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < m ; ++ j ) { c [ i + j ] += ( a [ i ] * b [ j ] ) % MOD ; } } for ( let k = 0 ; k < c . length ; ++ k ) { c [ k ] %= MOD ; document . write ( c [ k ] + " " ) ; } } let A = [ 1 , 2 , 3 , 4 ] ; let B = [ 5 , 6 , 7 , 8 , 9 ] ; findConvolution ( A , B ) ;

Index/key variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function count1s ( start_i , start_j , end_i , end_j , mat ) { let count = 0 ; for ( let x = start_i ; x < end_i ; x ++ ) { for ( let y = start_j ; y < end_j ; y ++ ) { if ( mat [ x ] [ y ] == 1 ) count ++ ; } } return count ; } function findMinimumCount ( N , M , A , B , mat ) { let minimum = 1e9 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( i + A <= N && j + B <= M ) { let count = count1s ( i , j , i + A , j + B , mat ) ; minimum = Math . min ( count , minimum ) ; } if ( i + B <= N && j + A <= M ) { let count = count1s ( i , j , i + B , j + A , mat ) ; minimum = Math . min ( count , minimum ) ; } } } return minimum ; } let A = 2 , B = 2 ; let N = 3 , M = 4 ; let mat = [ [ 1 , 0 , 1 , 0 ] , [ 0 , 1 , 0 , 1 ] , [ 1 , 0 , 1 , 0 ] ] ; document . write ( findMinimumCount ( N , M , A , B , mat ) ) ;

Index/key variables: x, y
Accumulator variables: count, i, j, x, y
Iterator variables: i, j, x, y
Javascript program:
function checkEvenPower ( n ) { var x = 0 ; while ( x < n ) { var value = Math . pow ( 2 , x ) ; if ( value == n ) { if ( x % 2 == 0 ) return true ; else return false ; } x ++ ; } return false ; } var N = 4 ; document . write ( ( checkEvenPower ( N ) ? " " : " " ) ) ;

Accumulator variables: x
Javascript program:
function findSum ( N , K ) { var ans = 0 ; var i = 1 ; while ( i <= N ) { ans += Math . floor ( N / i ) ; i = i * K ; } document . write ( ans ) ; } var N = 10 , K = 2 ; findSum ( N , K ) ;

Accumulator variables: ans
Javascript program:
function countAPs ( S , D ) { S = S * 2 ; let answer = 0 ; for ( let i = 1 ; i <= Math . sqrt ( S ) ; i ++ ) { if ( S % i == 0 ) { if ( ( ( S / i ) - D * i + D ) % 2 == 0 ) answer ++ ; if ( ( D * i - ( S / i ) + D ) % 2 == 0 ) answer ++ ; } } return answer ; } let S = 12 , D = 1 ; document . write ( countAPs ( S , D ) ) ;

Accumulator variables: answer, i
Iterator variables: i
Javascript program:
function minimumInsertions ( arr , N , K ) { var possible = true ; var res = 0 ; var last = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= K ) { possible = false ; break ; } if ( last + arr [ i ] > K ) res ++ ; last = arr [ i ] ; } if ( possible ) { document . write ( res ) ; } else { document . write ( " " ) ; } } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var K = 6 ; var N = arr . length ; minimumInsertions ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Boolean variables: possible