dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
const MAX = 100005 ; function isPerfect ( N ) { let sum = 1 ; for ( let i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { if ( i * i != N ) sum = sum + i + Math . floor ( N / i ) ; else sum = sum + i ; } } if ( sum == N && N != 1 ) return true ; return false ; } function Query ( arr , N ) { let prefix = new Array ( MAX + 1 ) . fill ( 0 ) ; for ( let i = 2 ; i <= MAX ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + isPerfect ( i ) ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( prefix [ arr [ i ] [ 1 ] ] - prefix [ arr [ i ] [ 0 ] - 1 ] + " " ) ; } } let arr = [ [ 1 , 1000 ] , [ 1000 , 2000 ] , [ 2000 , 3000 ] ] ; let N = arr . length ; Query ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSteps ( N ) { var ans = 0 ; for ( var d = 2 ; d * d <= N ; d ++ ) { while ( N % d == 0 ) { ans += d ; N /= d ; } } if ( N != 1 ) { ans += N ; } return ans ; } var N = 3 ; minSteps ( N ) ; document . write ( minSteps ( N ) ) ;

Accumulator variables: N, ans, d
Iterator variables: d
Javascript program:
function Create_Rectangle ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { arr [ i ] = arr [ i ] . split ( " " ) } let p1 = [ - 1 , - 1 ] ; let p2 = [ - 1 , - 1 ] ; let p3 = [ ] ; let p4 = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( arr [ i ] [ j ] == ' ' ) if ( p1 [ 0 ] == - 1 ) p1 = [ i , j ] ; else p2 = [ i , j ] ; } } p3 = p1 ; p4 = p2 ; if ( p1 [ 0 ] == p2 [ 0 ] ) { p3 [ 0 ] = ( p1 [ 0 ] + 1 ) % n ; p4 [ 0 ] = ( p2 [ 0 ] + 1 ) % n ; } else if ( p1 [ 1 ] == p2 [ 1 ] ) { p3 [ 1 ] = ( p1 [ 1 ] + 1 ) % n ; p4 [ 1 ] = ( p2 [ 1 ] + 1 ) % n ; } else { let temp = p3 [ 0 ] ; p3 [ 0 ] = p4 [ 0 ] ; p4 [ 0 ] = temp ; } arr [ p3 [ 0 ] ] [ p3 [ 1 ] ] = ' ' ; arr [ p4 [ 0 ] ] [ p4 [ 1 ] ] = ' ' ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] . join ( " " ) + " " ) ; } } let n = 4 ; let arr = [ " " , " " , " " , " " ] ; Create_Rectangle ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function SumOfPrimeDivisors ( n ) { let sum = 0 ; if ( n % 2 == 0 ) { sum = sum + 2 ; } while ( n % 2 == 0 ) { n = n / 2 ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { sum = sum + i ; } while ( n % i == 0 ) { n = n / i ; } } if ( n > 2 ) { sum = sum + n ; } return sum ; } let n = 10 ; document . write ( SumOfPrimeDivisors ( n ) ) ;

Iterator variables: i
Javascript program:
function countOfBase ( N ) { let count = 0 ; for ( let i = 2 ; i <= N ; ++ i ) { let highestPower = parseInt ( Math . log ( N ) / Math . log ( i ) ) ; let firstDigit = parseInt ( N / Math . pow ( i , highestPower ) ) ; if ( firstDigit == 1 ) { ++ count ; } } return count ; } let N = 6 ; document . write ( countOfBase ( N ) )

