dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def decToBinary ( n ) :
    binaryNum = [ 0 ] * n ;
    i = 0 ;
    while ( n > 0 ) :
        binaryNum [ i ] = n % 2 ;
        n = int ( n / 2 ) ;
        i += 1 ;
    for j in range ( i - 1 , - 1 , - 1 ) :
        print ( binaryNum [ j ] , end = " " ) ;
n = 17 ;
decToBinary ( n ) ;

Index/key variables: i, j
Iterator variables: j
Python program:
def flipSign ( a ) :
    neg = 0 ;
    tmp = 1 if a < 0 else - 1 ;
    while ( a != 0 ) :
        neg += tmp ;
        a += tmp ;
    return neg ;
def areDifferentSign ( a , b ) :
    return ( ( a < 0 and b > 0 ) or ( a > 0 and b < 0 ) ) ;
def sub ( a , b ) :
    return a + flipSign ( b ) ;
def mul ( a , b ) :
    if ( a < b ) :
        return mul ( b , a ) ;
    sum = 0 ;
    for i in range ( abs ( b ) , 0 , - 1 ) :
        sum += a ;
    if ( b < 0 ) :
        sum = flipSign ( sum ) ;
    return sum ;
def division ( a , b ) :
    quotient = 0 ;
    divisor = flipSign ( abs ( b ) ) ;
    for dividend in range ( abs ( a ) , abs ( divisor ) + divisor , divisor ) :
        quotient += 1 ;
    if ( areDifferentSign ( a , b ) ) :
        quotient = flipSign ( quotient ) ;
    return quotient ;
print ( " Subtraction ▁ is " , sub ( 4 , - 2 ) ) ;
print ( " Product ▁ is " , mul ( - 9 , 6 ) ) ;
a , b = 8 , 2 ;
if ( b ) :
    print ( " Division ▁ is " , division ( a , b ) ) ;
else :
    print ( " Exception ▁ : - ▁ Divide ▁ by ▁ 0" ) ;

Accumulator variables: a, neg, quotient, sum
Iterator variables: dividend, i
Python program:
def numOfCombinations ( arr , N ) :
    C = [ 0 , 0 , 0 ]
    for i in range ( N ) :
        C [ arr [ i ] % 3 ] = C [ arr [ i ] % 3 ] + 1
    return ( C [ 1 ] * C [ 2 ] + C [ 0 ] * ( C [ 0 ] - 1 ) / 2 + C [ 0 ] * ( C [ 0 ] - 1 ) * ( C [ 0 ] - 2 ) / 6 + C [ 1 ] * ( C [ 1 ] - 1 ) * ( C [ 1 ] - 2 ) / 6 + C [ 2 ] * ( C [ 2 ] - 1 ) * ( C [ 2 ] - 2 ) / 6 + C [ 0 ] * C [ 1 ] * C [ 2 ] )
arr1 = [ 1 , 5 , 7 , 2 , 9 , 14 ]
print ( int ( numOfCombinations ( arr1 , 6 ) ) )
arr2 = [ 3 , 6 , 9 , 12 ]
print ( int ( numOfCombinations ( arr2 , 4 ) ) )

Index/key variables: i
Iterator variables: i
Python program:
def __gcd ( x , y ) :
    if x > y :
        small = y
    else :
        small = x
    for i in range ( 1 , small + 1 ) :
        if ( ( x % i == 0 ) and ( y % i == 0 ) ) :
            gcd = i
    return gcd
def FindLCM ( a , b ) :
    return ( a * b ) / __gcd ( a , b ) ;
def rangeDivisor ( m , n , a , b ) :
    lcm = FindLCM ( a , b )
    a_divisor = int ( n / a - ( m - 1 ) / a )
    b_divisor = int ( n / b - ( m - 1 ) / b )
    common_divisor = int ( n / lcm - ( m - 1 ) / lcm )
    ans = a_divisor + b_divisor - common_divisor
    return ans
m = 3
n = 11
a = 2
b = 3 ;
print ( rangeDivisor ( m , n , a , b ) )
m = 11
n = 1000000
a = 6
b = 35
print ( rangeDivisor ( m , n , a , b ) )

