dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def maxCount ( arr , N , K ) :
    st = set ( )
    for i in range ( N ) :
        st . add ( arr [ i ] )
    if ( N - len ( st ) <= K ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 2 , 2 , 3 ]
    K = 3
    N = len ( arr )
    maxCount ( arr , N , K )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
def max_sum ( a , v , q , n ) :
    x = 0 ;
    m = - 10 ** 9 ;
    for i in range ( q ) :
        p = v [ i ] [ 0 ] [ 0 ] ;
        q = v [ i ] [ 0 ] [ 1 ] ;
        k = v [ i ] [ 1 ] ;
        a [ p ] += k ;
        if ( q + 1 <= n ) :
            a [ q + 1 ] -= k ;
    for i in range ( 1 , n + 1 ) :
        x += a [ i ] ;
        m = max ( m , x ) ;
    return m ;
n = 10
q = 3 ;
a = [ 0 ] * ( n + 5 ) ;
v = [ [ [ 0 for i in range ( 2 ) ] for x in range ( 2 ) ] for z in range ( q ) ]
v [ 0 ] [ 0 ] [ 0 ] = 1 ;
v [ 0 ] [ 0 ] [ 1 ] = 5 ;
v [ 0 ] [ 1 ] = 3 ;
v [ 1 ] [ 0 ] [ 0 ] = 4 ;
v [ 1 ] [ 0 ] [ 1 ] = 8 ;
v [ 1 ] [ 1 ] = 7 ;
v [ 2 ] [ 0 ] [ 0 ] = 6 ;
v [ 2 ] [ 0 ] [ 1 ] = 9 ;
v [ 2 ] [ 1 ] = 1 ;
print ( max_sum ( a , v , q , n ) ) ;

Index/key variables: i, p
Accumulator variables: x
Iterator variables: i
Python program:
def findWinner ( X , Y ) :
    playerA = ( X ^ Y )
    flag = False
    for i in range ( 1 , X + 1 , 1 ) :
        for j in range ( 1 , Y + 1 , 1 ) :
            val = ( i ^ j )
            if ( val > playerA ) :
                flag = True
                break
        if ( flag ) :
            break
    if ( flag ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    A = 2
    B = 4
    findWinner ( A , B )

Iterator variables: i, j
Boolean variables: flag
Python program:
def prefixFactorialArray ( A , N ) :
    for i in range ( 1 , N ) :
        A [ i ] += A [ i - 1 ]
    fact = [ 0 for x in range ( A [ N - 1 ] + 1 ) ]
    fact [ 0 ] = 1
    for i in range ( 1 , A [ N - 1 ] + 1 ) :
        fact [ i ] = i * fact [ i - 1 ]
    for i in range ( 0 , N ) :
        A [ i ] = fact [ A [ i ] ]
    for i in range ( 0 , N ) :
        print ( A [ i ] , end = " ▁ " )
arr = [ 1 , 2 , 3 , 4 ]
N = len ( arr )
prefixFactorialArray ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def maxFrequency ( arr , N , K ) :
    arr . sort ( )
    start = 0
    end = 0
    sum = 0
    res = 0
    for end in range ( N ) :
        sum += arr [ end ]
        while ( ( end - start + 1 ) * arr [ end ] - sum > K ) :
            sum -= arr [ start ]
            start += 1
        res = max ( res , end - start + 1 )
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 4 , 8 , 13 ]
    N = 4
    K = 5
    maxFrequency ( arr , N , K )

Index/key variables: end, start
Accumulator variables: sum
Iterator variables: end
Python program:
def countPairs ( arr , n , x ) :
    count = 0
    mp = { }
    for i in range ( n ) :
        if ( ( arr [ i ] - x * i ) in mp ) :
            mp [ arr [ i ] - x * i ] += 1
        else :
            mp [ arr [ i ] - x * i ] = 1
    for key , value in mp . items ( ) :
        n = value
        count += ( n * ( n - 1 ) ) // 2
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    n = 6
    x = 3
    arr = [ 5 , 4 , 8 , 11 , 13 , 16 ]
    countPairs ( arr , n , x )

