dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findOptimalSolution ( a , N ) :
    a . sort ( )
    points = 0
    for i in range ( 0 , N ) :
        points += a [ i ] * i
    return points
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 4 , 2 , 3 , 9 ]
    N = len ( a )
    print ( findOptimalSolution ( a , N ) )

Index/key variables: i
Accumulator variables: points
Iterator variables: i
Python program:
def number_of_tower ( house , r , n ) :
    house . sort ( )
    numOfTower = 0
    i = 0
    while ( i < n ) :
        numOfTower += 1
        loc = house [ i ] + r
        while ( i < n and house [ i ] <= loc ) :
            i += 1
        i -= 1
        loc = house [ i ] + r
        while ( i < n and house [ i ] <= loc ) :
            i += 1
    return numOfTower
if __name__ == " _ _ main _ _ " :
    house = [ 7 , 2 , 4 , 6 , 5 , 9 , 12 , 11 ]
    r = 2
    n = len ( house )
    print ( number_of_tower ( house , r , n ) )

Index/key variables: i
Accumulator variables: numOfTower
Python program:
def isAlphabaticOrder ( s ) :
    n = len ( s )
    c = [ s [ i ] for i in range ( len ( s ) ) ]
    c . sort ( reverse = False )
    for i in range ( n ) :
        if ( c [ i ] != s [ i ] ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    s = " aabbbcc "
    if ( isAlphabaticOrder ( s ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def printOrder ( arr , n , k ) :
    a = arr [ 0 : k ] ;
    a . sort ( ) ;
    b = arr [ k : n ] ;
    b . sort ( ) ;
    b . reverse ( ) ;
    return a + b ;
arr = [ 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , - 1 ] ;
k = 4 ;
n = len ( arr ) ;
arr = printOrder ( arr , n , k ) ;
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " ) ;

Index/key variables: i
Iterator variables: i
Python program:
def sortStack ( Input ) :
    tmpStack = [ ]
    while len ( Input ) != 0 :
        tmp = Input [ - 1 ]
        Input . pop ( )
        while len ( tmpStack ) != 0 and tmpStack [ - 1 ] > tmp :
            Input . append ( tmpStack [ - 1 ] )
            tmpStack . pop ( )
        tmpStack . append ( tmp )
    return tmpStack
def sortedMerge ( s1 , s2 ) :
    res = [ ]
    while len ( s1 ) != 0 :
        res . append ( s1 [ - 1 ] )
        s1 . pop ( )
    while len ( s2 ) != 0 :
        res . append ( s2 [ - 1 ] )
        s2 . pop ( )
    return sortStack ( res )
s1 = [ ]
s2 = [ ]
s1 . append ( 34 )
s1 . append ( 3 )
s1 . append ( 31 )
s2 . append ( 1 )
s2 . append ( 12 )
s2 . append ( 23 )
tmpStack = [ ]
tmpStack = sortedMerge ( s1 , s2 )
print ( " Sorted ▁ and ▁ merged ▁ stack ▁ : " )
while len ( tmpStack ) != 0 :
    print ( tmpStack [ - 1 ] , end = " ▁ " )
    tmpStack . pop ( )

Accumulator variables: Input, res, tmpStack
Python program:
def lexicographicSubConcat ( s ) :
    n = len ( s ) ;
    sub_count = ( n * ( n + 1 ) ) // 2 ;
    arr = [ 0 ] * sub_count ;
    index = 0 ;
    for i in range ( n ) :
        for j in range ( 1 , n - i + 1 ) :
            arr [ index ] = s [ i : i + j ] ;
            index += 1 ;
    arr . sort ( ) ;
    res = " " ;
    for i in range ( sub_count ) :
        res += arr [ i ] ;
    return res ;
s = " abc " ;
print ( lexicographicSubConcat ( s ) ) ;

Index/key variables: i, index
Accumulator variables: res
Iterator variables: i, j
Python program:
MAX_CHAR = 26
def sortString ( str ) :
    charCount = [ 0 for i in range ( MAX_CHAR ) ]
    for i in range ( 0 , len ( str ) , 1 ) :
        charCount [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 0 , MAX_CHAR , 1 ) :
        for j in range ( 0 , charCount [ i ] , 1 ) :
            print ( chr ( ord ( ' a ' ) + i ) , end = " " )
if __name__ == ' _ _ main _ _ ' :
    s = " geeksforgeeks "
    sortString ( s )

Index/key variables: i
Iterator variables: i, j
Python program:
class prefix :
    def __init__ ( self , sum , index ) :
        self . sum = sum
        self . index = index
def findSubArray ( arr , n ) :
    start , end , min_diff = None , None , float ( ' inf ' )
    pre_sum = [ None ] * ( n + 1 )
    pre_sum [ 0 ] = prefix ( 0 , - 1 )
    for i in range ( 1 , n + 1 ) :
        pre_sum [ i ] = prefix ( pre_sum [ i - 1 ] . sum + arr [ i - 1 ] , i - 1 )
    pre_sum . sort ( key = lambda x : x . sum )
    for i in range ( 1 , n + 1 ) :
        diff = pre_sum [ i ] . sum - pre_sum [ i - 1 ] . sum
        if min_diff > diff :
            min_diff = diff
            start = pre_sum [ i - 1 ] . index
            end = pre_sum [ i ] . index
    return ( start + 1 , end )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , - 4 , - 1 , 6 ]
    n = len ( arr )
    point = findSubArray ( arr , n )
    print ( " Subarray ▁ starting ▁ from " , point [ 0 ] , " to " , point [ 1 ] )

Index/key variables: i
Iterator variables: i
Class/struct names: prefix
Python program:
MIN_MERGE = 32
def calcMinRun ( n ) :
    r = 0
    while n >= MIN_MERGE :
        r |= n & 1
        n >>= 1
    return n + r
def insertionSort ( arr , left , right ) :
    for i in range ( left + 1 , right + 1 ) :
        j = i
        while j > left and arr [ j ] < arr [ j - 1 ] :
            arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]
            j -= 1
def merge ( arr , l , m , r ) :
    len1 , len2 = m - l + 1 , r - m
    left , right = [ ] , [ ]
    for i in range ( 0 , len1 ) :
        left . append ( arr [ l + i ] )
    for i in range ( 0 , len2 ) :
        right . append ( arr [ m + 1 + i ] )
    i , j , k = 0 , 0 , l
    while i < len1 and j < len2 :
        if left [ i ] <= right [ j ] :
            arr [ k ] = left [ i ]
            i += 1
        else :
            arr [ k ] = right [ j ]
            j += 1
        k += 1
    while i < len1 :
        arr [ k ] = left [ i ]
        k += 1
        i += 1
    while j < len2 :
        arr [ k ] = right [ j ]
        k += 1
        j += 1
def timSort ( arr ) :
    n = len ( arr )
    minRun = calcMinRun ( n )
    for start in range ( 0 , n , minRun ) :
        end = min ( start + minRun - 1 , n - 1 )
        insertionSort ( arr , start , end )
    size = minRun
    while size < n :
        for left in range ( 0 , n , 2 * size ) :
            mid = min ( n - 1 , left + size - 1 )
            right = min ( ( left + 2 * size - 1 ) , ( n - 1 ) )
            if mid < right :
                merge ( arr , left , mid , right )
        size = 2 * size
if __name__ == " _ _ main _ _ " :
    arr = [ - 2 , 7 , 15 , - 14 , 0 , 15 , 0 , 7 , - 7 , - 4 , - 13 , 5 , 8 , - 14 , 12 ]
    print ( " Given ▁ Array ▁ is " )
    print ( arr )
    timSort ( arr )
    print ( " After ▁ Sorting ▁ Array ▁ is " )
    print ( arr )

Index/key variables: i, j, k
Accumulator variables: n, r, right
Iterator variables: i, left, start
Python program:
def pendulumArrangement ( arr , n ) :
    arr . sort ( )
    op = [ 0 ] * n
    mid = int ( ( n - 1 ) / 2 )
    j = 1
    i = 1
    op [ mid ] = arr [ 0 ]
    for i in range ( 1 , mid + 1 ) :
        op [ mid + i ] = arr [ j ]
        j += 1
        op [ mid - i ] = arr [ j ]
        j += 1
    if ( int ( n % 2 ) == 0 ) :
        op [ mid + i ] = arr [ j ]
    print ( " Pendulum ▁ arrangement : " )
    for i in range ( 0 , n ) :
        print ( op [ i ] , end = " ▁ " )
arr = [ 14 , 6 , 19 , 21 , 12 ]
n = len ( arr )
pendulumArrangement ( arr , n )

Index/key variables: i, j, mid
Iterator variables: i
Python program:
def TotalPerfectPowerSum ( L , R ) :
    pows = [ ]
    pows . append ( 0 )
    pows . append ( 1 )
    for p in range ( 2 , 25 ) :
        num = 2
        while ( ( int ) ( pow ( num , p ) + 0.5 ) <= R ) :
            pows . append ( ( int ) ( pow ( num , p ) + 0.5 ) )
            num = num + 1
    ok = [ 0 for _ in range ( R + 1 ) ]
    for i in range ( 0 , int ( len ( pows ) ) ) :
        for j in range ( 0 , len ( pows ) ) :
            if ( pows [ i ] + pows [ j ] <= R and pows [ i ] + pows [ j ] >= L ) :
                ok [ pows [ i ] + pows [ j ] ] = 1
    for i in range ( 0 , R + 1 ) :
        ok [ i ] += ok [ i - 1 ]
    return ok [ R ] - ok [ L - 1 ]
if __name__ == " _ _ main _ _ " :
    L = 5
    R = 8
    print ( TotalPerfectPowerSum ( L , R ) )

Index/key variables: R, i, j
Accumulator variables: pows
Iterator variables: i, j, p
Python program:
import sys
class Node :
    def __init__ ( self , val ) :
        self . val = val
        self . left = None
        self . right = None
def minAbsDiff ( root ) :
    minDiff = [ 0 ] * ( 1 )
    minDiff [ 0 ] = sys . maxsize
    postOrder ( root )
    preOrder ( root , minDiff )
    return minDiff [ 0 ]
def postOrder ( root ) :
    if ( root == None ) :
        return 0
    root . val += postOrder ( root . left ) + postOrder ( root . right )
    return root . val
def preOrder ( root , minDiff ) :
    if ( root == None ) :
        return
    leftDiff = abs ( root . left . val - ( root . val - root . left . val ) )
    rightDiff = abs ( root . right . val - ( root . val - root . right . val ) )
    minDiff [ 0 ] = min ( minDiff [ 0 ] , min ( leftDiff , rightDiff ) )
    return
root = Node ( 1 )
root . left = Node ( 2 )
root . right = Node ( 3 )
root . left . left = Node ( 4 )
root . left . right = Node ( 5 )
root . right . left = Node ( 6 )
root . right . right = Node ( 7 )
print ( minAbsDiff ( root ) )

Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def lengthUtil ( root , maximum , minimum , curr = 0 ) :
    if ( root == None ) :
        return
    lengthUtil ( root . left , maximum , minimum , curr - 1 )
    if ( minimum [ 0 ] > curr ) :
        minimum [ 0 ] = curr
    if ( maximum [ 0 ] < curr ) :
        maximum [ 0 ] = curr
    lengthUtil ( root . right , maximum , minimum , curr + 1 )
def getLength ( root ) :
    maximum = [ 0 ]
    minimum = [ 0 ]
    lengthUtil ( root , maximum , minimum , 0 )
    return ( abs ( minimum [ 0 ] ) + maximum [ 0 ] ) + 1
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 7 )
    root . left = newNode ( 6 )
    root . right = newNode ( 5 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 3 )
    root . right . left = newNode ( 2 )
    root . right . right = newNode ( 1 )
    print ( getLength ( root ) )

