dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findTheOrder ( arr , s , N ) { let ans = [ ] ; let A = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { let p = [ arr [ i ] , i + 1 ] ; A . push ( p ) ; } A . sort ( function ( p1 , p2 ) { return p1 [ 0 ] - p2 [ 0 ] ; } ) ; let q = [ ] ; let index = 0 ; for ( let i = 0 ; i < 2 * N ; i ++ ) { if ( s [ i ] == ' ' ) { ans . push ( A [ index ] [ 1 ] ) ; q . push ( A [ index ] ) ; index ++ ; } else { ans . push ( q [ 0 ] [ 1 ] ) ; q . shift ( ) ; } q . sort ( function ( a , b ) { return b [ 0 ] - a [ 0 ] ; } ) ; } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let N = 3 ; let arr = [ 2 , 1 , 3 ] ; let s = " " ; findTheOrder ( arr , s , N ) ;

Index/key variables: i, index
Accumulator variables: i, index
Iterator variables: i
Javascript program:
function printArr ( arr , N ) { for ( var i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function rearrangeArr ( arr , N ) { var totalSum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } if ( totalSum == 0 ) { document . write ( " " + " " ) ; } else if ( totalSum > 0 ) { arr . sort ( compare ) ; arr = reverse ( arr ) ; printArr ( arr , N ) ; } else { arr . sort ( compare ) ; printArr ( arr , N ) ; } } function compare ( a , b ) { if ( a < b ) { return - 1 ; } else if ( a > b ) { return 1 ; } else { return 0 ; } } function reverse ( a ) { var i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } var arr = [ 1 , - 1 , - 2 , 3 ] ; var N = arr . length ; rearrangeArr ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Javascript program:
var MOD = 1000000007 ; function solve ( values , salary ) { var ret = 1 ; var amt = 0 ; values . sort ( ( a , b ) => a - b ) ; salary . sort ( ( a , b ) => a - b ) ; while ( salary . length ) { while ( values . length && values [ values . length - 1 ] >= salary [ salary . length - 1 ] ) { amt ++ ; values . pop ( ) ; } if ( amt == 0 ) return 0 ; ret *= amt -- ; ret %= MOD ; salary . pop ( ) ; } return ret ; } var values = [ 1 , 2 ] , salary = [ 2 ] ; document . write ( solve ( values , salary ) ) ;

Accumulator variables: amt, ret
Javascript program:
function countPairs ( arr , n ) { let ans = 0 ; arr . sort ( function ( a , b ) { return a - b } ) ; let left = 0 , right = 1 ; while ( right < n ) { if ( arr [ left ] == arr [ right ] ) ans += right - left ; else left = right ; right ++ ; } return ans ; } let arr = [ 2 , 2 , 3 , 2 , 3 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: left, right
Accumulator variables: ans, right
Javascript program:
function sortString ( S ) { let sorted = [ ] ; let original = [ ] ; let insert = false ; if ( S . length == 1 ) { document . write ( 0 + " " ) ; } let curr = 1 ; for ( let i = 0 ; i < ( S . length - 1 ) ; i ++ ) { if ( S [ i ] == S [ i + 1 ] ) { curr += 1 ; insert = false ; } else { sorted . push ( curr ) ; original . push ( curr ) ; curr = 1 ; insert = true ; } } if ( ( S [ S . length - 1 ] != S [ S . length - 2 ] ) insert == false ) { sorted . push ( curr ) ; original . push ( curr ) ; } sorted . sort ( function ( a , b ) { return a - b } ) ; let t_cost = 0 ; for ( let i = 0 ; i < sorted . length ; i ++ ) { t_cost += Math . abs ( sorted [ i ] - original [ i ] ) ; } return parseInt ( t_cost / 2 , 10 ) ; } let S = " " ; document . write ( sortString ( S ) ) ;

Index/key variables: i
Accumulator variables: curr, i, t_cost
Iterator variables: i
Boolean variables: insert
Javascript program:
function frequentWords ( arr , K ) { var Freq = new Map ( ) ; for ( var word of arr ) { Freq . set ( word , Freq . has ( word ) ? Freq . get ( word ) : 0 ) ; } var Order = [ ] ; for ( var word of [ ... Freq . keys ( ) ] ) { Order . push ( word ) ; if ( Order . length > K ) { Order . pop ( ) ; } } var ans = [ ] ; Order . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ; while ( Order . length != 0 ) { ans . push ( Order [ Order . length - 1 ] ) Order . pop ( ) ; } ans . reverse ( ) ; return ans ; } var N = 3 , K = 2 ; var arr = [ ] ; arr . push ( " " ) ; arr . push ( " " ) ; arr . push ( " " ) ; var ans = frequentWords ( arr , K ) ; for ( var word of ans ) { document . write ( word + " " ) ; }

Iterator variables: word
Javascript program:
let letters = [ 4 , 3 , 3 , 3 , 4 , 4 , 3 , 5 , 5 , 4 ] ; function sumOfLetters ( n ) { let sum = 0 ; while ( n > 0 ) { sum += letters [ n % 10 ] ; n = Math . floor ( n / 10 ) ; } return sum ; } function sortArr ( arr , n ) { let vp = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { vp . push ( [ sumOfLetters ( arr [ i ] ) , arr [ i ] ] ) ; } vp . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ; for ( let i = 0 ; i < vp . length ; i ++ ) document . write ( vp [ i ] [ 1 ] + " " ) ; } let arr = [ 12 , 10 , 31 , 18 ] ; let n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
class node { constructor ( key ) { this . left = null ; this . right = null ; this . val = key ; } } function newnode ( key ) { let temp = new node ( key ) ; return temp ; } function func ( root ) { let q = [ ] ; let t = true ; q . push ( root ) ; let i = - 1 , j = - 1 ; while ( q . length > 0 ) { let h = q . length ; while ( h > 0 ) { root = q [ 0 ] ; if ( i == - 1 ) { j = root . val ; } if ( i == - 2 ) { if ( j <= root . val ) { j = root . val ; i = - 3 ; } else { t = false ; break ; } } if ( root . left != null ) { q . push ( root . left ) ; } if ( root . right != null ) { q . push ( root . right ) ; } h = h - 1 ; q . shift ( ) ; } i = - 2 ; if ( t == false ) { break ; } } if ( t ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let root = newnode ( 10 ) ; root . right = newnode ( 50 ) ; root . right . right = newnode ( 15 ) ; root . left = newnode ( 20 ) ; root . left . left = newnode ( 50 ) ; root . left . right = newnode ( 23 ) ; root . right . left = newnode ( 10 ) ; func ( root ) ;

Boolean variables: t
Class/struct names: node
Javascript program:
function calculate_minimum_split ( n , a , k ) { let p = Array . from ( { length : n - 1 } , ( _ , i ) => 0 ) ; for ( let i = 1 ; i < n ; i ++ ) p [ i - 1 ] = a [ i ] - a [ i - 1 ] ; p . sort ( ( a , b ) => a - b ) ; p . reverse ( ) ; let min_sum = 0 ; for ( let i = 0 ; i < k - 1 ; i ++ ) min_sum += p [ i ] ; let res = a [ n - 1 ] - a [ 0 ] - min_sum ; return res ; } let arr = [ 4 , 8 , 15 , 16 , 23 , 42 ] ; let k = 3 ; let n = arr . length ; document . write ( calculate_minimum_split ( n , arr , k ) ) ;

Index/key variables: i
Accumulator variables: i, min_sum
Iterator variables: i
Javascript program:
function myCompare ( date1 , date2 ) { var day1 = date1 . substr ( 0 , 2 ) ; var month1 = date1 . substr ( 3 , 2 ) ; var year1 = date1 . substr ( 6 , 4 ) ; var day2 = date2 . substr ( 0 , 2 ) ; var month2 = date2 . substr ( 3 , 2 ) ; var year2 = date2 . substr ( 6 , 4 ) ; if ( year1 < year2 ) return - 1 ; if ( year1 > year2 ) return 1 ; if ( month1 < month2 ) return - 1 ; if ( month1 > month2 ) return 1 ; if ( day1 < day2 ) return - 1 ; if ( day1 > day2 ) return 1 ; } function printDatesAscending ( arr ) { var n = arr . length ; arr . sort ( myCompare ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } var arr = [ ] ; arr . push ( " " ) ; arr . push ( " " ) ; arr . push ( " " ) ; arr . push ( " " ) ; arr . push ( " " ) ; printDatesAscending ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isVowel ( ch ) { ch = ch . toUpperCase ( ) ; return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function countVowels ( str ) { let count = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) ++ count ; return count ; } function sortArr ( arr , n ) { let vp = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { vp . push ( [ countVowels ( arr [ i ] ) , arr [ i ] ] ) ; } vp . sort ( ) ; for ( let i = 0 ; i < vp . length ; i ++ ) document . write ( vp [ i ] [ 1 ] + " " ) ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumCost ( price , n ) { price . sort ( ) ; let totalCost = 0 ; for ( let i = n - 1 ; i > 1 ; i -= 2 ) { if ( i == 2 ) { totalCost += price [ 2 ] + price [ 0 ] ; } else { let price_first = price [ i ] + price [ 0 ] + 2 * price [ 1 ] ; let price_second = price [ i ] + price [ i - 1 ] + 2 * price [ 0 ] ; totalCost += Math . min ( price_first , price_second ) ; } } if ( n == 1 ) { totalCost += price [ 0 ] ; } else { totalCost += price [ 1 ] ; } return totalCost ; } let price = [ 30 , 40 , 60 , 70 ] ; let n = price . length ; document . write ( minimumCost ( price , n ) ) ;

Index/key variables: i
Accumulator variables: i, totalCost
Iterator variables: i
Javascript program:
var N = 100 ; var INF = 1000000 ; var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; var vis = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; function findSum ( arr , n , k , l , r ) { if ( ( l ) + ( n - 1 - r ) == k ) return arr [ r ] - arr [ l ] ; if ( vis [ l ] [ r ] ) return dp [ l ] [ r ] ; vis [ l ] [ r ] = 1 ; dp [ l ] [ r ] = Math . min ( findSum ( arr , n , k , l , r - 1 ) , findSum ( arr , n , k , l + 1 , r ) ) ; return dp [ l ] [ r ] ; } var arr = [ 1 , 2 , 100 , 120 , 140 ] ; var k = 2 ; var n = arr . length ; document . write ( findSum ( arr , n , k , 0 , n - 1 ) ) ;

Index/key variables: l, r
Javascript program:
function unique_combination ( l , sum , K , local , A ) { if ( sum == K ) { document . write ( " " ) ; for ( let i = 0 ; i < local . length ; i ++ ) { if ( i != 0 ) document . write ( " " ) ; document . write ( local [ i ] ) ; if ( i != local . length - 1 ) document . write ( " " ) ; } document . write ( " " + " " ) ; return ; } for ( let i = l ; i < A . length ; i ++ ) { if ( sum + A [ i ] > K ) continue ; if ( i > l && A [ i ] == A [ i - 1 ] ) continue ; local . push ( A [ i ] ) ; unique_combination ( i + 1 , sum + A [ i ] , K , local , A ) ; local . pop ( ) ; } } function Combination ( A , K ) { A . sort ( ( a , b ) => a - b ) ; let local = [ ] ; unique_combination ( 0 , 0 , K , local , A ) ; } let A = [ 10 , 1 , 2 , 7 , 6 , 1 , 5 ] ; let K = 8 ; Combination ( A , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function solution ( arr , x ) { let closestSum = Number . MAX_VALUE ; for ( let i = 0 ; i < arr . length ; i ++ ) { for ( let j = i + 1 ; j < arr . length ; j ++ ) { for ( let k = j + 1 ; k < arr . length ; k ++ ) { if ( Math . abs ( x - closestSum ) > Math . abs ( x - ( arr [ i ] + arr [ j ] + arr [ k ] ) ) ) closestSum = ( arr [ i ] + arr [ j ] + arr [ k ] ) ; } } } return closestSum ; } let arr = [ - 1 , 2 , 1 , - 4 ] ; let x = 1 ; document . write ( solution ( arr , x ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function addEdge ( adj , u , v ) { adj [ u ] . push ( v ) ; } function getindeg ( adj , V , indeg ) { for ( let i = 0 ; i < V ; i ++ ) { for ( let x = 0 ; x < adj [ i ] . length ; x ++ ) { indeg [ adj [ i ] [ x ] ] = indeg [ adj [ i ] [ x ] ] + 1 ; } } } function topo ( adj , V , indeg ) { let q = [ ] ; for ( let i = 0 ; i < V ; i ++ ) { if ( indeg [ i ] == 0 ) { q . push ( i ) ; } } let res = [ ] ; while ( q . length > 0 ) { let u = q . shift ( ) ; res . push ( u ) ; for ( let x = 0 ; x < adj [ u ] . length ; x ++ ) { indeg [ adj [ u ] [ x ] ] = indeg [ adj [ u ] [ x ] ] - 1 ; if ( indeg [ adj [ u ] [ x ] ] == 0 ) { q . push ( adj [ u ] [ x ] ) ; } } } return res ; } function makearray ( v , V ) { let adj = [ ] ; for ( let i = 0 ; i < V ; i ++ ) { adj . push ( [ ] ) ; } for ( let i = 0 ; i < v . length ; i ++ ) { for ( let j = 0 ; j < v [ i ] . length - 1 ; j ++ ) { addEdge ( adj , v [ i ] [ j ] , v [ i ] [ j + 1 ] ) ; } } let indeg = [ ] ; for ( let i = 0 ; i < V ; i ++ ) { indeg . push ( 0 ) ; } getindeg ( adj , V , indeg ) ; let res = topo ( adj , V , indeg ) ; return res ; } let n = 10 ; let subseqs = [ [ 9 , 1 , 2 , 8 , 3 ] , [ 6 , 1 , 2 ] , [ 9 , 6 , 3 , 4 ] , [ 5 , 2 , 7 ] , [ 0 , 9 , 5 , 4 ] ] ; let res = makearray ( subseqs , n ) ; for ( let x = 0 ; x < res . length ; x ++ ) { document . write ( res [ x ] + " " ) ; }

Index/key variables: i, j, u, x
Accumulator variables: i, j, x
Iterator variables: i, j, x
Javascript program:
let pr = [ ] ; let prime = new Array ( 10000000 + 1 ) ; function sieve ( n ) { for ( let i = 2 ; i <= n ; i += 1 ) { prime [ i ] = 1 ; } for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } for ( let p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) pr . push ( p ) ; } function SemiPrimeSum ( N ) { let ans = 0 ; for ( let i = 0 ; i < pr . length ; i += 1 ) { for ( let j = i ; j < pr . length ; j += 1 ) { if ( pr [ i ] * pr [ j ] > N ) break ; ans += pr [ i ] * pr [ j ] ; } } return ans ; } let N = 6 ; sieve ( N ) ; document . write ( SemiPrimeSum ( N ) ) ;

Index/key variables: i, j, p
Accumulator variables: ans, i, j, p
Iterator variables: i, j, p
Javascript program:
function compressArr ( arr , n ) { let i = 0 , j = 0 ; arr . sort ( function ( a , b ) { return a - b } ) ; while ( i < n ) { j = i ; while ( ( j + 1 < n ) && ( arr [ j + 1 ] == arr [ j ] + 1 ) ) { j ++ ; } if ( i == j ) { document . write ( arr [ i ] + " " ) ; i ++ ; } else { document . write ( arr [ i ] + " " + arr [ j ] + " " ) ; i = j + 1 ; } } } let n = 7 ; let arr = [ 1 , 3 , 4 , 5 , 6 , 9 , 10 ] ; compressArr ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function removeElements ( arr , n ) { let brr = new Array ( n ) ; brr . fill ( 0 ) ; let l = 1 ; brr [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( brr [ l - 1 ] <= arr [ i ] ) { brr [ l ] = arr [ i ] ; l ++ ; } } for ( let i = 0 ; i < l ; i ++ ) document . write ( brr [ i ] + " " ) ; } let arr = [ 10 , 12 , 9 , 10 , 2 , 13 , 14 ] ; let n = arr . length ; removeElements ( arr , n ) ;

Index/key variables: i, l
Accumulator variables: i, l
Iterator variables: i
Javascript program:
function removeElements ( arr , n ) { let l = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ l - 1 ] <= arr [ i ] ) { arr [ l ] = arr [ i ] ; l ++ ; } } for ( let i = 0 ; i < l ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 10 , 12 , 9 , 10 , 2 , 13 , 14 ] ; let n = arr . length ; removeElements ( arr , n ) ;

Index/key variables: i, l
Accumulator variables: i, l
Iterator variables: i
Javascript program:
function findX ( a , n ) { a . sort ( ( x , y ) => x - y ) ; let x = a [ 0 ] * a [ n - 1 ] ; let vec = [ ] ; for ( let i = 2 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) { vec . push ( i ) ; if ( parseInt ( x / i ) != i ) vec . push ( parseInt ( x / i ) ) ; } } vec . sort ( ( x , y ) => x - y ) ; if ( vec . length != n ) return - 1 ; else { let i = 0 ; for ( let j = 0 ; j < vec . length ; j ++ ) { if ( a [ i ++ ] != vec [ j ] ) return - 1 ; } } return x ; } let a = [ 2 , 5 , 4 , 10 ] ; let n = a . length ; document . write ( findX ( a , n ) ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function pendulumArrangement ( arr , n ) { arr . sort ( function ( a , b ) { return a - b } ) ; let odd , temp , p , pos ; pos = n - 1 ; if ( n % 2 == 0 ) odd = n - 1 ; else odd = n - 2 ; while ( odd > 0 ) { temp = arr [ odd ] ; p = odd ; while ( p != pos ) { arr [ p ] = arr [ p + 1 ] ; p ++ ; } arr [ p ] = temp ; odd = odd - 2 ; pos = pos - 1 ; } let start = 0 , end = parseInt ( ( n - 1 ) / 2 , 10 ) ; for ( ; start < end ; start ++ , end -- ) { temp = arr [ start ] ; arr [ start ] = arr [ end ] ; arr [ end ] = temp ; } for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 11 , 2 , 4 , 55 , 6 , 8 ] ; let n = arr . length ; pendulumArrangement ( arr , n ) ;

Index/key variables: end, i, odd, p, start
Accumulator variables: end, i, p, start
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function AddNode ( root , data ) { if ( root == null ) { root = new Node ( data ) ; return root ; } if ( root . data < data ) root . right = AddNode ( root . right , data ) ; else if ( root . data > data ) root . left = AddNode ( root . left , data ) ; return root ; } function TargetPair ( node , tar ) { let LeftList = [ ] ; let RightList = [ ] ; let curr_left = node ; let curr_right = node ; while ( curr_left != null curr_right != null LeftList . length > 0 && RightList . length > 0 ) { while ( curr_left != null ) { LeftList . push ( curr_left ) ; curr_left = curr_left . left ; } while ( curr_right != null ) { RightList . push ( curr_right ) ; curr_right = curr_right . right ; } let LeftNode = LeftList [ LeftList . length - 1 ] ; let RightNode = RightList [ RightList . length - 1 ] ; let leftVal = LeftNode . data ; let rightVal = RightNode . data ; if ( leftVal >= rightVal ) break ; if ( leftVal + rightVal < tar ) { LeftList . pop ( ) ; curr_left = LeftNode . right ; } else if ( leftVal + rightVal > tar ) { RightList . pop ( ) ; curr_right = RightNode . left ; } else { document . write ( LeftNode . data + " " + RightNode . data + " " ) ; RightList . pop ( ) ; LeftList . pop ( ) ; curr_left = LeftNode . right ; curr_right = RightNode . left ; } } } let root = null ; root = AddNode ( root , 2 ) ; root = AddNode ( root , 6 ) ; root = AddNode ( root , 5 ) ; root = AddNode ( root , 3 ) ; root = AddNode ( root , 4 ) ; root = AddNode ( root , 1 ) ; root = AddNode ( root , 7 ) ; let sum = 8 ; TargetPair ( root , sum ) ;

Class/struct names: Node
Javascript program:
function findNumber ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; var max = arr [ n - 1 ] ; var table = Array ( ( 2 * max ) + 1 ) . fill ( 0 ) ; table [ 0 ] = 0 ; for ( i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) table [ i ] = Number . MAX_VALUE ; var ans = - 1 ; for ( i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( arr [ j ] <= i ) { var res = table [ i - arr [ j ] ] ; if ( res != Number . MAX_VALUE && res + 1 < table [ i ] ) table [ i ] = res + 1 ; } } if ( i > arr [ n - 1 ] && table [ i ] == Number . MAX_VALUE ) { ans = i ; break ; } } return ans ; } var arr = [ 6 , 7 , 15 ] ; var n = arr . length ; document . write ( findNumber ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MOD = 1000000007 ; let max = 101 ; let C = new Array ( max ) ; for ( let i = 0 ; i < max ; i ++ ) { C [ i ] = new Array ( max ) ; for ( let j = 0 ; j < max ; j ++ ) { C [ i ] [ j ] = 0 ; } } function power ( x , y ) { let res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( y % 2 == 1 ) { res = ( res * x ) % MOD ; } y = y >> 1 ; x = ( x * x ) % MOD ; } return res % MOD ; } function combi ( n , k ) { let 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 ] % MOD + C [ i - 1 ] [ j ] % MOD ) % MOD ; } } } function product ( a , n , k ) { let ans = 1 ; a . sort ( function ( a , b ) { return a - b } ) ; let powa = C [ n - 1 ] [ k - 1 ] ; for ( let i = 0 ; i < n ; i ++ ) { let powla = C [ i ] [ k - 1 ] ; let powfa = C [ n - i - 1 ] [ k - 1 ] ; let powe = ( ( powa % MOD ) - ( powla + powfa ) % MOD + MOD ) % MOD ; let mul = power ( a [ i ] , powe ) % MOD ; ans = ( ( ans % MOD ) * ( mul % MOD ) ) % MOD ; } return ans % MOD ; } combi ( 100 , 100 ) ; let arr = [ 1 , 2 , 3 , 4 ] ; let n = arr . length ; let k = 3 ; let ans = product ( arr , n , k ) ; document . write ( ans ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let s1 , s2 ; function makeEqualLength ( ) { let len_a = s1 . length ; let len_b = s2 . length ; let num_zeros = Math . abs ( len_a - len_b ) ; if ( len_a < len_b ) { for ( let i = 0 ; i < num_zeros ; i ++ ) { s1 = ' ' + s1 ; } return len_b ; } else { for ( let i = 0 ; i < num_zeros ; i ++ ) { s2 = ' ' + s2 ; } } return len_a ; } function andOperationBitwise ( ) { let length = makeEqualLength ( ) ; let res = " " ; for ( let i = 0 ; i < length ; i ++ ) { res = res + String . fromCharCode ( ( s1 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) & s2 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) + ' ' . charCodeAt ( ) ) ; } return res ; } let arr = [ " " , " " , " " ] ; let n = arr . length ; let result ; if ( n < 2 ) { document . write ( arr [ n - 1 ] + " " ) ; } result = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { s1 = result ; s2 = arr [ i ] ; result = andOperationBitwise ( ) ; } document . write ( result ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPoints ( n , m , a , b , x , y ) { a . sort ( function ( a , b ) { return a - b } ) ; b . sort ( function ( a , b ) { return a - b } ) ; let j = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( a [ i ] + y < b [ j ] ) break ; if ( b [ j ] >= a [ i ] - x && b [ j ] <= a [ i ] + y ) { count ++ ; j ++ ; break ; } else j ++ ; } } return count ; } let x = 1 , y = 4 ; let a = [ 1 , 5 ] ; let n = a . length ; let b = [ 1 , 1 , 2 ] ; let m = a . length ; document . write ( countPoints ( n , m , a , b , x , y ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i
Javascript program:
let N = 4 ; function merge_and_sort ( output , arr , n , k ) { for ( let i = 0 ; i < k ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { output [ i * n + j ] = arr [ i ] [ j ] ; } } output . sort ( function ( a , b ) { return a - b } ) ; } let arr = [ [ 5 , 7 , 15 , 18 ] , [ 1 , 8 , 9 , 17 ] , [ 1 , 4 , 7 , 7 ] ] ; let n = N ; let k = 3 ; let output = new Array ( n * k ) ; merge_and_sort ( output , arr , n , k ) ; for ( let i = 0 ; i < n * k ; i ++ ) document . write ( output [ i ] + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minOperations ( n , m , k , matrix ) { let arr = [ ] ; let mod ; if ( matrix [ 0 ] [ 0 ] < 0 ) { mod = k - ( Math . abs ( matrix [ 0 ] [ 0 ] ) % k ) ; } else { mod = matrix [ 0 ] [ 0 ] % k ; } for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < m ; ++ j ) { arr . push ( matrix [ i ] [ j ] ) ; let val = matrix [ i ] [ j ] ; if ( val < 0 ) { let res = k - ( Math . abs ( val ) % k ) ; if ( res != mod ) { return - 1 ; } } else { let foo = matrix [ i ] [ j ] ; if ( foo % k != mod ) { return - 1 ; } } } } arr . sort ( function ( a , b ) { return a - b ; } ) ; let median = arr [ ( n * m ) / 2 ] ; let minOperations = 0 ; for ( let i = 0 ; i < n * m ; ++ i ) minOperations += Math . abs ( arr [ i ] - median ) / k ; if ( ( n * m ) % 2 == 0 ) { let median2 = arr [ ( ( n * m ) / 2 ) - 1 ] ; let minOperations2 = 0 ; for ( let i = 0 ; i < n * m ; ++ i ) minOperations2 += Math . abs ( arr [ i ] - median2 ) / k ; minOperations = Math . min ( minOperations , minOperations2 ) ; } return minOperations ; } let matrix = [ [ 2 , 4 , 6 ] , [ 8 , 10 , 12 ] , [ 14 , 16 , 18 ] , [ 20 , 22 , 24 ] ] ; let n = matrix . length ; let m = matrix [ 0 ] . length ; let k = 2 ; document . write ( minOperations ( n , m , k , matrix ) ) ;

Index/key variables: i, j
Accumulator variables: minOperations, minOperations2
Iterator variables: i, j
Javascript program:
function minSubarray ( A , n ) { let minValue = Number . MAX_VALUE ; let maxValue = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { minValue = Math . min ( minValue , A [ i ] ) ; maxValue = Math . max ( maxValue , A [ i ] ) ; } let pos_min = - 1 , pos_max = - 1 , ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( A [ i ] == minValue ) pos_min = i ; if ( A [ i ] == maxValue ) pos_max = i ; if ( pos_max != - 1 && pos_min != - 1 ) ans = Math . min ( ans , Math . abs ( pos_min - pos_max ) + 1 ) ; } return ans ; } let A = [ 1 , 5 , 9 , 7 , 1 , 9 , 4 ] ; let n = A . length ; document . write ( minSubarray ( A , n ) ) ;

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