dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class node { constructor ( key ) { this . left = null ; this . right = null ; this . data = key ; } } function newNode ( key ) { let temp = new node ( key ) ; return ( temp ) ; } function printLevelOrder ( root ) { if ( root == null ) return ; let q = [ ] ; q . push ( root ) ; while ( q . length != 0 ) { let temp = q [ 0 ] ; document . write ( temp . data + " " ) ; q . shift ( ) ; if ( temp . left != null ) { q . push ( temp . left ) ; } else if ( temp . right != null ) { document . write ( " " ) ; } if ( temp . right != null ) { q . push ( temp . right ) ; } else if ( temp . left != null ) { document . write ( " " ) ; } } } function pruneTree ( root ) { if ( root == null ) { return null ; } root . left = pruneTree ( root . left ) ; root . right = pruneTree ( root . right ) ; if ( root . data % 2 == 0 && root . right == null && root . left == null ) return null ; return root ; } let root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 8 ) ; root . left . right = newNode ( 10 ) ; root . right = newNode ( 7 ) ; root . right . left = newNode ( 12 ) ; root . right . right = newNode ( 5 ) ; let newRoot = pruneTree ( root ) ; printLevelOrder ( newRoot ) ;

Class/struct names: node
Javascript program:
function countWays ( mtrx , vrtx , i , dest , visited ) { if ( i == dest ) { return 1 ; } let total = 0 ; for ( let j = 0 ; j < vrtx ; j ++ ) { if ( mtrx [ i ] [ j ] == 1 && ! visited [ j ] ) { visited [ j ] = true ; total += countWays ( mtrx , vrtx , j , dest , visited ) ; visited [ j ] = false ; } } return total ; } function totalWays ( mtrx , vrtx , src , dest ) { let visited = new Array ( vrtx ) ; for ( let i = 0 ; i < vrtx ; i ++ ) { visited [ i ] = false ; } visited [ src ] = true ; return countWays ( mtrx , vrtx , src , dest , visited ) ; } let vrtx = 11 ; let mtrx = [ [ 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 ] , [ 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 0 ] , [ 1 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ] ; let src = 3 ; let dest = 9 ; document . write ( totalWays ( mtrx , vrtx , src - 1 , dest - 1 ) ) ;

Index/key variables: i, j, src
Accumulator variables: i, j, total
Iterator variables: i, j
Javascript program:
class Node { constructor ( key ) { this . key = key ; this . left = this . right = null ; } } function evenPaths ( node , count ) { if ( node == null || ( node . key % 2 != 0 ) ) { return count ; } if ( node . left == null && node . right == null ) { count ++ ; } count = evenPaths ( node . left , count ) ; return evenPaths ( node . right , count ) ; } function countEvenPaths ( node ) { return evenPaths ( node , 0 ) ; } let root = new Node ( 12 ) ; root . left = new Node ( 13 ) ; root . right = new Node ( 12 ) ; root . right . left = new Node ( 14 ) ; root . right . right = new Node ( 16 ) ; root . right . left . left = new Node ( 21 ) ; root . right . left . right = new Node ( 22 ) ; root . right . right . left = new Node ( 22 ) ; root . right . right . right = new Node ( 24 ) ; root . right . right . right . left = new Node ( 8 ) ; document . write ( countEvenPaths ( root ) ) ;

Accumulator variables: count
Class/struct names: Node
Javascript program:
var ans = 0 ; var c = [ ] ; var ans = 0 ; var c = [ ] ; subsetGen ( arr , 0 , n , ans ) ; document . write ( ans ) ; function subsetSum ( i , curr ) { if ( i == c . length ) { ans += curr ; return ; } subsetSum ( i + 1 , curr + c [ i ] ) ; subsetSum ( i + 1 , curr ) ; } function subsetGen ( arr , i , n , ans ) { if ( i == n ) { subsetSum ( 0 , ans , 0 ) ; return ; } subsetGen ( arr , i + 1 , n , ans ) ; c . push ( arr [ i ] ) ; subsetGen ( arr , i + 1 , n , ans ) ; c . pop ( ) ; } var arr = [ 1 , 1 ] ; var n = arr . length ;

Index/key variables: i
Accumulator variables: ans
Javascript program:
let N = 1000 ; let adj = [ ] ; function dfsUtil ( u , node , visited , road_used , parent , it ) { let c = 0 ; for ( let i = 0 ; i < node ; i ++ ) if ( visited [ i ] ) c ++ ; if ( c == node ) return ; visited [ u ] = true ; road_used . push ( [ parent , u ] ) ; document . write ( u + " " ) ; for ( let x = 0 ; x < adj [ u ] . length ; x ++ ) { if ( ! visited [ adj [ u ] [ x ] ] ) { dfsUtil ( adj [ u ] [ x ] , node , visited , road_used , u , it + 1 ) ; } } for ( let y = 0 ; y < road_used . length ; y ++ ) { if ( road_used [ y ] [ 1 ] == u ) { dfsUtil ( road_used [ y ] [ 0 ] , node , visited , road_used , u , it + 1 ) ; } } } function dfs ( node ) { let visited = new Array ( node ) ; let road_used = [ ] ; for ( let i = 0 ; i < node ; i ++ ) { visited [ i ] = false ; } dfsUtil ( 0 , node , visited , road_used , - 1 , 0 ) ; } function insertEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } let node = 11 , edge = 13 ; for ( let i = 0 ; i < N ; i ++ ) { adj . push ( [ ] ) ; } insertEdge ( 0 , 1 ) ; insertEdge ( 0 , 2 ) ; insertEdge ( 1 , 5 ) ; insertEdge ( 1 , 6 ) ; insertEdge ( 2 , 4 ) ; insertEdge ( 2 , 9 ) ; insertEdge ( 6 , 7 ) ; insertEdge ( 6 , 8 ) ; insertEdge ( 7 , 8 ) ; insertEdge ( 2 , 3 ) ; insertEdge ( 3 , 9 ) ; insertEdge ( 3 , 10 ) ; insertEdge ( 9 , 10 ) ; dfs ( node ) ; 9