Class/struct names: newNode
Python program:
def findMaximumSumWithMflips ( arr , N , M ) :
    pq = [ ]
    sum = 0
    for i in range ( N ) :
        pq . append ( arr [ i ] )
        sum += arr [ i ]
        pq . sort ( )
    while ( M > 0 ) :
        sum -= pq [ 0 ]
        temp = - 1 * pq [ 0 ]
        pq = pq [ 1 : ]
        sum += temp
        pq . append ( temp )
        pq . sort ( )
        M -= 1
    print ( sum )
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 3 , 7 , - 1 , - 5 , - 3 ]
    N = len ( arr )
    M = 4
    findMaximumSumWithMflips ( arr , N , M )

Index/key variables: i
Accumulator variables: M, pq, sum
Iterator variables: i
Python program:
def miniOperToMakeAllEleEqual ( arr , n , k ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    if ( sum % n ) :
        print ( - 1 )
        return
    valueAfterDivision = sum // n
    count = 0
    for i in range ( n ) :
        if ( abs ( valueAfterDivision - arr [ i ] ) % k != 0 ) :
            print ( - 1 )
            return
        count += abs ( valueAfterDivision - arr [ i ] ) // k
    print ( count // 2 )
if __name__ == ' _ _ main _ _ ' :
    n = 3
    k = 3
    arr = [ 5 , 8 , 11 ]
    miniOperToMakeAllEleEqual ( arr , n , k )

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i
Python program:
def minOperations ( a ) :
    res = 100000000000
    N = len ( a )
    for r in range ( 0 , 2 ) :
        sum = 0
        ans = 0
        for i in range ( 0 , N ) :
            sum += a [ i ]
            if ( ( i + r ) % 2 ) :
                if ( sum <= 0 ) :
                    ans += - sum + 1
                    sum = 1
            else :
                if ( sum >= 0 ) :
                    ans += sum + 1 ;
                    sum = - 1 ;
        res = min ( res , ans )
    print ( res )
a = [ 1 , - 3 , 1 , 0 ]
minOperations ( a ) ;

Index/key variables: i
Accumulator variables: ans, sum
Iterator variables: i, r
Python program:
def Print ( a , b ) :
    minProd = 0
    for i in range ( len ( a ) ) :
        print ( a [ i ] , end = " ▁ " )
    print ( ) ;
    for i in range ( len ( b ) ) :
        print ( b [ i ] , end = " ▁ " )
        minProd += a [ i ] * b [ i ]
    print ( )
    print ( minProd )
def reverse ( left , right , arr ) :
    while ( left < right ) :
        temp = arr [ left ]
        arr [ left ] = arr [ right ]
        arr [ right ] = temp
        left += 1
        right -= 1
def minimumProdArray ( a , b , l ) :
    total = 0
    for i in range ( len ( a ) ) :
        total += a [ i ] * b [ i ]
    Min = 2147483647
    first = 0 ;
    second = 0 ;
    for i in range ( len ( a ) ) :
        left = i - 1 ;
        right = i + 1 ;
        total1 = total ;
        while ( left >= 0 and right < len ( a ) ) :
            total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ;
            total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ;
            if ( Min >= total1 ) :
                Min = total1
                first = left
                second = right
            left -= 1
            right += 1
    for i in range ( len ( a ) ) :
        left = i
        right = i + 1
        total1 = total
        while ( left >= 0 and right < len ( a ) ) :
            total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ]
            total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ]
            if ( Min >= total1 ) :
                Min = total1
                first = left
                second = right
            left -= 1
            right += 1
    if ( Min < total ) :
        reverse ( first , second , a )
        Print ( a , b )
    else :
        Print ( a , b )
