dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def rearrangeArr ( arr , N ) :
    totalSum = 0
    for i in range ( N ) :
        totalSum += arr [ i ]
    if ( totalSum == 0 ) :
        print ( - 1 )
    elif ( totalSum > 0 ) :
        arr . sort ( reverse = True )
        print ( * arr , sep = ' ▁ ' )
    else :
        arr . sort ( )
        print ( * arr , sep = ' ▁ ' )
arr = [ 1 , - 1 , - 2 , 3 ]
N = len ( arr )
rearrangeArr ( arr , N ) ;

Index/key variables: i
Accumulator variables: totalSum
Iterator variables: i
Python program:
MOD = 1000000007
def solve ( values , salary ) :
    ret = 1
    amt = 0
    values = sorted ( values )
    salary = sorted ( salary )
    while ( len ( salary ) > 0 ) :
        while ( ( len ( values ) and values [ - 1 ] >= salary [ - 1 ] ) ) :
            amt += 1
            del values [ - 1 ]
        if ( amt == 0 ) :
            return 0
        ret *= amt
        amt -= 1
        ret %= MOD
        del salary [ - 1 ]
    return ret
if __name__ == ' _ _ main _ _ ' :
    values = [ 1 , 2 ]
    salary = [ 2 ]
    print ( solve ( values , salary ) )

Accumulator variables: amt, ret
Python program:
def countPairs ( arr , n ) :
    ans = 0
    arr . sort ( )
    left = 0
    right = 1 ;
    while ( right < n ) :
        if ( arr [ left ] == arr [ right ] ) :
            ans += right - left ;
        else :
            left = right ;
        right += 1
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 2 , 3 , 2 , 3 ]
    N = len ( arr )
    print ( countPairs ( arr , N ) )

Index/key variables: left, right
Accumulator variables: ans
Python program:
def compare ( p1 , p2 ) :
    return p1 [ 0 ] > p2 [ 0 ]
def maximiseScore ( A , B , K , N ) :
    pairs = [ ]
    for i in range ( N ) :
        pairs . append ( [ A [ i ] , B [ i ] ] )
    pairs . sort ( key = lambda x : x [ 0 ] , reverse = True )
    Sum = 0
    for i in range ( N ) :
        if ( pairs [ i ] [ 1 ] == 0 ) :
            Sum += pairs [ i ] [ 0 ]
        elif ( pairs [ i ] [ 1 ] == 1 ) :
            if ( K > 0 ) :
                Sum += pairs [ i ] [ 0 ]
                K -= 1
            else :
                Sum -= pairs [ i ] [ 0 ]
    return Sum
A = [ 5 , 4 , 6 , 2 , 8 ]
B = [ 1 , 0 , 1 , 1 , 0 ]
K = 2
N = len ( A )
print ( maximiseScore ( A , B , K , N ) )

