dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findPoint ( n , p ) :
    for i in range ( n * 4 + 1 ) :
        x1 = 2e9
        x2 = - 2e9
        y1 = 2e9
        y2 = - 2e9
        for j in range ( n * 4 + 1 ) :
            if ( i != j ) :
                x1 = min ( x1 , p [ j ] [ 0 ] )
                x2 = max ( x2 , p [ j ] [ 0 ] )
                y1 = min ( y1 , p [ j ] [ 1 ] )
                y2 = max ( y2 , p [ j ] [ 1 ] )
        ok = 1
        c1 = 0
        c2 = 0
        c3 = 0
        c4 = 0
        for j in range ( 1 , n * 4 + 1 , 1 ) :
            if ( i != j ) :
                if ( ( p [ j ] [ 0 ] == x1 or p [ j ] [ 0 ] == x2 ) or ( p [ j ] [ 1 ] == y1 or p [ j ] [ 1 ] == y2 ) ) :
                    if ( p [ j ] [ 0 ] == x1 ) :
                        c1 += 1
                    if ( p [ j ] [ 0 ] == x2 ) :
                        c2 += 1
                    if ( p [ j ] [ 1 ] == y1 ) :
                        c3 += 1
                    if ( p [ j ] [ 1 ] == y2 ) :
                        c4 += 1
                else :
                    ok = 0
        if ( ok and c1 >= n and c2 >= n and c3 >= n and c4 >= n and x2 - x1 == y2 - y1 ) :
            print ( p [ i ] [ 0 ] , p [ i ] [ 1 ] )
if __name__ == ' _ _ main _ _ ' :
    N = 2
    arr = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 0 , 2 ] , [ 1 , 0 ] , [ 1 , 1 ] , [ 1 , 2 ] , [ 2 , 0 ] , [ 2 , 1 ] , [ 2 , 2 ] ]
    findPoint ( N , arr )

Index/key variables: i, j
Accumulator variables: c1, c2, c3, c4
Iterator variables: i, j
Python program:
def findSegment ( n , m , segment_length ) :
    meet_point = ( 1.0 * n ) / 2.0
    sum = 0
    segment_number = 0
    for i in range ( 0 , m , 1 ) :
        sum += segment_length [ i ]
        if ( sum == meet_point ) :
            segment_number = - 1
            break
        if ( sum > meet_point ) :
            segment_number = i + 1
            break
    return segment_number
if __name__ == ' _ _ main _ _ ' :
    n = 13
    m = 3
    segment_length = [ 3 , 2 , 8 ]
    ans = findSegment ( n , m , segment_length )
    print ( ans )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import math
def countLattice ( r ) :
    if ( r <= 0 ) :
        return 0
    result = 4
    for x in range ( 1 , r ) :
        ySquare = r * r - x * x
        y = int ( math . sqrt ( ySquare ) )
        if ( y * y == ySquare ) :
            result += 4
    return result
r = 5
print ( countLattice ( r ) )

Accumulator variables: result
Iterator variables: x
Python program:
def countSubArrays ( arr , N , K , M ) :
    count = 0
    sum = 0
    for i in range ( K ) :
        sum += arr [ i ]
    if sum >= K * M :
        count += 1
    for i in range ( K , N ) :
        sum += ( arr [ i ] - arr [ i - K ] )
        if sum >= K * M :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 3 , 2 , 1 , 3 , 9 ]
    K = 2
    M = 4
    N = len ( arr )
    count = countSubArrays ( arr , N , K , M )
    print ( count )

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i
Python program:
def findSmallestNumK ( n ) :
    cummAnd = n
    i = n - 1
    while ( cummAnd != 0 ) :
        cummAnd = cummAnd & i
        if ( cummAnd == 0 ) :
            return i
        i -= 1
    return - 1
if __name__ == ' _ _ main _ _ ' :
    N = 17
    lastNum = findSmallestNumK ( N ) ;
    K = lastNum if lastNum == - 1 else N - lastNum
    print ( K )

