dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function sumOfFactors ( n ) { let sum = 0 ; for ( let f = 1 ; f <= n / 2 ; f ++ ) { if ( n % f == 0 ) { sum += f ; } } return sum ; } function getSum ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 && arr [ i ] == sumOfFactors ( arr [ i ] ) ) { sum += arr [ i ] ; } } return sum ; } let arr = [ 17 , 6 , 10 , 6 , 4 ] ; let n = arr . length ; document . write ( getSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: f, i, sum
Iterator variables: f, i
Javascript program:
const N = 2 ; const M = 2 ; function Matrix ( a ) { let ch = ' ' ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( a [ i ] [ j ] == ' ' ) a [ i ] [ j ] = ch ; ch = ( ch == ' ' ) ? ' ' : ' ' ; document . write ( a [ i ] [ j ] + " " ) ; } document . write ( " " ) ; if ( i % 2 == 0 ) ch = ' ' ; else ch = ' ' ; } } let a = [ [ ' ' , ' ' ] , [ ' ' , ' ' ] ] ; Matrix ( a ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let cnt_neg = 0 ; let exists_zero = false ; function preProcess ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 0 ) cnt_neg ++ ; if ( arr [ i ] == 0 ) exists_zero = true ; } } function isPossible ( k ) { if ( ! exists_zero ) { if ( k >= cnt_neg && ( k - cnt_neg ) % 2 == 0 ) return true ; else return false ; } else { if ( k >= cnt_neg ) return true ; else return false ; } } let arr = [ - 1 , 2 , - 3 , 4 , 5 ] ; let n = arr . length ; preProcess ( arr , n ) ; let queries = [ 1 , 2 , 3 , 4 ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) { if ( isPossible ( queries [ i ] ) ) document . write ( " " ) ; else document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: cnt_neg, i
Iterator variables: i
Boolean variables: exists_zero
Javascript program:
function FindXorSum ( arr , k , n ) { if ( n < k ) return 0 ; let x = new Array ( n ) . fill ( 0 ) ; let result = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i > 0 ) x [ i ] = x [ i - 1 ] ^ arr [ i ] ; else x [ i ] = arr [ i ] ; if ( i >= k - 1 ) { let sum = 0 ; sum = x [ i ] ; if ( i - k > - 1 ) sum ^= x [ i - k ] ; result += sum ; } } return result ; } let arr = [ 1 , 2 , 3 , 4 ] ; let n = 4 , k = 2 ; document . write ( FindXorSum ( arr , k , n ) ) ;

