dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def minSwapsToSort ( arr , n ) :
    arrPos = [ [ 0 for x in range ( 2 ) ] for y in range ( n ) ]
    for i in range ( n ) :
        arrPos [ i ] [ 0 ] = arr [ i ]
        arrPos [ i ] [ 1 ] = i
    arrPos . sort ( )
    vis = [ False ] * ( n )
    ans = 0
    for i in range ( n ) :
        if ( vis [ i ] or arrPos [ i ] [ 1 ] == i ) :
            continue
        cycle_size = 0
        j = i
        while ( not vis [ j ] ) :
            vis [ j ] = 1
            j = arrPos [ j ] [ 1 ]
            cycle_size += 1
        ans += ( cycle_size - 1 )
    return ans
def minSwapToMakeArraySame ( a , b , n ) :
    mp = { }
    for i in range ( n ) :
        mp [ b [ i ] ] = i
    for i in range ( n ) :
        b [ i ] = mp [ a [ i ] ]
    return minSwapsToSort ( b , n )
if __name__ == " _ _ main _ _ " :
    a = [ 3 , 6 , 4 , 8 ]
    b = [ 4 , 6 , 8 , 3 ]
    n = len ( a )
    print ( minSwapToMakeArraySame ( a , b , n ) )

Index/key variables: i, j
Accumulator variables: ans, cycle_size
Iterator variables: i
Python program:
def missingK ( a , k , n ) :
    difference = 0
    ans = 0
    count = k
    flag = 0
    for i in range ( 0 , n - 1 ) :
        difference = 0
        if ( ( a [ i ] + 1 ) != a [ i + 1 ] ) :
            difference += ( a [ i + 1 ] - a [ i ] ) - 1
            if ( difference >= count ) :
                ans = a [ i ] + count
                flag = 1
                break
            else :
                count -= difference
    if ( flag ) :
        return ans
    else :
        return - 1
a = [ 1 , 5 , 11 , 19 ]
k = 11
n = len ( a )
missing = missingK ( a , k , n )
print ( missing )

Index/key variables: i
Accumulator variables: count, difference
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = next
def printList ( node ) :
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        node = node . next
    print ( " " )
def newNode ( key ) :
    temp = Node ( 0 )
    temp . data = key
    temp . next = None
    return temp
def insertBeg ( head , val ) :
    temp = newNode ( val )
    temp . next = head
    head = temp
    return head
def rearrangeOddEven ( head ) :
    odd = [ ]
    even = [ ]
    i = 1
    while ( head != None ) :
        if ( head . data % 2 != 0 and i % 2 == 0 ) :
            odd . append ( head )
        elif ( head . data % 2 == 0 and i % 2 != 0 ) :
            even . append ( head )
        head = head . next
        i = i + 1
    while ( len ( odd ) != 0 and len ( even ) != 0 ) :
        odd [ - 1 ] . data , even [ - 1 ] . data = even [ - 1 ] . data , odd [ - 1 ] . data
        odd . pop ( )
        even . pop ( )
    return head
head = newNode ( 8 )
head = insertBeg ( head , 7 )
head = insertBeg ( head , 6 )
head = insertBeg ( head , 5 )
head = insertBeg ( head , 3 )
head = insertBeg ( head , 2 )
head = insertBeg ( head , 1 )
print ( " Linked ▁ List : " )
printList ( head )
rearrangeOddEven ( head )
print ( " Linked ▁ List ▁ after ▁ " , " Rearranging : " )
printList ( head )

Accumulator variables: even, odd
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
def printList ( node ) :
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        node = node . next
    print ( " ▁ " )
def newNode ( key ) :
    temp = Node ( )
    temp . data = key
    temp . next = None
    return temp
def insertBeg ( head , val ) :
    temp = newNode ( val )
    temp . next = head
    head = temp
    return head