n = 4 ;
a = [ 2 , 3 , 1 , 5 ]
b = [ 8 , 2 , 4 , 3 ]
minimumProdArray ( a , b , n )

Index/key variables: i, left, right
Accumulator variables: minProd, total, total1
Iterator variables: i
Python program:
def MaxCollection ( S , P , Q ) :
    maxstr = [ i for i in ( " ab " if P >= Q else " ba " ) ]
    minstr = [ i for i in ( " ba " if P >= Q else " ab " ) ]
    maxp = max ( P , Q )
    minp = min ( P , Q )
    cost = 0
    stack1 = [ ]
    s = [ i for i in S ]
    for ch in s :
        if ( len ( stack1 ) > 0 and ( stack1 [ - 1 ] == maxstr [ 0 ] and ch == maxstr [ 1 ] ) ) :
            del stack1 [ - 1 ]
            cost += maxp
        else :
            stack1 . append ( ch )
    sb = " "
    while ( len ( stack1 ) > 0 ) :
        sb += stack1 [ - 1 ]
        del stack1 [ - 1 ]
    sb = sb [ : : - 1 ]
    remstr = sb
    for ch in remstr :
        if ( len ( stack1 ) > 0 and ( stack1 [ - 1 ] == minstr [ 0 ] and ch == minstr [ 1 ] ) ) :
            del stack1 [ - 1 ]
            cost += minp
        else :
            stack1 . append ( ch )
    return cost