Index/key variables: i
Accumulator variables: K, Sum, pairs
Iterator variables: i
Python program:
def sortString ( S ) :
    sorted1 = [ ]
    original = [ ]
    insert = False
    if ( len ( S ) == 1 ) :
        print ( 0 )
    curr = 1
    for i in range ( len ( S ) - 1 ) :
        if ( S [ i ] == S [ i + 1 ] ) :
            curr += 1
            insert = False
        else :
            sorted1 . append ( curr )
            original . append ( curr )
            curr = 1
            insert = True
    if ( ( S [ ( len ( S ) - 1 ) ] != S [ ( len ( S ) - 2 ) ] ) or insert == False ) :
        sorted1 . append ( curr )
        original . append ( curr )
    sorted1 . sort ( )
    t_cost = 0
    for i in range ( len ( sorted1 ) ) :
        t_cost += abs ( sorted1 [ i ] - original [ i ] )
    return ( t_cost // 2 )
if __name__ == " _ _ main _ _ " :
    S = " aabbcccdeffffggghhhhhii "
    print ( sortString ( S ) )

Index/key variables: i
Accumulator variables: curr, original, sorted1, t_cost
Iterator variables: i
Boolean variables: insert
Python program:
letters = [ 4 , 3 , 3 , 3 , 4 , 4 , 3 , 5 , 5 , 4 ]
def sumOfLetters ( n ) :
    sum = 0
    while ( n > 0 ) :
        sum += letters [ n % 10 ]
        n = n // 10
    return sum
def sortArr ( arr , n ) :
    vp = [ ]
    for i in range ( n ) :
        vp . append ( [ sumOfLetters ( arr [ i ] ) , arr [ i ] ] )
    vp . sort ( key = lambda x : x [ 0 ] )
    for i in vp :
        print ( i [ 1 ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 10 , 31 , 18 ]
    n = len ( arr )
    sortArr ( arr , n )

Index/key variables: i
Accumulator variables: sum, vp
Iterator variables: i
Python program:
from functools import cmp_to_key
def myCompare ( date1 , date2 ) :
    day1 = date1 [ 0 : 2 ]
    month1 = date1 [ 3 : 3 + 2 ]
    year1 = date1 [ 6 : 6 + 4 ]
    day2 = date2 [ 0 : 2 ]
    month2 = date2 [ 3 : 3 + 2 ]
    year2 = date2 [ 6 : 6 + 4 ]
    if ( year1 < year2 ) :
        return - 1
    if ( year1 > year2 ) :
        return 1
    if ( month1 < month2 ) :
        return - 1
    if ( month1 > month2 ) :
        return 1
    if ( day1 < day2 ) :
        return - 1
    if ( day1 > day2 ) :
        return 1
def printDatesAscending ( arr ) :
    arr = sorted ( arr , key = cmp_to_key ( lambda a , b : myCompare ( a , b ) ) )
    for i in range ( len ( arr ) ) :
        print ( arr [ i ] )
arr = [ ]
arr . append ( "25-08-1996" )
arr . append ( "03-08-1970" )
arr . append ( "09-04-1994" )
arr . append ( "29-08-1996" )
arr . append ( "14-02-1972" )
printDatesAscending ( arr )

Index/key variables: i
Iterator variables: i
Python program:
def isVowel ( ch ) :
    ch = ch . upper ( ) ;
    return ( ch == ' A ' or ch == ' E ' or ch == ' I ' or ch == ' O ' or ch == ' U ' ) ;
def countVowels ( string ) :
    count = 0 ;
    for i in range ( len ( string ) ) :
        if ( isVowel ( string [ i ] ) ) :
            count += 1 ;
    return count ;
def sortArr ( arr , n ) :
    vp = [ ] ;
    for i in range ( n ) :
        vp . append ( ( countVowels ( arr [ i ] ) , arr [ i ] ) ) ;
    vp . sort ( )
    for i in range ( len ( vp ) ) :
        print ( vp [ i ] [ 1 ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ " lmno " , " pqrst " , " aeiou " , " xyz " ] ;
    n = len ( arr ) ;
    sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: count, vp
Iterator variables: i
Python program:
def minimumCost ( price , n ) :
    price = sorted ( price )
    totalCost = 0
    for i in range ( n - 1 , 1 , - 2 ) :
        if ( i == 2 ) :
            totalCost += price [ 2 ] + price [ 0 ]
        else :
            price_first = price [ i ] + price [ 0 ] + 2 * price [ 1 ]
            price_second = price [ i ] + price [ i - 1 ] + 2 * price [ 0 ]
            totalCost += min ( price_first , price_second )
    if ( n == 1 ) :
        totalCost += price [ 0 ]
    else :
        totalCost += price [ 1 ]
    return totalCost
price = [ 30 , 40 , 60 , 70 ]
n = len ( price )
print ( minimumCost ( price , n ) )

Index/key variables: i
Accumulator variables: totalCost
Iterator variables: i
Python program:
import numpy as np
N = 100
INF = 1000000
dp = np . zeros ( ( N , N ) ) ;
vis = np . zeros ( ( N , N ) ) ;
def findSum ( arr , n , k , l , r ) :
    if ( ( l ) + ( n - 1 - r ) == k ) :
        return arr [ r ] - arr [ l ] ;
    if ( vis [ l ] [ r ] ) :
        return dp [ l ] [ r ] ;
    vis [ l ] [ r ] = 1 ;
    dp [ l ] [ r ] = min ( findSum ( arr , n , k , l , r - 1 ) , findSum ( arr , n , k , l + 1 , r ) ) ;
    return dp [ l ] [ r ]
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 100 , 120 , 140 ] ;
    k = 2 ;
    n = len ( arr ) ;
    print ( findSum ( arr , n , k , 0 , n - 1 ) ) ;

Index/key variables: l, r
Python program:
def canbuildword ( s , isoriginalword , mp ) :
    if s in mp and mp [ s ] == 0 :
        return False
    if s in mp and mp [ s ] == 1 and isoriginalword == 0 :
        return True
    for i in range ( 1 , len ( s ) ) :
        left = s [ : i ]
        right = s [ i : ]
        if left in mp and mp [ left ] == 1 and canbuildword ( right , 0 , mp ) :
            return True
    mp [ s ] = 0
    return False
def printlongestword ( listofwords ) :
    mp = dict ( )
    for i in listofwords :
        mp [ i ] = 1
    listofwords . sort ( key = lambda x : len ( x ) , reverse = True )
    for i in listofwords :
        if canbuildword ( i , 1 , mp ) :
            return i
    return " - 1"
if __name__ == " _ _ main _ _ " :
    listofwords = [ " geeks " , " for " , " geeksfor " , " geeksforgeeks " ]
    print ( printlongestword ( listofwords ) )

Index/key variables: i, left, s
Iterator variables: i
Python program:
import sys
def solution ( arr , x ) :
    closestSum = sys . maxsize
    for i in range ( len ( arr ) ) :
        for j in range ( i + 1 , len ( arr ) ) :
            for k in range ( j + 1 , len ( arr ) ) :
                if ( abs ( x - closestSum ) > abs ( x - ( arr [ i ] + arr [ j ] + arr [ k ] ) ) ) :
                    closestSum = ( arr [ i ] + arr [ j ] + arr [ k ] )
    return closestSum
if __name__ == " _ _ main _ _ " :
    arr = [ - 1 , 2 , 1 , - 4 ]
    x = 1
    print ( solution ( arr , x ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
from collections import deque
adj = [ [ ] for i in range ( 100 ) ]
def addEdge ( u , v ) :
    adj [ u ] . append ( v )
def getindeg ( V , indeg ) :
    for i in range ( V ) :
        for x in adj [ i ] :
            indeg [ x ] += 1
def topo ( V , indeg ) :
    q = deque ( )
    for i in range ( V ) :
        if ( indeg [ i ] == 0 ) :
            q . appendleft ( i )
    res = [ ]
    while ( len ( q ) > 0 ) :
        u = q . popleft ( )
        res . append ( u )
        for x in adj [ u ] :
            indeg [ x ] -= 1
            if ( indeg [ x ] == 0 ) :
                q . appendleft ( x )
    return res
def makearray ( v , V ) :
    for i in range ( len ( v ) ) :
        for j in range ( len ( v [ i ] ) - 1 ) :
            addEdge ( v [ i ] [ j ] , v [ i ] [ j + 1 ] )
    indeg = [ 0 for i in range ( V ) ]
    getindeg ( V , indeg )
    res = topo ( V , indeg )
    return res
n = 10
subseqs = [ [ 9 , 1 , 2 , 8 , 3 ] , [ 6 , 1 , 2 ] , [ 9 , 6 , 3 , 4 ] , [ 5 , 2 , 7 ] , [ 0 , 9 , 5 , 4 ] ]
res = makearray ( subseqs , n )
for x in res :
    print ( x , end = " ▁ " )

Index/key variables: i, j, u, x
Accumulator variables: res
Iterator variables: i, j, x
Python program:
pr = [ ]
prime = [ 1 for i in range ( 10000000 + 1 ) ]
def sieve ( n ) :
    for p in range ( 2 , n ) :
        if p * p > n :
            break
        if ( prime [ p ] == True ) :
            for i in range ( 2 * p , n + 1 , p ) :
                prime [ i ] = False
    for p in range ( 2 , n + 1 ) :
        if ( prime [ p ] ) :
            pr . append ( p )
def SemiPrimeSum ( N ) :
    ans = 0
    for i in range ( len ( pr ) ) :
        for j in range ( i , len ( pr ) ) :
            if ( pr [ i ] * pr [ j ] > N ) :
                break
            ans += pr [ i ] * pr [ j ]
    return ans
N = 6
sieve ( N )
print ( SemiPrimeSum ( N ) )

Index/key variables: i, j, p
Accumulator variables: ans, pr
Iterator variables: i, j, p
Python program:
def compressArr ( arr , n ) :
    i = 0 ;
    j = 0 ;
    arr . sort ( ) ;
    while ( i < n ) :
        j = i ;
        while ( ( j + 1 < n ) and ( arr [ j + 1 ] == arr [ j ] + 1 ) ) :
            j += 1 ;
        if ( i == j ) :
            print ( arr [ i ] , end = " ▁ " ) ;
            i += 1 ;
        else :
            print ( arr [ i ] , " - " , arr [ j ] , end = " ▁ " ) ;
            i = j + 1 ;
n = 7 ;
arr = [ 1 , 3 , 4 , 5 , 6 , 9 , 10 ] ;
compressArr ( arr , n ) ;

Index/key variables: i, j
Python program:
def removeElements ( arr , n ) :
    brr = [ 0 ] * n ; l = 1 ;
    brr [ 0 ] = arr [ 0 ] ;
    for i in range ( 1 , n ) :
        if ( brr [ l - 1 ] <= arr [ i ] ) :
            brr [ l ] = arr [ i ] ;
            l += 1 ;
    for i in range ( l ) :
        print ( brr [ i ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 12 , 9 , 10 , 2 , 13 , 14 ] ;
    n = len ( arr ) ;
    removeElements ( arr , n ) ;

Index/key variables: i, l
Iterator variables: i
Python program:
def removeElements ( arr , n ) :
    l = 1
    for i in range ( 1 , n ) :
        if ( arr [ l - 1 ] <= arr [ i ] ) :
            arr [ l ] = arr [ i ]
            l += 1
    for i in range ( l ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 12 , 9 , 10 , 2 , 13 , 14 ]
    n = len ( arr )
    removeElements ( arr , n )

Index/key variables: i, l
Iterator variables: i
Python program:
import math
def findX ( list , int ) :
    list . sort ( )
    x = list [ 0 ] * list [ int - 1 ]
    vec = [ ]
    i = 2
    while ( i * i <= x ) :
        if ( x % i == 0 ) :
            vec . append ( i )
            if ( ( x // i ) != i ) :
                vec . append ( x // i )
        i += 1
    vec . sort ( )
    if ( len ( vec ) != int ) :
        return - 1
    else :
        j = 0
        for it in range ( int ) :
            if ( a [ j ] != vec [ it ] ) :
                return - 1
            else :
                j += 1
    return x
a = [ 2 , 5 , 4 , 10 ]
n = len ( a )
print ( findX ( a , n ) )

Index/key variables: it, j
Accumulator variables: i, vec
Iterator variables: it
Python program:
def pendulumArrangement ( arr , n ) :
    arr . sort ( reverse = False )
    pos = n - 1
    if ( n % 2 == 0 ) :
        odd = n - 1
    else :
        odd = n - 2
    while ( odd > 0 ) :
        temp = arr [ odd ]
        in1 = odd
        while ( in1 != pos ) :
            arr [ in1 ] = arr [ in1 + 1 ]
            in1 += 1
        arr [ in1 ] = temp
        odd = odd - 2
        pos = pos - 1
    start = 0
    end = int ( ( n - 1 ) / 2 )
    while ( start < end ) :
        temp = arr [ start ]
        arr [ start ] = arr [ end ]
        arr [ end ] = temp
        start += 1
        end -= 1
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 2 , 4 , 55 , 6 , 8 ]
    n = len ( arr )
    pendulumArrangement ( arr , n )

Index/key variables: end, i, in1, odd, start
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def AddNode ( root , data ) :
    if ( root == None ) :
        root = Node ( data )
        return root
    if ( root . data < data ) :
        root . right = AddNode ( root . right , data )
    elif ( root . data > data ) :
        root . left = AddNode ( root . left , data )
    return root
def TargetPair ( node , tar ) :
    LeftList = [ ]
    RightList = [ ]
    curr_left = node
    curr_right = node
    while ( curr_left != None or curr_right != None or len ( LeftList ) > 0 and len ( RightList ) > 0 ) :
        while ( curr_left != None ) :
            LeftList . append ( curr_left )
            curr_left = curr_left . left
        while ( curr_right != None ) :
            RightList . append ( curr_right )
            curr_right = curr_right . right
        LeftNode = LeftList [ - 1 ]
        RightNode = RightList [ - 1 ]
        leftVal = LeftNode . data
        rightVal = RightNode . data
        if ( leftVal >= rightVal ) :
            break
        if ( leftVal + rightVal < tar ) :
            del LeftList [ - 1 ]
            curr_left = LeftNode . right
        elif ( leftVal + rightVal > tar ) :
            del RightList [ - 1 ]
            curr_right = RightNode . left
        else :
            print ( LeftNode . data , RightNode . data )
            del RightList [ - 1 ]
            del LeftList [ - 1 ]
            curr_left = LeftNode . right
            curr_right = RightNode . left
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = AddNode ( root , 2 )
    root = AddNode ( root , 6 )
    root = AddNode ( root , 5 )
    root = AddNode ( root , 3 )
    root = AddNode ( root , 4 )
    root = AddNode ( root , 1 )
    root = AddNode ( root , 7 )
    sum = 8
    TargetPair ( root , sum )

Accumulator variables: LeftList, RightList
Class/struct names: Node
Python program:
def findNumber ( arr , n ) :
    arr = sorted ( arr )
    Max = arr [ n - 1 ]
    table = [ 10 ** 9 for i in range ( ( 2 * Max ) + 1 ) ]
    table [ 0 ] = 0
    ans = - 1
    for i in range ( 1 , 2 * Max + 1 ) :
        for j in range ( n ) :
            if ( arr [ j ] <= i ) :
                res = table [ i - arr [ j ] ]
                if ( res != 10 ** 9 and res + 1 < table [ i ] ) :
                    table [ i ] = res + 1
        if ( i > arr [ n - 1 ] and table [ i ] == 10 ** 9 ) :
            ans = i
            break
    return ans
arr = [ 6 , 7 , 15 ]
n = len ( arr )
print ( findNumber ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
MOD = 1000000007
max = 101
C = [ [ 0 for i in range ( max ) ] for j in range ( max ) ]
def power ( x , y ) :
    res = 1
    x = x % MOD
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % MOD
        y = y >> 1
        x = ( x * x ) % MOD
    return res % MOD
def combi ( n , k ) :
    for i in range ( n + 1 ) :
        for j in range ( min ( i , k ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] % MOD + C [ i - 1 ] [ j ] % MOD ) % MOD
def product ( a , n , k ) :
    ans = 1
    a . sort ( reverse = False )
    powa = C [ n - 1 ] [ k - 1 ]
    for i in range ( n ) :
        powla = C [ i ] [ k - 1 ]
        powfa = C [ n - i - 1 ] [ k - 1 ]
        powe = ( ( powa % MOD ) - ( powla + powfa ) % MOD + MOD ) % MOD
        mul = power ( a [ i ] , powe ) % MOD
        ans = ( ( ans % MOD ) * ( mul % MOD ) ) % MOD
    return ans % MOD
if __name__ == ' _ _ main _ _ ' :
    combi ( 100 , 100 )
    arr = [ 1 , 2 , 3 , 4 ]
    n = len ( arr )
    k = 3
    ans = product ( arr , n , k )
    print ( ans )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def makeEqualLength ( a , b ) :
    len_a = len ( a )
    len_b = len ( b )
    num_zeros = abs ( len_a - len_b )
    if ( len_a < len_b ) :
        for i in range ( num_zeros ) :
            a = '0' + a
        return len_b , a , b
    else :
        for i in range ( num_zeros ) :
            b = '0' + b
    return len_a , a , b
def andOperationBitwise ( s1 , s2 ) :
    length , s1 , s2 = makeEqualLength ( s1 , s2 )
    res = " "
    for i in range ( length ) :
        res = res + str ( int ( s1 [ i ] ) & int ( s2 [ i ] ) )
    return res
arr = [ "101" , "110110" , "111" ]
n = len ( arr )
if ( n < 2 ) :
    print ( arr [ n - 1 ] )
else :
    result = arr [ 0 ]
    for i in range ( n ) :
        result = andOperationBitwise ( result , arr [ i ] ) ;
    print ( result )

Index/key variables: i
Iterator variables: i
Python program:
def countPoints ( n , m , a , b , x , y ) :
    a . sort ( )
    b . sort ( )
    j , count = 0 , 0
    for i in range ( 0 , n ) :
        while j < m :
            if a [ i ] + y < b [ j ] :
                break
            if ( b [ j ] >= a [ i ] - x and b [ j ] <= a [ i ] + y ) :
                count += 1
                j += 1
                break
            else :
                j += 1
    return count
if __name__ == " _ _ main _ _ " :
    x , y = 1 , 4
    a = [ 1 , 5 ]
    n = len ( a )
    b = [ 1 , 1 , 2 ]
    m = len ( b )
    print ( countPoints ( n , m , a , b , x , y ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i
Python program:
N = 4
def merge_and_sort ( output , arr , n , k ) :
    for i in range ( k ) :
        for j in range ( n ) :
            output [ i * n + j ] = arr [ i ] [ j ] ;
    output . sort ( )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 5 , 7 , 15 , 18 ] , [ 1 , 8 , 9 , 17 ] , [ 1 , 4 , 7 , 7 ] ] ;
    n = N ;
    k = len ( arr )
    output = [ 0 for i in range ( n * k ) ]
    merge_and_sort ( output , arr , n , k ) ;
    for i in range ( n * k ) :
        print ( output [ i ] , end = ' ▁ ' )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def minOperations ( n , m , k , matrix ) :
    arr = [ ]
    if ( matrix [ 0 ] [ 0 ] < 0 ) :
        mod = k - ( abs ( matrix [ 0 ] [ 0 ] ) % k )
    else :
        mod = matrix [ 0 ] [ 0 ] % k
    for i in range ( n ) :
        for j in range ( m ) :
            arr . append ( matrix [ i ] [ j ] )
            val = matrix [ i ] [ j ]
            if ( val < 0 ) :
                res = k - ( abs ( val ) % k )
                if ( res != mod ) :
                    return - 1
            else :
                foo = matrix [ i ] [ j ]
                if ( foo % k != mod ) :
                    return - 1
    arr . sort ( )
    median = arr [ ( n * m ) // 2 ]
    minOperations = 0
    for i in range ( n * m ) :
        minOperations += abs ( arr [ i ] - median ) // k
    if ( ( n * m ) % 2 == 0 ) :
        median2 = arr [ ( ( n * m ) // 2 ) - 1 ]
        minOperations2 = 0
        for i in range ( n * m ) :
            minOperations2 += abs ( arr [ i ] - median2 ) / k
        minOperations = min ( minOperations , minOperations2 )
    return minOperations
if __name__ == " _ _ main _ _ " :
    matrix = [ [ 2 , 4 , 6 ] , [ 8 , 10 , 12 ] , [ 14 , 16 , 18 ] , [ 20 , 22 , 24 ] ]
    n = len ( matrix )
    m = len ( matrix [ 0 ] )
    k = 2
    print ( minOperations ( n , m , k , matrix ) )

Index/key variables: i, j
Accumulator variables: arr, minOperations, minOperations2
Iterator variables: i, j
Python program:
import sys
def minSubarray ( A , n ) :
    minValue = min ( A )
    maxValue = max ( A )
    pos_min , pos_max , ans = - 1 , - 1 , sys . maxsize
    for i in range ( 0 , n ) :
        if A [ i ] == minValue :
            pos_min = i
        if A [ i ] == maxValue :
            pos_max = i
        if pos_max != - 1 and pos_min != - 1 :
            ans = min ( ans , abs ( pos_min - pos_max ) + 1 )
    return ans
A = [ 1 , 5 , 9 , 7 , 1 , 9 , 4 ]
n = len ( A )
print ( minSubarray ( A , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def countSequences ( arr , n ) :
    count = 1
    arr . sort ( )
    for i in range ( n - 1 ) :
        if ( arr [ i ] + 1 != arr [ i + 1 ] ) :
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 7 , 3 , 5 , 10 ]
    n = len ( arr )
    print ( countSequences ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def minimumMoves ( a , n ) :
    operations = 0
    a . sort ( reverse = False )
    for i in range ( 0 , n , 1 ) :
        operations = operations + abs ( a [ i ] - ( i + 1 ) )
    return operations
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 3 , 2 ]
    n = len ( arr )
    print ( minimumMoves ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def printCase ( n ) :
    if ( n <= 2 ) :
        print ( " - 1" )
        return
    for i in range ( n , 0 , - 1 ) :
        print ( i , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    n = 3
    printCase ( n )

Iterator variables: i
Python program:
def findMissingNumber ( ranges , m ) :
    ranges . sort ( )
    ans = [ ]
    prev = 0
    for j in range ( len ( ranges ) ) :
        start = ranges [ j ] [ 0 ]
        end = ranges [ j ] [ 1 ]
        for i in range ( prev + 1 , start ) :
            ans . append ( i )
        prev = end
    for i in range ( prev + 1 , m + 1 ) :
        ans . append ( i )
    for i in range ( len ( ans ) ) :
        if ans [ i ] <= m :
            print ( ans [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    N , M = 2 , 6
    ranges = [ ]
    ranges . append ( [ 1 , 2 ] )
    ranges . append ( [ 4 , 5 ] )
    findMissingNumber ( ranges , M )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def check ( n , k , a , b ) :
    a . sort ( )
    b . sort ( )
    fl = False
    ind = - 1
    for i in range ( n ) :
        if ( a [ i ] != b [ i ] ) :
            if ( fl == True ) :
                return False
            fl = True
            ind = i
    if ( ind == - 1 or abs ( a [ ind ] - b [ ind ] ) <= k ) :
        return True
    return False
n , k = 2 , 4
a = [ 1 , 5 ]
b = [ 1 , 1 ]
if ( check ( n , k , a , b ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, ind
Iterator variables: i
Boolean variables: fl
Python program:
def SubseqWidths ( A ) :
    MOD = 10 ** 9 + 7
    N = len ( A )
    A . sort ( )
    pow2 = [ 1 ]
    for i in range ( 1 , N ) :
        pow2 . append ( pow2 [ - 1 ] * 2 % MOD )
    ans = 0
    for i , x in enumerate ( A ) :
        ans = ( ans + ( pow2 [ i ] - pow2 [ N - 1 - i ] ) * x ) % MOD
    return ans
A = [ 5 , 6 , 4 , 3 , 8 ]
print ( SubseqWidths ( A ) )

Index/key variables: i
Accumulator variables: pow2
Iterator variables: i, x