def rearrange ( head ) :
    even = None
    temp = None
    prev_temp = None
    i = None
    j = None
    k = None
    l = None
    ptr = None
    temp = ( head ) . next
    prev_temp = head
    while ( temp != None ) :
        x = temp . next
        if ( temp . data % 2 != 0 ) :
            prev_temp . next = x
            temp . next = ( head )
            ( head ) = temp
        else :
            prev_temp = temp
        temp = x
    temp = ( head ) . next
    prev_temp = ( head )
    while ( temp != None and temp . data % 2 != 0 ) :
        prev_temp = temp
        temp = temp . next
    even = temp
    prev_temp . next = None
    i = head
    j = even
    while ( j != None and i != None ) :
        k = i . next
        l = j . next
        i . next = j
        j . next = k
        ptr = j
        i = k
        j = l
    if ( i == None ) :
        ptr . next = j
    return head
head = newNode ( 8 )
head = insertBeg ( head , 7 )
head = insertBeg ( head , 6 )
head = insertBeg ( head , 3 )
head = insertBeg ( head , 5 )
head = insertBeg ( head , 1 )
head = insertBeg ( head , 2 )
head = insertBeg ( head , 10 )
print ( " Linked ▁ List : " )
printList ( head )
print ( " Rearranged ▁ List " )
head = rearrange ( head )
printList ( head )

Class/struct names: Node
Python program:
def printMat ( mat ) :
    for i in range ( len ( mat ) ) :
        for j in range ( len ( mat [ 0 ] ) ) :
            print ( mat [ i ] [ j ] , end = " ▁ " )
        print ( )
def performSwap ( mat , i , j ) :
    N = len ( mat )
    ei = N - 1 - i
    ej = N - 1 - j
    temp = mat [ i ] [ j ]
    mat [ i ] [ j ] = mat [ ej ] [ i ]
    mat [ ej ] [ i ] = mat [ ei ] [ ej ]
    mat [ ei ] [ ej ] = mat [ j ] [ ei ]
    mat [ j ] [ ei ] = temp
def rotate ( mat , N , K ) :
    K = K % 4
    while ( K > 0 ) :
        for i in range ( int ( N / 2 ) ) :
            for j in range ( i , N - i - 1 ) :
                if ( i != j and ( i + j ) != N - 1 ) :
                    performSwap ( mat , i , j )
        K -= 1
    printMat ( mat )
K = 5
mat = [ [ 1 , 2 , 3 , 4 ] , [ 6 , 7 , 8 , 9 ] , [ 11 , 12 , 13 , 14 ] , [ 16 , 17 , 18 , 19 ] ]
N = len ( mat )
rotate ( mat , N , K )

Index/key variables: ei, ej, i, j
Accumulator variables: K
Iterator variables: i, j
Python program:
def findRotations ( str ) :
    tmp = str + str
    n = len ( str )
    for i in range ( 1 , n + 1 ) :
        substring = tmp [ i : i + n ]
        if ( str == substring ) :
            return i
    return n
if __name__ == ' _ _ main _ _ ' :
    str = " abc "
    print ( findRotations ( str ) )

Iterator variables: i
Python program:
MAX = 10000
prefix = [ 0 ] * ( MAX + 1 )
def isPowerOfTwo ( x ) :
    if ( x and ( not ( x & ( x - 1 ) ) ) ) :
        return True
    return False
def computePrefix ( n , a ) :
    if ( isPowerOfTwo ( a [ 0 ] ) ) :
        prefix [ 0 ] = 1
    for i in range ( 1 , n ) :
        prefix [ i ] = prefix [ i - 1 ]
        if ( isPowerOfTwo ( a [ i ] ) ) :
            prefix [ i ] += 1
def query ( L , R ) :
    return prefix [ R ] - prefix [ L - 1 ]
if __name__ == " _ _ main _ _ " :
    A = [ 3 , 8 , 5 , 2 , 5 , 10 ]
    N = len ( A )
    Q = 2
    computePrefix ( N , A )
    print ( query ( 0 , 4 ) )
    print ( query ( 3 , 5 ) )

