dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findNumber ( s , d ) { var num = [ ] ; var val = parseInt ( s / d ) ; var rem = s % d ; for ( var i = 1 ; i <= d - rem ; i ++ ) { num . push ( val . toString ( ) ) ; } if ( rem != 0 ) { val ++ ; for ( var i = d - rem + 1 ; i <= d ; i ++ ) { num . push ( val . toString ( ) ) ; } } return num ; } var s = 25 , d = 4 ; var n = findNumber ( s , d ) ; for ( var i = 0 ; i < n . length ; i ++ ) { document . write ( n [ i ] ) ; }

Index/key variables: i
Accumulator variables: i, val
Iterator variables: i
Javascript program:
function kthSmallest ( a , k ) { var res = 0 ; var j = 0 ; for ( var i = 0 ; i < 32 ; i ++ ) { while ( j < 32 && ( a & ( 1 << j ) ) ) j ++ ; if ( k & ( 1 << i ) ) res |= ( 1 << j ) ; j ++ ; } return res ; } var a = 10 , k = 3 ; document . write ( kthSmallest ( a , k ) ) ;

Accumulator variables: i, j, res
Iterator variables: i
Javascript program:
function fastmod ( base , exp , mod ) { if ( exp == 0 ) return 1 ; else if ( exp % 2 == 0 ) { var ans = fastmod ( base , exp / 2 , mod ) ; return ( ans % mod * ans % mod ) % mod ; } else return ( fastmod ( base , exp - 1 , mod ) % mod * base % mod ) % mod ; } function countSetBits ( n ) { var count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function findPowerSum ( n , ar ) { var mod = parseInt ( 1e9 + 7 ) ; var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { var base = countSetBits ( ar [ i ] ) ; var exp = ar [ i ] ; sum += fastmod ( base , exp , mod ) ; sum %= mod ; } return sum ; } var n = 3 ; var ar = [ 1 , 2 , 3 ] ; document . write ( findPowerSum ( n , ar ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function CountTriangles ( n ) { var curr = 1 ; var Tri_count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { Tri_count = ( curr * 3 ) + 2 ; curr = Tri_count ; } return Tri_count ; } var n = 10 ; document . write ( CountTriangles ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sub_arrays ( a , n , k ) { let sum = new Array ( n + 2 ) ; for ( let i = 0 ; i < n + 2 ; i ++ ) { sum [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { a [ i ] -- ; a [ i ] %= k ; sum [ i + 1 ] += sum [ i ] + a [ i ] ; sum [ i + 1 ] %= k ; } let ans = 0 , l = 0 , r = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { if ( ! mp . has ( sum [ i ] ) ) mp . set ( sum [ i ] , 0 ) ; } let temp ; for ( let i = 0 ; i < n + 1 ; i ++ ) { ans += mp . get ( sum [ i ] ) ; temp = mp . get ( sum [ i ] ) + 1 ; mp . set ( sum [ i ] , temp ) ; r ++ ; if ( r - l >= k ) { temp = mp . get ( sum [ l ] ) - 1 ; mp . set ( sum [ i ] , temp ) ; l ++ ; } } return ans ; } let a = [ 1 , 4 , 2 , 3 , 5 ] ; let n = a . length ; let k = 4 ; document . write ( sub_arrays ( a , n , k ) ) ;

Index/key variables: i, l
Accumulator variables: ans, i, l, r
Iterator variables: i
Javascript program:
function sieve ( prime , n ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( var p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } function sumPrime ( d ) { var maxVal = Math . pow ( 2 , d ) - 1 ; var prime = new Array ( maxVal + 1 ) ; prime . fill ( true ) ; sieve ( prime , maxVal ) ; var sum = 0 ; for ( var i = 2 ; i <= maxVal ; i ++ ) { if ( prime [ i ] ) { sum += i ; } } return sum ; } var d = 8 ; document . write ( sumPrime ( d ) ) ;

Index/key variables: i, p
Accumulator variables: i, p, sum
Iterator variables: i, p
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function isPossible ( arr , n , p ) { let gcd = 0 ; for ( let i = 0 ; i < n ; i ++ ) gcd = __gcd ( gcd , arr [ i ] ) ; if ( p % gcd == 0 ) return true ; return false ; } let arr = [ 6 , 9 ] ; let n = arr . length ; let p = 3 ; if ( isPossible ( arr , n , p ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function generateArr ( arr , n ) { var flip = true ; for ( i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) { if ( flip ^= true ) document . write ( parseInt ( ( Math . ceil ( arr [ i ] / 2.0 ) ) ) + " " ) ; else document . write ( parseInt ( ( Math . floor ( arr [ i ] / 2.0 ) ) ) + " " ) ; } else { document . write ( arr [ i ] / 2 + " " ) ; } } } var arr = [ 3 , - 5 , - 7 , 9 , 2 , - 2 ] ; var n = arr . length ; generateArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: flip, i
Iterator variables: i
Boolean variables: flip
Javascript program:
function binomialCoeff ( n , k ) { var C = new Array ( n + 1 ) ; for ( var i = 0 ; i < C . length ; i ++ ) { C [ i ] = new Array ( k + 1 ) ; } var 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 cntSubSeq ( arr , n , k ) { arr . sort ( ) ; var num = arr [ k - 1 ] ; var Y = 0 ; for ( var i = k - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] == num ) Y += 1 ; } var cntX = Y ; for ( var i = k ; i < n ; i ++ ) { if ( arr [ i ] == num ) cntX += 1 ; } return binomialCoeff ( cntX , Y ) ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var k = 2 ; document . write ( cntSubSeq ( arr , n , k ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: Y, cntX, i, j
Iterator variables: i, j
Javascript program:
function convertToBinary ( num , a , n ) { let pointer = n - 1 ; while ( num > 0 ) { a [ pointer ] = num % 2 ; num = parseInt ( num / 2 ) ; pointer -- ; } } function checkforsum ( a , n ) { let sum1 = 0 ; let sum2 = 0 ; let mid = parseInt ( n / 2 ) ; for ( let i = 0 ; i < mid ; i ++ ) sum1 = sum1 + a [ i ] ; for ( let j = mid ; j < n ; j ++ ) sum2 = sum2 + a [ j ] ; if ( sum1 == sum2 ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( a [ i ] ) ; document . write ( " " ) ; } } function print_seq ( m ) { let n = ( 2 * m ) ; let a = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { a [ j ] = 0 ; } for ( let i = 0 ; i < Math . pow ( 2 , n ) ; i ++ ) { convertToBinary ( i , a , n ) ; checkforsum ( a , n ) ; } } let m = 2 ; print_seq ( m ) ;

Index/key variables: i, j, pointer
Accumulator variables: i, j, pointer
Iterator variables: i, j
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function coprime ( a , b ) { if ( __gcd ( a , b ) == 1 ) return true ; else return false ; } function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n == 2 n == 3 ) return true ; for ( let i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function findNumbers ( a , b , n ) { let possible = true ; if ( ! coprime ( a , b ) ) possible = false ; let c1 = 1 ; let c2 = 1 ; let num1 , num2 ; let st = new Set ( ) ; if ( possible ) { while ( st . size != n ) { num1 = a + ( c1 * b ) ; if ( isPrime ( num1 ) ) { st . add ( num1 ) ; } c1 ++ ; num2 = b + ( c2 * a ) ; if ( isPrime ( num2 ) ) { st . add ( num2 ) ; } c2 ++ ; } st = [ ... st ] . sort ( ( a , b ) => a - b ) for ( let i of st ) document . write ( i + " " ) ; } else document . write ( " " ) ; } let a = 3 ; let b = 5 ; let n = 4 ; findNumbers ( a , b , n ) ;

Accumulator variables: c1, c2, i
Iterator variables: i
Boolean variables: possible
Javascript program:
function findIntegers ( n , a , x , t1 , t2 ) { let flag = true ; for ( let i = 0 ; i < n ; i ++ ) { let temp = Math . pow ( a [ i ] , 2 ) + x ; if ( temp % 10 != t1 && temp % 10 != t2 ) { document . write ( temp + " " ) ; flag = false ; } } if ( flag ) document . write ( " " ) ; } let N = 4 , X = 10 , T1 = 5 , T2 = 6 ; let a = [ 3 , 1 , 4 , 7 ] ; findIntegers ( N , a , X , T1 , T2 ) ; document . write ( " " ) ; N = 4 , X = 2 , T1 = 5 , T2 = 6 ; let b = [ 2 , 18 , 22 , 8 ] ; findIntegers ( N , b , X , T1 , T2 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
const TEN = 10 ; function digitSum ( n ) { let sum = 0 ; while ( n > 0 ) { sum += n % TEN ; n = Math . floor ( n / TEN ) ; } return sum ; } function getNthTerm ( n ) { let sum = digitSum ( n ) ; if ( sum % TEN == 0 ) return ( n * TEN ) ; let extra = TEN - ( sum % TEN ) ; return ( ( n * TEN ) + extra ) ; } function firstNTerms ( n ) { for ( let i = 1 ; i <= n ; i ++ ) document . write ( getNthTerm ( i ) + " " ) ; } let n = 10 ; firstNTerms ( n ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let min1 = Number . MAX_VALUE ; let count = 0 ; function permutation ( str1 , i , n , p ) { if ( i == n ) { let q = parseInt ( str1 ) ; if ( q - p > 0 && q < min1 ) { min1 = q ; count = 1 ; } } else { for ( let j = i ; j <= n ; j ++ ) { str1 = swap ( str1 , i , j ) ; permutation ( str1 , i + 1 , n , p ) ; str1 = swap ( str1 , i , j ) ; } } return min1 ; } function swap ( str , i , j ) { let ch = str . split ( " " ) ; let temp = ch [ i ] ; ch [ i ] = ch [ j ] ; ch [ j ] = temp ; return ( ch ) . join ( " " ) ; } let A = 213 ; let B = 111 ; let str1 = A . toString ( ) ; let len = str1 . length ; let h = permutation ( str1 , 0 , len - 1 , B ) ; if ( count == 1 ) document . write ( h ) ; else document . write ( - 1 ) ;

Index/key variables: i, j
Accumulator variables: j
Iterator variables: j
Javascript program:
function Alcuin ( n ) { let _n = n , ans ; ans = Math . round ( ( _n * _n ) / 12 ) - Math . floor ( _n / 4 ) * Math . floor ( ( _n + 2 ) / 4 ) ; return ans ; } function solve ( n ) { let i = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { document . write ( Alcuin ( i ) + " " ) ; } } let n = 15 ; solve ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( arr , n ) { var b = Array ( n ) . fill ( 0 ) ; var p = 0 ; for ( i = n - 1 ; i >= 0 ; i -- ) { b [ p ] = arr [ i -- ] ; if ( i >= 0 ) b [ n - 1 - p ] = arr [ i ] ; p ++ ; } return b ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var b = solve ( arr , n ) ; document . write ( " " + b . toString ( ) + " " ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i
Javascript program:
function productsDistinct ( N ) { var s = " " ; while ( N ) { s += String . fromCharCode ( N % 10 + ' ' . charCodeAt ( 0 ) ) ; N = parseInt ( N / 10 ) ; } s = s . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; var sz = s . length ; var se = new Set ( ) ; for ( var i = 0 ; i < sz ; i ++ ) { var product = 1 ; for ( var j = i ; j < sz ; j ++ ) { product *= ( s [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; if ( se . has ( product ) ) return false ; else se . add ( product ) ; } } return true ; } var N = 2345 ; if ( productsDistinct ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: j
Accumulator variables: i, j, product, s
Iterator variables: i, j
Javascript program:
function findSmallestNonZeroY ( A_num ) { let A_binary = ( A_num >>> 0 ) . toString ( 2 ) ; let B = 1 ; let len = A_binary . length ; let no_ones = bitCount ( A_num ) ; if ( len == no_ones ) { return A_num + 1 ; } for ( let i = 0 ; i < len ; i ++ ) { let ch = A_binary [ len - i - 1 ] ; if ( ch == ' ' ) { B = Math . floor ( Math . pow ( 2.0 , i ) ) ; break ; } } return B ; } function bitCount ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let X = findSmallestNonZeroY ( 10 ) ; document . write ( X ) ;

Accumulator variables: i, setBits
Iterator variables: i
Javascript program:
function maxElement ( a , n ) { if ( n < 3 ) return - 1 ; let maxElement = a [ 0 ] ; let maxProd = a [ n - 1 ] * a [ 1 ] ; for ( let i = 1 ; i < n ; i ++ ) { let currProd = a [ i - 1 ] * a [ ( i + 1 ) % n ] ; if ( currProd > maxProd ) { maxProd = currProd ; maxElement = a [ i ] ; } else if ( currProd == maxProd ) { maxElement = Math . max ( maxElement , a [ i ] ) ; } } return maxElement ; } let a = [ 5 , 6 , 4 , 3 , 2 ] ; let n = a . length ; document . write ( maxElement ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function ncr ( n , r ) { let ans = 1 ; for ( let i = 1 ; i <= r ; i += 1 ) { ans *= ( n - r + i ) ; ans = parseInt ( ans / i ) ; } return ans ; } function totalWays ( X , Y , M , W ) { return ( ncr ( M , X ) * ncr ( W , Y ) ) ; } let X = 4 , Y = 3 , M = 6 , W = 5 ; document . write ( totalWays ( X , Y , M , W ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function specialSieve ( n ) { let cnt = 0 ; let prime = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) prime [ i ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( ! prime [ i ] ) { cnt ++ ; for ( let j = i ; j <= n ; j += i ) prime [ j ] = cnt ; } } for ( let i = 2 ; i <= n ; i ++ ) document . write ( prime [ i ] + " " ) ; } let n = 6 ; specialSieve ( n ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
let maximum = Number . MIN_VALUE , x , ans = Number . MAX_VALUE ; let graph = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { graph [ i ] = [ ] ; } let weight = [ ] ; function __builtin_popcount ( x ) { let c = 0 ; for ( let i = 0 ; i < 60 ; i ++ ) if ( ( ( x >> i ) & 1 ) != 0 ) c ++ ; return c ; } function dfs ( node , parent ) { let a = __builtin_popcount ( weight [ node ] + x ) ; if ( maximum < a ) { maximum = a ; ans = node ; } else if ( maximum == a ) ans = Math . min ( ans , node ) ; for ( let i = 0 ; i < graph [ node ] . length ; i ++ ) { if ( graph [ node ] [ i ] == parent ) continue ; dfs ( graph [ node ] [ i ] , node ) ; } } x = 15 ; weight . push ( 0 ) ; weight . push ( 5 ) ; weight . push ( 10 ) ; ; weight . push ( 11 ) ; ; weight . push ( 8 ) ; weight . push ( 6 ) ; graph [ 1 ] . push ( 2 ) ; graph [ 2 ] . push ( 3 ) ; graph [ 2 ] . push ( 4 ) ; graph [ 1 ] . push ( 5 ) ; dfs ( 1 , 1 ) ; document . write ( ans ) ;

Index/key variables: i, node
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function count_pairs ( a , b , n , m ) { var odd1 = 0 , even1 = 0 ; var odd2 = 0 , even2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) odd1 ++ ; else even1 ++ ; } for ( i = 0 ; i < m ; i ++ ) { if ( b [ i ] % 2 == 1 ) odd2 ++ ; else even2 ++ ; } var pairs = Math . min ( odd1 , odd2 ) + Math . min ( even1 , even2 ) ; return pairs ; } var a = [ 9 , 14 , 6 , 2 , 11 ] ; var b = [ 8 , 4 , 7 , 20 ] ; var n = a . length ; var m = b . length ; document . write ( count_pairs ( a , b , n , m ) ) ;

Index/key variables: i
Accumulator variables: even1, even2, i, odd1, odd2
Iterator variables: i
Javascript program:
function solve ( array , N ) { let Arraynew = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { Arraynew [ i ] = Math . log ( array [ i ] ) ; } let prefixsum = new Array ( N ) ; prefixsum [ 0 ] = Arraynew [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { prefixsum [ i ] = prefixsum [ i - 1 ] + Arraynew [ i ] ; } let answer = 0 ; let minabs = Math . abs ( prefixsum [ N - 1 ] - 2 * prefixsum [ 0 ] ) ; for ( let i = 1 ; i < N - 1 ; i ++ ) { let ans1 = Math . abs ( prefixsum [ N - 1 ] - 2 * prefixsum [ i ] ) ; if ( ans1 < minabs ) { minabs = ans1 ; answer = i ; } } document . write ( " " + answer + " " ) ; } let array = [ 1 , 4 , 12 , 2 , 6 ] ; let N = 5 ; solve ( array , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getValueOfF ( n ) { if ( n == 1 ) return 0 ; if ( n == 2 ) return 1 ; let cnt = 0 ; while ( n % 2 == 0 ) { cnt += 1 ; n = parseInt ( n / 2 , 10 ) ; } return 2 * cnt ; } let n = 20 ; document . write ( getValueOfF ( n ) ) ;

Accumulator variables: cnt
Javascript program:
let N = 100005 ; let mod = 1000000007 ; let cnt = new Array ( N ) ; cnt . fill ( 0 ) ; function Divisors ( ) { for ( let i = 1 ; i < N ; i ++ ) { for ( let j = 1 ; j * i < N ; j ++ ) { cnt [ i * j ] ++ ; } } } function Sumofdivisors ( A , B , C ) { let sum = 0 ; Divisors ( ) ; for ( let i = 1 ; i <= A ; i ++ ) { for ( let j = 1 ; j <= B ; j ++ ) { for ( let k = 1 ; k <= C ; k ++ ) { let x = i * j * k ; sum += cnt [ x ] ; if ( sum >= mod ) { sum -= mod ; } } } } return sum ; } let A = 5 , B = 6 , C = 7 ; document . write ( Sumofdivisors ( A , B , C ) ) ;

Index/key variables: x
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Javascript program:
function A_mod_B ( N , a ) { var len = N . length ; var ans = 0 ; for ( var i = 0 ; i < len ; i ++ ) ans = ( ans * 10 + parseInt ( N . charAt ( i ) - ' ' ) ) % a ; return ans % a ; } function findMod ( N ) { var mod = A_mod_B ( N , 4 ) ; var ans = ( 1 + parseInt ( Math . pow ( 2 , mod ) + Math . pow ( 3 , mod ) + Math . pow ( 4 , mod ) ) ) ; return ( ans % 5 ) ; } var N = " " ; document . write ( findMod ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printElements ( arr , n ) { for ( var i = 1 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] && arr [ i ] > arr [ i + 1 ] ) document . write ( arr [ i ] + " " ) ; } } var arr = [ 2 , 3 , 1 , 5 , 4 , 9 , 8 , 7 , 5 ] ; var n = arr . length ; printElements ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPrime ( x ) { for ( let i = 2 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) return 0 ; } return 1 ; } function minimumCost ( n ) { if ( isPrime ( n ) ) return 1 ; if ( n % 2 == 1 && isPrime ( n - 2 ) ) return 2 ; if ( n % 2 == 0 ) return 2 ; return 3 ; } let n = 6 ; document . write ( minimumCost ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 100001 ; prefix = Array ( MAX ) . fill ( 0 ) function sieve_modified ( ) { for ( var i = 1 ; i < MAX ; i += 2 ) { for ( var j = i ; j < MAX ; j += i ) prefix [ j ] += i ; } for ( var i = 1 ; i < MAX ; i ++ ) prefix [ i ] += prefix [ i - 1 ] ; } function sumOddFactors ( L , R ) { return ( prefix [ R ] - prefix [ L - 1 ] ) ; } sieve_modified ( ) ; var l = 6 , r = 10 ; document . write ( sumOddFactors ( l , r ) ) ;

Index/key variables: R, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var n = 3 ; function preComputeXor ( arr , prefix_xor ) { for ( i = 0 ; i < n ; i ++ ) for ( j = 0 ; j < n ; j ++ ) { if ( j == 0 ) prefix_xor [ i ] [ j ] = arr [ i ] [ j ] ; else prefix_xor [ i ] [ j ] = ( prefix_xor [ i ] [ j - 1 ] ^ arr [ i ] [ j ] ) ; } for ( i = 0 ; i < n ; i ++ ) for ( j = 1 ; j < n ; j ++ ) prefix_xor [ j ] [ i ] = ( prefix_xor [ j - 1 ] [ i ] ^ prefix_xor [ j ] [ i ] ) ; } function ansQuerie ( prefix_xor , x1 , y1 , x2 , y2 ) { var xor_1 = 0 , xor_2 = 0 , xor_3 = 0 ; if ( x1 != 0 ) xor_1 = prefix_xor [ x1 - 1 ] [ y2 ] ; if ( y1 != 0 ) xor_2 = prefix_xor [ x2 ] [ y1 - 1 ] ; if ( x1 != 0 && y1 != 0 ) xor_3 = prefix_xor [ x1 - 1 ] [ y1 - 1 ] ; return ( ( prefix_xor [ x2 ] [ y2 ] ^ xor_1 ) ^ ( xor_2 ^ xor_3 ) ) ; } var arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; var prefix_xor = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) prefix_xor [ i ] = Array ( n ) . fill ( 0 ) ; preComputeXor ( arr , prefix_xor ) ; document . write ( ansQuerie ( prefix_xor , 1 , 1 , 2 , 2 ) + " " ) ; document . write ( ansQuerie ( prefix_xor , 1 , 2 , 2 , 2 ) ) ;

Index/key variables: i, j, x2, y2
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isDigitSumOne ( nm ) { if ( nm % 9 == 1 ) return true ; else return false ; } function printValidNums ( n ) { let cbrt_n = Math . ceil ( Math . pow ( n , 1 / 3 ) ) ; for ( let i = 1 ; i <= cbrt_n ; i ++ ) { let cube = Math . pow ( i , 3 ) ; if ( cube >= 1 && cube <= n && isDigitSumOne ( cube ) ) document . write ( cube + " " ) ; } } let n = 1000 ; printValidNums ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countRhombi ( h , w ) { let ct = 0 ; for ( let i = 2 ; i <= h ; i += 2 ) for ( let j = 2 ; j <= w ; j += 2 ) ct += ( h - i + 1 ) * ( w - j + 1 ) ; return ct ; } let h = 2 , w = 2 ; document . write ( countRhombi ( h , w ) ) ;

Accumulator variables: ct, i, j
Iterator variables: i, j
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function getWinner ( arr , n ) { let gcd = arr [ 0 ] ; let maxEle = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { gcd = __gcd ( gcd , arr [ i ] ) ; maxEle = Math . max ( maxEle , arr [ i ] ) ; } let totalMoves = parseInt ( maxEle / gcd , 10 ) - n ; if ( totalMoves % 2 == 1 ) return ' ' ; return ' ' ; } let arr = [ 5 , 6 , 7 ] ; let n = arr . length ; document . write ( getWinner ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPairs ( n ) { let num = ( parseInt ( n / 2 , 10 ) + 1 ) ; let max = n % num ; let count = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { let val = ( ( n % i ) % j ) % n ; if ( val == max ) count ++ ; } } return count ; } let n = 5 ; document . write ( countPairs ( n ) ) ;

Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function sum ( n ) { let i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } let n = 5 ; document . write ( " " + sum ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var N = 100005 ; function ABUNDANT ( ) { var v = new Set ( ) ; var i , j ; for ( i = 1 ; i < N ; i ++ ) { var sum = 1 ; for ( j = 2 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { sum += j ; if ( parseInt ( i / j ) != j ) sum += parseInt ( i / j ) ; } } if ( sum > i ) v . add ( i ) ; } return v ; } function SumOfAbundant ( n ) { var v = new Set ( ) ; v = ABUNDANT ( ) ; var i ; for ( i = 1 ; i <= n ; i ++ ) { if ( v . has ( i ) && v . has ( n - i ) ) { document . write ( i + ' ' + ( n - i ) ) return ; } } document . write ( - 1 ) ; } var n = 24 ; SumOfAbundant ( n ) ;

Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function obtain_str ( n ) { let len = Math . floor ( ( Math . log ( n + 1 ) / Math . log ( 2 ) ) ) ; let rel_ind = n + 1 - Math . pow ( 2 , len ) ; let i = 0 ; let str = [ ] ; for ( i = 0 ; i < len ; i ++ ) { str . push ( ' ' ) ; } i = 0 ; while ( rel_ind > 0 ) { if ( rel_ind % 2 == 1 ) str [ i ] = ' ' ; rel_ind = parseInt ( rel_ind / 2 , 10 ) ; i ++ ; } return reverse ( str . join ( " " ) ) ; } function reverse ( input ) { let a = input . split ( ' ' ) ; let l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { let temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a . join ( " " ) ; } let n = 11 ; document . write ( obtain_str ( n ) ) ;

Index/key variables: i, l, r
Accumulator variables: i, l, r
Iterator variables: i, l
Javascript program:
function getSum ( n , d ) { let sum = 0 ; while ( d <= n ) { sum += d ; d += 10 ; } return sum ; } let n = 30 ; let d = 3 ; document . write ( getSum ( n , d ) ) ;

Accumulator variables: d, sum
Javascript program:
function sum ( N ) { let MOD = 1000000007 ; let val = N * ( N + 1 ) ; val = val % MOD ; return val ; } function sumX ( N , M , K ) { let MOD = 1000000007 ; for ( let i = 0 ; i < M ; i ++ ) { N = sum ( K + N ) ; } N = N % MOD ; return N ; } let N = 1 ; let M = 2 ; let K = 3 ; document . write ( sumX ( N , M , K ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printMode ( a , n ) { let max = Number . MIN_VALUE ; for ( let i = 0 ; i < a . length ; i ++ ) { max = Math . max ( max , a [ i ] ) ; } let t = max + 1 ; let count = new Array ( t ) ; for ( let i = 0 ; i < t ; i ++ ) count [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) count [ a [ i ] ] ++ ; let mode = 0 ; let k = count [ 0 ] ; for ( let i = 1 ; i < t ; i ++ ) { if ( count [ i ] > k ) { k = count [ i ] ; mode = i ; } } document . write ( " " + mode ) ; } let a = [ 1 , 4 , 1 , 2 , 7 , 1 , 2 , 5 , 3 , 6 ] ; let n = a . length ; printMode ( a , n ) ;

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