dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function build ( tree , arr , start , end , index ) { if ( start == end ) { if ( start % 2 == 0 ) { tree [ index ] = arr [ start ] ; } else { tree [ index ] = - arr [ start ] ; } return ; } var mid = start + parseInt ( ( end - start ) / 2 ) ; build ( tree , arr , start , mid , 2 * index + 1 ) ; build ( tree , arr , mid + 1 , end , 2 * index + 2 ) ; tree [ index ] = tree [ 2 * index + 1 ] + tree [ 2 * index + 2 ] ; } function update ( tree , index , start , end , pos , val ) { if ( start == end ) { if ( start % 2 == 0 ) { tree [ index ] = val ; } else { tree [ index ] = - val ; } return ; } var mid = start + parseInt ( ( end - start ) / 2 ) ; if ( mid >= pos ) { update ( tree , 2 * index + 1 , start , mid , pos , val ) ; } else { update ( tree , 2 * index + 2 , mid + 1 , end , pos , val ) ; } tree [ index ] = tree [ 2 * index + 1 ] + tree [ 2 * index + 2 ] ; } function FindSum ( tree , start , end , L , R , index ) { if ( L > end R < start ) { return 0 ; } if ( L <= start && R >= end ) { return tree [ index ] ; } var mid = start + parseInt ( ( end - start ) / 2 ) ; var X = FindSum ( tree , start , mid , L , R , 2 * index + 1 ) ; var Y = FindSum ( tree , mid + 1 , end , L , R , 2 * index + 2 ) ; return X + Y ; } var arr = [ 1 , 2 , 3 , 4 ] ; var N = arr . length ; var tree = Array ( 4 * N + 5 ) . fill ( 0 ) ; build ( tree , arr , 0 , N - 1 , 0 ) ; var Q = [ [ 2 , 0 , 3 ] , [ 1 , 1 , 5 ] , [ 2 , 1 , 2 ] ] ; var cntQuey = 3 ; for ( var i = 0 ; i < cntQuey ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { update ( tree , 0 , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] ) ; } else { if ( Q [ i ] [ 1 ] % 2 == 0 ) { document . write ( FindSum ( tree , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 ) + " " ) ; } else { document . write ( - FindSum ( tree , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 ) + " " ) ; } } }

