dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def longestAlternativeSequence ( a , n ) :
    maxi1 = 0
    f1 = 0
    for i in range ( n ) :
        if ( f1 == 0 ) :
            if ( a [ i ] % 2 ) :
                f1 = 1
                maxi1 += 1
        else :
            if ( a [ i ] % 2 == 0 ) :
                maxi1 += 1
                f1 = 0
    maxi2 = 0
    f2 = 0
    for i in range ( n ) :
        if ( f2 ) :
            if ( a [ i ] % 2 ) :
                f2 = 1
                maxi2 += 1
        else :
            if ( a [ i ] % 2 == 0 ) :
                maxi2 += 1
                f2 = 0
    return max ( maxi1 , maxi2 )
a = [ 13 , 16 , 8 , 9 , 32 , 10 ]
n = len ( a )
print ( longestAlternativeSequence ( a , n ) )

Index/key variables: i
Accumulator variables: maxi1, maxi2
Iterator variables: i
Python program:
def nambiarNumber ( Str , i ) :
    if ( i >= len ( Str ) ) :
        return " "
    firstDigit = ord ( Str [ i ] ) - ord ( '0' )
    digitParity = firstDigit % 2
    sumDigits = 0
    while ( i < len ( Str ) ) :
        sumDigits += ( ord ( Str [ i ] ) - ord ( '0' ) )
        sumParity = sumDigits % 2
        if ( digitParity != sumParity ) :
            break
        i += 1
    return ( " " + str ( sumDigits ) + nambiarNumber ( Str , i + 1 ) )
Str = "9880127431"
print ( nambiarNumber ( Str , 0 ) )

Index/key variables: i
Accumulator variables: sumDigits
Python program:
def power ( x , y ) :
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = res * x
    return res
def Fermat ( i ) :
    power2_i = power ( 2 , i )
    power2_2_i = power ( 2 , power2_i )
    return power2_2_i + 1
def Fermat_Number ( n ) :
    for i in range ( n ) :
        print ( Fermat ( i ) , end = " " )
        if ( i != n - 1 ) :
            print ( end = " , ▁ " )
n = 7
Fermat_Number ( n )

