dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
def sortArr ( a , n ) :
    k = int ( math . log ( n , 2 ) )
    k = int ( pow ( 2 , k ) )
    while ( k > 0 ) :
        i = 0
        while i + k < n :
            if a [ i ] > a [ i + k ] :
                a [ i ] , a [ i + k ] = a [ i + k ] , a [ i ]
            i = i + 1
        k = k // 2
    for i in range ( n ) :
        print ( a [ i ] , end = " ▁ " )
a = [ 5 , 20 , 30 , 40 , 36 , 33 , 25 , 15 , 10 ]
n = len ( a )
sortArr ( a , n )

Index/key variables: i
Iterator variables: i
Python program:
def maximumSum ( arr , n , k ) :
    elt = n // k ;
    sum = 0 ;
    arr . sort ( ) ;
    count = 0 ;
    i = n - 1 ;
    while ( count < k ) :
        sum += arr [ i ] ;
        i -= 1 ;
        count += 1 ;
    count = 0 ;
    i = 0 ;
    while ( count < k ) :
        sum += arr [ i ] ;
        i += elt - 1 ;
        count += 1 ;
    print ( sum ) ;
if __name__ == ' _ _ main _ _ ' :
    Arr = [ 1 , 13 , 7 , 17 , 6 , 5 ] ;
    K = 2 ;
    size = len ( Arr ) ;
    maximumSum ( Arr , size , K ) ;

Index/key variables: i
Accumulator variables: count, sum
Python program:
def findMinSum ( arr , K , L , size ) :
    if ( K * L > size ) :
        return - 1
    minsum = 0
    arr . sort ( )
    for i in range ( K ) :
        minsum += arr [ i ]
    return minsum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 15 , 5 , 1 , 35 , 16 , 67 , 10 ]
    K = 3
    L = 2
    length = len ( arr )
    print ( findMinSum ( arr , K , L , length ) )

Index/key variables: i
Accumulator variables: minsum
Iterator variables: i
Python program:
def findKthSmallest ( arr , n , k ) :
    max = 0
    for i in range ( n ) :
        if ( arr [ i ] > max ) :
            max = arr [ i ]
    counter = [ 0 ] * ( max + 1 )
    smallest = 0
    for i in range ( n ) :
        counter [ arr [ i ] ] += 1
    for num in range ( 1 , max + 1 ) :
        if ( counter [ num ] > 0 ) :
            smallest += counter [ num ]
        if ( smallest >= k ) :
            return num
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 1 , 4 , 4 , 20 , 15 , 8 ]
    N = len ( arr )
    K = 5
    print ( findKthSmallest ( arr , N , K ) )

Index/key variables: i, num
Accumulator variables: smallest
Iterator variables: i, num
Python program:
def lexNumbers ( n ) :
    s = [ ]
    for i in range ( 1 , n + 1 ) :
        s . append ( str ( i ) )
    s . sort ( )
    ans = [ ]
    for i in range ( n ) :
        ans . append ( int ( s [ i ] ) )
    for i in range ( n ) :
        print ( ans [ i ] , end = ' ▁ ' )
if __name__ == " _ _ main _ _ " :
    n = 15
    lexNumbers ( n )