Index/key variables: i, index, start
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumSubarrays ( arr , n ) { let current = ' ' ; let answer = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( current == ' ' ) { if ( arr [ i ] < arr [ i - 1 ] ) { current = ' ' ; } else if ( arr [ i ] == arr [ i - 1 ] ) { current = ' ' ; } else { current = ' ' ; } } else if ( current == ' ' ) { if ( arr [ i ] >= arr [ i - 1 ] ) { current = ' ' ; } else { current = ' ' ; answer += 1 ; } } else { if ( arr [ i ] <= arr [ i - 1 ] ) { current = ' ' ; } else { current = ' ' ; answer += 1 ; } } } document . write ( answer ) ; } let arr = [ 2 , 3 , 9 , 5 , 4 , 6 , 8 ] ; let n = arr . length ; minimumSubarrays ( arr , n ) ;

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Javascript program:
function ConstMatrix ( mat , N , M , A , B ) { if ( N * M != A * B ) return ; let idx = 0 ; let res = new Array ( A ) ; for ( var i = 0 ; i < res . length ; i ++ ) { res [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { res [ Math . floor ( idx / B ) ] [ idx % B ] = mat [ i ] [ j ] ; idx ++ ; } } for ( let i = 0 ; i < A ; i ++ ) { for ( let j = 0 ; j < B ; j ++ ) document . write ( res [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } let mat = [ [ 1 , 2 , 3 , 4 , 5 , 6 ] ] ; let A = 2 ; let B = 3 ; let N = mat . length ; let M = mat [ 0 ] . length ; ConstMatrix ( mat , N , M , A , B ) ;

Index/key variables: i, j
Accumulator variables: i, idx, j
Iterator variables: i, j
Javascript program:
function printFinalPrices ( arr ) { var minStk = [ ] var n = arr . length ; var i ; var reduce = Array ( n ) . fill ( 0 ) ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( minStk . length > 0 ) { if ( minStk [ minStk . length - 1 ] <= arr [ i ] ) { reduce [ i ] = minStk [ minStk . length - 1 ] ; } else { while ( minStk . length > 0 && ( minStk [ minStk . length - 1 ] > arr [ i ] ) ) { minStk . pop ( ) ; } if ( minStk . length > 0 ) { reduce [ i ] = minStk [ minStk . length - 1 ] ; } } } minStk . push ( arr [ i ] ) ; } for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] - reduce [ i ] + " " ) ; } var arr = [ 8 , 4 , 6 , 2 , 3 ] ; printFinalPrices ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function constructArray ( A , N ) { let left = [ ] ; let right = [ ] ; let X = [ ] ; let Y = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { X [ i ] = 0 ; left [ i ] = 0 ; right [ i ] = 0 ; Y [ i ] = 0 ; } for ( let i = 0 ; i < N ; i ++ ) { X [ i ] = left [ A [ i ] ] ; left [ A [ i ] ] ++ ; } for ( let i = N - 1 ; i >= 0 ; i -- ) { Y [ i ] = right [ A [ i ] ] ; right [ A [ i ] ] ++ ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( Y [ i ] - X [ i ] + " " ) ; } } let A = [ 3 , 2 , 1 , 2 , 3 ] ; let N = A . length ; constructArray ( A , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } ; function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } function largestElement ( head_ref ) { var Max = - 1000000000 ; var head = head_ref ; while ( head != null ) { if ( Max < head . data ) { Max = head . data ; } head = head . next ; } return Max ; } function createHashMap ( Max ) { var hashmap = new Set ( ) ; var prev = 0 ; var curr = 1 ; hashmap . add ( prev ) ; hashmap . add ( curr ) ; while ( curr <= Max ) { var temp = curr + prev ; hashmap . add ( temp ) ; prev = curr ; curr = temp ; } return hashmap ; } function meanofnodes ( head ) { var Max = largestElement ( head ) ; var hashmap = createHashMap ( Max ) ; var curr = head ; var cnt = 0 ; var sum = 0.0 ; while ( curr != null ) { if ( ( curr . data ) & 1 ) { if ( hashmap . has ( curr . data ) ) { cnt ++ ; sum += curr . data ; hashmap . delete ( curr . data ) ; } } curr = curr . next ; } return ( sum / cnt ) ; } var head = null ; head = push ( head , 5 ) ; head = push ( head , 21 ) ; head = push ( head , 8 ) ; head = push ( head , 12 ) ; head = push ( head , 3 ) ; head = push ( head , 13 ) ; head = push ( head , 144 ) ; head = push ( head , 6 ) ; document . write ( meanofnodes ( head ) ) ;

Accumulator variables: cnt, sum
Class/struct names: Node
Javascript program:
function findNumbers ( n ) { var i = 0 ; while ( i <= n ) { document . write ( 2 * i * i + 4 * i + 1 + i % 2 + " " ) ; i ++ ; } } var n = 6 ; findNumbers ( n ) ;

Accumulator variables: i
Javascript program:
function Queries ( arr , N , Q ) { let dq = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { dq . push ( arr [ i ] ) ; } let sz = Q . length ; for ( let i = 0 ; i < sz ; i ++ ) { if ( Q [ i ] [ 0 ] == 0 ) { let front = dq [ 0 ] ; dq . shift ( ) ; dq . push ( front ) ; } else if ( Q [ i ] [ 0 ] == 1 ) { let back = dq [ dq . length - 1 ] ; dq . pop ( ) ; dq . unshift ( back ) ; } else if ( Q [ i ] [ 0 ] == 2 ) { dq [ Q [ i ] [ 1 ] ] = Q [ i ] [ 2 ] ; } else { document . write ( dq [ Q [ i ] [ 1 ] ] + " " ) ; } } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; let Q = [ [ 0 ] , [ 1 ] , [ 3 , 1 ] , [ 2 , 2 , 54 ] , [ 3 , 2 ] ] ; Queries ( arr , N , Q ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function smallSubarray ( arr , n , total_sum ) { let m = new Map ( ) ; let length = Number . MAX_VALUE ; let prefixSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { prefixSum += arr [ i ] ; if ( prefixSum == total_sum ) { length = Math . min ( length , i + 1 ) ; } m . set ( prefixSum , i ) ; if ( m . has ( prefixSum - total_sum ) ) { length = Math . min ( length , i - m . get ( prefixSum - total_sum ) ) ; } } return length ; } function smallestSubarrayremoved ( arr , n , k ) { let total_sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > k ) { arr [ i ] = 1 ; } else if ( arr [ i ] < k ) { arr [ i ] = - 1 ; } else { arr [ i ] = 0 ; } total_sum += arr [ i ] ; } if ( total_sum == 0 ) { return 0 ; } else { return smallSubarray ( arr , n , total_sum ) ; } } let arr = [ 12 , 16 , 12 , 13 , 10 ] ; let K = 13 ; let n = arr . length ; document . write ( smallestSubarrayremoved ( arr , n , K ) ) ;

