dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
MAX = 10
def findSubarray ( array , n ) :
    mp = dict ( )
    mp [ 0 ] = 1
    answer = 0
    preXor = 0
    for i in range ( n ) :
        value = 1
        preXor ^= array [ i ]
        for j in range ( 1 , MAX + 1 ) :
            Y = value ^ preXor
            if ( Y in mp . keys ( ) ) :
                answer += mp [ Y ]
            value *= 2
        if ( preXor in mp . keys ( ) ) :
            mp [ preXor ] += 1
        else :
            mp [ preXor ] = 1
    return answer
array = [ 2 , 6 , 7 , 5 , 8 ]
n = len ( array )
print ( findSubarray ( array , n ) )

Index/key variables: Y, i, preXor
Accumulator variables: answer, value
Iterator variables: i, j
Python program:
def max_xor ( arr , n ) :
    maxx = 0
    mask = 0 ;
    se = set ( )
    for i in range ( 30 , - 1 , - 1 ) :
        mask |= ( 1 << i )
        newMaxx = maxx | ( 1 << i )
        for i in range ( n ) :
            se . add ( arr [ i ] & mask )
        for prefix in se :
            if ( newMaxx ^ prefix ) in se :
                maxx = newMaxx
                break
        se . clear ( )
    return maxx
arr = [ 25 , 10 , 2 , 8 , 5 , 3 ]
n = len ( arr )
print ( max_xor ( arr , n ) )

Index/key variables: i
Accumulator variables: mask, se
Iterator variables: i, prefix
Python program:
def CountTriplets ( arr , n ) :
    ans = 0
    for i in range ( n - 1 ) :
        first = arr [ i ]
        for j in range ( i + 1 , n ) :
            first ^= arr [ j ]
            if ( first == 0 ) :
                ans += ( j - i )
    return ans
arr = [ 2 , 5 , 6 , 4 , 2 ]
n = len ( arr )
print ( CountTriplets ( arr , n ) )

