dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def distribute ( N , K , M , arr ) :
    distribution = [ 0 ] * N
    ptr = K - 1
    rem = M
    while ( rem > 0 ) :
        if ( rem >= arr [ ptr ] ) :
            distribution [ ptr ] += arr [ ptr ]
            rem -= arr [ ptr ]
        else :
            distribution [ ptr ] += rem
            rem = 0
        ptr = ( ptr + 1 ) % N
    for i in range ( N ) :
        print ( distribution [ i ] , end = " ▁ " )
arr = [ 2 , 3 , 2 , 1 , 4 ]
M = 11
S = 2
N = len ( arr )
distribute ( N , S , M , arr )

Index/key variables: i, ptr
Accumulator variables: rem
Iterator variables: i
Python program:
def sumOfSquaredDifferences ( arr , N ) :
    ans = 0
    sumA , sumB = 0 , 0
    for i in range ( N ) :
        sumA += ( arr [ i ] * arr [ i ] )
        sumB += arr [ i ]
    sumA = N * sumA
    sumB = ( sumB * sumB )
    ans = sumA - sumB
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 8 , 4 ]
    N = len ( arr )
    sumOfSquaredDifferences ( arr , N )

Index/key variables: i
Accumulator variables: sumA, sumB
Iterator variables: i
Python program:
def waysToRemove ( n , m ) :
    ans = 0
    if ( m == 1 ) :
        print ( n )
        return
    d = 0
    while d >= 0 :
        length = m + ( m - 1 ) * d
        if ( length > n ) :
            break
        ans += ( n - length ) + 1
        d += 1
    print ( ans )
if __name__ == " _ _ main _ _ " :
    N = 5
    M = 3
    waysToRemove ( N , M )

Accumulator variables: ans, d
Python program:
from collections import deque
def countStairs ( n , x , a , b ) :
    vis = [ 0 ] * ( n + 1 )
    moves = [ + a , - a , + b , - b ]
    q = deque ( )
    q . append ( x )
    vis [ x ] = 1
    while ( len ( q ) > 0 ) :
        currentStair = q . popleft ( )
        for j in range ( 4 ) :
            newStair = currentStair + moves [ j ]
            if ( newStair > 0 and newStair <= n and ( not vis [ newStair ] ) ) :
                q . append ( newStair )
                vis [ newStair ] = 1
    cnt = 0
    for i in range ( 1 , n + 1 ) :
        if ( vis [ i ] == 1 ) :
            cnt += 1
    print ( cnt )
if __name__ == ' _ _ main _ _ ' :
    N , S , A , B = 10 , 2 , 5 , 7
    countStairs ( N , S , A , B )

Index/key variables: i, j, newStair, x
Accumulator variables: cnt, q
Iterator variables: i, j
Python program:
def smallerNumbers ( arr , N ) :
    for i in range ( N ) :
        count = 0
        for j in range ( N ) :
            if ( arr [ j ] < arr [ i ] ) :
                count += 1
        print ( count , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 4 , 1 , 1 , 2 ]
    N = len ( arr )
    smallerNumbers ( arr , N )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def minimumOperations ( X , Y ) :
    GCD = gcd ( X , Y )
    X = X // GCD
    Y = Y // GCD
    count = 0
    while ( X != Y ) :
        if ( Y > X ) :
            X , Y = Y , X
        if ( X % 2 == 0 ) :
            X = X // 2
        elif ( X % 3 == 0 ) :
            X = X // 3
        elif ( X % 5 == 0 ) :
            X = X // 5
        else :
            print ( " - 1" )
            return
        count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    X , Y = 15 , 20
    minimumOperations ( X , Y )

Accumulator variables: count
Python program:
def minOperations ( a , n ) :
    ans = 0
    for i in range ( n ) :
        ans += a [ i ]
    ans -= n
    x = 1
    while ( 1 ) :
        curPow = 1
        curCost = 0
        for i in range ( n ) :
            curCost += abs ( a [ i ] - curPow )
            curPow *= x
        if ( curPow / x > ans + a [ n - 1 ] ) :
            break
        ans = min ( ans , curCost )
        x += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 5 , 7 ]
    N = len ( arr )
    print ( minOperations ( arr , N ) )