Index/key variables: i
Accumulator variables: i, prefixSum, total_sum
Iterator variables: i
Javascript program:
function balancedTernary ( n ) { var output = " " ; while ( n > 0 ) { var rem = n % 3 ; n = parseInt ( n / 3 ) ; if ( rem == 2 ) { rem = - 1 ; n ++ ; } output = ( rem == 0 ? ' ' : ( rem == 1 ) ? ' ' : ' ' ) + output ; } return output ; } var n = 238 ; document . write ( " " + n + " " + balancedTernary ( n ) ) ;

Accumulator variables: n
Javascript program:
var spt = 0 ; function printVector ( arr ) { var min_i = 1000000000 ; for ( var i = 0 ; i < arr . length ; i ++ ) min_i = Math . min ( min_i , arr [ i ] ) ; var freq = 0 ; for ( var i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == min_i ) freq ++ ; } spt += freq ; } function findWays ( arr , i , n ) { if ( n == 0 ) printVector ( arr ) ; for ( var j = i ; j <= n ; j ++ ) { arr . push ( j ) ; findWays ( arr , j , n - j ) ; arr . pop ( ) ; } } function spt_function ( n ) { var arr = [ ] ; findWays ( arr , 1 , n ) ; document . write ( spt ) ; } var N = 4 ; spt_function ( N ) ;

