dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def colMaxDiff ( mat ) :
    max_diff = 0
    for i in range ( N ) :
        max_val = mat [ 0 ] [ i ]
        min_val = mat [ 0 ] [ i ]
        for j in range ( 1 , N ) :
            max_val = max ( max_val , mat [ j ] [ i ] )
            min_val = min ( min_val , mat [ j ] [ i ] )
        max_diff = max ( max_diff , max_val - min_val )
    return max_diff
if __name__ == " _ _ main _ _ " :
    mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 5 , 3 , 5 , 4 , 0 ] , [ 5 , 6 , 7 , 8 , 9 ] , [ 0 , 6 , 3 , 4 , 12 ] , [ 9 , 7 , 12 , 4 , 3 ] ]
    print ( " Max ▁ difference ▁ : " , colMaxDiff ( mat ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def search ( ar , size ) :
    a = 0
    b = size - 1
    mid = 0
    while b > a + 1 :
        mid = ( a + b ) // 2
        if ( ar [ a ] - a ) != ( ar [ mid ] - mid ) :
            b = mid
        elif ( ar [ b ] - b ) != ( ar [ mid ] - mid ) :
            a = mid
    return ar [ a ] + 1
a = [ 1 , 2 , 3 , 4 , 5 , 6 , 8 ]
n = len ( a )
print ( " Missing ▁ number : " , search ( a , n ) )

Index/key variables: a, b, mid
Python program:
def deleteElement ( A , L , R , N ) :
    j = 0
    for i in range ( N ) :
        if i <= L or i >= R :
            A [ j ] = A [ i ]
            j += 1
    return j
if __name__ == " _ _ main _ _ " :
    A = [ 5 , 8 , 11 , 15 , 26 , 14 , 19 , 17 , 10 , 14 ]
    L , R = 2 , 7
    n = len ( A )
    res_size = deleteElement ( A , L , R , n )
    for i in range ( res_size ) :
        print ( A [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i
Python program:
def findInd ( preSum , n , val ) :
    l = 0
    h = n - 1
    ans = - 1
    while ( l <= h ) :
        mid = ( l + h ) // 2
        if preSum [ mid ] [ 0 ] <= val :
            ans = mid
            l = mid + 1
        else :
            h = mid - 1
    return ans
def LongestSub ( arr , n , x ) :
    for i in range ( n ) :
        arr [ i ] -= x
    maxlen = 0
    preSum = [ ]
    total = 0
    minInd = [ None ] * n
    for i in range ( n ) :
        total += arr [ i ]
        preSum . append ( ( total , i ) )
    preSum = sorted ( preSum )
    minInd [ 0 ] = preSum [ 0 ] [ 1 ]
    for i in range ( 1 , n ) :
        minInd [ i ] = min ( minInd [ i - 1 ] , preSum [ i ] [ 1 ] )
    total = 0
    for i in range ( n ) :
        total += arr [ i ]
        if total >= 0 :
            maxlen = i + 1
        else :
            ind = findInd ( preSum , n , total )
            if ( ind != - 1 ) & ( minInd [ ind ] < i ) :
                maxlen = max ( maxlen , i - minInd [ ind ] )
    return maxlen
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 2 , 1 , 6 , - 3 ]
    n = len ( arr )
    x = 3
    print ( LongestSub ( arr , n , x ) )

Index/key variables: i, ind, mid
Accumulator variables: preSum, total
Iterator variables: i
Python program:
def findmissing ( ar , N ) :
    l = 0
    r = N - 1
    while ( l <= r ) :
        mid = ( l + r ) / 2
        mid = int ( mid )
        if ( ar [ mid ] != mid + 1 and ar [ mid - 1 ] == mid ) :
            return ( mid + 1 )
        elif ( ar [ mid ] != mid + 1 ) :
            r = mid - 1
        else :
            l = mid + 1
    return ( - 1 )
def main ( ) :
    ar = [ 1 , 2 , 3 , 4 , 5 , 7 , 8 ]
    N = len ( ar )
    res = findmissing ( ar , N )
    print ( res )
if __name__ == " _ _ main _ _ " :
    main ( )

Index/key variables: mid
Python program:
import math
def findFirst ( arr , n , x ) :
    arr . sort ( )
    ptr = lowerBound ( arr , 0 , n , x )
    return 1 if ( ptr != x ) else ( ptr - arr )
def lowerBound ( a , low , high , element ) :
    while ( low < high ) :
        middle = low + ( high - low ) // 2
        if ( element > a [ middle ] ) :
            low = middle + 1
        else :
            high = middle
    return low
if __name__ == ' _ _ main _ _ ' :
    x = 20
    arr = [ 10 , 30 , 20 , 50 , 20 ]
    n = len ( arr )
    print ( findFirst ( arr , n , x ) )

Index/key variables: middle
Python program:
def findFirst ( arr , n , x ) :
    count = 0
    isX = False
    for i in range ( n ) :
        if ( arr [ i ] == x ) :
            isX = True
        elif ( arr [ i ] < x ) :
            count += 1
    return - 1 if ( isX == False ) else count
if __name__ == " _ _ main _ _ " :
    x = 20
    arr = [ 10 , 30 , 20 , 50 , 20 ]
    n = len ( arr )
    print ( findFirst ( arr , n , x ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Boolean variables: isX
Python program:
def findDuplicate ( arr ) :
    slow = arr [ 0 ]
    fast = arr [ 0 ]
    while True :
        slow = arr [ slow ]
        fast = arr [ arr [ fast ] ]
        if slow == fast :
            break
    ptr1 = arr [ 0 ]
    ptr2 = slow
    while ptr1 != ptr2 :
        ptr1 = arr [ ptr1 ]
        ptr2 = arr [ ptr2 ]
    return ptr1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 2 , 1 ]
    print ( findDuplicate ( arr ) )

Index/key variables: fast, ptr1, ptr2, slow
Python program:
MAX_CHAR = 26 ;
def printGreaterCount ( str1 ) :
    len1 = len ( str1 ) ;
    ans = [ 0 ] * len1 ;
    count = [ 0 ] * MAX_CHAR ;
    for i in range ( len1 - 1 , - 1 , - 1 ) :
        count [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1 ;
        for j in range ( ord ( str1 [ i ] ) - ord ( ' a ' ) + 1 , MAX_CHAR ) :
            ans [ i ] += count [ j ] ;
    for i in range ( len1 ) :
        print ( ans [ i ] , end = " ▁ " ) ;
str1 = " abcd " ;
printGreaterCount ( str1 ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printPairs ( arr , n , sum ) :
    mydict = dict ( )
    for i in range ( n ) :
        temp = sum - arr [ i ]
        if temp in mydict :
            count = mydict [ temp ]
            for j in range ( count ) :
                print ( " ( " , temp , " , ▁ " , arr [ i ] , " ) " , sep = " " , end =   ' ' )
        if arr [ i ] in mydict :
            mydict [ arr [ i ] ] += 1
        else :
            mydict [ arr [ i ] ] = 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 5 , 7 , - 1 , 5 ]
    n = len ( arr )
    sum = 6
    printPairs ( arr , n , sum )

Index/key variables: i, temp
Iterator variables: i, j
Python program:
import sys
def maxProduct ( arr , n ) :
    if ( n < 4 ) :
        return - 1
    maxA = - sys . maxsize - 1
    maxB = - sys . maxsize - 1
    maxC = - sys . maxsize - 1
    maxD = - sys . maxsize - 1
    minA = sys . maxsize
    minB = sys . maxsize
    minC = sys . maxsize
    minD = sys . maxsize
    for i in range ( n ) :
        if ( arr [ i ] > maxA ) :
            maxD = maxC
            maxC = maxB
            maxB = maxA
            maxA = arr [ i ]
        elif ( arr [ i ] > maxB ) :
            maxD = maxC
            maxC = maxB
            maxB = arr [ i ]
        elif ( arr [ i ] > maxC ) :
            maxD = maxC
            maxC = arr [ i ]
        elif ( arr [ i ] > maxD ) :
            maxD = arr [ i ]
        if ( arr [ i ] < minA ) :
            minD = minC
            minC = minB
            minB = minA
            minA = arr [ i ]
        elif ( arr [ i ] < minB ) :
            minD = minC
            minC = minB
            minB = arr [ i ]
        elif ( arr [ i ] < minC ) :
            minD = minC
            minC = arr [ i ]
        elif ( arr [ i ] < minD ) :
            minD = arr [ i ]
    x = maxA * maxB * maxC * maxD
    y = minA * minB * minC * minD
    z = minA * minB * maxA * maxB
    return max ( x , max ( y , z ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , - 4 , 3 , - 6 , 7 , 0 ]
    n = len ( arr )
    max1 = maxProduct ( arr , n )
    if ( max1 == - 1 ) :
        print ( " No ▁ Quadruple ▁ Exists " )
    else :
        print ( " Maximum ▁ product ▁ is " , max1 )

Index/key variables: i
Iterator variables: i
Python program:
def countTripletsLessThanL ( n , L , arr ) :
    arr . sort ( )
    ways = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            for k in range ( j + 1 , n ) :
                mostDistantDistance = arr [ k ] - arr [ i ]
                if ( mostDistantDistance <= L ) :
                    ways += 1
    return ways
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 ]
    n = len ( arr )
    L = 3
    ans = countTripletsLessThanL ( n , L , arr )
    print ( " Total ▁ Number ▁ of ▁ ways ▁ = " , ans )

Index/key variables: i, k
Accumulator variables: ways
Iterator variables: i, j, k
Python program:
def binary_lower ( value , arr , n ) :
    start = 0
    end = n - 1
    ans = - 1
    while ( start <= end ) :
        mid = ( start + end ) // 2
        if ( arr [ mid ] >= value ) :
            end = mid - 1
            ans = mid
        else :
            start = mid + 1
    return ans
def countTriplet ( arr , n , k ) :
    count = 0
    arr . sort ( )
    for i in range ( 2 , n ) :
        cur = ( binary_lower ( arr [ i ] - k , arr , n ) )
        if ( cur <= i - 2 ) :
            count += ( ( i - cur ) * ( i - cur - 1 ) ) // 2
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 2 , 2 , 3 ]
    k = 1
    n = len ( arr )
    print ( countTriplet ( arr , n , k ) )

Index/key variables: i, mid
Accumulator variables: count
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , length = None , suffixEdge = None ) :
        self . start = None
        self . end = None
        self . length = length
        self . insertionEdge = [ 0 ] * 26
        self . suffixEdge = suffixEdge
    tree = [ Node ( ) for i in range ( MAXN ) ]
    currNode , ptr = 1 , 2
    tree [ 1 ] = root1
    tree [ 2 ] = root2
    s = " forgeeksskeegfor "
    for i in range ( 0 , len ( s ) ) :
        insert ( i )
def insert ( currIndex ) :
    global currNode , ptr
    temp = currNode
    while True :
        currLength = tree [ temp ] . length
        if ( currIndex - currLength >= 1 and ( s [ currIndex ] == s [ currIndex - currLength - 1 ] ) ) :
            break
        temp = tree [ temp ] . suffixEdge
    if tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ] != 0 :
        currNode = tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ]
        return
    ptr += 1
    tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ] = ptr
    tree [ ptr ] . end = currIndex
    tree [ ptr ] . length = tree [ temp ] . length + 2
    tree [ ptr ] . start = ( tree [ ptr ] . end - tree [ ptr ] . length + 1 )
    currNode = ptr
    temp = tree [ temp ] . suffixEdge
    if tree [ currNode ] . length == 1 :
        tree [ currNode ] . suffixEdge = 2
        return
    while True :
        currLength = tree [ temp ] . length
        if ( currIndex - currLength >= 1 and s [ currIndex ] == s [ currIndex - currLength - 1 ] ) :
            break
        temp = tree [ temp ] . suffixEdge
    tree [ currNode ] . suffixEdge = tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ]