Accumulator variables: i
Python program:
def compute ( query ) :
    v = [ None ] * 100001
    dp = [ None ] * 100001
    v [ 1 ] = 1
    v [ 2 ] = 0
    dp [ 1 ] = 0
    dp [ 2 ] = 0
    for i in range ( 3 , 100001 ) :
        if ( i % 2 != 0 ) :
            if ( ( i // 2 ) % 2 == 0 ) :
                v [ i ] = 1
                dp [ i ] = dp [ i - 1 ]
            else :
                v [ i ] = v [ i // 2 ] + 1
                dp [ i ] = dp [ i - 1 ] + v [ i ] - 1
        else :
            v [ i ] = 0
            dp [ i ] = dp [ i - 1 ]
    for x in query :
        print ( dp [ x ] )
query = [ 5 , 2 ]
compute ( query )

Index/key variables: i, x
Iterator variables: i, x
Python program:
def find ( a , n , k ) :
    v = [ ]
    for i in range ( 1 , n ) :
        v . append ( a [ i - 1 ] - a [ i ] )
    v . sort ( )
    res = a [ n - 1 ] - a [ 0 ]
    for i in range ( k - 1 ) :
        res += v [ i ]
    return res
arr = [ 4 , 8 , 15 , 16 , 23 , 42 ]
N = len ( arr )
K = 3
print ( find ( arr , N , K ) )

Index/key variables: i
Accumulator variables: res, v
Iterator variables: i
Python program:
def power ( a , b , c ) :
    result = 1
    while ( b > 0 ) :
        if ( ( b & 1 ) == 1 ) :
            result = ( result * a ) % c
        b //= 2
        a = ( a * a ) % c
    return result
def calculate ( X , N ) :
    a = 10 * [ 0 ]
    cyclicity = 11 * [ 0 ]
    cyclicity [ 1 ] = 1
    cyclicity [ 2 ] = 4
    cyclicity [ 3 ] = 4
    cyclicity [ 4 ] = 2
    cyclicity [ 5 ] = 1
    cyclicity [ 6 ] = 1
    cyclicity [ 7 ] = 4
    cyclicity [ 8 ] = 4
    cyclicity [ 9 ] = 2
    cyclicity [ 10 ] = 1
    if ( N == 0 or N == 1 ) :
        return ( X % 10 )
    elif ( N == 2 or N == 3 or N == 4 ) :
        temp = 1e18 ;
        a [ 2 ] = 2
        a [ 3 ] = 6
        a [ 4 ] = 4
        v = X % 10
        if ( v != 0 ) :
            u = cyclicity [ v ]
            r = a [ N ] % u
            if ( r == 0 ) :
                if ( v == 2 or v == 4 or v == 6 or v == 8 ) :
                    return 6
                elif ( v == 5 ) :
                    return 5
                elif ( v == 1 or v == 3 or v == 7 or v == 9 ) :
                    return 1
            else :
                return ( power ( v , r , temp ) % 10 )
        else :
            return 0
    return 1
if __name__ == " _ _ main _ _ " :
    X = 18
    N = 4
    result = calculate ( X , N )
    print ( result )

Index/key variables: N, v
Accumulator variables: b
Python program:
def formQuadruplets ( arr , n ) :
    ans = 0
    pairs = 0
    pairs = n // 4
    arr . sort ( reverse = True )
    for i in range ( 0 , n - pairs , 3 ) :
        ans += arr [ i + 2 ]
    return ans
arr = [ 2 , 1 , 7 , 5 , 5 , 4 , 1 , 1 , 3 , 3 , 2 , 2 ]
n = len ( arr )
print ( formQuadruplets ( arr , n ) )

Accumulator variables: ans
Iterator variables: i
Python program:
from bisect import bisect_left
def LIS ( arr , n ) :
    m = { }
    for i in range ( n ) :
        m [ arr [ i ] ] = m . get ( arr [ i ] , [ ] )
        m [ arr [ i ] ] . append ( i )
    k = n
    ans = 1
    for key , value in m . items ( ) :
        if ( value [ len ( value ) - 1 ] < k ) :
            k = value [ 0 ]
            ans += 1
        else :
            k = bisect_left ( value , k )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 2 , 1 , 2 ]
    n = len ( arr )
    LIS ( arr , n )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i, key, value
Python program:
mod = 1000000007
def waysToColor ( arr , n , k ) :
    global mod
    powOf2 = [ 0 for i in range ( 500 ) ]
    c = [ [ 0 for i in range ( 500 ) ] for j in range ( 500 ) ]
    for i in range ( n + 1 ) :
        c [ i ] [ 0 ] = 1 ;
        for j in range ( 1 , i + 1 ) :
            c [ i ] [ j ] = ( c [ i - 1 ] [ j ] + c [ i - 1 ] [ j - 1 ] ) % mod ;
    powOf2 [ 0 ] = 1
    powOf2 [ 1 ] = 1 ;
    for i in range ( 2 , n + 1 ) :
        powOf2 [ i ] = ( powOf2 [ i - 1 ] * 2 ) % mod ;
    rem = n - k ;
    arr [ k ] = n + 1 ;
    k += 1
    arr . sort ( )
    answer = 1 ;
    for i in range ( k ) :
        x = 0
        if i - 1 >= 0 :
            x = arr [ i ] - arr [ i - 1 ] - 1
        else :
            x = arr [ i ] - 1
        answer = answer * ( c [ rem ] [ x ] % mod ) * ( ( powOf2 [ x ] if ( i != 0 and i != k - 1 ) else 1 ) ) % mod
        rem -= x ;
    return answer ;
if __name__ == ' _ _ main _ _ ' :
    N = 6 ;
    K = 3 ;
    arr = [ 1 , 2 , 6 , 0 ]
    print ( waysToColor ( arr , N , K ) )

Index/key variables: i, j, k, rem, x
Iterator variables: i, j
Python program:
def printArray ( a , n ) :
    a . sort ( ) ;
    i = 0 ;
    j = n - 1 ;
    while ( i <= j ) :
        if ( i == j ) :
            print ( a [ i ] , end = " ▁ " ) ;
        else :
            print ( a [ j ] , end = " ▁ " ) ;
            print ( a [ i ] , end = " ▁ " ) ;
        i = i + 1 ;
        j = j - 1 ;
    print ( ) ;
if __name__ == " _ _ main _ _ " :
    arr1 = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
    n1 = len ( arr1 ) ;
    printArray ( arr1 , n1 ) ;

Index/key variables: i, j
Python program:
def SmallestDiv ( n ) :
    i = 2
    while i * i <= n :
        if ( n % i == 0 ) :
            return i
        i += 1
    return n
if __name__ == " _ _ main _ _ " :
    X = 385
    ans = SmallestDiv ( X )
    print ( ans )

Accumulator variables: i
Python program:
def printArr ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " ) ;
def findArray ( n , k , s ) :
    vis = [ 0 ] * n ;
    cnt = 0 ;
    arr = [ 0 ] * n ;
    i = 0 ;
    while ( i < n and cnt < k ) :
        arr [ i ] = s ;
        vis [ i ] = 1 ;
        cnt += 1 ;
        i += 2 ;
    val = s ;
    if ( s % 2 == 0 ) :
        val += 1 ;
    else :
        val = val + 2 ;
    for i in range ( n ) :
        if ( vis [ i ] == 0 ) :
            arr [ i ] = val ;
    printArr ( arr , n ) ;
if __name__ == " _ _ main _ _ " :
    n = 8 ; k = 3 ; s = 12 ;
    findArray ( n , k , s ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
M = 1000000007
def power ( x , y , p ) :
    res = 1
    x = x % p
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p
        x = ( x * x ) % p
    return res
def modInverse ( n , p ) :
    return power ( n , p - 2 , p )
def nCrModPFermat ( n , r , p ) :
    if ( r == 0 ) :
        return 1
    fac = [ 0 ] * ( n + 1 )
    fac [ 0 ] = 1
    for i in range ( 1 , n + 1 ) :
        fac [ i ] = fac [ i - 1 ] * i % p
    return ( fac [ n ] * modInverse ( fac [ r ] , p ) % p * modInverse ( fac [ n - r ] , p ) % p ) % p
def countOdd ( n ) :
    x = n // 2
    if ( n % 2 == 1 ) :
        x += 1
    return x
def counteEven ( n ) :
    x = n // 2
    return x
def CountEvenSumSequences ( n ) :
    count = 0
    for i in range ( n + 1 ) :
        even = i
        odd = n - i
        if ( odd % 2 == 1 ) :
            continue
        tot = ( power ( countOdd ( n ) , odd , M ) * nCrModPFermat ( n , odd , M ) ) % M
        tot = ( tot * power ( counteEven ( n ) , i , M ) ) % M
        count += tot
        count %= M
    return count
n = 5
print ( CountEvenSumSequences ( n ) )

Index/key variables: i, n, r
Accumulator variables: count
Iterator variables: i
Python program:
def nextOccurrence ( strr , n , start , ch ) :
    for i in range ( start , n ) :
        if ( strr [ i ] == ch ) :
            return i
    return - 1
def countSubStr ( strr , n , ch ) :
    cnt = 0
    j = nextOccurrence ( strr , n , 0 , ch )
    for i in range ( n ) :
        while ( j != - 1 and j < i ) :
            j = nextOccurrence ( strr , n , j + 1 , ch )
        if ( j == - 1 ) :
            break
        cnt += ( n - j )
    return cnt
strr = " geeksforgeeks "
n = len ( strr )
ch = ' k '
print ( countSubStr ( strr , n , ch ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def checkEvenOdd ( arr , n ) :
    for i in range ( n ) :
        if ( arr [ i ] % 2 == 0 ) :
            print ( " Even " , end = " " ) ;
            return ;
    print ( " Odd " , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 12 , 20 , 36 , 38 ] ;
    n = len ( arr ) ;
    checkEvenOdd ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
MAXN = 30
def countMaxLength ( N ) :
    pre = [ 0 for i in range ( MAXN ) ]
    p = 1
    pre [ 0 ] = 0
    for i in range ( 1 , MAXN , 1 ) :
        p *= 2
        pre [ i ] = pre [ i - 1 ] + i * p
    for i in range ( 1 , MAXN , 1 ) :
        if ( pre [ i ] >= N ) :
            ind = i
            break
    x = N - pre [ ind - 1 ]
    y = 2 * ind - 1
    if ( x >= y ) :
        res = min ( x , y )
    else :
        res = max ( x , 2 * ( ind - 2 ) + 1 )
    return res
if __name__ == ' _ _ main _ _ ' :
    N = 25
    print ( countMaxLength ( N ) )

Index/key variables: i
Accumulator variables: p
Iterator variables: i
Python program:
def factorialUsingRecursion ( n ) :
    if ( n == 0 ) :
        return 1 ;
    return n * factorialUsingRecursion ( n - 1 ) ;
def factorialUsingIteration ( n ) :
    res = 1 ;
    for i in range ( 2 , n + 1 ) :
        res *= i ;
    return res ;
num = 5 ;
print ( " Factorial ▁ of " , num , " using ▁ Recursion ▁ is : " , factorialUsingRecursion ( 5 ) ) ;
print ( " Factorial ▁ of " , num , " using ▁ Iteration ▁ is : " , factorialUsingIteration ( 5 ) ) ;

Accumulator variables: res
Iterator variables: i
Python program:
def revereseArray ( arr , n ) :
    rev = n * [ 0 ]
    for i in range ( 0 , n ) :
        rev [ n - i - 1 ] = arr [ i ]
    for i in range ( 0 , n ) :
        arr [ i ] = rev [ i ]
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    n = len ( arr )
    print ( * arr )
    revereseArray ( arr , n ) ;
    print ( " Reversed ▁ array ▁ is " )
    print ( * arr )

Index/key variables: i
Iterator variables: i
Python program:
def revereseArray ( arr , n ) :
    for i in range ( 0 , int ( n / 2 ) ) :
        arr [ i ] , arr [ n - i - 1 ] = arr [ n - i - 1 ] , arr [ i ]
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    n = len ( arr )
    print ( * arr )
    revereseArray ( arr , n )
    print ( " Reversed ▁ array ▁ is " )
    print ( * arr )

Index/key variables: i
Iterator variables: i
Python program:
def findString ( str , M ) :
    N = len ( str )
    M = min ( M , N )
    s1 = " "
    while ( M != 0 ) :
        s1 = " "
        for i in range ( N - 1 ) :
            if ( str [ i ] == '0' ) :
                if ( ( str [ i - 1 ] == '1' and str [ i + 1 ] != '1' ) or ( str [ i - 1 ] != '1' and str [ i + 1 ] == '1' ) ) :
                    s1 += '1'
                else :
                    s1 += '0'
            else :
                s1 += '1'
        if ( str == s1 ) :
            break
        s1 += '1'
        str = s1
        M -= 1
    print ( s1 )
if __name__ == ' _ _ main _ _ ' :
    str = "0110100"
    M = 3
    findString ( str , M )

Index/key variables: i
Accumulator variables: M, s1
Iterator variables: i
Python program:
import sys
def numberofSubsequences ( a , L , R , X , n ) :
    ans = 0
    for i in range ( 0 , ( 1 << n ) , 1 ) :
        cnt = 0
        sum = 0
        minVal = sys . maxsize
        maxVal = - sys . maxsize - 1
        for j in range ( n ) :
            if ( ( i & ( 1 << j ) ) ) :
                cnt += 1
                sum += a [ j ]
                maxVal = max ( maxVal , a [ j ] )
                minVal = min ( minVal , a [ j ] )
        if ( cnt >= 2 and sum >= L and sum <= R and ( maxVal - minVal >= X ) ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = [ 10 , 20 , 30 , 25 ]
    L = 40
    R = 50
    X = 10
    N = len ( a )
    print ( numberofSubsequences ( a , L , R , X , N ) )

Index/key variables: j
Accumulator variables: ans, cnt, sum
Iterator variables: i, j
Python program:
def Minimum ( N , K ) :
    sum = N * ( N + 1 ) // 2
    if ( K > sum ) :
        return - 1
    if ( K <= N ) :
        return 1
    sum = 0
    count = 0
    while ( N >= 1 and sum < K ) :
        count += 1
        sum += N
        N -= 1
    return count
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 10
    print ( Minimum ( N , K ) )

Accumulator variables: N, count, sum
Python program:
def largestNum ( arr , n ) :
    st = set ( [ ] )
    res = 0
    for i in range ( n ) :
        st . add ( arr [ i ] )
        if ( - 1 * arr [ i ] ) in st :
            res = max ( res , abs ( arr [ i ] ) )
    return res
arr = [ 3 , 2 , - 2 , 5 , - 3 ]
n = len ( arr )
print ( largestNum ( arr , n ) )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
def findElement ( A , N , X ) :
    i = 0
    Comparisons = 0
    T = 1
    Found = " No "
    Comparisons += 1
    if ( N % 2 == 1 ) :
        i = 1
        T *= ( A [ 0 ] - X )
    while ( i < N ) :
        Comparisons += 1
        T *= ( A [ i ] - X )
        T *= ( A [ i + 1 ] - X )
        i += 2
    Comparisons += 1
    if ( T == 0 ) :
        print ( " Yes " , Comparisons )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    A = [ - 3 , 5 , 11 , 3 , 100 , 2 , 88 , 22 , 7 , 900 , 23 , 4 , 1 ]
    N = len ( A )
    X = 1
    findElement ( A , N , X )

Index/key variables: i
Accumulator variables: Comparisons, T
Python program:
def find ( arr , N , key ) :
    l = 0
    h = N - 1
    while l <= h :
        mid = ( l + h ) // 2
        if arr [ mid ] == key :
            return mid
        if arr [ l ] >= arr [ mid ] :
            if arr [ l ] >= key >= arr [ mid ] :
                h = mid - 1
            else :
                l = mid + 1
        else :
            if arr [ mid ] >= key >= arr [ h ] :
                l = mid + 1
            else :
                h = mid - 1
    return - 1
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 8 , 6 , 5 , 2 , 1 , 13 , 12 ]
    N = len ( arr )
    key = 8
    ans = find ( arr , N , key )
    print ( ans )

Index/key variables: h, l, mid
Python program:
def maxItems ( n , m , a , b , K ) :
    count = 0
    A = [ 0 for i in range ( n + 1 ) ]
    B = [ 0 for i in range ( m + 1 ) ]
    for i in range ( 1 , n + 1 , 1 ) :
        A [ i ] = a [ i - 1 ] + A [ i - 1 ]
    for i in range ( 1 , m + 1 , 1 ) :
        B [ i ] = b [ i - 1 ] + B [ i - 1 ]
    for i in range ( n + 1 ) :
        if ( A [ i ] > K ) :
            break
        rem = K - A [ i ]
        j = 0
        lo = 0
        hi = m
        while ( lo <= hi ) :
            mid = ( lo + hi ) // 2
            if ( B [ mid ] <= rem ) :
                j = mid
                lo = mid + 1
            else :
                hi = mid - 1
        count = max ( j + i , count )
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    n = 4
    m = 5
    K = 7
    A = [ 2 , 4 , 7 , 3 ]
    B = [ 1 , 9 , 3 , 4 , 5 ]
    maxItems ( n , m , A , B , K )

Index/key variables: i, mid
Iterator variables: i
Python program:
def isPrime ( N ) :
    if ( N == 1 ) :
        return False
    for i in range ( 2 , N + 1 ) :
        if i * i > N :
            break
        if ( N % i == 0 ) :
            return False
    return True
def findCoPrime ( L , R ) :
    coPrime , i = 0 , R + 1
    while True :
        if ( isPrime ( i ) ) :
            coPrime = i
            break
        i += 1
    return coPrime
if __name__ == ' _ _ main _ _ ' :
    L , R = 16 , 17
    print ( findCoPrime ( L , R ) )

Iterator variables: i
Python program:
def maximumValue ( arr , n ) :
    ans = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            ans = max ( ans , arr [ i ] + arr [ j ] + i - j )
    print ( ans )
arr = [ 1 , 9 , 3 , 6 , 5 ]
N = len ( arr )
maximumValue ( arr , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maximumValue ( arr , n ) :
    maxvalue = arr [ 0 ]
    result = 0
    for i in range ( 1 , n ) :
        result = max ( result , maxvalue + arr [ i ] - i )
        maxvalue = max ( maxvalue , arr [ i ] + i )
    print ( result )
arr = [ 1 , 9 , 3 , 6 , 5 ]
N = len ( arr )
maximumValue ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def lower_bound ( arr , key ) :
    low = 0 ;
    high = len ( arr ) - 1 ;
    while ( low < high ) :
        mid = low + ( high - low ) // 2 ;
        if ( arr [ mid ] >= key ) :
            high = mid ;
        else :
            low = mid + 1 ;
    return low ;
def closestValue ( A , k ) :
    close = A [ - 1 ] ;
    it = lower_bound ( A , k ) ;
    if ( it != len ( A ) ) :
        close = A [ it ] ;
        if ( it != 0 ) :
            if ( ( k - A [ it - 1 ] ) < ( close - k ) ) :
                close = A [ it - 1 ] ;
    return close ;
def minPossible ( arr , brr , crr ) :
    arr . sort ( ) ;
    crr . sort ( ) ;
    minimum = 10 ** 9 ;
    for val in brr :
        arr_close = closestValue ( arr , val ) ;
        crr_close = closestValue ( crr , val ) ;
        if ( abs ( val - arr_close ) + abs ( val - crr_close ) < minimum ) :
            minimum = abs ( val - arr_close ) + abs ( val - crr_close ) ;
    print ( minimum ) ;
a = [ 1 , 8 , 5 ] ;
b = [ 2 , 9 ] ;
c = [ 5 , 4 ] ;
minPossible ( a , b , c ) ;

Index/key variables: it, mid
Iterator variables: val
Python program:
def minimum_swaps ( arr , n ) :
    count = 0
    max_el = max ( arr )
    min_el = min ( arr )
    if ( min_el == max_el ) :
        return 0
    index_max = - 1
    index_min = - 1
    for i in range ( n ) :
        if ( arr [ i ] == max_el and index_max == - 1 ) :
            index_max = i
        if ( arr [ i ] == min_el ) :
            index_min = i
    count += index_max
    count += ( n - 1 - index_min )
    if ( index_min < index_max ) :
        count -= 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 1 , 6 , 5 ]
    N = len ( arr )
    print ( minimum_swaps ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
ans = 0
def DFS ( src , Adj , arr , currentMin , currentMax ) :
    global ans
    ans = max ( ans , max ( abs ( currentMax - arr [ src - 1 ] ) , abs ( currentMin - arr [ src - 1 ] ) ) )
    currentMin = min ( currentMin , arr [ src - 1 ] )
    currentMax = min ( currentMax , arr [ src - 1 ] )
    for child in Adj [ src ] :
        DFS ( child , Adj , arr , currentMin , currentMax )
def getMaximumDifference ( Edges , arr , N , M ) :
    global ans
    Adj = [ [ ] for i in range ( N + 1 ) ]
    for i in range ( M ) :
        u = Edges [ i ] [ 0 ]
        v = Edges [ i ] [ 1 ]
        Adj [ u ] . append ( v )
    DFS ( 1 , Adj , arr , arr [ 0 ] , arr [ 0 ] )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    M = 4
    Edges = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 4 , 5 ] , [ 1 , 3 ] ]
    arr = [ 13 , 8 , 3 , 15 , 18 ]
    getMaximumDifference ( Edges , arr , N , M )

Index/key variables: i, src, u
Iterator variables: child, i
Python program:
def leastWeightedSumPath ( n , edges , src , dst , K ) :
    graph = [ [ ] for i in range ( 3 ) ]
    for edge in edges :
        graph [ edge [ 0 ] ] . append ( [ edge [ 1 ] , edge [ 2 ] ] )
    pq = [ ]
    costs = [ [ 10 ** 9 for i in range ( K + 2 ) ] for i in range ( n ) ]
    costs [ src ] [ K + 1 ] = 0
    pq . append ( [ 0 , src , K + 1 ] )
    pq = sorted ( pq ) [ : : - 1 ]
    while ( len ( pq ) > 0 ) :
        top = pq [ - 1 ]
        del pq [ - 1 ]
        if ( top [ 1 ] == dst ) :
            return top [ 0 ]
        if ( top [ 2 ] == 0 ) :
            continue
        for neighbor in graph [ top [ 1 ] ] :
            if ( costs [ neighbor [ 0 ] ] [ top [ 2 ] - 1 ] < neighbor [ 1 ] + top [ 0 ] ) :
                continue
            costs [ neighbor [ 0 ] ] [ top [ 2 ] - 1 ] = neighbor [ 1 ] + top [ 0 ]
            pq . append ( [ neighbor [ 1 ] + top [ 0 ] , neighbor [ 0 ] , top [ 2 ] - 1 ] )
        pq = sorted ( pq ) [ : : - 1 ]
    return - 1
if __name__ == ' _ _ main _ _ ' :
    n , src , dst , k = 3 , 0 , 2 , 1
    edges = [ [ 0 , 1 , 100 ] , [ 1 , 2 , 100 ] , [ 0 , 2 , 500 ] ]
    print ( leastWeightedSumPath ( n , edges , src , dst , k ) )

Index/key variables: src
Accumulator variables: pq
Iterator variables: edge, neighbor
Python program:
def indivisibleDigits ( arr , N ) :
    for i in range ( N ) :
        num = 0
        print ( arr [ i ] , end = ' ▁ ' )
        for j in range ( 2 , 10 ) :
            temp = arr [ i ]
            flag = True
            while ( temp > 0 ) :
                if ( ( temp % 10 ) != 0 and ( temp % 10 ) % j == 0 ) :
                    flag = False
                    break
                temp //= 10
            if ( flag ) :
                print ( j , end = ' ▁ ' )
        print ( )
arr = [ 4162 , 1152 , 99842 ]
N = len ( arr )
indivisibleDigits ( arr , N )

Index/key variables: i
Accumulator variables: temp
Iterator variables: i, j
Boolean variables: flag