dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def Next_greater ( a , n , x ) :
    a = sorted ( a )
    low , high , ans = 0 , n - 1 , x + 1
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( a [ mid ] <= ans ) :
            if ( a [ mid ] == ans ) :
                ans += 1
                high = n - 1
            low = mid + 1
        else :
            high = mid - 1
    return ans
a = [ 1 , 5 , 10 , 4 , 7 ]
x = 4
n = len ( a )
print ( Next_greater ( a , n , x ) )

Index/key variables: mid
Accumulator variables: ans
Python program:
MAX = 10000
import sys
from math import ceil , floor
def xorOnSortedArray ( arr , n , k , x ) :
    arr1 = [ 0 for i in range ( MAX + 1 ) ]
    arr2 = [ 0 for i in range ( MAX + 1 ) ]
    xor_val = [ 0 for i in range ( MAX + 1 ) ]
    for i in range ( n ) :
        arr1 [ arr [ i ] ] += 1
    for i in range ( MAX + 1 ) :
        xor_val [ i ] = i ^ x
    while ( k > 0 ) :
        k -= 1
        count = 0
        for i in range ( MAX + 1 ) :
            store = arr1 [ i ]
            if ( arr1 [ i ] > 0 ) :
                if ( count % 2 == 0 ) :
                    div = arr1 [ i ] // 2 + 1
                    arr1 [ i ] = arr1 [ i ] - div
                    arr2 [ xor_val [ i ] ] += div
                elif ( count % 2 != 0 ) :
                    div = arr1 [ i ] // 2
                    arr1 [ i ] = arr1 [ i ] - div
                    arr2 [ xor_val [ i ] ] += div
            count = count + store
        for i in range ( MAX + 1 ) :
            arr1 [ i ] = arr1 [ i ] + arr2 [ i ]
            arr2 [ i ] = 0
    mn = sys . maxsize
    mx = - sys . maxsize - 1
    for i in range ( MAX + 1 ) :
        if ( arr1 [ i ] > 0 ) :
            if ( mn > i ) :
                mn = i
            if ( mx < i ) :
                mx = i
    print ( mn , mx )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 605 , 986 ]
    n = len ( arr )
    k = 548
    x = 569
    xorOnSortedArray ( arr , n , k , x )

Index/key variables: i
Accumulator variables: k
Iterator variables: i
Python program:
def printArrangement ( a , n ) :
    a = sorted ( a )
    b = [ 0 for i in range ( n ) ]
    low = 0
    high = n - 1
    for i in range ( n ) :
        if ( i % 2 == 0 ) :
            b [ low ] = a [ i ]
            low += 1
        else :
            b [ high ] = a [ i ]
            high -= 1
    for i in range ( n ) :
        if ( i == 0 ) :
            if ( b [ n - 1 ] + b [ 1 ] <= b [ i ] ) :
                print ( " - 1" )
                return
        elif ( i == ( n - 1 ) ) :
            if ( b [ n - 2 ] + b [ 0 ] <= b [ i ] ) :
                print ( " - 1" )
                return
        else :
            if ( b [ i - 1 ] + b [ i + 1 ] <= b [ i ] ) :
                print ( " - 1" )
                return
    for i in range ( n ) :
        print ( b [ i ] , end = " ▁ " )
a = [ 1 , 4 , 4 , 3 , 2 ]
n = len ( a )
printArrangement ( a , n )

Index/key variables: high, i, low
Iterator variables: i
Python program:
def findSubarray ( a , k , n ) :
    vec = [ ]
    for i in range ( n - k + 1 ) :
        temp = [ ]
        for j in range ( i , i + k ) :
            temp . append ( a [ j ] )
        vec . append ( temp )
    vec = sorted ( vec )
    return vec [ len ( vec ) - 1 ]
a = [ 1 , 4 , 3 , 2 , 5 ]
k = 4
n = len ( a )
ans = findSubarray ( a , k , n )
for it in ans :
    print ( it , end = " ▁ " )

