dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let MAX = 10 function countPalindromes ( n , m , matrix ) { let count = n * m ; let length_of_sequence_row ; let length_of_sequence_column ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { length_of_sequence_row = Math . min ( j , m - 1 - j ) ; length_of_sequence_column = Math . min ( i , n - i - 1 ) ; for ( let k = 1 ; k <= length_of_sequence_row ; k ++ ) { if ( matrix [ i ] [ j - k ] == matrix [ i ] [ j + k ] ) { count ++ ; } else { break ; } } for ( let k = 1 ; k <= length_of_sequence_column ; k ++ ) { if ( matrix [ i - k ] [ j ] == matrix [ i + k ] [ j ] ) { count ++ ; } else { break ; } } } } return count ; } let m = 3 , n = 3 ; let matrix = [ [ 2 , 1 , 2 ] , [ 1 , 1 , 1 ] , [ 2 , 1 , 2 ] ] ; document . write ( countPalindromes ( n , m , matrix ) + " " ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Javascript program:
function set_bits ( n ) { let count = 0 ; while ( n ) { count += n % 2 ; n = parseInt ( n / 2 ) ; } return count ; } function minSteps ( n ) { let ans = 0 ; while ( n != 1 ) { if ( n % 2 == 0 ) n = parseInt ( n / 2 ) ; else if ( n == 3 || set_bits ( n - 1 ) < set_bits ( n + 1 ) ) n -- ; else n ++ ; ans ++ ; } return ans ; } let n = 15 ; document . write ( minSteps ( n ) ) ;

Accumulator variables: ans, count, n
Javascript program:
function lcm ( a , b ) { return ( a / __gcd ( a , b ) * b ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function findNums ( x ) { let ans = - 1 ; for ( let i = 1 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 && lcm ( i , Math . floor ( x / i ) ) == x ) { ans = i ; } } document . write ( ans + " " + Math . floor ( x / ans ) ) ; } let x = 12 ; findNums ( x ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var MAXN = 1000000 ; function maxCommonElement ( A , D , N ) { var cnt = Array ( MAXN ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = A [ i ] ; j < MAXN ; j += D [ i ] ) cnt [ j ] ++ ; } var ans = 0 ; var com = 0 ; for ( var i = 0 ; i < MAXN ; i ++ ) { if ( cnt [ i ] > ans ) { ans = cnt [ i ] ; com = i ; } } return com ; } var A = [ 13 , 1 , 2 , 5 ] , D = [ 5 , 10 , 1 , 12 ] ; var N = A . length ; document . write ( maxCommonElement ( A , D , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findTrailingZeros ( n ) { if ( n & 1 ) return 0 ; else { let ans = 0 ; n = parseInt ( n / 2 ) ; while ( n ) { ans += parseInt ( n / 5 ) ; n = parseInt ( n / 5 ) ; } return ans ; } } let n = 12 ; document . write ( findTrailingZeros ( n ) ) ;

Accumulator variables: ans
Javascript program:
function maxGCD ( N , K ) { var minSum = ( K * ( K + 1 ) ) / 2 ; if ( N < minSum ) return - 1 ; var i = parseInt ( Math . sqrt ( N ) ) ; var res = 1 ; while ( i >= 1 ) { if ( N % i == 0 ) { if ( i >= minSum ) res = Math . max ( res , N / i ) ; if ( N / i >= minSum ) res = Math . max ( res , i ) ; } i -- ; } return res ; } var N = 18 , K = 3 ; document . write ( maxGCD ( N , K ) ) ;

Accumulator variables: i
Javascript program:
function checkZeroArray ( arr , n ) { let sum = 0 , maximum = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + arr [ i ] ; maximum = Math . max ( maximum , arr [ i ] ) ; } if ( sum % 2 == 0 && maximum <= sum / 2 ) return true ; return false ; } let arr = [ 1 , 2 , 1 , 2 , 2 ] ; let n = arr . length ; if ( checkZeroArray ( arr , n ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function subArray ( arr , n , m ) { var i ; var mp = new Map ( ) ; for ( i = 0 ; i < n ; i ++ ) { mp . set ( arr [ i ] , i + 1 ) ; } var sumcur = 0 ; var p = 1000000000 ; var ans = [ ] ; for ( i = 1 ; i <= m ; i ++ ) { sumcur += mp . get ( i ) ; p = Math . min ( p , mp . get ( i ) ) ; var val = p * i - i + parseInt ( ( i * ( i + 1 ) ) / 2 ) ; if ( i == m ) { if ( val == sumcur ) { return true ; } else return false ; } } } var arr = [ 4 , 5 , 1 , 3 , 2 , 6 ] ; var n = arr . length ; var m = 3 ; if ( subArray ( arr , n , m ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sumcur
Iterator variables: i
Javascript program:
function isPalindrome ( s ) { var left = 0 , right = s . length - 1 ; while ( left <= right ) { if ( s [ left ] != s [ right ] ) { return false ; } left ++ ; right -- ; } return true ; } function getSum ( n ) { var start = Math . pow ( 10 , n - 1 ) ; var end = Math . pow ( 10 , n ) - 1 ; var sum = 0 ; for ( var i = start ; i <= end ; i ++ ) { var s = ( i . toString ( ) ) ; if ( isPalindrome ( s ) ) { sum += i ; } } return sum ; } var n = 1 ; var ans = getSum ( n ) ; document . write ( ans + " " ) ;

Index/key variables: left, right
Accumulator variables: i, left, right, sum
Iterator variables: i
Javascript program:
function cntSubSeq ( arr , n ) { let pos_count = 0 ; let neg_count = 0 ; let result ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos_count ++ ; if ( arr [ i ] < 0 ) neg_count ++ ; } result = Math . pow ( 2 , pos_count ) ; if ( neg_count > 0 ) result *= Math . pow ( 2 , neg_count - 1 ) ; result -= 1 ; return result ; } let arr = [ 2 , - 3 , - 1 , 4 ] ; let n = arr . length ; document . write ( cntSubSeq ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, neg_count, pos_count, result
Iterator variables: i
Javascript program:
function findMin ( arr , n ) { var m = 0 ; for ( var i = 0 ; i < n ; i ++ ) m = Math . max ( m , arr [ i ] ) ; var freq = Array ( m + 2 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; for ( var i = 1 ; i <= m + 1 ; i ++ ) { var j = i ; var cnt = 0 ; while ( j <= m ) { cnt += freq [ j ] ; j += i ; } if ( ! cnt ) return i ; } return m + 1 ; } var arr = [ 2 , 12 , 6 ] ; var n = arr . length ; document . write ( findMin ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i
Javascript program:
function findMin ( arr , n ) { var m = 0 ; for ( var i = 0 ; i < n ; i ++ ) m = Math . max ( m , arr [ i ] ) ; var cnt = Array ( m + 2 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 1 ; j * j <= arr [ i ] ; j ++ ) { if ( arr [ i ] % j == 0 ) { if ( j * j == arr [ i ] ) cnt [ j ] ++ ; else cnt [ j ] ++ , cnt [ arr [ i ] / j ] ++ ; } } } for ( var i = 1 ; i <= m + 1 ; i ++ ) if ( cnt [ i ] == 0 ) { return i ; } return - 1 ; } var arr = [ 2 , 12 , 6 ] ; var n = arr . length ; document . write ( findMin ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const sz = 1e5 ; let isPrime = new Array ( sz + 1 ) ; function sieve ( ) { isPrime . fill ( true ) isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( let j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } function printArray ( arr , len ) { for ( let i = 0 ; i < len ; i ++ ) { document . write ( arr [ i ] + ' ' ) ; } } function removePrimes ( arr , len ) { sieve ( ) ; for ( let i = 0 ; i < len ; i ++ ) { if ( isPrime [ arr [ i ] ] ) { for ( let j = i ; j < len ; j ++ ) { arr [ j ] = arr [ j + 1 ] ; } i -- ; len -- ; } } printArray ( arr , len ) ; } let arr = [ 4 , 6 , 5 , 3 , 8 , 7 , 10 , 11 , 14 , 15 ] ; let len = arr . length ; removePrimes ( arr , len ) ;

Index/key variables: i, j
Accumulator variables: i, j, len
Iterator variables: i, j
Javascript program:
function minOR ( arr , n ) { if ( n == 1 ) return 0 ; var pre = Array ( n ) , suf = Array ( n ) ; pre [ 0 ] = arr [ 0 ] , suf [ n - 1 ] = arr [ n - 1 ] ; for ( var i = 1 ; i < n ; i ++ ) pre [ i ] = ( pre [ i - 1 ] arr [ i ] ) ; for ( var i = n - 2 ; i >= 0 ; i -- ) suf [ i ] = ( suf [ i + 1 ] arr [ i ] ) ; var ans = Math . min ( pre [ n - 2 ] , suf [ 1 ] ) ; for ( var i = 1 ; i < n - 1 ; i ++ ) ans = Math . min ( ans , ( pre [ i - 1 ] suf [ i + 1 ] ) ) ; return ans ; } var arr = [ 1 , 2 , 3 ] ; var n = arr . length ; document . write ( minOR ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function subgrids ( N , Z , row , col , r , c ) { var conrow = [ ] ; var concol = [ ] ; var K = Math . sqrt ( Z ) ; conrow . push ( row [ 0 ] - 0 - 1 ) ; conrow . push ( N + 1 - row [ r - 1 ] - 1 ) ; for ( var i = 1 ; i < r ; i ++ ) { conrow . push ( row [ i ] - row [ i - 1 ] - 1 ) ; } concol . push ( col [ 0 ] - 0 - 1 ) ; concol . push ( N + 1 - col - 1 ) ; for ( var i = 1 ; i < c ; i ++ ) { concol . push ( col [ i ] - col [ i - 1 ] - 1 ) ; } var row_size = conrow . length ; var col_size = concol . length ; var answer = 0 ; for ( var i = 0 ; i < row_size ; i ++ ) { for ( var j = 0 ; j < col_size ; j ++ ) { var total = parseInt ( concol [ j ] / K ) * parseInt ( conrow [ i ] / K ) ; answer += ( total ) ; } } return answer ; } var N = 8 , Z = 4 ; var row = [ 4 , 6 ] ; var col = [ 3 , 8 ] ; var r = row . length ; var c = col . length ; document . write ( subgrids ( N , Z , row , col , r , c ) ) ;

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function countDigits ( n ) { let cnt = 0 ; while ( n > 0 ) { cnt ++ ; n = Math . floor ( n / 10 ) ; } return cnt ; } function digitPowSum ( n ) { let sum = 0 ; let pw = countDigits ( n ) ; while ( n > 0 ) { let d = n % 10 ; sum += Math . pow ( d , pw ) ; pw -- ; n = Math . floor ( n / 10 ) ; } return sum ; } function countNum ( n ) { let count = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { if ( i == digitPowSum ( i ) ) { count ++ ; } } return count ; } let n = 200 ; document . write ( countNum ( n ) ) ;

Accumulator variables: cnt, count, i, pw, sum
Iterator variables: i
Javascript program:
function perfectSquares ( l , r ) { for ( let i = l ; i <= r ; i ++ ) { if ( Math . sqrt ( i ) == parseInt ( Math . sqrt ( i ) ) ) document . write ( i + " " ) ; } } let l = 2 ; let r = 24 ; perfectSquares ( l , r )

Accumulator variables: i
Iterator variables: i
Javascript program:
function perfectSquares ( l , r ) { let number = Math . ceil ( Math . sqrt ( l ) ) ; let n2 = number * number ; number = ( number * 2 ) + 1 ; while ( ( n2 >= l && n2 <= r ) ) { document . write ( n2 + " " ) ; n2 = n2 + number ; number += 2 ; } } let l = 2 , r = 24 ; perfectSquares ( l , r ) ;

Accumulator variables: number
Javascript program:
function xorK ( n , k ) { let res = n ; for ( let i = 1 ; i < k ; i ++ ) res = ( res ^ n ) ; return n ; } let n = 123 , k = 3 ; document . write ( xorK ( n , k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findRemainders ( n ) { var vc = new Set ( ) ; for ( var i = 1 ; i <= Math . ceil ( Math . sqrt ( n ) ) ; i ++ ) vc . add ( parseInt ( n / i ) ) ; for ( var i = parseInt ( n / Math . ceil ( Math . sqrt ( n ) ) ) - 1 ; i >= 0 ; i -- ) vc . add ( i ) ; [ ... vc ] . sort ( ( a , b ) => a - b ) . forEach ( it => { document . write ( it + " " ) ; } ) ; } var n = 5 ; findRemainders ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 100005 ; var prime = new Array ( MAX ) . fill ( false ) ; function SieveOfEratosthenes ( ) { for ( i = 0 ; i < MAX ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] ) { for ( i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } } function countPrimes ( n ) { SieveOfEratosthenes ( ) ; var cnt = 0 ; for ( i = 2 ; i < n ; i ++ ) { if ( prime [ i ] && prime [ i - 2 ] ) cnt ++ ; } return cnt ; } var n = 11 ; document . write ( countPrimes ( n ) ) ;

Index/key variables: i, p
Accumulator variables: cnt, i, p
Iterator variables: i, p
Javascript program:
var MAX = 10 ; function distinctDigits ( x ) { var present = new Array ( MAX ) . fill ( false ) ; while ( x > 0 ) { var digit = x % 10 ; if ( present [ digit ] ) return false ; present [ digit ] = true ; x = parseInt ( x / 10 ) ; } return true ; } function findK ( l , r ) { var maxExp = Number . MIN_VALUE ; var k = - 1 ; for ( var i = l ; i <= r ; i ++ ) { if ( distinctDigits ( i ) ) { var exp = ( l - i ) * ( i - r ) ; if ( exp >= maxExp ) { k = i ; maxExp = exp ; } } } return k ; } var l = 50 , r = 60 ; document . write ( findK ( l , r ) ) ;

Index/key variables: digit
Accumulator variables: i
Iterator variables: i
Javascript program:
function findPerm ( Q , n ) { var minval = 0 , qsum = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { qsum += Q [ i ] ; if ( qsum < minval ) minval = qsum ; } var P = Array ( n ) ; P [ 0 ] = 1 - minval ; var permFound = true ; for ( var i = 0 ; i < n - 1 ; i ++ ) { P [ i + 1 ] = P [ i ] + Q [ i ] ; if ( P [ i + 1 ] > n P [ i + 1 ] < 1 ) { permFound = false ; break ; } } if ( permFound ) { for ( var i = 0 ; i < n ; i ++ ) { document . write ( P [ i ] + " " ) ; } } else { document . write ( - 1 ) ; } } var Q = [ - 2 , 1 ] ; var n = 1 + Q . length ; findPerm ( Q , n ) ;

Index/key variables: i
Accumulator variables: i, qsum
Iterator variables: i
Boolean variables: permFound
Javascript program:
function Hex ( num ) { let m = new Map ( ) ; let digit = ' ' . charCodeAt ( 0 ) ; let c = ' ' . charCodeAt ( 0 ) ; for ( let i = 0 ; i <= 15 ; i ++ ) { if ( i < 10 ) { m . set ( i , String . fromCharCode ( digit ) ) ; digit ++ ; } else { m . set ( i , String . fromCharCode ( c ) ) ; c ++ ; } } let res = " " ; if ( num == 0 ) { return " " ; } if ( num > 0 ) { while ( num != 0 ) { res = m . get ( num % 16 ) + res ; num = Math . floor ( num / 16 ) ; } } else { let n = num + Math . pow ( 2 , 32 ) ; while ( n != 0 ) { res = m . get ( n % 16 ) + res ; n = Math . floor ( n / 16 ) ; } } return res ; } let x = 134 , y = - 1 , z = - 234 ; document . write ( " " ) ; document . write ( x + " " + Hex ( x ) + " " ) ; document . write ( y + " " + Hex ( y ) + " " ) ; document . write ( z + " " + Hex ( z ) + " " ) ;

Accumulator variables: c, digit, i
Iterator variables: i
Javascript program:
function min_changes ( a , n ) { let ans_a = 0 , ans_b = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( a [ i ] == 0 ) ans_a ++ ; else ans_b ++ ; } else { if ( a [ i ] == 0 ) ans_b ++ ; else ans_a ++ ; } } return Math . min ( ans_a , ans_b ) ; } let a = [ 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 ] ; let n = a . length ; document . write ( min_changes ( a , n ) ) ;

Index/key variables: i
Accumulator variables: ans_a, ans_b, i
Iterator variables: i
Javascript program:
function minNum ( num , k ) { let len = num . length ; if ( len == 0 k == 0 ) { let num_str = num . join ( " " ) ; return num_str ; } if ( len == 1 ) return " " ; if ( num [ 0 ] != ' ' ) { num [ 0 ] = ' ' ; k -- ; } let i = 1 ; while ( k > 0 && i < len ) { if ( num [ i ] != ' ' ) { num [ i ] = ' ' ; k -- ; } i ++ ; } let num_str = num . join ( " " ) ; return num_str ; } let num = " " ; let k = 3 ; document . write ( minNum ( num . split ( " " ) , k ) ) ;

Index/key variables: i
Accumulator variables: i, k
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function removeLeadingZeros ( a ) { if ( a != null && a . data == 0 ) return removeLeadingZeros ( a . next ) ; else return a ; } function getSize ( a ) { let sz = 0 ; while ( a != null ) { a = a . next ; sz ++ ; } return sz ; } 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 compare ( a , b ) { a = removeLeadingZeros ( a ) ; b = removeLeadingZeros ( b ) ; let lenA = getSize ( a ) ; let lenB = getSize ( b ) ; if ( lenA > lenB ) { return 1 ; } else if ( lenB > lenA ) { return - 1 ; } while ( a != null && b != null ) { if ( a . data > b . data ) return 1 ; else if ( a . data < b . data ) return - 1 ; a = a . next ; b = b . next ; } return 0 ; } var a = null ; a = push ( a , 7 ) ; a = push ( a , 6 ) ; a = push ( a , 5 ) ; var b = null ; b = push ( b , 3 ) ; b = push ( b , 3 ) ; b = push ( b , 2 ) ; document . write ( compare ( a , b ) ) ;

Accumulator variables: sz
Class/struct names: Node
Javascript program:
function sumArr ( arr , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } function sumModArr ( arr , n ) { for ( i = 0 ; i < n - 1 ; i ++ ) { var subSum = 0 ; for ( j = i + 1 ; j < n ; j ++ ) { subSum += arr [ j ] ; } arr [ i ] -= subSum ; } return sumArr ( arr , n ) ; } var arr = [ 40 , 25 , 12 , 10 ] ; var n = arr . length ; document . write ( sumModArr ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, subSum, sum
Iterator variables: i, j
Javascript program:
function minHealth ( health , n ) { var gcd = 0 ; for ( var i = 0 ; i < n ; i ++ ) { gcd = __gcd ( gcd , health [ i ] ) ; } return gcd ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var health = [ 5 , 6 , 1 , 2 , 3 , 4 ] ; var n = health . length ; document . write ( minHealth ( health , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function constructArr ( pair , n ) { let size = Math . floor ( ( 1 + Math . sqrt ( 1 + 8 * n ) ) / 2 ) ; let arr = new Array ( size ) ; arr [ 0 ] = Math . floor ( Math . sqrt ( ( pair [ 0 ] * pair [ 1 ] ) / pair [ size - 1 ] ) ) ; for ( let i = 1 ; i < size ; i ++ ) arr [ i ] = Math . floor ( pair [ i - 1 ] / arr [ 0 ] ) ; printArr ( arr , size ) ; } let pair = [ 48 , 18 , 24 , 24 , 32 , 12 ] ; let n = pair . length ; constructArr ( pair , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findPairs ( arr , n ) { let cntEven = 0 , cntOdd = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) cntEven ++ ; else cntOdd ++ ; } let evenPairs = 0 ; evenPairs += ( ( cntEven * ( cntEven - 1 ) ) / 2 ) ; evenPairs += ( ( cntOdd * ( cntOdd - 1 ) ) / 2 ) ; let oddPairs = 0 ; oddPairs += ( cntEven * cntOdd ) ; document . write ( " " + oddPairs + " " ) ; document . write ( " " + evenPairs ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; findPairs ( arr , n ) ;

Index/key variables: i
Accumulator variables: cntEven, cntOdd, evenPairs, i, oddPairs
Iterator variables: i
Javascript program:
MOD = 1000000007 ; function factMod ( n ) { var fact = 1 ; for ( i = 2 ; i <= n ; i ++ ) { fact *= ( i % MOD ) ; fact %= MOD ; } return parseInt ( fact ) ; } function countWays ( n , m ) { return factMod ( m ) ; } var n = 2 , m = 2 ; document . write ( countWays ( n , m ) ) ;

Accumulator variables: fact, i
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { var res = 1 ; if ( k > n - k ) k = n - k ; for ( var i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res = parseInt ( res / ( i + 1 ) ) ; } return res ; } function Fuss_catalan ( n ) { var c = binomialCoeff ( 3 * n , n ) ; return parseInt ( c / ( 2 * n + 1 ) ) ; } for ( var i = 0 ; i < 10 ; i ++ ) document . write ( Fuss_catalan ( i ) + " " ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function isComposite ( n ) { for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return true ; } return false ; } function Power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( y & 1 ) { res = ( res * x ) % p ; } x = ( x * x ) % p ; } return res ; } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function isEulerPseudoprime ( N , A ) { if ( A <= 0 ) return false ; if ( N % 2 == 0 || ! isComposite ( N ) ) return false ; if ( __gcd ( A , N ) != 1 ) return false ; let mod = Power ( A , ( N - 1 ) / 2 , N ) ; if ( mod != 1 && mod != N - 1 ) return false ; return true ; } let N = 121 , A = 3 ; if ( isEulerPseudoprime ( N , A ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
const sz = 1e5 ; let isPrime = new Array ( sz + 1 ) ; function sieve ( ) { isPrime . fill ( true ) ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( let j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } function minDifference ( L , R ) { let fst = 0 ; for ( let i = L ; i <= R ; i ++ ) { if ( isPrime [ i ] ) { fst = i ; break ; } } let snd = 0 ; for ( let i = fst + 1 ; i <= R ; i ++ ) { if ( isPrime [ i ] ) { snd = i ; break ; } } if ( snd == 0 ) return - 1 ; let diff = snd - fst ; let left = snd + 1 ; let right = R ; for ( let i = left ; i <= right ; i ++ ) { if ( isPrime [ i ] ) { if ( i - snd <= diff ) { fst = snd ; snd = i ; diff = snd - fst ; } } } return diff ; } sieve ( ) ; let L = 21 , R = 50 ; document . write ( minDifference ( L , R ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findCnt ( arr , n , k ) { var ret = 0 ; var i = 0 ; while ( i < n ) { var j = i + 1 ; while ( j < n && arr [ j ] >= arr [ j - 1 ] ) j ++ ; var x = Math . max ( 0 , j - i - k + 1 ) ; ret += ( x * ( x + 1 ) ) / 2 ; i = j ; } return ret ; } var arr = [ 5 , 4 , 3 , 2 , 1 ] ; var n = arr . length ; var k = 2 ; document . write ( findCnt ( arr , n , k ) ) ;

Index/key variables: j
Accumulator variables: j, ret
Javascript program:
function countElements ( p , n ) { var ans = 0 ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( p [ i - 1 ] > p [ i ] && p [ i ] > p [ i + 1 ] ) ans ++ ; else if ( p [ i - 1 ] < p [ i ] && p [ i ] < p [ i + 1 ] ) ans ++ ; } return ans ; } var p = [ 2 , 5 , 1 , 3 , 4 ] ; var n = p . length ; document . write ( countElements ( p , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function cntSubArrays ( arr , n , k ) { var res = 0 ; var i = 0 ; while ( i < n ) { var j = i + 1 ; while ( j < n && arr [ j ] >= arr [ j - 1 ] ) j ++ ; res += Math . max ( j - i - k + 1 , 0 ) ; i = j ; } return res ; } var arr = [ 1 , 2 , 3 , 2 , 5 ] ; var n = arr . length ; var k = 2 ; document . write ( cntSubArrays ( arr , n , k ) ) ;

Index/key variables: j
Accumulator variables: j, res
Javascript program:
function cntPairs ( a , n ) { var odd = 0 , even = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) odd ++ ; else if ( ( a [ i ] / 2 ) % 2 == 1 ) even ++ ; } var ans = odd * even + ( odd * ( odd - 1 ) ) / 2 ; return ans ; } var a = [ 4 , 2 , 7 , 11 , 14 , 15 , 18 ] ; var n = a . length ; document . write ( cntPairs ( a , n ) ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function isPossible ( a , n ) { var cur = a [ 0 ] ; cur -- ; for ( var i = 1 ; i < n ; i ++ ) { var nxt = a [ i ] ; if ( nxt > cur ) nxt -- ; else if ( nxt < cur ) return false ; cur = nxt ; } return true ; } var a = [ 1 , 2 , 1 , 2 , 3 ] ; var n = a . length ; if ( isPossible ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: cur, i, nxt
Iterator variables: i
Javascript program:
function max_element ( a , n ) { let pre = new Array ( n ) ; pre [ 0 ] = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) pre [ i ] = Math . max ( pre [ i - 1 ] , a [ i ] ) ; let suf = new Array ( n ) ; suf [ n - 1 ] = a [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) suf [ i ] = Math . max ( suf [ i + 1 ] , a [ i ] ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i == 0 ) document . write ( suf [ i + 1 ] + " " ) ; else if ( i == n - 1 ) document . write ( pre [ i - 1 ] + " " ) ; else document . write ( Math . max ( pre [ i - 1 ] , suf [ i + 1 ] ) + " " ) ; } } let a = [ 2 , 5 , 6 , 1 , 3 ] ; let n = a . length ; max_element ( a , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPossible ( a , n ) { let k = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] != i + 1 ) k ++ ; } if ( k <= 2 ) return true ; return false ; } let a = [ 5 , 2 , 3 , 4 , 1 ] ; let n = a . length ; if ( isPossible ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

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