dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = self . right = None
def inorder ( root ) :
    if root != None :
        inorder ( root . left )
        print ( root . key , end = " ▁ " )
        inorder ( root . right )
def insert ( node , key ) :
    if node == None :
        return newNode ( key )
    if key < node . key :
        node . left = insert ( node . left , key )
    else :
        node . right = insert ( node . right , key )
    return node
def minValueNode ( node ) :
    current = node
    while current . left != None :
        current = current . left
    return current
def deleteNode ( root , key ) :
    if root == None :
        return root
    if key < root . key :
        root . left = deleteNode ( root . left , key )
    elif key > root . key :
        root . right = deleteNode ( root . right , key )
    else :
        if root . left == None :
            temp = root . right
            return temp
        elif root . right == None :
            temp = root . left
            return temp
        temp = minValueNode ( root . right )
        root . key = temp . key
        root . right = deleteNode ( root . right , temp . key )
    return root
def changeKey ( root , oldVal , newVal ) :
    root = deleteNode ( root , oldVal )
    root = insert ( root , newVal )
    return root
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 50 )
    root = insert ( root , 30 )
    root = insert ( root , 20 )
    root = insert ( root , 40 )
    root = insert ( root , 70 )
    root = insert ( root , 60 )
    root = insert ( root , 80 )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ given ▁ tree " )
    inorder ( root )
    root = changeKey ( root , 40 , 10 )
    print ( )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree " )
    inorder ( root )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = self . right = None
def printCommon ( root1 , root2 ) :
    s1 = [ ]
    s2 = [ ]
    while 1 :
        if root1 :
            s1 . append ( root1 )
            root1 = root1 . left
        elif root2 :
            s2 . append ( root2 )
            root2 = root2 . left
        elif len ( s1 ) != 0 and len ( s2 ) != 0 :
            root1 = s1 [ - 1 ]
            root2 = s2 [ - 1 ]
            if root1 . key == root2 . key :
                print ( root1 . key , end = " ▁ " )
                s1 . pop ( - 1 )
                s2 . pop ( - 1 )
                root1 = root1 . right
                root2 = root2 . right
            elif root1 . key < root2 . key :
                s1 . pop ( - 1 )
                root1 = root1 . right
                root2 = None
            elif root1 . key > root2 . key :
                s2 . pop ( - 1 )
                root2 = root2 . right
                root1 = None
        else :
            break
def inorder ( root ) :
    if root :
        inorder ( root . left )
        print ( root . key , end = " ▁ " )
        inorder ( root . right )
def insert ( node , key ) :
    if node == None :
        return newNode ( key )
    if key < node . key :
        node . left = insert ( node . left , key )
    elif key > node . key :
        node . right = insert ( node . right , key )
    return node
if __name__ == ' _ _ main _ _ ' :
    root1 = None
    root1 = insert ( root1 , 5 )
    root1 = insert ( root1 , 1 )
    root1 = insert ( root1 , 10 )
    root1 = insert ( root1 , 0 )
    root1 = insert ( root1 , 4 )
    root1 = insert ( root1 , 7 )
    root1 = insert ( root1 , 9 )
    root2 = None
    root2 = insert ( root2 , 10 )
    root2 = insert ( root2 , 7 )
    root2 = insert ( root2 , 20 )
    root2 = insert ( root2 , 4 )
    root2 = insert ( root2 , 9 )
    print ( " Tree ▁ 1 ▁ : ▁ " )
    inorder ( root1 )
    print ( )
    print ( " Tree ▁ 2 ▁ : ▁ " )
    inorder ( root2 )
    print ( )
    print ( " Common ▁ Nodes : ▁ " )
    printCommon ( root1 , root2 )

Accumulator variables: s1, s2
Class/struct names: newNode
Python program:
def binarySearch ( inorder , l , r , d ) :
    mid = ( l + r ) >> 1
    if ( inorder [ mid ] == d ) :
        return mid
    elif ( inorder [ mid ] > d ) :
        return binarySearch ( inorder , l , mid - 1 , d )
    else :
        return binarySearch ( inorder , mid + 1 , r , d )
    ind = [ 0 ]