Iterator variables: i
Python program:
def printUnique ( l , r ) :
    for i in range ( l , r + 1 ) :
        num = i ;
        visited = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
        while ( num ) :
            if visited [ num % 10 ] == 1 :
                break ;
            visited [ num % 10 ] = 1 ;
            num = ( int ) ( num / 10 ) ;
        if num == 0 :
            print ( i , end = " ▁ " ) ;
l = 1 ;
r = 20 ;
printUnique ( l , r ) ;

Iterator variables: i
Python program:
def printCubes ( a , b ) :
    for i in range ( a , b + 1 ) :
        j = 1
        for j in range ( j ** 3 , i + 1 ) :
            if ( j ** 3 == i ) :
                print ( j ** 3 , end = " ▁ " )
                break
a = 1 ; b = 100
print ( " Perfect ▁ cubes ▁ in ▁ given ▁ range : ▁ " )
printCubes ( a , b )

Iterator variables: i, j
Python program:
def toBinary ( n ) :
    if ( n >= 1 or n <= 0 ) :
        return " ERROR " ;
    frac = 0.5 ;
    answer = " . " ;
    while ( n > 0 ) :
        if ( len ( answer ) >= 32 ) :
            return " ERROR " ;
        if ( n >= frac ) :
            answer += "1" ;
            n = n - frac ;
        else :
            answer += "0" ;
        frac = ( frac / 2 ) ;
    return answer ;
n = 0.625 ;
result = toBinary ( n ) ;
print ( " ( ▁ 0" , result , " ) ▁ in ▁ base ▁ 2" ) ;
m = 0.72 ;
result = toBinary ( m ) ;
print ( " ( " , result , " ) " ) ;