if __name__ == ' _ _ main _ _ ' :
    S = " cbbaabbaab "
    P = 6 ;
    Q = 4 ;
    print ( MaxCollection ( S , P , Q ) ) ;

Accumulator variables: cost, sb, stack1
Iterator variables: ch
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def fillSet ( root , s , hd ) :
    if ( not root ) :
        return
    fillSet ( root . left , s , hd - 1 )
    s . add ( hd )
    fillSet ( root . right , s , hd + 1 )
def verticalWidth ( root ) :
    s = set ( )
    fillSet ( root , s , 0 )
    return len ( s )
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . left . left = Node ( 4 )
    root . left . right = Node ( 5 )
    root . right . left = Node ( 6 )
    root . right . right = Node ( 7 )
    root . right . left . right = Node ( 8 )
    root . right . right . right = Node ( 9 )
    print ( verticalWidth ( root ) )

Class/struct names: Node
Python program:
def minKBitFlips ( A , K , N ) :
    flip = [ ]
    count = 0
    for i in range ( N ) :
        if ( len ( flip ) > 0 and ( i - flip [ 0 ] >= K ) ) :
            flip . pop ( 0 )
        if ( A [ i ] % 2 == len ( flip ) % 2 ) :
            if ( i + K - 1 >= N ) :
                return - 1
            flip . append ( i )
            count += 1
    return count