Index/key variables: j
Accumulator variables: temp, vec
Iterator variables: i, it, j
Python program:
import sys
def knapSack ( W , wt , val , n ) :
    maxratio = - sys . maxsize - 1 ;
    maxindex = 0 ;
    for i in range ( n ) :
        if ( ( val [ i ] / wt [ i ] ) > maxratio ) :
            maxratio = ( val [ i ] / wt [ i ] ) ;
            maxindex = i ;
    return ( W * maxratio ) ;
val = [ 14 , 27 , 44 , 19 ] ;
wt = [ 6 , 7 , 9 , 8 ] ;
n = len ( val ) ;
W = 50 ;
print ( knapSack ( W , wt , val , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def sortArray ( a , n ) :
    ans = [ ]
    for i in range ( n ) :
        if ( a [ i ] >= 0 ) :
            ans . append ( a [ i ] )
    ans = sorted ( ans )
    j = 0
    for i in range ( n ) :
        if ( a [ i ] >= 0 ) :
            a [ i ] = ans [ j ]
            j += 1
    for i in range ( n ) :
        print ( a [ i ] , end = " ▁ " )
arr = [ 2 , - 6 , - 3 , 8 , 4 , 1 ]
n = len ( arr )
sortArray ( arr , n )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i
Python program:
import sys
def solution ( arr , x ) :
    arr . sort ( ) ;
    closestSum = sys . maxsize ;
    for i in range ( len ( arr ) - 2 ) :
        ptr1 = i + 1 ; ptr2 = len ( arr ) - 1 ;
        while ( ptr1 < ptr2 ) :
            sum = arr [ i ] + arr [ ptr1 ] + arr [ ptr2 ] ;
            if ( abs ( x - sum ) < abs ( x - closestSum ) ) :
                closestSum = sum ;
            if ( sum > x ) :
                ptr2 -= 1 ;
            else :
                ptr1 += 1 ;
    return closestSum ;
if __name__ == " _ _ main _ _ " :
    arr = [ - 1 , 2 , 1 , - 4 ] ;
    x = 1 ;
    print ( solution ( arr , x ) ) ;

Index/key variables: i, ptr1, ptr2
Iterator variables: i
Python program:
class node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def inorder ( root ) :
    if ( root != None ) :
        inorder ( root . left )
        print ( root . data , end = " ▁ " )
        inorder ( root . right )
def merge ( root1 , root2 ) :
    if ( not root1 and not root2 ) :
        return
    if ( not root1 ) :
        inorder ( root2 )
        return
    if ( not root2 ) :
        inorder ( root1 )
        return
    temp1 = root1
    prev1 = None
    while ( temp1 . left ) :
        prev1 = temp1
        temp1 = temp1 . left
    temp2 = root2
    prev2 = None
    while ( temp2 . left ) :
        prev2 = temp2
        temp2 = temp2 . left
    if ( temp1 . data <= temp2 . data ) :
        print ( temp1 . data , end = " ▁ " )
        if ( prev1 == None ) :
            merge ( root1 . right , root2 )
        else :
            prev1 . left = temp1 . right
            merge ( root1 , root2 )
    else :
        print ( temp2 . data , end = " ▁ " )
        if ( prev2 == None ) :
            merge ( root1 , root2 . right )
        else :
            prev2 . left = temp2 . right
            merge ( root1 , root2 )
if __name__ == ' _ _ main _ _ ' :
    root1 = None
    root2 = None
    root1 = node ( 3 )
    root1 . left = node ( 1 )
    root1 . right = node ( 5 )
    root2 = node ( 4 )
    root2 . left = node ( 2 )
    root2 . right = node ( 6 )
    merge ( root1 , root2 )

Class/struct names: node
Python program:
def print_in_order ( a1 , a2 , n , m ) :
    mp = dict . fromkeys ( a1 , 0 ) ;
    for i in range ( n ) :
        mp [ a1 [ i ] ] += 1 ;
    for i in range ( m ) :
        if a2 [ i ] in mp . keys ( ) :
            for j in range ( mp [ a2 [ i ] ] ) :
                print ( a2 [ i ] , end = " ▁ " ) ;
            del ( mp [ a2 [ i ] ] ) ;
    for key , value in mp . items ( ) :
        for j in range ( value ) :
            print ( key , end = " ▁ " ) ;
    print ( ) ;
if __name__ == " _ _ main _ _ " :
    a1 = [ 2 , 1 , 2 , 5 , 7 , 1 , 9 , 3 , 6 , 8 , 8 ] ;
    a2 = [ 2 , 1 , 8 , 3 ] ;
    n = len ( a1 ) ;
    m = len ( a2 ) ;
    print_in_order ( a1 , a2 , n , m ) ;

Index/key variables: i
Iterator variables: i, j, key, value
Python program:
def IsSorted ( A , B , n ) :
    for i in range ( n ) :
        x = max ( A [ i ] , B [ i ] ) ;
        y = min ( A [ i ] , B [ i ] ) ;
        A [ i ] = x ;
        B [ i ] = y ;
    for i in range ( 1 , n ) :
        if ( A [ i ] <= A [ i - 1 ] or B [ i ] <= B [ i - 1 ] ) :
            return False ;
    return True ;
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 4 , 3 , 5 , 7 ] ;
    B = [ 2 , 2 , 5 , 8 , 9 ] ;
    n = len ( A ) ;
    if ( IsSorted ( A , B , n ) ) :
        print ( True )
    else :
        print ( False )

Index/key variables: i
Iterator variables: i
Python program:
def K_multiple ( a , n , k ) :
    a . sort ( ) ;
    s = set ( ) ;
    for i in range ( n ) :
        if ( ( a [ i ] % k == 0 and a [ i ] // k not in s ) or a [ i ] % k != 0 ) :
            s . add ( a [ i ] ) ;
    for i in s :
        print ( i , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 3 , 4 , 5 , 6 , 10 ] ;
    k = 2 ;
    n = len ( a ) ;
    K_multiple ( a , n , k ) ;

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def maxWater ( height , n ) :
    maximum = 0 ;
    i = 0
    j = n - 1
    while ( i < j ) :
        if ( height [ i ] < height [ j ] ) :
            maximum = max ( maximum , ( j - i - 1 ) * height [ i ] ) ;
            i += 1 ;
        elif ( height [ j ] < height [ i ] ) :
            maximum = max ( maximum , ( j - i - 1 ) * height [ j ] ) ;
            j -= 1 ;
        else :
            maximum = max ( maximum , ( j - i - 1 ) * height [ i ] ) ;
            i += 1 ;
            j -= 1 ;
    return maximum ;
height = [ 2 , 1 , 3 , 4 , 6 , 5 ]
n = len ( height )
print ( maxWater ( height , n ) ) ;

Index/key variables: i, j
Python program:
def check ( arr , n ) :
    modify = 0
    if ( arr [ 0 ] > arr [ 1 ] ) :
        arr [ 0 ] = arr [ 1 ] // 2
        modify += 1
    for i in range ( 1 , n - 1 ) :
        if ( ( arr [ i - 1 ] < arr [ i ] and arr [ i + 1 ] < arr [ i ] ) or ( arr [ i - 1 ] > arr [ i ] and arr [ i + 1 ] > arr [ i ] ) ) :
            arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) // 2
            if ( arr [ i ] == arr [ i - 1 ] or arr [ i ] == arr [ i + 1 ] ) :
                return False
            modify += 1
    if ( arr [ n - 1 ] < arr [ n - 2 ] ) :
        modify += 1
    if ( modify > 1 ) :
        return False
    return True
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 8 , 6 , 9 , 12 ]
    n = len ( arr )
    if ( check ( arr , n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: modify
Iterator variables: i
Python program:
N , M = 2 , 2
def isMatrixInc ( a ) :
    for i in range ( N ) :
        for j in range ( M ) :
            if ( i - 1 >= 0 ) :
                if ( a [ i ] [ j ] <= a [ i - 1 ] [ j ] ) :
                    return False ;
            if ( j - 1 >= 0 ) :
                if ( a [ i ] [ j ] <= a [ i ] [ j - 1 ] ) :
                    return False ;
    return True ;
if __name__ == " _ _ main _ _ " :
    a = [ [ 2 , 10 ] , [ 11 , 20 ] ] ;
    if ( isMatrixInc ( a ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 10000005
prime = [ False ] * N
def seive ( ) :
    for i in range ( 2 , N ) :
        if not prime [ i ] :
            for j in range ( i + 1 , N ) :
                prime [ j ] = True
    prime [ 1 ] = True
def maxSizeArr ( arr , n , k ) :
    v , diff = [ ] , [ ]
    for i in range ( n ) :
        if prime [ arr [ i ] ] :
            v . append ( i )
    for i in range ( 1 , len ( v ) ) :
        diff . append ( v [ i ] - v [ i - 1 ] - 1 )
    diff . sort ( )
    for i in range ( 1 , len ( diff ) ) :
        diff [ i ] += diff [ i - 1 ]
    if k > n or ( k == 0 and len ( v ) ) :
        return - 1
    elif len ( v ) <= k :
        return ( n - k )
    elif len ( v ) > k :
        tt = len ( v ) - k
        s = 0
        s += diff [ tt - 1 ]
        res = n - ( len ( v ) + s )
        return res
if __name__ == " _ _ main _ _ " :
    seive ( )
    arr = [ 2 , 4 , 2 , 2 , 4 , 2 , 4 , 2 ]
    n = len ( arr )
    k = 2
    print ( maxSizeArr ( arr , n , k ) )

Index/key variables: i, j
Accumulator variables: diff, v
Iterator variables: i, j
Python program:
def sortArr ( arr , n ) :
    mp = [ ]
    for i in range ( n ) :
        count = 0
        k = arr [ i ]
        while ( k ) :
            k = k & k - 1
            count += 1
        mp . append ( ( 32 - count , arr [ i ] ) )
    mp . sort ( key = lambda x : x [ 0 ] )
    for it in mp :
        print ( it [ 1 ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 2 , 3 , 9 , 4 , 6 , 7 , 15 , 32 ]
    n = len ( arr )
    sortArr ( arr , n )

Index/key variables: i
Accumulator variables: count, mp
Iterator variables: i, it
Python program:
def findSmallestNumber ( arr , n ) :
    dp = [ float ( ' inf ' ) ] * n
    result = [ ( - 1 , 0 ) ] * n
    arr . sort ( )
    q = [ ]
    for i in arr :
        if i != 0 :
            if dp [ i % n ] > 10 ** 9 :
                q . append ( i % n )
                dp [ i % n ] = 1
                result [ i % n ] = - 1 , i
    while len ( q ) > 0 :
        u = q . pop ( 0 )
        for i in arr :
            v = ( u * 10 + i ) % n
            if dp [ u ] + 1 < dp [ v ] :
                dp [ v ] = dp [ u ] + 1
                q . append ( v )
                result [ v ] = u , i
    if dp [ 0 ] > 10 ** 9 :
        return - 1
    else :
        ans = [ ]
        u = 0
        while u != - 1 :
            ans . append ( result [ u ] [ 1 ] )
            u = result [ u ] [ 0 ]
        ans = ans [ : : - 1 ]
        for i in ans :
            return i
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 2 , 3 ]
    n = 12
    print ( findSmallestNumber ( arr , n ) )

Index/key variables: u, v
Accumulator variables: ans, q
Iterator variables: i
Python program:
mod = 1000000007
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
def nCr ( n , r ) :
    return int ( fact ( n ) / ( fact ( r ) * fact ( n - r ) ) )
def powmod ( a , n ) :
    if ( n == 0 ) :
        return 1
    pt = powmod ( a , int ( n / 2 ) )
    pt = ( pt * pt ) % mod
    if ( n % 2 ) :
        return ( pt * a ) % mod
    else :
        return pt
def CountSubset ( arr , n ) :
    ans = powmod ( 2 , n - 1 )
    arr . sort ( reverse = False )
    for i in range ( n ) :
        j = i + 1
        while ( j < n and arr [ j ] == arr [ i ] ) :
            r = n - 1 - j
            l = i
            ans = ( ans + nCr ( l + r , l ) ) % mod
            j += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 2 ]
    n = len ( arr )
    print ( CountSubset ( arr , n ) )

Index/key variables: i, j
Iterator variables: i
Python program:
mod = 1000000007
arr = [ [ None for i in range ( 1001 ) ] for j in range ( 1001 ) ]
def Preprocess ( ) :
    arr [ 0 ] [ 0 ] = 1
    for i in range ( 1 , 1001 ) :
        arr [ i ] [ 0 ] = 1
        for j in range ( 1 , i ) :
            arr [ i ] [ j ] = ( arr [ i - 1 ] [ j - 1 ] + arr [ i - 1 ] [ j ] ) % mod
        arr [ i ] [ i ] = 1
def powmod ( a , n ) :
    if not n :
        return 1
    pt = powmod ( a , n // 2 )
    pt = ( pt * pt ) % mod
    if n % 2 :
        return ( pt * a ) % mod
    else :
        return pt
def CountSubset ( val , n ) :
    ans = powmod ( 2 , n - 1 )
    val . sort ( )
    for i in range ( 0 , n ) :
        j = i + 1
        while j < n and val [ j ] == val [ i ] :
            r = n - 1 - j
            l = i
            ans = ( ans + arr [ l + r ] [ l ] ) % mod
            j += 1
    return ans
if __name__ == " _ _ main _ _ " :
    Preprocess ( )
    val = [ 2 , 3 , 2 ]
    n = len ( val )
    print ( CountSubset ( val , n ) )

Index/key variables: i, j, l
Iterator variables: i, j
Python program:
def reArrange ( words , n ) :
    mp = { }
    for i in range ( n ) :
        mp [ words [ i ] ] = i + 1
    words . sort ( ) ;
    for i in range ( n ) :
        print ( mp [ words [ i ] ] , end = " ▁ " )
words = [ " live " , " place " , " travel " , " word " , " sky " ]
n = len ( words )
reArrange ( words , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
MAX = 100000
def findSumofEle ( arr1 , m , arr2 , n ) :
    hash = [ 0 for i in range ( MAX ) ]
    for i in range ( n ) :
        hash [ arr2 [ i ] ] += 1
    for i in range ( 1 , MAX , 1 ) :
        hash [ i ] = hash [ i ] + hash [ i - 1 ]
    maximumFreq = 0
    for i in range ( m ) :
        maximumFreq = max ( maximumFreq , hash [ arr1 [ i ] ] )
    sumOfElements = 0
    for i in range ( m ) :
        if ( maximumFreq == hash [ arr1 [ i ] ] ) :
            sumOfElements += arr1 [ i ]
    return sumOfElements
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 2 , 5 , 6 , 8 ]
    arr2 = [ 4 , 10 ]
    m = len ( arr1 )
    n = len ( arr2 )
    print ( findSumofEle ( arr1 , m , arr2 , n ) )

Index/key variables: i
Accumulator variables: sumOfElements
Iterator variables: i
Python program:
def PrintBothArrays ( a , n ) :
    v1 , v2 = [ ] , [ ] ;
    mpp = dict . fromkeys ( a , 0 ) ;
    for i in range ( n ) :
        mpp [ a [ i ] ] += 1 ;
        if ( mpp [ a [ i ] ] == 1 ) :
            v1 . append ( a [ i ] ) ;
        elif ( mpp [ a [ i ] ] == 2 ) :
            v2 . append ( a [ i ] ) ;
        else :
            print ( " Not ▁ possible " ) ;
            return ;
    v1 . sort ( ) ;
    print ( " Strictly ▁ increasing ▁ array ▁ is : " ) ;
    for it in v1 :
        print ( it , end = " ▁ " ) ;
    v2 . sort ( reverse = True ) ;
    print ( " Strictly decreasing array is : " ) ;
    for it in v2 :
        print ( it , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    a = [ 7 , 2 , 7 , 3 , 3 , 1 , 4 ] ;
    n = len ( a ) ;
    PrintBothArrays ( a , n ) ;

Index/key variables: i
Accumulator variables: v1, v2
Iterator variables: i, it
Python program:
def isUgly ( n ) :
    while n % 2 == 0 :
        n = n // 2
    while n % 3 == 0 :
        n = n // 3
    while n % 5 == 0 :
        n = n // 5
    if n == 1 :
        return True
    return False
def sortUglyNumbers ( arr , n ) :
    list = [ ]
    for i in range ( 0 , n ) :
        if isUgly ( arr [ i ] ) :
            list . append ( arr [ i ] )
            arr [ i ] = - 1
    list . sort ( )
    j = 0
    for i in range ( 0 , n ) :
        if arr [ i ] == - 1 :
            print ( list [ j ] , end = " ▁ " )
            j += 1
        else :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 7 , 12 , 10 ]
    n = len ( arr )
    sortUglyNumbers ( arr , n )

Index/key variables: i, j
Accumulator variables: list
Iterator variables: i
Python program:
def printArr ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " ) ;
def sortArr ( arr , n , k ) :
    prev = - 1 ;
    for i in range ( n ) :
        if ( arr [ i ] % k == 0 ) :
            if ( prev != - 1 ) :
                temp = arr [ prev + 1 : i ] ;
                temp . sort ( ) ;
                arr = arr [ : prev + 1 ] + temp + arr [ i : ] ;
            prev = i ;
    printArr ( arr , n ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 1 , 13 , 3 , 7 , 8 , 21 , 13 , 12 ] ;
    n = len ( arr ) ;
    k = 2 ;
    sortArr ( arr , n , k ) ;

Index/key variables: i
Iterator variables: i
Python program:
def printNumbers ( arr , n ) :
    arr . sort ( )
    A , B = arr [ n - 1 ] , - 1
    for i in range ( n - 2 , - 1 , - 1 ) :
        if A % arr [ i ] != 0 :
            B = arr [ i ]
            break
        if i - 1 >= 0 and arr [ i ] == arr [ i - 1 ] :
            B = arr [ i ]
            break
    print ( " A ▁ = " , A , " , ▁ B ▁ = " , B )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 8 , 16 , 1 , 2 , 4 ]
    n = len ( arr )
    printNumbers ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def printArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " ) ;
def removeMin ( arr , n ) :
    minVal = arr [ 0 ] ;
    for i in range ( 1 , n ) :
        minVal = min ( minVal , arr [ i ] ) ;
    for i in range ( n ) :
        arr [ i ] = arr [ i ] - minVal ;
def removeFromMax ( arr , n ) :
    maxVal = arr [ 0 ] ;
    for i in range ( 1 , n ) :
        maxVal = max ( maxVal , arr [ i ] ) ;
    for i in range ( n ) :
        arr [ i ] = maxVal - arr [ i ] ;
def modifyArray ( arr , n , k ) :
    if ( k % 2 == 0 ) :
        removeMin ( arr , n ) ;
    else :
        removeFromMax ( arr , n ) ;
    printArray ( arr , n ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 8 , 12 , 16 ] ;
    n = len ( arr )
    k = 2 ;
    modifyArray ( arr , n , k ) ;

Index/key variables: i
Iterator variables: i
Python program:
def maxProd ( arr , n , k ) :
    product = 1 ;
    s = dict . fromkeys ( arr , 0 ) ;
    arr . sort ( ) ;
    for i in range ( n ) :
        if ( s [ arr [ i ] ] == 0 ) :
            product = product * arr [ i ] ;
        s [ arr [ i ] ] = s [ arr [ i ] ] + 1 ;
    j = n - 1 ;
    while ( j >= 0 and k > 0 ) :
        if ( ( k > ( s [ arr [ j ] ] - 1 ) ) and ( ( s [ arr [ j ] ] - 1 ) > 0 ) ) :
            product *= pow ( arr [ j ] , s [ arr [ j ] ] - 1 ) ;
            k = k - s [ arr [ j ] ] + 1 ;
            s [ arr [ j ] ] = 0 ;
        if ( k <= ( s [ arr [ j ] ] - 1 ) and ( ( s [ arr [ j ] ] - 1 ) > 0 ) ) :
            product *= pow ( arr [ j ] , k ) ;
            break ;
        j -= 1
    return product ;
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 6 , 7 , 8 , 2 , 5 , 6 , 8 ] ;
    n = len ( arr ) ;
    k = 2 ;
    print ( maxProd ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: product
Iterator variables: i
Python program:
def mergeTwoArrays ( l , r ) :
    ret = [ ]
    l_in , r_in = 0 , 0
    while l_in + r_in < len ( l ) + len ( r ) :
        if ( l_in != len ( l ) and ( r_in == len ( r ) or l [ l_in ] < r [ r_in ] ) ) :
            ret . append ( l [ l_in ] )
            l_in += 1
        else :
            ret . append ( r [ r_in ] )
            r_in += 1
    return ret
def mergeArrays ( arr ) :
    arr_s = [ ]
    while len ( arr ) != 1 :
        arr_s [ : ] = [ ]
        for i in range ( 0 , len ( arr ) , 2 ) :
            if i == len ( arr ) - 1 :
                arr_s . append ( arr [ i ] )
            else :
                arr_s . append ( mergeTwoArrays ( arr [ i ] , arr [ i + 1 ] ) )
        arr = arr_s [ : ]
    return arr [ 0 ]
if __name__ == " _ _ main _ _ " :
    arr = [ [ 3 , 13 ] , [ 8 , 10 , 11 ] , [ 9 , 15 ] ]
    output = mergeArrays ( arr )
    for i in range ( 0 , len ( output ) ) :
        print ( output [ i ] , end = " ▁ " )

Index/key variables: i, l_in, r_in
Accumulator variables: arr_s, ret
Iterator variables: i
Python program:
def findAnswer ( n , arr ) :
    arr . sort ( reverse = False )
    sum = 0
    for i in range ( int ( n / 2 ) ) :
        sum += ( ( arr [ i ] + arr [ n - i - 1 ] ) * ( arr [ i ] + arr [ n - i - 1 ] ) )
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 53 , 28 , 143 , 5 ]
    n = len ( arr )
    print ( findAnswer ( n , arr ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
n = 4 ;
def merge ( l , r , output ) :
    l_in = l * n ;
    r_in = ( ( l + r ) // 2 + 1 ) * n ;
    l_c = ( ( l + r ) // 2 - l + 1 ) * n ;
    r_c = ( r - ( l + r ) // 2 ) * n ;
    l_arr = [ 0 ] * l_c ; r_arr = [ 0 ] * r_c ;
    for i in range ( l_c ) :
        l_arr [ i ] = output [ l_in + i ] ;
    for i in range ( r_c ) :
        r_arr [ i ] = output [ r_in + i ] ;
    l_curr = 0 ; r_curr = 0 ;
    in1 = l_in ;
    while ( l_curr + r_curr < l_c + r_c ) :
        if ( r_curr == r_c or ( l_curr != l_c and l_arr [ l_curr ] < r_arr [ r_curr ] ) ) :
            output [ in1 ] = l_arr [ l_curr ] ;
            l_curr += 1 ; in1 += 1 ;
        else :
            output [ in1 ] = r_arr [ r_curr ] ;
            r_curr += 1 ; in1 += 1 ;
def divide ( l , r , output , arr ) :
    if ( l == r ) :
        for i in range ( n ) :
            output [ l * n + i ] = arr [ l ] [ i ] ;
        return ;
    divide ( l , ( l + r ) // 2 , output , arr ) ;
    divide ( ( l + r ) // 2 + 1 , r , output , arr ) ;
    merge ( l , r , output ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ [ 5 , 7 , 15 , 18 ] , [ 1 , 8 , 9 , 17 ] , [ 1 , 4 , 7 , 7 ] ] ;
    k = len ( arr ) ;
    output = [ 0 ] * ( n * k ) ;
    divide ( 0 , k - 1 , output , arr ) ;
    for i in range ( n * k ) :
        print ( output [ i ] , end = " ▁ " ) ;

Index/key variables: i, in1, l, l_curr, r_curr
Iterator variables: i