if __name__ == " _ _ main _ _ " :
    MAXN = 1000
    root1 = Node ( - 1 , 1 )
    root2 = Node ( 0 , 1 )
    last = ptr
    for i in range ( tree [ last ] . start , tree [ last ] . end + 1 ) :
        print ( s [ i ] , end = " " )

Index/key variables: currIndex, currNode, i, last, ptr, temp
Iterator variables: i
Class/struct names: Node
Python program:
def missingNum ( arr , n ) :
    minvalue = min ( arr )
    xornum = 0
    for i in range ( 0 , n ) :
        xornum ^= ( minvalue ) ^ arr [ i ]
        minvalue = minvalue + 1
    return xornum ^ minvalue
arr = [ 13 , 12 , 11 , 15 ]
n = len ( arr )
print ( missingNum ( arr , n ) )

Index/key variables: i
Accumulator variables: xornum
Iterator variables: i
Python program:
def findLastIndex ( str , x ) :
    index = - 1
    for i in range ( 0 , len ( str ) ) :
        if str [ i ] == x :
            index = i
    return index
str = " geeksforgeeks "
x = ' e '
index = findLastIndex ( str , x )
if index == - 1 :
    print ( " Character ▁ not ▁ found " )
else :
    print ( ' Last ▁ index ▁ is ' , index )