A = [ 0 , 1 , 0 ]
N = len ( A )
K = 1
ans = minKBitFlips ( A , K , 3 )
print ( ans )

Index/key variables: i
Accumulator variables: count, flip
Iterator variables: i
Python program:
def minKBitFlips ( A , K ) :
    temp = [ 0 ] * len ( A )
    count = 0
    flip = 0
    for i in range ( len ( A ) ) :
        flip ^= temp [ i ]
        if ( A [ i ] == flip ) :
            count += 1
            if ( i + K > len ( A ) ) :
                return - 1
            flip ^= 1
            if ( i + K < len ( A ) ) :
                temp [ i + K ] ^= 1
    return count
A = [ 0 , 1 , 0 ]
K = 1
ans = minKBitFlips ( A , K )
print ( ans )

Index/key variables: i
Accumulator variables: count, flip
Iterator variables: i
Python program:
def findKthElement ( N , K ) :
    v = [ ]
    for i in range ( 1 , N + 1 ) :
        if ( i % 2 == 0 ) :
            v . append ( i )
    for i in range ( 1 , N + 1 ) :
        if ( i % 2 != 0 ) :
            v . append ( i )
    print ( v [ K - 1 ] )
if __name__ == " _ _ main _ _ " :
    N = 10
    K = 3
    findKthElement ( N , K )

Accumulator variables: v
Iterator variables: i
Python program:
from bisect import bisect_right
def countminOpsToConstructAString ( A , B ) :
    N = len ( A )
    i = 0
    mp = [ [ ] for i in range ( 26 ) ]
    for i in range ( N ) :
        mp [ ord ( A [ i ] ) - ord ( ' a ' ) ] . append ( i )
    previous = - 1
    ans , i = 1 , 0
    while i < len ( B ) :
        ch = B [ i ]
        if ( len ( mp [ ord ( ch ) - ord ( ' a ' ) ] ) == 0 ) :
            print ( - 1 )
            return
        it = bisect_right ( mp [ ord ( ch ) - ord ( ' a ' ) ] , previous )
        if ( it == len ( mp [ ord ( ch ) - ord ( ' a ' ) ] ) ) :
            previous = - 1
            ans += 1
            continue
        previous = mp [ ord ( ch ) - ord ( ' a ' ) ] [ it ]
        i += 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    A , B = " abc " , " abac "
    countminOpsToConstructAString ( A , B )

Index/key variables: i, it
Accumulator variables: ans
Iterator variables: i
Python program:
from collections import deque
from sys import maxsize
INT_MIN = - maxsize
class Node :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def isSorted ( root : Node , level : int ) -> bool :
    if root is None :
        return True
    prevVal = INT_MIN
    currLevel = 0
    currNode = Node ( 0 )
    q = deque ( )
    q . append ( ( root , 0 ) )
    while q :
        currNode = q [ 0 ] [ 0 ]
        currLevel = q [ 0 ] [ 1 ]
        q . popleft ( )
        if currLevel == level :
            if prevVal <= currNode . key :
                prevVal = currNode . key
            else :
                return False
        if currNode . left :
            q . append ( ( currNode . left , currLevel - 1 ) )
        if currNode . right :
            q . append ( ( currNode . right , currLevel + 1 ) )
    return True
if __name__ == " _ _ main _ _ " :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 5 )
    root . left . left = Node ( 7 )
    root . left . right = Node ( 4 )
    root . left . right . left = Node ( 6 )
    level = - 1
    if isSorted ( root , level ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: q
Class/struct names: Node
Python program:
def minimumStepReqArr ( arr , N ) :
    cntStep = 0
    N += 1
    i = 31
    while ( i >= 0 ) :
        if ( N & ( 1 << i ) ) :
            cntStep += 1
        i -= 1
    return cntStep
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 ]
    N = len ( arr )
    print ( minimumStepReqArr ( arr , N ) )

