dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function binomialCoeff ( n , k ) { var C = new Array ( n + 1 ) ; for ( var i = 0 ; i < C . length ; i ++ ) { C [ i ] = new Array ( k + 1 ) ; } var i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } function findMax ( n ) { return binomialCoeff ( n , Math . floor ( n / 2 ) ) ; } var n = 5 ; document . write ( binomialCoeff ( n , Math . floor ( n / 2 ) ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countKdivPairs ( A , n , K ) { var freq = Array ( K ) . fill ( 0 ) ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var rem = A [ i ] % K ; ans += freq [ ( K - rem ) % K ] ; freq [ rem ] ++ ; } return ans ; } var A = [ 2 , 2 , 1 , 7 , 5 , 3 ] ; var n = A . length ; var K = 4 ; document . write ( countKdivPairs ( A , n , K ) ) ;

Index/key variables: i, rem
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function min_visible_bottles ( arr , n ) { let m = new Map ( ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) } else { m . set ( arr [ i ] , 1 ) } ans = Math . max ( ans , m . get ( arr [ i ] ) ) ; } document . write ( " " + " " + ans + " " ) ; } let n = 8 ; let arr = [ 1 , 1 , 2 , 3 , 4 , 5 , 5 , 4 ] ; min_visible_bottles ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function create ( head , x ) { var temp , ptr = head ; temp = new Node ( ) ; temp . data = x ; temp . next = null ; if ( head == null ) head = temp ; else { while ( ptr . next != null ) { ptr = ptr . next ; } ptr . next = temp ; } return head ; } function removeNthFromEnd ( head , B ) { var len = 0 ; var tmp = head ; while ( tmp != null ) { len ++ ; tmp = tmp . next ; } if ( B > len ) { document . write ( " " + len ) ; document . write ( " " + B + " " ) ; document . write ( " " ) ; return head ; } else if ( B == len ) { return head . next ; } else { var diff = len - B ; var prev = null ; var curr = head ; for ( i = 0 ; i < diff ; i ++ ) { prev = curr ; curr = curr . next ; } prev . next = curr . next ; return head ; } } function display ( head ) { var temp = head ; while ( temp != null ) { document . write ( temp . data + " " ) ; temp = temp . next ; } document . write ( " " ) ; } var head = null ; head = create ( head , 1 ) ; head = create ( head , 2 ) ; head = create ( head , 3 ) ; head = create ( head , 4 ) ; head = create ( head , 5 ) ; var n = 2 ; document . write ( " " ) ; display ( head ) ; head = removeNthFromEnd ( head , 2 ) ; document . write ( " " ) ; display ( head ) ;