Index/key variables: i
Iterator variables: i
Python program:
def findLastIndex ( str , x ) :
    for i in range ( len ( str ) - 1 , - 1 , - 1 ) :
        if ( str [ i ] == x ) :
            return i
    return - 1
str = " geeksforgeeks "
x = ' e '
index = findLastIndex ( str , x )
if ( index == - 1 ) :
    print ( " Character ▁ not ▁ found " )
else :
    print ( " Last ▁ index ▁ is ▁ " , index )

Index/key variables: i
Iterator variables: i
Python program:
def countMaxSetBits ( left , right ) :
    while ( left | ( left + 1 ) ) <= right :
        left |= left + 1
    return left
l = 1
r = 5
print ( countMaxSetBits ( l , r ) )
l = 1
r = 10
print ( countMaxSetBits ( l , r ) )

Accumulator variables: left
Python program:
class newNode :
    def __init__ ( self , item ) :
        self . key = item
        self . left = None
        self . right = None
def insert ( node , key ) :
    if ( node == None ) :
        return newNode ( key )
    if ( key < node . key ) :
        node . left = insert ( node . left , key )
    elif ( key > node . key ) :
        node . right = insert ( node . right , key )
    return node
def findFloor ( root , key ) :
    curr = root
    ans = None
    while ( curr ) :
        if ( curr . key <= key ) :
            ans = curr
            curr = curr . right
        else :
            curr = curr . left
    if ( ans ) :
        return ans . key
    return - 1