Index/key variables: i, u, v, x, y
Accumulator variables: c, i, x, y
Iterator variables: i, x, y
Javascript program:
let max ; function findMaximumNum ( str , k ) { if ( k == 0 ) return ; let n = str . length ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( str [ i ] < str [ j ] ) { let t = str [ i ] ; str [ i ] = str [ j ] ; str [ j ] = t ; if ( ( str ) . join ( " " ) > ( max ) ) max = ( str ) . join ( " " ) ; findMaximumNum ( str , k - 1 ) ; let c = str [ i ] ; str [ i ] = str [ j ] ; str [ j ] = c ; } } } } let str = " " ; let k = 4 ; max = str ; findMaximumNum ( str . split ( " " ) , k ) ; document . write ( max + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function merge ( x , y ) { for ( let i = 0 ; i < y . length ; i ++ ) { if ( x [ x . length - 1 ] > y [ i ] ) x . push ( y [ i ] ) ; } return x ; } function mergeDel ( l ) { if ( l . length == 1 ) return l ; let m = Math . floor ( l . length / 2 ) ; let temp1 = l . slice ( 0 , m ) ; let temp2 = l . slice ( m , l . length ) ; return merge ( mergeDel ( temp1 ) , mergeDel ( temp2 ) ) ; } let arr = [ 5 , 4 , 3 , 2 , 1 ] ; let ans = mergeDel ( arr ) ; document . write ( " " ) ; document . write ( ans . join ( " " ) ) ; document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mergeSort ( arr , array_size ) { let temp = new Array ( array_size ) ; return _mergeSort ( arr , temp , 0 , array_size - 1 ) ; } function _mergeSort ( arr , temp , left , right ) { let mid , inv_count = 0 ; if ( right > left ) { mid = parseInt ( ( right + left ) / 2 , 10 ) ; inv_count = _mergeSort ( arr , temp , left , mid ) ; inv_count += _mergeSort ( arr , temp , mid + 1 , right ) ; inv_count += merge ( arr , temp , left , mid + 1 , right ) ; } return inv_count ; } function merge ( arr , temp , left , mid , right ) { let i , j , k ; let inv_count = 0 ; i = left ; j = mid ; k = left ; while ( ( i <= mid - 1 ) && ( j <= right ) ) { if ( arr [ i ] > 2 * arr [ j ] ) { inv_count += ( mid - i ) ; j ++ ; } else { i ++ ; } } i = left ; j = mid ; k = left ; while ( ( i <= mid - 1 ) && ( j <= right ) ) { if ( arr [ i ] <= arr [ j ] ) { temp [ k ++ ] = arr [ i ++ ] ; } else { temp [ k ++ ] = arr [ j ++ ] ; } } while ( i <= mid - 1 ) temp [ k ++ ] = arr [ i ++ ] ; while ( j <= right ) temp [ k ++ ] = arr [ j ++ ] ; for ( i = left ; i <= right ; i ++ ) arr [ i ] = temp [ i ] ; return inv_count ; } let arr = [ 1 , 20 , 6 , 4 , 5 ] ; let n = arr . length ; document . write ( mergeSort ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, inv_count, j, k
Iterator variables: i
Javascript program:
var N = 100005 ; var lazy = Array ( 4 * N ) . fill ( 0 ) ; var se = new Set ( ) ; function update ( x , y , value , id , l , r ) { if ( x >= r l >= y ) return ; if ( x <= l && r <= y ) { lazy [ id ] = value ; return ; } var mid = parseInt ( ( l + r ) / 2 ) ; if ( lazy [ id ] != 0 ) lazy [ 2 * id ] = lazy [ 2 * id + 1 ] = lazy [ id ] ; lazy [ id ] = 0 ; update ( x , y , value , 2 * id , l , mid ) ; update ( x , y , value , 2 * id + 1 , mid , r ) ; } function query ( id , l , r ) { if ( lazy [ id ] != 0 ) { se . add ( lazy [ id ] ) ; return ; } if ( r - l < 2 ) return ; var mid = parseInt ( ( l + r ) / 2 ) ; query ( 2 * id , l , mid ) ; query ( 2 * id + 1 , mid , r ) ; } var n = 5 , q = 3 ; update ( 1 , 4 , 1 , 1 , 0 , n ) ; update ( 0 , 2 , 2 , 1 , 0 , n ) ; update ( 3 , 4 , 3 , 1 , 0 , n ) ; query ( 1 , 0 , n ) ; document . write ( se . size ) ;

Index/key variables: id
Javascript program:
var MOD = 1000000009 ; function power ( n ) { if ( n <= 1 ) return 1 ; n -- ; var res = [ [ 1 , 0 , ] , [ 0 , 1 ] ] ; var tMat = [ [ 2 , 3 ] , [ 1 , 0 ] ] ; while ( n ) { if ( n & 1 ) { var tmp = Array . from ( Array ( 2 ) , ( ) => Array ( 2 ) ) ; tmp [ 0 ] [ 0 ] = ( res [ 0 ] [ 0 ] * tMat [ 0 ] [ 0 ] + res [ 0 ] [ 1 ] * tMat [ 1 ] [ 0 ] ) % MOD ; tmp [ 0 ] [ 1 ] = ( res [ 0 ] [ 0 ] * tMat [ 0 ] [ 1 ] + res [ 0 ] [ 1 ] * tMat [ 1 ] [ 1 ] ) % MOD ; tmp [ 1 ] [ 0 ] = ( res [ 1 ] [ 0 ] * tMat [ 0 ] [ 0 ] + res [ 1 ] [ 1 ] * tMat [ 1 ] [ 0 ] ) % MOD ; tmp [ 1 ] [ 1 ] = ( res [ 1 ] [ 0 ] * tMat [ 0 ] [ 1 ] + res [ 1 ] [ 1 ] * tMat [ 1 ] [ 1 ] ) % MOD ; res [ 0 ] [ 0 ] = tmp [ 0 ] [ 0 ] ; res [ 0 ] [ 1 ] = tmp [ 0 ] [ 1 ] ; res [ 1 ] [ 0 ] = tmp [ 1 ] [ 0 ] ; res [ 1 ] [ 1 ] = tmp [ 1 ] [ 1 ] ; } n = parseInt ( n / 2 ) ; var tmp = Array . from ( Array ( 2 ) , ( ) => Array ( 2 ) ) ; tmp [ 0 ] [ 0 ] = ( tMat [ 0 ] [ 0 ] * tMat [ 0 ] [ 0 ] + tMat [ 0 ] [ 1 ] * tMat [ 1 ] [ 0 ] ) % MOD ; tmp [ 0 ] [ 1 ] = ( tMat [ 0 ] [ 0 ] * tMat [ 0 ] [ 1 ] + tMat [ 0 ] [ 1 ] * tMat [ 1 ] [ 1 ] ) % MOD ; tmp [ 1 ] [ 0 ] = ( tMat [ 1 ] [ 0 ] * tMat [ 0 ] [ 0 ] + tMat [ 1 ] [ 1 ] * tMat [ 1 ] [ 0 ] ) % MOD ; tmp [ 1 ] [ 1 ] = ( tMat [ 1 ] [ 0 ] * tMat [ 0 ] [ 1 ] + tMat [ 1 ] [ 1 ] * tMat [ 1 ] [ 1 ] ) % MOD ; tMat [ 0 ] [ 0 ] = tmp [ 0 ] [ 0 ] ; tMat [ 0 ] [ 1 ] = tmp [ 0 ] [ 1 ] ; tMat [ 1 ] [ 0 ] = tmp [ 1 ] [ 0 ] ; tMat [ 1 ] [ 1 ] = tmp [ 1 ] [ 1 ] ; } return ( res [ 0 ] [ 0 ] * 1 + res [ 0 ] [ 1 ] * 1 ) % MOD ; } var n = 3 ; document . write ( power ( n ) ) ;

Accumulator variables: n
Javascript program:
function shuffleArray ( a , n ) { for ( let i = 0 , q = 1 , k = n ; i < n ; i ++ , k ++ , q ++ ) for ( let j = k ; j > i + q ; j -- ) { let temp = a [ j - 1 ] ; a [ j - 1 ] = a [ j ] ; a [ j ] = temp ; } } let a = [ 1 , 3 , 5 , 7 , 2 , 4 , 6 , 8 ] ; shuffleArray ( a , a . length / 2 ) ; document . write ( a . join ( " " ) ) ;

Index/key variables: j
Accumulator variables: i, j, k, q
Iterator variables: i, j
Javascript program:
function isFeasible ( mid , arr , n , k ) { let pos = arr [ 0 ] ; let elements = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - pos >= mid ) { pos = arr [ i ] ; elements ++ ; if ( elements == k ) return true ; } } return false ; } function largestMinDist ( arr , n , k ) { arr . sort ( function ( a , b ) { return a - b } ) ; let res = - 1 ; let left = 1 , right = arr [ n - 1 ] ; while ( left < right ) { let mid = parseInt ( ( left + right ) / 2 , 10 ) ; if ( isFeasible ( mid , arr , n , k ) ) { res = Math . max ( res , mid ) ; left = mid + 1 ; } else right = mid ; } return res ; } let arr = [ 1 , 2 , 8 , 4 , 9 ] ; let n = arr . length ; let k = 3 ; document . write ( largestMinDist ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: elements, i
Iterator variables: i
Javascript program:
function findFrequency ( arr , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , 0 ) ; mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } for ( let [ key , value ] of mp . entries ( ) ) { document . write ( " " + key + " " + value + " " ) ; } } let arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ] ; let n = arr . length ; findFrequency ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function normal_slope ( a , b , x1 , y1 ) { var g = a / 2 ; var f = b / 2 ; if ( g - x1 == 0 ) return ( - 1 ) ; var slope = ( f - y1 ) / ( g - x1 ) ; if ( slope == 0 ) return ( - 2 ) ; return slope ; } function normal_equation ( a , b , x1 , y1 ) { var slope = normal_slope ( a , b , x1 , y1 ) ; if ( slope == - 1 ) { document . write ( " " + x1 ) ; } if ( slope == - 2 ) { document . write ( " " + y1 ) ; } if ( slope != - 1 && slope != - 2 ) { x1 *= - slope ; x1 += y1 ; if ( x1 > 0 ) document . write ( " " + slope + " " + x1 . toFixed ( 1 ) ) ; else document . write ( " " + slope + " " + x1 . toFixed ( 1 ) ) ; } } var a = 4 , b = 6 , c = 5 ; var x1 = 12 , y1 = 14 ; normal_equation ( a , b , x1 , y1 ) ;