Index/key variables: i
Accumulator variables: freq, i, j, spt
Iterator variables: i, j
Javascript program:
function check ( x ) { return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ; } function count ( arr , n ) { let cnt = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( check ( arr [ i ] & arr [ j ] ) ) cnt ++ ; } } return cnt ; } let arr = [ 6 , 4 , 2 , 3 ] ; let n = arr . length ; document . write ( count ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function countPairs ( A , n ) { let count = 0 , i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( ( A [ i ] % 2 == 0 && A [ j ] % 2 == 0 ) || ( A [ i ] % 2 != 0 && A [ j ] % 2 != 0 ) ) count ++ ; } } return count ; } let A = [ 1 , 2 , 3 , 1 , 3 ] ; let n = A . length ; document . write ( countPairs ( A , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function isWeaklyPrimeNum ( N ) { if ( ! isPrime ( N ) ) return false ; var s = N . toString ( ) ; for ( var j = 0 ; j < s . length ; j ++ ) { var str = s ; for ( var i = 0 ; i <= 9 ; i ++ ) { var c = ' ' + i . toString ( ) ; str [ j ] = c ; var Num = parseInt ( str ) ; if ( str [ j ] != s [ j ] && isPrime ( Num ) ) { return false ; } } } return true ; } var N = 294001 ; if ( isWeaklyPrimeNum ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function isUnPrimeableNum ( N ) { if ( isPrime ( N ) ) return false ; var s = N . toString ( ) ; for ( var j = 0 ; j < s . length ; j ++ ) { var str = s ; for ( var i = 0 ; i <= 9 ; i ++ ) { var c = ' ' + parseInt ( i ) ; str [ j ] = c ; var Num = parseInt ( str ) ; if ( str [ j ] != s [ j ] && isPrime ( Num ) ) { return false ; } } } return true ; } var N = 200 ; if ( isUnPrimeableNum ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function getRow ( rowIndex ) { let currow = [ ] ; currow . push ( 1 ) ; if ( rowIndex == 0 ) { return currow ; } let prev = getRow ( rowIndex - 1 ) ; for ( let i = 1 ; i < prev . length ; i ++ ) { let curr = prev [ i - 1 ] + prev [ i ] ; currow . push ( curr ) ; } currow . push ( 1 ) ; return currow ; } let n = 3 ; let arr = getRow ( n ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i == arr . length - 1 ) document . write ( arr [ i ] ) ; else document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function allQuotients ( N ) { var s = new Set ( ) ; for ( var k = 1 ; k <= N + 1 ; k ++ ) { s . add ( parseInt ( N / k ) ) ; } var ls = Array . from ( s ) . reverse ( ) ; ls . forEach ( v => document . write ( v + " " ) ) } var N = 5 ; allQuotients ( N ) ;

Accumulator variables: k
Iterator variables: k
Javascript program:
function greatestOddFactor ( n ) { let pow_2 = ( Math . log ( n ) ) ; let i = 1 ; while ( i <= pow_2 ) { let fac_2 = ( 2 * i ) ; if ( n % fac_2 == 0 ) { if ( ( n / fac_2 ) % 2 == 1 ) { return ( n / fac_2 ) ; } } i += 1 ; } return 0 ; } let N = 8642 ; document . write ( greatestOddFactor ( N ) ) ; ;

Accumulator variables: i
Javascript program:
class node { constructor ( ) { this . i = " " ; this . next = null ; } } function newnode ( s ) { var temp = new node ( ) ; temp . i = s ; temp . next = null ; return temp ; } function Majority_in_linklist ( head ) { var s = " " ; var t = " " ; var p = 0 , q = 0 ; var ptr = null ; while ( head != null ) { if ( s == head . i ) { p = p + 1 ; } else { if ( t == head . i ) { q = q + 1 ; } else { if ( p == 0 ) { s = head . i ; p = 1 ; } else { if ( q == 0 ) { t = head . i ; q = 1 ; } else { p = p - 1 ; q = q - 1 ; } } } } head = head . next ; } head = ptr ; p = 0 ; q = 0 ; while ( head != null ) { if ( s == head . i ) { p = 1 ; } else { if ( t == head . i ) { q = 1 ; } } head = head . next ; } if ( p > q ) { return s ; } else { return t ; } } var head = newnode ( " " ) ; head . next = newnode ( " " ) ; head . next . next = newnode ( " " ) ; head . next . next . next = newnode ( " " ) ; head . next . next . next . next = newnode ( " " ) ; head . next . next . next . next . next = newnode ( " " ) ; head . next . next . next . next . next . next = newnode ( " " ) ; head . next . next . next . next . next . next . next = newnode ( " " ) ; document . write ( Majority_in_linklist ( head ) ) ;

Class/struct names: node
Javascript program:
function max_number ( arr , sum ) { let frac = new Array ( 9 ) ; let maxi = Number . MIN_VALUE ; let ans = [ ] ; let pos = 0 ; for ( let i = 0 ; i < 9 ; i ++ ) { frac [ i ] = Math . floor ( sum / arr [ i ] ) ; if ( frac [ i ] > maxi ) { pos = i ; maxi = frac [ i ] ; } } for ( let i = 0 ; i < maxi ; i ++ ) { ans . push ( String . fromCharCode ( ( pos + 1 ) + ' ' . charCodeAt ( 0 ) ) ) ; } sum -= maxi * arr [ pos ] ; for ( let i = 0 ; i < maxi ; i ++ ) { for ( let j = 1 ; j <= 9 ; j ++ ) { if ( sum + arr [ pos ] - arr [ j - 1 ] >= 0 ) { ans [ i ] = String . fromCharCode ( ( j + ' ' . charCodeAt ( 0 ) ) ) ; sum += arr [ pos ] - arr [ j - 1 ] ; break ; } } } if ( maxi == 0 ) { return " " ; } else { return ans . join ( " " ) ; } } let arr = [ 3 , 4 , 2 , 4 , 6 , 5 , 4 , 2 , 3 ] ; let s = 13 ; document . write ( max_number ( arr , s ) ) ;

Index/key variables: i, pos
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function checkOverlapping ( a , b ) { if ( a [ 0 ] < b [ 0 ] ) { var temp = a [ 0 ] ; a [ 0 ] = b [ 0 ] ; b [ 0 ] = temp ; temp = a [ 1 ] ; a [ 1 ] = b [ 1 ] ; b [ 1 ] = temp ; } if ( b [ 0 ] <= a [ 0 ] && a [ 0 ] <= b [ 1 ] ) return true ; return false ; } function find ( a , i ) { if ( a [ i ] == i ) { return i ; } a [ i ] = find ( a , a [ i ] ) ; return a [ i ] ; } function union ( a , x , y ) { var xs = find ( a , x ) ; var ys = find ( a , y ) ; if ( xs == ys ) { return true ; } a [ ys ] = xs ; return false ; } function checkNonOverlapping ( arr , n ) { var dsu = [ ] ; for ( var i = 0 ; i < n + 1 ; i ++ ) { dsu . push ( i ) ; } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( checkOverlapping ( arr [ i ] , arr [ j ] ) ) { if ( union ( dsu , i , j ) ) { return false ; } } } } return true ; } var arr = Array ( ) ; arr . push ( [ 1 , 4 ] ) ; arr . push ( [ 2 , 2 ] ) ; arr . push ( [ 2 , 3 ] ) ; var n = arr . length ; if ( checkNonOverlapping ( arr , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j, ys
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function FindValue ( N , K ) { if ( N % 2 == 0 ) { N = N + 2 * K ; } else { let i ; for ( i = 2 ; i < Math . sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) break ; } N = N + i ; N = N + 2 * ( K - 1 ) ; } document . write ( N + " " ) ; } let N = 9 ; let K = 4 ; FindValue ( N , K ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function heptadecagonal_num ( n ) { return ( ( 15 * n * n ) - 13 * n ) / 2 ; } function sum_heptadecagonal_num ( n ) { let summ = 0 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { summ += heptadecagonal_num ( i ) ; } return summ ; } let n = 5 ; document . write ( sum_heptadecagonal_num ( n ) ) ;

Accumulator variables: i, summ
Iterator variables: i
Javascript program:
var pref = Array ( 100001 ) . fill ( 0 ) ; function isComposite ( n ) { if ( n <= 1 ) return 0 ; if ( n <= 3 ) return 0 ; if ( n % 2 == 0 n % 3 == 0 ) return n ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return n ; return 0 ; } function preCompute ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isComposite ( i ) ; } } function printSum ( L , R ) { document . write ( pref [ R ] - pref [ L - 1 ] + " " ) ; } function printSumComposite ( arr , Q ) { preCompute ( ) ; for ( var i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } var Q = 2 ; var arr = [ [ 10 , 13 ] , [ 12 , 21 ] ] ; printSumComposite ( arr , Q ) ;

Index/key variables: R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
var pref = Array ( 100010 ) . fill ( 0 ) ; function isPerfectSquare ( x ) { var s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isNonFibonacci ( n ) { if ( isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ) return 0 ; else return n ; } function compute ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isNonFibonacci ( i ) ; } } function printSum ( L , R ) { var sum = pref [ R ] - pref [ L - 1 ] ; document . write ( sum + " " ) ; } compute ( ) ; var Q = 2 ; var arr = [ [ 1 , 5 ] , [ 6 , 10 ] ] ; for ( var i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; }

Index/key variables: R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i += 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } function twinPrime ( n1 , n2 ) { return ( isPrime ( n1 ) && isPrime ( n2 ) && Math . abs ( n1 - n2 ) == 2 ) ; } function countTwinPairs ( arr , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( twinPrime ( arr [ i ] , arr [ j ] ) ) { count ++ ; } } } return count ; } var arr = [ 2 , 3 , 5 , 11 ] ; var n = arr . length ; document . write ( countTwinPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function solve ( arr , n ) { let unfilled_indices = new Set ( ) ; let missing = new Set ( ) ; for ( let i = 1 ; i < n ; i ++ ) { missing . add ( i ) ; } for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { unfilled_indices . add ( i ) ; } else { missing . delete ( arr [ i ] ) ; } } let mi = new Array ( missing . size ) ; let l = 0 ; for ( let x of missing . values ( ) ) { mi [ l ++ ] = x ; } let m = missing . size ; for ( let it of unfilled_indices . values ( ) ) { arr [ it ] = mi [ m - 1 ] ; m -- ; } let pos = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == i ) { pos = i ; } } let x ; if ( pos != 0 ) { for ( let i = 1 ; i < n ; i ++ ) { if ( pos != i ) { if ( unfilled_indices . has ( i ) ) { x = arr [ i ] ; arr [ i ] = pos ; arr [ pos ] = x ; break ; } } } } printArray ( arr , n ) ; } function printArray ( arr , n ) { for ( let i = 1 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let arr = [ 0 , 7 , 4 , 0 , 3 , 0 , 5 , 1 ] ; let n = arr . length ; solve ( arr , n ) ;

Index/key variables: i, it, pos
Accumulator variables: i, l, m
Iterator variables: i, it, x
Javascript program:
function check ( x , pos , neg , k ) { let pairs = 0 ; let p = neg . length - 1 ; let nn = neg . length - 1 ; let pp = pos . length - 1 ; for ( let i = 0 ; i < neg . length ; i ++ ) { while ( ( p >= 0 ) && ( neg [ i ] * neg [ p ] <= x ) ) p -- ; pairs += Math . min ( nn - p , nn - i ) ; } p = 0 ; for ( let i = pos . length - 1 ; i >= 0 ; i -- ) { while ( ( p < pos . length ) && ( pos [ i ] * pos [ p ] <= x ) ) p ++ ; pairs += Math . min ( p , i ) ; } p = pos . length - 1 ; for ( let i = neg . length - 1 ; i >= 0 ; i -- ) { while ( ( p >= 0 ) && ( neg [ i ] * pos [ p ] <= x ) ) p -- ; pairs += pp - p ; } return ( pairs >= k ) ; } function kth_element ( a , n , k ) { let pos = [ ] ; let neg = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) pos . push ( a [ i ] ) ; else neg . push ( a [ i ] ) ; } sort ( pos . begin ( ) , pos . end ( ) ) ; sort ( neg . begin ( ) , neg . end ( ) ) ; pos . sort ( function ( a , b ) { return a - b } ) ; neg . sort ( function ( a , b ) { return a - b } ) ; let l = - 1e8 , ans = 0 , r = 1e8 ; while ( l <= r ) { let mid = ( l + r ) >> 1 ; if ( check ( mid , pos , neg , k ) ) { ans = mid ; r = mid - 1 ; } else l = mid + 1 ; } return ans ; } let a = [ - 4 , - 2 , 3 , 3 ] ; let k = 3 ; let n = a . length ; document . write ( kth_element ( a , n , k ) ) ;

