dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from queue import Queue
adj = [ [ 0 ] * 100000 ] * 100000
setNum = [ 0 ] * 100000
def addEdge ( a1 , a2 ) :
    adj [ a1 ] . append ( a2 ) ;
    adj [ a2 ] . append ( a1 ) ;
def toBipartite ( N ) :
    for i in range ( 0 , N ) :
        setNum [ i ] = - 1
    q = Queue ( ) ;
    q . put ( 0 ) ;
    setNum [ 0 ] = 0 ;
    while ( not q . empty ( ) ) :
        v = q . queue [ 0 ] ;
        q . get ( ) ;
        for u in adj [ v ] :
            if ( setNum [ u ] == - 1 ) :
                setNum [ u ] = setNum [ v ] ^ 1 ;
                q . put ( u ) ;
def pathLengthQuery ( A , B ) :
    if ( setNum [ A ] == setNum [ B ] ) :
        print ( " Odd " ) ;
    else :
        print ( " Even " ) ;
N = 7 ;
addEdge ( 0 , 1 ) ;
addEdge ( 0 , 2 ) ;
addEdge ( 1 , 3 ) ;
addEdge ( 3 , 4 ) ;
addEdge ( 3 , 5 ) ;
addEdge ( 2 , 6 ) ;
toBipartite ( N ) ;
pathLengthQuery ( 4 , 2 ) ;
pathLengthQuery ( 0 , 4 ) ;

Index/key variables: A, B, a1, a2, i, u, v
Iterator variables: i, u
Python program:
import math
def highestPowerof2 ( n ) :
    p = int ( math . log ( n , 2 ) )
    if p % 2 == 0 :
        p -= 1
    return int ( pow ( 2 , p ) )
def minStep ( N , X ) :
    if N % 2 and X == 0 :
        return - 1
    size = 0
    while X < N :
        N -= highestPowerof2 ( N )
        size += 1
    if N :
        size += 1
    return size
if __name__ == ' _ _ main _ _ ' :
    N = 11
    X = 2
    print ( minStep ( N , X ) )

Accumulator variables: N, size
Python program:
def findMaxK ( N ) :
    K = N
    i = N - 1
    while ( i >= 0 ) :
        K &= i
        if ( K == 0 ) :
            return i
        i -= 1
    return 0
if __name__ == ' _ _ main _ _ ' :
    N = 5
    print ( findMaxK ( N ) )