Accumulator variables: x1
Javascript program:
function findSquareSum ( Coordinates , N ) { let xq = 0 , yq = 0 ; let xs = 0 , ys = 0 ; let res = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let a , b ; a = Coordinates [ i ] [ 0 ] ; b = Coordinates [ i ] [ 1 ] ; res += xq ; res -= 2 * xs * a ; res += i * ( a * a ) ; xq += a * a ; xs += a ; res += yq ; res -= 2 * ys * b ; res += i * b * b ; yq += b * b ; ys += b ; } document . write ( res ) ; } let arr = [ [ 1 , 1 ] , [ - 1 , - 1 ] , [ 1 , - 1 ] , [ - 1 , 1 ] ] ; let N = arr . length ; findSquareSum ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, res, xq, xs, yq, ys
Iterator variables: i
Javascript program:
function getPointsIns ( x1 , y1 , radius , x2 , y2 , points ) { let ans = 0 ; for ( let i = 0 ; i < points . length ; i ++ ) { let condOne = false , condTwo = false ; if ( ( points [ i ] [ 1 ] - y2 ) * ( x2 - x1 ) - ( y2 - y1 ) * ( points [ i ] [ 0 ] - x2 ) >= 0 ) { condOne = true ; } if ( radius >= Math . sqrt ( Math . pow ( ( y1 - points [ i ] [ 1 ] ) , 2 ) + Math . pow ( x1 - points [ i ] [ 0 ] , 2 ) ) ) { condTwo = true ; } if ( condOne && condTwo ) { ans += 1 ; } } return ans ; } let X = 0 ; let Y = 0 ; let R = 5 ; let P = 5 ; let Q = 0 ; let arr = [ [ 2 , 3 ] , [ 5 , 6 ] , [ - 1 , 4 ] , [ 5 , 5 ] ] ; document . write ( getPointsIns ( X , Y , R , P , Q , arr ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Boolean variables: condOne, condTwo
Javascript program:
function cntPairs ( points , n , K ) { var ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var dist = 0 ; for ( k = 0 ; k < K ; k ++ ) { var temp = ( points [ i ] [ k ] - points [ j ] [ k ] ) ; dist += temp * temp ; } if ( Math . sqrt ( dist ) * Math . sqrt ( dist ) == dist ) { ans += 1 ; } } } document . write ( ans + " " ) ; } var K = 2 ; var points = [ [ 1 , 2 ] , [ 5 , 5 ] , [ - 2 , 8 ] ] ; var n = points . length ; cntPairs ( points , n , K ) ;