Index/key variables: i, p
Accumulator variables: i, p, pairs
Iterator variables: i
Javascript program:
function squareRoot ( n , l ) { let x = n ; let root ; let count = 0 ; while ( true ) { count ++ ; root = 0.5 * ( x + ( n / x ) ) ; if ( Math . abs ( root - x ) < l ) break ; x = root ; } return root . toFixed ( 4 ) ; } let n = 327 ; let l = 0.00001 ; document . write ( squareRoot ( n , l ) ) ;

Accumulator variables: count
Javascript program:
let factorial = new Array ( 1000005 ) ; let modinverse = new Array ( 1000005 ) ; factorial . fill ( 0 ) ; modinverse . fill ( 0 ) ; let mod = 1000000007 ; let N = 1000005 ; function power ( a , m1 ) { if ( m1 == 0 ) return 1 ; else if ( m1 == 1 ) return a ; else if ( m1 == 2 ) return ( a * a ) % mod ; else if ( ( m1 & 1 ) != 0 ) return ( a * power ( power ( a , parseInt ( m1 / 2 , 10 ) ) , 2 ) ) % mod ; else return power ( power ( a , parseInt ( m1 / 2 , 10 ) ) , 2 ) % mod ; } function factorialfun ( ) { factorial [ 0 ] = 1 ; for ( let i = 1 ; i < N ; i ++ ) factorial [ i ] = ( factorial [ i - 1 ] * i ) % mod ; } function modinversefun ( ) { modinverse [ N - 1 ] = power ( factorial [ N - 1 ] , mod - 2 ) % mod ; for ( let i = N - 2 ; i >= 0 ; i -- ) modinverse [ i ] = ( modinverse [ i + 1 ] * ( i + 1 ) ) % mod ; } function binomial ( n , r ) { if ( r > n ) return 0 ; let a = ( factorial [ n ] * modinverse [ n - r ] ) % mod ; a = ( a * modinverse [ r ] ) % mod ; return a * 0 + 2 ; } function ways ( x , y ) { factorialfun ( ) ; modinversefun ( ) ; if ( ( 2 * x - y ) % 3 == 0 && ( 2 * y - x ) % 3 == 0 ) { let m = parseInt ( ( 2 * x - y ) / 3 , 10 ) ; let n = parseInt ( ( 2 * y - x ) / 3 , 10 ) ; System . out . println ( n + m + " " + n ) ; return binomial ( ( n + m ) , n ) ; } return 0 ; } let x = 3 , y = 3 ; document . write ( ways ( x , y ) ) ;

Index/key variables: i, n, r
Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( n , x , y ) { var length = Math . ceil ( Math . log2 ( n + 2 ) ) - 1 ; var rank = n - ( 1 << length ) + 1 ; var left = " " , right = " " ; for ( var i = length - 1 ; i >= 0 ; i -- ) { var mask = 1 << i ; var bit = mask & rank ; if ( bit ) { left += y ; right += y ; } else { left += x ; right += x ; } } right = right . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; return left + right ; } var n = 23 ; var x = ' ' , y = ' ' ; var ans = solve ( n , x , y ) ; document . write ( ans + " " ) ;

Accumulator variables: i, left, right
Iterator variables: i