Index/key variables: i
Accumulator variables: count
Iterator variables: i, key, value
Python program:
def recreationalSpot ( arr , N ) :
    if ( N < 3 ) :
        return " No "
    preMin = [ 0 ] * N
    preMin [ 0 ] = arr [ 0 ]
    for i in range ( 1 , N ) :
        preMin [ i ] = min ( preMin [ i - 1 ] , arr [ i ] )
    stack = [ ]
    for j in range ( N - 1 , - 1 , - 1 ) :
        if ( arr [ j ] > preMin [ j ] ) :
            while ( len ( stack ) > 0 and stack [ - 1 ] <= preMin [ j ] ) :
                del stack [ - 1 ]
            if ( len ( stack ) > 0 and stack [ - 1 ] < arr [ j ] ) :
                return " Yes "
            stack . append ( arr [ j ] )
    return " No "
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 7 , 11 , 5 , 13 , 2 ]
    size = len ( arr )
    print ( recreationalSpot ( arr , size ) )

Index/key variables: i, j
Accumulator variables: stack
Iterator variables: i, j
Python program:
def reverseBin ( N ) :
    S = " "
    i = 0
    for i in range ( 32 ) :
        if ( N & ( 1 << i ) ) :
            S += '1'
        else :
            S += '0'
    S = list ( S )
    S = S [ : : - 1 ]
    S = ' ' . join ( S )
    M = 0
    for i in range ( 32 ) :
        if ( S [ i ] == '1' ) :
            M += ( 1 << i )
    return M
def maximumOfTwo ( N ) :
    M = reverseBin ( N )
    return max ( N , M )
if __name__ == ' _ _ main _ _ ' :
    N = 6
    print ( maximumOfTwo ( N ) )

Index/key variables: i
Accumulator variables: M, S
Iterator variables: i
Python program:
from math import sqrt
def complexRoot ( A , B ) :
    ans = [ ]
    X1 = abs ( sqrt ( ( A + sqrt ( A * A + B * B ) ) / 2 ) )
    Y1 = B / ( 2 * X1 )
    ans . append ( [ X1 , Y1 ] )
    X2 = - 1 * X1
    Y2 = B / ( 2 * X2 )
    if ( X2 != 0 ) :
        ans . append ( [ X2 , Y2 ] )
    X3 = ( A - sqrt ( A * A + B * B ) ) / 2
    if ( X3 > 0 ) :
        X3 = abs ( sqrt ( X3 ) )
        Y3 = B / ( 2 * X3 )
        ans . append ( [ X3 , Y3 ] )
        X4 = - 1 * X3
        Y4 = B / ( 2 * X4 )
        if ( X4 != 0 ) :
            ans . append ( [ X4 , Y4 ] )
    print ( " The ▁ Square ▁ roots ▁ are : ▁ " )
    for p in ans :
        print ( round ( p [ 0 ] , 6 ) , end = " " )
        if ( p [ 1 ] > 0 ) :
            print ( " + " , end = " " )
        if ( p [ 1 ] ) :
            print ( str ( round ( p [ 1 ] , 6 ) ) + " * i " )
        else :
            print ( )
if __name__ == ' _ _ main _ _ ' :
    A , B = 0 , 1
    complexRoot ( A , B )