Index/key variables: i, j, k
Accumulator variables: ans, dist, i, j, k
Iterator variables: i, j, k
Javascript program:
class point { constructor ( x , y ) { this . x = x ; this . y = y ; } } function lineFromPoints ( P , Q , a , b , c ) { a = Q . y - P . y ; b = P . x - Q . x ; c = a * ( P . x ) + b * ( P . y ) ; } function perpenBisectorFromLine ( P , Q , a , b , c ) { let mid_point = new point ( ) ; mid_point . x = ( P . x + Q . x ) / 2 ; mid_point . y = ( P . y + Q . y ) / 2 ; c = - b * ( mid_point . x ) + a * ( mid_point . y ) ; let temp = a ; a = - b ; b = temp ; } function LineInterX ( a1 , b1 , c1 , a2 , b2 , c2 ) { let determ = a1 * b2 - a2 * b1 ; let x = ( b2 * c1 - b1 * c2 ) ; x /= determ ; return x ; } function LineInterY ( a1 , b1 , c1 , a2 , b2 , c2 ) { let determ = a1 * b2 - a2 * b1 ; let y = ( a1 * c2 - a2 * c1 ) ; y /= determ ; return y ; } function findPosition ( P , Q , R , D ) { let r = new point ( ) ; let a = 0 , b = 0 , c = 0 ; lineFromPoints ( P , Q , a , b , c ) ; let e = 0 , f = 0 , g = 0 ; lineFromPoints ( Q , R , e , f , g ) ; perpenBisectorFromLine ( P , Q , a , b , c ) ; perpenBisectorFromLine ( Q , R , e , f , g ) ; r . x = LineInterX ( a , b , c , e , f , g ) ; r . y = LineInterY ( a , b , c , e , f , g ) ; let q = ( r . x - P . x ) * ( r . x - P . x ) + ( r . y - P . y ) * ( r . y - P . y ) ; let dis = ( r . x - D . x ) * ( r . x - D . x ) + ( r . y - D . y ) * ( r . y - D . y ) ; if ( dis < q ) { document . write ( " " + D . x + " " + D . y + " " + " " ) ; } else if ( dis == q ) { document . write ( " " + D . x + " " + D . y + " " + " " ) ; } else { document . write ( " " + D . x + " " + D . y + " " + " " ) ; } } let A , B , C , D ; A = new point ( 2 , 8 ) ; B = new point ( 2 , 1 ) ; C = new point ( 4 , 5 ) ; D = new point ( 3 , 0 ) ; findPosition ( A , B , C , D ) ;

