dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def preprocess ( arr , N , left , right ) :
    left [ 0 ] = 0
    lastIncr = 0
    for i in range ( 1 , N ) :
        if ( arr [ i ] > arr [ i - 1 ] ) :
            lastIncr = i
        left [ i ] = lastIncr
    right [ N - 1 ] = N - 1
    firstDecr = N - 1
    i = N - 2
    while ( i >= 0 ) :
        if ( arr [ i ] > arr [ i + 1 ] ) :
            firstDecr = i
        right [ i ] = firstDecr
        i -= 1
def isSubarrayMountainForm ( arr , left , right , L , R ) :
    return ( right [ L ] >= left [ R ] )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 2 , 4 , 4 , 6 , 3 , 2 ]
    N = len ( arr )
    left = [ 0 for i in range ( N ) ]
    right = [ 0 for i in range ( N ) ]
    preprocess ( arr , N , left , right )
    L = 0
    R = 2
    if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) :
        print ( " Subarray ▁ is ▁ in ▁ mountain ▁ form " )
    else :
        print ( " Subarray ▁ is ▁ not ▁ in ▁ mountain ▁ form " )
    L = 1
    R = 3
    if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) :
        print ( " Subarray ▁ is ▁ in ▁ mountain ▁ form " )
    else :
        print ( " Subarray ▁ is ▁ not ▁ in ▁ mountain ▁ form " )

Index/key variables: L, R, i
Iterator variables: i
Python program:
from math import ceil , floor , log
MAX = 1000
def sieveOfEratosthenes ( isPrime ) :
    isPrime [ 1 ] = False
    for p in range ( 2 , MAX + 1 ) :
        if p * p > MAX :
            break
        if ( isPrime [ p ] == True ) :
            for i in range ( 2 * p , MAX + 1 , p ) :
                isPrime [ i ] = False
def getMid ( s , e ) :
    return s + ( e - s ) // 2
def queryPrimesUtil ( st , ss , se , qs , qe , index ) :
    if ( qs <= ss and qe >= se ) :
        return st [ index ]
    if ( se < qs or ss > qe ) :
        return 0
    mid = getMid ( ss , se )
    return queryPrimesUtil ( st , ss , mid , qs , qe , 2 * index + 1 ) + queryPrimesUtil ( st , mid + 1 , se , qs , qe , 2 * index + 2 )
def updateValueUtil ( st , ss , se , i , diff , si ) :
    if ( i < ss or i > se ) :
        return
    st [ si ] = st [ si ] + diff
    if ( se != ss ) :
        mid = getMid ( ss , se )
        updateValueUtil ( st , ss , mid , i , diff , 2 * si + 1 )
        updateValueUtil ( st , mid + 1 , se , i , diff , 2 * si + 2 )
def updateValue ( arr , st , n , i , new_val , isPrime ) :
    if ( i < 0 or i > n - 1 ) :
        printf ( " Invalid ▁ Input " )
        return
    diff , oldValue = 0 , 0
    oldValue = arr [ i ]
    arr [ i ] = new_val
    if ( isPrime [ oldValue ] and isPrime [ new_val ] ) :
        return
    if ( ( not isPrime [ oldValue ] ) and ( not isPrime [ new_val ] ) ) :
        return
    if ( isPrime [ oldValue ] and not isPrime [ new_val ] ) :
        diff = - 1
    if ( not isPrime [ oldValue ] and isPrime [ new_val ] ) :
        diff = 1
    updateValueUtil ( st , 0 , n - 1 , i , diff , 0 )
def queryPrimes ( st , n , qs , qe ) :
    primesInRange = queryPrimesUtil ( st , 0 , n - 1 , qs , qe , 0 )
    print ( " Number ▁ of ▁ Primes ▁ in ▁ subarray ▁ from ▁ " , qs , " ▁ to ▁ " , qe , " ▁ = ▁ " , primesInRange )
def constructSTUtil ( arr , ss , se , st , si , isPrime ) :
    if ( ss == se ) :
        if ( isPrime [ arr [ ss ] ] ) :
            st [ si ] = 1
        else :
            st [ si ] = 0
        return st [ si ]
    mid = getMid ( ss , se )
    st [ si ] = constructSTUtil ( arr , ss , mid , st , si * 2 + 1 , isPrime ) + constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 , isPrime )
    return st [ si ]