Iterator variables: p
Python program:
def minTime ( A , n , K ) :
    max_ability = A [ 0 ]
    for i in range ( 1 , n ) :
        max_ability = max ( max_ability , A [ i ] )
    tmp = [ 0 for i in range ( max_ability + 1 ) ]
    count = 0
    for i in range ( n ) :
        tmp [ A [ i ] ] += 1
    i = max_ability
    while ( i >= 0 ) :
        if ( tmp [ i ] != 0 ) :
            if ( tmp [ i ] * i < K ) :
                K -= ( i * tmp [ i ] )
                tmp [ i // 2 ] += tmp [ i ]
                count += tmp [ i ]
                if ( K <= 0 ) :
                    return count
            else :
                if ( K % i != 0 ) :
                    count += ( K // i ) + 1
                else :
                    count += ( K // i )
                return count
        i -= 1
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 1 , 7 , 2 , 4 ]
    N = 5
    K = 15
    print ( minTime ( arr , N , K ) )

Index/key variables: i
Accumulator variables: K, count
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def findlcm ( arr , n ) :
    ans = arr [ 0 ]
    for i in range ( n ) :
        ans = ( ( ( arr [ i ] * ans ) ) / ( gcd ( arr [ i ] , ans ) ) )
    return ans
def minimumRod ( A , N ) :
    print ( int ( N * findlcm ( A , N ) ) )
arr = [ 1 , 2 ]
N = len ( arr )
minimumRod ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def findDigit ( N , D ) :
    while ( N > 0 ) :
        a = N % 10
        if ( a == D ) :
            return True
        N /= 10
    return False
def check ( N , D ) :
    while ( N > 0 ) :
        if ( findDigit ( N , D ) == True ) :
            return True
        N -= D
    return False
if __name__ == ' _ _ main _ _ ' :
    N = 24
    D = 7
    if ( check ( N , D ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: N
Python program:
def minOperations ( N ) :
    arr = [ 0 ] * N
    sum = 0
    for i in range ( N ) :
        arr [ i ] = ( 2 * i ) + 1
        sum = sum + arr [ i ]
    mid = 0
    if N % 2 == 0 :
        mid = sum / N
    else :
        mid = arr [ int ( N / 2 ) ]
    ans = 0
    for i in range ( int ( N / 2 ) ) :
        ans += mid - arr [ i ]
    return int ( ans )
N = 6
print ( minOperations ( N ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def findXORS ( arr1 , arr2 , N , M ) :
    res = 0
    for i in range ( N ) :
        for j in range ( M ) :
            temp = arr1 [ i ] & arr2 [ j ]
            res ^= temp
    return res
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 1 , 2 , 3 ]
    arr2 = [ 6 , 5 ]
    N = len ( arr1 )
    M = len ( arr2 )
    print ( findXORS ( arr1 , arr2 , N , M ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Python program:
def findXORS ( arr1 , arr2 , N , M ) :
    XORS1 = 0
    XORS2 = 0
    for i in range ( N ) :
        XORS1 ^= arr1 [ i ]
    for i in range ( M ) :
        XORS2 ^= arr2 [ i ]
    return XORS1 and XORS2
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 1 , 2 , 3 ]
    arr2 = [ 6 , 5 ]
    N = len ( arr1 )
    M = len ( arr2 )
    print ( findXORS ( arr1 , arr2 , N , M ) )

Index/key variables: i
Accumulator variables: XORS1, XORS2
Iterator variables: i
Python program:
def isPowerof2 ( n ) :
    return ( ( n & ( n - 1 ) ) and n )
def countNum ( N ) :
    count = 0
    for i in range ( 1 , N + 1 ) :
        flag = isPowerof2 ( i )
        if ( not flag ) :
            count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    N = 100
    countNum ( N )

Accumulator variables: count
Iterator variables: i
Python program:
import math
def nearestPow ( x , base ) :
    k = int ( math . log ( x , base ) )
    if abs ( base ** k - x ) < abs ( base ** ( k + 1 ) - x ) :
        return base ** k
    else :
        return base ** ( k + 1 )
def replaceWithNearestPowerOfK ( arr , K ) :
    for i in range ( len ( arr ) ) :
        strEle = str ( arr [ i ] )
        for c in strEle :
            if int ( c ) == K :
                arr [ i ] = nearestPow ( arr [ i ] , K )
                break
    print ( arr )
arr = [ 432 , 953 , 232 , 333 ]
K = 3
replaceWithNearestPowerOfK ( arr , K )

Index/key variables: i
Iterator variables: c, i
Python program:
from math import ceil
def ceilDifference ( arr , n , x ) :
    totalSum = 0
    perElementSum = 0
    for i in range ( n ) :
        totalSum += arr [ i ]
        perElementSum += ceil ( arr [ i ] / x )
    totalCeilSum = ceil ( totalSum / x )
    return abs ( perElementSum - totalCeilSum )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    K = 4
    N = len ( arr )
    print ( ceilDifference ( arr , N , K ) )

Index/key variables: i
Accumulator variables: perElementSum, totalSum
Iterator variables: i
Python program:
def countTriplets ( N ) :
    ans = 0
    for i in range ( 1 , N + 1 ) :
        for j in range ( 1 , N + 1 ) :
            if ( i * j > N ) :
                break
            ans += N // ( i * j )
    return ans
if __name__ == " _ _ main _ _ " :
    N = 10
    print ( countTriplets ( N ) )

Accumulator variables: ans
Iterator variables: i, j
Python program:
import math
def countNumbers ( N ) :
    count = 0
    for i in range ( 1 , N + 1 ) :
        if ( math . gcd ( i , N ) != 1 ) :
            count += 1
    print ( count )
if __name__ == " _ _ main _ _ " :
    N = 5
    countNumbers ( N )

Accumulator variables: count
Iterator variables: i
Python program:
def phi ( N ) :
    result = N
    for p in range ( 2 , int ( pow ( N , 1 / 2 ) ) + 1 ) :
        if ( N % p == 0 ) :
            while ( N % p == 0 ) :
                N = N / p
            result -= result // p
    if ( N > 1 ) :
        result -= result // N
    return result
def countNumbers ( N ) :
    count = N - phi ( N )
    print ( count )
N = 5
countNumbers ( N )

Accumulator variables: result
Iterator variables: p
Python program:
def Query ( arr , N , Q ) :
    mul = 1
    add = 0
    for i in range ( len ( Q ) ) :
        if ( Q [ i ] [ 0 ] == 0 ) :
            add = add + Q [ i ] [ 1 ]
        elif ( Q [ i ] [ 0 ] == 1 ) :
            mul = mul * Q [ i ] [ 1 ]
            add = add * Q [ i ] [ 1 ]
        else :
            ans = arr [ Q [ i ] [ 1 ] ] * mul + add
            print ( ans , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 1 , 23 , 45 , 100 ]
    N = len ( arr )
    Q = [ [ 1 , 2 ] , [ 0 , 10 ] , [ 2 , 3 ] , [ 1 , 5 ] , [ 2 , 4 ] ]
    Query ( arr , N , Q )

Index/key variables: i
Iterator variables: i
Python program:
import math
def nthFibo ( n ) :
    a = ( 5 ** ( 1 / 2 ) + 1 ) / 2
    b = ( - 5 ** ( 1 / 2 ) + 1 ) / 2
    r = 5 ** ( 1 / 2 )
    ans = ( a ** n - b ** n ) / r
    return int ( ans )
def nearFibo ( X ) :
    a = ( 5 ** ( 1 / 2 ) + 1 ) / 2
    n = int ( math . log ( ( 5 ** ( 1 / 2 ) ) * X ) / math . log ( a ) )
    nth = nthFibo ( n )
    nplus = nthFibo ( n + 1 )
    if abs ( X - nth ) < abs ( X - nplus ) :
        return nth
    else :
        return nplus
def getCost ( arr ) :
    cost = 0
    for i in arr :
        fibo = nearFibo ( i )
        cost += abs ( i - fibo )
    return cost
arr = [ 56 , 34 , 23 , 98 , 7 ]
print ( getCost ( arr ) )

Accumulator variables: cost
Iterator variables: i
Python program:
def getMaxPairSum ( arr , N , K ) :
    preMax = [ 0 ] * N
    preMax [ 0 ] = arr [ 0 ]
    for i in range ( 1 , N ) :
        preMax [ i ] = max ( preMax [ i - 1 ] , arr [ i ] )
    res = - 10 ** 8
    for i in range ( K , N ) :
        res = max ( res , arr [ i ] + preMax [ i - K ] )
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 8 , 6 , 3 ]
    K = 3
    N = len ( arr )
    print ( getMaxPairSum ( arr , N , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def countPairs ( arr , N ) :
    count = 0
    for i in range ( N - 1 ) :
        for j in range ( i + 1 , N ) :
            if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 1 , 2 ]
    N = len ( arr )
    print ( countPairs ( arr , N ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
from math import sqrt
def CountPairs ( arr , N ) :
    res = 0
    mp = { }
    for i in range ( N ) :
        if ( arr [ i ] in mp ) :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    for key , value in mp . items ( ) :
        x = key
        y = value
        if ( x == 1 ) :
            res += N - 1
            continue
        res += ( y * ( y - 1 ) ) // 2
        for j in range ( 2 , int ( sqrt ( x ) ) + 1 , 1 ) :
            if ( x % j == 0 ) :
                res += mp [ j ]
                if ( j != x // j ) :
                    res += mp [ x // j ]
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 1 , 2 ]
    N = len ( arr )
    print ( CountPairs ( arr , N ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j, key, value
Python program:
def countbits ( n ) :
    count = 0
    while ( n != 0 ) :
        if ( n & 1 ) :
            count += 1
        n = n // 2
    return count
def BitProduct ( arr , N ) :
    product = 1
    for i in range ( N ) :
        bits = countbits ( arr [ i ] )
        product *= bits
    return product
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 4 , 1 , 5 ]
    N = len ( arr )
    print ( BitProduct ( arr , N ) )

Index/key variables: i
Accumulator variables: count, product
Iterator variables: i
Python program:
from math import sqrt
def OddDivisorsSum ( n , q , a , Query ) :
    DP = [ 0 ] * n
    for i in range ( n ) :
        x = sqrt ( a [ i ] )
        if ( x * x == a [ i ] ) :
            DP [ i ] = a [ i ]
    for i in range ( 1 , n ) :
        DP [ i ] = DP [ i - 1 ] + DP [ i ]
    for i in range ( q ) :
        l = Query [ i ] [ 0 ]
        r = Query [ i ] [ 1 ]
        if ( l == 0 ) :
            print ( DP [ r ] , end = " ▁ " )
        else :
            print ( DP [ r ] - DP [ l - 1 ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 5 , 6 , 9 ]
    N = len ( arr )
    Q = 3
    Query = [ [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] ]
    OddDivisorsSum ( N , Q , arr , Query )

Index/key variables: i, r
Iterator variables: i
Python program:
from collections import defaultdict
def findSubset ( arr ) :
    N = len ( arr )
    mp = defaultdict ( int )
    totSum = 0
    s = 0
    flag = 0
    ans = [ ]
    for i in range ( len ( arr ) ) :
        totSum += arr [ i ]
        mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1
    arr . sort ( )
    i = N - 1
    while ( i >= 0 ) :
        frq = mp [ arr [ i ] ]
        if ( ( frq + len ( ans ) ) < ( N - ( frq + len ( ans ) ) ) ) :
            for k in range ( frq ) :
                ans . append ( arr [ i ] )
                totSum -= arr [ i ]
                s += arr [ i ]
                i -= 1
        else :
            i -= frq
        if ( s > totSum ) :
            flag = 1
            break
    if ( flag == 1 ) :
        for i in range ( len ( ans ) - 1 , - 1 , - 1 ) :
            print ( ans [ i ] , end = " ▁ " )
    else :
        print ( - 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 3 , 2 , 4 , 1 , 2 ]
    findSubset ( arr )

Index/key variables: i
Accumulator variables: ans, s, totSum
Iterator variables: i, k
Python program:
def minStepK ( arr , N , K ) :
    E = 0
    S = 0
    for i in range ( N ) :
        S += arr [ i ]
        if ( arr [ i ] % 2 == 0 ) :
            E += 1
    if ( S >= K ) :
        return 0
    elif ( S + E < K ) :
        return - 1
    else :
        return K - S
if __name__ == " _ _ main _ _ " :
    arr = [ 0 , 1 , 1 , 0 , 1 ]
    N = len ( arr )
    K = 4
    print ( minStepK ( arr , N , K ) )

Index/key variables: i
Accumulator variables: E, S
Iterator variables: i
Python program:
def Rotate ( n , f ) :
    temp = n
    maxi = n
    mini = n
    for idx in range ( 7 ) :
        if temp & 1 :
            temp >>= 1
            temp += 2 ** 7
        else :
            temp >>= 1
        mini = min ( mini , temp )
        maxi = max ( maxi , temp )
    if ( f ) :
        return ( maxi )
    else :
        return ( mini )
def calcMinDiff ( arr ) :
    caseOne = 0
    sumOfodd = 0
    sumOfeven = 0
    for i in range ( len ( arr ) ) :
        if i % 2 :
            sumOfodd += Rotate ( arr [ i ] , 0 )
        else :
            sumOfeven += Rotate ( arr [ i ] , 1 )
    caseOne = abs ( sumOfodd - sumOfeven )
    caseTwo = 0
    sumOfodd = 0
    sumOfeven = 0
    for i in range ( len ( arr ) ) :
        if i % 2 :
            sumOfodd += Rotate ( arr [ i ] , 1 )
        else :
            sumOfeven += Rotate ( arr [ i ] , 0 )
    caseTwo = abs ( sumOfodd - sumOfeven )
    return max ( caseOne , caseTwo )
arr = [ 123 , 86 , 234 , 189 ]
print ( calcMinDiff ( arr ) )

Index/key variables: i
Accumulator variables: sumOfeven, sumOfodd, temp
Iterator variables: i, idx
Python program:
def minimumDiff ( arr , N ) :
    res = arr [ 0 ]
    sum1 = 0
    for i in range ( N ) :
        sum1 += arr [ i ]
    min_diff = sum1
    for i in range ( N ) :
        if ( abs ( sum1 - ( arr [ i ] * N ) ) < min_diff ) :
            min_diff = abs ( sum1 - ( arr [ i ] * N ) )
            res = arr [ i ]
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    N = len ( arr )
    minimumDiff ( arr , N )

Index/key variables: i
Accumulator variables: sum1
Iterator variables: i
Python program:
def Sum ( arr , N , K ) :
    sum = 0
    v = [ ]
    for i in range ( N ) :
        v . append ( arr [ i ] )
    flag = False
    i = 0
    lenn = len ( v )
    while ( i < lenn ) :
        if ( flag == False and ( v [ i ] % K == 0 ) ) :
            v . append ( v [ i ] // K )
        else :
            flag = True
        sum += v [ i % N ]
        i += 1
        lenn = len ( v )
    return sum
arr = [ 4 , 6 , 8 , 2 ]
K = 2
N = len ( arr )
print ( Sum ( arr , N , K ) )

Index/key variables: i
Accumulator variables: sum, v
Iterator variables: i
Boolean variables: flag
Python program:
def primeDivisors ( arr , N ) :
    K = arr [ 0 ]
    for i in range ( 1 , N ) :
        K = max ( K , arr [ i ] )
    prime = [ 0 ] * ( K + 1 )
    prime [ 0 ] = 1
    prime [ 1 ] = 1
    for i in range ( 2 , K + 1 ) :
        if ( not prime [ i ] ) :
            for j in range ( 2 * i , K + 1 , i ) :
                prime [ j ] = 1
    factor = [ 0 ] * ( K + 1 )
    factor [ 0 ] = 0
    factor [ 1 ] = 1
    for i in range ( 2 , K + 1 ) :
        factor [ i ] += 1
        for j in range ( i , K + 1 , i ) :
            factor [ j ] += 1
    count = 0
    for i in range ( N ) :
        if ( prime [ factor [ arr [ i ] ] ] == 0 ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 13 , 17 , 25 ]
    N = len ( arr )
    print ( primeDivisors ( arr , N ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def SieveOfEratosthenes ( n , prime ) :
    prime [ 0 ] = 0
    prime [ 1 ] = 0
    p = 2
    while p * p <= n :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , n + 1 , p ) :
                prime [ i ] = False
        p += 1
def countPrime ( n ) :
    prime = [ True ] * ( n + 1 )
    SieveOfEratosthenes ( n , prime )
    dp = [ 0 ] * ( n + 1 )
    dp [ 1 ] = 0
    for i in range ( 2 , n + 1 ) :
        dp [ i ] += dp [ i - 1 ]
        if ( prime [ i ] == 1 and prime [ i - 2 ] == 1 ) :
            dp [ i ] += 1
    print ( dp [ n ] )
if __name__ == " _ _ main _ _ " :
    N = 6
    countPrime ( N )

Index/key variables: i, n, p
Iterator variables: i
Python program:
def findMinSum ( mat , N ) :
    sum1 = 0
    for i in range ( N ) :
        res = 0
        for j in range ( N ) :
            if ( i != j ) :
                res |= mat [ i ] [ j ]
        sum1 += res
    return sum1
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ - 1 , 2 , 3 ] , [ 9 , - 1 , 7 ] , [ 4 , 5 , - 1 ] ]
    N = 3
    print ( findMinSum ( mat , N ) )

Index/key variables: i, j
Accumulator variables: res, sum1
Iterator variables: i, j
Python program:
from collections import defaultdict
def findGCD ( a , b ) :
    if ( b == 0 ) :
        return a
    return findGCD ( b , a % b )
def findLCM ( a , b ) :
    return ( a * b ) // findGCD ( a , b )
def uniqueElementsLCM ( arr , N ) :
    freq = defaultdict ( int )
    for i in range ( N ) :
        freq [ arr [ i ] ] += 1
    lcm = 1
    for i in freq :
        if ( freq [ i ] == 1 ) :
            lcm = findLCM ( lcm , i )
    if ( lcm == 1 ) :
        lcm = - 1
    print ( lcm )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 1 , 3 , 3 , 4 ]
    N = len ( arr )
    uniqueElementsLCM ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def maxAdjacentDifference ( A ) :
    diff = 0
    for i in range ( 1 , len ( A ) , 1 ) :
        diff = max ( diff , A [ i ] - A [ i - 1 ] )
    return diff
def MinimumValue ( arr , N ) :
    MinValue = sys . maxsize
    for i in range ( N ) :
        new_arr = [ ]
        for j in range ( N ) :
            if ( i == j ) :
                continue
            new_arr . append ( arr [ j ] )
        MinValue = min ( MinValue , maxAdjacentDifference ( new_arr ) )
    return MinValue
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 7 , 8 ]
    N = len ( arr )
    print ( MinimumValue ( arr , N ) )

Index/key variables: i, j
Accumulator variables: new_arr
Iterator variables: i, j
Python program:
def countPairs ( arr , N ) :
    even = 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 == 0 ) :
            even += 1
    if ( N - even >= 1 ) :
        print ( even )
        return
    print ( 0 )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 4 , 7 , 2 ]
    N = len ( arr )
    countPairs ( arr , N )

Index/key variables: i
Accumulator variables: even
Iterator variables: i