Index/key variables: i
Accumulator variables: ans, s
Iterator variables: i
Python program:
N = 4
def func ( a ) :
    for i in range ( N ) :
        if i % 2 == 0 :
            for j in range ( N ) :
                for k in range ( j + 1 , N ) :
                    if a [ i ] [ j ] > a [ i ] [ k ] :
                        temp = a [ i ] [ j ]
                        a [ i ] [ j ] = a [ i ] [ k ]
                        a [ i ] [ k ] = temp
        else :
            for j in range ( N ) :
                for k in range ( j + 1 , N ) :
                    if a [ i ] [ j ] < a [ i ] [ k ] :
                        temp = a [ i ] [ j ]
                        a [ i ] [ j ] = a [ i ] [ k ]
                        a [ i ] [ k ] = temp
    for i in range ( N ) :
        for j in range ( N ) :
            print ( a [ i ] [ j ] , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    a = [ [ 5 , 7 , 3 , 4 ] , [ 9 , 5 , 8 , 2 ] , [ 6 , 3 , 8 , 1 ] , [ 5 , 8 , 9 , 3 ] ]
    func ( a )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
g = [ dict ( ) for i in range ( 200005 ) ]
s = set ( )
ns = set ( )
def dfs ( x ) :
    global s , g , ns
    v = [ ]
    v . clear ( ) ;
    ns . clear ( ) ;
    for it in s :
        if ( x in g and not g [ x ] [ it ] ) :
            v . append ( it ) ;
        else :
            ns . add ( it ) ;
    s = ns ;
    for i in v :
        dfs ( i ) ;
def weightOfMST ( N ) :
    cnt = 0 ;
    for i in range ( 1 , N + 1 ) :
        s . add ( i ) ;
    while ( len ( s ) != 0 ) :
        cnt += 1
        t = list ( s ) [ 0 ]
        s . discard ( t ) ;
        dfs ( t ) ;
    print ( cnt )
if __name__ == ' _ _ main _ _ ' :
    N = 6
    M = 11 ;
    edges = [ [ 1 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 1 , 6 ] , [ 2 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] , [ 2 , 6 ] , [ 3 , 4 ] , [ 3 , 5 ] , [ 3 , 6 ] ] ;
    for i in range ( M ) :
        u = edges [ i ] [ 0 ] ;
        v = edges [ i ] [ 1 ] ;
        g [ u ] [ v ] = 1 ;
        g [ v ] [ u ] = 1 ;
    weightOfMST ( N ) ;

Index/key variables: i, it, u, v, x
Accumulator variables: cnt, ns, s
Iterator variables: i, it
Python program:
def countPairs ( A , B ) :
    n = len ( A )
    A . sort ( )
    B . sort ( )
    ans = 0
    for i in range ( n ) :
        if ( A [ i ] > B [ ans ] ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = [ 30 , 28 , 45 , 22 ]
    B = [ 35 , 25 , 22 , 48 ]
    print ( countPairs ( A , B ) )

Index/key variables: ans, i
Iterator variables: i
Python program:
def maxMod ( arr , n ) :
    maxVal = max ( arr )
    secondMax = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] < maxVal and arr [ i ] > secondMax ) :
            secondMax = arr [ i ]
    return secondMax
