dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function xor_c ( a , b ) { return ( a == b ) ? ' ' : ' ' ; } function flip ( c ) { return ( c == ' ' ) ? ' ' : ' ' ; } function binarytoGray ( binary ) { let gray = " " ; gray += binary [ 0 ] ; for ( let i = 1 ; i < binary . length ; i ++ ) { gray += xor_c ( binary [ i - 1 ] , binary [ i ] ) ; } return gray ; } function graytoBinary ( gray ) { let binary = " " ; binary += gray [ 0 ] ; for ( let i = 1 ; i < gray . length ; i ++ ) { if ( gray [ i ] == ' ' ) binary += binary [ i - 1 ] ; else binary += flip ( binary [ i - 1 ] ) ; } return binary ; } let binary = " " ; document . write ( " " + binary + " " + binarytoGray ( binary ) + " " ) ; let gray = " " ; document . write ( " " + gray + " " + graytoBinary ( gray ) ) ;

Index/key variables: i
Accumulator variables: binary, gray, i
Iterator variables: i
Javascript program:
function seriesSum ( calculated , current , N ) { let i , cur = 1 ; if ( current == N + 1 ) return 0 ; for ( i = calculated ; i < calculated + current ; i ++ ) cur *= i ; return cur + seriesSum ( i , current + 1 , N ) ; } let N = 5 ; document . write ( seriesSum ( 1 , 1 , N ) ) ;