Iterator variables: i
Javascript program:
function countWays ( arr , N ) { let arr_xor = 0 ; for ( let i = 0 ; i < N ; i ++ ) arr_xor ^= arr [ i ] ; let pref_xor = 0 , suff_xor = 0 ; let pref_ind = [ ] ; let suff_inds = new Array ( N + 1 ) ; suff_inds . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { pref_xor ^= arr [ i ] ; if ( pref_xor == arr_xor ) pref_ind . push ( i ) ; } for ( let i = N - 1 ; i >= 0 ; i -- ) { suff_xor ^= arr [ i ] ; suff_inds [ i ] += suff_inds [ i + 1 ] ; if ( suff_xor == arr_xor ) suff_inds [ i ] ++ ; } let tot_ways = 0 ; for ( let idx of pref_ind ) { if ( idx < N - 1 ) tot_ways += suff_inds [ idx + 2 ] ; } return tot_ways ; } let arr = [ 7 , 0 , 5 , 2 , 7 ] ; let N = arr . length ; document . write ( countWays ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: arr_xor, i, pref_xor, suff_xor, tot_ways
Iterator variables: i, idx
Javascript program:
let dp = new Array ( 1000 ) ; for ( let i = 0 ; i < 1000 ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } function IsSumEqualsXor ( i , n , bound , s ) { if ( i == n ) return 1 ; if ( dp [ i ] [ bound ] != - 1 ) return dp [ i ] [ bound ] ; let ans = 0 ; if ( bound != 0 && s [ i ] == ' ' ) { ans = IsSumEqualsXor ( i + 1 , n , 1 , s ) ; } else { ans = 2 * IsSumEqualsXor ( i + 1 , n , bound != 0 & ( s [ i ] == ' ' ) ? 1 : 0 , s ) ; ans += IsSumEqualsXor ( i + 1 , n , 0 , s ) ; } dp [ i ] [ bound ] = ans return dp [ i ] [ bound ] ; } function reverse ( input ) { let a = input . split ( ' ' ) ; let l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { let temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a . join ( " " ) ; } function convertToBinary ( n ) { let ans = " " ; while ( n > 0 ) { let rem = String . fromCharCode ( n % 2 + 48 ) ; ans += ( rem ) ; n = parseInt ( n / 2 , 10 ) ; } ans = reverse ( ans ) ; return ans ; } function IsSumEqualsXorUtil ( N ) { let s = convertToBinary ( N ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { for ( let j = 0 ; j < dp [ 0 ] . length ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( IsSumEqualsXor ( 0 , s . length , 1 , s . split ( ' ' ) ) + " " ) ; } let N = 10 ; IsSumEqualsXorUtil ( N ) ;

Index/key variables: bound, i, j, l, r
Accumulator variables: ans, i, j, l, r
Iterator variables: i, j, l
Javascript program:
function findDecimal ( arr , N ) { let bit , power = 0 , result = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { bit = Math . abs ( Math . floor ( arr [ i ] ) - Math . round ( arr [ i ] ) ) ; if ( bit != 0 ) result += Math . pow ( 2 , power ) ; power ++ ; } document . write ( result ) ; } let arr = [ 1.2 , 2.6 , 4.2 , 6.9 , 3.1 , 21.6 , 91.2 ] ; let N = arr . length ; findDecimal ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, power, result
Iterator variables: i
Javascript program:
function totalMoney ( N ) { let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { ans += Math . floor ( i / 7 ) ; ans += ( i % 7 + 1 ) ; } return ans ; } let N = 15 ; document . write ( totalMoney ( N ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
class pair { constructor ( count , prevIndex ) { this . count = count ; this . prevIndex = prevIndex ; } } function findSum ( arr , n ) { let map = new Map ( ) ; let left = new Array ( n ) ; let right = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! map . has ( arr [ i ] ) ) { left [ i ] = 0 ; map . set ( arr [ i ] , new pair ( 1 , i ) ) ; } else { let tmp = map . get ( arr [ i ] ) ; left [ i ] = ( tmp . count ) * ( i - tmp . prevIndex ) + left [ tmp . prevIndex ] ; map . set ( arr [ i ] , new pair ( tmp . count + 1 , i ) ) ; } } map . clear ( ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( ! map . has ( arr [ i ] ) ) { right [ i ] = 0 ; map . set ( arr [ i ] , new pair ( 1 , i ) ) ; } else { let tmp = map . get ( arr [ i ] ) ; right [ i ] = ( tmp . count ) * ( Math . abs ( i - tmp . prevIndex ) ) + right [ tmp . prevIndex ] ; map . set ( arr [ i ] , new pair ( tmp . count + 1 , i ) ) ; } } for ( let i = 0 ; i < n ; i ++ ) document . write ( left [ i ] + right [ i ] + " " ) ; } let arr = [ 1 , 3 , 1 , 1 , 2 ] ; let N = arr . length ; findSum ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: pair
Javascript program:
function isPresent ( n , x ) { let num = ( n ) . toString ( ) ; for ( let i = 0 ; i < num . length ; i ++ ) { if ( ( num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) == x ) return i ; } return - 1 ; } function removeDigit ( n , index ) { let num = ( n ) . toString ( ) ; let ans = " " ; for ( let i = 0 ; i < num . length ; i ++ ) { if ( i != index ) ans += num [ i ] ; } if ( ans == " " || ( ans . length == 1 && ans [ 0 ] == ' ' ) ) return - 1 ; let x = parseInt ( ans ) ; return x ; } function reduceNtoX ( a , b , d , n ) { let q = [ ] ; q . push ( a ) ; let visited = new Map ( ) ; visited . set ( a , true ) ; while ( q . length != 0 ) { let top = q . shift ( ) ; if ( top < 0 ) continue ; if ( top == b ) return true ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! visited . has ( top / d [ i ] ) ) visited . set ( top / d [ i ] , false ) ; if ( d [ i ] != 0 && top % d [ i ] == 0 && ! visited . get ( top / d [ i ] ) ) { q . push ( top / d [ i ] ) ; visited . set ( top / d [ i ] , true ) ; } let index = isPresent ( top , d [ i ] ) ; if ( index != - 1 ) { let newElement = removeDigit ( top , index ) ; if ( ! visited . has ( newElement ) ) visited . set ( newElement , false ) ; if ( newElement != - 1 && ( ! visited . get ( newElement ) ) ) { q . push ( newElement ) ; visited . set ( newElement , true ) ; } } } } return false ; } let A = 5643 , B = 81 ; let D = [ 3 , 8 , 1 ] ; let N = D . length ; if ( reduceNtoX ( A , B , D , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var prime = new Array ( 100000 ) ; function SieveOfEratosthenes ( n ) { prime . fill ( true ) ; for ( var p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * p ; i <= n ; i += p ) { prime [ i ] = false ; } } } } function findTriplets ( N ) { SieveOfEratosthenes ( N ) ; var V = [ ] ; for ( var i = 3 ; i <= N ; i ++ ) { if ( 2 + i <= N && prime [ i ] == true && prime [ 2 + i ] == true ) { var a1 = [ 2 , i , i + 2 ] ; V . push ( a1 ) ; } } for ( var i = 0 ; i < V . length ; i ++ ) { document . write ( V [ i ] [ 0 ] + " " + V [ i ] [ 1 ] + " " + V [ i ] [ 2 ] + " " ) ; } } N = 8 ; findTriplets ( N ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
let MAX = 50 let primes = [ ] ; function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function findPrime ( ) { for ( let i = 2 ; i <= MAX ; i ++ ) { if ( isPrime ( i ) ) primes . push ( i ) ; } } function gcd ( a , b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } function findMinimumNumber ( arr , N ) { findPrime ( ) ; let ans = Number . MAX_SAFE_INTEGER ; let n = primes . length ; for ( let i = 1 ; i < ( 1 << n ) ; i ++ ) { let temp = 1 ; for ( let j = 0 ; j < n ; j ++ ) { if ( i & ( 1 << j ) ) { temp *= primes [ j ] ; } } let check = true ; for ( let k = 0 ; k < N ; k ++ ) { if ( gcd ( temp , arr [ k ] ) == 1 ) { check = false ; break ; } } if ( check ) ans = Math . min ( ans , temp ) ; } document . write ( ans ) ; } let arr = [ 3 , 4 , 6 , 7 , 8 , 9 , 10 ] ; let N = arr . length ; findMinimumNumber ( arr , N ) ;

Index/key variables: j, k
Accumulator variables: i, j, k, temp
Iterator variables: i, j, k
Boolean variables: check
Javascript program:
var R = 100005 ; var arr = Array ( R ) . fill ( 0 ) ; function canExpress ( N ) { var temp = N ; var n = 0 ; while ( N != 0 ) { N = parseInt ( N / 10 ) ; n ++ ; } N = temp ; var sum = 0 ; while ( N != 0 ) { sum += Math . pow ( N % 10 , n ) ; N = parseInt ( N / 10 ) ; } return ( sum == temp ) ; } function precompute ( ) { for ( var i = 1 ; i < R ; i ++ ) { if ( canExpress ( i ) ) { arr [ i ] = 1 ; } } for ( var i = 1 ; i < R ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; } } function countNumbers ( queries , N ) { precompute ( ) ; for ( var i = 0 ; i < N ; i ++ ) { var L1 = queries [ i ] [ 0 ] ; var R1 = queries [ i ] [ 1 ] ; document . write ( ( arr [ R1 ] - arr [ L1 - 1 ] ) + " " ) ; } } var queries = [ [ 1 , 400 ] , [ 1 , 9 ] ] ; var N = queries . length ; countNumbers ( queries , N ) ;

Index/key variables: R1, i
Accumulator variables: i, n, sum
Iterator variables: i
Javascript program:
function sumOfNodeInAPath ( node_value ) { let sum_of_node = 0 ; while ( node_value ) { sum_of_node += node_value ; node_value = Math . floor ( node_value / 2 ) ; } document . write ( sum_of_node ) ; return ; } function findSum ( Q ) { for ( let i = 0 ; i < Q . length ; i ++ ) { let node_value = Q [ i ] ; sumOfNodeInAPath ( node_value ) ; document . write ( " " ) ; } } let arr = [ 1 , 5 , 20 , 100 ] ; findSum ( arr ) ;

Index/key variables: i
Accumulator variables: i, sum_of_node
Iterator variables: i
Javascript program:
function minDeletions ( arr , N ) { var freq = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . set ( arr [ i ] , 1 ) ; } } var v = [ ] ; freq . forEach ( ( value , key ) => { v . push ( value ) ; } ) ; v . sort ( ) ; var size = v . length ; var ans = N - ( v [ 0 ] * size ) ; for ( var i = 1 ; i < v . length ; i ++ ) { if ( v [ i ] != v [ i - 1 ] ) { var safe = v [ i ] * ( size - i ) ; ans = Math . min ( ans , N - safe ) ; } } document . write ( ans ) ; } var arr = [ 2 , 4 , 3 , 2 , 5 , 3 ] ; var N = arr . length ; minDeletions ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } var head ; function push ( new_data ) { var new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } function getCountRec ( node ) { if ( node == null ) return 0 ; return 1 + getCountRec ( node . next ) ; } function getCount ( ) { return getCountRec ( head ) ; } push ( 1 ) ; push ( 3 ) ; push ( 1 ) ; push ( 2 ) ; push ( 1 ) ; document . write ( " " + getCount ( ) ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } var head ; var slow_ptr , fast_ptr , second_half ; function isPalindrome ( head ) { slow_ptr = head ; fast_ptr = head ; var prev_of_slow_ptr = head ; var midnode = null ; var res = true ; if ( head != null && head . next != null ) { while ( fast_ptr != null && fast_ptr . next != null ) { fast_ptr = fast_ptr . next . next ; prev_of_slow_ptr = slow_ptr ; slow_ptr = slow_ptr . next ; } if ( fast_ptr != null ) { midnode = slow_ptr ; slow_ptr = slow_ptr . next ; } second_half = slow_ptr ; prev_of_slow_ptr . next = null ; reverse ( ) ; res = compareLists ( head , second_half ) ; reverse ( ) ; if ( midnode != null ) { prev_of_slow_ptr . next = midnode ; midnode . next = second_half ; } else prev_of_slow_ptr . next = second_half ; } return res ; } function reverse ( ) { var prev = null ; var current = second_half ; var next ; while ( current != null ) { next = current . next ; current . next = prev ; prev = current ; current = next ; } second_half = prev ; } function compareLists ( head1 , head2 ) { var temp1 = head1 ; var temp2 = head2 ; while ( temp1 != null && temp2 != null ) { if ( temp1 . data == temp2 . data ) { temp1 = temp1 . next ; temp2 = temp2 . next ; } else return false ; } if ( temp1 == null && temp2 == null ) return true ; return false ; } function push ( new_data ) { var new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } function printList ( ptr ) { while ( ptr != null ) { document . write ( ptr . data + " " ) ; ptr = ptr . next ; } document . write ( " " ) ; } var str = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] ; var string = str . toString ( ) ; for ( i = 0 ; i < 7 ; i ++ ) { push ( str [ i ] ) ; printList ( head ) ; if ( isPalindrome ( head ) != false ) { document . write ( " " ) ; document . write ( " " ) ; } else { document . write ( " " ) ; document . write ( " " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: res
Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } var head ; function swapNodes ( x , y ) { if ( x == y ) return ; var prevX = null , currX = head ; while ( currX != null && currX . data != x ) { prevX = currX ; currX = currX . next ; } var prevY = null , currY = head ; while ( currY != null && currY . data != y ) { prevY = currY ; currY = currY . next ; } if ( currX == null currY == null ) return ; if ( prevX != null ) prevX . next = currY ; else head = currY ; if ( prevY != null ) prevY . next = currX ; else head = currX ; var temp = currX . next ; currX . next = currY . next ; currY . next = temp ; } function push ( new_data ) { var new_Node = new Node ( new_data ) ; new_Node . next = head ; head = new_Node ; } function printList ( ) { var tNode = head ; while ( tNode != null ) { document . write ( tNode . data + " " ) ; tNode = tNode . next ; } } push ( 7 ) ; push ( 6 ) ; push ( 5 ) ; push ( 4 ) ; push ( 3 ) ; push ( 2 ) ; push ( 1 ) ; document . write ( " " ) ; printList ( ) ; swapNodes ( 4 , 3 ) ; document . write ( " " ) ; printList ( ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function isCircular ( head ) { if ( head == null ) return true ; node = head . next ; while ( node != null && node != head ) node = node . next ; return ( node == head ) ; } function newNode ( data ) { temp = new Node ( ) ; temp . data = data ; temp . next = null ; return temp ; } head = newNode ( 1 ) ; head . next = newNode ( 2 ) ; head . next . next = newNode ( 3 ) ; head . next . next . next = newNode ( 4 ) ; document . write ( isCircular ( head ) ? " " : " " ) ; head . next . next . next . next = head ; document . write ( isCircular ( head ) ? " " : " " ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function getJosephusPosition ( m , n ) { var head = new Node ( 1 ) ; var prev = head ; for ( i = 2 ; i <= n ; i ++ ) { prev . next = new Node ( i ) ; prev = prev . next ; } prev . next = head ; var ptr1 = head , ptr2 = head ; while ( ptr1 . next != ptr1 ) { var count = 1 ; while ( count != m ) { ptr2 = ptr1 ; ptr1 = ptr1 . next ; count ++ ; } ptr2 . next = ptr1 . next ; ptr1 = ptr2 . next ; } document . write ( " " + " " + ptr1 . data ) ; } var n = 14 , m = 2 ; getJosephusPosition ( m , n ) ;

Accumulator variables: count, i
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } var head ; function push ( new_data ) { new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } function printList ( ) { node = head ; while ( node != null ) { document . write ( node . data + " " ) ; node = node . next ; } document . write ( " " ) ; } function countNodes ( ) { var count = 0 ; s = head ; while ( s != null ) { count ++ ; s = s . next ; } return count ; } function swapKth ( k ) { var n = countNodes ( ) ; if ( n < k ) return ; if ( 2 * k - 1 == n ) return ; x = head ; x_prev = null ; for ( i = 1 ; i < k ; i ++ ) { x_prev = x ; x = x . next ; } y = head ; y_prev = null ; for ( i = 1 ; i < n - k + 1 ; i ++ ) { y_prev = y ; y = y . next ; } if ( x_prev != null ) x_prev . next = y ; if ( y_prev != null ) y_prev . next = x ; temp = x . next ; x . next = y . next ; y . next = temp ; if ( k == 1 ) head = y ; if ( k == n ) head = x ; } for ( let i = 8 ; i >= 1 ; i -- ) push ( i ) ; document . write ( " " ) ; printList ( ) ; document . write ( " " ) ; for ( let i = 1 ; i < 9 ; i ++ ) { swapKth ( i ) ; document . write ( " " + i + " " ) ; printList ( ) ; document . write ( " " ) ; }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . next = this . prev = null ; } } function countPairs ( first , second , value ) { let count = 0 ; while ( first != null && second != null && first != second && second . next != first ) { if ( ( first . data + second . data ) == value ) { count ++ ; first = first . next ; second = second . prev ; } else if ( ( first . data + second . data ) > value ) second = second . prev ; else first = first . next ; } return count ; } function countTriplets ( head , x ) { if ( head == null ) return 0 ; let current , first , last ; let count = 0 ; last = head ; while ( last . next != null ) last = last . next ; for ( current = head ; current != null ; current = current . next ) { first = current . next ; count += countPairs ( first , last , x - current . data ) ; } return count ; } function insert ( head , data ) { let temp = new Node ( ) ; temp . data = data ; temp . next = temp . prev = null ; if ( ( head ) == null ) ( head ) = temp ; else { temp . next = head ; ( head ) . prev = temp ; ( head ) = temp ; } return head ; } let head = null ; head = insert ( head , 9 ) ; head = insert ( head , 8 ) ; head = insert ( head , 6 ) ; head = insert ( head , 5 ) ; head = insert ( head , 4 ) ; head = insert ( head , 2 ) ; head = insert ( head , 1 ) ; let x = 17 ; document . write ( " " + countTriplets ( head , x ) ) ;

Accumulator variables: count
Iterator variables: current
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . prev = null ; this . next = null ; } } function deleteNode ( head_ref , del ) { if ( head_ref == null del == null ) return head_ref ; if ( head_ref == del ) head_ref = del . next ; if ( del . next != null ) del . next . prev = del . prev ; if ( del . prev != null ) del . prev . next = del . next ; return head_ref ; } function removeDuplicates ( head_ref ) { if ( ( head_ref ) == null || ( head_ref ) . next == null ) return head_ref ; var ptr1 , ptr2 ; for ( ptr1 = head_ref ; ptr1 != null ; ptr1 = ptr1 . next ) { ptr2 = ptr1 . next ; while ( ptr2 != null ) { if ( ptr1 . data == ptr2 . data ) { var next = ptr2 . next ; head_ref = deleteNode ( head_ref , ptr2 ) ; ptr2 = next ; } else ptr2 = ptr2 . next ; } } return head_ref ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) ( head_ref ) . prev = new_node ; ( head_ref ) = new_node ; return head_ref ; } function printList ( head ) { if ( head == null ) document . write ( " " ) ; while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } } var head = null ; head = push ( head , 12 ) ; head = push ( head , 12 ) ; head = push ( head , 10 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 4 ) ; head = push ( head , 6 ) ; head = push ( head , 4 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; document . write ( " " ) ; printList ( head ) ; head = removeDuplicates ( head ) ; document . write ( " " + " " ) ; printList ( head ) ;

Iterator variables: ptr1
Class/struct names: Node
Javascript program:
/ *javascript mplementation to remove duplicates from an unsorted doubly linked list class Node { constructor ( val ) { this . data = val ; this . prev = null ; this . next = null ; } } function deleteNode ( head_ref , del ) { if ( head_ref == null del == null ) return null ; if ( head_ref == del ) head_ref = del . next ; if ( del . next != null ) del . next . prev = del . prev ; if ( del . prev != null ) del . prev . next = del . next ; return head_ref ; } function removeDuplicates ( head_ref ) { if ( ( head_ref ) == null ) return null ; var us = new Set ( ) ; var current = head_ref , next ; while ( current != null ) { if ( us . has ( current . data ) ) { next = current . next ; head_ref = deleteNode ( head_ref , current ) ; current = next ; } else { us . add ( current . data ) ; current = current . next ; } } return head_ref ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) ( head_ref ) . prev = new_node ; ( head_ref ) = new_node ; return head_ref ; } function printList ( head ) { if ( head == null ) document . write ( " " ) ; while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } } var head = null ; head = push ( head , 12 ) ; head = push ( head , 12 ) ; head = push ( head , 10 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 4 ) ; head = push ( head , 6 ) ; head = push ( head , 4 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; document . write ( " " ) ; printList ( head ) ; head = removeDuplicates ( head ) ; document . write ( " " + " " ) ; printList ( head ) ;

Class/struct names: Node