arr = [ 2 , 4 , 1 , 5 , 3 , 6 ]
n = len ( arr )
print ( maxMod ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 100005
def Min_Replace ( arr , n , k ) :
    arr . sort ( reverse = False )
    freq = [ 0 for i in range ( MAX ) ]
    p = 0
    freq [ p ] = 1
    for i in range ( 1 , n , 1 ) :
        if ( arr [ i ] == arr [ i - 1 ] ) :
            freq [ p ] += 1
        else :
            p += 1
            freq [ p ] += 1
    freq . sort ( reverse = True )
    ans = 0
    for i in range ( k , p + 1 , 1 ) :
        ans += freq [ i ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 7 , 8 , 2 , 3 , 2 , 3 ]
    n = len ( arr )
    k = 2
    print ( Min_Replace ( arr , n , k ) )

Index/key variables: i, p
Accumulator variables: ans
Iterator variables: i
Python program:
def Segment ( x , l , n ) :
    if ( n == 1 ) :
        return 1
    ans = 2
    for i in range ( 1 , n - 1 ) :
        if ( x [ i ] - l [ i ] > x [ i - 1 ] ) :
            ans += 1
        elif ( x [ i ] + l [ i ] < x [ i + 1 ] ) :
            x [ i ] = x [ i ] + l [ i ]
            ans += 1
    return ans
x = [ 1 , 3 , 4 , 5 , 8 ]
l = [ 10 , 1 , 2 , 2 , 5 ]
n = len ( x )
print ( Segment ( x , l , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def MinimizeleftOverSum ( a , n ) :
    v1 , v2 = [ ] , [ ] ;
    for i in range ( n ) :
        if ( a [ i ] % 2 ) :
            v1 . append ( a [ i ] ) ;
        else :
            v2 . append ( a [ i ] ) ;
    if ( len ( v1 ) > len ( v2 ) ) :
        v1 . sort ( ) ;
        v2 . sort ( ) ;
        x = len ( v1 ) - len ( v2 ) - 1 ;
        sum = 0 ;
        i = 0 ;
        while ( i < x ) :
            sum += v1 [ i ] ;
            i += 1
        return sum ;
    elif ( len ( v2 ) > len ( v1 ) ) :
        v1 . sort ( ) ;
        v2 . sort ( ) ;
        x = len ( v2 ) - len ( v1 ) - 1 ;
        sum = 0 ;
        i = 0 ;
        while ( i < x ) :
            sum += v2 [ i ] ;
            i += 1
        return sum ;
    else :
        return 0 ;
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 2 , 2 , 2 ] ;
    n = len ( a ) ;
    print ( MinimizeleftOverSum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: sum, v1, v2
Iterator variables: i
Python program:
def minOperation ( S , N , K ) :
    if N % K :
        print ( " Not ▁ Possible " )
        return
    count = [ 0 ] * 26
    for i in range ( 0 , N ) :
        count [ ord ( S [ i ] ) - 97 ] += 1
    E = N // K
    greaterE = [ ]
    lessE = [ ]
    for i in range ( 0 , 26 ) :
        if count [ i ] < E :
            lessE . append ( E - count [ i ] )
        else :
            greaterE . append ( count [ i ] - E )
    greaterE . sort ( )
    lessE . sort ( )
    mi = float ( ' inf ' )
    for i in range ( 0 , K + 1 ) :
        set1 , set2 = i , K - i
        if ( len ( greaterE ) >= set1 and len ( lessE ) >= set2 ) :
            step1 , step2 = 0 , 0
            for j in range ( 0 , set1 ) :
                step1 += greaterE [ j ]
            for j in range ( 0 , set2 ) :
                step2 += lessE [ j ]
            mi = min ( mi , max ( step1 , step2 ) )
    print ( mi )
if __name__ == " _ _ main _ _ " :
    S = " accb "
    N = len ( S )
    K = 2
    minOperation ( S , N , K )

Index/key variables: i, j
Accumulator variables: greaterE, lessE, step1, step2
Iterator variables: i, j
Python program:
def minMovesToSort ( arr , n ) :
    moves = 0
    mn = arr [ n - 1 ]
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( arr [ i ] > mn ) :
            moves += arr [ i ] - mn
    return moves
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 5 , 2 , 8 , 4 ]
    n = len ( arr )
    print ( minMovesToSort ( arr , n ) )

Index/key variables: i
Accumulator variables: moves
Iterator variables: i
Python program:
def SieveOfEratosthenes ( n ) :
    prime [ 1 ] = False
    p = 2
    while p * p <= n :
        if prime [ p ] :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = False
        p += 1
def sortPrimes ( arr , n ) :
    SieveOfEratosthenes ( 100005 )
    v = [ ]
    for i in range ( 0 , n ) :
        if prime [ arr [ i ] ] :
            v . append ( arr [ i ] )
    v . sort ( reverse = True )
    j = 0
    for i in range ( 0 , n ) :
        if prime [ arr [ i ] ] :
            arr [ i ] = v [ j ]
            j += 1
    return arr
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 3 , 2 , 6 , 100 , 17 ]
    n = len ( arr )
    prime = [ True ] * 100006
    arr = sortPrimes ( arr , n )
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j, p
Accumulator variables: v
Iterator variables: i
Python program:
def findOptimalPairs ( arr , N ) :
    arr . sort ( reverse = False )
    i = 0
    j = N - 1
    while ( i <= j ) :
        print ( " ( " , arr [ i ] , " , " , arr [ j ] , " ) " , end = " ▁ " )
        i += 1
        j -= 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 9 , 6 , 5 , 1 ]
    N = len ( arr )
    findOptimalPairs ( arr , N )