def constructST ( arr , n , isPrime ) :
    x = ceil ( log ( n , 2 ) )
    max_size = 2 * pow ( 2 , x ) - 1
    st = [ 0 ] * ( max_size )
    constructSTUtil ( arr , 0 , n - 1 , st , 0 , isPrime )
    return st
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 5 , 7 , 9 ]
    n = len ( arr )
    isPrime = [ True ] * ( MAX + 1 )
    sieveOfEratosthenes ( isPrime )
    st = constructST ( arr , n , isPrime )
    start = 0
    end = 4
    queryPrimes ( st , n , start , end )
    i = 3
    x = 6
    updateValue ( arr , st , n , i , x , isPrime )
    start = 0
    end = 4
    queryPrimes ( st , n , start , end )

Index/key variables: i, index, new_val, oldValue, p, si, ss
Iterator variables: i, p
Python program:
def checkEVENodd ( arr , n , l , r ) :
    if ( arr [ r ] == 1 ) :
        print ( " odd " )
    else :
        print ( " even " )
arr = [ 1 , 1 , 0 , 1 ]
n = len ( arr )
checkEVENodd ( arr , n , 1 , 3 )

Index/key variables: r
Python program:
twos = [ 0 ] * 1000
fives = [ 0 ] * 1000
sum = 0
def returnTwos ( val ) :
    count = 0
    while ( val % 2 == 0 and val != 0 ) :
        val = val // 2
        count += 1
    return count
def returnFives ( val ) :
    count = 0
    while ( val % 5 == 0 and val != 0 ) :
        val = val // 5
        count += 1
    return count
def solve_queries ( arr , n ) :
    global sum
    arrr1 = list ( map ( int , input ( ) . split ( ) ) )
    typee = arrr1 [ 0 ]
    if ( typee == 1 ) :
        ql , qr , x = arrr1 [ 1 ] , arrr1 [ 2 ] , arrr1 [ 3 ]
        temp = returnTwos ( x )
        temp1 = returnFives ( x )
        i = ql - 1
        while ( i < qr ) :
            arr [ i ] = arr [ i ] * x
            twos [ i ] += temp
            fives [ i ] += temp1
            i += 1
    if ( typee == 2 ) :
        ql , qr , y = arrr1 [ 1 ] , arrr1 [ 2 ] , arrr1 [ 3 ]
        temp = returnTwos ( y )
        temp1 = returnFives ( y )
        i = ql - 1
        while ( i < qr ) :
            arr [ i ] = ( i - ql + 2 ) * y
            twos [ i ] = returnTwos ( i - ql + 2 ) + temp
            fives [ i ] = returnFives ( i - ql + 2 ) + temp1
            i += 1
    if ( typee == 3 ) :
        ql , qr = arrr1 [ 1 ] , arrr1 [ 2 ]
        sumtwos = 0
        sumfives = 0
        i = ql - 1
        while ( i < qr ) :
            sumtwos += twos [ i ]
            sumfives += fives [ i ]
            i += 1
        sum += min ( sumtwos , sumfives )
n , m = map ( int , input ( ) . split ( ) )
arr = list ( map ( int , input ( ) . split ( ) ) )
for i in range ( n ) :
    twos [ i ] = returnTwos ( arr [ i ] )
    fives [ i ] = returnFives ( arr [ i ] )
while ( m ) :
    m -= 1
    solve_queries ( arr , n )
print ( sum )

Index/key variables: i
Accumulator variables: count, m, sumfives, sumtwos
Iterator variables: i
Python program:
import math
def findMean ( arr , l , r ) :
    sum , count = 0 , 0
    for i in range ( l , r + 1 ) :
        sum += arr [ i ]
        count += 1
    mean = math . floor ( sum / count )
    return mean
arr = [ 1 , 2 , 3 , 4 , 5 ]
print ( findMean ( arr , 0 , 2 ) )
print ( findMean ( arr , 1 , 3 ) )
print ( findMean ( arr , 0 , 4 ) )

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i
Python program:
import math as mt
MAX = 1000005
prefixSum = [ 0 for i in range ( MAX ) ]
def calculatePrefixSum ( arr , n ) :
    prefixSum [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ]