Accumulator variables: x, y
Class/struct names: point
Javascript program:
function countOdd ( n ) { let coun = 0 , m , j , i ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( i >= 1 ) { m = parseInt ( ( n - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } else { m = parseInt ( ( ( n - 1 ) - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } } return coun ; } function countEven ( n ) { let coun = 0 , m , j , i ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( i >= 1 ) { m = parseInt ( ( ( n - 1 ) - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } else { m = parseInt ( ( n - i ) / 2 , 10 ) ; j = parseInt ( ( i * ( i + 1 ) ) / 2 , 10 ) ; coun += j * m ; } } return coun ; } let n = 5 ; if ( n >= 1 ) document . write ( countOdd ( n ) ) ; else document . write ( countEven ( n ) ) ;

Accumulator variables: coun, i
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { var res = 1 ; var i ; if ( k > n - k ) k = n - k ; for ( i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function countPaths ( x1 , y1 , x2 , y2 ) { var m = Math . abs ( x1 - x2 ) ; var n = Math . abs ( y1 - y2 ) ; return ( binomialCoeff ( m + n , n ) ) ; } var x1 = 2 , y1 = 3 , x2 = 4 , y2 = 5 ; document . write ( countPaths ( x1 , y1 , x2 , y2 ) ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function maxLines ( n , x1 , y1 , x2 , y2 ) { var s = [ ] ; var slope = 2147483647 ; for ( let i = 0 ; i < n ; i ++ ) { if ( x1 [ i ] === x2 [ i ] ) slope = 2147483647 ; else slope = ( ( ( y2 [ i ] - y1 [ i ] ) * 1.0 ) / ( x2 [ i ] - x1 [ i ] ) ) * 1.0 ; s . push ( slope ) ; } return s . length ; } var n = 2 ; var x1 = [ 1 , 2 ] ; var y1 = [ 1 , 2 ] ; var x2 = [ 2 , 4 ] ; var y2 = [ 2 , 10 ] ; document . write ( maxLines ( n , x1 , y1 , x2 , y2 ) ) ;

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: x, y
Javascript program:
function overlappingArea ( l1 , r1 , l2 , r2 ) { let x = 0 let y = 1 let area1 = Math . abs ( l1 [ x ] - r1 [ x ] ) * Math . abs ( l1 [ y ] - r1 [ y ] ) let area2 = Math . abs ( l2 [ x ] - r2 [ x ] ) * Math . abs ( l2 [ y ] - r2 [ y ] ) let x_dist = ( Math . min ( r1 [ x ] , r2 [ x ] ) - Math . max ( l1 [ x ] , l2 [ x ] ) ) let y_dist = ( Math . min ( r1 [ y ] , r2 [ y ] ) - Math . max ( l1 [ y ] , l2 [ y ] ) ) let areaI = 0 if ( x_dist > 0 && y_dist > 0 ) areaI = x_dist * y_dist return ( area1 + area2 - areaI ) } let l1 = [ 2 , 2 ] let r1 = [ 5 , 7 ] let l2 = [ 3 , 4 ] let r2 = [ 6 , 9 ] document . write ( overlappingArea ( l1 , r1 , l2 , r2 ) )

Index/key variables: x, y
Javascript program:
function lcs ( a , b ) { let m = a . length ; let n = b . length ; let X = a . split ( ' ' ) ; let Y = b . split ( ' ' ) ; let L = new Array ( m + 1 ) ; for ( let i = 0 ; i <= m ; i ++ ) { L [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j <= n ; j ++ ) { L [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i ] [ j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; } else { L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } } let index = L [ m ] [ n ] ; let lcs = new Array ( index + 1 ) ; lcs . fill ( ' ' ) ; let i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { lcs [ index - 1 ] = X [ i - 1 ] ; i -- ; j -- ; index -- ; else if ( L [ i - 1 ] [ j ] > L [ i ] [ j - 1 ] ) { i -- ; } else { j -- ; } } let ans = " " ; for ( let x = 0 ; x < lcs . length ; x ++ ) { ans += lcs [ x ] ; } return ans ; } function longestPalSubseq ( str ) { let rev = str ; rev = reverse ( rev ) ; return lcs ( str , rev ) ; } function reverse ( str ) { let ans = " " ; let try1 = str . split ( ' ' ) ; for ( let i = try1 . length - 1 ; i >= 0 ; i -- ) { ans += try1 [ i ] ; } return ans ; } let str = " " ; document . write ( longestPalSubseq ( str ) ) ;

Index/key variables: i, j, m, n, x
Accumulator variables: ans, i, index, j, x
Iterator variables: i, j, x
Javascript program:
let M = 3 ; let N = 3 ; function contribution_height ( current , previous ) { return Math . abs ( current - previous ) ; } function surfaceArea ( A ) { let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { let up = 0 ; let left = 0 ; if ( i > 0 ) up = A [ i - 1 ] [ j ] ; if ( j > 0 ) left = A [ i ] [ j - 1 ] ; ans += contribution_height ( A [ i ] [ j ] , up ) + contribution_height ( A [ i ] [ j ] , left ) ; if ( i == N - 1 ) ans += A [ i ] [ j ] ; if ( j == M - 1 ) ans += A [ i ] [ j ] ; } } ans += N * M * 2 ; return ans ; } let A = [ [ 1 , 3 , 4 ] , [ 2 , 2 , 3 ] , [ 1 , 2 , 4 ] ] ; document . write ( surfaceArea ( A ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function printSet ( x , y ) { arr = [ ] ; for ( let i = 0 ; i <= Math . min ( x , y ) ; i ++ ) { let pq = [ i , Math . min ( x , y ) - i ] ; arr . push ( pq ) ; } for ( let [ key , value ] of arr . entries ( ) ) { document . write ( value [ 0 ] + " " + value [ 1 ] + " " ) } } let x = 4 ; let y = 4 ; printSet ( x , y )

Accumulator variables: i
Iterator variables: i
Javascript program:
function countRect ( n ) { let ans = 0 ; for ( let length = 1 ; length <= parseInt ( Math . sqrt ( n ) , 10 ) ; ++ length ) for ( let height = length ; height * length <= n ; ++ height ) ans ++ ; return ans ; } let n = 5 ; document . write ( countRect ( n ) ) ;

Accumulator variables: ans
Iterator variables: height
Javascript program:
function bestApproximate ( x , y , n ) { let m , c , sum_x = 0 , sum_y = 0 , sum_xy = 0 , sum_x2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum_x += x [ i ] ; sum_y += y [ i ] ; sum_xy += x [ i ] * y [ i ] ; sum_x2 += Math . pow ( x [ i ] , 2 ) ; } m = ( n * sum_xy - sum_x * sum_y ) / ( n * sum_x2 - Math . pow ( sum_x , 2 ) ) ; c = ( sum_y - m * sum_x ) / n ; document . write ( " " + m ) ; document . write ( " " + c ) ; } let x = [ 1 , 2 , 3 , 4 , 5 ] ; let y = [ 14 , 27 , 40 , 55 , 68 ] ; let n = x . length ; bestApproximate ( x , y , n ) ;

Index/key variables: i
Accumulator variables: i, sum_x, sum_x2, sum_xy, sum_y
Iterator variables: i