Index/key variables: i, j
Python program:
def countBits ( a ) :
    count = 0
    while ( a ) :
        if ( a & 1 ) :
            count += 1
        a = a >> 1
    return count
def insertionSort ( arr , aux , n ) :
    for i in range ( 1 , n , 1 ) :
        key1 = aux [ i ]
        key2 = arr [ i ]
        j = i - 1
        while ( j >= 0 and aux [ j ] < key1 ) :
            aux [ j + 1 ] = aux [ j ]
            arr [ j + 1 ] = arr [ j ]
            j = j - 1
        aux [ j + 1 ] = key1
        arr [ j + 1 ] = key2
def sortBySetBitCount ( arr , n ) :
    aux = [ 0 for i in range ( n ) ]
    for i in range ( 0 , n , 1 ) :
        aux [ i ] = countBits ( arr [ i ] )
    insertionSort ( arr , aux , n )
def printArr ( arr , n ) :
    for i in range ( 0 , n , 1 ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    n = len ( arr )
    sortBySetBitCount ( arr , n )
    printArr ( arr , n )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i
Python program:
def countBits ( a ) :
    count = 0
    while ( a ) :
        if ( a & 1 ) :
            count += 1
        a = a >> 1
    return count
def sortBySetBitCount ( arr , n ) :
    count = [ [ ] for i in range ( 32 ) ]
    setbitcount = 0
    for i in range ( n ) :
        setbitcount = countBits ( arr [ i ] )
        count [ setbitcount ] . append ( arr [ i ] )
    for i in range ( 31 , - 1 , - 1 ) :
        v1 = count [ i ]
        for i in range ( len ( v1 ) ) :
            arr [ j ] = v1 [ i ]
            j += 1
def printArr ( arr , n ) :
    print ( * arr )
arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
n = len ( arr )
sortBySetBitCount ( arr , n )
printArr ( arr , n )

Index/key variables: i, j, setbitcount
Accumulator variables: count
Iterator variables: i
Python program:
def generateString ( k1 , k2 , s ) :
    s = list ( s )
    C1s = 0
    C0s = 0
    flag = 0
    pos = [ ]
    for i in range ( len ( s ) ) :
        if ( s [ i ] == '0' ) :
            C0s += 1
            if ( ( i + 1 ) % k1 != 0 and ( i + 1 ) % k2 != 0 ) :
                pos . append ( i )
        else :
            C1s += 1
        if ( C0s >= C1s ) :
            if ( len ( pos ) == 0 ) :
                print ( - 1 )
                flag = 1
                break
            else :
                k = pos [ len ( pos ) - 1 ]
                s [ k ] = '1'
                C0s -= 1
                C1s += 1
                pos = pos [ : - 1 ]
    s = ' ' . join ( s )
    if ( flag == 0 ) :
        print ( s )
if __name__ == ' _ _ main _ _ ' :
    K1 = 2
    K2 = 4
    S = "11000100"
    generateString ( K1 , K2 , S )

Index/key variables: i, k
Accumulator variables: C0s, C1s, pos
Iterator variables: i
Python program:
import math
def maximizeProduct ( N ) :
    MSB = ( int ) ( math . log2 ( N ) )
    X = 1 << MSB
    Y = N - ( 1 << MSB )
    for i in range ( MSB ) :
        if ( not ( N & ( 1 << i ) ) ) :
            X += 1 << i
            Y += 1 << i
    print ( X , Y )
if __name__ == " _ _ main _ _ " :
    N = 45
    maximizeProduct ( N )

Accumulator variables: X, Y
Iterator variables: i
Python program:
from math import log10
def check ( num ) :
    sm = 0
    num2 = num * num
    while ( num ) :
        sm += num % 10
        num //= 10
    sm2 = 0
    while ( num2 ) :
        sm2 += num2 % 10
        num2 //= 10
    return ( ( sm * sm ) == sm2 )
def convert ( s ) :
    val = 0
    s = s [ : : - 1 ]
    cur = 1
    for i in range ( len ( s ) ) :
        val += ( ord ( s [ i ] ) - ord ( '0' ) ) * cur
        cur *= 10
    return val
def generate ( s , len1 , uniq ) :
    if ( len ( s ) == len1 ) :
        if ( check ( convert ( s ) ) ) :
            uniq . add ( convert ( s ) )
        return
    for i in range ( 4 ) :
        generate ( s + chr ( i + ord ( '0' ) ) , len1 , uniq )
def totalNumbers ( L , R ) :
    ans = 0
    max_len = int ( log10 ( R ) ) + 1
    uniq = set ( )
    for i in range ( 1 , max_len + 1 , 1 ) :
        generate ( " " , i , uniq )
    for x in uniq :
        if ( x >= L and x <= R ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    L = 22
    R = 22
    print ( totalNumbers ( L , R ) )

Index/key variables: i
Accumulator variables: ans, cur, num, num2, sm, sm2, val
Iterator variables: i, x
Python program:
def convertXintoY ( X , Y ) :
    while ( Y > X ) :
        if ( Y % 2 == 0 ) :
            Y //= 2
        elif ( Y % 10 == 1 ) :
            Y //= 10
        else :
            break
    if ( X == Y ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    X , Y = 100 , 40021
    convertXintoY ( X , Y )

Accumulator variables: Y
Python program:
def generateString ( K ) :
    s = " "
    for i in range ( 97 , 97 + K , 1 ) :
        s = s + chr ( i ) ;
        for j in range ( i + 1 , 97 + K , 1 ) :
            s += chr ( i )
            s += chr ( j )
    s += chr ( 97 )
    print ( s )
if __name__ == ' _ _ main _ _ ' :
    K = 4
    generateString ( K )

Accumulator variables: s
Iterator variables: i, j
Python program:
def minSteps ( a , n ) :
    prefix_sum = a [ : ]
    for i in range ( 1 , n ) :
        prefix_sum [ i ] += prefix_sum [ i - 1 ]
    mx = - 1
    for subgroupsum in prefix_sum :
        sum = 0
        i = 0
        grp_count = 0
        while i < n :
            sum += a [ i ]
            if sum == subgroupsum :
                grp_count += 1
                sum = 0
            elif sum > subgroupsum :
                grp_count = - 1
                break
            i += 1
        if grp_count > mx :
            mx = grp_count
    return n - mx
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 2 , 1 , 3 ]
    N = len ( A )
    print ( minSteps ( A , N ) )

Index/key variables: i
Accumulator variables: grp_count, sum
Iterator variables: i, subgroupsum
Python program:
def maxSheets ( A , B ) :
    area = A * B
    count = 1
    while ( area % 2 == 0 ) :
        area //= 2
        count *= 2
    return count
A = 5
B = 10
print ( maxSheets ( A , B ) )

Accumulator variables: area, count
Python program:
import sys
def minMoves ( arr ) :
    N = len ( arr )
    if ( N <= 2 ) :
        return 0
    ans = sys . maxsize
    for i in range ( - 1 , 2 ) :
        for j in range ( - 1 , 2 ) :
            num1 = arr [ 0 ] + i
            num2 = arr [ 1 ] + j
            flag = 1
            moves = abs ( i ) + abs ( j )
            for idx in range ( 2 , N ) :
                num = num1 + num2
                if ( abs ( arr [ idx ] - num ) > 1 ) :
                    flag = 0
                else :
                    moves += abs ( arr [ idx ] - num )
                num1 = num2
                num2 = num
            if ( flag ) :
                ans = min ( ans , moves )
    if ( ans == sys . maxsize ) :
        return - 1
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 8 , 9 , 17 , 27 ]
    print ( minMoves ( arr ) )

Index/key variables: idx
Accumulator variables: moves
Iterator variables: i, idx, j
Python program:
def querySum ( arr , N , Q , M ) :
    for i in range ( M ) :
        x = Q [ i ] [ 0 ]
        y = Q [ i ] [ 1 ]
        sum = 0
        while ( x < N ) :
            sum += arr [ x ]
            x += y
        print ( sum , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 7 , 5 , 4 ] ;
    Q = [ [ 2 , 1 ] , [ 3 , 2 ] ]
    N = len ( arr )
    M = len ( Q )
    querySum ( arr , N , Q , M )

Index/key variables: i, x
Accumulator variables: sum
Iterator variables: i
Python program:
from collections import defaultdict
def countOfSubarray ( arr , N ) :
    mp = defaultdict ( lambda : 0 )
    answer = 0
    sum = 0
    mp [ 1 ] += 1
    for i in range ( N ) :
        sum += arr [ i ]
        answer += mp [ sum - i ]
        mp [ sum - i ] += 1
    print ( answer )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 2 , 1 , 2 , - 2 , 2 , 4 ]
    N = len ( arr )
    countOfSubarray ( arr , N )