if __name__ == ' _ _ main _ _ ' :
    N = 25
    root = None
    root = insert ( root , 19 )
    insert ( root , 2 )
    insert ( root , 1 )
    insert ( root , 3 )
    insert ( root , 12 )
    insert ( root , 9 )
    insert ( root , 21 )
    insert ( root , 19 )
    insert ( root , 25 )
    print ( findFloor ( root , N ) )

Class/struct names: newNode
Python program:
def compareStrings ( str1 , str2 ) :
    i = 0
    while i < len ( str1 ) - 1 and str1 [ i ] == str2 [ i ] :
        i += 1
    if str1 [ i ] > str2 [ i ] :
        return - 1
    return str1 [ i ] < str2 [ i ]
def searchStr ( arr , string , first , last ) :
    if first > last :
        return - 1
    mid = ( last + first ) // 2
    if len ( arr [ mid ] ) == 0 :
        left , right = mid - 1 , mid + 1
        while True :
            if left < first and right > last :
                return - 1
            if right <= last and len ( arr [ right ] ) != 0 :
                mid = right
                break
            if left >= first and len ( arr [ left ] ) != 0 :
                mid = left
                break
            right += 1
            left -= 1
    if compareStrings ( string , arr [ mid ] ) == 0 :
        return mid
    if compareStrings ( string , arr [ mid ] ) < 0 :
        return searchStr ( arr , string , mid + 1 , last )
    return searchStr ( arr , string , first , mid - 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ " for " , " " , " " , " " , " geeks " , " ide " , " " , " practice " , " " , " " , " quiz " , " " , " " ]
    string = " quiz "
    n = len ( arr )
    print ( searchStr ( arr , string , 0 , n - 1 ) )