Accumulator variables: K, i
Python program:
def countPairs ( arr , n ) :
    count = 0
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            if ( ( arr [ j ] % arr [ i ] == 0 ) and ( j + 1 ) % ( i + 1 ) == 0 and ( arr [ j ] // arr [ i ] == ( j + 1 ) // ( i + 1 ) ) ) :
                count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , - 2 , 4 , 20 , 25 , - 6 ]
    n = len ( arr )
    print ( countPairs ( arr , n ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def countPairs ( arr , n ) :
    count = 0
    for x in range ( 1 , n + 1 , 1 ) :
        for y in range ( 2 * x , n + 1 , x ) :
            if ( ( arr [ y - 1 ] % arr [ x - 1 ] == 0 ) and ( arr [ y - 1 ] // arr [ x - 1 ] == y // x ) ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , - 2 , 4 , 20 , 25 , - 6 ]
    n = len ( arr )
    print ( countPairs ( arr , n ) )

Accumulator variables: count
Iterator variables: x, y
Python program:
def countMinDistance ( n , m , edges ) :
    g = [ [ ] for i in range ( 10005 ) ]
    for i in range ( m ) :
        a = edges [ i ] [ 0 ] - 1
        b = edges [ i ] [ 1 ] - 1
        g [ a ] . append ( b )
        g [ b ] . append ( a )
    queue1 = [ ]
    queue1 . append ( [ 0 , 0 ] )
    dist = [ 1e9 for i in range ( n ) ]
    ways1 = [ 0 for i in range ( n ) ]
    dist [ 0 ] = 0
    ways1 [ 0 ] = 1
    while ( len ( queue1 ) > 0 ) :
        up = queue1 [ 0 ]
        queue1 = queue1 [ : - 1 ]
        x = up [ 0 ]
        dis = up [ 1 ]
        if ( dis > dist [ x ] ) :
            continue
        if ( x == n - 1 ) :
            continue
        for y in g [ x ] :
            if ( dist [ y ] > dis + 1 ) :
                dist [ y ] = dis + 1
                ways1 [ y ] = ways1 [ x ]
                queue1 . append ( [ y , dis + 1 ] )
            elif ( dist [ y ] == dis + 1 ) :
                ways1 [ y ] += ways1 [ x ]
    queue2 = [ ]
    queue2 . append ( [ n - 1 , 0 ] )
    dist1 = [ 1e9 for i in range ( n ) ]
    ways2 = [ 0 for i in range ( n ) ]
    dist1 [ n - 1 ] = 0
    ways2 [ n - 1 ] = 1
    while ( len ( queue2 ) > 0 ) :
        up = queue2 [ 0 ]
        queue2 = queue2 [ : - 1 ]
        x = up [ 0 ]
        dis = up [ 1 ]
        if ( dis > dist1 [ x ] ) :
            continue
        if ( x == 0 ) :
            continue
        for y in g [ x ] :
            if ( dist1 [ y ] > dis + 1 ) :
                dist1 [ y ] = dis + 1
                ways2 [ y ] = ways2 [ x ]
                queue2 . append ( [ y , dis + 1 ] )
            elif ( dist1 [ y ] == 1 + dis ) :
                ways2 [ y ] += ways2 [ x ]
    ways1 [ n - 1 ] = 1
    ways2 [ n - 1 ] = 1
    for i in range ( n ) :
        print ( ways1 [ i ] * ways2 [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    M = 5
    edges = [ [ 1 , 2 ] , [ 1 , 4 ] , [ 1 , 3 ] , [ 2 , 5 ] , [ 2 , 4 ] ]
    countMinDistance ( N , M , edges )

Index/key variables: a, b, i, x, y
Accumulator variables: queue1, queue2
Iterator variables: i, y
Python program:
def findSumOfAllSubsets ( arr , n , k ) :
    factorial_N = 1
    factorial_d = 1
    factorial_D = 1
    for i in range ( 1 , n , 1 ) :
        factorial_N *= i
    for i in range ( 1 , k , 1 ) :
        factorial_d *= i
    for i in range ( 1 , n - k + 1 , 1 ) :
        factorial_D *= i
    freq = factorial_N // ( factorial_d * factorial_D )
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    sum = sum * freq
    print ( " Sum ▁ of ▁ all ▁ subsets ▁ of ▁ size ▁ = ▁ " , k , " ▁ is ▁ = > " , sum )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 5 ]
    n = 4
    k = 2
    findSumOfAllSubsets ( arr , n , k )

Index/key variables: i
Accumulator variables: factorial_D, factorial_N, factorial_d, sum
Iterator variables: i
Python program:
def maximumTripletXOR ( A , B , C ) :
    ans = 0
    for i in range ( 30 , - 1 , - 1 ) :
        cur = 1 << i
        if ( A >= cur ) :
            ans += cur
            A -= cur
        elif ( B >= cur ) :
            ans += cur
            B -= cur
        elif ( C >= cur ) :
            ans += cur
            C -= cur
    return ans
A = 6
B = 2
C = 10
print ( maximumTripletXOR ( A , B , C ) )

Accumulator variables: A, B, C, ans
Iterator variables: i
Python program:
def intCount ( X , K ) :
    ans = 0
    for z in range ( 0 , int ( pow ( 10 , K ) ) , int ( ( pow ( 10 , K ) - 1 ) / 9 ) ) :
        if ( z > X ) :
            break
        ans += int ( ( X - z ) / int ( pow ( 10 , K ) ) + 1 )
    return ans
def intCountInRange ( L , R , K ) :
    return ( intCount ( R , K ) - intCount ( L - 1 , K ) )
L = 49
R = 101
K = 2
print ( intCountInRange ( L , R , K ) )

Accumulator variables: ans
Iterator variables: z
Python program:
def countQuadruples ( A , N ) :
    ans = 0
    freq = { }
    for i in range ( N ) :
        if A [ i ] in freq :
            ans += freq [ A [ i ] ]
        else :
            freq [ A [ i ] ] = 0
        for j in range ( i ) :
            for k in range ( j ) :
                if A [ i ] * A [ j ] * A [ k ] in freq :
                    freq [ A [ i ] * A [ j ] * A [ k ] ] += 1
                else :
                    freq [ A [ i ] * A [ j ] * A [ k ] ] = 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 2 , 2 , 7 , 40 , 160 ]
    N = len ( arr )
    print ( countQuadruples ( arr , N ) )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
import math
def printFactors ( n ) :
    for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            d1 = i
            d2 = n
            while ( d2 % d1 == 0 ) :
                d2 = d2 // d1
            if ( d1 > 1 and d2 > 1 ) :
                print ( d1 , d2 , sep = " , ▁ " )
                return
    print ( - 1 )
N = 10
printFactors ( N )

Iterator variables: i
Python program:
def countTriplets ( arr , n ) :
    odd = 0
    even = 0
    for i in range ( n ) :
        if ( arr [ i ] & 1 ) :
            odd += 1
        else :
            even += 1
    c1 = odd * ( even * ( even - 1 ) ) // 2
    c2 = ( odd * ( odd - 1 ) * ( odd - 2 ) ) // 6
    return c1 + c2
arr = [ 4 , 5 , 6 , 4 , 5 , 10 , 1 , 7 ]
n = len ( arr )
ans = countTriplets ( arr , n )
print ( ans )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
def maxUniqueElements ( A , N ) :
    mp = { }
    for i in range ( N ) :
        if A [ i ] in mp :
            mp [ A [ i ] ] += 1
        else :
            mp [ A [ i ] ] = 1
    cnt = 0
    for key , value in mp . items ( ) :
        if ( value % 2 == 0 ) :
            cnt += 1
    ans = len ( mp )
    if ( cnt % 2 == 1 ) :
        ans -= 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    A = [ 1 , 2 , 1 , 3 , 7 ]
    print ( maxUniqueElements ( A , N ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i, key, value
Python program:
def countCells ( n , m , s ) :
    mx1 = - 1
    cont1 = 0
    i = 0
    while ( i < s and i < n ) :
        aux = ( n - ( i + 1 ) ) // s + 1
        if ( aux > mx1 ) :
            mx1 = cont1 = aux
        elif ( aux == mx1 ) :
            cont1 += aux
        i += 1
    mx2 = - 1
    cont2 = 0
    i = 0
    while ( i < s and i < m ) :
        aux = ( m - ( i + 1 ) ) // s + 1
        if ( aux > mx2 ) :
            mx2 = cont2 = aux
        elif ( aux == mx2 ) :
            cont2 += aux
        i += 1
    return cont1 * cont2
if __name__ == ' _ _ main _ _ ' :
    N = 5
    M = 5
    K = 2
    print ( countCells ( N , M , K ) )

Accumulator variables: cont1, cont2, i
Python program:
def countTotalPairs ( N , K ) :
    if ( K == 0 ) :
        return N * N
    ans = 0
    for b in range ( K + 1 , N + 1 ) :
        ans += ( N // b ) * ( b - K )
        ans += max ( N % b - K + 1 , 0 )
    return ans
N = 5
K = 2
print ( countTotalPairs ( N , K ) )

Accumulator variables: ans
Iterator variables: b
Python program:
def minSumDifference ( ar , n ) :
    sum = 0
    for i in range ( n ) :
        sum += ar [ i ]
    rem = sum % n
    return rem * ( n - rem )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 8 , 5 , 2 , 1 , 11 , 7 , 10 , 4 ]
    N = len ( arr )
    print ( minSumDifference ( arr , N ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def minSteps ( N ) :
    count = 1
    res = 0
    for i in range ( 1 , N + 1 , count ) :
        res = max ( res , count )
        count += 1
    return res
if __name__ == ' _ _ main _ _ ' :
    N = 6
    print ( minSteps ( N ) )

Accumulator variables: count
Iterator variables: i
Python program:
def countReachablePoints ( X , Y , L , R ) :
    diff_arr = [ 0 for i in range ( 100000 ) ]
    count = 0
    diff_arr [ X ] = 1
    diff_arr [ X + 1 ] = - 1
    for i in range ( X , Y + 1 , 1 ) :
        diff_arr [ i ] += diff_arr [ i - 1 ]
        if ( diff_arr [ i ] >= 1 ) :
            diff_arr [ i + L ] += 1
            diff_arr [ i + R + 1 ] -= 1
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    X = 3
    Y = 12
    L = 2
    R = 3
    print ( countReachablePoints ( X , Y , L , R ) )

Index/key variables: X, i
Accumulator variables: count
Iterator variables: i
Python program:
def sieveOfEratosthenes ( N , s ) :
    prime = [ False ] * ( N + 1 )
    for i in range ( 2 , N + 1 , 2 ) :
        s [ i ] = 2
    for i in range ( 3 , N + 1 , 2 ) :
        if ( prime [ i ] == False ) :
            s [ i ] = i
            for j in range ( i , int ( N / i ) + 1 , 2 ) :
                if ( prime [ i * j ] == False ) :
                    prime [ i * j ] = True
                    s [ i * j ] = i
def generatePrimeFactors ( N ) :
    curr = s [ N ]
    cnt = { s [ N ] : 1 }
    while ( N > 1 ) :
        N //= s [ N ]
        if N and s [ N ] :
            if cnt . get ( s [ N ] , 0 ) == 0 :
                cnt [ s [ N ] ] = 1
            else :
                cnt [ s [ N ] ] += 1
    if 0 in cnt :
        cnt . pop ( 0 )
    totfactor = 1
    for i in cnt . values ( ) :
        totfactor *= i + 1
    return totfactor
def countTriplets ( N ) :
    CountTriplet = 0
    for z in range ( 1 , N + 1 ) :
        p = generatePrimeFactors ( N - z )
        if p > 1 :
            CountTriplet += p
    return CountTriplet + 1
N = 10
s = [ 0 ] * ( N + 1 )
sieveOfEratosthenes ( N , s )
print ( countTriplets ( N ) )

Index/key variables: N, i
Accumulator variables: CountTriplet, totfactor
Iterator variables: i, j, z
Python program:
def minimumSubarray ( arr , n , m ) :
    mapu = [ 0 for i in range ( m + 1 ) ]
    c = 0
    for i in range ( n ) :
        mapu [ arr [ i ] ] += 1
        if ( mapu [ arr [ i ] ] == ( n // m ) + 1 ) :
            c += 1
    if ( c == 0 ) :
        return 0
    ans = n
    l = 0
    r = 0
    while ( r < n ) :
        mapu [ arr [ r ] ] -= 1
        if ( mapu [ arr [ r ] ] == ( n // m ) ) :
            c -= 1
        if ( c == 0 ) :
            while ( l <= r and c == 0 ) :
                ans = min ( ans , r - l + 1 )
                mapu [ arr [ l ] ] += 1
                if ( mapu [ arr [ l ] ] > ( n // m ) ) :
                    c += 1
                l += 1
        r += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 1 , 1 , 2 ]
    M = 2
    N = len ( arr )
    print ( minimumSubarray ( arr , N , M ) )

Index/key variables: i, l, r
Accumulator variables: c
Iterator variables: i
Python program:
def checkSum ( arr , n , k ) :
    m = { }
    for i in range ( n ) :
        if arr [ i ] in m :
            m [ arr [ i ] ] += 1
        else :
            m [ arr [ i ] ] = 1
    freq = [ [ ] for i in range ( n + 1 ) ]
    for i in range ( n ) :
        f = m [ arr [ i ] ]
        if ( f != - 1 ) :
            freq [ f ] . append ( arr [ i ] )
            m [ arr [ i ] ] = - 1
    count = 0
    kleastfreqsum = 0
    for i in range ( n + 1 ) :
        for x in freq [ i ] :
            kleastfreqsum += x
            count += 1
            if ( count == k ) :
                break
        if ( count == k ) :
            break
    count = 0
    kmostfreqsum = 0
    i = n
    while ( i >= 0 ) :
        for x in freq [ i ] :
            kmostfreqsum += x
            count += 1
            if ( count == k ) :
                break
        i -= 1
        if ( count == k ) :
            break
    if ( kleastfreqsum == kmostfreqsum ) :
        return " Yes "
    return " No "
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 1 , 2 , 3 , 3 , 4 ]
    N = len ( arr )
    K = 2
    print ( checkSum ( arr , N , K ) )

Index/key variables: f, i
Accumulator variables: count, kleastfreqsum, kmostfreqsum
Iterator variables: i, x
Python program:
def solve ( start , end ) :
    num = " "
    ans = [ ]
    for i in range ( 1 , 10 , 1 ) :
        num = str ( i )
        value = int ( num )
        if ( value >= start and value <= end ) :
            ans . append ( value )
        for j in range ( i + 1 , 10 , 1 ) :
            num += str ( j )
            value = int ( num )
            if ( value >= start and value <= end ) :
                ans . append ( value )
    ans . sort ( )
    return ans
if __name__ == ' _ _ main _ _ ' :
    L = 12
    R = 87
    ans = solve ( 12 , 87 )
    for it in ans :
        print ( it , end = " ▁ " )

Accumulator variables: ans, num
Iterator variables: i, it, j
Python program:
import sys
def minDistance ( start , end , n , d ) :
    left = - sys . maxsize
    right = sys . maxsize
    for i in range ( n ) :
        left = max ( left , start [ i ] )
        right = min ( right , end [ i ] )
    if ( left > right ) :
        return - 1
    if ( d >= left and d <= right ) :
        return 0
    if ( d < left ) :
        return ( left - d )
    if ( d > right ) :
        return ( d - right )
start = [ 0 , 2 , 4 ]
end = [ 7 , 14 , 6 ]
n = len ( start )
d = 3
print ( minDistance ( start , end , n , d ) )

Index/key variables: i
Iterator variables: i
Python program:
def power ( x , y ) :
    if ( y == 0 ) :
        return 1
    if ( y % 2 == 0 ) :
        return power ( x , y // 2 ) * power ( x , y // 2 )
    return x * power ( x , y // 2 ) * power ( x , y // 2 )
def order ( num ) :
    count = 0
    while ( num ) :
        count += 1
        num = num // 10
    return count
def isArmstrong ( N ) :
    r = order ( N )
    temp = N
    sum = 0
    while ( temp ) :
        d = temp % 10
        sum += power ( d , r )
        temp = temp // 10
    return ( sum == N )
def maxSum ( arr , N , K ) :
    if ( N < K ) :
        return - 1
    res = 0
    for i in range ( K ) :
        res += arr [ i ]
    curr_sum = res
    for i in range ( K , N , 1 ) :
        curr_sum += arr [ i ] - arr [ i - K ]
        res = max ( res , curr_sum )
    return res
def maxArmstrong ( arr , N , K ) :
    for i in range ( N ) :
        arr [ i ] = isArmstrong ( arr [ i ] )
    return maxSum ( arr , N , K )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 28 , 2 , 3 , 6 , 153 , 99 , 828 , 24 ]
    K = 6
    N = len ( arr )
    print ( maxArmstrong ( arr , N , K ) )

Index/key variables: i
Accumulator variables: count, curr_sum, res, sum
Iterator variables: i
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 countWays ( s , t ) :
    n = len ( s ) ;
    sum1 = 0
    sum2 = 0
    K = 0
    for i in range ( n ) :
        if ( s [ i ] == '1' ) :
            sum1 += 1
        else :
            sum1 -= 1
    m = len ( t )
    for i in range ( m ) :
        if ( t [ i ] == '1' ) :
            sum2 += 1
        elif ( t [ i ] == '0' ) :
            sum2 -= 1
        else :
            K += 1
    P = abs ( sum1 - sum2 )
    if ( P > K or ( K - P ) % 2 ) :
        print ( 0 )
        return
    print ( nCr ( K , ( P + K ) // 2 ) )
if __name__ == ' _ _ main _ _ ' :
    S1 = "1010"
    S2 = "10 ? ? "
    countWays ( S1 , S2 )

Index/key variables: i
Accumulator variables: K, sum1, sum2
Iterator variables: i
Python program:
def countPairs ( arr , N ) :
    answer = 0
    for i in range ( N ) :
        for j in range ( i + 1 , N ) :
            if arr [ i ] + arr [ j ] == i + j :
                answer += 1
    print ( answer )
arr = [ 0 , 1 , 2 , 3 , 4 , 5 ]
N = len ( arr )
countPairs ( arr , N )

Index/key variables: i, j
Accumulator variables: answer
Iterator variables: i, j
Python program:
from math import sqrt
def primeFactor ( N ) :
    v = [ ]
    count = 0
    while ( ( N % 2 ) == 0 ) :
        N >>= 1
        count += 1
    if ( count ) :
        v . append ( [ 2 , count ] )
    for i in range ( 3 , int ( sqrt ( N ) ) + 1 , 2 ) :
        count = 0
        while ( N % i == 0 ) :
            count += 1
            N = N / i
        if ( count ) :
            v . append ( [ i , count ] )
    if ( N > 2 ) :
        v . append ( [ N , 1 ] )
    return v
def printAnswer ( n ) :
    v = primeFactor ( n )
    maxi_size = 0
    prime_factor = 0
    for i in range ( len ( v ) ) :
        if ( maxi_size < v [ i ] [ 1 ] ) :
            maxi_size = v [ i ] [ 1 ]
            prime_factor = v [ i ] [ 0 ]
    if ( maxi_size < 2 ) :
        print ( 1 , n )
    else :
        product = 1
        print ( maxi_size )
        for i in range ( maxi_size - 1 ) :
            print ( prime_factor , end = " ▁ " )
            product *= prime_factor
        print ( n // product )
if __name__ == ' _ _ main _ _ ' :
    N = 360
    printAnswer ( N )

Index/key variables: i
Accumulator variables: N, count, product, v
Iterator variables: i
Python program:
def ABS ( x ) :
    return max ( x , - x )
def findFraction ( x , y , n ) :
    A = - 1
    B = - 1
    for i in range ( 1 , n + 1 ) :
        d = ( i * x ) // y
        if ( d >= 0 and ( A == - 1 or ABS ( B * x - y * A ) * ABS ( i * y ) > ABS ( i * x - y * d ) * ABS ( B * y ) ) ) :
            A = d
            B = i
        d += 1
        if ( d >= 0 and ( A == - 1 or ABS ( B * x - y * A ) * ABS ( i * y ) > ABS ( i * x - y * d ) * ABS ( B * y ) ) ) :
            A = d
            B = i
    print ( str ( A ) + " / " + str ( B ) )
if __name__ == ' _ _ main _ _ ' :
    x = 3
    y = 7
    n = 6
    findFraction ( x , y , n )

Accumulator variables: d
Iterator variables: i
Python program:
def BaseConversion ( N ) :
    s = " "
    while ( N != 0 ) :
        if ( N % 2 == 0 ) :
            s = "0" + s
        else :
            s = "1" + s
            N -= 1
        N /= - 2
    if ( s == " " ) :
        s = "0"
    return s
N = - 9
print ( BaseConversion ( N ) )

Accumulator variables: N
Python program:
from math import ceil
def finalInstances ( instances , arr ) :
    i = 0
    while i < len ( arr ) :
        if arr [ i ] < 25 and instances > 1 :
            instances = ceil ( instances / 2 )
            i += 10
        elif arr [ i ] > 60 and instances <= 10 ** 8 :
            instances *= 2
            i += 10
        i += 1
    print ( instances )
instances = 2
arr = [ 25 , 23 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 76 , 80 ]
finalInstances ( instances , arr )

Index/key variables: i
Accumulator variables: instances
Python program:
def isMakeZero ( arr , N , K ) :
    MP = { }
    V = [ ]
    X = 1
    while ( X > 0 and X < 10 ** 20 ) :
        V . append ( X )
        X *= K
    for i in range ( 0 , N , 1 ) :
        for j in range ( len ( V ) - 1 , - 1 , - 1 ) :
            if ( V [ j ] not in MP and V [ j ] <= arr [ i ] ) :
                arr [ i ] -= V [ j ]
                MP [ V [ j ] ] = 1
        if ( arr [ i ] != 0 ) :
            break
    if ( i < N - 1 ) :
        return " No "
    else :
        return " Yes "
arr = [ 8 , 0 , 3 , 4 , 80 ]
N = len ( arr )
K = 2
print ( isMakeZero ( arr , N , K ) )

Index/key variables: i, j
Accumulator variables: V, X
Iterator variables: i, j
Python program:
from math import sqrt
def perfectSquare ( arr , N ) :
    for i in range ( N ) :
        p = sqrt ( arr [ i ] )
        if ( p * p != arr [ i ] ) :
            return " No "
    return " Yes "
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 4 , 100 ]
    N = len ( arr )
    print ( perfectSquare ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def countKAverageSubarrays ( arr , n , k ) :
    res = 0
    for L in range ( n ) :
        sum = 0
        for R in range ( L , n , 1 ) :
            sum += arr [ R ]
            len1 = ( R - L + 1 )
            if ( sum % len1 == 0 ) :
                avg = sum // len1
                if ( avg == k ) :
                    res += 1
    return res
if __name__ == ' _ _ main _ _ ' :
    K = 6
    arr = [ 12 , 5 , 3 , 10 , 4 , 8 , 10 , 12 , - 6 , - 1 ]
    N = len ( arr )
    print ( countKAverageSubarrays ( arr , N , K ) )

Index/key variables: R
Accumulator variables: res, sum
Iterator variables: L, R
Python program:
def minimumElement ( arr , N , K ) :
    minElement = arr [ 0 ] ;
    for i in range ( N ) :
        minElement = min ( minElement , arr [ i ] ) ;
    reqOperations = 0 ;
    for i in range ( N ) :
        reqOperations += arr [ i ] - minElement
    if ( reqOperations < K ) :
        K -= reqOperations ;
        minElement -= ( K + N - 1 ) // N ;
    return minElement ;
arr = [ 10 , 10 , 10 , 10 ] ;
K = 7 ;
N = len ( arr )
print ( minimumElement ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: reqOperations
Iterator variables: i
Python program:
def FractionSplit ( n , d ) :
    UnitFactions = [ ]
    while ( n > 0 ) :
        x = ( d + n - 1 ) // n
        s = "1 / " + str ( x )
        UnitFactions . append ( s ) ;
        n = n * x - d ;
        d = d * x
    return UnitFactions ;
n = 13 ;
d = 18 ;
res = FractionSplit ( n , d ) ;
for s in res :
    print ( s + " , ▁ " , end = " ▁ " ) ;

Accumulator variables: UnitFactions
Iterator variables: s
Python program:
def findPermutation ( N ) :
    arr = [ i + 1 for i in range ( N ) ]
    for i in range ( 1 , N , 2 ) :
        arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]
    if N % 2 and N > 1 :
        arr [ - 1 ] , arr [ - 2 ] = arr [ - 2 ] , arr [ - 1 ]
    for i in arr :
        print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 7
    findPermutation ( N )

Index/key variables: i
Iterator variables: i