Index/key variables: i, j
Accumulator variables: ans, first
Iterator variables: i, j
Python program:
def findMajority ( arr , n ) :
    Len = 32
    number = 0
    for i in range ( Len ) :
        count = 0
        for j in range ( n ) :
            if ( arr [ j ] & ( 1 << i ) ) :
                count += 1
        if ( count > ( n // 2 ) ) :
            number += ( 1 << i )
    count = 0
    for i in range ( n ) :
        if ( arr [ i ] == number ) :
            count += 1
    if ( count > ( n // 2 ) ) :
        print ( number )
    else :
        print ( " Majority ▁ Element ▁ Not ▁ Present " )
arr = [ 3 , 3 , 4 , 2 , 4 , 4 , 2 , 4 , 4 ]
n = len ( arr )
findMajority ( arr , n )

Index/key variables: i, j
Accumulator variables: count, number
Iterator variables: i, j
Python program:
def countBits ( a , b ) :
    count = 0
    while ( a or b ) :
        last_bit_a = a & 1
        last_bit_b = b & 1
        if ( last_bit_a != last_bit_b ) :
            count += 1
        a = a >> 1
        b = b >> 1
    return count
a = 10
b = 7
print ( countBits ( a , b ) )

Accumulator variables: count
Python program:
def pairORSum ( arr , n ) :
    for i in range ( 0 , n ) :
        for j in range ( ( i + 1 ) , n ) :
            ans = ans + arr [ i ] | arr [ j ]
    return ans
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
print ( pairORSum ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False ;
    for i in range ( 2 , n ) :
        if ( n % i == 0 ) :
            return False ;
    return True ;
def countPrimePosition ( arr ) :
    c0 = 0 ; c1 = 0 ;
    n = len ( arr ) ;
    for i in range ( n ) :
        if ( arr [ i ] == 0 and isPrime ( i ) ) :
            c0 += 1 ;
        if ( arr [ i ] == 1 and isPrime ( i ) ) :
            c1 += 1 ;
    print ( " Number ▁ of ▁ 0s ▁ = " , c0 ) ;
    print ( " Number ▁ of ▁ 1s ▁ = " , c1 ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 0 , 1 , 0 , 1 ] ;
    countPrimePosition ( arr ) ;

Index/key variables: i
Accumulator variables: c0, c1
Iterator variables: i
Python program:
N = 101
def prefix ( arr , prefix_xor , n ) :
    for i in range ( 1 , n ) :
        for j in range ( 1 , n ) :
            prefix_xor [ i ] [ j ] = ( arr [ i ] [ j ] ^ prefix_xor [ i - 1 ] [ j ] ^ prefix_xor [ i ] [ j - 1 ] ^ prefix_xor [ i - 1 ] [ j - 1 ] )
def Max_xor ( prefix_xor , n ) :
    max_value = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , n + 1 ) :
            for i1 in range ( i , n + 1 ) :
                for j1 in range ( j , n + 1 ) :
                    x = 0
                    x ^= prefix_xor [ i1 ] [ j1 ]
                    x ^= prefix_xor [ i - 1 ] [ j - 1 ]
                    x ^= prefix_xor [ i1 ] [ j - 1 ]
                    x ^= prefix_xor [ i - 1 ] [ j1 ]
                    max_value = max ( max_value , x )
    print ( max_value )
arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ]
n = 4
prefix_xor = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]
prefix ( arr , prefix_xor , n )
Max_xor ( prefix_xor , n )

Index/key variables: i, i1, j, j1
Accumulator variables: x
Iterator variables: i, i1, j, j1
Python program:
arr = [ 0 ] * 32
def balTernary ( ter ) :
    carry , base , i = 0 , 10 , 31
    while ter > 0 :
        rem = ( ter % base ) + carry
        if rem == 0 :
            arr [ i ] = 0
            carry , i = 0 , i - 1
        elif rem == 1 :
            arr [ i ] = 1
            carry , i = 0 , i - 1
        elif rem == 2 :
            arr [ i ] = - 1
            carry , i = 1 , i - 1
        elif rem == 3 :
            arr [ i ] = 0
            carry , i = 1 , i - 1
        ter = ter // base
    if carry == 1 :
        arr [ i ] = 1
def ternary ( number ) :
    ans , rem , base = 0 , 1 , 1
    while number > 0 :
        rem = number % 3
        ans = ans + rem * base
        number //= 3
        base = base * 10
    return ans
if __name__ == " _ _ main _ _ " :
    number = 3056
    ter = ternary ( number )
    balTernary ( ter )
    i = 0
    while arr [ i ] == 0 :
        i += 1
    for j in range ( i , 32 ) :
        if arr [ j ] == - 1 :
            print ( ' Z ' , end = " " )
        else :
            print ( arr [ j ] , end = " " )

Index/key variables: i, j
Accumulator variables: number
Iterator variables: j
Python program:
def minAND ( arr , n ) :
    s = arr [ 0 ]
    for i in range ( 1 , n ) :
        s = s & arr [ i ]
    print ( s )
arr = [ 1 , 2 , 3 ]
n = len ( arr )
minAND ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def check ( a , n ) :
    for i in range ( n ) :
        if ( a [ i ] ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    a = [ 0 , 1 , 0 , 1 ]
    n = len ( a )
    if ( check ( a , n ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i
Iterator variables: i
Python program:
def printArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
def findArray ( q , n ) :
    arr = [ None ] * n
    k = 0
    for j in range ( int ( n / 4 ) ) :
        ans = q [ k ] ^ q [ k + 3 ]
        arr [ k + 1 ] = q [ k + 1 ] ^ ans
        arr [ k + 2 ] = q [ k + 2 ] ^ ans
        arr [ k ] = q [ k ] ^ ( ( arr [ k + 1 ] ) ^ ( arr [ k + 2 ] ) )
        arr [ k + 3 ] = q [ k + 3 ] ^ ( arr [ k + 1 ] ^ arr [ k + 2 ] )
        k += 4
    printArray ( arr , n )
if __name__ == ' _ _ main _ _ ' :
    q = [ 4 , 1 , 7 , 0 ]
    n = len ( q )
    findArray ( q , n )

Index/key variables: i, k
Iterator variables: i, j
Python program:
def countX ( n ) :
    binary = " { 0 : b } " . format ( n )
    count = 0
    for i in range ( len ( binary ) ) :
        if ( binary [ i ] == '1' ) :
            count += 1
    answer = int ( pow ( 2 , count ) )
    return answer
if __name__ == " _ _ main _ _ " :
    n = 5
    answer = countX ( n )
    print ( answer )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def isEqualBlock ( n ) :
    first_bit = n % 2
    first_count = 1
    n = n // 2
    while n % 2 == first_bit and n > 0 :
        n = n // 2
        first_count += 1
    if n == 0 :
        return False
    while n > 0 :
        first_bit = n % 2
        curr_count = 1
        n = n // 2
        while n % 2 == first_bit :
            n = n // 2
            curr_count += 1
        if curr_count != first_count :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    n = 51
    if isEqualBlock ( n ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: curr_count, first_count
Python program:
from math import pow
def binToDecimal3 ( n ) :
    a = [ 0 for i in range ( 64 ) ]
    x = 0
    i = 0
    while ( n > 0 ) :
        a [ i ] = n % 2
        n = int ( n / 2 )
        i += 1
    if ( i < 3 ) :
        x = 3
    else :
        x = i
    d = 0
    p = 0
    for i in range ( x - 3 , x , 1 ) :
        d += a [ i ] * pow ( 2 , p )
        p += 1
    print ( int ( d ) , end = " ▁ " )
    d = 0
    p = 0
    for i in range ( 0 , 3 , 1 ) :
        d += a [ i ] * pow ( 2 , p )
        p += 1
    print ( int ( d ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    n = 86
    binToDecimal3 ( n )

Index/key variables: i
Accumulator variables: d, p
Iterator variables: i
Python program:
def isPowerOfTwo ( x ) :
    if ( x == 0 ) :
        return False
    if ( ( x & ( x - 1 ) ) == 0 ) :
        return True
    else :
        return False
def countNum ( a , n ) :
    count = 0
    for i in range ( 0 , n , 1 ) :
        if ( isPowerOfTwo ( a [ i ] ) or isPowerOfTwo ( a [ i ] + 1 ) ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 6 , 9 , 3 , 1 ]
    n = len ( arr )
    print ( countNum ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def checkEvenParity ( x ) :
    parity = 0
    while ( x != 0 ) :
        x = x & ( x - 1 )
        parity += 1
    if ( parity % 2 == 0 ) :
        return True
    else :
        return False
def sumlist ( a , n ) :
    sum = 0
    for i in range ( n ) :
        if ( checkEvenParity ( a [ i ] ) ) :
            sum += a [ i ]
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 3 , 5 , 9 ]
    n = len ( arr )
    print ( sumlist ( arr , n ) )

Index/key variables: i
Accumulator variables: parity, sum
Iterator variables: i
Python program:
from typing import List
import bisect
from math import sqrt , floor
MAX = 100
BIT = [ 0 for _ in range ( MAX + 1 ) ]
class queries :
    def __init__ ( self , type : int = 0 , l : int = 0 , r : int = 0 ) -> None :
        self . type = type
        self . l = l
        self . r = r
def update ( x : int , val : int , n : int ) -> None :
    a = x
    while a <= n :
        BIT [ a ] += val
        a += a & - a
def sum ( x : int ) -> int :
    s = 0
    a = x
    while a :
        s += BIT [ a ]
        a -= a & - a
    return s
def answerQueries ( arr : List [ int ] , que : List [ queries ] , n : int , q : int ) -> None :
    s = set ( )
    for i in range ( 1 , n ) :
        if ( arr [ i ] > 1 ) :
            s . add ( i )
        update ( i , arr [ i ] , n )
    for i in range ( q ) :
        if ( que [ i ] . type == 1 ) :
            while True :
                ss = list ( sorted ( s ) )
                it = bisect . bisect_left ( ss , que [ i ] . l )
                if it == len ( s ) or ss [ it ] > que [ i ] . r :
                    break
                que [ i ] . l = ss [ it ]
                update ( ss [ it ] , floor ( sqrt ( arr [ ss [ it ] ] ) - arr [ ss [ it ] ] ) , n )
                arr [ ss [ it ] ] = floor ( sqrt ( arr [ ss [ it ] ] ) )
                if ( arr [ ss [ it ] ] == 1 ) :
                    s . remove ( ss [ it ] )
                que [ i ] . l += 1
        else :
            print ( sum ( que [ i ] . r ) - sum ( que [ i ] . l - 1 ) )
if __name__ == " _ _ main _ _ " :
    q = 4
    arr = [ 0 , 4 , 5 , 1 , 2 , 4 ]
    n = len ( arr )
    que = [ queries ( ) for _ in range ( q + 1 ) ]
    que [ 0 ] . type , que [ 0 ] . l , que [ 0 ] . r = 2 , 1 , 5
    que [ 1 ] . type , que [ 1 ] . l , que [ 1 ] . r = 1 , 1 , 2
    que [ 2 ] . type , que [ 2 ] . l , que [ 2 ] . r = 1 , 2 , 4
    que [ 3 ] . type , que [ 3 ] . l , que [ 3 ] . r = 2 , 1 , 5
    answerQueries ( arr , que , n , q )

Index/key variables: a, i, int, it, queries
Accumulator variables: s
Iterator variables: i
Class/struct names: queries
Python program:
def findevenPair ( A , N ) :
    evenPair = 0
    for i in range ( 0 , N ) :
        for j in range ( i + 1 , N ) :
            if ( ( A [ i ] ^ A [ j ] ) % 2 == 0 ) :
                evenPair += 1
    return evenPair ;
def main ( ) :
    A = [ 5 , 4 , 7 , 2 , 1 ]
    N = len ( A )
    print ( findevenPair ( A , N ) )
if __name__ == ' _ _ main _ _ ' :
    main ( )

Index/key variables: i, j
Accumulator variables: evenPair
Iterator variables: i, j
Python program:
def findEvenPair ( A , N ) :
    count = 0
    for i in range ( 0 , N ) :
        if ( A [ i ] % 2 != 0 ) :
            count += 1
    totalPairs = ( N * ( N - 1 ) / 2 )
    oddEvenPairs = count * ( N - count )
    return ( int ) ( totalPairs - oddEvenPairs )
def main ( ) :
    a = [ 5 , 4 , 7 , 2 , 1 ]
    n = len ( a )
    print ( findEvenPair ( a , n ) )
if __name__ == ' _ _ main _ _ ' :
    main ( )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findevenPair ( A , N ) :
    evenPair = 0
    for i in range ( 0 , N ) :
        for j in range ( i + 1 , N ) :
            if ( ( A [ i ] & A [ j ] ) % 2 == 0 ) :
                evenPair += 1
    return evenPair
a = [ 5 , 1 , 3 , 2 ]
n = len ( a )
print ( findevenPair ( a , n ) )

Index/key variables: i, j
Accumulator variables: evenPair
Iterator variables: i, j
Python program:
def findevenPair ( A , N ) :
    count = 0
    for i in range ( 0 , N ) :
        if ( A [ i ] % 2 != 0 ) :
            count += 1
    oddCount = count * ( count - 1 ) / 2
    return ( int ) ( ( N * ( N - 1 ) / 2 ) - oddCount )
a = [ 5 , 1 , 3 , 2 ]
n = len ( a )
print ( findevenPair ( a , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def xorGivenSetBits ( arr , n , k ) :
    v = [ ]
    for i in range ( 0 , n , 1 ) :
        if ( bin ( arr [ i ] ) . count ( '1' ) == k ) :
            v . append ( arr [ i ] )
    result = v [ 0 ]
    for i in range ( 1 , len ( v ) , 1 ) :
        result = result ^ v [ i ]
    return result
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 13 , 1 , 19 , 7 ]
    n = len ( arr )
    k = 3
    print ( xorGivenSetBits ( arr , n , k ) )

Index/key variables: i
Accumulator variables: v
Iterator variables: i
Python program:
def ReplaceElements ( arr , n ) :
    X = 0
    for i in range ( n ) :
        X ^= arr [ i ]
    for i in range ( n ) :
        arr [ i ] = X ^ arr [ i ]
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 3 , 5 , 5 ]
    n = len ( arr )
    ReplaceElements ( arr , n )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Accumulator variables: X
Iterator variables: i
Python program:
def countZeros ( x ) :
    total_bits = 32
    res = 0
    while ( ( x & ( 1 << ( total_bits - 1 ) ) ) == 0 ) :
        x = ( x << 1 )
        res += 1
    return res
x = 101
print ( countZeros ( x ) )

Accumulator variables: res
Python program:
def solve ( A , B ) :
    count = 0
    for i in range ( 0 , 32 ) :
        if ( ( ( A >> i ) & 1 ) != ( ( B >> i ) & 1 ) ) :
            count = count + 1
    print ( " Number ▁ of ▁ different ▁ bits ▁ : " , count )
A = 12
B = 15
solve ( A , B )

Iterator variables: i
Python program:
class Node :
    def __init__ ( self ) :
        self . data = None
        self . left = None
        self . right = None
def newNode ( data ) :
    node = Node ( )
    node . data = data
    node . left = None
    node . right = None
    return node
def printSetBit ( root : Node ) :
    if root is None :
        return
    print ( " Set ▁ bits ▁ in ▁ Node ▁ % d ▁ = ▁ % d " % ( root . data , bin ( root . data ) . count ( '1' ) ) )
    printSetBit ( root . left )
    printSetBit ( root . right )
if __name__ == " _ _ main _ _ " :
    root = newNode ( 16 )
    root . left = newNode ( 13 )
    root . left . left = newNode ( 14 )
    root . left . right = newNode ( 12 )
    root . right = newNode ( 11 )
    root . right . left = newNode ( 10 )
    root . right . right = newNode ( 16 )
    printSetBit ( root )

Class/struct names: Node
Python program:
def AND ( a , n ) :
    ans = a [ 0 ]
    for i in range ( n ) :
        ans &= a [ i ]
    return ans
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 3 ]
    n = len ( a )
    print ( AND ( a , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def TwoscomplementbyXOR ( str ) :
    n = len ( str )
    check_bit = 0
    i = n - 1
    s = list ( str )
    while ( i >= 0 ) :
        if ( s [ i ] == '0' and check_bit == 0 ) :
            continue
        else :
            if ( check_bit == 1 ) :
                s [ i ] = chr ( ( ord ( s [ i ] ) - 48 ) ^ 1 + 48 )
            check_bit = 1
        i -= 1
    str = " " . join ( s )
    if ( check_bit == 0 ) :
        return "1" + str
    else :
        return str
str = "101"
print ( TwoscomplementbyXOR ( str ) )

Index/key variables: i
Python program:
def bit_count ( n ) :
    count = 0 ;
    while ( n > 0 ) :
        count += 1 ;
        n = n & ( n - 1 ) ;
    return count ;
def maxsum ( arr , n ) :
    bits = [ 0 ] * n ;
    for i in range ( n ) :
        bits [ i ] = bit_count ( arr [ i ] ) ;
    sum = [ 0 ] * 32 ;
    for i in range ( n ) :
        sum [ bits [ i ] ] += arr [ i ] ;
    maximum = 0 ;
    for i in range ( 32 ) :
        maximum = max ( sum [ i ] , maximum ) ;
    return maximum ;
arr = [ 2 , 3 , 8 , 5 , 6 , 7 ] ;
n = len ( arr ) ;
print ( maxsum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def xor_pair_sum ( ar , n ) :
    total = 0
    for i in range ( n ) :
        total = total ^ ar [ i ]
    return 2 * total
if __name__ == " _ _ main _ _ " :
    data = [ 1 , 2 , 3 ]
    print ( xor_pair_sum ( data , len ( data ) ) )

Index/key variables: i
Iterator variables: i
Python program:
def findEvenPair ( A , N ) :
    count = 0
    for i in range ( N ) :
        if ( not ( A [ i ] & 1 ) ) :
            count += 1
    return count * ( count - 1 ) // 2
if __name__ == " _ _ main _ _ " :
    A = [ 5 , 6 , 2 , 8 ]
    N = len ( A )
    print ( findEvenPair ( A , N ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def checkSame ( n ) :
    set , unset = 0 , 0
    while ( n ) :
        if ( n and 1 ) :
            set + 1
        else :
            unset += 1
        n = n >> 1
    if ( set == unset ) :
        return True
    else :
        return False
if __name__ == ' _ _ main _ _ ' :
    n = 12
    if ( checkSame ( n ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Accumulator variables: unset
Python program:
def KthCharacter ( m , n , k ) :
    distance = pow ( 2 , n )
    Block_number = int ( k / distance )
    remaining = k % distance
    s = [ 0 ] * 32
    x = 0
    while ( m > 0 ) :
        s [ x ] = m % 2
        m = int ( m / 2 )
        x += 1
    root = s [ x - 1 - Block_number ]
    if ( remaining == 0 ) :
        print ( root )
        return
    flip = True
    while ( remaining > 1 ) :
        if ( remaining & 1 ) :
            flip = not ( flip )
        remaining = remaining >> 1
    if ( flip ) :
        print ( not ( root ) )
    else :
        print ( root )
m = 5
k = 5
n = 3
KthCharacter ( m , n , k )

Index/key variables: x
Boolean variables: flip
Python program:
from math import pow
def getInteger ( L , R ) :
    number = 0
    for i in range ( L , R + 1 , 1 ) :
        number += pow ( 2 , i )
    return number
if __name__ == ' _ _ main _ _ ' :
    L = 2
    R = 5
    print ( int ( getInteger ( L , R ) ) )

Accumulator variables: number
Iterator variables: i
Python program:
def findXor ( arr , n ) :
    xoR = 0 ;
    for i in range ( 0 , n ) :
        xoR = xoR ^ arr [ i ]
    return xoR * 2
arr = [ 1 , 5 , 6 ]
n = len ( arr )
print ( findXor ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def printOdds ( arr , n ) :
    res = 0
    for i in range ( 0 , n ) :
        res = res ^ arr [ i ]
    set_bit = res & ( ~ ( res - 1 ) )
    x = 0
    y = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] & set_bit ) :
            x = x ^ arr [ i ]
        else :
            y = y ^ arr [ i ]
    print ( x , y , end = " " )
arr = [ 2 , 3 , 3 , 4 , 4 , 5 ]
n = len ( arr )
printOdds ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
BitCount = [ 0 ] * 10000
def fillSetBitsmatrix ( arr : list , n : int ) :
    global BitCount
    for i in range ( 32 ) :
        for j in range ( n ) :
            temp = arr [ j ] >> i
            if temp % 2 != 0 :
                BitCount [ j ] += 1
    for i in range ( 1 , n ) :
        BitCount [ i ] += BitCount [ i - 1 ]
def Query ( Q : list , q : int ) :
    for i in range ( q ) :
        print ( BitCount [ Q [ i ] [ 1 ] ] - BitCount [ Q [ i ] [ 0 ] - 1 ] )
if __name__ == " _ _ main _ _ " :
    Arr = [ 1 , 5 , 6 , 10 , 9 , 4 , 67 ]
    n = len ( Arr )
    fillSetBitsmatrix ( Arr , n )
    q = 2
    Q = [ ( 1 , 5 ) , ( 2 , 6 ) ]
    Query ( Q , q )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def decimalToBinaryNumber ( x , n ) :
    binaryNumber = [ 0 ] * x ;
    i = 0 ;
    while ( x > 0 ) :
        binaryNumber [ i ] = x % 2 ;
        x = x // 2 ;
        i += 1 ;
    for j in range ( 0 , n - i ) :
        print ( '0' , end = " " ) ;
    for j in range ( i - 1 , - 1 , - 1 ) :
        print ( binaryNumber [ j ] , end = " " ) ;
def generateGrayarr ( n ) :
    N = 1 << n ;
    for i in range ( N ) :
        x = i ^ ( i >> 1 ) ;
        decimalToBinaryNumber ( x , n ) ;
        print ( ) ;
if __name__ == ' _ _ main _ _ ' :
    n = 3 ;
    generateGrayarr ( n ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
BITS = 32 ;
def andSum ( arr , n ) :
    ans = 0
    for i in range ( 0 , BITS ) :
        countSetBits = 0
        for j in range ( 0 , n ) :
            if ( arr [ j ] & ( 1 << i ) ) :
                countSetBits = ( countSetBits + 1 )
        subset = ( ( 1 << countSetBits ) - 1 )
        subset = ( subset * ( 1 << i ) )
        ans = ans + subset
    return ans
arr = [ 1 , 2 , 3 ]
size = len ( arr )
print ( andSum ( arr , size ) )

Index/key variables: j
Iterator variables: i, j
Python program:
def countSetBits ( n ) :
    count = 0
    while ( n ) :
        count += n & 1
        n >>= 1
    return count
i = 3
print ( countSetBits ( i ) )

Accumulator variables: count, n
Python program:
def isEven ( n ) :
    isEven = True ;
    for i in range ( 1 , n + 1 ) :
        if isEven == True :
            isEven = False ;
        else :
            isEven = True ;
    return isEven ;
n = 101 ;
if isEven ( n ) == True :
    print ( " Even " ) ;
else :
    print ( " Odd " ) ;

Iterator variables: i
Boolean variables: isEven
Python program:
def checkValidPair ( num1 , num2 ) :
    s1 = str ( num1 )
    s2 = str ( num2 )
    for i in range ( len ( s1 ) ) :
        for j in range ( len ( s2 ) ) :
            if ( s1 [ i ] == s2 [ j ] ) :
                return True ;
    return False ;
def countPairs ( arr , n ) :
    numberOfPairs = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( checkValidPair ( arr [ i ] , arr [ j ] ) ) :
                numberOfPairs += 1
    return numberOfPairs
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 12 , 24 ]
    n = len ( arr )
    print ( countPairs ( arr , n ) )

Index/key variables: i, j
Accumulator variables: numberOfPairs
Iterator variables: i, j
Python program:
NUM_BITS = 32
def isPowerOf2 ( num ) :
    return ( num and ( num & ( num - 1 ) ) == 0 )
def checkSubsequence ( arr , n ) :
    if ( n == 1 ) :
        return isPowerOf2 ( arr [ 0 ] )
    total = 0
    for i in range ( 0 , NUM_BITS ) :
        total = total | ( 1 << i )
    for i in range ( 0 , NUM_BITS ) :
        ans = total
        for j in range ( 0 , n ) :
            if ( arr [ j ] & ( 1 << i ) ) :
                ans = ans & arr [ j ]
        if ( isPowerOf2 ( ans ) ) :
            return True
    return False
arr = [ 12 , 13 , 7 ]
n = len ( arr )
if ( checkSubsequence ( arr , n ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: j
Iterator variables: i, j