def findMean ( l , r ) :
    if ( l == 0 ) :
        return mt . floor ( prefixSum [ r ] / ( r + 1 ) )
    return ( mt . floor ( ( prefixSum [ r ] - prefixSum [ l - 1 ] ) / ( r - l + 1 ) ) )
arr = [ 1 , 2 , 3 , 4 , 5 ]
n = len ( arr )
calculatePrefixSum ( arr , n )
print ( findMean ( 0 , 2 ) )
print ( findMean ( 1 , 3 ) )
print ( findMean ( 0 , 4 ) )

Index/key variables: i, r
Iterator variables: i
Python program:
def updateQuery ( arr , n , q , l , r , k ) :
    if ( q == 0 ) :
        arr [ l - 1 ] += k
        arr [ r ] += - k
    else :
        arr [ l - 1 ] += - k
        arr [ r ] += k
    return
def generateArray ( arr , n ) :
    for i in range ( 1 , n ) :
        arr [ i ] += arr [ i - 1 ]
    return
n = 5
arr = [ 0 for i in range ( n + 1 ) ]
q = 0 ; l = 1 ; r = 3 ; k = 2
updateQuery ( arr , n , q , l , r , k )
q , l , r , k = 1 , 3 , 5 , 3
updateQuery ( arr , n , q , l , r , k ) ;
q , l , r , k = 0 , 2 , 5 , 1
updateQuery ( arr , n , q , l , r , k )
generateArray ( arr , n )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, r
Iterator variables: i
Python program:
def calculateProduct ( A , L , R , P ) :
    L = L - 1
    R = R - 1
    ans = 1
    for i in range ( R + 1 ) :
        ans = ans * A [ i ]
        ans = ans % P
    return ans
A = [ 1 , 2 , 3 , 4 , 5 , 6 ]
P = 229
L = 2
R = 5
print ( calculateProduct ( A , L , R , P ) )
L = 1
R = 3
print ( calculateProduct ( A , L , R , P ) )

Index/key variables: i
Iterator variables: i
Python program:
def modInverse ( a , m ) :
    m0 , x0 , x1 = m , 0 , 1
    if m == 1 :
        return 0
    while a > 1 :
        q = a // m
        t = m
        m , a = a % m , t
        t = x0
        x0 = x1 - q * x0
        x1 = t
    if x1 < 0 :
        x1 += m0
    return x1
def calculate_Pre_Product ( A , N , P ) :
    pre_product [ 0 ] = A [ 0 ]
    for i in range ( 1 , N ) :
        pre_product [ i ] = pre_product [ i - 1 ] * A [ i ]
        pre_product [ i ] = pre_product [ i ] % P
def calculate_inverse_product ( A , N , P ) :
    inverse_product [ 0 ] = modInverse ( pre_product [ 0 ] , P )
    for i in range ( 1 , N ) :
        inverse_product [ i ] = modInverse ( pre_product [ i ] , P )
def calculateProduct ( A , L , R , P ) :
    L = L - 1
    R = R - 1
    ans = 0
    if L == 0 :
        ans = pre_product [ R ]
    else :
        ans = pre_product [ R ] * inverse_product [ L - 1 ]
    return ans
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    N = len ( A )
    P = 113
    MAX = 100
    pre_product = [ None ] * ( MAX )
    inverse_product = [ None ] * ( MAX )
    calculate_Pre_Product ( A , N , P )
    calculate_inverse_product ( A , N , P )
    L , R = 2 , 5
    print ( calculateProduct ( A , L , R , P ) )
    L , R = 1 , 3
    print ( calculateProduct ( A , L , R , P ) )

Index/key variables: R, i
Iterator variables: i
Python program:
MAX = 10000
prefix = [ 0 ] * ( MAX + 1 )
def buildPrefix ( ) :
    prime = [ 1 ] * ( MAX + 1 )
    p = 2
    while ( p * p <= MAX ) :
        if ( prime [ p ] == 1 ) :
            i = p * 2
            while ( i <= MAX ) :
                prime [ i ] = 0
                i += p
        p += 1
    for p in range ( 2 , MAX + 1 ) :
        prefix [ p ] = prefix [ p - 1 ]
        if ( prime [ p ] == 1 ) :
            prefix [ p ] += 1
