dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
n = 5
def printSumSimple ( mat , k ) :
    if ( k > n ) :
        return
    for i in range ( n - k + 1 ) :
        for j in range ( n - k + 1 ) :
            sum = 0
            for p in range ( i , k + i ) :
                for q in range ( j , k + j ) :
                    sum += mat [ p ] [ q ]
            print ( sum , end = " ▁ " )
        print ( )
if __name__ == " _ _ main _ _ " :
    mat = [ [ 1 , 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 , 4 ] , [ 5 , 5 , 5 , 5 , 5 ] ]
    k = 3
    printSumSimple ( mat , k )

Index/key variables: p, q
Accumulator variables: sum
Iterator variables: i, j, p, q
Python program:
n = 5
def printSumTricky ( mat , k ) :
    global n
    if k > n :
        return
    stripSum = [ [ None ] * n for i in range ( n ) ]
    for j in range ( n ) :
        Sum = 0
        for i in range ( k ) :
            Sum += mat [ i ] [ j ]
        stripSum [ 0 ] [ j ] = Sum
        for i in range ( 1 , n - k + 1 ) :
            Sum += ( mat [ i + k - 1 ] [ j ] - mat [ i - 1 ] [ j ] )
            stripSum [ i ] [ j ] = Sum
    for i in range ( n - k + 1 ) :
        Sum = 0
        for j in range ( k ) :
            Sum += stripSum [ i ] [ j ]
        print ( Sum , end = " ▁ " )
        for j in range ( 1 , n - k + 1 ) :
            Sum += ( stripSum [ i ] [ j + k - 1 ] - stripSum [ i ] [ j - 1 ] )
            print ( Sum , end = " ▁ " )
        print ( )
mat = [ [ 1 , 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 , 4 ] , [ 5 , 5 , 5 , 5 , 5 ] ]
k = 3
printSumTricky ( mat , k )

Index/key variables: i, j
Accumulator variables: Sum
Iterator variables: i, j
Python program:
M = 3
N = 4
def transpose ( A , B ) :
    for i in range ( N ) :
        for j in range ( M ) :
            B [ i ] [ j ] = A [ j ] [ i ]
A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] ]
B = [ [ 0 for x in range ( M ) ] for y in range ( N ) ]
transpose ( A , B )
print ( " Result ▁ matrix ▁ is " )
for i in range ( N ) :
    for j in range ( M ) :
        print ( B [ i ] [ j ] , " ▁ " , end = ' ' )
    print ( )

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 4
def transpose ( A ) :
    for i in range ( N ) :
        for j in range ( i + 1 , N ) :
            A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]
A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]
transpose ( A )
print ( " Modified ▁ matrix ▁ is " )
for i in range ( N ) :
    for j in range ( N ) :
        print ( A [ i ] [ j ] , " ▁ " , end = ' ' )
    print ( )

Index/key variables: i, j
Iterator variables: i, j
Python program:
R = 3
C = 3
def pathCountRec ( mat , m , n , k ) :
    if m < 0 or n < 0 :
        return 0
    elif m == 0 and n == 0 :
        return k == mat [ m ] [ n ]
    return ( pathCountRec ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountRec ( mat , m , n - 1 , k - mat [ m ] [ n ] ) )
def pathCount ( mat , k ) :
    return pathCountRec ( mat , R - 1 , C - 1 , k )
k = 12
mat = [ [ 1 , 2 , 3 ] , [ 4 , 6 , 5 ] , [ 3 , 2 , 1 ] ]
print ( pathCount ( mat , k ) )

Index/key variables: m, n
Python program:
R = 3
C = 3
MAX_K = 1000
def pathCountDPRecDP ( mat , m , n , k ) :
    if m < 0 or n < 0 :
        return 0
    elif m == 0 and n == 0 :
        return k == mat [ m ] [ n ]
    if ( dp [ m ] [ n ] [ k ] != - 1 ) :
        return dp [ m ] [ n ] [ k ]
    dp [ m ] [ n ] [ k ] = ( pathCountDPRecDP ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountDPRecDP ( mat , m , n - 1 , k - mat [ m ] [ n ] ) )
    return dp [ m ] [ n ] [ k ]
def pathCountDP ( mat , k ) :
    return pathCountDPRecDP ( mat , R - 1 , C - 1 , k )
