dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def constructPermutation ( S , N ) :
    ans = [ 0 ] * N
    ans [ 0 ] = 1
    for i in range ( 1 , N ) :
        if ( S [ i - 1 ] == '0' ) :
            ans [ i ] = i + 1
        else :
            ans [ i ] = ans [ i - 1 ]
        for j in range ( i ) :
            if ( ans [ j ] >= ans [ i ] ) :
                ans [ j ] += 1
    for i in range ( N ) :
        print ( ans [ i ] , end = " " )
        if ( i != N - 1 ) :
            print ( " ▁ " , end = " " )
S = "100101"
constructPermutation ( S , len ( S ) + 1 )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def KthSolution ( X , K ) :
    ans = 0
    for i in range ( 64 ) :
        if not ( X & ( 1 << i ) ) :
            if ( K & 1 ) :
                ans |= ( 1 << i )
            K >>= 1
            if not K :
                break
    return ans
X = 10
K = 5
print ( KthSolution ( X , K ) )

Accumulator variables: K, ans
Iterator variables: i
Python program:
def countArrays ( n , k ) :
    divisors = [ [ ] for i in range ( k + 1 ) ]
    for i in range ( 1 , k + 1 , 1 ) :
        for j in range ( 2 * i , k + 1 , i ) :
            divisors [ j ] . append ( i )
    dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]
    for j in range ( 1 , k + 1 , 1 ) :
        dp [ 1 ] [ j ] = 1
    for x in range ( 2 , n + 1 , 1 ) :
        sum = 0
        for j in range ( 1 , k + 1 , 1 ) :
            sum += dp [ x - 1 ] [ j ]
        for y in range ( 1 , k + 1 , 1 ) :
            dp [ x ] [ y ] = sum
            for d in divisors [ y ] :
                dp [ x ] [ y ] = ( dp [ x ] [ y ] - dp [ x - 1 ] [ d ] )
    sum = 0
    for j in range ( 1 , k + 1 , 1 ) :
        sum += dp [ n ] [ j ]
    return sum
if __name__ == ' _ _ main _ _ ' :
    N = 2
    K = 3
    print ( countArrays ( N , K ) )

Index/key variables: d, j, n, x, y
Accumulator variables: sum
Iterator variables: d, i, j, x, y
Python program:
def minimumMoves ( A , B , N ) :
    ans = 0
    sum_A = 0
    sum_B = 0
    for i in range ( N ) :
        sum_A += A [ i ]
    for i in range ( N ) :
        sum_B += B [ i ]
    if ( sum_A != sum_B ) :
        return - 1
    i = 0
    while ( i < N ) :
        if ( A [ i ] > B [ i ] ) :
            temp = A [ i ] - B [ i ]
            j = i - 1
            while ( j >= 0 and temp > 0 ) :
                if ( B [ j ] > A [ j ] ) :
                    cnt = min ( temp , ( B [ j ] - A [ j ] ) )
                    A [ j ] += cnt
                    temp -= cnt
                    ans += ( cnt * abs ( j - i ) )
                j -= 1
            if ( temp > 0 ) :
                j = i + 1
                while ( j < N and temp > 0 ) :
                    if ( B [ j ] > A [ j ] ) :
                        cnt = min ( temp , ( B [ j ] - A [ j ] ) )
                        A [ j ] += cnt
                        temp -= cnt
                        ans += ( cnt * abs ( j - i ) )
                    j += 1
        i += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 5 , 7 ]
    B = [ 13 , 0 , 0 ]
    N = len ( A )
    print ( minimumMoves ( A , B , N ) )