Accumulator variables: cntStep, i
Python program:
def minOpsToEmptyString ( S , N ) :
    one = 0
    zero = 0
    x0 = 0
    x1 = 0
    for i in range ( N ) :
        if ( S [ i ] == '0' ) :
            x0 += 1
            x1 = 0
        else :
            x1 += 1
            x0 = 0
        zero = max ( x0 , zero )
        one = max ( x1 , one )
    print ( max ( one , zero ) )
if __name__ == " _ _ main _ _ " :
    S = "0100100111"
    N = len ( S )
    minOpsToEmptyString ( S , N )

Index/key variables: i
Accumulator variables: x0, x1
Iterator variables: i
Python program:
def ReverseSwap ( mat , n ) :
    lowerEle = [ [ ] for i in range ( n ) ]
    upperEle = [ [ ] for i in range ( n ) ]
    index = 0
    for i in range ( n ) :
        for j in range ( n ) :
            index = abs ( i - j )
            if ( i == j ) :
                continue
            elif ( j < i ) :
                lowerEle [ index ] . append ( mat [ i ] [ j ] )
            else :
                upperEle [ index ] . append ( mat [ i ] [ j ] )
    for i in range ( n ) :
        for j in range ( n ) :
            index = abs ( i - j )
            if ( i == j ) :
                continue
            elif ( j < i ) :
                mat [ i ] [ j ] = upperEle [ index ] [ - 1 ]
                del upperEle [ index ] [ - 1 ]
            else :
                mat [ i ] [ j ] = lowerEle [ index ] [ - 1 ]
                del lowerEle [ index ] [ - 1 ]
    for i in range ( n ) :
        for j in range ( n ) :
            print ( mat [ i ] [ j ] , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 2 ] , [ 4 , 5 ] ]
    N = len ( mat )
    ReverseSwap ( mat , N )

Index/key variables: i, index, j
Iterator variables: i, j
Python program:
def primePower ( X ) :
    primePow = [ ]
    for i in range ( 2 , X + 1 ) :
        if i * i > X + 1 :
            break
        if ( X % i == 0 ) :
            p = 1
            while ( X % i == 0 ) :
                X //= i
                p *= i
            primePow . append ( p )
    if ( X > 1 ) :
        primePow . append ( X )
    return primePow
def getSum ( ar ) :
    sum = 0
    for i in ar :
        sum += i
    return sum
def getMinSum ( pos , arr , primePow ) :
    if ( pos == len ( primePow ) ) :
        return getSum ( arr )
    res = 10 ** 9
    for i in range ( len ( arr ) ) :
        arr [ i ] *= primePow [ pos ]
        res = min ( res , getMinSum ( pos + 1 , arr , primePow ) )
        arr [ i ] //= primePow [ pos ]
    return res
def minimumSumWithGivenLCM ( k , x ) :
    primePow = primePower ( x )
    n = len ( primePow )
    sum = 0
    if ( n <= k ) :
        for i in primePow :
            sum += i
        sum += k - n
    else :
        arr = [ 1 ] * ( k )
        sum = getMinSum ( 0 , arr , primePow )
    return sum
if __name__ == ' _ _ main _ _ ' :
    k = 3
    x = 210
    print ( minimumSumWithGivenLCM ( k , x ) )

Index/key variables: i, pos
Accumulator variables: X, p, primePow, sum
Iterator variables: i
Python program:
def findMinOperationsReqEmpStr ( str ) :
    cntOne = 0
    cntZero = 0
    for element in str :
        if element == '0' :
            if cntOne > 0 :
                cntOne = cntOne - 1
            cntZero = cntZero + 1
        else :
            if cntZero > 0 :
                cntZero = cntZero - 1
            cntOne = cntOne + 1
    return cntOne + cntZero
if __name__ == " _ _ main _ _ " :
    str = "0100100111"
    print ( findMinOperationsReqEmpStr ( str ) )

Iterator variables: element
Python program:
def countChanges ( mat ) :
    n = len ( mat )
    m = len ( mat [ 0 ] )
    ans = 0
    for j in range ( m - 1 ) :
        if ( mat [ n - 1 ] [ j ] != ' R ' ) :
            ans += 1
    for i in range ( n - 1 ) :
        if ( mat [ i ] [ m - 1 ] != ' D ' ) :
            ans += 1
    return ans
arr = [ [ ' R ' , ' R ' , ' R ' , ' D ' ] , [ ' D ' , ' D ' , ' D ' , ' R ' ] , [ ' R ' , ' D ' , ' R ' , ' F ' ] ]
cnt = countChanges ( arr )
print ( cnt )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j