k = 12
dp = [ [ [ - 1 for col in range ( MAX_K ) ] for col in range ( C ) ] for row in range ( R ) ]
mat = [ [ 1 , 2 , 3 ] , [ 4 , 6 , 5 ] , [ 3 , 2 , 1 ] ]
print ( pathCountDP ( mat , k ) )

Index/key variables: k, m, n
Python program:
SIZE = 10
def sortMat ( mat , n ) :
    temp = [ 0 ] * ( n * n )
    k = 0
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            temp [ k ] = mat [ i ] [ j ]
            k += 1
    temp . sort ( )
    k = 0
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            mat [ i ] [ j ] = temp [ k ]
            k += 1
def printMat ( mat , n ) :
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            print ( mat [ i ] [ j ] , end = " ▁ " )
        print ( )
mat = [ [ 5 , 4 , 7 ] , [ 1 , 3 , 8 ] , [ 2 , 9 , 6 ] ]
n = 3
print ( " Original ▁ Matrix : " )
printMat ( mat , n )
sortMat ( mat , n )
print ( " Matrix After Sorting : " )
printMat ( mat , n )

Index/key variables: i, j, k
Iterator variables: i, j
Python program:
def bubbleSort ( arr ) :
    n = len ( arr )
    for i in range ( n ) :
        swapped = False
        for j in range ( 0 , n - i - 1 ) :
            if arr [ j ] > arr [ j + 1 ] :
                arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]
                swapped = True
        if swapped == False :
            break
arr = [ 64 , 34 , 25 , 12 , 22 , 11 , 90 ]
bubbleSort ( arr )
print ( " Sorted ▁ array ▁ : " )
for i in range ( len ( arr ) ) :
    print ( " % d " % arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: swapped
Python program:
def findCrossOver ( arr , low , high , x ) :
    if ( arr [ high ] <= x ) :
        return high
    if ( arr [ low ] > x ) :
        return low
    mid = ( low + high ) // 2
    if ( arr [ mid ] <= x and arr [ mid + 1 ] > x ) :
        return mid
    if ( arr [ mid ] < x ) :
        return findCrossOver ( arr , mid + 1 , high , x )
    return findCrossOver ( arr , low , mid - 1 , x )
def printKclosest ( arr , x , k , n ) :
    l = findCrossOver ( arr , 0 , n - 1 , x )
    r = l + 1
    count = 0
    if ( arr [ l ] == x ) :
        l -= 1
    while ( l >= 0 and r < n and count < k ) :
        if ( x - arr [ l ] < arr [ r ] - x ) :
            print ( arr [ l ] , end = " ▁ " )
            l -= 1
        else :
            print ( arr [ r ] , end = " ▁ " )
            r += 1
        count += 1
    while ( count < k and l >= 0 ) :
        print ( arr [ l ] , end = " ▁ " )
        l -= 1
        count += 1
    while ( count < k and r < n ) :
        print ( arr [ r ] , end = " ▁ " )
        r += 1
        count += 1
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 16 , 22 , 30 , 35 , 39 , 42 , 45 , 48 , 50 , 53 , 55 , 56 ]
    n = len ( arr )
    x = 35
    k = 4
    printKclosest ( arr , x , 4 , n )

Index/key variables: high, l, low, mid, r
Accumulator variables: count
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def push ( head_ref , new_data ) :
    new_node = Node ( 0 )
    new_node . data = new_data
    new_node . next = ( head_ref )
    ( head_ref ) = new_node
    return head_ref
def insertionSort ( head_ref ) :
    sorted = None
    current = head_ref
    while ( current != None ) :
        next = current . next
        sorted = sortedInsert ( sorted , current )
        current = next
    head_ref = sorted
    return head_ref
def sortedInsert ( head_ref , new_node ) :
    current = None
    if ( head_ref == None or ( head_ref ) . data >= new_node . data ) :
        new_node . next = head_ref
        head_ref = new_node
    else :
        current = head_ref
        while ( current . next != None and current . next . data < new_node . data ) :
            current = current . next
        new_node . next = current . next
        current . next = new_node
    return head_ref
def printList ( head ) :
    temp = head
    while ( temp != None ) :
        print ( temp . data , end = " ▁ " )
        temp = temp . next
a = None
a = push ( a , 5 )
a = push ( a , 20 )
a = push ( a , 4 )
a = push ( a , 3 )
a = push ( a , 30 )
print ( " Linked ▁ List ▁ before ▁ sorting ▁ " )
printList ( a )
a = insertionSort ( a )
print ( " Linked List after sorting   " )
printList ( a )