Index/key variables: i
Accumulator variables: answer, sum
Iterator variables: i
Python program:
def checkDigits ( n ) :
    while True :
        r = n % 10
        if ( r == 3 or r == 4 or r == 6 or r == 7 or r == 9 ) :
            return False
        n //= 10
        if n == 0 :
            break
    return True
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    for i in range ( 2 , n + 1 ) :
        if i * i > n :
            break
        if ( n % i == 0 ) :
            return False
    return True
def isAllPrime ( n ) :
    return isPrime ( n ) and checkDigits ( n )
if __name__ == ' _ _ main _ _ ' :
    N = 101
    if ( isAllPrime ( N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: n
Iterator variables: i
Python program:
def countEvenSum ( low , high , k ) :
    even_count = high / 2 - ( low - 1 ) / 2
    odd_count = ( high + 1 ) / 2 - low / 2
    even_sum = 1
    odd_sum = 0
    for i in range ( 0 , k ) :
        prev_even = even_sum
        prev_odd = odd_sum
        even_sum = ( ( prev_even * even_count ) + ( prev_odd * odd_count ) )
        odd_sum = ( ( prev_even * odd_count ) + ( prev_odd * even_count ) )
    print ( int ( even_sum ) )
low = 4 ;
high = 5 ;
K = 3 ;
countEvenSum ( low , high , K ) ;

Iterator variables: i
Python program:
def findShifts ( A , N ) :
    shift = [ 0 for i in range ( N ) ]
    for i in range ( N ) :
        if ( i == A [ i ] - 1 ) :
            shift [ i ] = 0
        else :
            shift [ i ] = ( A [ i ] - 1 - i + N ) % N
    for i in range ( N ) :
        print ( shift [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 4 , 3 , 2 , 5 ]
    N = len ( arr )
    findShifts ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def constructmatrix ( N ) :
    check = bool ( True )
    for i in range ( N ) :
        for j in range ( N ) :
            if ( i == j ) :
                print ( 1 , end = " ▁ " )
            elif ( check ) :
                print ( 2 , end = " ▁ " )
                check = bool ( False )
            else :
                print ( - 2 , end = " ▁ " )
                check = bool ( True )
        print ( )
N = 5
constructmatrix ( 5 )

Iterator variables: i, j
Python program:
def check ( unit_digit , X ) :
    for times in range ( 1 , 11 ) :
        digit = ( X * times ) % 10
        if ( digit == unit_digit ) :
            return times
    return - 1
def getNum ( N , X ) :
    unit_digit = N % 10
    times = check ( unit_digit , X )
    if ( times == - 1 ) :
        return times
    else :
        if ( N >= ( times * X ) ) :
            return times
        else :
            return - 1
N = 58
X = 7
print ( getNum ( N , X ) )

Iterator variables: times
Python program:
def getLargestString ( s , k ) :
    frequency_array = [ 0 ] * 26
    for i in range ( len ( s ) ) :
        frequency_array [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    ans = " "
    i = 25
    while i >= 0 :
        if ( frequency_array [ i ] > k ) :
            temp = k
            st = chr ( i + ord ( ' a ' ) )
            while ( temp > 0 ) :
                ans += st
                temp -= 1
            frequency_array [ i ] -= k
            j = i - 1
            while ( frequency_array [ j ] <= 0 and j >= 0 ) :
                j -= 1
            if ( frequency_array [ j ] > 0 and j >= 0 ) :
                str1 = chr ( j + ord ( ' a ' ) )
                ans += str1
                frequency_array [ j ] -= 1
            else :
                break
        elif ( frequency_array [ i ] > 0 ) :
            temp = frequency_array [ i ]
            frequency_array [ i ] -= temp
            st = chr ( i + ord ( ' a ' ) )
            while ( temp > 0 ) :
                ans += st
                temp -= 1
        else :
            i -= 1
    return ans
if __name__ == " _ _ main _ _ " :
    S = " xxxxzza "
    k = 3
    print ( getLargestString ( S , k ) )

Index/key variables: i, j
Accumulator variables: ans, temp
Iterator variables: i
Python program:
def minOperations ( a , b , n ) :
    minA = min ( a ) ;
    for x in range ( minA , - 1 , - 1 ) :
        check = True ;
        operations = 0 ;
        for i in range ( n ) :
            if ( x % b [ i ] == a [ i ] % b [ i ] ) :
                operations += ( a [ i ] - x ) / b [ i ] ;
            else :
                check = False ;
                break ;
        if ( check ) :
            return operations ;
    return - 1 ;
if __name__ == ' _ _ main _ _ ' :
    N = 5 ;
    A = [ 5 , 7 , 10 , 5 , 15 ] ;
    B = [ 2 , 2 , 1 , 3 , 5 ] ;
    print ( int ( minOperations ( A , B , N ) ) ) ;

Index/key variables: i
Accumulator variables: operations
Iterator variables: i, x
Boolean variables: check
Python program:
def getLargestSum ( N ) :
    max_sum = 0
    for i in range ( 1 , N + 1 ) :
        for j in range ( i + 1 , N + 1 , 1 ) :
            if ( i * j % ( i + j ) == 0 ) :
                max_sum = max ( max_sum , i + j )
    return max_sum
if __name__ == ' _ _ main _ _ ' :
    N = 25
    max_sum = getLargestSum ( N )
    print ( max_sum )

Iterator variables: i, j
Python program:
def maxSubArraySum ( a , size ) :
    max_so_far = - 10 ** 9
    max_ending_here = 0
    for i in range ( size ) :
        max_ending_here = max_ending_here + a [ i ]
        if ( max_ending_here < 0 ) :
            max_ending_here = 0
        if ( max_so_far < max_ending_here ) :
            max_so_far = max_ending_here
    return max_so_far
def maxSum ( a , n ) :
    S = 0
    for i in range ( n ) :
        S += a [ i ]
    X = maxSubArraySum ( a , n )
    return 2 * X - S
if __name__ == ' _ _ main _ _ ' :
    a = [ - 1 , - 2 , - 3 ]
    n = len ( a )
    max_sum = maxSum ( a , n )
    print ( max_sum )

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