Index/key variables: i, j
Accumulator variables: ans, sum_A, sum_B, temp
Iterator variables: i
Python program:
import sys
def arrayDivisionByTwo ( arr , n ) :
    cnt = 0
    ans = sys . maxsize
    for i in range ( n ) :
        cnt = 0
        while ( arr [ i ] % 2 == 0 ) :
            arr [ i ] = arr [ i ] // 2
            cnt += 1
        ans = min ( ans , cnt )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 8 , 12 , 40 ]
    n = len ( arr )
    print ( arrayDivisionByTwo ( arr , n ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def printMinInteger ( P , Q , N ) :
    if ( Q > P ) :
        t = P
        P = Q
        Q = t
    if ( Q == 0 and ( P == 0 or N % P != 0 ) ) :
        print ( " Not ▁ Possible " )
        return
    count_P = 0
    count_Q = 0
    while ( N > 0 ) :
        if ( N % P == 0 ) :
            count_P += N / P
            N = 0
        else :
            N = N - Q
            count_Q += 1
    if ( N == 0 ) :
        for i in range ( count_Q ) :
            print ( Q , end = " " )
        for i in range ( int ( count_P ) ) :
            print ( P , end = " " )
    else :
        print ( " Not ▁ Possible " )
N = 32
P = 7
Q = 4
printMinInteger ( P , Q , N )

Accumulator variables: count_P, count_Q
Iterator variables: i
Python program:
def minPushes ( N , K , arr ) :
    dp = [ - 1 ] * 100000
    dp [ N ] = 0
    for i in range ( len ( arr ) ) :
        for xx in range ( 100000 ) :
            x = xx
            if ( dp [ x ] == - 1 ) :
                continue
            next = ( x + arr [ i ] ) % 100000
            while ( dp [ next ] == - 1 or dp [ next ] > dp [ x ] + 1 ) :
                dp [ next ] = dp [ x ] + 1
                x = next
                next = ( next + arr [ i ] ) % 100000
    return dp [ K ]
N = 99880
K = 89
arr = [ 100 , 3 ]
print ( minPushes ( N , K , arr ) )

Index/key variables: K, N, i, next, x
Iterator variables: i, xx
Python program:
def minimumOperations ( A , N ) :
    cur_prefix_1 = 0
    parity = - 1
    minOperationsCase1 = 0
    for i in range ( N ) :
        cur_prefix_1 += A [ i ]
        if ( cur_prefix_1 == 0 or parity * cur_prefix_1 < 0 ) :
            minOperationsCase1 += abs ( parity - cur_prefix_1 )
            cur_prefix_1 = parity
        parity *= - 1
    cur_prefix_2 = 0
    parity = 1
    minOperationsCase2 = 0
    for i in range ( N ) :
        cur_prefix_2 += A [ i ]
        if ( cur_prefix_2 == 0 or parity * cur_prefix_2 < 0 ) :
            minOperationsCase2 += abs ( parity - cur_prefix_2 )
            cur_prefix_2 = parity
        parity *= - 1
    return min ( minOperationsCase1 , minOperationsCase2 )
A = [ 1 , - 3 , 1 , 0 ]
N = len ( A )
print ( minimumOperations ( A , N ) )

Index/key variables: i
Accumulator variables: cur_prefix_1, cur_prefix_2, minOperationsCase1, minOperationsCase2, parity
Iterator variables: i
Python program:
def maximumSumArray ( arr , N ) :
    arrA = [ 0 ] * N
    ans = [ 0 ] * N
    maxSum = 0 ;
    for i in range ( N ) :
        arrA [ i ] = arr [ i ] ;
    for i in range ( N ) :
        arrB = [ 0 ] * N
        maximum = arrA [ i ] ;
        arrB [ i ] = maximum ;
        temp = 0
        for j in range ( i - 1 , - 1 , - 1 ) :
            arrB [ j ] = min ( maximum , arrA [ j ] ) ;
            maximum = arrB [ j ] ;
            temp = j
        maximum = arrA [ i ] ;
        for j in range ( i + 1 , N ) :
            arrB [ j ] = min ( maximum , arrA [ j ] ) ;
            maximum = arrB [ j ] ;
        sum = 0 ;
        for j in range ( N ) :
            sum += arrB [ j ] ;
        if ( sum > maxSum ) :
            maxSum = sum ;
            ans = arrB ;
    for val in ans :
        print ( val ) ;
A = [ 10 , 6 , 8 ] ;
N = len ( A )
maximumSumArray ( A , N ) ;

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j, val
Python program:
def maxAmount ( n , k , arr ) :
    A = [ 0 for i in range ( 1000001 ) ]
    for i in range ( n ) :
        A [ arr [ i ] ] += 1
    j = 0
    for j in range ( 1000001 ) :
        while ( A [ i ] != 0 ) :
            arr [ j ] = i ;
            j += 1
            A [ i ] -= 1
    ans = 6
    mod = 1000000007
    i = n - 1
    j = n - 2
    while ( k > 0 and j >= 0 ) :
        if ( arr [ i ] > arr [ j ] ) :
            ans = ans + min ( k , ( i - j ) ) * arr [ i ]
            k = k - ( i - j )
            arr [ i ] -= 1
        else :
            while ( j >= 0 and arr [ j ] == arr [ i ] ) :
                j -= 1
            if ( j < 0 ) :
                break
            ans = ans + min ( k , ( i - j ) ) * arr [ i ]
            k = k - ( i - j )
            arr [ i ] -= 1
    while ( k > 0 and arr [ i ] != 0 ) :
        ans = ans + min ( n , k ) * arr [ i ]
        k -= n
        arr [ i ] -= 1
    ans = ans % mod
    x = ans
    return x
if __name__ == ' _ _ main _ _ ' :
    n = 5
    k = 3
    arr = [ 4 , 3 , 6 , 2 , 4 ]
    ans = maxAmount ( n , k , arr )
    print ( ans )

Index/key variables: i, j
Accumulator variables: k
Iterator variables: i, j
Python program:
def maxAverage ( A , N , X , Y ) :
    A . sort ( )
    sum = 0
    res = 0
    count = 0
    for i in range ( N ) :
        sum += A [ i ]
        count += 1
        if ( count == X ) :
            if ( N - i - 1 < X ) :
                i += 1
                cnt = 0
                while ( i < N ) :
                    cnt += 1
                    sum += A [ i ]
                    i += 1
                X = X + cnt
                res += sum / X
                break
            res += sum / X
            sum = 0
            count = 0
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    A = [ 4 , 10 , 6 , 5 ]
    N = len ( A )
    X = 2
    Y = 3
    maxAverage ( A , N , X , Y )

Index/key variables: i
Accumulator variables: cnt, count, res, sum
Iterator variables: i
Python program:
S = " aaabc "
def isAdjChar ( s ) :
    for i in range ( len ( s ) - 1 ) :
        if ( s [ i ] == s [ i + 1 ] ) :
            return True
    return False
def rearrangeStringUtil ( N ) :
    global S
    S = list ( S )
    i = 0
    j = 1
    k = 2
    while ( k < N ) :
        if ( S [ i ] != S [ j ] ) :
            i += 1
            j += 1
            if ( j == k ) :
                k += 1
        else :
            if ( S [ j ] == S [ k ] ) :
                k += 1
            else :
                temp = S [ k ]
                S [ k ] = S [ j ]
                S [ j ] = temp
                i += 1
                j += 1
                if ( j == k ) :
                    k += 1
    S = ' ' . join ( S )
def rearrangeString ( N ) :
    global S
    if ( isAdjChar ( S ) == False ) :
        return S
    if ( len ( S ) == 2 ) :
        return " - 1"
    rearrangeStringUtil ( N )
    S = S [ : : - 1 ]
    rearrangeStringUtil ( N )
    if ( isAdjChar ( S ) == False ) :
        return S
    return " - 1"
if __name__ == ' _ _ main _ _ ' :
    N = len ( S )
    print ( rearrangeString ( N ) )

Index/key variables: i, j, k
Iterator variables: i
Python program:
import sys
def findMaximumPoints ( N , X , H ) :
    ans = 0
    prev = - sys . maxsize - 1
    for i in range ( N ) :
        if ( prev < ( X [ i ] - H [ i ] ) ) :
            ans += 1
            prev = X [ i ]
        elif ( i == N - 1 or ( X [ i ] + H [ i ] ) < X [ i + 1 ] ) :
            ans += 1
            prev = X [ i ] + H [ i ]
        else :
            prev = X [ i ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    X = [ 1 , 2 , 3 ]
    H = [ 2 , 5 , 5 ]
    N = len ( X )
    print ( findMaximumPoints ( N , X , H ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def sumOfCombinationOf4OR5 ( arr , N ) :
    ans = [ - 1 for i in range ( N ) ]
    for i in range ( N ) :
        if ( arr [ i ] < 4 ) :
            continue
        sum = 10 ** 9
        cnt = 0
        for j in range ( 0 , arr [ i ] + 1 , 4 ) :
            if ( ( arr [ i ] - j ) % 5 == 0 ) :
                sum = min ( sum , cnt + ( arr [ i ] - j ) // 5 )
            cnt += 1
        if ( sum != 10 ** 9 ) :
            ans [ i ] = sum
    for num in ans :
        print ( num , end = " ▁ " )
arr = [ 7 , 15 , 17 , 22 ]
N = len ( arr )
sumOfCombinationOf4OR5 ( arr , N )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i, j, num
Python program:
def printBinaryString ( arr , N ) :
    for i in range ( 1 , N + 1 ) :
        if ( i % 2 ) :
            print ( 0 , end = " " ) ;
        else :
            print ( 1 , end = " " ) ;
N = 5 ;
M = 3 ;
arr = [ [ 1 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] ] ;
printBinaryString ( arr , N ) ;

Iterator variables: i
Python program:
from math import gcd
def maxZeroes ( A , B ) :
    mp = { }
    N = len ( A )
    ans = 0
    cnt = 0
    for i in range ( N ) :
        num = - B [ i ]
        den = A [ i ]
        gc = gcd ( num , den )
        if ( den != 0 ) :
            num //= gc
            den //= gc
        if ( num <= 0 ) :
            num *= - 1
            den *= - 1
        if ( den == 0 and num == 0 ) :
            cnt += 1
        if ( den != 0 ) :
            mp [ ( num , den ) ] = mp . get ( ( num , den ) , 0 ) + 1
            ans = max ( mp [ ( num , den ) ] , ans )
    print ( ans + cnt )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , - 1 ]
    B = [ - 6 , - 12 , 6 ]
    maxZeroes ( A , B )

Index/key variables: i
Accumulator variables: cnt, den, num
Iterator variables: i
Python program:
def MinCost ( days , cost , N ) :
    size = days [ N - 1 ] + 1
    dp = [ 0 for i in range ( size ) ]
    dp [ size - 1 ] = min ( cost [ 0 ] , min ( cost [ 1 ] , cost [ 2 ] ) )
    ptr = N - 2
    for i in range ( size - 2 , 0 , - 1 ) :
        if ( ptr >= 0 and days [ ptr ] == i ) :
            val1 = dp [ i + 1 ] + cost [ 0 ]
            val2 = cost [ 1 ] + ( 0 if ( i + 7 >= size ) else dp [ i + 7 ] )
            val3 = cost [ 2 ] + ( 0 if ( i + 30 >= size ) else dp [ i + 30 ] )
            dp [ i ] = min ( val1 , min ( val2 , val3 ) )
            ptr -= 1 ;
        else :
            dp [ i ] = dp [ i + 1 ]
    return dp [ 1 ]
arr = [ 2 , 4 , 6 , 7 , 8 , 10 , 17 ]
cost = [ 3 , 8 , 20 ]
N = len ( arr )
print ( MinCost ( arr , cost , N ) )

Index/key variables: i, ptr
Iterator variables: i
Python program:
def countPairs ( N , arr ) :
    open = [ 0 ] * 100
    close = [ 0 ] * 100
    ans = 0
    for i in range ( N ) :
        c = [ i for i in arr [ i ] ]
        d = 0
        minm = 0
        for j in range ( len ( c ) ) :
            if ( c [ j ] == ' ( ' ) :
                d += 1
            else :
                d -= 1
                if ( d < minm ) :
                    minm = d
        if ( d >= 0 ) :
            if ( minm == 0 ) :
                close [ d ] += 1
        elif ( d < 0 ) :
            if ( minm == d ) :
                open [ - d ] += 1
    ans += close [ 0 ] // 2
    for i in range ( 1 , 100 ) :
        ans += min ( open [ i ] , close [ i ] )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    N = 7
    list = [ ]
    list . append ( " ) ( ) ) " )
    list . append ( " ) " )
    list . append ( " ( ( " )
    list . append ( " ( ( " )
    list . append ( " ( " )
    list . append ( " ) " )
    list . append ( " ) " )
    countPairs ( N , list )

Index/key variables: d, i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def minElements ( arr , N , K ) :
    count = 0
    requiredNum = 1
    i = 0
    while ( requiredNum <= K ) :
        if ( i < N and requiredNum >= arr [ i ] ) :
            requiredNum += arr [ i ]
            i += 1
        else :
            count += 1
            requiredNum += requiredNum
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 ]
    K = 6
    N = len ( arr )
    print ( minElements ( arr , N , K ) )

Index/key variables: i
Accumulator variables: count, requiredNum
Python program:
import math
from functools import cmp_to_key
def comparator ( p1 , p2 ) :
    a = p1 [ 0 ]
    b = p1 [ 1 ]
    c = p2 [ 0 ]
    d = p2 [ 1 ]
    val1 = a / b
    val2 = c / d
    return val1 > val2
def maximumProfit ( A , B , N , W ) :
    V = [ ]
    for i in range ( 0 , N ) :
        temp = int ( math . sqrt ( A [ i ] ) )
        if temp * temp == A [ i ] :
            continue
        V . append ( [ B [ i ] , A [ i ] ] )
    V = sorted ( V , key = cmp_to_key ( comparator ) )
    profit = 0.00
    k = len ( V )
    for i in range ( k ) :
        if V [ i ] [ 1 ] <= W :
            profit += V [ i ] [ 0 ]
            W -= V [ i ] [ 1 ]
        else :
            profit += ( V [ i ] [ 0 ] * W ) / V [ i ] [ 1 ]
            break
    return profit
if __name__ == ' _ _ main _ _ ' :
    N = 3
    W = 10
    A = [ 4 , 5 , 7 ]
    B = [ 8 , 5 , 4 ]
    print ( round ( maximumProfit ( A , B , N , W ) , 5 ) )

Index/key variables: i
Accumulator variables: V, W, profit
Iterator variables: i
Python program:
def maximumCount ( arr , N ) :
    odd = 0
    even = 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 ) :
            odd += 1
        else :
            even += 1
    if ( odd and even ) :
        return N - 2
    else :
        return N - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 9 , 13 , 15 , 3 , 16 , 9 , 13 , 18 ]
    N = len ( arr )
    print ( maximumCount ( arr , N ) )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
def minPossibleValue ( N , K , X ) :
    for i in range ( 1 , N + 1 ) :
        if ( X <= K ) :
            X = X * 2 ;
        else :
            X = X + K ;
    return X ;
N = 7 ;
K = 4 ;
X = 1 ;
print ( minPossibleValue ( N , K , X ) ) ;

Iterator variables: i
Python program:
import sys
def findMissingValue ( arr , N ) :
    minE = sys . maxsize
    maxE = - sys . maxsize - 1
    for i in range ( N - 1 ) :
        if ( arr [ i ] == - 1 and arr [ i + 1 ] != - 1 ) :
            minE = min ( minE , arr [ i + 1 ] )
            maxE = max ( maxE , arr [ i + 1 ] )
        if ( arr [ i ] != - 1 and arr [ i + 1 ] == - 1 ) :
            minE = min ( minE , arr [ i ] )
            maxE = max ( maxE , arr [ i ] )
    if ( minE == sys . maxsize and maxE == - sys . maxsize - 1 ) :
        print ( "0" )
    else :
        print ( ( minE + maxE ) // 2 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , - 1 , - 1 , - 1 , 5 ]
    N = len ( arr )
    findMissingValue ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def findLastElement ( N , A ) :
    l = len ( A )
    j = 0
    while ( N > l * ( 2 ** j ) ) :
        N = N - l * 2 ** j
        j += 1
    k = 1
    r = 2 ** j
    for i in range ( 1 , l ) :
        if N > r * i :
            k += 1
    for i in range ( 0 , len ( A ) ) :
        if ( i + 1 == k ) :
            print ( A [ i ] )
            return
if __name__ == ' _ _ main _ _ ' :
    K = 7
    A = [ 1 , 2 , 3 ]
    findLastElement ( K , A )

Index/key variables: i
Accumulator variables: j, k
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def findMaxD ( arr , N , K ) :
    for i in range ( 0 , N ) :
        arr [ i ] = abs ( arr [ i ] - K )
    D = arr [ 0 ]
    for i in range ( 1 , N ) :
        D = gcd ( D , arr [ i ] )
    return D
arr = [ 1 , 7 , 11 ]
N = len ( arr )
K = 3
print ( findMaxD ( arr , N , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxOperations ( S , N ) :
    X = 0
    Y = 0
    for i in range ( N ) :
        if ( S [ i ] == '0' ) :
            break
        Y += 1
    i = N - 1
    while ( i >= 0 ) :
        if ( S [ i ] == '1' ) :
            break
        X += 1
    if ( N == X + Y ) :
        return 0
    return N - ( X + Y ) - 1
if __name__ == ' _ _ main _ _ ' :
    S = "001111"
    N = len ( S )
    print ( maxOperations ( S , N ) )

Index/key variables: i
Accumulator variables: X, Y
Iterator variables: i
Python program:
def maximumSum ( S , N , K ) :
    sum = 0
    freq = [ 0 ] * 256
    for i in range ( N ) :
        freq [ ord ( S [ i ] ) ] += 1
    freq = sorted ( freq ) [ : : - 1 ]
    for i in range ( 256 ) :
        if ( K > freq [ i ] ) :
            sum += freq [ i ] * freq [ i ]
            K -= freq [ i ]
        else :
            sum += freq [ i ] * K
            break
    return sum
if __name__ == ' _ _ main _ _ ' :
    S = " GEEKSFORGEEKS "
    K = 10
    N = len ( S )
    print ( maximumSum ( S , N , K ) )

Index/key variables: i
Accumulator variables: K, sum
Iterator variables: i
Python program:
dp = [ [ [ 0 for i in range ( 10 ) ] for col in range ( 10 ) ] for row in range ( 100 ) ]
def countOfNumbers ( digit , prev1 , prev2 , n ) :
    if ( digit == n + 1 ) :
        return 1
    val = dp [ digit ] [ prev1 ] [ prev2 ]
    if ( val != - 1 ) :
        return val
    val = 0
    if ( digit == 1 ) :
        i = 1
        if n == 1 :
            i = 0
        for j in range ( i , 10 ) :
            val += countOfNumbers ( digit + 1 , j , prev1 , n )
    elif ( digit == 2 ) :
        for i in range ( 0 , 10 ) :
            val += countOfNumbers ( digit + 1 , i , prev1 , n )
    else :
        diff = abs ( prev2 - prev1 )
        for i in range ( 0 , 10 ) :
            if ( abs ( prev1 - i ) <= diff ) :
                val += countOfNumbers ( digit + 1 , i , prev1 , n )
    return val
def countNumbersUtil ( N ) :
    for i in range ( 0 , 100 ) :
        for j in range ( 0 , 10 ) :
            for k in range ( 0 , 10 ) :
                dp [ i ] [ j ] [ k ] = - 1
    print ( countOfNumbers ( 1 , 0 , 0 , N ) )
N = 3
countNumbersUtil ( N )

Index/key variables: digit, i, j, k, prev1, prev2
Accumulator variables: val
Iterator variables: i, j, k
Python program:
def possibleNumbers ( numbers , N , M , A , B ) :
    if ( M == 0 ) :
        numbers . add ( N )
        return
    possibleNumbers ( numbers , N + A , M - 1 , A , B )
    possibleNumbers ( numbers , N + B , M - 1 , A , B )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    M = 3
    A = 4
    B = 6
    numbers = set ( )
    possibleNumbers ( numbers , N , M , A , B )
    for x in numbers :
        print ( x , end = " ▁ " )

Iterator variables: x
Python program:
import sys
def maxSum ( arr , n ) :
    sum = 0
    max_neg = sys . maxsize
    tempsum = 0
    small = sys . maxsize
    for i in range ( n ) :
        sum += arr [ i ]
        small = min ( small , arr [ i ] )
        if ( arr [ i ] > 0 ) :
            tempsum = 0
        else :
            tempsum += arr [ i ]
        max_neg = min ( max_neg , tempsum )
    if ( max_neg == 0 ) :
        max_neg = small
    print ( sum - max_neg )
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ]
    n = len ( arr )
    maxSum ( arr , n )

Index/key variables: i
Accumulator variables: sum, tempsum
Iterator variables: i
Python program:
def RemoveOneChar ( A , B , N , M ) :
    X = 0
    Y = N - 1
    for i in range ( M ) :
        if ( A [ X ] != B [ i ] ) :
            break
        X += 1
    for i in range ( M - 1 , - 1 , - 1 ) :
        if ( A [ Y ] != B [ i ] ) :
            break
        Y -= 1
    if ( N - M == 1 and Y < X ) :
        print ( X - Y + 1 )
        for i in range ( Y , X + 1 ) :
            print ( i + 1 , end = " ▁ " )
        print ( )
    else :
        print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    A = " abaac "
    B = " abac "
    N = len ( A )
    M = len ( B )
    RemoveOneChar ( A , B , N , M )

Index/key variables: X, Y, i
Iterator variables: i
Python program:
def minimumOperation ( a , b ) :
    n = len ( a )
    i = 0
    minoperation = 0
    while ( i < n ) :
        if ( a [ i ] == b [ i ] ) :
            i = i + 1
            continue
        elif ( a [ i ] == b [ i + 1 ] and a [ i + 1 ] == b [ i ] and i < n - 1 ) :
            minoperation += 1
            i = i + 2
        elif ( a [ i ] != b [ i ] ) :
            minoperation += 1
            i = i + 1
        else :
            i += 1
    print ( minoperation )
if __name__ == ' _ _ main _ _ ' :
    a = "10010010"
    b = "00001000"
    minimumOperation ( a , b )

Index/key variables: i
Accumulator variables: minoperation
Python program:
def findMinOperations ( arr , N , K ) :
    operations = 0
    for i in range ( K ) :
        freq = { }
        for j in range ( i , N , K ) :
            if arr [ j ] in freq :
                freq [ arr [ j ] ] += 1
            else :
                freq [ arr [ j ] ] = 1
        max1 = 0
        num = 0
        for key , value in freq . items ( ) :
            if ( value > max1 ) :
                max1 = value
                num = key
        for key , value in freq . items ( ) :
            if ( key != num ) :
                operations += value
    print ( operations )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 4 , 3 , 5 , 6 ]
    K = 2
    N = len ( arr )
    findMinOperations ( arr , N , K )

Index/key variables: j
Accumulator variables: operations
Iterator variables: i, j, key, value
Python program:
from math import sqrt
def countOfPairs ( x , y ) :
    count = 0
    for k in range ( 1 , int ( sqrt ( x ) ) + 1 , 1 ) :
        count += max ( 0 , min ( y , x / k - 1 ) - k )
    print ( int ( count ) )
if __name__ == ' _ _ main _ _ ' :
    x = 4
    y = 5
    countOfPairs ( x , y )

Accumulator variables: count
Iterator variables: k