dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
def isprm ( n ) :
    if ( n <= 1 ) :
        return 0
    if ( n <= 3 ) :
        return 1
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return 0
    i = 5
    while i * i <= n :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return 0
        i += 6
    return 1
def shortestpath ( m , n ) :
    mfactor = [ ]
    nfactor = [ ]
    fre = dict . fromkeys ( range ( n + 1 ) , 0 )
    mfactor . append ( m )
    fre [ m ] = 1
    while ( m != 1 ) :
        if ( isprm ( m ) ) :
            mfactor . append ( 1 )
            fre [ 1 ] = 1
            m = 1
        else :
            sqt = ( int ) ( math . sqrt ( m ) )
            for i in range ( 2 , sqt + 1 ) :
                if ( m % i == 0 ) :
                    mfactor . append ( m // i )
                    fre [ m // i ] = 1
                    m = ( m // i )
                    break
    nfactor . append ( n )
    while ( fre [ n ] != 1 ) :
        if ( isprm ( n ) ) :
            nfactor . append ( 1 )
            n = 1
        else :
            sqt = ( int ) ( math . sqrt ( n ) )
            for i in range ( 2 , sqt + 1 ) :
                if ( n % i == 0 ) :
                    nfactor . append ( n // i )
                    n = ( n // i )
                    break
    for i in range ( len ( mfactor ) ) :
        if ( mfactor [ i ] == n ) :
            break
        print ( mfactor [ i ] , end = " ▁ < - - > ▁ " )
    for i in range ( len ( nfactor ) - 1 , - 1 , - 1 ) :
        if ( i == 0 ) :
            print ( nfactor [ i ] , end = " " )
        else :
            print ( nfactor [ i ] , end = " ▁ < - - > ▁ " )
if __name__ == " _ _ main _ _ " :
    m = 18
    n = 19
    shortestpath ( m , n )

Index/key variables: i, m, n
Accumulator variables: mfactor, nfactor
Iterator variables: i
Python program:
mod = int ( 1e9 + 7 )
def NumberOfTrees ( arr , N ) :
    maxElement = max ( arr ) ;
    level = [ 0 ] * ( maxElement + 1 ) ;
    for i in range ( N ) :
        level [ arr [ i ] ] += 1 ;
    if ( arr [ 0 ] != 0 or level [ 0 ] != 1 ) :
        return 0 ;
    ans = 1 ;
    for i in range ( maxElement ) :
        for j in range ( level [ i + 1 ] ) :
            ans = ( ans * level [ i ] ) % mod ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    N = 7 ;
    arr = [ 0 , 3 , 2 , 1 , 2 , 2 , 1 ] ;
    print ( NumberOfTrees ( arr , N ) ) ;

Index/key variables: i
Iterator variables: i, j
Python program:
mod = int ( 1e9 + 7 )
def power ( x , y ) :
    if ( y == 0 ) :
        return 1
    p = power ( x , y // 2 ) % mod
    p = ( p * p ) % mod
    if ( y & 1 ) :
        p = ( x * p ) % mod
    return p
def NumberOfTrees ( arr , N ) :
    maxElement = max ( arr )
    level = [ 0 ] * ( maxElement + 1 )
    for i in range ( N ) :
        level [ arr [ i ] ] += 1
    if ( arr [ 0 ] != 0 or level [ 0 ] != 1 ) :
        return 0
    ans = 1
    for i in range ( maxElement ) :
        ans = ( ans * power ( level [ i ] , level [ i + 1 ] ) ) % mod
    return ans
N = 7
arr = [ 0 , 3 , 2 , 1 , 2 , 2 , 1 ]
print ( NumberOfTrees ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def carryCount ( num1 , num2 ) :
    count = 0
    while ( num2 != 0 ) :
        carry = num1 & num2
        num1 = num1 ^ num2
        num2 = carry << 1
        count += bin ( num2 ) . count ( '1' )
    return count
A = 15
B = 10
print ( carryCount ( A , B ) )

Accumulator variables: count
Python program:
Mod = int ( 1e9 + 7 )
def power ( X , Y , Mod ) :
    if Y == 0 :
        return 1
    p = power ( X , Y // 2 , Mod ) % Mod
    p = ( p * p ) % Mod
    if Y & 1 :
        p = ( X * p ) % Mod
    return p
def Inversefactorial ( N ) :
    if N <= 0 :
        return 1
    fact = 1
    for i in range ( 1 , N + 1 ) :
        fact = ( fact * i ) % Mod
    return power ( fact , Mod - 2 , Mod )
def factorial ( N ) :
    if N <= 0 :
        return 1
    fact = 1
    for i in range ( 1 , N + 1 ) :
        fact = ( fact * i ) % Mod
    return fact
def nck ( N , K ) :
    factN = factorial ( N )
    inv = Inversefactorial ( K )
    invFact = Inversefactorial ( N - K )
    return ( ( ( factN * inv ) % Mod ) * invFact ) % Mod
def TotalWays ( N , M ) :
    if ( N + M ) % 3 != 0 :
        return 0
    X = N - ( N + M ) // 3
    Y = M - ( N + M ) // 3
    if X < 0 or Y < 0 :
        return 0
    return nck ( X + Y , Y )
N , M = 3 , 3
print ( TotalWays ( N , M ) )

Iterator variables: i
Python program:
def calculateProfit ( n , earnings , cost , e ) :
    profit = 0 ;
    for i in range ( n ) :
        earning_per_day = 0 ;
        daily_spent_food = 0 ;
        if ( i == ( n - 1 ) ) :
            earning_per_day = earnings [ i ] * e ;
            profit = profit + earning_per_day ;
            break ;
        if ( cost [ i ] < earnings [ i ] ) :
            earning_per_day = earnings [ i ] * e ;
            daily_spent_food = cost [ i ] * e ;
            profit = ( profit + earning_per_day - daily_spent_food ) ;
    print ( profit ) ;
if __name__ == ' _ _ main _ _ ' :
    n = 4 ;
    earnings = [ 1 , 8 , 6 , 7 ] ;
    cost = [ 1 , 3 , 4 , 1 ] ;
    e = 5 ;
    calculateProfit ( n , earnings , cost , e ) ;

Index/key variables: i
Iterator variables: i
Python program:
def checkEvenSum ( arr , N , size ) :
    even_freq , odd_freq = 0 , 0
    for i in range ( size ) :
        if ( arr [ i ] & 1 ) :
            odd_freq += 1
        else :
            even_freq += 1
    if ( even_freq >= N ) :
        return True
    else :
        if ( odd_freq & 1 ) :
            taken = odd_freq - 1
            req = N - taken
            if ( even_freq < req ) :
                return False
            else :
                return True
        else :
            taken = odd_freq
            req = N - taken
            if ( even_freq < req ) :
                return False
            else :
                return True
    return False
if __name__ == " _ _ main _ _ " :
    arr = [ 9 , 2 , 3 , 4 , 18 , 7 , 7 , 6 ]
    size = len ( arr )
    N = 5
    if ( checkEvenSum ( arr , N , size ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: even_freq, odd_freq
Iterator variables: i
Python program:
def minOperations ( a , N ) :
    num_of_ops1 = num_of_ops2 = sum = 0 ;
    for i in range ( N ) :
        sum += a [ i ]
        if ( i % 2 == 0 and sum >= 0 ) :
            num_of_ops1 += ( 1 + abs ( sum ) )
            sum = - 1
        elif ( i % 2 == 1 and sum <= 0 ) :
            num_of_ops1 += ( 1 + abs ( sum ) )
            sum = 1
    sum = 0
    for i in range ( N ) :
        sum += a [ i ]
        if ( i % 2 == 1 and sum >= 0 ) :
            num_of_ops2 += ( 1 + abs ( sum ) )
            sum = - 1
        elif ( i % 2 == 0 and sum <= 0 ) :
            num_of_ops2 += ( 1 + abs ( sum ) )
            sum = 1
    return min ( num_of_ops1 , num_of_ops2 )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , - 4 , 5 , 0 , 1 ]
    N = len ( arr )
    print ( minOperations ( arr , N ) )

Index/key variables: i
Accumulator variables: num_of_ops1, num_of_ops2, sum
Iterator variables: i
Python program:
def checkEquall ( arr , N ) :
    sumEven , sumOdd = 0 , 0
    for i in range ( N ) :
        if ( i & 1 ) :
            sumOdd += arr [ i ]
        else :
            sumEven += arr [ i ]
    if ( sumEven == sumOdd ) :
        return True
    else :
        return False
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 7 , 3 , 5 , 7 ]
    N = len ( arr )
    if ( checkEquall ( arr , N ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i
Accumulator variables: sumEven, sumOdd
Iterator variables: i
Python program:
def isSumOfPower ( n ) :
    isSum = [ 0 ] * ( n + 1 )
    perfectPowers = [ ]
    perfectPowers . append ( 1 )
    for i in range ( n + 1 ) :
        isSum [ i ] = False
    for i in range ( 2 , n + 1 ) :
        if ( isSum [ i ] == True ) :
            perfectPowers . append ( i )
            continue
        j = i * i
        while ( j > 0 and j < ( n + 1 ) ) :
            isSum [ j ] = True
            j *= i
    for i in range ( len ( perfectPowers ) ) :
        isSum [ perfectPowers [ i ] ] = False
    for i in range ( len ( perfectPowers ) ) :
        for j in range ( len ( perfectPowers ) ) :
            sum = ( perfectPowers [ i ] + perfectPowers [ j ] )
            if ( sum < ( n + 1 ) ) :
                isSum [ sum ] = True
    return isSum [ n ]
n = 9
if ( isSumOfPower ( n ) ) :
    print ( " true " )
else :
    print ( " false " )

Index/key variables: i, j, n, sum
Accumulator variables: perfectPowers
Iterator variables: i, j
Python program:
def update ( arr , N ) :
    for i in range ( N ) :
        arr [ i ] += ( i + 1 ) ;
def check ( arr , N ) :
    f = 0 ;
    for i in range ( N ) :
        count = 0 ;
        for j in range ( N ) :
            if ( arr [ i ] == arr [ j ] ) :
                count += 1 ;
        if ( count >= 2 ) :
            f = 1 ;
            break ;
    if ( f == 1 ) :
        return True ;
    else :
        return False ;
def incrementCount ( arr , N ) :
    min = 0 ;
    while ( check ( arr , N ) != True ) :
        update ( arr , N ) ;
        min += 1 ;
    print ( min ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 3 ;
    arr = [ 12 , 8 , 4 ] ;
    incrementCount ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: count, min
Iterator variables: i, j
Python program:
def checkPossible ( a , n ) :
    even_no_count = 0
    for i in range ( n ) :
        if ( a [ i ] % 2 == 0 ) :
            even_no_count += 1
    if ( n // 2 > even_no_count ) :
        print ( " No " )
        return
    print ( " Yes " )
    j = 0
    for i in range ( 1 , n , 2 ) :
        if ( a [ i ] % 2 == 0 ) :
            continue
        else :
            while ( j < n and a [ j ] % 2 != 0 ) :
                j += 2
            a [ i ] += a [ j ]
            a [ j ] = a [ i ] - a [ j ]
            a [ i ] -= a [ j ]
    for i in range ( n ) :
        print ( a [ i ] , end = " ▁ " )
arr = [ 2 , 3 , 4 , 5 , 6 , 7 ]
n = len ( arr )
checkPossible ( arr , n )

Index/key variables: i, j
Accumulator variables: even_no_count
Iterator variables: i
Python program:
import math
def maxORminusXOR ( N ) :
    MSB = int ( math . log2 ( N ) ) ;
    M = 0
    for i in range ( MSB + 1 ) :
        M += ( 1 << i )
    return M
if __name__ == ' _ _ main _ _ ' :
    N = 10
    print ( maxORminusXOR ( N ) )

Accumulator variables: M
Iterator variables: i
Python program:
def canMake ( n , ar ) :
    if ( n == 1 ) :
        return True ;
    else :
        if ( ar [ 0 ] < ar [ 1 ] ) :
            i = 1 ;
            while ( i < n and ar [ i - 1 ] < ar [ i ] ) :
                i += 1 ;
            while ( i + 1 < n and ar [ i ] > ar [ i + 1 ] ) :
                i += 1 ;
            if ( i >= n - 1 ) :
                return True ;
            else :
                return False ;
        elif ( ar [ 0 ] > ar [ 1 ] ) :
            i = 1 ;
            while ( i < n and ar [ i - 1 ] > ar [ i ] ) :
                i += 1 ;
            while ( i + 1 < n and ar [ i ] < ar [ i + 1 ] ) :
                i += 1 ;
            if ( i >= n - 1 ) :
                return True ;
            else :
                return False ;
        else :
            for i in range ( 2 , n ) :
                if ( ar [ i - 1 ] <= ar [ i ] ) :
                    return False ;
            return True ;
arr = [ 1 , 2 , 3 , 4 , 5 ] ;
n = len ( arr ) ;
if ( canMake ( n , arr ) == False ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;

Index/key variables: i
Iterator variables: i
Python program:
def check_length ( n ) :
    ans = 0
    while ( n ) :
        n = n >> 1
        ans += 1
    return ans
def check_ith_bit ( n , i ) :
    if ( n & ( 1 << ( i - 1 ) ) ) :
        return True
    else :
        return False
def no_of_flips ( n ) :
    ln = check_length ( n )
    ans = 0
    right = 1
    left = ln
    while ( right < left ) :
        if ( check_ith_bit ( n , right ) != check_ith_bit ( n , left ) ) :
            ans += 1
        left -= 1
        right += 1
    return ans
n = 12
print ( no_of_flips ( n ) )

Accumulator variables: ans, left, right
Python program:
def check ( a , n ) :
    ma = a [ 1 ] - a [ 0 ]
    for i in range ( 1 , n - 1 ) :
        if ( ( a [ i ] > a [ i - 1 ] and a [ i + 1 ] < a [ i ] ) or ( a [ i ] < a [ i - 1 ] and a [ i + 1 ] > a [ i ] ) ) :
            ma = max ( ma , abs ( a [ i ] - a [ i + 1 ] ) )
        else :
            return False
    print ( " Amplitude ▁ = ▁ " , ma )
    return True
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 2 , 1 , 5 , 0 , 7 , - 6 ]
    n = len ( a )
    wave = ( n - 1 ) // 2
    if ( check ( a , n ) ) :
        print ( " Waves ▁ = ▁ " , wave )
    else :
        print ( " - 1" )

Index/key variables: i
Iterator variables: i
Python program:
def findRank ( A , N ) :
    rank = [ 0 ] * N
    s = [ ]
    s . append ( A [ N - 1 ] )
    for i in range ( N - 2 , - 1 , - 1 ) :
        if ( A [ i ] < s [ - 1 ] ) :
            s . append ( A [ i ] )
            rank [ i ] = len ( s ) - 1
        else :
            while ( len ( s ) > 0 and A [ i ] >= s [ - 1 ] ) :
                del s [ - 1 ]
            s . append ( A [ i ] )
            rank [ i ] = len ( s ) - 1
    for i in range ( N ) :
        print ( rank [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 5 , 4 ]
    N = len ( A )
    findRank ( A , N )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
from collections import deque
def largestString ( n , k , sc ) :
    s = [ i for i in sc ]
    deq = deque ( )
    for i in range ( n ) :
        while ( len ( deq ) > 0 and deq [ - 1 ] < s [ i ] and k > 0 ) :
            deq . popleft ( )
            k -= 1
        deq . append ( s [ i ] )
    st = " "
    for c in deq :
        st = st + c
    return st
if __name__ == ' _ _ main _ _ ' :
    n = 4
    k = 2
    sc = " ritz "
    result = largestString ( n , k , sc )
    print ( result )

Index/key variables: i
Accumulator variables: deq, k
Iterator variables: c, i
Python program:
def countSetBit ( n ) :
    i = 0 ;
    ans = 0 ;
    while ( ( 1 << i ) <= n ) :
        k = True ;
        change = 1 << i ;
        for j in range ( n + 1 ) :
            ans += 0 if k == True else 1 ;
            if ( change == 1 ) :
                k = False if k == True else True ;
                change = 1 << i ;
            else :
                change -= 1 ;
        i += 1 ;
    return ans ;
def countSetBits ( L , R ) :
    return abs ( countSetBit ( R ) - countSetBit ( L - 1 ) ) ;
if __name__ == ' _ _ main _ _ ' :
    L = 3 ;
    R = 5 ;
    print ( " Total ▁ set ▁ bit ▁ count ▁ is ▁ " , countSetBits ( L , R ) ) ;

Accumulator variables: ans, change, i
Iterator variables: j
Boolean variables: k
Python program:
def countSetBits ( L , R ) :
    count = 0 ;
    for i in range ( L , R + 1 ) :
        n = i ;
        while ( n > 0 ) :
            count += ( n & 1 ) ;
            n = n >> 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    L = 3 ; R = 5 ;
    print ( " Total ▁ set ▁ Bit ▁ count ▁ is ▁ " , countSetBits ( L , R ) ) ;

Accumulator variables: count
Iterator variables: i
Python program:
def countSetBits ( L , R ) :
    count = 0 ;
    for i in range ( L , R + 1 ) :
        count += countSetBit ( i ) ;
    return count ;
def countSetBit ( n ) :
    count = 0
    while ( n ) :
        count += n & 1
        n >>= 1
    return count
if __name__ == ' _ _ main _ _ ' :
    L = 3 ;
    R = 5 ;
    print ( " Total ▁ set ▁ bit ▁ count ▁ is ▁ " , countSetBits ( L , R ) ) ;

Accumulator variables: count, n
Iterator variables: i
Python program:
def countElement ( A , N , B , M , K ) :
    cnt = 0
    for i in range ( M ) :
        currentElement = B [ i ]
        for j in range ( N ) :
            diff = abs ( currentElement - A [ j ] )
            if ( diff <= K ) :
                cnt += 1
                break
    print ( cnt )
if __name__ == ' _ _ main _ _ ' :
    A = [ 100 , 65 , 35 , 85 , 55 ]
    B = [ 30 , 60 , 75 , 95 ]
    N = len ( A )
    M = len ( B )
    K = 5
    countElement ( A , N , B , M , K )

Index/key variables: i, j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
def createString ( N ) :
    for i in range ( N ) :
        print ( ' a ' , end = ' ' )
    for i in range ( N ) :
        print ( ' b ' , end = ' ' )
N = 4
createString ( N )

Iterator variables: i
Python program:
def maxSubset ( A , flag ) :
    n = len ( A )
    sum = 0 ;
    if ( flag ) :
        for i in range ( 1 , n ) :
            A [ i ] = - A [ i ]
    for i in range ( 1 , n ) :
        if ( A [ i ] > 0 ) :
            sum += A [ i ]
    return sum
def findBest ( A ) :
    x = maxSubset ( A , 0 )
    y = maxSubset ( A , 1 )
    y = - y
    y += A [ 0 ]
    y = - y
    return max ( x , y )
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 10 , 4 , - 6 , 3 ]
    print ( findBest ( A ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def countSwaps ( A , n ) :
    A . sort ( )
    ind , res = 1 , 0
    for i in range ( n ) :
        while ( ind < n and A [ ind ] == A [ i ] ) :
            ind += 1
        if ( ind < n and A [ ind ] > A [ i ] ) :
            res += 1
            ind += 1
        if ( ind >= n ) :
            break
    return res
A = [ 4 , 3 , 3 , 2 , 5 ]
print ( countSwaps ( A , 5 ) )

Index/key variables: i, ind
Accumulator variables: res
Iterator variables: i
Python program:
def countSwaps ( A , n ) :
    mp = { }
    max_frequency = 0
    for i in range ( n ) :
        if A [ i ] in mp :
            mp [ A [ i ] ] += 1
        else :
            mp [ A [ i ] ] = 1
        max_frequency = max ( max_frequency , mp [ A [ i ] ] )
    return n - max_frequency
if __name__ == " _ _ main _ _ " :
    A = [ 6 , 5 , 4 , 3 , 2 , 1 ]
    print ( countSwaps ( A , 6 ) )

Index/key variables: i
Iterator variables: i
Python program:
def min_operation ( a , n ) :
    ans = 0
    for i in range ( n ) :
        if ( i > 0 ) :
            ans += abs ( a [ i ] - a [ i - 1 ] )
        else :
            ans += abs ( a [ i ] )
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 ]
    n = len ( arr )
    print ( min_operation ( arr , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def FindMatrix ( n , m , x , y ) :
    if ( n * m == 1 ) :
        if ( x > y ) :
            print ( y )
        else :
            print ( x )
        return
    a = min ( x , y )
    b = min ( 2 * x , y ) - a
    flag = True
    for i in range ( n ) :
        for j in range ( m ) :
            if ( flag ) :
                print ( a , end = " ▁ " )
            else :
                print ( b , end = " ▁ " )
            flag = not flag
        if ( ( ( n % 2 != 0 and m % 2 == 0 ) or ( n % 2 == 0 and m % 2 == 0 ) ) ) :
            flag = not flag
        print ( )
N = 3
M = 3
X = 5
Y = 3
FindMatrix ( N , M , X , Y )

Iterator variables: i, j
Boolean variables: flag
Python program:
def findCount ( Arr1 , Arr2 ) :
    MAX = max ( max ( Arr1 ) , max ( Arr2 ) ) ;
    Count = [ 0 for i in range ( 2 * MAX + 1 ) ]
    n = len ( Arr1 ) ;
    m = len ( Arr2 ) ;
    for i in range ( n ) :
        for j in range ( m ) :
            element = Arr1 [ i ] + Arr2 [ j ] ;
            Count [ element ] += 1 ;
    for i in range ( 1 , 2 * MAX + 1 ) :
        if ( Count [ i ] > 0 ) :
            print ( i , " - > " , Count [ i ] ) ;
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 1 , 2 ] ;
    arr2 = [ 1 , 2 , 1 ] ;
    findCount ( arr1 , arr2 ) ;

Index/key variables: element, i, j
Iterator variables: i, j
Python program:
def ConstructBinaryString ( N , M , K ) :
    if ( M < ( N - 1 ) or M > K * ( N + 1 ) ) :
        return ' - 1'
    ans = " "
    l = min ( K , M // ( N - 1 ) )
    temp = N
    while ( temp ) :
        temp -= 1
        ans += '0'
        if ( temp == 0 ) :
            break
        for i in range ( l ) :
            ans += '1'
    M -= ( N - 1 ) * l
    if ( M == 0 ) :
        return ans
    l = min ( M , K )
    for i in range ( l ) :
        ans += '1'
    M -= l
    while ( M > 0 ) :
        ans = '1' + ans
        M -= 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    M = 9
    K = 2
    print ( ConstructBinaryString ( N , M , K ) )

Accumulator variables: M, ans, temp
Iterator variables: i
Python program:
def number ( num ) :
    a = [ 0 ] * 20
    r , i , j = 0 , 0 , 0
    while ( num > 0 ) :
        r = num % 10
        if ( 9 - r > r ) :
            a [ i ] = r
        else :
            a [ i ] = 9 - r
        i += 1
        num = num // 10
    if ( a [ i - 1 ] == 0 ) :
        print ( 9 , end = " " )
        i -= 1
    for j in range ( i - 1 , - 1 , - 1 ) :
        print ( a [ j ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    num = 4545
    number ( num )

Index/key variables: i, j
Iterator variables: j
Python program:
def countDigitSum ( N , K ) :
    l = pow ( 10 , N - 1 )
    r = pow ( 10 , N ) - 1
    count = 0
    for i in range ( l , r + 1 ) :
        num = i
        digits = [ 0 ] * N
        for j in range ( N - 1 , - 1 , - 1 ) :
            digits [ j ] = num % 10
            num //= 10
        sum = 0
        flag = 0
        for j in range ( 0 , K ) :
            sum += digits [ j ]
        for j in range ( 1 , N - K + 1 ) :
            curr_sum = 0
            for m in range ( j , j + K ) :
                curr_sum += digits [ m ]
            if ( sum != curr_sum ) :
                flag = 1
                break
        if ( flag == 0 ) :
            count += 1
    return count
N = 2
K = 1
print ( countDigitSum ( N , K ) )

Index/key variables: j, m
Accumulator variables: count, curr_sum, num, sum
Iterator variables: i, j, m
Python program:
def noOfFactors ( N ) :
    if ( N == 1 ) :
        return 1
    count = 0
    ans = 1
    while ( N % 2 == 0 ) :
        count += 1
        N = N // 2
    ans *= ( count // 2 + 1 )
    i = 3
    while i * i <= N :
        count = 0
        while ( N % i == 0 ) :
            count += 1
            N = N // i
        ans *= ( count // 2 + 1 )
        i += 2
    return ans
if __name__ == " _ _ main _ _ " :
    N = 100
    print ( noOfFactors ( N ) )

Accumulator variables: ans, count, i
Python program:
def DFS ( U , vis , adj ) :
    vis [ U ] = 1
    for V in adj [ U ] :
        if ( vis [ V ] == 0 ) :
            DFS ( V , vis , adj )
def minCost ( N , M , vCost , eCost , sorc , colored , destination ) :
    adj = [ [ ] for i in range ( N + 1 ) ]
    for i in range ( M ) :
        adj [ sorc [ i ] ] . append ( destination [ i ] )
        adj [ destination [ i ] ] . append ( sorc [ i ] )
    vis = [ 0 ] * ( N + 1 )
    for i in range ( len ( colored ) ) :
        DFS ( colored [ i ] , vis , adj )
    X = 0
    for i in range ( 1 , N + 1 ) :
        if ( vis [ i ] == 0 ) :
            X += 1
            DFS ( i , vis , adj )
    mincost = X * min ( vCost , eCost )
    print ( mincost )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    M = 1
    sorc = [ 1 ]
    destination = [ 2 ]
    vCost = 3
    eCost = 2
    colored = [ 1 ]
    minCost ( N , M , vCost , eCost , sorc , colored , destination )

Index/key variables: U, V, i
Accumulator variables: X
Iterator variables: V, i
Python program:
def calculateWays ( arr1 , arr2 , N ) :
    A = arr2 [ 0 ]
    B = arr2 [ 1 ]
    C = arr2 [ 2 ]
    D = arr2 [ 3 ]
    ans , b , c , d = 0 , 0 , 0 , 0
    while b <= B and b * 5 <= ( N ) :
        c = 0
        while ( c <= C and b * 5 + c * 10 <= ( N ) ) :
            d = 0
            while ( d <= D and b * 5 + c * 10 + d * 20 <= ( N ) ) :
                if ( ( b * 5 ) + ( c * 10 ) + ( d * 20 ) >= ( N - A ) ) :
                    ans += 1
                d += 1
            c += 1
        b += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 123
    arr1 = [ 1 , 5 , 10 , 20 ]
    arr2 = [ 6 , 4 , 3 , 5 ]
    print ( calculateWays ( arr1 , arr2 , N ) )

Accumulator variables: ans, b, c, d