Accumulator variables: i, len
Iterator variables: i
Class/struct names: Node
Javascript program:
function solveEven ( n , arr , b ) { let left = n - 1 ; for ( let i = 0 ; i < parseInt ( n / 2 , 10 ) ; ++ i ) { b [ i ] = arr [ left ] ; left = left - 2 ; if ( left < 0 ) break ; } let right = 0 ; for ( let i = parseInt ( n / 2 , 10 ) ; i <= n - 1 ; ++ i ) { b [ i ] = arr [ right ] ; right = right + 2 ; if ( right > n - 2 ) break ; } } function solveOdd ( n , arr , b ) { let left = n - 1 ; for ( let i = 0 ; i < parseInt ( n / 2 , 10 ) + 1 ; ++ i ) { b [ i ] = arr [ left ] ; left = left - 2 ; if ( left < 0 ) break ; } let right = 1 ; for ( let i = parseInt ( n / 2 , 10 ) + 1 ; i <= n - 1 ; ++ i ) { b [ i ] = arr [ right ] ; right = right + 2 ; if ( right > n - 2 ) break ; } } function solve ( n , arr ) { let b = new Array ( n ) ; if ( n % 2 == 0 ) solveEven ( n , arr , b ) ; else solveOdd ( n , arr , b ) ; for ( let i = 0 ; i <= n - 1 ; ++ i ) { document . write ( b [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 ] ; let n = arr . length ; solve ( n , arr ) ;

Index/key variables: i, left, right
Iterator variables: i
Javascript program:
function sum_of_elements ( arr , n ) { var sumfirst = 0 , sumsecond = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i < parseInt ( n / 2 ) ) { sumfirst += arr [ i ] ; } else { sumsecond += arr [ i ] ; } } document . write ( " " + sumfirst + " " ) ; document . write ( " " + sumsecond + " " ) ; } var arr = [ 20 , 30 , 60 , 10 , 25 , 15 , 40 ] ; var n = arr . length ; sum_of_elements ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, sumfirst, sumsecond
Iterator variables: i
Javascript program:
function lowerWythoff ( n ) { var phi = ( 1 + Math . sqrt ( 5 ) ) / 2.0 ; for ( var i = 1 ; i <= n ; i ++ ) { var ans = Math . floor ( i * phi ) ; document . write ( ans ) ; if ( i != n ) document . write ( " " ) ; } } var n = 5 ; lowerWythoff ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function insert ( root , item ) { var ptr , temp ; temp = new Node ( ) ; temp . data = item ; temp . next = null ; if ( root == null ) root = temp ; else { ptr = root ; while ( ptr . next != null ) ptr = ptr . next ; ptr . next = temp ; } return root ; } function newList ( root1 , root2 ) { var ptr1 = root1 , ptr2 = root2 , ptr ; var root = null , temp ; while ( ptr1 != null ) { temp = new Node ( ) ; temp . next = null ; if ( ptr1 . data < ptr2 . data ) temp . data = ptr2 . data ; else temp . data = ptr1 . data ; if ( root == null ) root = temp ; else { ptr = root ; while ( ptr . next != null ) ptr = ptr . next ; ptr . next = temp ; } ptr1 = ptr1 . next ; ptr2 = ptr2 . next ; } return root ; } function display ( root ) { while ( root != null ) { document . write ( root . data + " " ) ; root = root . next ; } document . write ( " " ) ; } root1 = null , root2 = null , root = null ; root1 = insert ( root1 , 5 ) ; root1 = insert ( root1 , 2 ) ; root1 = insert ( root1 , 3 ) ; root1 = insert ( root1 , 8 ) ; document . write ( " " ) ; display ( root1 ) ; root2 = insert ( root2 , 1 ) ; root2 = insert ( root2 , 7 ) ; root2 = insert ( root2 , 4 ) ; root2 = insert ( root2 , 5 ) ; document . write ( " " ) ; display ( root2 ) ; root = newList ( root1 , root2 ) ; document . write ( " " ) ; display ( root ) ;

Class/struct names: Node
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function countQuadruplets ( l , r , k ) { var count = 0 ; for ( u = l ; u <= r ; u ++ ) { for ( v = l ; v <= r ; v ++ ) { for ( w = l ; w <= r ; w ++ ) { for ( x = l ; x <= r ; x ++ ) { if ( gcd ( gcd ( u , v ) , gcd ( w , x ) ) == k ) count ++ ; } } } } return count ; } var l = 1 , r = 10 , k = 2 ; document . write ( countQuadruplets ( l , r , k ) ) ;

Accumulator variables: count, u, v, w, x
Iterator variables: u, v, w, x
Javascript program:
function findIndex ( a , n ) { let res = 0 ; let min_diff = Number . MAX_VALUE ; let prod = new Array ( n ) ; prod [ 0 ] = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prod [ i ] = prod [ i - 1 ] * a [ i ] ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let curr_diff = Math . abs ( parseInt ( prod [ n - 1 ] / prod [ i ] , 10 ) - prod [ i ] ) ; if ( curr_diff < min_diff ) { min_diff = curr_diff ; res = i ; } } return res ; } let arr = [ 3 , 2 , 5 , 7 , 2 , 9 ] ; let N = arr . length ; document . write ( findIndex ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function printNumbers ( a , n , x ) { let flag = false ; for ( let i = 0 ; i < n ; i ++ ) { let num = a [ i ] ; let g = __gcd ( num , x ) ; while ( g != 1 ) { num = parseInt ( num / g ) ; g = __gcd ( num , x ) ; } if ( num == 1 ) { flag = true ; document . write ( a [ i ] + " " ) ; } } if ( ! flag ) document . write ( " " ) ; } let x = 60 ; let a = [ 2 , 5 , 10 , 7 , 17 ] ; let n = a . length ; printNumbers ( a , n , x ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function print ( rStation , n ) { for ( var i = 1 ; i <= n ; i ++ ) document . write ( rStation [ i ] + " " ) ; document . write ( " " ) ; } function radiated_Station ( station , n ) { var rStation = [ ] ; rStation . length = 6 ; rStation . fill ( 0 ) for ( var i = 1 ; i <= n ; i ++ ) { var li = i - 1 , ri = i + 1 ; var lRad = station [ i ] - 1 , rRad = station [ i ] - 1 ; rStation [ i ] += station [ i ] ; while ( li >= 1 && lRad >= 1 ) { rStation [ li -- ] += lRad -- ; } while ( ri <= n && rRad >= 1 ) { rStation [ ri ++ ] += rRad -- ; } } print ( rStation , n ) ; } var station = [ 0 , 7 , 9 , 12 , 2 , 5 ] var n = station . length - 1 ; radiated_Station ( station , n ) ;

Index/key variables: i
Accumulator variables: i, lRad, li, rRad, ri
Iterator variables: i
Javascript program:
function findMaximumDiff ( a , n ) { var ind1 = 0 ; for ( i = n - 1 ; i > 0 ; i -- ) { if ( a [ 0 ] != a [ i ] ) { ind1 = i ; break ; } } var ind2 = 0 ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( a [ n - 1 ] != a [ i ] ) { ind2 = ( n - 1 - i ) ; break ; } } return Math . max ( ind1 , ind2 ) ; } var a = [ 1 , 2 , 3 , 2 , 3 ] ; var n = a . length ; document . write ( findMaximumDiff ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 100005 ; let n = 10 ; let tree = [ ] ; let currentIdx = 0 ; let startIdx ; let endIdx ; let p ; function Add_edge ( u , v ) { tree [ u ] . push ( v ) ; tree [ v ] . push ( u ) ; } function intisalise ( ) { startIdx = new Array ( n + 1 ) ; endIdx = new Array ( n + 1 ) ; p = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { startIdx [ i ] = 0 ; endIdx [ i ] = 0 ; p [ i ] = 0 ; } } function Dfs ( ch , par ) { p [ currentIdx ] = ch ; startIdx [ ch ] = currentIdx ++ ; for ( let c = 0 ; c < tree [ ch ] . length ; c ++ ) { if ( tree [ ch ] != par ) Dfs ( tree [ ch ] , ch ) ; } endIdx [ ch ] = currentIdx - 1 ; } function findNode ( v , k ) { k += startIdx [ v ] - 1 ; if ( k <= endIdx [ v ] ) return p [ k ] ; return - 1 ; } n = 9 ; for ( let i = 0 ; i <= n ; i ++ ) tree . push ( [ ] ) ; Add_edge ( 1 , 2 ) ; Add_edge ( 1 , 3 ) ; Add_edge ( 1 , 4 ) ; Add_edge ( 3 , 5 ) ; Add_edge ( 3 , 7 ) ; Add_edge ( 5 , 6 ) ; Add_edge ( 5 , 8 ) ; Add_edge ( 7 , 9 ) ; intisalise ( ) ; Dfs ( 1 , 0 ) ; let v = 3 , k = 4 ; document . write ( findNode ( v , k ) ) ;

Index/key variables: ch, currentIdx, i, k, u, v
Accumulator variables: c, currentIdx, i, k
Iterator variables: c, i
Javascript program:
function sum ( k , n ) { let sum = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { let p = 1 ; for ( let j = 0 ; j < n - i ; j ++ ) { p = p * k ; } for ( let j = 0 ; j < i ; j ++ ) { p = p * ( k - 1 ) ; } sum = sum + p ; } return sum ; } let n = 3 ; let K = 3 ; document . write ( sum ( K , n ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function is_prime ( num ) { var count = 0 ; for ( i = 1 ; i * i <= ( num ) ; i ++ ) { if ( ( num ) % i == 0 ) { if ( i * i != ( num ) ) count += 2 ; else count ++ ; } } if ( count == 2 ) return true ; else return false ; } function is_divisible ( n ) { if ( n == 1 ) { return " " ; } else { if ( is_prime ( n + 1 ) ) return " " ; else return " " ; } } var n ; n = 3 ; document . write ( is_divisible ( n ) + " " ) ; n = 4 ; document . write ( is_divisible ( n ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
let MAX = 100005 ; function partial_sum ( prefix_sum , arr , n ) { for ( let i = 1 ; i <= n ; i ++ ) { prefix_sum [ i ] = ( prefix_sum [ i - 1 ] + arr [ i - 1 ] ) ; } return prefix_sum ; } function countSubarrays ( arr , n , k ) { let prefix_sum = new Array ( MAX ) ; prefix_sum [ 0 ] = 0 ; prefix_sum = partial_sum ( prefix_sum , arr , n ) ; let sum ; if ( k == 1 ) { sum = 0 ; let m = new Map ( ) ; for ( let i = n ; i >= 0 ; i -- ) { if ( m . has ( prefix_sum [ i ] + 1 ) ) sum += m . get ( prefix_sum [ i ] + 1 ) ; if ( m . has ( prefix_sum [ i ] ) ) m . set ( prefix_sum [ i ] , m . get ( prefix_sum [ i ] ) + 1 ) ; else m . set ( prefix_sum [ i ] , 1 ) ; } return sum ; } if ( k == - 1 ) { sum = 0 ; let m = new Map ( ) ; for ( let i = n ; i >= 0 ; i -- ) { if ( m . has ( prefix_sum [ i ] + 1 ) ) sum += m . get ( prefix_sum [ i ] + 1 ) ; if ( m . has ( prefix_sum [ i ] - 1 ) ) sum += m . get ( prefix_sum [ i ] - 1 ) ; if ( m . has ( prefix_sum [ i ] ) ) m . set ( prefix_sum [ i ] , m . get ( prefix_sum [ i ] ) + 1 ) ; else m . set ( prefix_sum [ i ] , 1 ) ; } return sum ; } sum = 0 ; let b , l = 100000000000000 ; let m = new Map ( ) ; for ( let i = n ; i >= 0 ; i -- ) { b = 1 ; while ( true ) { if ( b > l ) break ; if ( m . has ( prefix_sum [ i ] + b ) ) sum += m . get ( prefix_sum [ i ] + b ) ; b *= k ; } if ( m . has ( prefix_sum [ i ] ) ) m . set ( ( prefix_sum [ i ] ) , m . get ( prefix_sum [ i ] ) + 1 ) ; else m . set ( ( prefix_sum [ i ] ) , 1 ) ; } return sum ; } let arr = [ 2 , 2 , 2 , 2 ] ; let n = arr . length ; let k = 2 ; document . write ( countSubarrays ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: b, i, sum
Iterator variables: i
Javascript program:
let mod = ( 1e9 + 7 ) ; function BitOperations ( a , n , b , m ) { let ch1 = a . split ( ' ' ) ; ch1 . reverse ( ) ; a = ch1 . join ( " " ) ; let ch2 = b . split ( ' ' ) ; ch2 . reverse ( ) ; b = ch2 . join ( " " ) ; let c = 0 ; for ( let i = 0 ; i < m ; i ++ ) if ( b [ i ] == ' ' ) c ++ ; let power = new Array ( n ) ; power [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) power [ i ] = ( power [ i - 1 ] * 2 ) % mod ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == ' ' ) { ans += c * power [ i ] ; if ( ans >= mod ) ans %= mod ; } if ( b [ i ] == ' ' ) c -- ; if ( c == 0 ) break ; } return ans ; } let a = " " , b = " " ; let n = a . length , m = b . length ; document . write ( BitOperations ( a , n , b , m ) ) ;

Index/key variables: i
Accumulator variables: ans, c, i
Iterator variables: i
Javascript program:
function sieve ( maxEle , prime ) { prime [ 0 ] = prime [ 1 ] = 1 ; for ( var i = 2 ; i * i <= maxEle ; i ++ ) { if ( ! prime [ i ] ) { for ( var j = 2 * i ; j <= maxEle ; j += i ) prime [ j ] = 1 ; } } } function digitSum ( n ) { var sum = 0 ; while ( n ) { sum += n % 10 ; n = parseInt ( n / 10 ) ; } return sum ; } function printAdditivePrime ( arr , n ) { var maxEle = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var prime = Array ( maxEle + 1 ) . fill ( 0 ) ; sieve ( maxEle , prime ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] == 0 ) { var sum = digitSum ( arr [ i ] ) ; if ( prime [ sum ] == 0 ) document . write ( arr [ i ] + " " ) ; } } } var a = [ 2 , 4 , 6 , 11 , 12 , 18 , 7 ] ; var n = a . length ; printAdditivePrime ( a , n ) ;

Index/key variables: i, j, sum
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
using System ; class GFG { function nthTerm ( n ) { let nth ; if ( n % 2 == 0 ) nth = 2 * ( ( n * n ) - n ) ; else nth = ( 2 * n * n ) - n ; return nth ; } let n = 5 ; document . write ( nthTerm ( n ) + " " ) ; n = 25 ; document . write ( nthTerm ( n ) + " " ) ; n = 25000000 ; document . write ( nthTerm ( n ) + " " ) ; n = 250000007 ; document . write ( nthTerm ( n ) + " " ) ;

Class/struct names: GFG
Javascript program:
function countDivisors ( n ) { var x = 0 , ans = 1 ; while ( n % 2 == 0 ) { x ++ ; n = n / 2 ; } ans = ans * ( x + 1 ) ; for ( var i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { x = 0 ; while ( n % i == 0 ) { x ++ ; n = n / i ; } ans = ans * ( x + 1 ) ; } if ( n > 2 ) ans = ans * 2 ; return ans ; } function getTotalCount ( n , k ) { var k_count = countDivisors ( k ) ; var count = 0 ; for ( var i = 1 ; i < n ; i ++ ) if ( k_count == countDivisors ( i ) ) count ++ ; if ( k < n ) count = count - 1 ; return count ; } var n = 500 , k = 6 ; document . write ( getTotalCount ( n , k ) ) ;

Accumulator variables: count, i, x
Iterator variables: i
Javascript program:
let MAX_VAL = 200000 ; function countIntervals ( arr , V , N ) { let min = Number . MAX_VALUE , max = Number . MIN_VALUE ; let li , ri ; let freq = new Array ( MAX_VAL ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { li = arr [ i ] [ 0 ] ; freq [ li ] = freq [ li ] + 1 ; ri = arr [ i ] [ 1 ] ; freq [ ri + 1 ] = freq [ ri + 1 ] - 1 ; if ( li < min ) min = li ; if ( ri > max ) max = ri ; } for ( let i = min ; i <= max ; i ++ ) freq [ i ] = freq [ i ] + freq [ i - 1 ] ; return freq [ V ] ; } let arr = [ [ 1 , 10 ] , [ 5 , 10 ] , [ 15 , 25 ] , [ 7 , 12 ] , [ 20 , 25 ] ] ; let V = 7 ; let N = arr . length ; document . write ( countIntervals ( arr , V , N ) ) ;

Index/key variables: V, i, li
Accumulator variables: i
Iterator variables: i
Javascript program:
function prletGroups ( n ) { let x = 1 ; let y = n * n ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n / 2 ; j ++ ) { document . write ( " " + x + " " + y + " " ) ; x ++ ; y -- ; } document . write ( " " ) ; } } let n = 4 ; prletGroups ( n ) ;

Accumulator variables: i, j, x, y
Iterator variables: i, j
Javascript program:
function minimum ( n ) { let product = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { while ( n % i == 0 ) n = n / i ; product = product * i ; } } if ( n >= 2 ) product = product * n ; return product ; } let n = 20 ; document . write ( minimum ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function numbers ( n , arr , m ) { let isZero = 0 , isFive = 0 ; let result = 0 ; if ( m < n ) { return - 1 ; } for ( let i = 0 ; i < m ; i ++ ) { if ( arr [ i ] == 0 ) { isZero = 1 ; } if ( arr [ i ] == 5 ) { isFive = 1 ; } } if ( isZero == 1 && isFive == 1 ) { result = 2 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { result = result * ( -- m ) ; } } else if ( isZero == 1 isFive == 1 ) { result = 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { result = result * ( -- m ) ; } } else { result = - 1 ; } return result ; } let n = 3 , m = 6 ; let arr = [ 2 , 3 , 5 , 6 , 7 , 9 ] ; document . write ( numbers ( n , arr , m ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( a , n ) { var maxAnd = Math . max ( ... a ) ; var maxOR = 0 ; for ( var i = 0 ; i < n ; i ++ ) { maxOR |= a [ i ] ; } document . write ( ( maxAnd + maxOR ) ) ; } var n = 4 ; var a = [ 3 , 5 , 6 , 1 ] ; maxSum ( a , n ) ;

Index/key variables: i
Accumulator variables: i, maxOR
Iterator variables: i
Javascript program:
var R = 3 ; var C = 4 ; function eqSet ( as , bs ) { if ( as . size !== bs . size ) return false ; for ( var a of as ) if ( ! bs . has ( a ) ) return false ; return true ; } function magic ( a , b , c , d , e , f , g , h , i ) { var s1 = new Set ( [ a , b , c , d , e , f , g , h , i ] ) ; var s2 = new Set ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ; if ( eqSet ( s1 , s2 ) && ( a + b + c ) == 15 && ( d + e + f ) == 15 && ( g + h + i ) == 15 && ( a + d + g ) == 15 && ( b + e + h ) == 15 && ( c + f + i ) == 15 && ( a + e + i ) == 15 && ( c + e + g ) == 15 ) return true ; return false ; } function CountMagicSquare ( Grid ) { var ans = 0 ; for ( var i = 0 ; i < R - 2 ; i ++ ) for ( var j = 0 ; j < C - 2 ; j ++ ) { if ( Grid [ i + 1 ] [ j + 1 ] != 5 ) continue ; if ( magic ( Grid [ i ] [ j ] , Grid [ i ] [ j + 1 ] , Grid [ i ] [ j + 2 ] , Grid [ i + 1 ] [ j ] , Grid [ i + 1 ] [ j + 1 ] , Grid [ i + 1 ] [ j + 2 ] , Grid [ i + 2 ] [ j ] , Grid [ i + 2 ] [ j + 1 ] , Grid [ i + 2 ] [ j + 2 ] ) ) ans += 1 ; } return ans ; } var G = [ [ 4 , 3 , 8 , 4 ] , [ 9 , 5 , 1 , 9 ] , [ 2 , 7 , 6 , 2 ] ] ; document . write ( CountMagicSquare ( G ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: a, i, j
Javascript program:
function sumSubarrayMins ( A , n ) { var left = Array ( n ) , right = Array ( n ) ; var s1 = [ ] , s2 = [ ] ; for ( var i = 0 ; i < n ; ++ i ) { var cnt = 1 ; while ( s1 . length != 0 && ( s1 [ s1 . length - 1 ] [ 0 ] ) > A [ i ] ) { cnt += s1 [ s1 . length - 1 ] [ 1 ] ; s1 . pop ( ) ; } s1 . push ( [ A [ i ] , cnt ] ) ; left [ i ] = cnt ; } for ( var i = n - 1 ; i >= 0 ; -- i ) { var cnt = 1 ; while ( s2 . length != 0 && ( s2 [ s2 . length - 1 ] [ 0 ] ) >= A [ i ] ) { cnt += s2 [ s2 . length - 1 ] [ 1 ] ; s2 . pop ( ) ; } s2 . push ( [ A [ i ] , cnt ] ) ; right [ i ] = cnt ; } var result = 0 ; for ( var i = 0 ; i < n ; ++ i ) result = ( result + A [ i ] * left [ i ] * right [ i ] ) ; return result ; } var A = [ 3 , 1 , 2 , 4 ] ; var n = A . length ; document . write ( sumSubarrayMins ( A , n ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Javascript program:
function getMin ( arr , n , k ) { let res = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) res = Math . min ( res , arr [ i ] ) ; } return res ; } function getMax ( arr , n , k ) { let res = Number . MIN_VALUE ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) res = Math . max ( res , arr [ i ] ) ; } return res ; } let arr = [ 10 , 1230 , 45 , 67 , 1 ] ; let k = 10 ; let n = arr . length ; document . write ( " " + getMin ( arr , n , k ) + " " ) ; document . write ( " " + getMax ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printNumberWithDR ( k , d ) { if ( d == 0 && k != 1 ) document . write ( " " ) ; else { document . write ( d ) ; k -- ; while ( k -- > 0 ) document . write ( " " ) ; } } var k = 4 , d = 4 ; printNumberWithDR ( k , d ) ;

Accumulator variables: k
Javascript program:
function countNumbers ( n ) { let c = 0 ; let limit = parseInt ( Math . sqrt ( n ) , 10 ) ; let prime = new Array ( limit + 1 ) ; prime . fill ( 0 ) ; for ( let i = 1 ; i <= limit ; i ++ ) { prime [ i ] = i ; } for ( let i = 2 ; i * i <= limit ; i ++ ) { if ( prime [ i ] == i ) { for ( let j = i * i ; j <= limit ; j += i ) { if ( prime [ j ] == j ) { prime [ j ] = i ; } } } } for ( let i = 2 ; i <= limit ; i ++ ) { let p = prime [ i ] ; let q = prime [ parseInt ( i / prime [ i ] , 10 ) ] ; if ( p * q == i && q != 1 && p != q ) { c += 1 ; } else if ( prime [ i ] == i ) { if ( Math . pow ( i , 8 ) <= n ) { c += 1 ; } } } return c ; } let n = 1000 ; document . write ( countNumbers ( n ) ) ;

Index/key variables: i, j
Accumulator variables: c, 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 isInterprime ( n ) { if ( n < 4 ) return false ; var prev_prime = n ; var next_prime = n ; while ( ! isPrime ( prev_prime ) ) { prev_prime -- ; } while ( ! isPrime ( next_prime ) ) { next_prime ++ ; } if ( ( prev_prime + next_prime ) == 2 * n ) return true ; else return false ; } var n = 9 ; if ( isInterprime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: next_prime, prev_prime
Iterator variables: i
Javascript program:
function get_unit_digit ( N ) { if ( N == 0 N == 1 ) return 1 ; else if ( N == 2 ) return 3 ; else if ( N == 3 ) return 9 ; return 3 ; } var N = 1 ; for ( N = 0 ; N <= 10 ; N ++ ) document . write ( " " + N + " " + get_unit_digit ( N ) + " " )

Accumulator variables: N
Iterator variables: N
Javascript program:
let f = new Array ( 1000 ) ; f . fill ( 0 ) ; function fib ( n ) { if ( n == 0 ) { return 0 ; } if ( n == 1 n == 2 ) { return ( f [ n ] = 1 ) ; } if ( f [ n ] > 0 ) { return f [ n ] ; } let k = ( ( n & 1 ) > 0 ) ? ( n + 1 ) / 2 : n / 2 ; f [ n ] = ( ( n & 1 ) > 0 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } function calculateSumOfSquares ( n ) { return fib ( n ) * fib ( n + 1 ) ; } let n = 6 ; document . write ( " " + calculateSumOfSquares ( n ) ) ;

Index/key variables: n
Javascript program:
function NumberOfSolutions ( x , y , z , n ) { var ans = 0 ; for ( var i = 0 ; i <= x ; i ++ ) { for ( var j = 0 ; j <= y ; j ++ ) { var temp = n - i - j ; if ( temp >= 0 ) { temp = Math . min ( temp , z ) ; ans += temp + 1 ; } } } return ans ; } var x = 1 , y = 2 , z = 3 , n = 4 ; document . write ( NumberOfSolutions ( x , y , z , n ) ) ;

Accumulator variables: ans, i, j
Iterator variables: i, j