def leafNodesRec ( preorder , inorder , l , r , ind , n ) :
    if ( l == r ) :
        print ( inorder [ l ] , end = " ▁ " )
        ind [ 0 ] = ind [ 0 ] + 1
        return
    if ( l < 0 or l > r or r >= n ) :
        return
    loc = binarySearch ( inorder , l , r , preorder [ ind [ 0 ] ] )
    ind [ 0 ] = ind [ 0 ] + 1
    leafNodesRec ( preorder , inorder , l , loc - 1 , ind , n )
    leafNodesRec ( preorder , inorder , loc + 1 , r , ind , n )
def leafNodes ( preorder , n ) :
    inorder = [ 0 ] * n
    for i in range ( n ) :
        inorder [ i ] = preorder [ i ]
    inorder . sort ( )
    ind = [ 0 ]
    leafNodesRec ( preorder , inorder , 0 , n - 1 , ind , n )
preorder = [ 890 , 325 , 290 , 530 , 965 ]
n = len ( preorder )
leafNodes ( preorder , n )

Index/key variables: i, l, mid
Iterator variables: i
Python program:
def leafNode ( preorder , n ) :
    s = [ ]
    i = 0
    for j in range ( 1 , n ) :
        found = False
        if preorder [ i ] > preorder [ j ] :
            s . append ( preorder [ i ] )
        else :
            while len ( s ) != 0 :
                if preorder [ j ] > s [ - 1 ] :
                    s . pop ( - 1 )
                    found = True
                else :
                    break
        if found :
            print ( preorder [ i ] , end = " ▁ " )
        i += 1
    print ( preorder [ n - 1 ] )
if __name__ == ' _ _ main _ _ ' :
    preorder = [ 890 , 325 , 290 , 530 , 965 ]
    n = len ( preorder )
    leafNode ( preorder , n )

Index/key variables: i, j
Accumulator variables: s
Iterator variables: j
Boolean variables: found
Python program:
class newNode :
    def __init__ ( self , item ) :
        self . key = item
        self . left = self . right = None
        self . parent = None
def inorder ( root ) :
    if root != None :
        inorder ( root . left )
        print ( " Node ▁ : " , root . key , " , ▁ " , end = " " )
        if root . parent == None :
            print ( " Parent ▁ : ▁ NULL " )
        else :
            print ( " Parent ▁ : ▁ " , root . parent . key )
        inorder ( root . right )
def insert ( node , key ) :
    if node == None :
        return newNode ( key )
    if key < node . key :
        lchild = insert ( node . left , key )
        node . left = lchild
        lchild . parent = node
    elif key > node . key :
        rchild = insert ( node . right , key )
        node . right = rchild
        rchild . parent = node
    return node
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 50 )
    insert ( root , 30 )
    insert ( root , 20 )
    insert ( root , 40 )
    insert ( root , 70 )
    insert ( root , 60 )
    insert ( root , 80 )
    inorder ( root )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def constructTreeUtil ( pre , preLN , index_ptr , n ) :
    index = index_ptr [ 0 ]
    if index == n :
        return None
    temp = newNode ( pre [ index ] )
    index_ptr [ 0 ] += 1
    if preLN [ index ] == ' N ' :
        temp . left = constructTreeUtil ( pre , preLN , index_ptr , n )
        temp . right = constructTreeUtil ( pre , preLN , index_ptr , n )
    return temp
def constructTree ( pre , preLN , n ) :
    index = [ 0 ]
    return constructTreeUtil ( pre , preLN , index , n )
def printInorder ( node ) :
    if node == None :
        return
    printInorder ( node . left )
    print ( node . data , end = " ▁ " )
    printInorder ( node . right )
if __name__ == ' _ _ main _ _ ' :
    root = None
    pre = [ 10 , 30 , 20 , 5 , 15 ]
    preLN = [ ' N ' , ' N ' , ' L ' , ' L ' , ' L ' ]
    n = len ( pre )
    root = constructTree ( pre , preLN , n )
    print ( " Following ▁ is ▁ Inorder ▁ Traversal ▁ of " , " the ▁ Constructed ▁ Binary ▁ Tree : " )
    printInorder ( root )

Index/key variables: index
Class/struct names: newNode
Python program:
def pairs ( arr , n , k ) :
    smallest = 999999999999
    count = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if abs ( arr [ i ] + arr [ j ] - k ) < smallest :
                smallest = abs ( arr [ i ] + arr [ j ] - k )
                count = 1
            elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :
                count += 1
    print ( " Minimal ▁ Value ▁ = ▁ " , smallest )
    print ( " Total ▁ Pairs ▁ = ▁ " , count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 5 , 7 , 5 , 1 , 9 , 9 ]
    k = 12
    n = len ( arr )
    pairs ( arr , n , k )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
        self . leftSize = 0