Accumulator variables: cur, i
Iterator variables: i
Javascript program:
function getSum ( BITree , index ) { let sum = 0 ; while ( index > 0 ) { sum += BITree [ index ] ; index -= index & ( - index ) ; } return sum ; } function updateBIT ( BITree , n , index , val ) { while ( index <= n ) { BITree [ index ] += val ; index += index & ( - index ) ; } } function convert ( arr , n ) { let temp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) temp [ i ] = arr [ i ] ; temp . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n ; i ++ ) { arr [ i ] = lower_bound ( temp , 0 , n , arr [ i ] ) + 1 ; } } function lower_bound ( a , low , high , element ) { while ( low < high ) { let middle = low + Math . floor ( ( high - low ) / 2 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function getInvCount ( arr , n ) { let invcount = 0 ; convert ( arr , n ) ; let BIT = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) BIT [ i ] = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { invcount += getSum ( BIT , arr [ i ] - 1 ) ; updateBIT ( BIT , n , arr [ i ] , 1 ) ; } return invcount ; } let arr = [ 8 , 4 , 2 , 1 ] ; let n = arr . length ; document . write ( " " + getInvCount ( arr , n ) ) ;

Index/key variables: i, index, middle
Accumulator variables: i, index, invcount, sum
Iterator variables: i
Javascript program:
function modFact ( n , p ) { if ( n >= p ) return 0 ; let result = 1 ; for ( let i = 1 ; i <= n ; i ++ ) result = ( result * i ) % p ; return result ; } let n = 25 , p = 29 ; document . write ( modFact ( n , p ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function inv ( a , m ) { let m0 = m ; let x0 = 0 ; let x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { let q = parseInt ( a / m ) ; let t = m ; m = a % m ; a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } function findMinX ( num , rem , k ) { let prod = 1 ; for ( let i = 0 ; i < k ; i ++ ) prod *= num [ i ] ; let result = 0 ; for ( let i = 0 ; i < k ; i ++ ) { pp = parseInt ( prod / num [ i ] ) ; result += rem [ i ] * inv ( pp , num [ i ] ) * pp ; } return result % prod ; } let num = new Array ( 3 , 4 , 5 ) ; let rem = new Array ( 2 , 3 , 1 ) ; let k = num . length ; document . write ( " " + findMinX ( num , rem , k ) ) ;

Index/key variables: i
Accumulator variables: i, prod, result, x1
Iterator variables: i
Javascript program:
function findMinX ( num , rem , k ) { while ( true ) { var j ; for ( j = 0 ; j < k ; j ++ ) if ( x % num [ j ] != rem [ j ] ) break ; if ( j == k ) return x ; x ++ ; } } var num = [ 3 , 4 , 5 ] ; var rem = [ 2 , 3 , 1 ] ; var k = num . length ; document . write ( " " + findMinX ( num , rem , k ) ) ;

Index/key variables: j
Accumulator variables: j, x
Iterator variables: j
Javascript program:
function nCrModpDP ( n , r , p ) { C = Array ( r + 1 ) . fill ( 0 ) ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = Math . min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ; } return C [ r ] ; } function nCrModpLucas ( n , r , p ) { if ( r == 0 ) return 1 ; var ni = n % p , ri = r % p ; } var n = 1000 , r = 900 , p = 13 ; document . write ( " " + nCrModpLucas ( n , r , p ) ) ;

Index/key variables: j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let N = 30 ; let fib = new Array ( N ) ; function largestFiboLessOrEqual ( n ) { fib [ 0 ] = 1 ; fib [ 1 ] = 2 ; let i ; for ( i = 2 ; fib [ i - 1 ] <= n ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } return ( i - 2 ) ; } function fibonacciEncoding ( n ) { let index = largestFiboLessOrEqual ( n ) ; let codeword = new Array ( index + 3 ) ; let i = index ; while ( n > 0 ) { codeword [ i ] = ' ' ; n = n - fib [ i ] ; i = i - 1 ; while ( i >= 0 && fib [ i ] > n ) { codeword [ i ] = ' ' ; i = i - 1 ; } } codeword [ index + 1 ] = ' ' ; codeword [ index + 2 ] = ' \0 ' ; let string = ( codeword ) . join ( " " ) ; return string ; } let n = 143 ; document . write ( " " + n + " " + fibonacciEncoding ( n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isValid ( n , d ) { var digit = n % 10 ; var sum = digit ; if ( digit == d ) return false ; n = parseInt ( n / 10 ) ; while ( n > 0 ) { digit = n % 10 ; if ( digit == d digit <= sum ) return false ; else { sum += digit ; n = parseInt ( n / 10 ) ; } } return true ; } function printGoodNumber ( L , R , d ) { for ( i = L ; i <= R ; i ++ ) { if ( isValid ( i , d ) ) document . write ( i + " " ) ; } } var L = 410 , R = 520 , d = 3 ; printGoodNumber ( L , R , d ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let dp = new Array ( 5001 ) ; for ( let i = 0 ; i < 5001 ; i ++ ) { dp [ i ] = new Array ( 5001 ) ; for ( let j = 0 ; j < 5001 ; j ++ ) { dp [ i ] [ j ] = new Array ( 5 ) ; } } function countWaysUtil ( n , parts , nextPart ) { if ( parts == 0 && n == 0 ) return 1 ; if ( n <= 0 parts <= 0 ) return 0 ; if ( dp [ n ] [ nextPart ] [ parts ] != - 1 ) return dp [ n ] [ nextPart ] [ parts ] ; for ( let i = nextPart ; i <= n ; i ++ ) ans += countWaysUtil ( n - i , parts - 1 , i ) ; return ( dp [ n ] [ nextPart ] [ parts ] = ans ) ; } function countWays ( n ) { for ( let i = 0 ; i < 5001 ; i ++ ) { for ( let j = 0 ; j < 5001 ; j ++ ) { for ( let l = 0 ; l < 5 ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } return countWaysUtil ( n , 4 , 1 ) ; } let n = 8 ; document . write ( countWays ( n ) ) ;

Index/key variables: i, j, l, n, nextPart, parts
Accumulator variables: ans, i, j, l
Iterator variables: i, j, l
Javascript program:
function simpleSieve ( limit ) { var mark = Array ( limit ) . fill ( true ) ; for ( p = 2 ; p * p < limit ; p ++ ) { if ( mark [ p ] == true ) { for ( i = p * p ; i < limit ; i += p ) mark [ i ] = false ; } } for ( p = 2 ; p < limit ; p ++ ) if ( mark [ p ] == true ) document . write ( p + " " ) ; }

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function printTwins ( low , high ) { var prime = Array . from ( { length : high + 1 } , ( _ , i ) => 0 ) ; var twin = false ; for ( i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( p = 2 ; p <= Math . floor ( Math . sqrt ( high ) ) + 1 ; p ++ ) { if ( prime [ p ] ) { for ( i = p * 2 ; i <= high ; i += p ) { prime [ i ] = false ; } } } for ( i = low ; i <= high ; i ++ ) { if ( prime [ i ] && prime [ i + 2 ] ) { var a = i + 2 ; document . write ( " " + " " + i + " " + a + " " ) ; twin = true ; break ; } } if ( twin == false ) { document . write ( " " ) ; } } printTwins ( 10 , 100 ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Boolean variables: twin
Javascript program:
function isFancy ( num ) { var fp = new Map ( ) ; fp . set ( ' ' , ' ' ) ; fp . set ( ' ' , ' ' ) ; fp . set ( ' ' , ' ' ) ; fp . set ( ' ' , ' ' ) ; fp . set ( ' ' , ' ' ) ; var n = num . length ; var l = 0 , r = n - 1 ; while ( l <= r ) { if ( ! fp . has ( num . charAt ( l ) ) || fp . get ( num . charAt ( l ) ) != num . charAt ( r ) ) return false ; l ++ ; r -- ; } return true ; } var str = " " ; if ( isFancy ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: l, r
Javascript program:
function nextSparse ( x ) { let bin = new Array ( ) ; while ( x != 0 ) { bin . push ( x & 1 ) ; x >>= 1 ; } bin . push ( 0 ) ; n = bin . length ; let last_final = 0 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( bin [ i ] == 1 && bin [ i - 1 ] == 1 && bin [ i + 1 ] != 1 ) { bin [ i + 1 ] = 1 ; for ( let j = i ; j >= last_final ; j -- ) bin [ j ] = 0 ; last_final = i + 1 ; } } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans += bin [ i ] * ( 1 << i ) ; return ans ; } let x = 38 ; document . write ( " " + nextSparse ( x ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function sumBitDifferences ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) { let count = 0 ; for ( let j = 0 ; j < n ; j ++ ) if ( ( arr [ j ] & ( 1 << i ) ) ) count ++ ; ans += ( count * ( n - count ) * 2 ) ; } return ans ; } let arr = [ 1 , 3 , 5 ] ; let n = arr . length ; document . write ( sumBitDifferences ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: ans, count, i, j
Iterator variables: i, j
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } function generateUtil ( x , arr , curr_sum , curr_idx ) { if ( curr_sum == x ) { printArr ( arr , curr_idx ) ; return ; } let num = 1 ; while ( num <= x - curr_sum && ( curr_idx == 0 num <= arr [ curr_idx - 1 ] ) ) { arr [ curr_idx ] = num ; generateUtil ( x , arr , curr_sum + num , curr_idx + 1 ) ; num ++ ; } } function generate ( x ) { let arr = new Array ( x ) ; generateUtil ( x , arr , 0 , 0 ) ; } let x = 5 ; generate ( x ) ;

Index/key variables: curr_idx, i
Accumulator variables: i, num
Iterator variables: i
Javascript program:
function isPerfect ( n ) { sum = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return true ; return false ; } document . write ( " " + " " ) ; for ( let n = 2 ; n < 10000 ; n ++ ) if ( isPerfect ( n ) ) document . write ( n + " " + " " ) ;

Accumulator variables: i, n
Iterator variables: i, n
Javascript program:
function checkUtil ( num , dig , base ) { if ( dig == 1 && num < base ) return true ; if ( dig > 1 && num >= base ) return checkUtil ( parseInt ( num / base ) , -- dig , base ) ; return false ; } function check ( num , dig ) { for ( base = 2 ; base <= 32 ; base ++ ) if ( checkUtil ( num , dig , base ) ) return true ; return false ; } var num = 8 ; var dig = 3 ; if ( check ( num , dig ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: base
Iterator variables: base
Javascript program:
function mod ( num , a ) { let res = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) res = ( res * 10 + num [ i ] - ' ' ) % a ; return res ; } let num = " " ; document . write ( mod ( num , 10 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function modInverse ( a , m ) { for ( let x = 1 ; x < m ; x ++ ) if ( ( ( a % m ) * ( x % m ) ) % m == 1 ) return x ; } let a = 3 ; let m = 11 ; document . write ( modInverse ( a , m ) ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function modInverse ( a , m ) { let m0 = m ; let y = 0 ; let x = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { let q = parseInt ( a / m ) ; let t = m ; m = a % m ; a = t ; t = y ; y = x - q * y ; x = t ; } if ( x < 0 ) x += m0 ; return x ; } let a = 3 ; let m = 11 ; document . write ( ` ${ modInverse ( a , m ) } ` ) ;

Accumulator variables: x
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function phi ( n ) { let result = 1 ; for ( let i = 2 ; i < n ; i ++ ) if ( gcd ( i , n ) == 1 ) result ++ ; return result ; } for ( let n = 1 ; n <= 10 ; n ++ ) document . write ( ` ${ n } ${ phi ( n ) } ` ) ;

Accumulator variables: i, n, result
Iterator variables: i, n
Javascript program:
function phi ( n ) { let result = n ; for ( let p = 2 ; p * p <= n ; ++ p ) { if ( n % p == 0 ) { while ( n % p == 0 ) n /= p ; result *= ( 1.0 - ( 1.0 / p ) ) ; } } if ( n > 1 ) result *= ( 1.0 - ( 1.0 / n ) ) ; return parseInt ( result ) ; } for ( let n = 1 ; n <= 10 ; n ++ ) document . write ( ` ${ n } ${ phi ( n ) } ` ) ;

Accumulator variables: n, result
Iterator variables: n, p
Javascript program:
function getRemainder ( num , divisor ) { while ( num >= divisor ) num -= divisor ; return num ; } let num = 100 , divisor = 7 ; document . write ( getRemainder ( num , divisor ) ) ;

Accumulator variables: num
Javascript program:
function factorial ( n ) { let res = 1 ; for ( let i = 2 ; i <= n ; i ++ ) res *= i ; return res ; } function sum ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) sum += 1.0 / factorial ( i ) ; return sum ; } let n = 5 ; document . write ( sum ( n ) . toFixed ( 5 ) ) ;

Accumulator variables: i, res, sum
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function catalan ( n ) { let c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } function findWays ( n ) { if ( n & 1 ) return 0 ; return catalan ( n / 2 ) ; } let n = 6 ; document . write ( " " + n + " " + findWays ( 6 ) ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function isOperand ( c ) { return ( c . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && c . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) ; } function value ( c ) { return ( c . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; } function evaluate ( exp ) { if ( exp . length == 0 ) return - 1 ; let res = value ( exp [ 0 ] ) ; for ( let i = 1 ; i < exp . length ; i += 2 ) { let opr = exp [ i ] , opd = exp [ i + 1 ] ; if ( isOperand ( opd ) == false ) return - 1 ; if ( opr == ' ' ) res += value ( opd ) ; else if ( opr == ' ' ) res -= value ( opd ) ; else if ( opr == ' ' ) res *= value ( opd ) ; else if ( opr == ' ' ) res /= value ( opd ) ; else return - 1 ; } return res ; } let expr1 = " " ; let res = evaluate ( expr1 ) ; if ( res == - 1 ) document . write ( expr1 + " " ) ; else document . write ( " " + expr1 + " " + res + " " ) ; let expr2 = " " ; res = evaluate ( expr2 ) ; if ( res == - 1 ) document . write ( expr2 + " " ) ; else document . write ( " " + expr2 + " " + res + " " ) ; let expr3 = " " ; res = evaluate ( expr3 ) ; if ( res == - 1 ) document . write ( expr3 + " " ) ; else document . write ( " " + expr3 + " " + res + " " ) ; let expr4 = " " ; res = evaluate ( expr4 ) ; if ( res == - 1 ) document . write ( expr4 + " " ) ; else document . write ( " " + expr4 + " " + res + " " ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function printFibonacciNumbers ( n ) { let f1 = 0 , f2 = 1 , i ; if ( n < 1 ) return ; document . write ( f1 + " " ) ; for ( i = 1 ; i < n ; i ++ ) { document . write ( f2 + " " ) ; let next = f1 + f2 ; f1 = f2 ; f2 = next ; } } printFibonacciNumbers ( 7 ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function accumulate ( arr ) { let sum = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { sum = sum + arr [ i ] ; } return sum ; } let arr = [ 12 , 3 , 4 , 15 ] ; let n = arr . length ; document . write ( " " + accumulate ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let M = 1e9 + 7 ; let directions = [ [ 0 , 1 ] , [ - 1 , 0 ] , [ 0 , - 1 ] , [ 1 , 0 ] , [ 1 , 1 ] , [ - 1 , - 1 ] , [ - 1 , 1 ] , [ 1 , - 1 ] , ] ; function isInside ( i , j , N , M ) { if ( i >= 0 && i < N && j >= 0 && j < M ) { return true ; } return false ; } function DFS ( mat , N , M , i , j , visited ) { if ( visited [ i ] [ j ] == true ) { return ; } visited [ i ] [ j ] = true ; for ( let it of directions ) { let I = i + it [ 0 ] ; let J = j + it [ 1 ] ; if ( isInside ( I , J , N , M ) ) { if ( mat [ I ] [ J ] == 0 ) { DFS ( mat , N , M , I , J , visited ) ; } } } } function check ( N , M , mat ) { let black = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == 0 ) { black ++ ; } } } if ( black < 2 * Math . max ( N , M ) ) { document . write ( " " ) ; return ; } let visited = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { let temp = [ ] ; for ( let j = 0 ; j < M ; j ++ ) { temp . push ( false ) ; } visited . push ( temp ) ; } let black_spots = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( visited [ i ] [ j ] == false && mat [ i ] [ j ] == 0 ) { black_spots ++ ; DFS ( mat , N , M , i , j , visited ) ; } } } let T = __gcd ( N , M ) ; cout << ( black_spots >= T ? " " : " " ) ; } let N = 3 ; M = 3 ; let mat = [ [ 0 , 0 , 1 ] , [ 1 , 1 , 1 ] , [ 0 , 0 , 1 ] , ] ; check ( M , N , mat ) ;

Index/key variables: I, J, i, j
Accumulator variables: black, black_spots, i, j
Iterator variables: i, it, j
Javascript program:
function countSubsequences ( arr ) { let odd = 0 ; let even = 0 ; for ( let x of arr ) { if ( x & 1 ) odd ++ ; else even ++ ; } return ( ( 1 << odd ) - 1 ) * ( 1 << even ) ; } let arr = [ 2 , 4 , 1 ] ; document . write ( countSubsequences ( arr ) ) ;

Accumulator variables: even, odd
Iterator variables: x
Javascript program:
class TreeNode { constructor ( val = " " , left = null , right = null ) { this . val = val ; this . left = left ; this . right = right ; } } function evalComp ( arr ) { let ans = 0 ; let getBit = 1 ; for ( let i = 0 ; i < 32 ; i ++ ) { let S = 0 ; let NS = 0 ; for ( j of arr ) { if ( getBit & j ) S += 1 ; else NS += 1 ; } if ( S > NS ) ans += 2 ** i ; getBit <<= 1 ; } document . write ( ans + " " ) ; } function compressTree ( root ) { let mp = new Map ( ) ; function Trav ( root , hd ) { if ( ! root ) return ; if ( ! mp . has ( hd ) ) mp . set ( hd , [ root . val ] ) ; else { let temp = mp . get ( hd ) ; temp . push ( root . val ) ; mp . set ( hd , temp ) ; } Trav ( root . left , hd - 1 ) ; Trav ( root . right , hd + 1 ) ; } Trav ( root , 0 ) ; let lower = [ ... mp . keys ( ) ] . sort ( ( a , b ) => a - b ) [ 0 ] ; let upper = [ ... mp . keys ( ) ] . sort ( ( a , b ) => b - a ) [ 0 ] ; for ( let i = lower ; i <= upper ; i ++ ) evalComp ( mp . get ( i ) ) ; } let root = new TreeNode ( 5 ) ; root . left = new TreeNode ( 3 ) ; root . right = new TreeNode ( 2 ) ; root . left . left = new TreeNode ( 1 ) ; root . left . right = new TreeNode ( 4 ) ; root . right . left = new TreeNode ( 1 ) ; root . right . right = new TreeNode ( 2 ) ; compressTree ( root ) ;

Accumulator variables: NS, S, ans, i
Iterator variables: i
Class/struct names: TreeNode
Javascript program:
function Or_of_Ands_for_each_query ( arr , n , queries , q ) { let bits = new Array ( 32 ) . fill ( 0 ) ; for ( let i = 0 ; i < 32 ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( ( 1 << i ) & arr [ j ] ) { bits [ i ] ++ ; } } } for ( let p = 0 ; p < q ; p ++ ) { for ( let i = 0 ; i < 32 ; i ++ ) { if ( ( 1 << i ) & arr [ queries [ p ] [ 0 ] ] ) { bits [ i ] -- ; } if ( queries [ p ] [ 1 ] & ( 1 << i ) ) { bits [ i ] ++ ; } } arr [ queries [ p ] [ 0 ] ] = queries [ p ] [ 1 ] ; let ans = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) { if ( bits [ i ] != 0 ) { ans |= ( 1 << i ) ; } } document . write ( ans + " " ) ; } } let n = 3 , q = 2 ; let arr = [ 3 , 5 , 7 ] ; let queries = [ [ 1 , 2 ] , [ 2 , 1 ] ] ; Or_of_Ands_for_each_query ( arr , n , queries , q ) ;

Index/key variables: i, j, p
Accumulator variables: ans, i, j, p
Iterator variables: i, j, p
Javascript program:
function XorSum ( A , B , N , M ) { let ans = - 1 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( ans == - 1 ) ans = ( A [ i ] & B [ j ] ) ; else ans ^= ( A [ i ] & B [ j ] ) ; } } return ans ; } let A = [ 3 , 5 ] ; let B = [ 2 , 3 ] ; let N = A . length ; let M = B . length ; document . write ( XorSum ( A , B , N , M ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countbitdiff ( xo ) { let count = 0 ; while ( xo ) { if ( xo % 2 == 1 ) { count ++ ; } xo = Math . floor ( xo / 2 ) ; } return count ; } function shortestPath ( n , a , b ) { let xorVal = a ^ b ; let cnt = countbitdiff ( xorVal ) ; if ( cnt % 2 == 0 ) document . write ( cnt / 2 + " " ) ; else document . write ( " " + " " ) ; } let n = 15 ; let a = 15 , b = 3 ; shortestPath ( n , a , b ) ;

Accumulator variables: count
Javascript program:
let M = 3 ; let N = 3 ; function findXOR ( X ) { let ans = 0 ; while ( X != 0 ) { ans ^= ( X % 10 ) ; X /= 10 ; } return ans ; } function printXORmatrix ( arr ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { document . write ( arr [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function convertXOR ( arr ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { let X = arr [ i ] [ j ] ; let temp = findXOR ( X ) ; arr [ i ] [ j ] = temp ; } } prletXORmatrix ( arr ) ; } let arr = [ [ 27 , 173 , 5 ] , [ 21 , 6 , 624 ] , [ 5 , 321 , 49 ] ] ; convertXOR ( arr ) ; ;

Index/key variables: i, j
Accumulator variables: X, ans, i, j
Iterator variables: i, j
Javascript program:
function countSet ( N ) { let ans = 0 ; while ( N ) { ans += N & 1 ; N >>= 1 ; } return ans ; } function countSub ( arr , k ) { let ans = 0 ; let setK = 0 ; for ( let i = 0 ; i < 5 ; i ++ ) { if ( countSet ( arr [ i ] ) == k ) setK += 1 ; else setK = 0 ; ans += setK ; } return ans ; } let arr = [ 4 , 2 , 1 , 5 , 6 ] ; let K = 2 ; document . write ( ( countSub ( arr , K ) ) ) ;

Index/key variables: i
Accumulator variables: ans, i, setK
Iterator variables: i
Javascript program:
function oddXorSubarray ( a , n ) { var odd = 0 ; var c_odd = 0 ; var result = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 != 0 ) { odd = ( odd == 0 ) ? 1 : 0 ; } if ( odd != 0 ) { c_odd ++ ; } } for ( i = 0 ; i < n ; i ++ ) { result += c_odd ; if ( a [ i ] % 2 != 0 ) { c_odd = ( n - i - c_odd ) ; } } document . write ( result ) ; } var arr = [ 1 , 4 , 7 , 9 , 10 ] ; var N = arr . length ; oddXorSubarray ( arr , N ) ;

Index/key variables: i
Accumulator variables: c_odd, i, result
Iterator variables: i
Javascript program:
function prletORSumforEachElement ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let req_sum = 0 ; for ( let j = 0 ; j < N ; j ++ ) { req_sum += ( arr [ i ] arr [ j ] ) ; } document . write ( req_sum + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; prletORSumforEachElement ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j, req_sum
Iterator variables: i, j
Javascript program:
function Bitwise_OR_sum_i ( arr1 , arr2 , M , N ) { let frequency = new Array ( 32 ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { let bit_position = 0 ; let num = arr1 [ i ] ; while ( num ) { if ( num & 1 ) { frequency [ bit_position ] += 1 ; } bit_position += 1 ; num >>= 1 ; } } for ( let i = 0 ; i < M ; i ++ ) { let num = arr2 [ i ] ; let value_at_that_bit = 1 ; let bitwise_OR_sum = 0 ; for ( let bit_position = 0 ; bit_position < 32 ; bit_position ++ ) { if ( num & 1 ) { bitwise_OR_sum += N * value_at_that_bit ; } else { bitwise_OR_sum += frequency [ bit_position ] * value_at_that_bit ; } num >>= 1 ; value_at_that_bit <<= 1 ; } document . write ( bitwise_OR_sum + ' ' ) ; } return ; } let arr1 = [ 1 , 2 , 3 ] ; let arr2 = [ 1 , 2 , 3 ] ; let N = arr1 . length ; let M = arr2 . length ; Bitwise_OR_sum_i ( arr1 , arr2 , M , N ) ;

Index/key variables: bit_position, i
Accumulator variables: bit_position, bitwise_OR_sum, i
Iterator variables: bit_position, i