Class/struct names: Node
Python program:
def count ( S , m , n ) :
    table = [ 0 for k in range ( n + 1 ) ]
    table [ 0 ] = 1
    for i in range ( 0 , m ) :
        for j in range ( S [ i ] , n + 1 ) :
            table [ j ] += table [ j - S [ i ] ]
    return table [ n ]
arr = [ 1 , 2 , 3 ]
m = len ( arr )
n = 4
x = count ( arr , m , n )
print ( x )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
import sys
dp = [ [ - 1 for i in range ( 100 ) ] for j in range ( 100 ) ]
def matrixChainMemoised ( p , i , j ) :
    if ( i == j ) :
        return 0
    if ( dp [ i ] [ j ] != - 1 ) :
        return dp [ i ] [ j ]
    dp [ i ] [ j ] = sys . maxsize
    for k in range ( i , j ) :
        dp [ i ] [ j ] = min ( dp [ i ] [ j ] , matrixChainMemoised ( p , i , k ) + matrixChainMemoised ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )
    return dp [ i ] [ j ]
def MatrixChainOrder ( p , n ) :
    i = 1
    j = n - 1
    return matrixChainMemoised ( p , i , j )
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
print ( " Minimum ▁ number ▁ of ▁ multiplications ▁ is " , MatrixChainOrder ( arr , n ) )

Index/key variables: i, j, k
Iterator variables: k
Python program:
import sys
def MatrixChainOrder ( p , n ) :
    m = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]
    for i in range ( 1 , n ) :
        m [ i ] [ i ] = 0
    for L in range ( 2 , n ) :
        for i in range ( 1 , n - L + 1 ) :
            j = i + L - 1
            m [ i ] [ j ] = sys . maxint
            for k in range ( i , j ) :
                q = m [ i ] [ k ] + m [ k + 1 ] [ j ] + p [ i - 1 ] * p [ k ] * p [ j ]
                if q < m [ i ] [ j ] :
                    m [ i ] [ j ] = q
    return m [ 1 ] [ n - 1 ]
arr = [ 1 , 2 , 3 , 4 ]
size = len ( arr )
print ( " Minimum ▁ number ▁ of ▁ multiplications ▁ is ▁ " + str ( MatrixChainOrder ( arr , size ) ) )

Index/key variables: i, j, k
Iterator variables: L, i, k
Python program:
import sys
def max ( a , b ) :
    return a if ( a > b ) else b
def cutRod ( price , n ) :
    if ( n <= 0 ) :
        return 0
    max_val = - sys . maxsize - 1
    for i in range ( 0 , n ) :
        max_val = max ( max_val , price [ i ] + cutRod ( price , n - i - 1 ) )
    return max_val
arr = [ 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 ]
size = len ( arr )
print ( " Maximum ▁ Obtainable ▁ Value ▁ is " , cutRod ( arr , size ) )

Index/key variables: i
Iterator variables: i
Python program:
def binomialCoeff ( n , k ) :
    res = 1
    if ( k > n - k ) :
        k = n - k
    for i in range ( 0 , k ) :
        res = res * ( n - i )
        res = res // ( i + 1 )
    return res
def printPascal ( n ) :
    for line in range ( 0 , n ) :
        for i in range ( 0 , line + 1 ) :
            print ( binomialCoeff ( line , i ) , " ▁ " , end = " " )
        print ( )
n = 7
printPascal ( n )

Iterator variables: i, line
Python program:
def printPascal ( n ) :
    for line in range ( 1 , n + 1 ) :
        C = 1 ;
        for i in range ( 1 , line + 1 ) :
            print ( C , end = " ▁ " ) ;
            C = int ( C * ( line - i ) / i ) ;
        print ( " " ) ;
n = 5 ;
printPascal ( n ) ;

Iterator variables: i, line
Python program:
def countSetBits ( n ) :
    count = 0
    while ( n ) :
        count += n & 1
        n >>= 1
    return count
i = 9
print ( countSetBits ( i ) )