def insert ( root , data ) :
    if root is None :
        return newNode ( data )
    if data <= root . data :
        root . left = insert ( root . left , data )
        root . leftSize += 1
    else :
        root . right = insert ( root . right , data )
    return root
def getRank ( root , x ) :
    if root . data == x :
        return root . leftSize
    if x < root . data :
        if root . left is None :
            return - 1
        else :
            return getRank ( root . left , x )
    else :
        if root . right is None :
            return - 1
        else :
            rightSize = getRank ( root . right , x )
            if rightSize == - 1 :
                return - 1
            else :
                return root . leftSize + 1 + rightSize
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 1 , 4 , 4 , 5 , 9 , 7 , 13 , 3 ]
    n = len ( arr )
    x = 4
    root = None
    for i in range ( n ) :
        root = insert ( root , arr [ i ] )
    print ( " Rank ▁ of " , x , " in ▁ stream ▁ is : " , getRank ( root , x ) )
    x = 13
    print ( " Rank ▁ of " , x , " in ▁ stream ▁ is : " , getRank ( root , x ) )
    x = 8
    print ( " Rank ▁ of " , x , " in ▁ stream ▁ is : " , getRank ( root , x ) )

Index/key variables: i
Iterator variables: i
Class/struct names: newNode
Python program:
if __name__ == ' _ _ main _ _ ' :
    a = [ 5 , 1 , 14 , 4 , 15 , 9 , 7 , 20 , 11 ]
    key = 20
    arraySize = len ( a )
    count = 0
    for i in range ( arraySize ) :
        if a [ i ] <= key :
            count += 1
    print ( " Rank ▁ of " , key , " in ▁ stream ▁ is : " , count - 1 )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def insert ( node , data ) :
    global succ
    root = node
    if ( node == None ) :
        return Node ( data )
    if ( data < node . data ) :
        root . left = insert ( node . left , data )
    elif ( data > node . data ) :
        root . right = insert ( node . right , data )
    return root