Index/key variables: R, i
Iterator variables: i
Python program:
def findNextNumber ( n ) :
    h = [ 0 for i in range ( 10 ) ]
    i = 0
    msb = n
    rem = 0
    next_num = - 1
    count = 0
    while ( msb > 9 ) :
        rem = msb % 10
        h [ rem ] = 1
        msb //= 10
        count += 1
    h [ msb ] = 1
    count += 1
    for i in range ( msb + 1 , 10 , 1 ) :
        if ( h [ i ] == 0 ) :
            next_num = i
            break
    if ( next_num == - 1 ) :
        for i in range ( 1 , msb , 1 ) :
            if ( h [ i ] == 0 ) :
                next_num = i
                count += 1
                break
    if ( next_num > 0 ) :
        for i in range ( 0 , 10 , 1 ) :
            if ( h [ i ] == 0 ) :
                msb = i
                break
        for i in range ( 1 , count , 1 ) :
            next_num = ( ( next_num * 10 ) + msb )
        if ( next_num > n ) :
            print ( next_num )
        else :
            print ( " Not ▁ Possible " )
    else :
        print ( " Not ▁ Possible " )
if __name__ == ' _ _ main _ _ ' :
    n = 2019
    findNextNumber ( n )

Index/key variables: i, msb, rem
Accumulator variables: count
Iterator variables: i
Python program:
def CalculateValues ( N ) :
    for C in range ( 0 , N // 7 + 1 ) :
        for B in range ( 0 , N // 5 + 1 ) :
            A = N - 7 * C - 5 * B
            if ( A >= 0 and A % 3 == 0 ) :
                print ( " A ▁ = " , A / 3 , " , ▁ B ▁ = " , B , " , ▁ \ ▁ C ▁ = " , C , sep = " ▁ " )
                return
    print ( - 1 )
    return
if __name__ == ' _ _ main _ _ ' :
    N = 19
    CalculateValues ( 19 )

Iterator variables: B, C
Python program:
def minimumTime ( arr , n ) :
    sum = 0
    T = max ( arr )
    for i in range ( n ) :
        sum += arr [ i ]
    print ( max ( 2 * T , sum ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 8 , 3 ]
    N = len ( arr )
    minimumTime ( arr , N )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def lexicographicallyMax ( s ) :
    n = len ( s )
    for i in range ( n ) :
        count = 0
        beg = i
        end = i
        if ( s [ i ] == '1' ) :
            count += 1
        for j in range ( i + 1 , n ) :
            if ( s [ j ] == '1' ) :
                count += 1
            if ( count % 2 == 0 and count != 0 ) :
                end = j
                break
        temp = s [ beg : end + 1 ]
        temp = temp [ : : - 1 ]
        s = s [ 0 : beg ] + temp + s [ end + 1 : ]
    print ( s )
S = "0101"
lexicographicallyMax ( S )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def maxPairs ( nums , k ) :
    nums = sorted ( nums )
    result = 0
    start , end = 0 , len ( nums ) - 1
    while ( start < end ) :
        if ( nums [ start ] + nums [ end ] > k ) :
            end -= 1
        elif ( nums [ start ] + nums [ end ] < k ) :
            start += 1
        else :
            start += 1
            end -= 1
            result += 1
    print ( result )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ]
    K = 5
    maxPairs ( arr , K )

Index/key variables: end, start
Accumulator variables: result
Python program:
def maxPairs ( nums , k ) :
    m = { }
    result = 0
    for i in nums :
        if ( ( i in m ) and m [ i ] > 0 ) :
            m [ i ] = m [ i ] - 1
            result += 1
        else :
            if k - i in m :
                m [ k - i ] += 1
            else :
                m [ k - i ] = 1
    print ( result )
arr = [ 1 , 2 , 3 , 4 ]
K = 5
maxPairs ( arr , K )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def removeIndicesToMakeSumEqual ( arr ) :
    N = len ( arr ) ;
    odd = [ 0 ] * N ;
    even = [ 0 ] * N ;
    even [ 0 ] = arr [ 0 ] ;
    for i in range ( 1 , N ) :
        odd [ i ] = odd [ i - 1 ] ;
        even [ i ] = even [ i - 1 ] ;
        if ( i % 2 == 0 ) :
            even [ i ] += arr [ i ] ;
        else :
            odd [ i ] += arr [ i ] ;
    find = False ;
    p = odd [ N - 1 ] ;
    q = even [ N - 1 ] - arr [ 0 ] ;
    if ( p == q ) :
        print ( "0 ▁ " ) ;
        find = True ;
    for i in range ( 1 , N ) :
        if ( i % 2 == 0 ) :
            p = even [ N - 1 ] - even [ i - 1 ] - arr [ i ] + odd [ i - 1 ] ;
            q = odd [ N - 1 ] - odd [ i - 1 ] + even [ i - 1 ] ;
        else :
            q = odd [ N - 1 ] - odd [ i - 1 ] - arr [ i ] + even [ i - 1 ] ;
            p = even [ N - 1 ] - even [ i - 1 ] + odd [ i - 1 ] ;
        if ( p == q ) :
            find = True ;
            print ( i , end = " " ) ;
    if ( find == False ) :
        print ( - 1 ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 1 , 6 , 2 ] ;
    removeIndicesToMakeSumEqual ( arr ) ;

Index/key variables: i
Iterator variables: i
Boolean variables: find
Python program:
def min_element_removal ( arr , N ) :
    left = [ 1 ] * N
    right = [ 1 ] * ( N )
    for i in range ( 1 , N ) :
        for j in range ( i ) :
            if ( arr [ j ] < arr [ i ] ) :
                left [ i ] = max ( left [ i ] , left [ j ] + 1 )
    for i in range ( N - 2 , - 1 , - 1 ) :
        for j in range ( N - 1 , i , - 1 ) :
            if ( arr [ i ] > arr [ j ] ) :
                right [ i ] = max ( right [ i ] , right [ j ] + 1 )
    maxLen = 0
    for i in range ( 1 , N - 1 ) :
        maxLen = max ( maxLen , left [ i ] + right [ i ] - 1 )
    print ( ( N - maxLen ) )
def makeBitonic ( arr , N ) :
    if ( N == 1 ) :
        print ( "0" )
        return
    if ( N == 2 ) :
        if ( arr [ 0 ] != arr [ 1 ] ) :
            print ( "0" )
        else :
            print ( "1" )
        return
    min_element_removal ( arr , N )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 1 , 5 , 6 , 2 , 3 , 1 ]
    N = len ( arr )
    makeBitonic ( arr , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countSubarrays ( A , N ) :
    ans = 0 ;
    for i in range ( N - 1 ) :
        if ( A [ i ] != A [ i + 1 ] ) :
            ans += 1 ;
            j = i - 1 ; k = i + 2 ;
            while ( j >= 0 and k < N and A [ j ] == A [ i ] and A [ k ] == A [ i + 1 ] ) :
                ans += 1 ;
                j -= 1 ;
                k += 1 ;
    print ( ans ) ;
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 1 , 0 , 0 , 1 , 0 ] ;
    N = len ( A ) ;
    countSubarrays ( A , N ) ;

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i
Python program:
maxN = 2002
lcount = [ [ 0 for i in range ( maxN ) ] for j in range ( maxN ) ]
rcount = [ [ 0 for i in range ( maxN ) ] for j in range ( maxN ) ]
def fill_counts ( a , n ) :
    maxA = a [ 0 ]
    for i in range ( n ) :
        if ( a [ i ] > maxA ) :
            maxA = a [ i ]
    for i in range ( n ) :
        lcount [ a [ i ] ] [ i ] = 1
        rcount [ a [ i ] ] [ i ] = 1
    for i in range ( maxA + 1 ) :
        for j in range ( n ) :
            lcount [ i ] [ j ] = ( lcount [ i ] [ j - 1 ] + lcount [ i ] [ j ] )
        for j in range ( n - 2 , - 1 , - 1 ) :
            rcount [ i ] [ j ] = ( rcount [ i ] [ j + 1 ] + rcount [ i ] [ j ] )
def countSubsequence ( a , n ) :
    fill_counts ( a , n )
    answer = 0
    for i in range ( 1 , n ) :
        for j in range ( i + 1 , n - 1 ) :
            answer += ( lcount [ a [ j ] ] [ i - 1 ] * rcount [ a [ i ] ] [ j + 1 ] )
    return answer
a = [ 1 , 2 , 3 , 2 , 1 , 3 , 2 ]
print ( countSubsequence ( a , 7 ) )

Index/key variables: i, j
Accumulator variables: answer
Iterator variables: i, j
Python program:
def maxiConsecutiveSubarray ( arr , N ) :
    maxi = 0 ;
    for i in range ( N - 1 ) :
        cnt = 1 ;
        for j in range ( i , N - 1 ) :
            if ( arr [ j + 1 ] == arr [ j ] + 1 ) :
                cnt += 1 ;
            else :
                break ;
        maxi = max ( maxi , cnt ) ;
        i = j ;
    return maxi ;
if __name__ == ' _ _ main _ _ ' :
    N = 11 ;
    arr = [ 1 , 3 , 4 , 2 , 3 , 4 , 2 , 3 , 5 , 6 , 7 ] ;
    print ( maxiConsecutiveSubarray ( arr , N ) ) ;

Index/key variables: j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
N = 100005
def SieveOfEratosthenes ( prime , p_size ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    p = 2
    while p * p <= p_size :
        if ( prime [ p ] ) :
            for i in range ( p * 2 , p_size + 1 , p ) :
                prime [ i ] = False
        p += 1
def digitSum ( number ) :
    sum = 0
    while ( number > 0 ) :
        sum += ( number % 10 )
        number //= 10
    return sum
def longestCompositeDigitSumSubsequence ( arr , n ) :
    count = 0
    prime = [ True ] * ( N + 1 )
    SieveOfEratosthenes ( prime , N )
    for i in range ( n ) :
        res = digitSum ( arr [ i ] )
        if ( res == 1 ) :
            continue
        if ( not prime [ res ] ) :
            count += 1
    print ( count )
if __name__ == " _ _ main _ _ " :
    arr = [ 13 , 55 , 7 , 3 , 5 , 1 , 10 , 21 , 233 , 144 , 89 ]
    n = len ( arr )
    longestCompositeDigitSumSubsequence ( arr , n )

Index/key variables: i, p, res
Accumulator variables: count, number, sum
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def newnode ( data ) :
    temp = Node ( data )
    return temp
def insert ( s , i , N , root , temp ) :
    if ( i == N ) :
        return temp
    if ( s [ i ] == ' L ' ) :
        root . left = insert ( s , i + 1 , N , root . left , temp )
    else :
        root . right = insert ( s , i + 1 , N , root . right , temp )
    return root
def SBTUtil ( root , sum ) :
    if ( root == None ) :
        return [ 0 , sum ]
    if ( root . left == None and root . right == None ) :
        return [ root . data , sum ]
    left , sum = SBTUtil ( root . left , sum )
    right , sum = SBTUtil ( root . right , sum )
    if ( root . left and root . right ) :
        if ( ( left % 2 == 0 and right % 2 != 0 ) or ( left % 2 != 0 and right % 2 == 0 ) ) :
            sum += root . data
    return [ left + right + root . data , sum ]
def build_tree ( R , N , str , values ) :
    root = newnode ( R )
    for i in range ( 0 , N - 1 ) :
        s = str [ i ]
        x = values [ i ]
        temp = newnode ( x )
        root = insert ( s , 0 , len ( s ) , root , temp )
    return root
def speciallyBalancedNodes ( R , N , str , values ) :
    root = build_tree ( R , N , str , values )
    sum = 0
    tmp , sum = SBTUtil ( root , sum )
    print ( sum , end = ' ▁ ' )
if __name__ == " _ _ main _ _ " :
    N = 7
    R = 12
    str = [ " L " , " R " , " RL " , " RR " , " RLL " , " RLR " ]
    values = [ 17 , 16 , 4 , 9 , 2 , 3 ]
    speciallyBalancedNodes ( R , N , str , values )

Index/key variables: i
Iterator variables: i
Class/struct names: Node
Python program:
def position ( arr , N ) :
    pos = - 1 ;
    count = 0 ;
    for i in range ( N ) :
        count = 0 ;
        for j in range ( N ) :
            if ( arr [ i ] [ 0 ] <= arr [ j ] [ 0 ] and arr [ i ] [ 1 ] >= arr [ j ] [ 1 ] ) :
                count += 1 ;
        if ( count == N ) :
            pos = i ;
    if ( pos == - 1 ) :
        print ( pos ) ;
    else :
        print ( pos + 1 ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 3 , 3 ] , [ 1 , 3 ] , [ 2 , 2 ] , [ 2 , 3 ] , [ 1 , 2 ] ] ;
    N = len ( arr ) ;
    position ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
import sys
def position ( arr , N ) :
    pos = - 1
    right = - sys . maxsize - 1
    left = sys . maxsize
    for i in range ( N ) :
        if ( arr [ i ] [ 1 ] > right ) :
            right = arr [ i ] [ 1 ]
        if ( arr [ i ] [ 0 ] < left ) :
            left = arr [ i ] [ 0 ]
    for i in range ( N ) :
        if ( arr [ i ] [ 0 ] == left and arr [ i ] [ 1 ] == right ) :
            pos = i + 1
    print ( pos )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 3 , 3 ] , [ 1 , 3 ] , [ 2 , 2 ] , [ 2 , 3 ] , [ 1 , 2 ] ]
    N = len ( arr )
    position ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def ctMinEdits ( str1 , str2 ) :
    N1 = len ( str1 )
    N2 = len ( str2 )
    freq1 = [ 0 ] * 256
    for i in range ( N1 ) :
        freq1 [ ord ( str1 [ i ] ) ] += 1
    freq2 = [ 0 ] * 256
    for i in range ( N2 ) :
        freq2 [ ord ( str2 [ i ] ) ] += 1
    for i in range ( 256 ) :
        if ( freq1 [ i ] > freq2 [ i ] ) :
            freq1 [ i ] = freq1 [ i ] - freq2 [ i ]
            freq2 [ i ] = 0
        else :
            freq2 [ i ] = freq2 [ i ] - freq1 [ i ]
            freq1 [ i ] = 0
    sum1 = 0
    sum2 = 0
    for i in range ( 256 ) :
        sum1 += freq1 [ i ]
        sum2 += freq2 [ i ]
    return max ( sum1 , sum2 )
