dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def difference ( arr , n ) :
    d1 = 0
    d2 = 0
    for i in range ( 0 , n ) :
        d1 = d1 + arr [ i ] [ i ]
        d2 = d2 + arr [ i ] [ n - i - 1 ]
    return abs ( d1 - d2 )
n = 3
arr = [ [ 11 , 2 , 4 ] , [ 4 , 5 , 6 ] , [ 10 , 8 , - 12 ] ]
print ( difference ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def spiralFill ( m , n , a ) :
    val = 1
    k , l = 0 , 0
    while ( k < m and l < n ) :
        for i in range ( l , n ) :
            a [ k ] [ i ] = val
            val += 1
        k += 1
        for i in range ( k , m ) :
            a [ i ] [ n - 1 ] = val
            val += 1
        n -= 1
        if ( k < m ) :
            for i in range ( n - 1 , l - 1 , - 1 ) :
                a [ m - 1 ] [ i ] = val
                val += 1
            m -= 1
        if ( l < n ) :
            for i in range ( m - 1 , k - 1 , - 1 ) :
                a [ i ] [ l ] = val
                val += 1
            l += 1
if __name__ == ' _ _ main _ _ ' :
    m , n = 4 , 4
    a = [ [ 0 for j in range ( m ) ] for i in range ( n ) ]
    spiralFill ( m , n , a )
    for i in range ( m ) :
        for j in range ( n ) :
            print ( a [ i ] [ j ] , end = ' ▁ ' )
        print ( ' ' )

Index/key variables: i, j, k, l
Accumulator variables: m, n, val
Iterator variables: i, j
Python program:
def printTreeEdges ( prufer , m ) :
    vertices = m + 2
    vertex_set = [ 0 ] * vertices
    for i in range ( vertices - 2 ) :
        vertex_set [ prufer [ i ] - 1 ] += 1
    print ( " The ▁ edge ▁ set ▁ E ( G ) ▁ is ▁ : " )
    j = 0
    for i in range ( vertices - 2 ) :
        for j in range ( vertices ) :
            if ( vertex_set [ j ] == 0 ) :
                vertex_set [ j ] = - 1
                print ( " ( " , ( j + 1 ) , " , ▁ " , prufer [ i ] , " ) ▁ " , sep = " " , end = " " )
                vertex_set [ prufer [ i ] - 1 ] -= 1
                break
    j = 0
    for i in range ( vertices ) :
        if ( vertex_set [ i ] == 0 and j == 0 ) :
            print ( " ( " , ( i + 1 ) , " , ▁ " , sep = " " , end = " " )
            j += 1
        elif ( vertex_set [ i ] == 0 and j == 1 ) :
            print ( ( i + 1 ) , " ) " )
prufer = [ 4 , 1 , 3 , 4 ]
n = len ( prufer )
printTreeEdges ( prufer , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
MAX = 100
def MAXMIN ( arr , n ) :
    MIN = 10 ** 9
    MAX = - 10 ** 9
    for i in range ( n ) :
        for j in range ( n // 2 + 1 ) :
            if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :
                if ( MIN > arr [ i ] [ n - j - 1 ] ) :
                    MIN = arr [ i ] [ n - j - 1 ]
                if ( MAX < arr [ i ] [ j ] ) :
                    MAX = arr [ i ] [ j ]
            else :
                if ( MIN > arr [ i ] [ j ] ) :
                    MIN = arr [ i ] [ j ]
                if ( MAX < arr [ i ] [ n - j - 1 ] ) :
                    MAX = arr [ i ] [ n - j - 1 ]
    print ( " MAXimum ▁ = " , MAX , " , ▁ MINimum ▁ = " , MIN )
arr = [ [ 5 , 9 , 11 ] , [ 25 , 0 , 14 ] , [ 21 , 6 , 4 ] ]
MAXMIN ( arr , 3 )

Index/key variables: i, j
Iterator variables: i, j
Python program:
R = 4
C = 5
def antiSpiralTraversal ( m , n , a ) :
    k = 0
    l = 0
    stk = [ ]
    while ( k <= m and l <= n ) :
        for i in range ( l , n + 1 ) :
            stk . append ( a [ k ] [ i ] )
        k += 1
        for i in range ( k , m + 1 ) :
            stk . append ( a [ i ] [ n ] )
        n -= 1
        if ( k <= m ) :
            for i in range ( n , l - 1 , - 1 ) :
                stk . append ( a [ m ] [ i ] )
            m -= 1
        if ( l <= n ) :
            for i in range ( m , k - 1 , - 1 ) :
                stk . append ( a [ i ] [ l ] )
            l += 1
    while len ( stk ) != 0 :
        print ( str ( stk [ - 1 ] ) , end = " ▁ " )
        stk . pop ( )
mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 7 , 8 , 9 , 10 ] , [ 11 , 12 , 13 , 14 , 15 ] , [ 16 , 17 , 18 , 19 , 20 ] ] ;
antiSpiralTraversal ( R - 1 , C - 1 , mat )

Index/key variables: i, k, l, m, n
Accumulator variables: stk
Iterator variables: i
Python program:
def minOperation ( arr ) :
    ans = 0
    for i in range ( N - 1 , - 1 , - 1 ) :
        for j in range ( M - 1 , - 1 , - 1 ) :
            if ( arr [ i ] [ j ] == 0 ) :
                ans += 1
                for k in range ( i + 1 ) :
                    for h in range ( j + 1 ) :
                        if ( arr [ k ] [ h ] == 1 ) :
                            arr [ k ] [ h ] = 0
                        else :
                            arr [ k ] [ h ] = 1
    return ans
mat = [ [ 0 , 0 , 1 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] ]
M = 5
N = 5
print ( minOperation ( mat ) )

Index/key variables: h, i, j, k
Accumulator variables: ans
Iterator variables: h, i, j, k
Python program:
ROW = 3
COL = 3
def transpose ( transpose_matrix , matrix ) :
    for i in range ( ROW ) :
        for j in range ( COL ) :
            transpose_matrix [ j ] [ i ] = matrix [ i ] [ j ]
def check ( transpose_matrix , matrix ) :
    for i in range ( ROW ) :
        for j in range ( COL ) :
            if ( matrix [ i ] [ j ] != - transpose_matrix [ i ] [ j ] ) :
                return False
    return True
def printMatrix ( matrix ) :
    for i in range ( ROW ) :
        for j in range ( COL ) :
            print ( matrix [ i ] [ j ] , " ▁ " , end = " " )
        print ( )
matrix = [ [ 0 , 5 , - 4 ] , [ - 5 , 0 , 1 ] , [ 4 , - 1 , 0 ] , ]
transpose_matrix = [ [ 0 for i in range ( 3 ) ] for j in range ( 3 ) ]
transpose ( transpose_matrix , matrix )
print ( " Transpose ▁ matrix : " )
printMatrix ( transpose_matrix )
if ( check ( transpose_matrix , matrix ) ) :
    print ( " Skew ▁ Symmetric ▁ Matrix " )
else :
    print ( " Not ▁ Skew ▁ Symmetric ▁ Matrix " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findSum ( n ) :
    ans = 0 ; temp = 0 ;
    for i in range ( 1 , n + 1 ) :
        if temp < n :
            temp = i - 1
            num = 1
            while temp < n :
                if temp + i <= n :
                    ans += i * num
                else :
                    ans += ( n - temp ) * num
                temp += i
                num += 1
    return ans
N = 2
print ( findSum ( N ) )

Accumulator variables: ans, num, temp
Iterator variables: i
Python program:
def countOps ( A , B , m , n ) :
    for i in range ( n ) :
        for j in range ( m ) :
            A [ i ] [ j ] -= B [ i ] [ j ] ;
    for i in range ( 1 , n ) :
        for j in range ( 1 , n ) :
            if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :
                return - 1 ;
    result = 0 ;
    for i in range ( n ) :
        result += abs ( A [ i ] [ 0 ] ) ;
    for j in range ( m ) :
        result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;
    return ( result ) ;
if __name__ == ' _ _ main _ _ ' :
    A = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ;
    B = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ;
    print ( countOps ( A , B , 3 , 3 ) ) ;

Index/key variables: i, j
Accumulator variables: result
Iterator variables: i, j
Python program:
from math import ceil , log
class newNode :
    def __init__ ( self , value ) :
        self . key = value
        self . child = [ ]
def BuildkaryTree ( A , n , k , h , ind ) :
    if ( n <= 0 ) :
        return None
    nNode = newNode ( A [ ind [ 0 ] ] )
    if ( nNode == None ) :
        print ( " Memory ▁ error " )
        return None
    for i in range ( k ) :
        if ( ind [ 0 ] < n - 1 and h > 1 ) :
            ind [ 0 ] += 1
            nNode . child . append ( BuildkaryTree ( A , n , k , h - 1 , ind ) )
        else :
            nNode . child . append ( None )
    return nNode
def BuildKaryTree ( A , n , k , ind ) :
    height = int ( ceil ( log ( float ( n ) * ( k - 1 ) + 1 ) / log ( float ( k ) ) ) )
    return BuildkaryTree ( A , n , k , height , ind )
def postord ( root , k ) :
    if ( root == None ) :
        return
    for i in range ( k ) :
        postord ( root . child [ i ] , k )
    print ( root . key , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    ind = [ 0 ]
    k = 3
    n = 10
    preorder = [ 1 , 2 , 5 , 6 , 7 , 3 , 8 , 9 , 10 , 4 ]
    root = BuildKaryTree ( preorder , n , k , ind )
    print ( " Postorder ▁ traversal ▁ of ▁ constructed " , " full ▁ k - ary ▁ tree ▁ is : ▁ " )
    postord ( root , k )

Index/key variables: i
Iterator variables: i
Class/struct names: newNode
Python program:
def findSum ( n ) :
    arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]
    for i in range ( n ) :
        for j in range ( n ) :
            arr [ i ] [ j ] = abs ( i - j )
    sum = 0
    for i in range ( n ) :
        for j in range ( n ) :
            sum += arr [ i ] [ j ]
    return sum
if __name__ == " _ _ main _ _ " :
    n = 3
    print ( findSum ( n ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
def findSum ( n ) :
    sum = 0
    for i in range ( n ) :
        sum += i * ( n - i )
    return 2 * sum
n = 3
print ( findSum ( n ) )

Accumulator variables: sum
Iterator variables: i
Python program:
R = 3
C = 5
def numofneighbour ( mat , i , j ) :
    count = 0 ;
    if ( i > 0 and mat [ i - 1 ] [ j ] ) :
        count += 1 ;
    if ( j > 0 and mat [ i ] [ j - 1 ] ) :
        count += 1 ;
    if ( i < R - 1 and mat [ i + 1 ] [ j ] ) :
        count += 1
    if ( j < C - 1 and mat [ i ] [ j + 1 ] ) :
        count += 1 ;
    return count ;
def findperimeter ( mat ) :
    perimeter = 0 ;
    for i in range ( 0 , R ) :
        for j in range ( 0 , C ) :
            if ( mat [ i ] [ j ] ) :
                perimeter += ( 4 - numofneighbour ( mat , i , j ) ) ;
    return perimeter ;
mat = [ [ 0 , 1 , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 0 , 0 ] , [ 1 , 0 , 0 , 0 , 0 ] ]
print ( findperimeter ( mat ) , end = " " ) ;

Index/key variables: i, j
Accumulator variables: perimeter
Iterator variables: i, j
Python program:
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 )
def findIndex ( Str , si , ei ) :
    if ( si > ei ) :
        return - 1
    s = [ ]
    for i in range ( si , ei + 1 ) :
        if ( Str [ i ] == ' ( ' ) :
            s . append ( Str [ i ] )
        elif ( Str [ i ] == ' ) ' ) :
            if ( s [ - 1 ] == ' ( ' ) :
                s . pop ( - 1 )
                if len ( s ) == 0 :
                    return i
    return - 1
def treeFromString ( Str , si , ei ) :
    if ( si > ei ) :
        return None
    root = newNode ( ord ( Str [ si ] ) - ord ( '0' ) )
    index = - 1
    if ( si + 1 <= ei and Str [ si + 1 ] == ' ( ' ) :
        index = findIndex ( Str , si + 1 , ei )
    if ( index != - 1 ) :
        root . left = treeFromString ( Str , si + 2 , index - 1 )
        root . right = treeFromString ( Str , index + 2 , ei - 1 )
    return root
if __name__ == ' _ _ main _ _ ' :
    Str = "4(2(3 ) ( 1 ) ) (6(5 ) ) "
    root = treeFromString ( Str , 0 , len ( Str ) - 1 )
    preOrder ( root )

Index/key variables: i, si
Accumulator variables: s
Iterator variables: i
Class/struct names: newNode
Python program:
MAX = 100
def printMatrixDiagonal ( mat , n ) :
    i = 0
    j = 0
    k = 0
    isUp = True
    while k < n * n :
        if isUp :
            while i >= 0 and j < n :
                print ( str ( mat [ i ] [ j ] ) , end = " ▁ " )
                k += 1
                j += 1
                i -= 1
            if i < 0 and j <= n - 1 :
                i = 0
            if j == n :
                i = i + 2
                j -= 1
        else :
            while j >= 0 and i < n :
                print ( mat [ i ] [ j ] , end = " ▁ " )
                k += 1
                i += 1
                j -= 1
            if j < 0 and i <= n - 1 :
                j = 0
            if i == n :
                j = j + 2
                i -= 1
        isUp = not isUp
if __name__ == " _ _ main _ _ " :
    mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    n = 3
    printMatrixDiagonal ( mat , n )

Index/key variables: i, j
Accumulator variables: k
Boolean variables: isUp
Python program:
mat = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ;
n = 4
mode = 0
it = 0
lower = 0
for t in range ( 2 * n - 1 ) :
    t1 = t
    if ( t1 >= n ) :
        mode += 1
        t1 = n - 1
        it -= 1
        lower += 1
    else :
        lower = 0
        it += 1
    for i in range ( t1 , lower - 1 , - 1 ) :
        if ( ( t1 + mode ) % 2 == 0 ) :
            print ( ( mat [ i ] [ t1 + lower - i ] ) )
        else :
            print ( mat [ t1 + lower - i ] [ i ] )

Index/key variables: i
Accumulator variables: it, lower, mode
Iterator variables: i, t
Python program:
def maxRowDiff ( mat , m , n ) :
    rowSum = [ 0 ] * m
    for i in range ( 0 , m ) :
        sum = 0
        for j in range ( 0 , n ) :
            sum += mat [ i ] [ j ]
        rowSum [ i ] = sum
    max_diff = rowSum [ 1 ] - rowSum [ 0 ]
    min_element = rowSum [ 0 ]
    for i in range ( 1 , m ) :
        if ( rowSum [ i ] - min_element > max_diff ) :
            max_diff = rowSum [ i ] - min_element
        if ( rowSum [ i ] < min_element ) :
            min_element = rowSum [ i ]
    return max_diff
m = 5
n = 4
mat = [ [ - 1 , 2 , 3 , 4 ] , [ 5 , 3 , - 2 , 1 ] , [ 6 , 7 , 2 , - 3 ] , [ 2 , 9 , 1 , 4 ] , [ 2 , 1 , - 2 , 0 ] ]
print ( maxRowDiff ( mat , m , n ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
R = 4
C = 4
def getTotalCoverageOfMatrix ( mat ) :
    res = 0
    for i in range ( R ) :
        isOne = False
        for j in range ( C ) :
            if ( mat [ i ] [ j ] == 1 ) :
                isOne = True
            elif ( isOne ) :
                res += 1
        isOne = False
        for j in range ( C - 1 , - 1 , - 1 ) :
            if ( mat [ i ] [ j ] == 1 ) :
                isOne = True
            elif ( isOne ) :
                res += 1
    for j in range ( C ) :
        isOne = False
        for i in range ( R ) :
            if ( mat [ i ] [ j ] == 1 ) :
                isOne = True
            elif ( isOne ) :
                res += 1
        isOne = False
        for i in range ( R - 1 , - 1 , - 1 ) :
            if ( mat [ i ] [ j ] == 1 ) :
                isOne = True
            elif ( isOne ) :
                res += 1
    return res
mat = [ [ 0 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 0 ] ]
print ( getTotalCoverageOfMatrix ( mat ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Boolean variables: isOne
Python program:
def sortedCount ( mat , r , c ) :
    result = 0
    for i in range ( r ) :
        j = 0
        for j in range ( c - 1 ) :
            if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :
                break
        if j == c - 2 :
            result += 1
    for i in range ( 0 , r ) :
        j = 0
        for j in range ( c - 1 , 0 , - 1 ) :
            if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :
                break
        if c > 1 and j == 1 :
            result += 1
    return result
m , n = 4 , 5
mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 4 , 3 , 1 , 2 , 6 ] , [ 8 , 7 , 6 , 5 , 4 ] , [ 5 , 7 , 8 , 9 , 10 ] ]
print ( sortedCount ( mat , m , n ) )

Index/key variables: i, j
Accumulator variables: result
Iterator variables: i, j
Python program:
MAX = 1000
def maxXOR ( mat , N ) :
    max_xor = 0
    for i in range ( N ) :
        r_xor = 0
        c_xor = 0
        for j in range ( N ) :
            r_xor = r_xor ^ mat [ i ] [ j ]
            c_xor = c_xor ^ mat [ j ] [ i ]
        if ( max_xor < max ( r_xor , c_xor ) ) :
            max_xor = max ( r_xor , c_xor )
    return max_xor
N = 3
mat = [ [ 1 , 5 , 4 ] , [ 3 , 7 , 2 ] , [ 5 , 9 , 10 ] ]
print ( " maximum ▁ XOR ▁ value ▁ : ▁ " , maxXOR ( mat , N ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
R = 3
C = 6
def spiralPrint ( m , n , a , c ) :
    k = 0
    l = 0
    count = 0
    while ( k < m and l < n ) :
        for i in range ( l , n ) :
            count += 1
            if ( count == c ) :
                print ( a [ k ] [ i ] , end = " ▁ " )
        k += 1
        for i in range ( k , m ) :
            count += 1
            if ( count == c ) :
                print ( a [ i ] [ n - 1 ] , end = " ▁ " )
        n -= 1
        if ( k < m ) :
            for i in range ( n - 1 , l - 1 , - 1 ) :
                count += 1
                if ( count == c ) :
                    print ( a [ m - 1 ] [ i ] , end = " ▁ " )
            m -= 1
        if ( l < n ) :
            for i in range ( m - 1 , k - 1 , - 1 ) :
                count += 1
                if ( count == c ) :
                    print ( a [ i ] [ l ] , end = " ▁ " )
            l += 1
a = [ [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 7 , 8 , 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 , 17 , 18 ] ]
k = 17
spiralPrint ( R , C , a , k )

Index/key variables: i, k, l
Accumulator variables: count, m, n
Iterator variables: i
Python program:
N = 5 ;
def countZeroes ( mat ) :
    row = N - 1 ;
    col = 0 ;
    count = 0 ;
    while ( col < N ) :
        while ( mat [ row ] [ col ] ) :
            if ( row < 0 ) :
                return count ;
            row = row - 1 ;
        count = count + ( row + 1 ) ;
        col = col + 1 ;
    return count ;
mat = [ [ 0 , 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 0 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] ] ;
print ( countZeroes ( mat ) ) ;

Index/key variables: col, row
Python program:
SIZE = 50
class node :
    def __init__ ( self , data ) :
        self . data = data
        self . right = None
        self . left = None
class Queue :
    def __init__ ( self ) :
        self . front = None
        self . rear = None
        self . size = 0
        self . array = [ ]
def newNode ( data ) :
    temp = node ( data )
    return temp
def createQueue ( size ) :
    global queue
    queue = Queue ( ) ;
    queue . front = queue . rear = - 1 ;
    queue . size = size ;
    queue . array = [ None for i in range ( size ) ]
    return queue ;
def isEmpty ( queue ) :
    return queue . front == - 1
def isFull ( queue ) :
    return queue . rear == queue . size - 1 ;
def hasOnlyOneItem ( queue ) :
    return queue . front == queue . rear ;
def Enqueue ( root ) :
    if ( isFull ( queue ) ) :
        return ;
    queue . rear += 1
    queue . array [ queue . rear ] = root ;
    if ( isEmpty ( queue ) ) :
        queue . front += 1 ;
def Dequeue ( ) :
    if ( isEmpty ( queue ) ) :
        return None ;
    temp = queue . array [ queue . front ] ;
    if ( hasOnlyOneItem ( queue ) ) :
        queue . front = queue . rear = - 1 ;
    else :
        queue . front += 1
    return temp ;
def getFront ( queue ) :
    return queue . array [ queue . front ] ;
def hasBothChild ( temp ) :
    return ( temp and temp . left and temp . right ) ;
def insert ( root , data , queue ) :
    temp = newNode ( data ) ;
    if not root :
        root = temp ;
    else :
        front = getFront ( queue ) ;
        if ( not front . left ) :
            front . left = temp ;
        elif ( not front . right ) :
            front . right = temp ;
        if ( hasBothChild ( front ) ) :
            Dequeue ( ) ;
    Enqueue ( temp ) ;
    return root
def levelOrder ( root ) :
    queue = createQueue ( SIZE ) ;
    Enqueue ( root ) ;
    while ( not isEmpty ( queue ) ) :
        temp = Dequeue ( ) ;
        print ( temp . data , end = ' ▁ ' )
        if ( temp . left ) :
            Enqueue ( temp . left ) ;
        if ( temp . right ) :
            Enqueue ( temp . right ) ;
if __name__ == " _ _ main _ _ " :
    root = None
    queue = createQueue ( SIZE ) ;
    for i in range ( 1 , 13 ) :
        root = insert ( root , i , queue ) ;
    levelOrder ( root ) ;

Iterator variables: i
Class/struct names: Queue, node
Python program:
N = 10
def findLargestPlus ( mat ) :
    left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    for i in range ( N ) :
        top [ 0 ] [ i ] = mat [ 0 ] [ i ]
        bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]
        left [ i ] [ 0 ] = mat [ i ] [ 0 ]
        right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]
    for i in range ( N ) :
        for j in range ( 1 , N ) :
            if ( mat [ i ] [ j ] == 1 ) :
                left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1
            else :
                left [ i ] [ j ] = 0
            if ( mat [ j ] [ i ] == 1 ) :
                top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1
            else :
                top [ j ] [ i ] = 0
            j = N - 1 - j
            if ( mat [ j ] [ i ] == 1 ) :
                bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1
            else :
                bottom [ j ] [ i ] = 0
            if ( mat [ i ] [ j ] == 1 ) :
                right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1
            else :
                right [ i ] [ j ] = 0
            j = N - 1 - j
    n = 0
    for i in range ( N ) :
        for j in range ( N ) :
            l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )
            if ( l > n ) :
                n = l
    if ( n ) :
        return 4 * ( n - 1 ) + 1
    return 0
if __name__ == " _ _ main _ _ " :
    mat = [ [ 1 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ] , [ 1 , 0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 1 ] , [ 1 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 ] , [ 1 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 ] , [ 1 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 ] , [ 1 , 1 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 0 ] ]
    print ( findLargestPlus ( mat ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findLeft ( str ) :
    n = len ( str ) - 1 ;
    while ( n > 0 ) :
        if ( str [ n ] == ' d ' ) :
            str = str [ 0 : n ] + ' c ' + str [ n + 1 : ] ;
            break ;
        if ( str [ n ] == ' b ' ) :
            str = str [ 0 : n ] + ' a ' + str [ n + 1 : ] ;
            break ;
        if ( str [ n ] == ' a ' ) :
            str = str [ 0 : n ] + ' b ' + str [ n + 1 : ] ;
        elif ( str [ n ] == ' c ' ) :
            str = str [ 0 : n ] + ' d ' + str [ n + 1 : ] ;
        n -= 1 ;
    return str ;
if __name__ == ' _ _ main _ _ ' :
    str = " aacbddc " ;
    print ( " Left ▁ of " , str , " is " , findLeft ( str ) ) ;

Index/key variables: n
Python program:
def printSpiral ( n ) :
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            x = min ( min ( i , j ) , min ( n - 1 - i , n - 1 - j ) )
            if ( i <= j ) :
                print ( ( n - 2 * x ) * ( n - 2 * x ) - ( i - x ) - ( j - x ) , end = " TABSYMBOL " )
            else :
                print ( ( ( n - 2 * x - 2 ) * ( n - 2 * x - 2 ) + ( i - x ) + ( j - x ) ) , end = " TABSYMBOL " )
        print ( )
n = 5
printSpiral ( n )

Iterator variables: i, j