Index/key variables: i
Accumulator variables: ans, curCost, curPow, x
Iterator variables: i
Python program:
import math
def printArray ( arr , N ) :
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " )
def nearestPowerDiff ( arr , N , a , b ) :
    for i in range ( N ) :
        log_a = int ( math . log ( arr [ i ] ) / math . log ( a ) )
        A = int ( pow ( a , log_a ) )
        B = int ( pow ( a , log_a + 1 ) )
        if ( ( arr [ i ] - A ) < ( B - arr [ i ] ) ) :
            log_a = A
        else :
            log_a = B
        log_b = int ( math . log ( arr [ i ] ) / math . log ( b ) )
        A = int ( pow ( b , log_b ) )
        B = int ( pow ( b , log_b + 1 ) )
        if ( ( arr [ i ] - A ) < ( B - arr [ i ] ) ) :
            log_b = A
        else :
            log_b = B
        arr [ i ] = abs ( log_a - log_b )
    printArray ( arr , N )
arr = [ 5 , 12 , 25 ]
A = 2
B = 3
N = len ( arr )
nearestPowerDiff ( arr , N , A , B )

Index/key variables: i
Iterator variables: i
Python program:
def bitOr ( arr , N ) :
    count = 0
    length = 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 == 0 ) :
            length += 1
        else :
            if ( length != 0 ) :
                count += ( ( length ) * ( length + 1 ) ) // 2
            length = 0
    count += ( ( length ) * ( length + 1 ) ) // 2
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 5 , 4 , 2 , 6 ]
    N = len ( arr )
    print ( bitOr ( arr , N ) )

Index/key variables: i
Accumulator variables: count, length
Iterator variables: i
Python program:
def ValidPairs ( X , K ) :
    count = 0
    for A in range ( - 1000 , 1001 , 1 ) :
        for B in range ( - 1000 , 1001 , 1 ) :
            if ( pow ( A , K ) - pow ( B , K ) == X ) :
                count += 1
                print ( A , B )
    if ( count == 0 ) :
        cout << " - 1"
X = 33
K = 5
ValidPairs ( X , K )