Accumulator variables: answer
Python program:
def firstkdigits ( n , k ) :
    product = 1
    for i in range ( n ) :
        product *= n
    while ( ( product // pow ( 10 , k ) ) != 0 ) :
        product = product // 10
    return product
n = 15
k = 4
print ( firstkdigits ( n , k ) )

Accumulator variables: product
Iterator variables: i
Python program:
def check ( st ) :
    n = len ( st )
    digitSum = 0
    for i in range ( 0 , n ) :
        digitSum = digitSum + ( int ) ( st [ i ] )
    return ( digitSum % 9 == 0 )
st = "99333"
if ( check ( st ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def getTotalXorOfSubarrayXors ( arr , N ) :
    res = 0
    for i in range ( 0 , N ) :
        for j in range ( i , N ) :
            for k in range ( i , j + 1 ) :
                res = res ^ arr [ k ]
    return res
arr = [ 3 , 5 , 2 , 4 , 6 ]
N = len ( arr )
print ( getTotalXorOfSubarrayXors ( arr , N ) )

Index/key variables: k
Iterator variables: i, j, k
Python program:
def getTotalXorOfSubarrayXors ( arr , N ) :
    res = 0
    for i in range ( 0 , N ) :
        freq = ( i + 1 ) * ( N - i )
        if ( freq % 2 == 1 ) :
            res = res ^ arr [ i ]
    return res
arr = [ 3 , 5 , 2 , 4 , 6 ]
N = len ( arr )
print ( getTotalXorOfSubarrayXors ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
import math
def isPerfectSquare ( x ) :
    sq = ( int ) ( math . sqrt ( x ) )
    return ( x == sq * sq )
def countPerfectDivisors ( n ) :
    cnt = 0
    for i in range ( 1 , ( int ) ( math . sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            if isPerfectSquare ( i ) :
                cnt = cnt + 1
            if n / i != i and isPerfectSquare ( n / i ) :
                cnt = cnt + 1
    return cnt
print ( " Total ▁ perfect ▁ divisor ▁ of ▁ 16 ▁ = ▁ " , countPerfectDivisors ( 16 ) )
print ( " Total ▁ perfect ▁ divisor ▁ of ▁ 12 ▁ = ▁ " , countPerfectDivisors ( 12 ) )

Iterator variables: i
Python program:
import math
def nearestGcd ( arr , n ) :
    for i in range ( n ) :
        closest = - 1
        j = i - 1
        k = i + 1
        while j > 0 or k <= n :
            if ( j >= 0 and math . gcd ( arr [ i ] , arr [ j ] ) > 1 ) :
                closest = j + 1
                break
            if ( k < n and math . gcd ( arr [ i ] , arr [ k ] ) > 1 ) :
                closest = k + 1
                break
            k += 1
            j -= 1
        print ( closest , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 9 , 4 , 3 , 13 ]
    n = len ( arr )
    nearestGcd ( arr , n )

Index/key variables: i, j, k
Iterator variables: i
Python program:
import math as mt
MAX = 100001
prime = [ 0 for i in range ( MAX + 1 ) ]
countdiv = [ 0 for i in range ( MAX + 1 ) ]
def SieveOfEratosthenes ( ) :
    for i in range ( 2 , mt . ceil ( mt . sqrt ( MAX + 1 ) ) ) :
        if ( prime [ i ] == 0 ) :
            for j in range ( i * 2 , MAX + 1 , i ) :
                prime [ j ] = i
    for i in range ( 1 , MAX ) :
        if ( prime [ i ] == 0 ) :
            prime [ i ] = i
def largestGCDSubsequence ( arr , n ) :
    ans = 0
    for i in range ( n ) :
        element = arr [ i ]
        while ( element > 1 ) :
            div = prime [ element ]
            countdiv [ div ] += 1
            ans = max ( ans , countdiv [ div ] )
            while ( element % div == 0 ) :
                element = element // div
    return ans
SieveOfEratosthenes ( )
arr = [ 10 , 15 , 7 , 25 , 9 , 35 ]
size = len ( arr )
print ( largestGCDSubsequence ( arr , size ) )

Index/key variables: div, element, i, j
Iterator variables: i, j
Python program:
from collections import deque
def countOfBinaryNumberLessThanN ( N ) :
    q = deque ( )
    q . append ( 1 )
    cnt = 0
    while ( q ) :
        t = q . popleft ( )
        if ( t <= N ) :
            cnt = cnt + 1
            q . append ( t * 10 )
            q . append ( t * 10 + 1 )
    return cnt
if __name__ == ' _ _ main _ _ ' :
    N = 200
    print ( countOfBinaryNumberLessThanN ( N ) )

Accumulator variables: q
Python program:
def sumofproduct ( n ) :
    ans = 0
    for x in range ( 1 , n + 1 ) :
        y = int ( n / x )
        ans += ( y * x )
    return ans
n = 10
print ( sumofproduct ( n ) )

Accumulator variables: ans
Iterator variables: x
Python program:
def fact ( n ) :
    num = 1
    for i in range ( 1 , n + 1 ) :
        num = num * i
    return num
def Special_Factorial_Number ( k ) :
    for i in range ( 1 , k + 1 ) :
        if ( fact ( i ) % k == 0 ) :
            return i
    return 0
if __name__ == ' _ _ main _ _ ' :
    k = 16
    print ( Special_Factorial_Number ( k ) )

Iterator variables: i
Python program:
import math
MAX = 10000 ;
primes = [ ] ;
def sieveSundaram ( ) :
    marked = [ False ] * int ( MAX / 2 + 1 ) ;
    for i in range ( 1 , int ( ( math . sqrt ( MAX ) - 1 ) / 2 ) + 1 ) :
        for j in range ( ( i * ( i + 1 ) ) << 1 , int ( MAX / 2 ) + 1 , 2 * i + 1 ) :
            marked [ j ] = True ;
    primes . append ( 2 ) ;
    for i in range ( 1 , int ( MAX / 2 ) + 1 ) :
        if ( marked [ i ] == False ) :
            primes . append ( 2 * i + 1 ) ;
def isEquidigital ( n ) :
    if ( n == 1 ) :
        return True ;
    original_no = n ;
    sumDigits = 0 ;
    while ( original_no > 0 ) :
        sumDigits += 1 ;
        original_no = int ( original_no / 10 ) ;
    pDigit = 0 ;
    count_exp = 0 ;
    p = 0 ;
    i = 0 ;
    while ( primes [ i ] <= int ( n / 2 ) ) :
        while ( n % primes [ i ] == 0 ) :
            p = primes [ i ] ;
            n = int ( n / p ) ;
            count_exp += 1 ;
        while ( p > 0 ) :
            pDigit += 1 ;
            p = int ( p / 10 ) ;
        while ( count_exp > 1 ) :
            pDigit += 1 ;
            count_exp = int ( count_exp / 10 ) ;
        i += 1 ;
    if ( n != 1 ) :
        while ( n > 0 ) :
            pDigit += 1 ;
            n = int ( n / 10 ) ;
    return ( pDigit == sumDigits ) ;
sieveSundaram ( ) ;
print ( " Printing ▁ first ▁ few ▁ Equidigital " , " Numbers ▁ using ▁ isEquidigital ( ) " ) ;
for i in range ( 1 , 20 ) :
    if ( isEquidigital ( i ) ) :
        print ( i , end = " ▁ " ) ;

Index/key variables: i, j
Accumulator variables: count_exp, pDigit, primes, sumDigits
Iterator variables: i, j
Python program:
import math
def lcm ( n ) :
    ans = 1
    for i in range ( 1 , n + 1 ) :
        ans = int ( ( ans * i ) / math . gcd ( ans , i ) )
    return ans
n = 20
print ( lcm ( n ) )

Iterator variables: i
Python program:
def y ( x ) :
    return ( 1 / ( 1 + x * x ) )
def trapezoidal ( a , b , n ) :
    h = ( b - a ) / n
    s = ( y ( a ) + y ( b ) )
    i = 1
    while i < n :
        s += 2 * y ( a + i * h )
        i += 1
    return ( ( h / 2 ) * s )
x0 = 0
xn = 1
n = 6
print ( " Value ▁ of ▁ integral ▁ is ▁ " , " % .4f " % trapezoidal ( x0 , xn , n ) )

Accumulator variables: i, s
Python program:
def maxProd ( n ) :
    if ( n == 2 or n == 3 ) :
        return ( n - 1 ) ;
    res = 1 ;
    while ( n > 4 ) :
        n -= 3 ;
        res *= 3 ;
    return ( n * res ) ;
if __name__ == ' _ _ main _ _ ' :
    print ( " Maximum ▁ Product ▁ is " , maxProd ( 45 ) )

Accumulator variables: n, res
Python program:
def factors ( n , k ) :
    v = [ ] ;
    while ( n % 2 == 0 ) :
        v . append ( 2 ) ;
        n //= 2 ;
    if ( len ( v ) >= k ) :
        return True ;
    for i in range ( 3 , int ( n ** ( 1 / 2 ) ) , 2 ) :
        while ( n % i == 0 ) :
            n = n // i ;
            v . append ( i ) ;
        if ( len ( v ) >= k ) :
            return True ;
    if ( n > 2 ) :
        v . append ( n ) ;
    if ( len ( v ) >= k ) :
        return True ;
    return False ;
def operation ( n , k ) :
    answered = False ;
    if ( n < k ) :
        answered = True ;
        print ( " No " ) ;
    ok = factors ( n , k ) ;
    if ( not ok and not answered ) :
        answered = True ;
        print ( " No " ) ;
    if ( ok and not answered ) :
        print ( " Yes " ) ;
if __name__ == " _ _ main _ _ " :
    n = 4 ;
    k = 2 ;
    operation ( n , k ) ;

Accumulator variables: n, v
Iterator variables: i
Boolean variables: answered
Python program:
import random
def generateOTP ( length ) :
    str = " abcdefghijklmnopqrstuvwxyzAB\ STRNEWLINE TABSYMBOL CDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
    n = len ( str ) ;
    OTP = " " ;
    for i in range ( 1 , length + 1 ) :
        OTP += str [ int ( random . random ( ) * 10 ) % n ] ;
    return ( OTP ) ;
if __name__ == ' _ _ main _ _ ' :
    length = 6 ;
    print ( " Your ▁ OTP ▁ is ▁ - ▁ " , generateOTP ( length ) ) ;

Accumulator variables: OTP
Iterator variables: i
Python program:
def __gcd ( a , b ) :
    if ( a == 0 ) :
        return b
    return __gcd ( b % a , a )
def LcmOfArray ( arr , idx ) :
    if ( idx == len ( arr ) - 1 ) :
        return arr [ idx ]
    a = arr [ idx ]
    b = LcmOfArray ( arr , idx + 1 )
    return int ( a * b / __gcd ( a , b ) )
arr = [ 1 , 2 , 8 , 3 ]
print ( LcmOfArray ( arr , 0 ) )
arr = [ 2 , 7 , 3 , 9 , 4 ]
print ( LcmOfArray ( arr , 0 ) )

Index/key variables: idx
Python program:
import math
def countDivisors ( n ) :
    count = 0
    for i in range ( 1 , ( int ) ( math . sqrt ( n ) ) + 2 ) :
        if ( n % i == 0 ) :
            if ( n // i == i ) :
                count = count + 1
            else :
                count = count + 2
    if ( count % 2 == 0 ) :
        print ( " Even " )
    else :
        print ( " Odd " )
print ( " The ▁ count ▁ of ▁ divisor : ▁ " )
countDivisors ( 10 )

Iterator variables: i
Python program:
def largestPower ( n , p ) :
    x = 0
    while ( n ) :
        n //= p
        x += n
    return x
def power ( x , y , p ) :
    res = 1
    x = x % p
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p
        x = ( x * x ) % p
    return res
def modFact ( n , p ) :
    if ( n >= p ) :
        return 0
    res = 1
    isPrime = [ 1 ] * ( n + 1 )
    i = 2
    while ( i * i <= n ) :
        if ( isPrime [ i ] ) :
            for j in range ( 2 * i , n , i ) :
                isPrime [ j ] = 0
        i += 1
    for i in range ( 2 , n ) :
        if ( isPrime [ i ] ) :
            k = largestPower ( n , i )
            res = ( res * power ( i , k , p ) ) % p
    return res
if __name__ == " _ _ main _ _ " :
    n = 25
    p = 29
    print ( modFact ( n , p ) )

Index/key variables: i, j
Accumulator variables: n, x
Iterator variables: i, j
Python program:
def replace0with5 ( number ) :
    number += calculateAddedValue ( number )
    return number
def calculateAddedValue ( number ) :
    result = 0
    decimalPlace = 1
    if ( number == 0 ) :
        result += ( 5 * decimalPlace )
    while ( number > 0 ) :
        if ( number % 10 == 0 ) :
            result += ( 5 * decimalPlace )
        number //= 10
        decimalPlace *= 10
    return result
print ( replace0with5 ( 1020 ) )

Accumulator variables: decimalPlace, number, result
Python program:
def sum ( n ) :
    sum = 0
    fact = 1
    for i in range ( 1 , n + 1 ) :
        fact *= i
        sum += 1.0 / fact
    print ( sum )
n = 5
sum ( n )

Accumulator variables: fact, sum
Iterator variables: i
Python program:
import math
def Print ( n , k ) :
    rem = 1
    for i in range ( 0 , k ) :
        print ( math . floor ( ( ( 10 * rem ) / n ) ) , end = " " )
        rem = ( 10 * rem ) % n
n = 7
k = 3
Print ( n , k ) ;
print ( " ▁ " )
n = 21
k = 4
Print ( n , k ) ;

Iterator variables: i
Python program:
def rearrange ( arr , n ) :
    for i in range ( 0 , n ) :
        arr [ i ] += ( arr [ arr [ i ] ] % n ) * n
    for i in range ( 0 , n ) :
        arr [ i ] = int ( arr [ i ] / n )
def printArr ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( " " )
arr = [ 3 , 2 , 0 , 1 ]
n = len ( arr )
print ( " Given ▁ array ▁ is " )
printArr ( arr , n )
rearrange ( arr , n ) ;
print ( " Modified ▁ array ▁ is " )
printArr ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def printArray ( arr , size ) :
    for i in range ( size ) :
        print ( arr [ i ] , end = " ▁ " ) ;
    print ( " " ) ;
    return ;
def printSequencesRecur ( arr , n , k , index ) :
    if ( k == 0 ) :
        printArray ( arr , index ) ;
    if ( k > 0 ) :
        for i in range ( 1 , n + 1 ) :
            arr [ index ] = i ;
            printSequencesRecur ( arr , n , k - 1 , index + 1 ) ;
def printSequences ( n , k ) :
    arr = [ 0 ] * n ;
    printSequencesRecur ( arr , n , k , 0 ) ;
    return ;
n = 3 ;
k = 2 ;
printSequences ( n , k ) ;

Index/key variables: i, index
Iterator variables: i
Python program:
from collections import defaultdict
def countPairs ( arr , N , K ) :
    mp = defaultdict ( int )
    cnt = 0
    for i in range ( N ) :
        cnt += mp [ K - arr [ i ] ]
        mp [ arr [ i ] ] += 1
    print ( cnt )
arr = [ 1 , 5 , 4 , 8 , 7 ]
N = len ( arr )
K = 9
countPairs ( arr , N , K )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def check ( x ) :
    if ( ( ( x ) & ( x - 1 ) ) == 0 ) :
        return 1
    return 0
def query ( l , r , pre ) :
    if ( l == 0 ) :
        return pre [ r ]
    else :
        return pre [ r ] - pre [ l - 1 ]
def countInRange ( arr , N , queries , Q ) :
    pre = [ 0 ] * N
    pre [ 0 ] = check ( arr [ 0 ] )
    for i in range ( 1 , N ) :
        pre [ i ] = pre [ i - 1 ] + check ( arr [ i ] )
    c = 0
    while ( Q > 0 ) :
        l = queries [ 0 ]
        r = queries [ 1 ]
        c += 1
        print ( query ( l , r , pre ) , end = " ▁ " )
        Q -= 1
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 11 , 16 , 8 , 2 , 5 , 1 , 3 , 256 , 1 ]
    N = len ( arr )
    queries = [ [ 0 , 9 ] , [ 4 , 9 ] ]
    Q = len ( queries )
    countInRange ( arr , N , queries , Q )

Index/key variables: i, r
Accumulator variables: Q, c
Iterator variables: i
Python program:
def build_num ( bit , k ) :
    ans = 0 ;
    for i in range ( 32 ) :
        if ( bit [ i ] == k ) :
            ans += ( 1 << i ) ;
    return ans ;
def minimumAND ( arr , n , k ) :
    bit = [ 0 ] * 32 ;
    for i in range ( k ) :
        for j in range ( 32 ) :
            if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) :
                bit [ j ] += 1 ;
    min_and = build_num ( bit , k ) ;
    for i in range ( k , n ) :
        for j in range ( 32 ) :
            if ( ( arr [ i - k ] & ( 1 << j ) ) > 0 ) :
                bit [ j ] -= 1 ;
        for j in range ( 32 ) :
            if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) :
                bit [ j ] += 1 ;
        min_and = min ( build_num ( bit , k ) , min_and ) ;
    return min_and ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , 3 , 6 , 11 , 13 ] ;
    k = 3 ;
    n = len ( arr ) ;
    print ( minimumAND ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def calculate ( bit_cnt ) :
    res = 1 ;
    while ( bit_cnt > 0 ) :
        bit_cnt -= 1 ;
        res = res * 3 ;
    return res ;
def unset_bit_count ( n ) :
    count = 0 ;
    while ( n > 0 ) :
        if ( ( n & 1 ) == 0 ) :
            count += 1 ;
        n = n >> 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    n = 2 ;
    count = unset_bit_count ( n ) ;
    ans = calculate ( count ) ;
    print ( ans ) ;

Accumulator variables: bit_cnt, count
Python program:
def solve ( A , B , n ) :
    cnt = 0 ;
    for i in range ( n ) :
        for j in range ( i , n ) :
            c = A [ i ] & A [ j ]
            if ( bin ( c ) . count ( '1' ) == B [ j ] ) :
                cnt += 1 ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    A = [ 2 , 3 , 1 , 4 , 5 ] ;
    B = [ 2 , 2 , 1 , 4 , 2 ] ;
    size = len ( A ) ;
    print ( solve ( A , B , size ) ) ;

Index/key variables: i, j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
def CalculatePairs ( a , n ) :
    cnt_zero = 0
    cnt_one = 0
    for i in range ( 0 , n ) :
        if ( a [ i ] % 2 == 0 ) :
            cnt_zero += 1
        else :
            cnt_one += 1
    total_XOR_pairs = cnt_zero * cnt_one
    total_AND_pairs = ( cnt_one ) * ( cnt_one - 1 ) / 2
    total_OR_pairs = cnt_zero * cnt_one + ( cnt_one ) * ( cnt_one - 1 ) / 2
    print ( " cntXOR ▁ = ▁ " , int ( total_XOR_pairs ) )
    print ( " cntAND ▁ = ▁ " , int ( total_AND_pairs ) )
    print ( " cntOR ▁ = ▁ " , int ( total_OR_pairs ) )
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 3 , 4 , 2 ]
    n = len ( a )
    CalculatePairs ( a , n )

Index/key variables: i
Accumulator variables: cnt_one, cnt_zero
Iterator variables: i
Python program:
def isSubsetAndZero ( array , length , N ) :
    arrAnd = array [ 0 ]
    for i in range ( 1 , length ) :
        arrAnd = arrAnd & array [ i ]
    if ( ( arrAnd & N ) == 0 ) :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == " _ _ main _ _ " :
    array = [ 1 , 2 , 4 ]
    length = len ( array )
    N = 3
    isSubsetAndZero ( array , length , N )

Index/key variables: i
Iterator variables: i
Python program:
def calculateSum ( n ) :
    sum = 0
    for i in range ( 0 , n ) :
        sum = sum + ( 1 << i )
    return sum
n = 10
print ( " Sum ▁ of ▁ series ▁ " , calculateSum ( n ) )

Iterator variables: i
Python program:
def printCombinations ( a , n , m ) :
    for i in range ( 0 , ( 1 << n ) ) :
        sum = 0
        num = 1 << ( n - 1 )
        for j in range ( 0 , n ) :
            if ( ( i & num ) > 0 ) :
                sum += a [ j ]
            else :
                sum += ( - 1 * a [ j ] )
            num = num >> 1
        if ( sum % m == 0 ) :
            num = 1 << ( n - 1 )
            for j in range ( 0 , n ) :
                if ( ( i & num ) > 0 ) :
                    print ( " + " , a [ j ] , end = " ▁ " , sep = " " )
                else :
                    print ( " - " , a [ j ] , end = " ▁ " , sep = " " )
                num = num >> 1
            print ( " " )
a = [ 3 , 5 , 6 , 8 ]
n = len ( a )
m = 5
printCombinations ( a , n , m )

Index/key variables: j
Accumulator variables: sum
Iterator variables: i, j
Python program:
N = 1000
tree = [ None ] * N
level = [ None ] * N
def constructTree ( low , high , pos , a ) :
    if low == high :
        level [ pos ] , tree [ pos ] = 0 , a [ high ]
        return
    mid = ( low + high ) // 2
    constructTree ( low , mid , 2 * pos + 1 , a )
    constructTree ( mid + 1 , high , 2 * pos + 2 , a )
    level [ pos ] = level [ 2 * pos + 1 ] + 1
    if level [ pos ] & 1 :
        tree [ pos ] = tree [ 2 * pos + 1 ] | tree [ 2 * pos + 2 ]
    else :
        tree [ pos ] = tree [ 2 * pos + 1 ] ^ tree [ 2 * pos + 2 ]
def update ( low , high , pos , index , a ) :
    if low == high and low == index :
        tree [ pos ] = a [ low ]
        return
    if index < low or index > high :
        return
    if low != high :
        mid = ( low + high ) // 2
        update ( low , mid , 2 * pos + 1 , index , a )
        update ( mid + 1 , high , 2 * pos + 2 , index , a )
        if level [ pos ] & 1 :
            tree [ pos ] = tree [ 2 * pos + 1 ] | tree [ 2 * pos + 2 ]
        else :
            tree [ pos ] = tree [ 2 * pos + 1 ] ^ tree [ 2 * pos + 2 ]
def updateValue ( index , value , a , n ) :
    a [ index ] = value
    update ( 0 , n - 1 , 0 , index , a )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 4 , 5 , 6 ]
    n = len ( a )
    constructTree ( 0 , n - 1 , 0 , a )
    index , value = 0 , 2
    updateValue ( index , value , a , n )
    print ( tree [ 0 ] )
    index , value = 3 , 5
    updateValue ( index , value , a , n )
    print ( tree [ 0 ] )

Index/key variables: high, index, low, pos
Python program:
def findUniquePair ( arr , n ) :
    XOR = arr [ 0 ]
    for i in range ( 1 , n ) :
        XOR = XOR ^ arr [ i ]
    set_bit_no = XOR & ~ ( XOR - 1 )
    x = 0
    y = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] & set_bit_no ) :
            x = x ^ arr [ i ]
        else :
            y = y ^ arr [ i ]
    print ( " The ▁ unique ▁ pair ▁ is ▁ ( " , x , " , ▁ " , y , " ) " , sep = " " )
a = [ 6 , 1 , 3 , 5 , 1 , 3 , 7 , 6 ]
n = len ( a )
findUniquePair ( a , n )

Index/key variables: i
Iterator variables: i