Index/key variables: i, left, mid, right
Python program:
def maximumMex ( arr , N ) :
    ans = [ ]
    arr = sorted ( arr )
    for i in range ( N ) :
        if ( i == 0 or arr [ i ] != arr [ i - 1 ] ) :
            ans . append ( arr [ i ] )
    for i in range ( N ) :
        if ( i > 0 and arr [ i ] == arr [ i - 1 ] ) :
            ans . append ( arr [ i ] )
    for i in range ( N ) :
        print ( ans [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 0 ]
    N = len ( arr )
    maximumMex ( arr , N )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def printMatrix ( a ) :
    for x in a :
        for y in x :
            print ( y , end = " ▁ " )
        print ( )
def sortBoundaryWise ( a ) :
    k = 0
    l = 0
    m = len ( a )
    n = len ( a [ 0 ] )
    n_k = 0
    n_l = 0
    n_m = m
    n_n = n
    while ( k < m and l < n ) :
        boundary = [ ]
        for i in range ( l , n ) :
            boundary . append ( a [ k ] [ i ] )
        k += 1
        for i in range ( k , m ) :
            boundary . append ( a [ i ] [ n - 1 ] )
        n -= 1
        if ( k < m ) :
            for i in range ( n - 1 , l - 1 , - 1 ) :
                boundary . append ( a [ m - 1 ] [ i ] )
            m -= 1
        if ( l < n ) :
            for i in range ( m - 1 , k - 1 , - 1 ) :
                boundary . append ( a [ i ] [ l ] )
            l += 1
        boundary . sort ( )
        ind = 0
        for i in range ( n_l , n_n ) :
            a [ n_k ] [ i ] = boundary [ ind ]
            ind += 1
        n_k += 1
        for i in range ( n_k , n_m ) :
            a [ i ] [ n_n - 1 ] = boundary [ ind ]
            ind += 1
        n_n -= 1
        if ( n_k < n_m ) :
            for i in range ( n_n - 1 , n_l - 1 , - 1 ) :
                a [ n_m - 1 ] [ i ] = boundary [ ind ]
                ind += 1
            n_m -= 1
        if ( n_l < n_n ) :
            for i in range ( n_m - 1 , n_k - 1 , - 1 ) :
                a [ i ] [ n_l ] = boundary [ ind ]
                ind += 1
            n_l += 1
    printMatrix ( a )
if __name__ == " _ _ main _ _ " :
    matrix = [ [ 9 , 7 , 4 , 5 ] , [ 1 , 6 , 2 , - 6 ] , [ 12 , 20 , 2 , 0 ] , [ - 5 , - 6 , 7 , - 2 ] ]
    sortBoundaryWise ( matrix )

Index/key variables: i, ind, k, l, n_k, n_l
Accumulator variables: boundary, m, n, n_m, n_n
Iterator variables: i, x, y
Python program:
import sys
def minimum_sum ( A , N ) :
    A . sort ( reverse = False )
    sum = sys . maxsize
    for i in range ( N - 2 ) :
        sum = min ( sum , abs ( A [ i ] - A [ i + 1 ] ) + abs ( A [ i + 1 ] - A [ i + 2 ] ) )
    print ( sum )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 1 , 2 , 3 ]
    N = len ( A )
    minimum_sum ( A , N )