str1 = " geeksforgeeks "
str2 = " geeksforcoder "
print ( ctMinEdits ( str1 , str2 ) )

Index/key variables: i
Accumulator variables: sum1, sum2
Iterator variables: i
Python program:
def CountPairs ( a , b , n ) :
    C = [ 0 ] * n
    for i in range ( n ) :
        C [ i ] = a [ i ] + b [ i ]
    freqCount = dict ( )
    for i in range ( n ) :
        if C [ i ] in freqCount . keys ( ) :
            freqCount [ C [ i ] ] += 1
        else :
            freqCount [ C [ i ] ] = 1
    NoOfPairs = 0
    for x in freqCount :
        y = freqCount [ x ]
        NoOfPairs = ( NoOfPairs + y * ( y - 1 ) // 2 )
    print ( NoOfPairs )
arr = [ 1 , 4 , 20 , 3 , 10 , 5 ]
brr = [ 9 , 6 , 1 , 7 , 11 , 6 ]
N = len ( arr )
CountPairs ( arr , brr , N )

Index/key variables: i, x
Iterator variables: i, x
Python program:
def medianChange ( arr1 , arr2 ) :
    N = len ( arr1 )
    median = [ ]
    if ( N & 1 ) :
        median . append ( arr1 [ N // 2 ] * 1 )
    else :
        median . append ( ( arr1 [ N // 2 ] + arr1 [ ( N - 1 ) // 2 ] ) // 2 )
    for x in arr2 :
        it = arr1 . index ( x )
        arr1 . pop ( it )
        N -= 1
        if ( N & 1 ) :
            median . append ( arr1 [ N // 2 ] * 1 )
        else :
            median . append ( ( arr1 [ N // 2 ] + arr1 [ ( N - 1 ) // 2 ] ) // 2 )
    for i in range ( len ( median ) - 1 ) :
        print ( median [ i + 1 ] - median [ i ] , end = ' ▁ ' )
if __name__ == " _ _ main _ _ " :
    arr1 = [ 2 , 4 , 6 , 8 , 10 ]
    arr2 = [ 4 , 6 ]
    medianChange ( arr1 , arr2 )

Index/key variables: i
Accumulator variables: N, median
Iterator variables: i, x
Python program:
nfa = 1
flag = 0
def state1 ( c ) :
    global nfa , flag
    if ( c == ' a ' ) :
        nfa = 2
    elif ( c == ' b ' or c == ' c ' ) :
        nfa = 1
    else :
        flag = 1
def state2 ( c ) :
    global nfa , flag
    if ( c == ' a ' ) :
        nfa = 3
    elif ( c == ' b ' or c == ' c ' ) :
        nfa = 2
    else :
        flag = 1
def state3 ( c ) :
    global nfa , flag
    if ( c == ' a ' ) :
        nfa = 1
    elif ( c == ' b ' or c == ' c ' ) :
        nfa = 3
    else :
        flag = 1
def state4 ( c ) :
    global nfa , flag
    if ( c == ' b ' ) :
        nfa = 5
    elif ( c == ' a ' or c == ' c ' ) :
        nfa = 4
    else :
        flag = 1
def state5 ( c ) :
    global nfa , flag
    if ( c == ' b ' ) :
        nfa = 6
    elif ( c == ' a ' or c == ' c ' ) :
        nfa = 5
    else :
        flag = 1
def state6 ( c ) :
    global nfa , flag
    if ( c == ' b ' ) :
        nfa = 4
    elif ( c == ' a ' or c == ' c ' ) :
        nfa = 6
    else :
        flag = 1
def state7 ( c ) :
    global nfa , flag
    if ( c == ' c ' ) :
        nfa = 8
    elif ( c == ' b ' or c == ' a ' ) :
        nfa = 7
    else :
        flag = 1
def state8 ( c ) :
    global nfa , flag
    if ( c == ' c ' ) :
        nfa = 9
    elif ( c == ' b ' or c == ' a ' ) :
        nfa = 8
    else :
        flag = 1
def state9 ( c ) :
    global nfa , flag
    if ( c == ' c ' ) :
        nfa = 7
    elif ( c == ' b ' or c == ' a ' ) :
        nfa = 9
    else :
        flag = 1
def checkA ( s , x ) :
    global nfa , flag
    for i in range ( x ) :
        if ( nfa == 1 ) :
            state1 ( s [ i ] )
        elif ( nfa == 2 ) :
            state2 ( s [ i ] )
        elif ( nfa == 3 ) :
            state3 ( s [ i ] )
    if ( nfa == 1 ) :
        return True
    else :
        nfa = 4
def checkB ( s , x ) :
    global nfa , flag
    for i in range ( x ) :
        if ( nfa == 4 ) :
            state4 ( s [ i ] )
        elif ( nfa == 5 ) :
            state5 ( s [ i ] )
        elif ( nfa == 6 ) :
            state6 ( s [ i ] )
    if ( nfa == 4 ) :
        return True
    else :
        nfa = 7
def checkC ( s , x ) :
    global nfa , flag
    for i in range ( x ) :
        if ( nfa == 7 ) :
            state7 ( s [ i ] )
        elif ( nfa == 8 ) :
            state8 ( s [ i ] )
        elif ( nfa == 9 ) :
            state9 ( s [ i ] )
    if ( nfa == 7 ) :
        return True
s = " bbbca "
x = 5
if ( checkA ( s , x ) or checkB ( s , x ) or checkC ( s , x ) ) :
    print ( " ACCEPTED " )
else :
    if ( flag == 0 ) :
        print ( " NOT ▁ ACCEPTED " )
    else :
        print ( " INPUT ▁ OUT ▁ OF ▁ DICTIONARY . " )

Index/key variables: i
Iterator variables: i