Index/key variables: i
Accumulator variables: i, result, sum
Iterator variables: i
Javascript program:
function reverse ( n ) { let rev = 0 ; while ( n > 0 ) { let d = n % 10 ; rev = rev * 10 + d ; n = parseInt ( n / 10 ) ; } return rev ; } function isPalin ( n ) { return ( n == reverse ( n ) ) ; } function countDigits ( n ) { let c = 0 ; while ( n > 0 ) { n = parseInt ( n / 10 ) ; c ++ ; } return c ; } function countPalinDigits ( arr , n ) { let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 10 || isPalin ( arr [ i ] ) ) { s += countDigits ( arr [ i ] ) ; } } return s ; } let arr = [ 121 , 56 , 434 ] ; let n = arr . length ; document . write ( countPalinDigits ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: c, i, s
Iterator variables: i
Javascript program:
function reverse ( n ) { let d = 0 , s = 0 ; while ( n > 0 ) { d = n % 10 ; s = s * 10 + d ; n = Math . floor ( n / 10 ) ; } return s ; } function isPalin ( n ) { return n == reverse ( n ) ; } function sumOfArray ( arr , n ) { let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] > 10 ) && isPalin ( arr [ i ] ) ) { s += arr [ i ] ; } } return s ; } let n = 6 ; let arr = [ 12 , 313 , 11 , 44 , 9 , 1 ] ; document . write ( sumOfArray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
const MAX = 1000000 ; let prime = new Array ( MAX + 1 ) ; function updatePrimes ( ) { for ( let i = 2 ; i <= MAX ; i ++ ) { prime [ i ] = 1 ; } prime [ 0 ] = prime [ 1 ] = 0 ; for ( let i = 2 ; i * i <= MAX ; i ++ ) { if ( prime [ i ] == 1 ) { for ( let j = i * i ; j <= MAX ; j += i ) { prime [ j ] = 0 ; } } } for ( let i = 1 ; i <= MAX ; i ++ ) { prime [ i ] += prime [ i - 1 ] ; } } function getDifference ( l , r ) { let total = r - l + 1 ; let primes = prime [ r ] - prime [ l - 1 ] ; let composites = total - primes ; return ( Math . abs ( primes - composites ) ) ; } let queries = [ [ 1 , 10 ] , [ 5 , 30 ] ] ; let q = queries . length ; updatePrimes ( ) ; for ( let i = 0 ; i < q ; i ++ ) document . write ( getDifference ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ;

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const MAX = 1000000 ; let Sieve = new Array ( MAX ) . fill ( 0 ) ; function constructSieve ( ) { for ( let i = 2 ; i <= MAX ; i ++ ) { if ( Sieve [ i ] == 0 ) { for ( let j = 2 * i ; j <= MAX ; j += i ) { let temp = j ; while ( temp > 1 && temp % i == 0 ) { Sieve [ j ] ++ ; temp = parseInt ( temp / i ) ; } } } } } function checkElements ( A , n , k ) { for ( let i = 0 ; i < n ; i ++ ) { if ( Sieve [ A [ i ] ] == k ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } constructSieve ( ) ; let k = 3 ; let A = [ 12 , 36 , 42 , 72 ] ; let n = A . length ; checkElements ( A , n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function cntWays ( arr , n ) { if ( n == 1 ) return 0 ; var tot_sum = 0 , sum = 0 , ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) tot_sum += arr [ i ] ; for ( var i = 0 ; i < n - 1 ; i ++ ) { sum += arr [ i ] ; if ( sum == tot_sum / 2 ) ans ++ ; } return ans ; } var arr = [ 1 , - 1 , 1 , - 1 , 1 , - 1 ] ; var n = arr . length ; document . write ( cntWays ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i, sum, tot_sum
Iterator variables: i
Javascript program:
const MAX = 32 ; let pow2 = new Array ( MAX ) ; let visited = new Array ( MAX ) ; let ans = [ ] ; function power_2 ( ) { let ans = 1 ; for ( let i = 0 ; i < MAX ; i ++ ) { pow2 [ i ] = ans ; ans *= 2 ; } } function countSetBits ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } function add ( num ) { let point = 0 ; let value = 0 ; for ( let i = 0 ; i < MAX ; i ++ ) { if ( visited [ i ] ) continue ; else { if ( num & 1 ) { value += ( 1 << i ) ; } num = parseInt ( num / 2 ) ; } } ans . push ( value ) ; } function solve ( n , k ) { ans . push ( k ) ; let countk = countSetBits ( k ) ; if ( pow2 [ countk ] < n ) { document . write ( - 1 ) ; return ; } let count = 0 ; for ( let i = 0 ; i < pow2 [ countk ] - 1 ; i ++ ) { add ( i ) ; count ++ ; if ( count == n ) break ; } for ( let i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let n = 3 , k = 5 ; power_2 ( ) ; solve ( n , k ) ;

Index/key variables: countk, i
Accumulator variables: ans, count, i, setBits, value
Iterator variables: i
Javascript program:
function countX ( a , b ) { if ( b > a ) return 0 ; else if ( a == b ) return - 1 ; else { let x = a - b , ans = 0 ; for ( let i = 1 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) { let d1 = i , d2 = b - 1 ; if ( i * i != x ) d2 = parseInt ( x / i ) ; if ( d1 > b ) ans ++ ; if ( d2 > b ) ans ++ ; } } return ans ; } } let a = 21 , b = 5 ; document . write ( countX ( a , b ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function sumPowersK ( n , k ) { var sum = 0 , num = 1 ; while ( num <= n ) { sum += num ; num *= k ; } return sum ; } function getSum ( n , k ) { var pwrK = sumPowersK ( n , k ) ; var sumAll = ( n * ( n + 1 ) ) / 2 ; return ( sumAll - pwrK ) ; } var n = 10 , k = 3 ; document . write ( getSum ( n , k ) ) ;

Accumulator variables: num, sum
Javascript program:
function maxPeople ( p ) { var tmp = 0 , count = 0 ; for ( var i = 1 ; i * i <= p ; i ++ ) { tmp = tmp + ( i * i ) ; if ( tmp <= p ) count ++ ; else break ; } return count ; } var p = 14 ; document . write ( maxPeople ( p ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
const kN = 1000000 ; function maxPeople ( p ) { let sums = new Array ( kN ) ; sums [ 0 ] = 0 ; for ( let i = 1 ; i < kN ; i ++ ) sums [ i ] = ( i * i ) + sums [ i - 1 ] ; let it = lower_bound ( sums , 0 , kN , p ) ; if ( it > p ) { -- it ; } return it ; } function lower_bound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } let p = 14 ; document . write ( maxPeople ( p ) ) ;

Index/key variables: i, middle
Accumulator variables: i
Iterator variables: i
Javascript program:
function findIndex ( a , n , k ) { var index = - 1 , max_ceil = Number . MIN_VALUE ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = ( a [ i ] + k - 1 ) / k ; } for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= max_ceil ) { max_ceil = a [ i ] ; index = i ; } } return index ; } var arr = [ 31 , 12 , 25 , 27 , 32 , 19 ] ; var K = 5 ; var N = arr . length ; document . write ( findIndex ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var MAXN = 60 ; function solveQuery ( L , X ) { var res ; var a = Array ( MAXN ) , b = Array ( L ) ; var ref = X , size_a = 0 ; while ( ref > 0 ) { a [ size_a ] = ref % 2 ; ref = parseInt ( ref / 2 ) ; size_a ++ ; } for ( var i = 0 ; i < Math . min ( size_a , L ) ; i ++ ) { if ( a [ i ] == 1 ) b [ i ] = 0 ; else b [ i ] = 1 ; } for ( var i = Math . min ( size_a , L ) ; i < L ; i ++ ) b [ i ] = 1 ; b [ L - 1 ] = 1 ; var temp = 0 , p = 1 ; for ( var i = 0 ; i < L ; i ++ ) { temp += b [ i ] * p ; p *= 2 ; } res = temp ^ X ; return res ; } var queries = [ [ 2 , 5 ] , [ 3 , 15 ] ] ; var q = queries . length ; for ( var i = 0 ; i < q ; i ++ ) document . write ( solveQuery ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ;

Index/key variables: i, size_a
Accumulator variables: i, p, size_a, temp
Iterator variables: i
Javascript program:
function Count_Segment ( p , n ) { var count = 0 ; var upto = Array ( n + 1 ) . fill ( 0 ) ; for ( i = 0 ; i < n + 1 ; i ++ ) upto [ i ] = 0 ; var j = 0 , curr = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( p [ i ] > p [ i - 1 ] && p [ i ] > p [ i + 1 ] ) { curr = p [ i ] ; j = i - 1 ; while ( j >= 0 && p [ j ] < curr ) { upto [ p [ j ] ] = curr ; j -= 1 ; } j = i + 1 ; while ( j < n && p [ j ] < curr ) { if ( upto [ curr - p [ j ] ] == curr ) count += 1 ; j += 1 ; } } } return count ; } var p = [ 3 , 4 , 1 , 5 , 2 ] ; var n = p . length ; document . write ( Count_Segment ( p , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i
Javascript program:
function closetAND ( arr , n , k ) { let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { let X = arr [ i ] ; for ( let j = i ; j < n ; j ++ ) { X &= arr [ j ] ; ans = Math . min ( ans , Math . abs ( k - X ) ) ; } } return ans ; } let arr = [ 4 , 7 , 10 ] ; let n = arr . length ; let k = 2 ; document . write ( closetAND ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: X, i, j
Iterator variables: i, j
Javascript program:
function getPrime ( arr , n ) { let max_val = Math . max ( ... arr ) ; let prime = new Array ( max_val + 1 ) . fill ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } let maximum = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) maximum = Math . max ( maximum , arr [ i ] ) ; } return maximum ; } let arr = [ 2 , 10 , 15 , 7 , 6 , 8 , 13 ] ; let n = arr . length ; document . write ( getPrime ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function getMinNum ( N ) { var lcm = 1 ; for ( var i = 2 ; i <= N ; i ++ ) lcm = ( ( i * lcm ) / ( __gcd ( i , lcm ) ) ) ; return ( lcm + 1 ) ; } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } var N = 5 ; document . write ( getMinNum ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isSafe ( N , M , str ) { var coll = 0 , colr = 0 , rowu = 0 , rowd = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { coll ++ ; if ( colr > 0 ) { colr -- ; } if ( coll == M ) { break ; } } else if ( str [ i ] == ' ' ) { colr ++ ; if ( coll > 0 ) { coll -- ; } if ( colr == M ) { break ; } } else if ( str [ i ] == ' ' ) { - rowu ++ ; if ( rowd > 0 ) { rowd -- ; } if ( rowu == N ) { break ; } } else if ( str [ i ] == ' ' ) { rowd ++ ; if ( rowu > 0 ) { rowu -- ; } if ( rowd == N ) { break ; } } } if ( Math . abs ( rowd ) < N && Math . abs ( rowu ) < N && Math . abs ( coll ) < M && Math . abs ( colr ) < M ) { return true ; } return false ; } var N = 1 , M = 1 ; var str = " " ; if ( isSafe ( N , M , str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: coll, colr, i, rowd, rowu
Iterator variables: i
Javascript program:
function Permutation ( n , k ) { let p = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) p [ i ] = i ; for ( let i = 1 ; i < n - k ; i ++ ) p [ i + 1 ] = i ; p [ 1 ] = n - k ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( p [ i ] + " " ) ; } let n = 5 , k = 2 ; Permutation ( n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countOnes ( arr , N ) { for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = i ; j <= N ; j ++ ) { if ( j % i == 0 ) { if ( arr [ j - 1 ] == 0 ) arr [ j - 1 ] = 1 ; else arr [ j - 1 ] = 0 ; } } } let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) if ( arr [ i ] == 1 ) count ++ ; return count ; } let N = 10 ; let arr = new Uint8Array ( 10 ) ; let ans = countOnes ( arr , N ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function validPosition ( arr , N , K ) { var count = 0 , sum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } for ( var i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] + K ) > ( sum - arr [ i ] ) ) count ++ ; } return count ; } var arr = [ 2 , 1 , 6 , 7 ] , K = 4 ; var N = arr . length ; document . write ( validPosition ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function count_unique ( s , n ) { if ( s . has ( n ) ) return ; s . add ( n ) ; n += 1 ; while ( n % 10 == 0 ) { n = Math . floor ( n / 10 ) ; } count_unique ( s , n ) ; } let n = 10 ; let s = new Set ( ) ; count_unique ( s , n ) ; document . write ( s . size ) ;

Accumulator variables: n
Javascript program:
function maxBitElement ( arr , n ) { let num = 0 , max = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { let cnt = BitCount ( arr [ i ] ) ; if ( cnt > max ) { max = cnt ; num = arr [ i ] ; } } return num ; } function BitCount ( n ) { let count = 0 ; while ( n != 0 ) { count ++ ; n &= ( n - 1 ) ; } return count ; } let arr = [ 3 , 2 , 4 , 7 , 1 , 10 , 5 , 8 , 9 , 6 ] ; let n = arr . length ; document . write ( maxBitElement ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i, n
Iterator variables: i
Javascript program:
var N = 1000 ; function countPairs ( arr , n ) { var size = ( 2 * N ) + 1 ; var freq = Array ( size ) . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { var x = arr [ i ] ; freq [ x + N ] ++ ; } var ans = 0 ; for ( i = 0 ; i < size ; i ++ ) { if ( freq [ i ] > 0 ) { ans += ( ( freq [ i ] ) * ( freq [ i ] - 1 ) ) / 2 ; for ( j = i + 2 ; j < 2001 ; j += 2 ) { if ( freq [ j ] > 0 && ( freq [ ( i + j ) / 2 ] > 0 ) ) { ans += ( freq [ i ] * freq [ j ] ) ; } } } } return ans ; } var arr = [ 4 , 2 , 5 , 1 , 3 , 5 ] ; var n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function count_pairs ( a , b , n , m ) { let odd1 = 0 , even1 = 0 ; let odd2 = 0 , even2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 ) odd1 ++ ; else even1 ++ ; } for ( let i = 0 ; i < m ; i ++ ) { if ( b [ i ] % 2 ) odd2 ++ ; else even2 ++ ; } let pairs = Math . min ( odd1 , even2 ) + Math . min ( odd2 , even1 ) ; return pairs ; } let a = [ 9 , 14 , 6 , 2 , 11 ] ; let b = [ 8 , 4 , 7 , 20 ] ; let n = a . length ; let 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 find_leftmost_unsetbit ( n ) { let ind = - 1 ; let i = 1 ; while ( n ) { if ( ! ( n & 1 ) ) ind = i ; i ++ ; n >>= 1 ; } return ind ; } function perform_steps ( n ) { let left = find_leftmost_unsetbit ( n ) ; if ( left == - 1 ) { document . write ( " " ) ; return ; } let step = 1 ; while ( find_leftmost_unsetbit ( n ) != - 1 ) { if ( step % 2 == 0 ) { n += 1 ; document . write ( " " + step + " " ) ; } else { let m = find_leftmost_unsetbit ( n ) ; let num = Math . pow ( 2 , m ) - 1 ; n = n ^ num ; document . write ( " " + step + " " + num + " " ) ; } step += 1 ; } } let n = 39 ; perform_steps ( n ) ;

Accumulator variables: i, n, step
Javascript program:
function vertices ( N , A , B ) { var position = 0 ; var minisum = Number . MAX_VALUE ; var sum = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( i == A i == B ) continue ; else { var x = Math . abs ( i - A ) ; var y = Math . abs ( i - B ) ; sum = x + y ; if ( sum < minisum ) { minisum = sum ; position = i ; } } } return position ; } var N = 3 , A = 1 , B = 2 ; document . write ( " " + vertices ( N , A , B ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function factorial ( n ) { let f = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { f *= i ; } return f ; } function sumFactorial ( arr , n ) { let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { s += factorial ( arr [ i ] ) ; } return s ; } let arr = [ 7 , 3 , 5 , 4 , 8 ] ; let n = arr . length ; document . write ( sumFactorial ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: f, i, s
Iterator variables: i
Javascript program:
let ans = 0 ; let gr = [ ] ; function Add_Edge ( u , v ) { gr [ u ] . push ( v ) ; gr [ v ] . push ( u ) ; } function dfs ( child , par , color ) { if ( color [ child ] != color [ par ] ) ans ++ ; for ( let i = 0 ; i < gr [ child ] . length ; i ++ ) { if ( gr [ child ] [ i ] == par ) continue ; dfs ( gr [ child ] [ i ] , child , color ) ; } } for ( let i = 0 ; i <= 10 ; i ++ ) gr . push ( [ ] ) ; let color = [ 0 , 1 , 2 , 3 , 2 , 2 , 3 ] ; Add_Edge ( 1 , 2 ) ; Add_Edge ( 1 , 3 ) ; Add_Edge ( 2 , 4 ) ; Add_Edge ( 2 , 5 ) ; Add_Edge ( 3 , 6 ) ; dfs ( 1 , 0 , color ) ; document . write ( ans ) ;

Index/key variables: child, i, par, u, v
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function highestPower ( str , len ) { let ans = 0 ; for ( let i = len - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) ans ++ ; else break ; } return ans ; } let str = " " ; let len = str . length ; document . write ( highestPower ( str , len ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var mod = parseInt ( 1e4 + 7 ) ; function factorial ( n , p ) { for ( var i = 2 ; i <= n ; i ++ ) res = ( res * i ) % p ; return res ; } function power ( x , y , p ) { while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function modInverse ( n , p ) { return power ( n , p - 2 , p ) ; } function nCrModP ( n , r , p ) { if ( r == 0 ) return 1 ; var fac = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; ; fac [ 0 ] = 1 ; for ( var i = 1 ; i <= n ; i ++ ) fac [ i ] = fac [ i - 1 ] * i % p ; return ( fac [ parseInt ( n ) ] * modInverse ( fac [ parseInt ( r ) ] , p ) % p * modInverse ( fac [ parseInt ( n ) - parseInt ( r ) ] , p ) % p ) % p ; } function countArrangements ( n , k , p ) { return ( factorial ( n , p ) * nCrModP ( k , n , p ) ) % p ; } var N = 5 , K = 8 ; document . write ( countArrangements ( N , K , mod ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 2 ; let M = 3 ; function check ( mat ) { let xorr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { xorr ^= mat [ i ] [ 0 ] ; } if ( xorr != 0 ) return true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 1 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] != mat [ i ] [ 0 ] ) return true ; } } return false ; } let mat = [ [ 7 , 7 , 7 ] , [ 10 , 10 , 7 ] ] ; if ( check ( mat ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, xorr
Iterator variables: i, j
Javascript program:
function sumodd ( n ) { return ( n * n ) ; } function sumeven ( n ) { return ( n * ( n + 1 ) ) ; } function findSum ( num ) { let sumo = 0 ; let sume = 0 ; let x = 1 ; let cur = 0 ; let ans = 0 ; while ( num > 0 ) { let inc = Math . min ( x , num ) ; num -= inc ; if ( cur == 0 ) { ans = ans + sumodd ( sumo + inc ) - sumodd ( sumo ) ; sumo += inc ; } else { ans = ans + sumeven ( sume + inc ) - sumeven ( sume ) ; sume += inc ; } x *= 2 ; cur ^= 1 ; } return ans ; } let n = 4 ; document . write ( findSum ( n ) ) ;

Accumulator variables: cur, num, sume, sumo, x
Javascript program:
let N = 3 ; let M = 7 ; function printOriginalMatrix ( a , b , mat ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) document . write ( Math . min ( a [ i ] , b [ j ] ) + " " ) ; else document . write ( " " + " " ) ; } document . write ( " " ) ; } } let a = [ 2 , 1 , 3 ] ; let b = [ 2 , 3 , 0 , 0 , 2 , 0 , 1 ] ; let mat = [ [ 1 , 0 , 0 , 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 1 ] , [ 1 , 1 , 0 , 0 , 0 , 0 , 0 ] ] ; printOriginalMatrix ( a , b , mat ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function percent ( n , x ) { let p = n * x ; p = Math . floor ( p / 100 ) ; return p ; } function getLoss ( price , quantity , X , n ) { let loss = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let originalPrice = price [ i ] ; let sellingPrice = originalPrice + percent ( originalPrice , X [ i ] ) ; let afterDiscount = sellingPrice - percent ( sellingPrice , X [ i ] ) ; loss += ( ( originalPrice - afterDiscount ) * quantity [ i ] ) ; } return loss ; } let price = [ 20 , 48 , 200 , 100 ] ; let quantity = [ 20 , 48 , 1 , 1 ] ; let X = [ 0 , 48 , 200 , 5 ] ; let n = X . length ; document . write ( getLoss ( price , quantity , X , n ) ) ;

Index/key variables: i
Accumulator variables: i, loss
Iterator variables: i
Javascript program:
function maxAbsDiff ( arr , n ) { let minEle = arr [ 0 ] ; let maxEle = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { minEle = Math . min ( minEle , arr [ i ] ) ; maxEle = Math . max ( maxEle , arr [ i ] ) ; } return ( maxEle - minEle ) ; } let arr = [ 2 , 1 , 5 , 3 ] ; let n = arr . length ; document . write ( maxAbsDiff ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubArraySum ( a , size ) { let max_so_far = Number . MIN_VALUE , max_ending_here = 0 ; for ( let i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } function maximizeSum ( a , n ) { let cnt = 0 ; let mini = Number . MAX_VALUE ; let minSubarray = Number . MAX_VALUE ; let sum = maxSubArraySum ( a , n ) ; let max_so_far = Number . MIN_VALUE , max_ending_here = 0 ; for ( let i = 0 ; i < n ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; cnt ++ ; minSubarray = Math . min ( a [ i ] , minSubarray ) ; if ( sum == max_ending_here ) { if ( cnt == 1 ) mini = Math . min ( mini , 0 ) ; else mini = Math . min ( mini , minSubarray ) ; } if ( max_ending_here < 0 ) { max_ending_here = 0 ; cnt = 0 ; minSubarray = Integer . MAX_VALUE ; } } return sum - mini ; } let a = [ 1 , 2 , 3 , - 2 , 3 ] ; let n = a . length ; document . write ( maximizeSum ( a , n ) ) ;

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