Index/key variables: i
Iterator variables: i
Python program:
def sameChar ( S , N ) :
    S = ' ' . join ( sorted ( S ) )
    mid = ord ( S [ N // 2 ] )
    total_operations = 0
    for i in range ( N ) :
        total_operations += abs ( ord ( S [ i ] ) - mid )
    print ( total_operations )
S = " geeks "
N = len ( S )
sameChar ( S , N )

Index/key variables: i
Accumulator variables: total_operations
Iterator variables: i
Python program:
import sys
def maxScore ( i , A , K , N , dp ) :
    if ( i >= N - 1 ) :
        return A [ N - 1 ] ;
    if ( dp [ i ] != - 1 ) :
        return dp [ i ] ;
    score = 1 - sys . maxsize ;
    for j in range ( 1 , K + 1 ) :
        score = max ( score , maxScore ( i + j , A , K , N , dp ) ) ;
    dp [ i ] = score + A [ i ] ;
    return dp [ i ] ;
def getScore ( A , N , K ) :
    dp = [ 0 ] * N ;
    for i in range ( N ) :
        dp [ i ] = - 1 ;
    print ( maxScore ( 0 , A , K , N , dp ) ) ;
if __name__ == ' _ _ main _ _ ' :
    A = [ 100 , - 30 , - 50 , - 15 , - 20 , - 30 ] ;
    K = 3 ;
    N = len ( A ) ;
    getScore ( A , N , K ) ;

Index/key variables: i
Iterator variables: i, j
Python program:
def getcount ( arr , N ) :
    count = 0
    if ( N < 3 ) :
        return 0
    for b in range ( 0 , N ) :
        for a in range ( 0 , N ) :
            if ( a == b ) :
                continue
            for c in range ( 0 , N ) :
                if ( c == a or c == b ) :
                    continue
                d = arr [ b ] * arr [ b ] // 4
                if ( arr [ a ] * arr ) <= d :
                    count += 1
    return count
arr = [ 1 , 2 , 3 , 4 , 5 ]
N = len ( arr )
print ( getcount ( arr , N ) )

Index/key variables: a, b
Accumulator variables: count
Iterator variables: a, b, c
Python program:
def splitArray ( arr , N ) :
    arr = sorted ( arr )
    result = 10 ** 9
    for i in range ( 1 , N ) :
        result = min ( result , arr [ i ] ^ arr [ i - 1 ] )
    return result
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 1 , 2 , 6 , 4 ]
    N = len ( arr )
    print ( splitArray ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def isIncreasing ( arr ) :
    for i in range ( len ( arr ) - 1 ) :
        if arr [ i ] > arr [ i + 1 ] :
            return False
    return True
def sortArr ( arr ) :
    prev = - 1
    for i in range ( len ( arr ) ) :
        optEle = arr [ i ]
        strEle = str ( arr [ i ] )
        for idx in range ( len ( strEle ) ) :
            temp = int ( strEle [ idx : ] + strEle [ : idx ] )
            if temp >= prev and temp < optEle :
                optEle = temp
        arr [ i ] = optEle
        prev = arr [ i ]
    if isIncreasing ( arr ) :
        return arr
    else :
        return " - 1"
if __name__ == ' _ _ main _ _ ' :
    arr = [ 511 , 321 , 323 , 432 , 433 ]
    res = sortArr ( arr )
    for i in res :
        print ( i , end = " ▁ " )

Index/key variables: i
Iterator variables: i, idx
Python program:
from bisect import bisect_left
def maximumShops ( opening , closing , n , k ) :
    a = [ [ 0 , 0 ] for i in range ( n ) ]
    for i in range ( n ) :
        a [ i ] [ 0 ] = opening [ i ]
        a [ i ] [ 1 ] = closing [ i ]
    a = sorted ( a )
    count = 1
    st = { }
    for i in range ( n ) :
        flag = False
        if ( len ( st ) == 0 ) :
            ar = list ( st . keys ( ) )
            it = bisect_left ( ar , a [ i ] [ 0 ] )
            if ( it != 0 ) :
                it -= 1
                if ( ar [ it ] <= a [ i ] [ 0 ] ) :
                    del st [ it ]
                    st [ a [ i ] [ 1 ] ] = 1
                    count += 1
                    flag = True
        if ( len ( st ) < k and flag == False ) :
            st [ a [ i ] [ 1 ] ] = 1
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    S = [ 1 , 8 , 3 , 2 , 6 ]
    E = [ 5 , 10 , 6 , 5 , 9 ]
    K , N = 2 , len ( S )
    print ( maximumShops ( S , E , N , K ) )

Index/key variables: i, it
Accumulator variables: count
Iterator variables: i
Boolean variables: flag
Python program:
def maxSum ( arr , brr , N , K ) :
    crr = [ ]
    for i in range ( N ) :
        crr . append ( arr [ i ] )
    for i in range ( K ) :
        crr . append ( brr [ i ] )
    crr = sorted ( crr ) [ : : - 1 ]
    sum = 0
    for i in range ( N ) :
        if ( crr [ i ] > 0 ) :
            sum += crr [ i ]
        else :
            break
    print ( sum )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 7 , 2 , - 1 , 4 , 5 ]
    N = len ( arr )
    brr = [ 1 , 2 , 3 , 2 ]
    K = len ( brr )
    maxSum ( arr , brr , N , K )

Index/key variables: i
Accumulator variables: crr, sum
Iterator variables: i
Python program:
def countPairs ( A , N ) :
    count = 0
    for i in range ( 0 , N ) :
        for j in range ( i + 1 , N ) :
            xo = ( A [ i ] ^ A [ j ] )
            mx = max ( A [ i ] , A [ j ] )
            if ( xo > mx ) :
                count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 3 ]
    N = len ( arr )
    countPairs ( arr , N )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def findTheOrder ( arr , s , N ) :
    ans = [ ]
    A = [ [ ] for i in range ( N ) ]
    for i in range ( N ) :
        A [ i ] = [ arr [ i ] , i + 1 ]
    A = sorted ( A )
    q = [ ]
    index = 0
    for i in range ( 2 * N ) :
        if ( s [ i ] == '0' ) :
            ans . append ( A [ index ] [ 1 ] )
            q . append ( A [ index ] )
            index += 1
        else :
            ans . append ( q [ - 1 ] [ 1 ] )
            del q [ - 1 ]
        q = sorted ( q )
    for i in ans :
        print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    arr = [ 2 , 1 , 3 ]
    s = "001011"
    findTheOrder ( arr , s , N )

Index/key variables: i, index
Accumulator variables: ans, q
Iterator variables: i
Python program:
def evenOddDiff ( a , n , k ) :
    j = - 1
    even = [ ]
    odd = [ ]
    for i in range ( n ) :
        if ( a [ i ] % 2 == 0 ) :
            even . append ( a [ i ] )
        else :
            odd . append ( a [ i ] )
    j += 1
    even . sort ( )
    even . reverse ( )
    odd . sort ( )
    odd . reverse ( )
    evenSum , oddSum = 0 , 0
    for i in range ( k ) :
        evenSum += even [ i ]
    for i in range ( k ) :
        oddSum += odd [ i ]
    print ( abs ( evenSum - oddSum ) )
arr = [ 1 , 8 , 3 , 4 , 5 ]
N = len ( arr )
K = 2
evenOddDiff ( arr , N , K )

Index/key variables: i
Accumulator variables: even, evenSum, odd, oddSum
Iterator variables: i