Accumulator variables: count, n
Python program:
BitsSetTable256 = [ 0 ] * 256
def initialize ( ) :
    BitsSetTable256 [ 0 ] = 0
    for i in range ( 256 ) :
        BitsSetTable256 [ i ] = ( i & 1 ) + BitsSetTable256 [ i // 2 ]
def countSetBits ( n ) :
    return ( BitsSetTable256 [ n & 0xff ] + BitsSetTable256 [ ( n >> 8 ) & 0xff ] + BitsSetTable256 [ ( n >> 16 ) & 0xff ] + BitsSetTable256 [ n >> 24 ] )
initialize ( )
n = 9
print ( countSetBits ( n ) )

Index/key variables: i
Iterator variables: i
Python program:
num_to_bits = [ 0 , 1 , 1 , 2 , 1 , 2 , 2 , 3 , 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 ] ;
def countSetBitsRec ( num ) :
    nibble = 0 ;
    if ( 0 == num ) :
        return num_to_bits [ 0 ] ;
    nibble = num & 0xf ;
    return num_to_bits [ nibble ] + countSetBitsRec ( num >> 4 ) ;
num = 31 ;
print ( countSetBitsRec ( num ) ) ;

Index/key variables: nibble
Python program:
def maxRepeating ( arr , n , k ) :
    for i in range ( 0 , n ) :
        arr [ arr [ i ] % k ] += k
    max = arr [ 0 ]
    result = 0
    for i in range ( 1 , n ) :
        if arr [ i ] > max :
            max = arr [ i ]
            result = i
    return result
arr = [ 2 , 3 , 3 , 5 , 3 , 4 , 1 , 7 ]
n = len ( arr )
k = 8
print ( " The ▁ maximum ▁ repeating ▁ number ▁ is " , maxRepeating ( arr , n , k ) )

Index/key variables: i
Iterator variables: i
Python program:
def fun ( x ) :
    y = ( x // 4 ) * 4
    ans = 0
    for i in range ( y , x + 1 ) :
        ans ^= i
    return ans
def query ( x ) :
    if ( x == 0 ) :
        return 0
    k = ( x + 1 ) // 2
    if x % 2 == 0 :
        return ( ( fun ( k - 1 ) * 2 ) ^ ( k & 1 ) )
    else :
        return ( 2 * fun ( k ) )
def allQueries ( q , l , r ) :
    for i in range ( q ) :
        print ( query ( r [ i ] ) ^ query ( l [ i ] - 1 ) )
q = 3
l = [ 2 , 2 , 5 ]
r = [ 4 , 8 , 9 ]
allQueries ( q , l , r )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def prefixXOR ( arr , preXOR , n ) :
    for i in range ( 0 , n , 1 ) :
        while ( arr [ i ] % 2 != 1 ) :
            arr [ i ] = int ( arr [ i ] / 2 )
        preXOR [ i ] = arr [ i ]
    for i in range ( 1 , n , 1 ) :
        preXOR [ i ] = preXOR [ i - 1 ] ^ preXOR [ i ]
def query ( preXOR , l , r ) :
    if ( l == 0 ) :
        return preXOR [ r ]
    else :
        return preXOR [ r ] ^ preXOR [ l - 1 ]
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 4 , 5 ]
    n = len ( arr )
    preXOR = [ 0 for i in range ( n ) ]
    prefixXOR ( arr , preXOR , n )
    print ( query ( preXOR , 0 , 2 ) )
    print ( query ( preXOR , 1 , 2 ) )

Index/key variables: i, r
Iterator variables: i
Python program:
def findMinSwaps ( arr , n ) :
    noOfZeroes = [ 0 ] * n
    count = 0
    noOfZeroes [ n - 1 ] = 1 - arr [ n - 1 ]
    for i in range ( n - 2 , - 1 , - 1 ) :
        noOfZeroes [ i ] = noOfZeroes [ i + 1 ]
        if ( arr [ i ] == 0 ) :
            noOfZeroes [ i ] = noOfZeroes [ i ] + 1
    for i in range ( 0 , n ) :
        if ( arr [ i ] == 1 ) :
            count = count + noOfZeroes [ i ]
    return count
arr = [ 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ]
n = len ( arr )
print ( findMinSwaps ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def minswaps ( arr ) :
    count = 0
    num_unplaced_zeros = 0
    for index in range ( len ( arr ) - 1 , - 1 , - 1 ) :
        if arr [ index ] == 0 :
            num_unplaced_zeros += 1
        else :
            count += num_unplaced_zeros
    return count
arr = [ 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ]
print ( minswaps ( arr ) )

Index/key variables: index
Accumulator variables: count, num_unplaced_zeros
Iterator variables: index
Python program:
def arraySortedOrNot ( arr , n ) :
    if ( n == 0 or n == 1 ) :
        return True
    for i in range ( 1 , n ) :
        if ( arr [ i - 1 ] > arr [ i ] ) :
            return False
    return True
arr = [ 20 , 23 , 23 , 45 , 78 , 88 ]
n = len ( arr )
if ( arraySortedOrNot ( arr , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def printTwoOdd ( arr , size ) :
    xor2 = arr [ 0 ]
    set_bit_no = 0
    n = size - 2
    x , y = 0 , 0
    for i in range ( 1 , size ) :
        xor2 = xor2 ^ arr [ i ]
    set_bit_no = xor2 & ~ ( xor2 - 1 )
    for i in range ( size ) :
        if ( arr [ i ] & set_bit_no ) :
            x = x ^ arr [ i ]
        else :
            y = y ^ arr [ i ]
    print ( " The ▁ two ▁ ODD ▁ elements ▁ are " , x , " & " , y )
arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 3 , 1 ]
arr_size = len ( arr )
printTwoOdd ( arr , arr_size )

Index/key variables: i
Iterator variables: i
Python program:
def printMax ( arr , k , n ) :
    brr = arr . copy ( )
    brr . sort ( reverse = True )
    for i in range ( n ) :
        if ( arr [ i ] in brr [ 0 : k ] ) :
            print ( arr [ i ] , end = " ▁ " )
arr = [ 50 , 8 , 45 , 12 , 25 , 40 , 84 ]
n = len ( arr )
k = 3
printMax ( arr , k , n )

Index/key variables: i
Iterator variables: i
Python program:
def binary_search ( arr , low , high , ele ) :
    while low < high :
        mid = ( low + high ) // 2
        if arr [ mid ] == ele :
            return mid
        elif arr [ mid ] > ele :
            high = mid
        else :
            low = mid + 1
    return - 1
def printSmall ( arr , asize , n ) :
    copy_arr = arr . copy ( )
    copy_arr . sort ( )
    for i in range ( asize ) :
        if binary_search ( copy_arr , low = 0 , high = n , ele = arr [ i ] ) > - 1 :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ]
    asize = len ( arr )
    n = 5
    printSmall ( arr , asize , n )

Index/key variables: i, mid
Iterator variables: i
Python program:
def checkIsAP ( arr , n ) :
    if ( n == 1 ) : return True
    arr . sort ( )
    d = arr [ 1 ] - arr [ 0 ]
    for i in range ( 2 , n ) :
        if ( arr [ i ] - arr [ i - 1 ] != d ) :
            return False
    return True
arr = [ 20 , 15 , 5 , 0 , 10 ]
n = len ( arr )
print ( " Yes " ) if ( checkIsAP ( arr , n ) ) else print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def checkIsAP ( arr , n ) :
    hm = { }
    smallest = float ( ' inf ' )
    second_smallest = float ( ' inf ' )
    for i in range ( n ) :
        if ( arr [ i ] < smallest ) :
            second_smallest = smallest
            smallest = arr [ i ]
        elif ( arr [ i ] != smallest and arr [ i ] < second_smallest ) :
            second_smallest = arr [ i ]
        if arr [ i ] not in hm :
            hm [ arr [ i ] ] = 1
        else :
            return False
    diff = second_smallest - smallest
    for i in range ( n - 1 ) :
        if ( second_smallest ) not in hm :
            return False
        second_smallest += diff
    return True
arr = [ 20 , 15 , 5 , 0 , 10 ]
n = len ( arr )
if ( checkIsAP ( arr , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Accumulator variables: second_smallest
Iterator variables: i
Python program:
def countPairs ( a , n ) :
    mn = + 2147483647
    mx = - 2147483648
    for i in range ( n ) :
        mn = min ( mn , a [ i ] )
        mx = max ( mx , a [ i ] )
    c1 = 0
    c2 = 0
    for i in range ( n ) :
        if ( a [ i ] == mn ) :
            c1 += 1
        if ( a [ i ] == mx ) :
            c2 += 1
    if ( mn == mx ) :
        return n * ( n - 1 ) // 2
    else :
        return c1 * c2
a = [ 3 , 2 , 1 , 1 , 3 ]
n = len ( a )
print ( countPairs ( a , n ) )

Index/key variables: i
Accumulator variables: c1, c2
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
def rearrange ( head ) :
    if ( head == None ) :
        return head
    prev , curr = head , head . next
    while ( curr ) :
        if ( prev . data > curr . data ) :
            prev . data , curr . data = curr . data , prev . data
        if ( curr . next and curr . next . data > curr . data ) :
            curr . next . data , curr . data = curr . data , curr . next . data
        prev = curr . next
        if ( not curr . next ) :
            break
        curr = curr . next . next
    return head
def push ( head , k ) :
    tem = Node ( k )
    tem . data = k
    tem . next = head
    head = tem
    return head
def display ( head ) :
    curr = head
    while ( curr != None ) :
        print ( curr . data , end = " ▁ " )
        curr = curr . next
if __name__ == ' _ _ main _ _ ' :
    head = None
    head = push ( head , 7 )
    head = push ( head , 3 )
    head = push ( head , 8 )
    head = push ( head , 6 )
    head = push ( head , 9 )
    head = rearrange ( head )
    display ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , key ) :
        self . data = key
        self . next = None
left = None
def printlist ( head ) :
    while ( head != None ) :
        print ( head . data , end = " ▁ " )
        if ( head . next != None ) :
            print ( " - > " , end = " " )
        head = head . next
    print ( )
def rearrange ( head ) :
    global left
    if ( head != None ) :
        left = head
        reorderListUtil ( left )
def reorderListUtil ( right ) :
    global left
    if ( right == None ) :
        return
    reorderListUtil ( right . next )
    if ( left == None ) :
        return
    if ( left != right and left . next != right ) :
        temp = left . next
        left . next = right
        right . next = temp
        left = temp
    else :
        if ( left . next == right ) :
            left . next . next = None
            left = None
        else :
            left . next = None
            left = None
head = Node ( 1 )
head . next = Node ( 2 )
head . next . next = Node ( 3 )
head . next . next . next = Node ( 4 )
head . next . next . next . next = Node ( 5 )
printlist ( head )
rearrange ( head )
printlist ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , new_data ) :
        self . data = new_data
        self . next = None
def newNode ( data ) :
    temp = Node ( 0 )
    temp . data = data
    temp . next = None
    return temp
def getLength ( Node ) :
    size = 0
    while ( Node != None ) :
        Node = Node . next
        size = size + 1
    return size
def paddZeros ( sNode , diff ) :
    if ( sNode == None ) :
        return None
    zHead = newNode ( 0 )
    diff = diff - 1
    temp = zHead
    while ( diff > 0 ) :
        diff = diff - 1
        temp . next = newNode ( 0 )
        temp = temp . next
    temp . next = sNode
    return zHead
borrow = True
def subtractLinkedListHelper ( l1 , l2 ) :
    global borrow
    if ( l1 == None and l2 == None and not borrow ) :
        return None
    l3 = None
    l4 = None
    if ( l1 != None ) :
        l3 = l1 . next
    if ( l2 != None ) :
        l4 = l2 . next
    previous = subtractLinkedListHelper ( l3 , l4 )
    d1 = l1 . data
    d2 = l2 . data
    sub = 0
    if ( borrow ) :
        d1 = d1 - 1
        borrow = False
    if ( d1 < d2 ) :
        borrow = True
        d1 = d1 + 10
    sub = d1 - d2
    current = newNode ( sub )
    current . next = previous
    return current
def subtractLinkedList ( l1 , l2 ) :
    if ( l1 == None and l2 == None ) :
        return None
    len1 = getLength ( l1 )
    len2 = getLength ( l2 )
    lNode = None
    sNode = None
    temp1 = l1
    temp2 = l2
    if ( len1 != len2 ) :
        if ( len1 > len2 ) :
            lNode = l1
        else :
            lNode = l2
        if ( len1 > len2 ) :
            sNode = l2
        else :
            sNode = l1
        sNode = paddZeros ( sNode , abs ( len1 - len2 ) )
    else :
        while ( l1 != None and l2 != None ) :
            if ( l1 . data != l2 . data ) :
                if ( l1 . data > l2 . data ) :
                    lNode = temp1
                else :
                    lNode = temp2
                if ( l1 . data > l2 . data ) :
                    sNode = temp2
                else :
                    sNode = temp1
                break
            l1 = l1 . next
            l2 = l2 . next
    global borrow
    borrow = False
    return subtractLinkedListHelper ( lNode , sNode )
def printList ( Node ) :
    while ( Node != None ) :
        print ( Node . data , end = " ▁ " )
        Node = Node . next
    print ( " ▁ " )
head1 = newNode ( 1 )
head1 . next = newNode ( 0 )
head1 . next . next = newNode ( 0 )
head2 = newNode ( 1 )
result = subtractLinkedList ( head1 , head2 )
printList ( result )

Boolean variables: borrow
Class/struct names: Node