def query ( L , R ) :
    return prefix [ R ] - prefix [ L - 1 ]
if __name__ == ' _ _ main _ _ ' :
    buildPrefix ( )
    L = 5
    R = 10
    print ( query ( L , R ) )
    L = 1
    R = 10
    print ( query ( L , R ) )

Index/key variables: R, i, p
Iterator variables: p
Python program:
def command ( brr , a , b ) :
    arr [ a ] ^= 1
    arr [ b + 1 ] ^= 1
def process ( arr , n ) :
    for k in range ( 1 , n + 1 , 1 ) :
        arr [ k ] ^= arr [ k - 1 ]
def result ( arr , n ) :
    for k in range ( 1 , n + 1 , 1 ) :
        print ( arr [ k ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    n = 5
    m = 3
    arr = [ 0 for i in range ( n + 2 ) ]
    command ( arr , 1 , 5 )
    command ( arr , 2 , 5 )
    command ( arr , 3 , 5 )
    process ( arr , n )
    result ( arr , n )

Index/key variables: a, k
Iterator variables: k
Python program:
def incrementByD ( arr , q_arr , n , m , d ) :
    sum = [ 0 for i in range ( n ) ]
    for i in range ( m ) :
        sum [ q_arr [ i ] [ 0 ] ] += d
        if ( ( q_arr [ i ] [ 1 ] + 1 ) < n ) :
            sum [ q_arr [ i ] [ 1 ] + 1 ] -= d
    arr [ 0 ] += sum [ 0 ]
    for i in range ( 1 , n ) :
        sum [ i ] += sum [ i - 1 ]
        arr [ i ] += sum [ i ]
def printArray ( arr , n ) :
    for i in arr :
        print ( i , end = " ▁ " )
arr = [ 3 , 5 , 4 , 8 , 6 , 1 ]
q_arr = [ [ 0 , 3 ] , [ 4 , 5 ] , [ 1 , 4 ] , [ 0 , 1 ] , [ 2 , 5 ] ]
n = len ( arr )
m = len ( q_arr )
d = 2
print ( " Original ▁ Array : " )
printArray ( arr , n )
incrementByD ( arr , q_arr , n , m , d )
print ( " Modified Array : " )
printArray ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 1000001
class Query :
    def __init__ ( self , l , r , idx ) :
        self . l = l
        self . r = r
        self . idx = idx
def update ( idx , val , bit , n ) :
    while idx <= n :
        bit [ idx ] += val
        idx += idx & - idx
def query ( idx , bit , n ) :
    summ = 0
    while idx :
        summ += bit [ idx ]
        idx -= idx & - idx
    return summ
def answeringQueries ( arr , n , queries , q ) :
    bit = [ 0 ] * ( n + 1 )
    last_visit = [ - 1 ] * MAX
    ans = [ 0 ] * q
    query_counter = 0
    for i in range ( n ) :
        if last_visit [ arr [ i ] ] != - 1 :
            update ( last_visit [ arr [ i ] ] + 1 , - 1 , bit , n )
        last_visit [ arr [ i ] ] = i
        update ( i + 1 , 1 , bit , n )
        while query_counter < q and queries [ query_counter ] . r == i :
            ans [ queries [ query_counter ] . idx ] = query ( queries [ query_counter ] . r + 1 , bit , n ) - query ( queries [ query_counter ] . l , bit , n )
            query_counter += 1
    for i in range ( q ) :
        print ( ans [ i ] )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 1 , 2 , 1 , 3 ]
    n = len ( a )
    queries = [ Query ( 0 , 4 , 0 ) , Query ( 1 , 3 , 1 ) , Query ( 2 , 4 , 2 ) ]
    q = len ( queries )
    queries . sort ( key = lambda x : x . r )
    answeringQueries ( a , n , queries , q )

Index/key variables: i, idx, query_counter
Accumulator variables: summ
Iterator variables: i
Class/struct names: Query
Python program:
MAX = 100000
tree = [ 0 ] * MAX
lazy = [ False ] * MAX
def toggle ( node : int , st : int , en : int , us : int , ue : int ) :
    if lazy [ node ] :
        lazy [ node ] = False
        tree [ node ] = en - st + 1 - tree [ node ]
        if st < en :
            lazy [ node << 1 ] = not lazy [ node << 1 ]
            lazy [ 1 + ( node << 1 ) ] = not lazy [ 1 + ( node << 1 ) ]
    if st > en or us > en or ue < st :
        return
    if us <= st and en <= ue :
        tree [ node ] = en - st + 1 - tree [ node ]
        if st < en :
            lazy [ node << 1 ] = not lazy [ node << 1 ]
            lazy [ 1 + ( node << 1 ) ] = not lazy [ 1 + ( node << 1 ) ]
        return
    mid = ( st + en ) // 2
    toggle ( ( node << 1 ) , st , mid , us , ue )
    toggle ( ( node << 1 ) + 1 , mid + 1 , en , us , ue )
    if st < en :
        tree [ node ] = tree [ node << 1 ] + tree [ ( node << 1 ) + 1 ]
def countQuery ( node : int , st : int , en : int , qs : int , qe : int ) -> int :
    if st > en or qs > en or qe < st :
        return 0
    if lazy [ node ] :
        lazy [ node ] = False
        tree [ node ] = en - st + 1 - tree [ node ]
        if st < en :
            lazy [ node << 1 ] = not lazy [ node << 1 ]
            lazy [ ( node << 1 ) + 1 ] = not lazy [ ( node << 1 ) + 1 ]
    if qs <= st and en <= qe :
        return tree [ node ]
    mid = ( st + en ) // 2
    return countQuery ( ( node << 1 ) , st , mid , qs , qe ) + countQuery ( ( node << 1 ) + 1 , mid + 1 , en , qs , qe )
if __name__ == " _ _ main _ _ " :
    n = 5
toggle ( 1 , 0 , n - 1 , 1 , 2 )
toggle ( 1 , 0 , n - 1 , 2 , 4 )
print ( countQuery ( 1 , 0 , n - 1 , 2 , 3 ) )
toggle ( 1 , 0 , n - 1 , 2 , 4 )
print ( countQuery ( 1 , 0 , n - 1 , 1 , 4 ) )

Index/key variables: node
Python program:
import bisect
def countPairs ( a , n , x , k ) :
    a . sort ( )
    ans = 0
    for i in range ( n ) :
        d = ( a [ i ] - 1 ) // x
        it1 = bisect . bisect_left ( a , max ( ( d + k ) * x , a [ i ] ) )
        it2 = bisect . bisect_left ( a , max ( ( d + k + 1 ) * x , a [ i ] ) )
        ans += it2 - it1
    return ans
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 3 , 5 , 7 ]
    n = len ( a )
    x = 2
    k = 1
    print ( countPairs ( a , n , x , k ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
import sys
def probability ( a , b , size1 , size2 ) :
    max1 = - ( sys . maxsize - 1 )
    count1 = 0
    for i in range ( size1 ) :
        if a [ i ] > max1 :
            count1 = 1
        elif a [ i ] == max1 :
            count1 += 1
    max2 = - ( sys . maxsize - 1 )
    count2 = 0
    for i in range ( size2 ) :
        if b [ i ] > max2 :
            max2 = b [ i ]
            count2 = 1
        elif b [ i ] == max2 :
            count2 += 1
    return round ( ( count1 * count2 ) / ( size1 * size2 ) , 6 )
a = [ 1 , 2 , 3 ]
b = [ 1 , 3 , 3 ]
size1 = len ( a )
size2 = len ( b )
print ( probability ( a , b , size1 , size2 ) )

Index/key variables: i
Accumulator variables: count1, count2
Iterator variables: i
Python program:
def countDe ( arr , n ) :
    i = 0
    v = arr . copy ( )
    arr . sort ( )
    count1 = 0
    i = 0
    while ( i < n ) :
        if ( arr [ i ] != v [ i ] ) :
            count1 = count1 + 1
        i = i + 1
    arr . sort ( reverse = True )
    count2 = 0
    i = 0
    while ( i < n ) :
        if ( arr [ i ] != v [ i ] ) :
            count2 = count2 + 1
        i = i + 1
    return ( min ( count1 , count2 ) )
arr = [ 5 , 9 , 21 , 17 , 13 ]
n = 5
print ( " Minimum ▁ Dearrangement ▁ = " , countDe ( arr , n ) )

Index/key variables: i
Python program:
def printMinimumProduct ( arr , n ) :
    first_min = min ( arr [ 0 ] , arr [ 1 ] )
    second_min = max ( arr [ 0 ] , arr [ 1 ] )
    for i in range ( 2 , n ) :
        if ( arr [ i ] < first_min ) :
            second_min = first_min
            first_min = arr [ i ]
        elif ( arr [ i ] < second_min ) :
            second_min = arr [ i ]
    return first_min * second_min
a = [ 11 , 8 , 5 , 7 , 5 , 100 ]
n = len ( a )
print ( printMinimumProduct ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def noOfTriples ( arr , n ) :
    arr . sort ( )
    count = 0
    for i in range ( n ) :
        if arr [ i ] == arr [ 2 ] :
            count += 1
    if arr [ 0 ] == arr [ 2 ] :
        return ( count - 2 ) * ( count - 1 ) * ( count ) / 6
    elif arr [ 1 ] == arr [ 2 ] :
        return ( count - 1 ) * ( count ) / 2
    return count
arr = [ 1 , 3 , 3 , 4 ]
n = len ( arr )
print ( noOfTriples ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def checkReverse ( arr , n ) :
    temp = [ 0 ] * n
    for i in range ( n ) :
        temp [ i ] = arr [ i ]
    temp . sort ( )
    for front in range ( n ) :
        if temp [ front ] != arr [ front ] :
            break
    for back in range ( n - 1 , - 1 , - 1 ) :
        if temp [ back ] != arr [ back ] :
            break
    if front >= back :
        return True
    while front != back :
        front += 1
        if arr [ front - 1 ] < arr [ front ] :
            return False
    return True
arr = [ 1 , 2 , 5 , 4 , 3 ]
n = len ( arr )
if checkReverse ( arr , n ) == True :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: back, front, i
Iterator variables: back, front, i
Python program:
import math as mt
def checkReverse ( arr , n ) :
    if ( n == 1 ) :
        return True
    i = 1
    for i in range ( 1 , n ) :
        if arr [ i - 1 ] < arr [ i ] :
            if ( i == n ) :
                return True
        else :
            break
    j = i
    while ( j < n and arr [ j ] < arr [ j - 1 ] ) :
        if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :
            return False
        j += 1
    if ( j == n ) :
        return True
    k = j
    if ( arr [ k ] < arr [ i - 1 ] ) :
        return False
    while ( k > 1 and k < n ) :
        if ( arr [ k ] < arr [ k - 1 ] ) :
            return False
        k += 1
    return True
arr = [ 1 , 3 , 4 , 10 , 9 , 8 ]
n = len ( arr )
if checkReverse ( arr , n ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j, k
Iterator variables: i
Python program:
def MinOperation ( a , b , n ) :
    a . sort ( reverse = False )
    b . sort ( reverse = False )
    result = 0
    for i in range ( 0 , n , 1 ) :
        if ( a [ i ] > b [ i ] ) :
            result = result + abs ( a [ i ] - b [ i ] )
        elif ( a [ i ] < b [ i ] ) :
            result = result + abs ( a [ i ] - b [ i ] )
    return result
if __name__ == ' _ _ main _ _ ' :
    a = [ 3 , 1 , 1 ]
    b = [ 1 , 2 , 2 ]
    n = len ( a )
    print ( MinOperation ( a , b , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def sortExceptUandL ( a , l , u , n ) :
    b = [ 0 ] * ( n - ( u - l + 1 ) )
    for i in range ( 0 , l ) :
        b [ i ] = a [ i ]
    for i in range ( u + 1 , n ) :
        b [ l + ( i - ( u + 1 ) ) ] = a [ i ]
    b . sort ( )
    for i in range ( 0 , l ) :
        a [ i ] = b [ i ]
    for i in range ( u + 1 , n ) :
        a [ i ] = b [ l + ( i - ( u + 1 ) ) ]
a = [ 5 , 4 , 3 , 12 , 14 , 9 ]
n = len ( a )
l = 2
u = 4
sortExceptUandL ( a , l , u , n )
for i in range ( 0 , n ) :
    print ( " { } ▁ " . format ( a [ i ] ) , end = " " )

Index/key variables: i
Iterator variables: i
Python program:
def sortExcept ( arr , k , n ) :
    arr [ k ] , arr [ - 1 ] = arr [ - 1 ] , arr [ k ]
    arr = sorted ( arr , key = lambda i : ( i is arr [ - 1 ] , i ) )
    last = arr [ - 1 ]
    i = n - 1
    while i > k :
        arr [ i ] = arr [ i - 1 ]
        i -= 1
    arr [ k ] = last
    return arr
if __name__ == ' _ _ main _ _ ' :
    a = [ 10 , 4 , 11 , 7 , 6 , 20 ]
    k = 2
    n = len ( a )
    a = sortExcept ( a , k , n )
    print ( " ▁ " . join ( list ( map ( str , a ) ) ) )

Index/key variables: i, k
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
def push ( head_ref , new_data ) :
    new_node = Node ( )
    new_node . data = new_data
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def printList ( head ) :
    while ( head != None ) :
        print ( head . data , end = " - > " )
        head = head . next
def sortlist ( arr , N , head ) :
    hash = dict ( )
    temp = head
    while ( temp != None ) :
        hash [ temp . data ] = hash . get ( temp . data , 0 ) + 1
        temp = temp . next
    temp = head
    for i in range ( N ) :
        frequency = hash . get ( arr [ i ] , 0 )
        while ( frequency > 0 ) :
            frequency = frequency - 1
            temp . data = arr [ i ]
            temp = temp . next
head = None
arr = [ 5 , 1 , 3 , 2 , 8 ]
N = len ( arr )
head = push ( head , 3 )
head = push ( head , 2 )
head = push ( head , 5 )
head = push ( head , 8 )
head = push ( head , 5 )
head = push ( head , 2 )
head = push ( head , 1 )
sortlist ( arr , N , head )
print ( " Sorted ▁ List : " )
printList ( head )

Index/key variables: i
Iterator variables: i
Class/struct names: Node
Python program:
def maxPartitions ( arr , n ) :
    ans = 0 ; max_so_far = 0
    for i in range ( 0 , n ) :
        max_so_far = max ( max_so_far , arr [ i ] )
        if ( max_so_far == i ) :
            ans += 1
    return ans
arr = [ 1 , 0 , 2 , 3 , 4 ]
n = len ( arr )
print ( maxPartitions ( arr , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def rankify ( A ) :
    R = [ 0 for x in range ( len ( A ) ) ]
    for i in range ( len ( A ) ) :
        ( r , s ) = ( 1 , 1 )
        for j in range ( len ( A ) ) :
            if j != i and A [ j ] < A [ i ] :
                r += 1
            if j != i and A [ j ] == A [ i ] :
                s += 1
        R [ i ] = r + ( s - 1 ) / 2
    return R
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 2 , 5 , 2 , 1 , 25 , 2 ]
    print ( A )
    print ( rankify ( A ) )

Index/key variables: i, j
Accumulator variables: r, s
Iterator variables: i, j
Python program:
def min_noOf_operation ( arr , n , k ) :
    res = 0
    for i in range ( 1 , n ) :
        noOfSubtraction = 0
        if ( arr [ i ] > arr [ i - 1 ] ) :
            noOfSubtraction = ( arr [ i ] - arr [ i - 1 ] ) / k ;
            if ( ( arr [ i ] - arr [ i - 1 ] ) % k != 0 ) :
                noOfSubtraction += 1
            arr [ i ] = arr [ i ] - k * noOfSubtraction
        res = res + noOfSubtraction
    return int ( res )
arr = [ 1 , 1 , 2 , 3 ]
N = len ( arr )
k = 5
print ( min_noOf_operation ( arr , N , k ) )

Index/key variables: i
Accumulator variables: noOfSubtraction
Iterator variables: i
Python program:
def maxSum ( arr , n ) :
    arr . sort ( )
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ] * i
    return sum
arr = [ 3 , 5 , 6 , 1 ]
n = len ( arr )
print ( maxSum ( arr , n ) )

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