Iterator variables: i
Python program:
def phi ( n ) :
    p = 2
    while ( p * p <= n ) :
        if ( n % p == 0 ) :
            while ( n % p == 0 ) :
                n //= p ;
            result -= ( result // p ) ;
        p += 1
    if ( n > 1 ) :
        result -= ( result // n ) ;
    return result ;
def Highly_Totient ( n ) :
    count = 0
    p_count = - 1
    mp = dict ( )
    i = 1
    while i < 100000 :
        tmp = phi ( i )
        if tmp not in mp :
            mp [ tmp ] = 0
        mp [ tmp ] += 1 ;
        i += 1
    i = 1
    while ( count < n ) :
        if ( ( i in mp ) and mp [ i ] > p_count ) :
            print ( i , end = ' ' ) ;
            if ( count < n - 1 ) :
                print ( " , ▁ " , end = ' ' ) ;
            p_count = mp [ i ] ;
            count += 1
        i += 1
if __name__ == ' _ _ main _ _ ' :
    n = 20 ;
    Highly_Totient ( n ) ;

Index/key variables: i, tmp
Accumulator variables: count, n, p, result
Python program:
def Division ( a , n ) :
    maxi = - 10 ** 9
    mini = 10 ** 9
    for i in a :
        maxi = max ( i , maxi )
        mini = min ( i , mini )
    return maxi // mini
a = [ 3 , 7 , 9 , 3 , 11 ]
n = len ( a )
print ( Division ( a , n ) )

Iterator variables: i
Python program:
from math import log , ceil
MAX = 1000000
def addPrimes ( ) :
    n = MAX
    prime = [ True for i in range ( n + 1 ) ]
    for p in range ( 2 , n + 1 ) :
        if p * p > n :
            break
        if ( prime [ p ] == True ) :
            for i in range ( 2 * p , n + 1 , p ) :
                prime [ i ] = False
    ans = [ ]
    for p in range ( 2 , n + 1 ) :
        if ( prime [ p ] ) :
            ans . append ( p )
    return ans
def pi ( x , v ) :
    l , r = 0 , len ( v ) - 1
    m , i = 0 , - 1
    while ( l <= r ) :
        m = ( l + r ) // 2
        if ( v [ m ] <= x ) :
            i = m
            l = m + 1
        else :
            r = m - 1
    return i + 1
def Ramanujan ( n , v ) :
    upperbound = ceil ( 4 * n * ( log ( 4 * n ) / log ( 2 ) ) )
    for i in range ( upperbound , - 1 , - 1 ) :
        if ( pi ( i , v ) - pi ( i / 2 , v ) < n ) :
            return 1 + i
def Ramanujan_Numbers ( n ) :
    c = 1
    v = addPrimes ( )
    for i in range ( 1 , n + 1 ) :
        print ( Ramanujan ( i , v ) , end = " " )
        if ( i != n ) :
            print ( end = " , ▁ " )
n = 10
Ramanujan_Numbers ( n )

Index/key variables: i, m, p
Accumulator variables: ans
Iterator variables: i, p
Python program:
MAX = 130
def validQuadruple ( arr , n ) :
    if ( n >= MAX ) :
        return True
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            for k in range ( j + 1 , n ) :
                for l in range ( k + 1 , n ) :
                    if ( ( arr [ i ] ^ arr [ j ] ^ arr [ k ] ^ arr [ l ] ) == 0 ) :
                        return True
    return False
arr = [ 1 , 0 , 2 , 3 , 7 ]
n = len ( arr )
if ( validQuadruple ( arr , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j, k, l
Iterator variables: i, j, k, l
Python program:
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 , 1 ) :
        res = res * i
    return res
def nCr ( n , r ) :
    return fact ( n ) // ( fact ( r ) * fact ( n - r ) )
def NumberOfWays ( X , Y , M , N ) :
    return fact ( X + Y ) * nCr ( M , X ) * nCr ( N , Y )
if __name__ == ' _ _ main _ _ ' :
    X = 2
    Y = 2
    M = 3
    N = 3
    print ( NumberOfWays ( X , Y , M , N ) )

Iterator variables: i
Python program:
def fact ( n ) :
    i , fac = 1 , 1
    for i in range ( 1 , n + 1 ) :
        fac = fac * i
    return fac
def log_Expansion ( x , n ) :
    Sum = 0
    i = 0
    for i in range ( n ) :
        Sum = Sum + pow ( x , 2 * i ) / fact ( 2 * i )
    return Sum
x = 1
n = 10
print ( log_Expansion ( x , n ) )

Iterator variables: i
Python program:
def prime ( n ) :
    for i in range ( 2 , n ) :
        if i * i > n :
            break
        if ( n % i == 0 ) :
            return False ;
    return True
def prime_range ( start , end , a ) :
    for i in range ( start , end ) :
        if ( prime ( a [ i ] ) ) :
            print ( a [ i ] , end = " ▁ " )
def Print ( arr , n ) :
    print ( " Prime ▁ numbers ▁ in ▁ the " , " first ▁ half ▁ are ▁ " , end = " " )
    prime_range ( 0 , n // 2 , arr )
    print ( )
    print ( " Prime ▁ numbers ▁ in ▁ the " , " second ▁ half ▁ are ▁ " , end = " " )
    prime_range ( n // 2 , n , arr )
    print ( )
arr = [ 2 , 5 , 10 , 15 , 17 , 21 , 23 ]
n = len ( arr )
Print ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def countElements ( arr , n ) :
    Sum = 0
    for i in range ( n ) :
        Sum += arr [ i ]
    mean = Sum / n
    cnt = 0
    for i in range ( n ) :
        newMean = ( Sum - arr [ i ] ) / ( n - 1 )
        if ( newMean == mean ) :
            cnt += 1
    return cnt
arr = [ 1 , 2 , 3 , 4 , 5 ]
n = len ( arr )
print ( countElements ( arr , n ) )

Index/key variables: i
Accumulator variables: Sum, cnt
Iterator variables: i
Python program:
from math import sqrt
def Prime ( n ) :
    for j in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) :
        if ( n % j == 0 ) :
            return False
    return True
def find_prime ( x , xsqmodp , y , ysqmodp ) :
    n = x * x - xsqmodp
    n1 = y * y - ysqmodp
    for j in range ( 2 , max ( int ( sqrt ( n ) ) , int ( sqrt ( n1 ) ) ) , 1 ) :
        if ( n % j == 0 and ( x * x ) % j == xsqmodp and n1 % j == 0 and ( y * y ) % j == ysqmodp ) :
            if ( Prime ( j ) ) :
                return j
        j1 = n // j
        if ( n % j1 == 0 and ( x * x ) % j1 == xsqmodp and n1 % j1 == 0 and ( y * y ) % j1 == ysqmodp ) :
            if ( Prime ( j1 ) ) :
                return j1
        j1 = n1 // j
        if ( n % j1 == 0 and ( x * x ) % j1 == xsqmodp and n1 % j1 == 0 and ( y * y ) % j1 == ysqmodp ) :
            if ( Prime ( j1 ) ) :
                return j1
    if ( n == n1 ) :
        return n
if __name__ == ' _ _ main _ _ ' :
    x = 3
    xsqmodp = 0
    y = 5
    ysqmodp = 1
    print ( find_prime ( x , xsqmodp , y , ysqmodp ) )

Iterator variables: j
Python program:
def FindElement ( a , n ) :
    s = 0
    for i in range ( n ) :
        s = s + a [ i ]
    if s % n == 0 :
        m = s // n
        for j in range ( n ) :
            if a [ j ] == m :
                return m
    return - 1
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 3 , 4 , 5 ]
    n = len ( a )
    print ( FindElement ( a , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def fac ( num ) :
    if ( num == 0 ) :
        return 1 ;
    fact = 1 ;
    for i in range ( 1 , num + 1 ) :
        fact = fact * i ;
    return fact ;
def Tanx_expansion ( terms , x ) :
    sum = 0 ;
    for i in range ( 1 , terms + 1 ) :
        B = 0 ;
        Bn = 2 * i ;
        for k in range ( Bn + 1 ) :
            temp = 0 ;
            for r in range ( 0 , k + 1 ) :
                temp = temp + pow ( - 1 , r ) * fac ( k ) * pow ( r , Bn ) / ( fac ( r ) * fac ( k - r ) ) ;
            B = B + temp / ( ( k + 1 ) ) ;
        sum = sum + pow ( - 4 , i ) * ( 1 - pow ( 4 , i ) ) * B * pow ( x , 2 * i - 1 ) / fac ( 2 * i ) ;
    print ( " % .9f " % ( sum ) ) ;
if __name__ == ' _ _ main _ _ ' :
    n , x = 6 , 1 ;
    Tanx_expansion ( n , x ) ;

Iterator variables: i, k, r
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def minimum_elements ( n , arr ) :
    if ( n < 3 ) :
        return 0
    ans = 0
    diff = arr [ 1 ] - arr [ 0 ]
    g = diff
    for i in range ( 2 , n ) :
        diff = arr [ i ] - arr [ i - 1 ]
        g = gcd ( g , diff )
    for i in range ( 1 , n ) :
        diff = arr [ i ] - arr [ i - 1 ]
        cnt = diff // g
        ans += ( cnt - 1 )
    return ans
arr = [ 1 , 5 , 8 , 10 , 12 , 16 ]
n = len ( arr )
print ( minimum_elements ( n , arr ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
from math import sqrt
def checkcomposite ( n ) :
    for i in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) :
        if ( n % i == 0 ) :
            return 1
    return 0
def power ( x , y , mod ) :
    res = 1
    while ( y ) :
        if ( y & 1 ) :
            res = ( res * x ) % mod
        y = y >> 1
        x = ( x * x ) % mod
    return res
def Check ( n , a ) :
    if ( a > 1 and checkcomposite ( n ) and power ( a , n - 1 , n ) == 1 ) :
        return 1
    return 0
if __name__ == ' _ _ main _ _ ' :
    N = 645
    a = 2
    print ( Check ( N , a ) )

Iterator variables: i
Python program:
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
def Count_number ( N ) :
    return ( N * fact ( N ) )
N = 2
print ( Count_number ( N ) )

Iterator variables: i
Python program:
def ncr ( n , r ) :
    res = 1
    for i in range ( 1 , r + 1 ) :
        res *= ( n - r + i )
        res //= i
    return res
def NoofSequences ( N , M ) :
    prime = { }
    for i in range ( 2 , int ( M ** ( .5 ) ) + 1 ) :
        while ( M % i == 0 ) :
            prime [ i ] = prime . get ( i , 0 ) + 1
            M //= i
    if ( M > 1 ) :
        prime [ M ] = prime . get ( M , 0 ) + 1
    ans = 1
    for it in prime :
        ans *= ( ncr ( N + prime [ it ] - 1 , N - 1 ) )
    return ans
N = 2
M = 6
print ( NoofSequences ( N , M ) )

Index/key variables: M, i, it
Accumulator variables: ans, res
Iterator variables: i, it
Python program:
def ncr ( n , r ) :
    ans = 1
    for i in range ( 1 , r + 1 ) :
        ans *= ( n - r + i )
        ans //= i
    return ans
def NoOfDistributions ( N , R ) :
    return ncr ( N - 1 , R - 1 )
N = 4
R = 3
print ( NoOfDistributions ( N , R ) )

Accumulator variables: ans
Iterator variables: i
Python program:
def ncr ( n , r ) :
    ans = 1
    for i in range ( 1 , r + 1 ) :
        ans *= ( n - r + i )
        ans //= i
    return ans
def NoOfDistributions ( N , R ) :
    return ncr ( N + R - 1 , R - 1 )
N = 4
R = 3
print ( NoOfDistributions ( N , R ) )

Accumulator variables: ans
Iterator variables: i
Python program:
import sys
def checkPerfectcube ( n ) :
    d = int ( n ** ( 1 / 3 ) ) ;
    if ( d * d * d == n ) :
        return True ;
    return False ;
def smallestPerfectCube ( a , n ) :
    mini = sys . maxsize ;
    for i in range ( n ) :
        if ( checkPerfectcube ( a [ i ] ) ) :
            mini = min ( a [ i ] , mini ) ;
    return mini ;
if __name__ == " _ _ main _ _ " :
    a = [ 16 , 8 , 25 , 2 , 3 , 10 ] ;
    n = len ( a ) ;
    print ( smallestPerfectCube ( a , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def CheckSubarray ( arr , N ) :
    presum = [ 0 for i in range ( N + 1 ) ]
    for i in range ( 1 , N + 1 ) :
        presum [ i ] = presum [ i - 1 ] + arr [ i - 1 ]
    for i in range ( 1 , N + 1 ) :
        for j in range ( i , N + 1 ) :
            if ( ( presum [ j ] - presum [ i - 1 ] ) % N == 0 ) :
                print ( i - 1 , j - 1 )
                return
    print ( " - 1" )
arr = [ 7 , 5 , 3 , 7 ]
N = len ( arr )
CheckSubarray ( arr , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def CheckSubarray ( arr , N ) :
    presum = [ 0 for i in range ( N + 1 ) ]
    for i in range ( 1 , N + 1 ) :
        presum [ i ] = presum [ i - 1 ] + arr [ i - 1 ]
    moduloclass = [ [ ] ] * N
    for i in range ( 1 , N + 1 , 1 ) :
        moduloclass [ presum [ i ] % N ] . append ( i - 1 )
    if ( len ( moduloclass [ 0 ] ) > 0 ) :
        print ( 0 + 1 , moduloclass [ 0 ] [ 0 ] + 2 )
        return
    for i in range ( 1 , N ) :
        if ( len ( moduloclass [ i ] ) >= 2 ) :
            print ( moduloclass [ i ] [ 0 ] + 1 , moduloclass [ i ] [ 1 ] )
            return
if __name__ == ' _ _ main _ _ ' :
    arr = [ 7 , 3 , 5 , 2 ]
    N = len ( arr )
    CheckSubarray ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def countBits ( n ) :
    count = 0 ;
    while ( n > 0 ) :
        count += 1 ;
        n >>= 1 ;
    return count ;
def findNearestNumber ( n ) :
    cnt = countBits ( n ) ;
    cnt -= 1 ;
    if ( cnt % 2 ) :
        return 1 << ( cnt + 1 ) ;
    else :
        tempnum = 0 ;
        for i in range ( 0 , cnt + 1 , 2 ) :
            tempnum += 1 << i ;
        if ( tempnum < n ) :
            return ( 1 << ( cnt + 2 ) ) ;
        elif ( tempnum == n ) :
            return n ;
        for i in range ( 0 , cnt + 1 , 2 ) :
            tempnum -= ( 1 << i ) ;
            if ( tempnum < n ) :
                tempnum += ( 1 << i ) ;
                return tempnum ;
n = 19 ;
print ( findNearestNumber ( n ) ) ;

Accumulator variables: count, n, tempnum
Iterator variables: i
Python program:
def constructString ( n ) :
    s = " "
    for i in range ( n ) :
        s += "10"
    return s
def binaryToDecimal ( n ) :
    num = n
    dec_value = 0
    base = 1
    Len = len ( num )
    for i in range ( Len - 1 , - 1 , - 1 ) :
        if ( num [ i ] == '1' ) :
            dec_value += base
        base = base * 2
    return dec_value
def findNumber ( n ) :
    s = constructString ( n - 1 )
    num = binaryToDecimal ( s )
    return num
n = 4
print ( findNumber ( n ) )

Index/key variables: i
Accumulator variables: dec_value, s
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def push ( head_ref , data ) :
    new_node = Node ( data )
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def bitonic_point ( node ) :
    if ( node == None ) :
        return - 1 ;
    if ( node . next == None ) :
        return - 1 ;
    if ( node . data > node . next . data ) :
        return - 1 ;
    while ( node . next != None ) :
        if ( node . data > node . next . data ) :
            break ;
        node = node . next ;
    bitonicPoint = node . data ;
    while ( node . next != None ) :
        if ( node . data < node . next . data ) :
            return - 1 ;
        node = node . next ;
    return bitonicPoint ;
if __name__ == ' _ _ main _ _ ' :
    head = None ;
    head = push ( head , 100 ) ;
    head = push ( head , 201 ) ;
    head = push ( head , 399 ) ;
    head = push ( head , 490 ) ;
    head = push ( head , 377 ) ;
    head = push ( head , 291 ) ;
    head = push ( head , 100 ) ;
    print ( bitonic_point ( head ) )

Class/struct names: Node
Python program:
def MinRemove ( a , n , k ) :
    cnt = [ 0 ] * k
    for i in range ( n ) :
        if ( a [ i ] == 0 ) :
            cnt [ 0 ] += 1 ;
        elif ( cnt [ a [ i ] - 1 ] > 0 ) :
            cnt [ a [ i ] - 1 ] -= 1 ;
            cnt [ a [ i ] ] += 1 ;
    return n - ( k * cnt [ k - 1 ] ) ;
if __name__ == " _ _ main _ _ " :
    a = [ 0 , 1 , 2 , 3 , 4 , 0 , 1 , 0 , 1 , 2 , 3 , 4 ]
    k = 5 ;
    n = len ( a ) ;
    print ( MinRemove ( a , n , k ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
from math import log2 , ceil , floor
def countNodes ( N , X ) :
    height = floor ( log2 ( N ) )
    if ( X > height ) :
        print ( " 0 0 " )
        return
    if ( N == 1 ) :
        print ( " 1 1 " )
        return
    max_total_nodes = ( 1 << ( height + 1 ) ) - 1
    nodes_last_level = ( 1 << height ) - ( max_total_nodes - N )
    from_root = 0
    from_leaf = 0
    if ( X == height ) :
        from_root = nodes_last_level
    else :
        from_root = 1 << X
    left_leaf_nodes = ( ( 1 << height ) - nodes_last_level ) // 2
    if ( X == 0 ) :
        from_leaf = nodes_last_level + left_leaf_nodes
    else :
        i = X
        while ( nodes_last_level > 1 and i > 0 ) :
            nodes_last_level = ceil ( nodes_last_level / 2 )
            i -= 1
        from_leaf = nodes_last_level
        i = X
        while ( left_leaf_nodes > 1 and i > 0 ) :
            left_leaf_nodes = ceil ( left_leaf_nodes / 2 )
            i -= 1
        from_leaf += left_leaf_nodes
    print ( from_root )
    print ( from_leaf )
if __name__ == ' _ _ main _ _ ' :
    N , X = 38 , 3
    countNodes ( N , X )

Accumulator variables: i
Python program:
def sum_of_4_squares ( n ) :
    i , odd , even = 0 , 0 , 0
    for i in range ( 1 , int ( n ** ( .5 ) ) + 1 ) :
        if ( n % i == 0 ) :
            if ( i % 2 == 0 ) :
                even += i
            else :
                odd += i
            if ( ( n // i ) != i ) :
                if ( ( n // i ) % 2 == 0 ) :
                    even += ( n // i )
                else :
                    odd += ( n // i )
    if ( n % 2 == 1 ) :
        return 8 * ( odd + even )
    else :
        return 24 * ( odd )
n = 4
print ( sum_of_4_squares ( n ) )

Accumulator variables: even, odd
Iterator variables: i
Python program:
def mosaic ( n ) :
    i = 0
    ans = 1
    for i in range ( 2 , n + 1 ) :
        if ( n % i == 0 and n > 0 ) :
            count = 0
            while ( n % i == 0 ) :
                n //= i
                count += 1
            ans *= count * i
    return ans
n = 36
print ( mosaic ( n ) )

Accumulator variables: ans, count, n
Iterator variables: i
Python program:
def Total_Ways ( n ) :
    fac = 1 ;
    for i in range ( 2 , n ) :
        fac = fac * i ;
    return ( fac * 2 ) ;
if __name__ == " _ _ main _ _ " :
    n = 5 ;
    print ( Total_Ways ( n ) ) ;

Iterator variables: i
Python program:
def MaxNumbers ( a , n ) :
    fre = [ 0 for i in range ( 3 ) ]
    for i in range ( n ) :
        a [ i ] %= 3
        fre [ a [ i ] ] += 1
    ans = fre [ 0 ]
    k = min ( fre [ 1 ] , fre [ 2 ] )
    ans += k
    fre [ 1 ] -= k
    fre [ 2 ] -= k
    ans += fre [ 1 ] // 3 + fre [ 2 ] // 3
    return ans
a = [ 1 , 4 , 10 , 7 , 11 , 2 , 8 , 5 , 9 ]
n = len ( a )
print ( MaxNumbers ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def countSetBits ( n ) :
    count = 0 ;
    while ( n ) :
        n &= ( n - 1 ) ;
        count += 1
    return count ;
def pairs ( arr , n , k ) :
    count = 0 ;
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            sum = countSetBits ( arr [ i ] ) + countSetBits ( arr [ j ] ) ;
            if ( sum == k ) :
                count += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    k = 4 ;
    print ( pairs ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: count, n
Iterator variables: i, j
Python program:
MAX = 32
def countSetBits ( n ) :
    count = 0 ;
    while ( n ) :
        n &= ( n - 1 ) ;
        count += 1 ;
    return count ;
def pairs ( arr , n , k ) :
    count = 0 ;
    f = [ 0 for i in range ( MAX + 1 ) ]
    for i in range ( n ) :
        f [ countSetBits ( arr [ i ] ) ] += 1 ;
    for i in range ( MAX + 1 ) :
        for j in range ( 1 , MAX + 1 ) :
            if ( i + j == k ) :
                if ( i == j ) :
                    count += ( ( f [ i ] * ( f [ i ] - 1 ) ) / 2 ) ;
                else :
                    count += ( f [ i ] * f [ j ] ) ;
    return count ;
arr = [ 1 , 2 , 3 , 4 , 5 ]
n = len ( arr )
k = 4
print ( pairs ( arr , n , k ) )

Index/key variables: i, j
Accumulator variables: count, n
Iterator variables: i, j
Python program:
import random
def UpperHessenbergMatrix ( n ) :
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if ( j > i + 1 ) :
                print ( '0' , end = " ▁ " )
            else :
                print ( random . randint ( 1 , 10 ) , end = " ▁ " )
        print ( )
n = 4 ;
UpperHessenbergMatrix ( n )

Iterator variables: i, j
Python program:
import random
def UpperHessenbergMatrix ( n ) :
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if ( i > j + 1 ) :
                print ( '0' , end = " ▁ " )
            else :
                print ( random . randint ( 1 , 10 ) , end = " ▁ " )
        print ( )
n = 4 ;
UpperHessenbergMatrix ( n )

Iterator variables: i, j
Python program:
def composite_factors ( n ) :
    count = 0 ;
    a = [ 0 ] * ( n + 1 ) ;
    for i in range ( 1 , n + 1 ) :
        if ( n % i == 0 ) :
            a [ i ] = i ;
    for i in range ( 2 , n + 1 ) :
        j = 2 ;
        p = 1 ;
        while ( j < a [ i ] ) :
            if ( a [ i ] % j == 0 ) :
                p = 0 ;
                break ;
            j += 1 ;
        if ( p == 0 and a [ i ] != 0 ) :
            count += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    n = 100 ;
    print ( composite_factors ( n ) ) ;

Index/key variables: i
Accumulator variables: count, j
Iterator variables: i
Python program:
def isMersenne ( n ) :
    while ( n != 0 ) :
        r = n % 2 ;
        if ( r == 0 ) :
            return False ;
        n //= 2 ;
    return True ;
def sumOfMersenne ( arr , n ) :
    sum = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] > 0 and isMersenne ( arr [ i ] ) ) :
            sum += arr [ i ] ;
    return sum ;
if __name__ == " _ _ main _ _ " :
    arr = [ 17 , 6 , 7 , 63 , 3 ] ;
    n = len ( arr ) ;
    print ( sumOfMersenne ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: n, sum
Iterator variables: i
Python program:
def sumOfFactors ( n ) :
    sum = 0
    for f in range ( 1 , n // 2 + 1 ) :
        if ( n % f == 0 ) :
            sum += f
    return sum
def getSum ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        if ( arr [ i ] > 0 and arr [ i ] == sumOfFactors ( arr [ i ] ) ) :
            sum += arr [ i ]
    return sum
arr = [ 17 , 6 , 10 , 6 , 4 ]
n = len ( arr )
print ( getSum ( arr , n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: f, i
Python program:
cnt_neg = 0 ;
exists_zero = None ;
def preProcess ( arr , n ) :
    global cnt_neg
    for i in range ( n ) :
        if ( arr [ i ] < 0 ) :
            cnt_neg += 1 ;
        if ( arr [ i ] == 0 ) :
            exists_zero = True ;
def isPossible ( k ) :
    if ( not exists_zero ) :
        if ( k >= cnt_neg and ( k - cnt_neg ) % 2 == 0 ) :
            return True ;
        else :
            return False ;
    else :
        if ( k >= cnt_neg ) :
            return True ;
        else :
            return False ;
if __name__ == " _ _ main _ _ " :
    arr = [ - 1 , 2 , - 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    preProcess ( arr , n ) ;
    queries = [ 1 , 2 , 3 , 4 ] ;
    q = len ( queries ) ;
    for i in range ( q ) :
        if ( isPossible ( queries [ i ] ) ) :
            print ( " Yes " ) ;
        else :
            print ( " No " ) ;

Index/key variables: i
Accumulator variables: cnt_neg
Iterator variables: i
Boolean variables: exists_zero