def check ( num ) :
    sum = 0
    i = num
    if ( num < 10 or num > 99 ) :
        return 0
    else :
        sum_of_digits = ( i % 10 ) + ( i // 10 )
        prod_of_digits = ( i % 10 ) * ( i // 10 )
        sum = sum_of_digits + prod_of_digits
    if ( sum == num ) :
        return 1
    else :
        return 0
def countSpecialDigit ( rt ) :
    global c
    if ( rt == None ) :
        return
    else :
        x = check ( rt . data )
        if ( x == 1 ) :
            c += 1
        countSpecialDigit ( rt . left )
        countSpecialDigit ( rt . right )
if __name__ == ' _ _ main _ _ ' :
    root = None
    c = 0
    root = insert ( root , 50 )
    root = insert ( root , 29 )
    root = insert ( root , 59 )
    root = insert ( root , 19 )
    root = insert ( root , 53 )
    root = insert ( root , 556 )
    root = insert ( root , 56 )
    root = insert ( root , 94 )
    root = insert ( root , 13 )
    countSpecialDigit ( root )
    print ( c )

Class/struct names: Node
Python program:
def buildTree ( inorder , start , end ) :
    if start > end :
        return None
    i = Max ( inorder , start , end )
    root = newNode ( inorder [ i ] )
    if start == end :
        return root
    root . left = buildTree ( inorder , start , i - 1 )
    root . right = buildTree ( inorder , i + 1 , end )
    return root
def Max ( arr , strt , end ) :
    i , Max = 0 , arr [ strt ]
    maxind = strt
    for i in range ( strt + 1 , end + 1 ) :
        if arr [ i ] > Max :
            Max = arr [ i ]
            maxind = i
    return maxind
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def printInorder ( node ) :
    if node == None :
        return
    printInorder ( node . left )
    print ( node . data , end = " ▁ " )
    printInorder ( node . right )
if __name__ == ' _ _ main _ _ ' :
    inorder = [ 5 , 10 , 40 , 30 , 28 ]
    Len = len ( inorder )
    root = buildTree ( inorder , 0 , Len - 1 )
    print ( " Inorder ▁ traversal ▁ of ▁ the " , " constructed ▁ tree ▁ is ▁ " )
    printInorder ( root )

Index/key variables: i, strt
Iterator variables: i
Class/struct names: newNode
Python program:
def middlesum ( mat , n ) :
    row_sum = 0
    col_sum = 0
    for i in range ( n ) :
        row_sum += mat [ n // 2 ] [ i ]
    print ( " Sum ▁ of ▁ middle ▁ row ▁ = ▁ " , row_sum )
    for i in range ( n ) :
        col_sum += mat [ i ] [ n // 2 ]
    print ( " Sum ▁ of ▁ middle ▁ column ▁ = ▁ " , col_sum )
mat = [ [ 2 , 5 , 7 ] , [ 3 , 7 , 2 ] , [ 5 , 6 , 9 ] ]
middlesum ( mat , 3 )

Index/key variables: i
Accumulator variables: col_sum, row_sum
Iterator variables: i
Python program:
MAX = 1000
from time import clock
arr = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]
def rowMajor ( ) :
    global arr
    for i in range ( MAX ) :
        for j in range ( MAX ) :
            arr [ i ] [ j ] += 1
def colMajor ( ) :
    global arr
    for i in range ( MAX ) :
        for j in range ( MAX ) :
            arr [ j ] [ i ] += 1
if __name__ == ' _ _ main _ _ ' :
    t = clock ( )
    rowMajor ( ) ;
    t = clock ( ) - t
    print ( " Row ▁ major ▁ access ▁ time ▁ : { : .2f } ▁ s " . format ( t ) )
    t = clock ( )
    colMajor ( )
    t = clock ( ) - t
    print ( " Column ▁ major ▁ access ▁ time ▁ : { : .2f } ▁ s " . format ( t ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
M = 3
N = 3
matrix = [ [ 12 , 23 , 34 ] , [ 45 , 56 , 67 ] , [ 78 , 89 , 91 ] ]
def rotateMatrix ( k ) :
    global M , N , matrix
    temp = [ 0 ] * M
    k = k % M
    for i in range ( 0 , N ) :
        for t in range ( 0 , M - k ) :
            temp [ t ] = matrix [ i ] [ t ]
        for j in range ( M - k , M ) :
            matrix [ i ] [ j - M + k ] = matrix [ i ] [ j ]
        for j in range ( k , M ) :
            matrix [ i ] [ j ] = temp [ j - k ]
def displayMatrix ( ) :
    global M , N , matrix
    for i in range ( 0 , N ) :
        for j in range ( 0 , M ) :
            print ( " { } ▁ " . format ( matrix [ i ] [ j ] ) , end = " " )
        print ( )
k = 2
rotateMatrix ( k )
displayMatrix ( )

Index/key variables: i, j, t
Iterator variables: i, j, t
Python program:
N = 3 ;
def multiply ( mat , res ) :
    for i in range ( N ) :
        for j in range ( N ) :
            res [ i ] [ j ] = 0 ;
            for k in range ( N ) :
                res [ i ] [ j ] += mat [ i ] [ k ] * mat [ k ] [ j ] ;
    return res ;
def InvolutoryMatrix ( mat ) :
    res = [ [ 0 for i in range ( N ) ] for j in range ( N ) ] ;
    res = multiply ( mat , res ) ;
    for i in range ( N ) :
        for j in range ( N ) :
            if ( i == j and res [ i ] [ j ] != 1 ) :
                return False ;
            if ( i != j and res [ i ] [ j ] != 0 ) :
                return False ;
    return True ;
mat = [ [ 1 , 0 , 0 ] , [ 0 , - 1 , 0 ] , [ 0 , 0 , - 1 ] ] ;
if ( InvolutoryMatrix ( mat ) ) :
    print ( " Involutory ▁ Matrix " ) ;
else :
    print ( " Not ▁ Involutory ▁ Matrix " ) ;

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def interchangeFirstLast ( mat , n , m ) :
    rows = n
    for i in range ( n ) :
        t = mat [ 0 ] [ i ]
        mat [ 0 ] [ i ] = mat [ rows - 1 ] [ i ]
        mat [ rows - 1 ] [ i ] = t
mat = [ [ 8 , 9 , 7 , 6 ] , [ 4 , 7 , 6 , 5 ] , [ 3 , 2 , 1 , 8 ] , [ 9 , 9 , 7 , 7 ] ]
n = 4
m = 4
interchangeFirstLast ( mat , n , m )
for i in range ( n ) :
    for j in range ( m ) :
        print ( mat [ i ] [ j ] , end = " ▁ " )
    print ( " " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def sortRowWise ( m ) :
    for i in range ( len ( m ) ) :
        for j in range ( len ( m [ i ] ) ) :
            for k in range ( len ( m [ i ] ) - j - 1 ) :
                if ( m [ i ] [ k ] > m [ i ] [ k + 1 ] ) :
                    t = m [ i ] [ k ]
                    m [ i ] [ k ] = m [ i ] [ k + 1 ]
                    m [ i ] [ k + 1 ] = t
    for i in range ( len ( m ) ) :
        for j in range ( len ( m [ i ] ) ) :
            print ( m [ i ] [ j ] , end = " ▁ " )
        print ( )
m = [ [ 9 , 8 , 7 , 1 ] , [ 7 , 3 , 0 , 2 ] , [ 9 , 5 , 3 , 2 ] , [ 6 , 3 , 1 , 2 ] ]
sortRowWise ( m )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def sortRowWise ( m ) :
    for i in range ( len ( m ) ) :
        m [ i ] . sort ( )
    for i in range ( len ( m ) ) :
        for j in range ( len ( m [ i ] ) ) :
            print ( m [ i ] [ j ] , end = " ▁ " )
        print ( )
    return 0
m = [ [ 9 , 8 , 7 , 1 ] , [ 7 , 3 , 0 , 2 ] , [ 9 , 5 , 3 , 2 ] , [ 6 , 3 , 1 , 2 ] ]
sortRowWise ( m )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def checkMarkov ( m ) :
    for i in range ( 0 , len ( m ) ) :
        sm = 0
        for j in range ( 0 , len ( m [ i ] ) ) :
            sm = sm + m [ i ] [ j ]
        if ( sm != 1 ) :
            return False
    return True
m = [ [ 0 , 0 , 1 ] , [ 0.5 , 0 , 0.5 ] , [ 1 , 0 , 0 ] ]
if ( checkMarkov ( m ) ) :
    print ( " ▁ yes ▁ " )
else :
    print ( " ▁ no ▁ " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 4
def isDiagonalMatrix ( mat ) :
    for i in range ( 0 , N ) :
        for j in range ( 0 , N ) :
            if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :
                return False
    return True
mat = [ [ 4 , 0 , 0 , 0 ] , [ 0 , 7 , 0 , 0 ] , [ 0 , 0 , 5 , 0 ] , [ 0 , 0 , 0 , 1 ] ]
if ( isDiagonalMatrix ( mat ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 4
def isScalarMatrix ( mat ) :
    for i in range ( 0 , N ) :
        for j in range ( 0 , N ) :
            if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :
                return False
    for i in range ( 0 , N - 1 ) :
        if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :
            return False
    return True
mat = [ [ 2 , 0 , 0 , 0 ] , [ 0 , 2 , 0 , 0 ] , [ 0 , 0 , 2 , 0 ] , [ 0 , 0 , 0 , 2 ] ]
if ( isScalarMatrix ( mat ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def buildUtil ( In , post , inStrt , inEnd , pIndex ) :
    if ( inStrt > inEnd ) :
        return None
    node = newNode ( post [ pIndex [ 0 ] ] )
    pIndex [ 0 ] -= 1
    if ( inStrt == inEnd ) :
        return node
    iIndex = search ( In , inStrt , inEnd , node . data )
    node . right = buildUtil ( In , post , iIndex + 1 , inEnd , pIndex )
    node . left = buildUtil ( In , post , inStrt , iIndex - 1 , pIndex )
    return node
def buildTree ( In , post , n ) :
    pIndex = [ n - 1 ]
    return buildUtil ( In , post , 0 , n - 1 , pIndex )
def search ( arr , strt , end , value ) :
    i = 0
    for i in range ( strt , end + 1 ) :
        if ( arr [ i ] == value ) :
            break
    return i
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def preOrder ( node ) :
    if node == None :
        return
    print ( node . data , end = " ▁ " )
    preOrder ( node . left )
    preOrder ( node . right )
if __name__ == ' _ _ main _ _ ' :
    In = [ 4 , 8 , 2 , 5 , 1 , 6 , 3 , 7 ]
    post = [ 8 , 4 , 5 , 2 , 6 , 7 , 3 , 1 ]
    n = len ( In )
    root = buildTree ( In , post , n )
    print ( " Preorder ▁ of ▁ the ▁ constructed ▁ tree ▁ : " )
    preOrder ( root )

Index/key variables: i
Iterator variables: i
Class/struct names: newNode
Python program:
def subCount ( arr , n , k ) :
    mod = [ 0 ] * k ;
    cumSum = 0 ;
    for i in range ( 0 , n ) :
        cumSum = cumSum + arr [ i ] ;
        mod [ ( ( cumSum % k ) + k ) % k ] = mod [ ( ( cumSum % k ) + k ) % k ] + 1 ;
    result = 0 ;
    for i in range ( 0 , k ) :
        if ( mod [ i ] > 1 ) :
            result = result + int ( ( mod [ i ] * ( mod [ i ] - 1 ) ) / 2 ) ;
    result = result + mod [ 0 ] ;
    return result ;
def countSubmatrix ( mat , n , k ) :
    tot_count = 0 ;
    temp = [ 0 ] * n ;
    for left in range ( 0 , n - 1 ) :
        for right in range ( left , n ) :
            for i in range ( 0 , n ) :
                temp [ i ] = ( temp [ i ] + mat [ i ] [ right ] ) ;
            tot_count = ( tot_count + subCount ( temp , n , k ) ) ;
    return tot_count ;
mat = [ [ 5 , - 1 , 6 ] , [ - 2 , 3 , 8 ] , [ 7 , 4 , - 9 ] ] ;
n = 3 ;
k = 4 ;
print ( " Count ▁ = ▁ { } " . format ( countSubmatrix ( mat , n , k ) ) ) ;

Index/key variables: i, right
Iterator variables: i, left, right
Python program:
def findMinOpeartion ( matrix , n ) :
    sumRow = [ 0 ] * n
    sumCol = [ 0 ] * n
    for i in range ( n ) :
        for j in range ( n ) :
            sumRow [ i ] += matrix [ i ] [ j ]
            sumCol [ j ] += matrix [ i ] [ j ]
    maxSum = 0
    for i in range ( n ) :
        maxSum = max ( maxSum , sumRow [ i ] )
        maxSum = max ( maxSum , sumCol [ i ] )
    count = 0
    i = 0
    j = 0
    while i < n and j < n :
        diff = min ( maxSum - sumRow [ i ] , maxSum - sumCol [ j ] )
        matrix [ i ] [ j ] += diff
        sumRow [ i ] += diff
        sumCol [ j ] += diff
        count += diff
        if ( sumRow [ i ] == maxSum ) :
            i += 1
        if ( sumCol [ j ] == maxSum ) :
            j += 1
    return count
def printMatrix ( matrix , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            print ( matrix [ i ] [ j ] , end = " ▁ " )
        print ( )
if __name__ == " _ _ main _ _ " :
    matrix = [ [ 1 , 2 ] , [ 3 , 4 ] ]
    print ( findMinOpeartion ( matrix , 2 ) )
    printMatrix ( matrix , 2 )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def ZigZag ( rows , columns , numbers ) :
    k = 0
    arr = [ [ 0 for i in range ( columns ) ] for j in range ( rows ) ]
    for i in range ( rows ) :
        if ( i % 2 == 0 ) :
            j = 0
            while j < columns and numbers [ k ] > 0 :
                arr [ i ] [ j ] = k + 1
                numbers [ k ] -= 1
                if numbers [ k ] == 0 :
                    k += 1
                j += 1
        else :
            j = columns - 1
            while j >= 0 and numbers [ k ] > 0 :
                arr [ i ] [ j ] = k + 1
                numbers [ k ] -= 1
                if numbers [ k ] == 0 :
                    k += 1
                j -= 1
    for i in arr :
        for j in i :
            print ( j , end = " ▁ " )
        print ( )
rows = 4 ;
columns = 5 ;
Numbers = [ 3 , 4 , 2 , 2 , 3 , 1 , 5 ]
ZigZag ( rows , columns , Numbers )

Index/key variables: i, j, k
Iterator variables: i, j