Accumulator variables: count
Iterator variables: A, B
Python program:
def maximumAND ( arr , n , m ) :
    tot = 1 << n
    mx = 0
    for bm in range ( tot ) :
        andans = 0
        count = 0
        for i in range ( n ) :
            if ( ( bm >> i ) & 1 ) :
                if ( count == 0 ) :
                    andans = arr [ i ]
                else :
                    andans = andans & arr [ i ]
                count += 1
        if ( count == ( m + 1 ) ) :
            mx = max ( mx , andans )
    return mx
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ]
    N = len ( arr )
    M = 2
    print ( maximumAND ( arr , N , M ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: bm, i
Python program:
def findTotalSum ( ops ) :
    if ( len ( ops ) == 0 ) :
        print ( 0 )
        return
    pts = [ ]
    ans = 0
    for i in range ( len ( ops ) ) :
        if ( ops [ i ] == " C " ) :
            ans -= pts [ - 1 ]
            pts . pop ( )
        elif ( ops [ i ] == " D " ) :
            pts . append ( pts [ - 1 ] * 2 )
            ans += pts [ - 1 ]
        elif ( ops [ i ] == " + " ) :
            a = pts [ - 1 ]
            pts . pop ( )
            b = pts [ - 1 ]
            pts . append ( a )
            ans += ( a + b )
            pts . append ( a + b )
        else :
            n = int ( ops [ i ] )
            ans += n
            pts . append ( n )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    arr = [ "5" , " - 2" , " C " , " D " , " + " ]
    findTotalSum ( arr )

Index/key variables: i
Accumulator variables: ans, pts
Iterator variables: i
Python program:
def findXOR ( mat , N ) :
    XOR = 0
    for i in range ( N ) :
        for j in range ( N ) :
            for k in range ( N ) :
                if ( ( i == j and j == k ) ) :
                    XOR ^= mat [ i ] [ j ] [ k ]
                    XOR ^= mat [ i ] [ j ] [ N - k - 1 ]
    print ( XOR )
mat = [ [ [ 1 , 2 ] , [ 3 , 4 ] ] , [ [ 5 , 6 ] , [ 7 , 8 ] ] ]
N = len ( mat )
findXOR ( mat , N )

Index/key variables: i, j, k
Accumulator variables: XOR
Iterator variables: i, j, k
Python program:
def findXOR ( mat , N ) :
    XOR = 0
    for i in range ( N ) :
        XOR ^= mat [ i ] [ i ] [ i ]
        XOR ^= mat [ i ] [ i ] [ N - i - 1 ]
    print ( XOR )
mat = [ [ [ 1 , 2 ] , [ 3 , 4 ] ] , [ [ 5 , 6 ] , [ 7 , 8 ] ] ]
N = len ( mat )
findXOR ( mat , N )

Index/key variables: i
Accumulator variables: XOR
Iterator variables: i
Python program:
MAX = 300004
graph = [ [ ] for i in range ( MAX ) ]
mod = 10 ** 9 + 7
ans = 0
def countSubtreesUtil ( cur , par ) :
    global mod , ans
    res = 1
    for i in range ( len ( graph [ cur ] ) ) :
        v = graph [ cur ] [ i ]
        if ( v == par ) :
            continue
        res = ( res * ( countSubtreesUtil ( v , cur ) + 1 ) ) % mod
    ans = ( ans + res ) % mod
    return res
def countSubtrees ( N , adj ) :
    for i in range ( N - 1 ) :
        a = adj [ i ] [ 0 ]
        b = adj [ i ] [ 1 ]
        graph [ a ] . append ( b )
        graph [ b ] . append ( a )
    countSubtreesUtil ( 1 , 1 )
    print ( ans + 1 )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    adj = [ [ 0 , 1 ] , [ 1 , 2 ] ]
    countSubtrees ( N , adj )

Index/key variables: a, b, cur, i
Iterator variables: i
Python program:
def checkWinner ( arr , N ) :
    diff = 0
    for i in range ( N ) :
        diff -= arr [ i ]
    if ( diff % 2 == 0 ) :
        print ( " A " )
    else :
        print ( " B " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 ]
    N = len ( arr )
    checkWinner ( arr , N )

Index/key variables: i
Accumulator variables: diff
Iterator variables: i
Python program:
from math import sqrt
def constructArray ( N ) :
    ans = [ ]
    for i in range ( 1 , int ( sqrt ( N ) ) + 1 , 1 ) :
        if ( N % i == 0 ) :
            ans . append ( i )
            if ( N != ( i * i ) ) :
                ans . append ( N / i )
    for it in ans :
        print ( int ( it ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 12
    constructArray ( N )

Accumulator variables: ans
Iterator variables: i, it
Python program:
MOD = 998244353
def findConvolution ( a , b ) :
    global MOD
    n , m = len ( a ) , len ( b )
    c = [ 0 ] * ( n + m - 1 )
    for i in range ( n ) :
        for j in range ( m ) :
            c [ i + j ] += ( a [ i ] * b [ j ] ) % MOD
    for k in range ( len ( c ) ) :
        c [ k ] %= MOD
        print ( c [ k ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 4 ]
    B = [ 5 , 6 , 7 , 8 , 9 ]
    findConvolution ( A , B )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
P = 51
def count1s ( start_i , start_j , end_i , end_j , mat ) :
    count = 0
    for x in range ( start_i , end_i ) :
        for y in range ( start_j , end_j ) :
            if ( mat [ x ] [ y ] == 1 ) :
                count += 1
    return count
def findMinimumCount ( N , M , A , B , mat ) :
    minimum = 1e9
    for i in range ( N ) :
        for j in range ( M ) :
            if ( i + A <= N and j + B <= M ) :
                count = count1s ( i , j , i + A , j + B , mat )
                minimum = min ( count , minimum )
            if ( i + B <= N and j + A <= M ) :
                count = count1s ( i , j , i + B , j + A , mat )
                minimum = min ( count , minimum )
    return minimum
if __name__ == " _ _ main _ _ " :
    A = 2
    B = 2
    N = 3
    M = 4
    mat = [ [ 1 , 0 , 1 , 0 ] , [ 0 , 1 , 0 , 1 ] , [ 1 , 0 , 1 , 0 ] ]
    print ( findMinimumCount ( N , M , A , B , mat ) )

Index/key variables: x, y
Accumulator variables: count
Iterator variables: i, j, x, y
Python program:
def checkEvenPower ( n ) :
    x = 0
    while ( x < n ) :
        value = pow ( 2 , x )
        if ( value == n ) :
            if ( x % 2 == 0 ) :
                return True
            else :
                return False
        x += 1
    return False
if __name__ == ' _ _ main _ _ ' :
    N = 4
    if checkEvenPower ( N ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: x
Python program:
def findSum ( N , K ) :
    ans = 0
    i = 1
    while ( i <= N ) :
        ans += N // i
        i = i * K
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    N , K = 10 , 2
    findSum ( N , K )

Accumulator variables: ans
Python program:
def countAPs ( S , D ) :
    S = S * 2
    answer = 0
    for i in range ( 1 , S ) :
        if i * i > S :
            break
        if ( S % i == 0 ) :
            if ( ( ( S // i ) - D * i + D ) % 2 == 0 ) :
                answer += 1
            if ( ( D * i - ( S // i ) + D ) % 2 == 0 ) :
                answer += 1
    return answer
if __name__ == ' _ _ main _ _ ' :
    S , D = 12 , 1
    print ( countAPs ( S , D ) ) ;

Accumulator variables: answer
Iterator variables: i
Python program:
def minimumInsertions ( arr , N , K ) :
    possible = 1
    res = 0
    last = 0
    for i in range ( N ) :
        if ( arr [ i ] >= K ) :
            possible = 0
            break
        if ( last + arr [ i ] > K ) :
            res += 1
        last = arr [ i ]
    if ( possible ) :
        print ( res )
    else :
        print ( " - 1" )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    K = 6
    N = len ( arr )
    minimumInsertions ( arr , N , K )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def distinct ( arr , n ) :
    mpp = { }
    for i in range ( n ) :
        mpp [ arr [ i ] ] = 1
    return len ( mpp )
def maxSubSum ( arr , n , k , totalDistinct ) :
    if ( k > n ) :
        return 0
    maxm = 0
    sum = 0
    for i in range ( n - k + 1 ) :
        sum = 0
        st = set ( )
        for j in range ( i , i + k , 1 ) :
            sum += arr [ j ]
            st . add ( arr [ j ] )
        if ( len ( st ) == totalDistinct ) :
            maxm = max ( sum , maxm )
    return maxm
if __name__ == ' _ _ main _ _ ' :
    arr = [ 7 , 7 , 2 , 4 , 2 , 7 , 4 , 6 , 6 , 6 ]
    K = 6
    N = len ( arr )
    totalDistinct = distinct ( arr , N )
    print ( maxSubSum ( arr , N , K , totalDistinct ) )

Index/key variables: i, j
Accumulator variables: st, sum
Iterator variables: i, j
Python program:
def distinct ( arr , N ) :
    st = set ( )
    for i in range ( N ) :
        st . add ( arr [ i ] )
    return len ( st )
def maxSubarraySumUtil ( arr , N , K , totalDistinct ) :
    if ( K > N ) :
        return 0
    mx = 0
    sum = 0
    mp = { }
    for i in range ( N ) :
        if ( arr [ i ] in mp ) :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
        sum += arr [ i ]
        if ( i >= K ) :
            if ( arr [ i - K ] in mp ) :
                mp [ arr [ i - K ] ] -= 1
                sum -= arr [ i - K ]
            if ( arr [ i - K ] in mp and mp [ arr [ i - K ] ] == 0 ) :
                mp . remove ( arr [ i - K ] )
        if ( len ( mp ) == totalDistinct ) :
            mx = max ( mx , sum )
    return mx
def maxSubarraySum ( arr , K ) :
    N = len ( arr )
    totalDistinct = distinct ( arr , N )
    print ( maxSubarraySumUtil ( arr , N , K , totalDistinct ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 7 , 7 , 2 , 4 , 2 , 7 , 4 , 6 , 6 , 6 ]
    K = 6
    maxSubarraySum ( arr , K )

Index/key variables: i
Accumulator variables: st, sum
Iterator variables: i
Python program:
def countAPs ( N ) :
    count = 0
    i = 1
    while ( i * i <= 2 * N ) :
        res = 2 * N
        if ( res % i == 0 ) :
            op = res / i - i + 1
            if ( op % 2 == 0 ) :
                count += 1
            if ( i * i != res and ( i - res / i + 1 ) % 2 == 0 ) :
                count += 1
        i += 1
    print ( count - 1 )
N = 963761198400
countAPs ( N )

Accumulator variables: count, i
Python program:
sieve = [ 0 for i in range ( 105 ) ]
def buildSieve ( ) :
    global sieve
    for i in range ( 2 , 100 ) :
        sieve [ i ] = 1
    for i in range ( 2 , 100 ) :
        if ( sieve [ i ] == 1 ) :
            for j in range ( i * i , 100 , i ) :
                sieve [ j ] = 0
def isAnyPrime ( first , last ) :
    global sieve
    num1 = first * 10 + last
    num2 = last * 10 + first
    if ( sieve [ num1 ] == 1 or sieve [ num2 ] == 1 ) :
        return True
    else :
        return False
def performQueries ( q ) :
    for i in range ( len ( q ) ) :
        A = q [ i ]
        last = A % 10
        first = 0
        while ( A >= 10 ) :
            A = A // 10
        first = A
        if ( isAnyPrime ( first , last ) ) :
            print ( " True " )
        else :
            print ( " False " )
if __name__ == ' _ _ main _ _ ' :
    q = [ 30 , 66 ]
    buildSieve ( )
    performQueries ( q )

Index/key variables: i, j, num1, num2
Iterator variables: i, j
Python program:
def oddDivisor ( N ) :
    X = N
    while ( N % 2 == 0 ) :
        N //= 2
    i = 3
    while ( i * i <= X ) :
        if ( N % i == 0 ) :
            return " Yes "
        i += 2
    if ( N != X ) :
        return " Yes "
    return " No "
N = 10
print ( oddDivisor ( N ) )

Accumulator variables: N, i
Python program:
primes = [ 0 ] * ( 1000006 )
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    else :
        return gcd ( b , a % b )
def preprocess ( ) :
    for i in range ( 1 , 1000001 ) :
        primes [ i ] = i
    i = 2
    while ( i * i <= 1000000 ) :
        if ( primes [ i ] == i ) :
            for j in range ( 2 * i , 1000001 , i ) :
                if ( primes [ j ] == j ) :
                    primes [ j ] = i
        i += 1
def Steps ( x , m ) :
    steps = 0
    flag = False
    while ( x > 1 ) :
        if ( primes [ x ] > m ) :
            flag = True
            break
        x //= primes [ x ]
        steps += 1
    if ( flag != 0 ) :
        return - 1
    return steps
def minimumSteps ( x , y , m ) :
    preprocess ( )
    g = gcd ( x , y )
    x = x // g
    y = y // g
    x_steps = Steps ( x , m )
    y_steps = Steps ( y , m )
    if ( x_steps == - 1 or y_steps == - 1 ) :
        return - 1
    return x_steps + y_steps
X = 160
Y = 180
M = 10
print ( minimumSteps ( X , Y , M ) )

Index/key variables: i, j, x
Accumulator variables: steps
Iterator variables: i, j
Boolean variables: flag
Python program:
import math
def isNonDeficient ( n ) :
    sum = 0
    for i in range ( 1 , int ( math . sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            if ( n // i == i ) :
                sum = sum + i
            else :
                sum = sum + i
                sum = sum + ( n // i )
    return sum >= 2 * n
def LongestNonDeficientSubsequence ( arr , n ) :
    res = 0
    for i in range ( n ) :
        if ( isNonDeficient ( arr [ i ] ) ) :
            res += 1
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 13 , 55 , 240 , 32 , 24 , 27 , 56 , 80 , 100 , 330 , 89 ]
    N = len ( arr )
    print ( LongestNonDeficientSubsequence ( arr , N ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def isPronic ( n ) :
    for i in range ( int ( n ** ( 1 / 2 ) ) + 1 ) :
        if i * ( i + 1 ) == n :
            return True
    return False
def countSub ( arr ) :
    ans = 0
    ispro = 0
    for i in arr :
        if isPronic ( i ) :
            ispro += 1
        else :
            ispro = 0
        ans += ispro
    return ans
arr = [ 5 , 6 , 12 , 3 , 4 ]
print ( countSub ( arr ) )

Accumulator variables: ans, ispro
Iterator variables: i
Python program:
import math
def LOG ( x , base ) :
    return int ( math . log ( x ) / math . log ( base ) )
def repbyNP ( arr ) :
    x = arr [ - 1 ]
    for i in range ( len ( arr ) ) :
        k = LOG ( arr [ i ] , x )
        temp = arr [ i ]
        if abs ( x ** k - arr [ i ] ) < abs ( x ** ( k + 1 ) - arr [ i ] ) :
            arr [ i ] = x ** k
        else :
            arr [ i ] = x ** ( k + 1 )
        x = temp
    return arr
arr = [ 2 , 4 , 6 , 3 , 11 ]
print ( repbyNP ( arr ) )

Index/key variables: i
Iterator variables: i
Python program:
def lastElement ( arr , n ) :
    sum = 0
    if n % 2 == 0 :
        multiplier = - 1
    else :
        multiplier = 1
    for i in range ( n ) :
        sum += arr [ i ] * multiplier
        multiplier = multiplier * ( n - 1 - i ) / ( i + 1 ) * ( - 1 )
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 4 , 2 , 1 ]
    N = len ( arr )
    print ( int ( lastElement ( arr , N ) ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def countPairs ( arr , N ) :
    odd = 0
    for i in range ( N ) :
        if ( arr [ i ] & 1 ) :
            odd += 1
    ans = ( N - odd + odd // 2 - 1 ) + odd // 2
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 6 , 1 , 3 ]
    N = len ( arr )
    print ( countPairs ( arr , N ) )

Index/key variables: i
Accumulator variables: odd
Iterator variables: i
Python program:
from math import log2
def countPairs ( arr , N ) :
    freq = { }
    for i in range ( N ) :
        x = int ( log2 ( arr [ i ] ) )
        freq [ x ] = freq . get ( x , 0 ) + 1
    pairs = 0
    for i in freq :
        pairs += freq [ i ] - 1
    return pairs
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 9 , 15 , 7 ]
    N = len ( arr )
    print ( countPairs ( arr , N ) )

Index/key variables: i, x
Accumulator variables: pairs
Iterator variables: i
Python program:
import math
def countBit ( n ) :
    return int ( math . log ( n , 2 ) ) + 1
def countSetBit ( n ) :
    ans = 0
    while n :
        ans += n & 1
        n >>= 1
    return ans
def maximize ( n ) :
    bits = countBit ( n )
    setBits = countSetBit ( n )
    ans = 0
    for i in range ( bits ) :
        if i < setBits :
            ans |= 1
        if i != setBits - 1 :
            ans <<= 1
    return ans
def minimize ( n ) :
    setBits = countSetBit ( n )
    ans = 0
    for i in range ( setBits ) :
        ans |= 1
        if i != setBits - 1 :
            ans <<= 1
    return ans
def maxDiff ( arr ) :
    caseOne = 0
    SumOfOdd = 0
    SumOfeven = 0
    for i in range ( len ( arr ) ) :
        if i % 2 :
            SumOfOdd += minimize ( arr [ i ] )
        else :
            SumOfeven += maximize ( arr [ i ] )
    caseOne = abs ( SumOfOdd - SumOfeven )
    caseTwo = 0
    SumOfOdd = 0
    SumOfeven = 0
    for i in range ( len ( arr ) ) :
        if i % 2 :
            SumOfOdd += maximize ( arr [ i ] )
        else :
            SumOfeven += minimize ( arr [ i ] )
    caseTwo = abs ( SumOfOdd - SumOfeven )
    return max ( caseOne , caseTwo )
arr = [ 54 , 32 , 11 , 23 ]
print ( maxDiff ( arr ) )

Index/key variables: i
Accumulator variables: SumOfOdd, SumOfeven, ans, n
Iterator variables: i
Python program:
def minimumDifference ( N ) :
    sum1 = ( 1 << N )
    sum2 = 0
    for i in range ( 1 , N // 2 ) :
        sum1 += ( 1 << i )
    for i in range ( N // 2 , N ) :
        sum2 += ( 1 << i )
    print ( sum1 - sum2 )
N = 4
minimumDifference ( N )

Accumulator variables: sum1, sum2
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( a == 0 ) :
        return b
    return gcd ( b % a , a )
def printAllDivisors ( arr , N ) :
    g = arr [ 0 ]
    divisors = dict ( )
    for i in range ( 1 , N ) :
        g = gcd ( arr [ i ] , g )
    for i in range ( 1 , g + 1 ) :
        if i * i > g :
            break
        if ( g % i == 0 ) :
            divisors [ i ] = 1
            if ( g // i != i ) :
                divisors [ g // i ] = 1
    for it in sorted ( divisors ) :
        print ( it , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 6 , 90 , 12 , 18 , 30 , 24 ]
    n = len ( arr )
    printAllDivisors ( arr , n )

Index/key variables: i
Iterator variables: i, it
Python program:
import math
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False ;
    for i in range ( 2 , n ) :
        if ( n % i == 0 ) :
            return False ;
    return True ;
def getSmallestPrimefactor ( n ) :
    for i in range ( 2 , ( int ) ( math . sqrt ( n ) + 1 ) ) :
        if ( n % i == 0 ) :
            return i ;
    return - 1
N = 100 ;
a = getSmallestPrimefactor ( N ) ;
if ( ( isPrime ( ( int ) ( N / a ) ) ) ) :
    print ( - 1 )
else :
    print ( ( int ) ( N / a ) ) ;

Iterator variables: i