dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
rem = [ [ 0 for x in range ( 11 ) ] for y in range ( 11 ) ]
def countPairs ( a , n , k ) :
    l = [ 0 ] * n
    p = [ 0 ] * ( 11 )
    p [ 0 ] = 1
    for i in range ( 1 , 11 ) :
        p [ i ] = ( p [ i - 1 ] * 10 ) % k
    for i in range ( n ) :
        x = a [ i ]
        while ( x > 0 ) :
            l [ i ] += 1
            x //= 10
        rem [ l [ i ] ] [ a [ i ] % k ] += 1
    ans = 0
    for i in range ( n ) :
        for j in range ( 1 , 11 ) :
            r = ( a [ i ] * p [ j ] ) % k
            xr = ( k - r ) % k
            ans += rem [ j ] [ xr ]
            if ( l [ i ] == j and ( r + a [ i ] % k ) % k == 0 ) :
                ans -= 1
    return ans
a = [ 4 , 5 , 2 ]
n = len ( a )
k = 2
print ( countPairs ( a , n , k ) )

Index/key variables: i, j, xr
Accumulator variables: ans, x
Iterator variables: i, j
Python program:
def countDigitSum ( N , K ) :
    l = pow ( 10 , N - 1 ) ;
    r = pow ( 10 , N ) - 1 ;
    count = 0 ;
    for i in range ( 1 , r + 1 ) :
        num = i ;
        digits = [ 0 ] * ( N ) ;
        for j in range ( N - 1 , 0 , - 1 ) :
            digits [ j ] = num % 10 ;
            num //= 10 ;
        sum = 0 ;
        flag = 0 ;
        for j in range ( 0 , K ) :
            sum += digits [ j ] ;
        for j in range ( K , N ) :
            if ( sum - digits [ j - K ] + digits [ j ] != sum ) :
                flag = 1 ;
                break ;
        if ( flag == 0 ) :
            count += 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    N = 2 ;
    K = 1 ;
    print ( countDigitSum ( N , K ) ) ;

Index/key variables: j
Accumulator variables: count, num, sum
Iterator variables: i, j
Python program:
def calculate ( arr ) :
    n = len ( arr )
    ans = [ ]
    for i in range ( n ) :
        sum = 0
        for j in range ( len ( arr ) ) :
            sum += abs ( arr [ i ] - arr [ j ] )
        ans . append ( sum )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 5 , 6 ]
    print ( calculate ( arr ) )

Index/key variables: i, j
Accumulator variables: ans, sum
Iterator variables: i, j
Python program:
def dfs ( graph , visited , x , k ) :
    for i in range ( len ( graph [ x ] ) ) :
        if ( not visited [ graph [ x ] [ i ] ] ) :
            k [ 0 ] += 1
            visited [ graph [ x ] [ i ] ] = True
            dfs ( graph , visited , graph [ x ] [ i ] , k )
def countNonAccessible ( graph , N ) :
    visited = [ False ] * ( N * N + N )
    ans = 0
    for i in range ( 1 , N * N + 1 ) :
        if ( not visited [ i ] ) :
            visited [ i ] = True
            k = [ 1 ]
            dfs ( graph , visited , i , k )
            ans += k [ 0 ] * ( N * N - k [ 0 ] )
    return ans
def insertpath ( graph , N , x1 , y1 , x2 , y2 ) :
    a = ( x1 - 1 ) * N + y1
    b = ( x2 - 1 ) * N + y2
    graph [ a ] . append ( b )
    graph [ b ] . append ( a )
if __name__ == ' _ _ main _ _ ' :
    N = 2
    graph = [ [ ] for i in range ( N * N + 1 ) ]
    insertpath ( graph , N , 1 , 1 , 1 , 2 )
    insertpath ( graph , N , 1 , 2 , 2 , 2 )
    print ( countNonAccessible ( graph , N ) )

Index/key variables: a, b, i, x
Accumulator variables: ans
Iterator variables: i
Python program:
def findMinimum ( s ) :
    n = len ( s )
    x = [ 0 ] * ( n + 1 )
    s = s [ : : - 1 ]
    for i in range ( n ) :
        if ( s [ i ] == '1' ) :
            if ( x [ i ] == 1 ) :
                x [ i + 1 ] = 1
                x [ i ] = 0
            elif ( i and x [ i - 1 ] == 1 ) :
                x [ i + 1 ] = 1
                x [ i - 1 ] = - 1
            else :
                x [ i ] = 1
    c = 0
    for i in range ( n + 1 ) :
        if ( x [ i ] != 0 ) :
            c += 1
    print ( c )
if __name__ == ' _ _ main _ _ ' :
    str = "111"
    findMinimum ( str )

Index/key variables: i
Accumulator variables: c
Iterator variables: i
Python program:
import sys
def splitIntoFibonacciHelper ( pos , S , seq ) :
    if ( pos == len ( S ) and ( len ( seq ) >= 3 ) ) :
        return True
    num = 0
    for i in range ( pos , len ( S ) ) :
        num = num * 10 + ( ord ( S [ i ] ) - ord ( '0' ) )
        if ( num > sys . maxsize ) :
            break
        if ( ord ( S [ pos ] ) == ord ( '0' ) and i > pos ) :
            break
        if ( len ( seq ) > 2 and ( num > ( seq [ - 1 ] + seq [ len ( seq ) - 2 ] ) ) ) :
            break
        if ( len ( seq ) < 2 or ( num == ( seq [ - 1 ] + seq [ len ( seq ) - 2 ] ) ) ) :
            seq . append ( num )
            if ( splitIntoFibonacciHelper ( i + 1 , S , seq ) ) :
                return True
            seq . pop ( )
    return False
def splitIntoFibonacci ( S ) :
    seq = [ ]
    splitIntoFibonacciHelper ( 0 , S , seq )
    if ( len ( seq ) >= 3 ) :
        for i in seq :
            print ( i , end = ' ▁ ' )
    else :
        print ( - 1 , end = ' ' )
if __name__ == ' _ _ main _ _ ' :
    S = "11235813"
    splitIntoFibonacci ( S )

Index/key variables: i, pos
Accumulator variables: seq
Iterator variables: i
Python program:
def solve ( arr , r , c ) :
    idx = 1
    dp = [ [ 0 for i in range ( c ) ] for i in range ( r ) ]
    for i in range ( r ) :
        if ( i % 2 == 0 ) :
            for j in range ( c ) :
                if ( arr [ idx - 1 ] == 0 ) :
                    idx += 1
                dp [ i ] [ j ] = idx
                arr [ idx - 1 ] -= 1
        else :
            for j in range ( c - 1 , - 1 , - 1 ) :
                if ( arr [ idx - 1 ] == 0 ) :
                    idx += 1
                dp [ i ] [ j ] = idx
                arr [ idx - 1 ] -= 1
    for i in range ( r ) :
        for j in range ( c ) :
            print ( dp [ i ] [ j ] , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    r = 3
    c = 5
    n = 5
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    solve ( arr , r , c )

Index/key variables: i, j
Accumulator variables: idx
Iterator variables: i, j
Python program:
def count ( k , s ) :
    ar = [ 0 ] * len ( s )
    end = 0
    for i in range ( len ( s ) ) :
        if s [ i ] == '1' :
            for j in range ( i , len ( s ) ) :
                if ( j <= i + k ) :
                    ar [ j ] = - 1
                    end = j
            i = end
    end = 0
    for i in range ( len ( s ) - 1 , - 1 , - 1 ) :
        if ( s [ i ] == '1' ) :
            for j in range ( i , - 1 , - 1 ) :
                if ( j >= i - k ) :
                    ar [ j ] = - 1
                    end = j
            i = end
    ans = 0
    end = 0
    for j in range ( len ( s ) ) :
        if ( ar [ j ] == 0 ) :
            ans += 1
            for g in range ( j , len ( s ) ) :
                if ( g <= j + k ) :
                    ar [ g ] = - 1
                    end = g
            j = end - 1
    return ans
K = 2
s = "000000"
print ( count ( K , s ) )

Index/key variables: g, i, j
Accumulator variables: ans
Iterator variables: g, i, j
Python program:
row = 6
col = 7
vis = [ [ 0 for i in range ( col + 1 ) ] for j in range ( row + 1 ) ]
id = 0
diameter = 0
length = 0
dx = [ - 1 , 1 , 0 , 0 ]
dy = [ 0 , 0 , - 1 , 1 ]
def dfs ( a , b , lis , x , y ) :
    global id , length , diameter
    vis [ a ] [ b ] = id
    length += 1
    if ( length > diameter ) :
        x = a
        y = b
        diameter = length
    for j in range ( 4 ) :
        cx = a + dx [ j ]
        cy = b + dy [ j ]
        if ( cx < 0 or cy < 0 or cx >= row or cy >= col or lis [ cx ] [ cy ] == 0 or vis [ cx ] [ cy ] ) :
            continue
        dfs ( cx , cy , lis , x , y )
    vis [ a ] [ b ] = 0
    length -= 1
    return x , y
def findMaximumLength ( lis ) :
    global id , length , diameter
    x = 0
    y = 0
    id += 1
    length = 0
    diameter = 0
    for i in range ( row ) :
        for j in range ( col ) :
            if ( lis [ i ] [ j ] != 0 ) :
                x , y = dfs ( i , j , lis , x , y )
                i = row
                break
    id += 1
    length = 0
    diameter = 0
    x , y = dfs ( x , y , lis , x , y )
    print ( diameter )
if __name__ == " _ _ main _ _ " :
    grid = [ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 1 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 1 , 1 , 1 , 0 ] , [ 0 , 0 , 0 , 1 , 0 , 0 , 0 ] ]
    findMaximumLength ( grid )

Index/key variables: a, b, cx, cy, i, j
Iterator variables: i, j
Python program:
def getSubsequence ( ar ) :
    N = len ( ar )
    ans = [ ]
    ans . append ( ar [ 0 ] )
    for i in range ( 1 , N - 1 ) :
        if ( ar [ i ] > ar [ i - 1 ] ) :
            if ( i < N - 1 and ar [ i ] <= ar [ i + 1 ] ) :
                continue
            else :
                ans . append ( ar [ i ] )
        else :
            if ( i < N - 1 and ar [ i + 1 ] < ar [ i ] ) :
                continue
            else :
                ans . append ( ar [ i ] )
    ans . append ( ar [ N - 1 ] )
    for it in ans :
        print ( it , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 3 , 5 ]
    getSubsequence ( arr )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i, it
Python program:
def dfs ( g , curMax , u , v ) :
    max1 = 0
    max2 = 0
    total = 0
    for i in range ( len ( g [ u ] ) ) :
        if ( g [ u ] [ i ] == v ) :
            continue
        total = max ( total , dfs ( g , curMax , g [ u ] [ i ] , u ) )
        if ( curMax [ 0 ] > max1 ) :
            max2 = max1
            max1 = curMax [ 0 ]
        else :
            max2 = max ( max2 , curMax [ 0 ] )
    total = max ( total , max1 + max2 )
    curMax [ 0 ] = max1 + 1
    return total
def maxProductOfTwoPaths ( g , N ) :
    res = - 999999999999
    path1 , path2 = None , None
    for i in range ( N ) :
        for j in range ( len ( g [ i ] ) ) :
            curMax = [ 0 ]
            path1 = dfs ( g , curMax , g [ i ] [ j ] , i )
            curMax = [ 0 ]
            path2 = dfs ( g , curMax , i , g [ i ] [ j ] )
            res = max ( res , path1 * path2 )
    return res
def addEdge ( g , u , v ) :
    g [ u ] . append ( v )
    g [ v ] . append ( u )
if __name__ == ' _ _ main _ _ ' :
    edges = [ [ 1 , 8 ] , [ 2 , 6 ] , [ 3 , 1 ] , [ 5 , 3 ] , [ 7 , 8 ] , [ 8 , 4 ] , [ 8 , 6 ] ]
    N = len ( edges )
    g = [ [ ] for i in range ( N + 2 ) ]
    for i in range ( N ) :
        addEdge ( g , edges [ i ] [ 0 ] , edges [ i ] [ 1 ] )
    print ( maxProductOfTwoPaths ( g , N ) )

Index/key variables: i, j, u, v
Iterator variables: i, j
Python program:
import sys
def MinimumValue ( arr , n ) :
    arr . sort ( ) ;
    minXor = sys . maxsize ;
    val = 0 ;
    for i in range ( 0 , n - 1 ) :
        val = arr [ i ] ^ arr [ i + 1 ] ;
        minXor = min ( minXor , val ) ;
    return minXor ;
if __name__ == ' _ _ main _ _ ' :
    N = 6 ;
    A = [ 12 , 3 , 14 , 5 , 9 , 8 ] ;
    print ( MinimumValue ( A , N ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def maxNormalSubstring ( P , Q , K , N ) :
    if ( K == 0 ) :
        return 0
    count = 0
    left , right = 0 , 0
    ans = 0
    while ( right < N ) :
        while ( right < N and count <= K ) :
            pos = ord ( P [ right ] ) - ord ( ' a ' )
            if ( Q [ pos ] == '0' ) :
                if ( count + 1 > K ) :
                    break
                else :
                    count += 1
            right += 1
            if ( count <= K ) :
                ans = max ( ans , right - left )
        while ( left < right ) :
            pos = ord ( P [ left ] ) - ord ( ' a ' )
            left += 1
            if ( Q [ pos ] == '0' ) :
                count -= 1
            if ( count < K ) :
                break
    return ans
if ( __name__ == " _ _ main _ _ " ) :
    P = " giraffe "
    Q = "01111001111111111011111111"
    K = 2
    N = len ( P )
    print ( maxNormalSubstring ( P , Q , K , N ) )

Index/key variables: left, pos, right
Accumulator variables: count
Python program:
def countOperations ( arr , n ) :
    count = 0 ;
    for i in range ( n - 1 ) :
        if ( arr [ i ] & 1 ) :
            arr [ i ] += 1 ;
            arr [ i + 1 ] += 1 ;
            count += 2 ;
    for i in range ( n ) :
        if ( arr [ i ] & 1 ) :
            return - 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 4 , 5 , 6 ] ;
    n = len ( arr ) ;
    print ( countOperations ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def countPairs ( arr , k ) :
    arr . sort ( )
    pair = 0
    index = 0
    while ( index < len ( arr ) - 1 ) :
        if arr [ index + 1 ] - arr [ index ] <= k :
            pair += 1
            index += 2
        else :
            index += 1
    return pair
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 4 , 3 , 7 , 5 ]
    k = 2
    count = countPairs ( arr , k )
    print ( count )

Index/key variables: index
Accumulator variables: pair
Python program:
def maxProfit ( profitA , profitB , n ) :
    preSum = [ 0 ] * n ;
    preSum [ 0 ] = profitA [ 0 ] ;
    for i in range ( 1 , n ) :
        preSum [ i ] = preSum [ i - 1 ] + profitA [ i ] ;
    suffSum = [ 0 ] * n ;
    suffSum [ n - 1 ] = profitB [ n - 1 ] ;
    for i in range ( n - 2 , - 1 , - 1 ) :
        suffSum [ i ] = suffSum [ i + 1 ] + profitB [ i ] ;
    res = preSum [ n - 1 ] ;
    for i in range ( 1 , n - 1 ) :
        res = max ( res , preSum [ i ] + suffSum [ i + 1 ] ) ;
    res = max ( res , suffSum [ 0 ] ) ;
    return res ;
if __name__ == " _ _ main _ _ " :
    profitA = [ 2 , 3 , 2 ] ;
    profitB = [ 10 , 30 , 40 ] ;
    n = len ( profitA ) ;
    print ( maxProfit ( profitA , profitB , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def minEdges ( v , n ) :
    adj = dict . fromkeys ( range ( n + 1 ) ) ;
    for i in range ( n + 1 ) :
        adj [ i ] = [ 0 ] * ( n + 1 ) ;
    for i in range ( len ( v ) ) :
        adj [ v [ i ] [ 0 ] ] [ v [ i ] [ 1 ] ] = 1 ;
        adj [ v [ i ] [ 1 ] ] [ v [ i ] [ 0 ] ] = 1 ;
    edgesNeeded = 3 ;
    for i in range ( 1 , n + 1 ) :
        for j in range ( i + 1 , n + 1 ) :
            for k in range ( j + 1 , n + 1 ) :
                if ( adj [ i ] [ j ] and adj [ j ] [ k ] and adj [ k ] [ i ] ) :
                    return 0 ;
                if ( not ( adj [ i ] [ j ] or adj [ j ] [ k ] or adj [ k ] [ i ] ) ) :
                    edgesNeeded = min ( edgesNeeded , 3 ) ;
                else :
                    if ( ( adj [ i ] [ j ] and adj [ j ] [ k ] ) or ( adj [ j ] [ k ] and adj [ k ] [ i ] ) or ( adj [ k ] [ i ] and adj [ i ] [ j ] ) ) :
                        edgesNeeded = 1 ;
                    else :
                        edgesNeeded = min ( edgesNeeded , 2 ) ;
    return edgesNeeded ;
if __name__ == " _ _ main _ _ " :
    n = 3 ;
    v = [ [ 1 , 2 ] , [ 1 , 3 ] ] ;
    print ( minEdges ( v , n ) ) ;

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def LongestXorSubsequence ( arr , n ) :
    v = [ ]
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            v . append ( [ ( arr [ i ] ^ arr [ j ] ) , ( i , j ) ] )
    v . sort ( )
    dp = [ 1 for x in range ( 88 ) ]
    for a , b in v :
        dp [ b [ 1 ] ] = max ( dp [ b [ 1 ] ] , 1 + dp [ b [ 0 ] ] )
    ans = 1
    for i in range ( 0 , n ) :
        ans = max ( ans , dp [ i ] )
    return ans
arr = [ 2 , 12 , 6 , 7 , 13 , 14 , 8 , 6 ]
n = len ( arr )
print ( LongestXorSubsequence ( arr , n ) )

Index/key variables: i, j
Accumulator variables: v
Iterator variables: a, b, i, j
Python program:
def dfs ( u , parent , totalSum , edge , subtree , res ) :
    Sum = subtree [ u ]
    for i in range ( len ( edge [ u ] ) ) :
        v = edge [ u ] [ i ]
        if ( v != parent ) :
            dfs ( v , u , totalSum , edge , subtree , res )
            Sum += subtree [ v ]
    subtree [ u ] = Sum
    if ( u != 0 and abs ( totalSum - 2 * Sum ) < res [ 0 ] ) :
        res [ 0 ] = abs ( totalSum - 2 * Sum )
def getMinSubtreeSumDifference ( vertex , edges , N ) :
    totalSum = 0
    subtree = [ None ] * N
    for i in range ( N ) :
        subtree [ i ] = vertex [ i ]
        totalSum += vertex [ i ]
    edge = [ [ ] for i in range ( N ) ]
    for i in range ( N - 1 ) :
        edge [ edges [ i ] [ 0 ] ] . append ( edges [ i ] [ 1 ] )
        edge [ edges [ i ] [ 1 ] ] . append ( edges [ i ] [ 0 ] )
    res = [ 999999999999 ]
    dfs ( 0 , - 1 , totalSum , edge , subtree , res )
    return res [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    vertex = [ 4 , 2 , 1 , 6 , 3 , 5 , 2 ]
    edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 0 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] , [ 3 , 6 ] ]
    N = len ( vertex )
    print ( getMinSubtreeSumDifference ( vertex , edges , N ) )

Index/key variables: i, u, v
Accumulator variables: Sum, totalSum
Iterator variables: i
Python program:
import math
def canBePicked ( digits , num ) :
    copyDigits = [ ] ;
    for i in range ( len ( digits ) ) :
        copyDigits . append ( digits [ i ] ) ;
    while ( num > 0 ) :
        digit = num % 10 ;
        if ( copyDigits [ digit ] == 0 ) :
            return False ;
        else :
            copyDigits [ digit ] -= 1 ;
        num = math . floor ( num / 10 ) ;
    return True ;
def countAlphabets ( n ) :
    count = 0 ;
    digits = [ 0 ] * 10 ;
    while ( n > 0 ) :
        digit = n % 10 ;
        digits [ digit ] += 1 ;
        n = math . floor ( n / 10 ) ;
    for i in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        if ( canBePicked ( digits , i ) ) :
            count += 1 ;
    for i in range ( ord ( ' A ' ) , ord ( ' Z ' ) + 1 ) :
        if ( canBePicked ( digits , i ) ) :
            count += 1 ;
    return count ;
n = 1623455078 ;
print ( countAlphabets ( n ) ) ;

Index/key variables: digit, i
Accumulator variables: copyDigits, count
Iterator variables: i
Python program:
def greatestKBits ( X , K ) :
    set_bit_count = bin ( X ) . count ( '1' )
    if ( set_bit_count <= K ) :
        return X
    diff = set_bit_count - K
    for i in range ( 0 , diff , 1 ) :
        X &= ( X - 1 )
    return X
if __name__ == ' _ _ main _ _ ' :
    X = 21
    K = 2
    print ( greatestKBits ( X , K ) )

Accumulator variables: X
Iterator variables: i
Python program:
class Graph :
    def __init__ ( self , V ) :
        self . V = V
        self . adj = [ [ ] for i in range ( V ) ]
    def addEdge ( self , s , d ) :
        self . adj [ s ] . append ( d )
        self . adj [ d ] . append ( s )
    def BFS ( self , s , d ) :
        if ( s == d ) :
            return 0
        level = [ - 1 ] * self . V
        queue = [ ]
        level [ s ] = 0
        queue . append ( s )
        while ( len ( queue ) != 0 ) :
            s = queue . pop ( )
            i = 0
            while i < len ( self . adj [ s ] ) :
                if ( level [ self . adj [ s ] [ i ] ] < 0 or level [ self . adj [ s ] [ i ] ] > level [ s ] + 1 ) :
                    level [ self . adj [ s ] [ i ] ] = level [ s ] + 1
                    queue . append ( self . adj [ s ] [ i ] )
                i += 1
        return level [ d ]
def isSafe ( i , j , M ) :
    global N
    if ( ( i < 0 or i >= N ) or ( j < 0 or j >= N ) or M [ i ] [ j ] == 0 ) :
        return False
    return True
def MinimumPath ( M ) :
    global N
    s , d = None , None
    V = N * N + 2
    g = Graph ( V )
    k = 1
    for i in range ( N ) :
        for j in range ( N ) :
            if ( M [ i ] [ j ] != 0 ) :
                if ( isSafe ( i , j + 1 , M ) ) :
                    g . addEdge ( k , k + 1 )
                if ( isSafe ( i , j - 1 , M ) ) :
                    g . addEdge ( k , k - 1 )
                if ( j < N - 1 and isSafe ( i + 1 , j , M ) ) :
                    g . addEdge ( k , k + N )
                if ( i > 0 and isSafe ( i - 1 , j , M ) ) :
                    g . addEdge ( k , k - N )
            if ( M [ i ] [ j ] == 1 ) :
                s = k
            if ( M [ i ] [ j ] == 2 ) :
                d = k
            k += 1
    return g . BFS ( s , d )
N = 4
M = [ [ 3 , 3 , 1 , 0 ] , [ 3 , 0 , 3 , 3 ] , [ 2 , 3 , 0 , 3 ] , [ 0 , 3 , 3 , 3 ] ]
print ( MinimumPath ( M ) )

Index/key variables: d, i, j, s
Accumulator variables: k, queue
Iterator variables: i, j
Class/struct names: Graph
Python program:
def split ( x , n ) :
    if ( x < n ) :
        print ( - 1 )
    elif ( x % n == 0 ) :
        for i in range ( n ) :
            print ( x // n , end = " ▁ " )
    else :
        zp = n - ( x % n )
        pp = x // n
        for i in range ( n ) :
            if ( i >= zp ) :
                print ( pp + 1 , end = " ▁ " )
            else :
                print ( pp , end = " ▁ " )
x = 5
n = 3
split ( x , n )

Iterator variables: i
Python program:
s = " ABCdcba "
u = [ 0 ] * 26
n = len ( s )
for i in range ( n ) :
    if ( s [ i ] . isupper ( ) ) :
        u [ ord ( s [ i ] ) - 65 ] += 1
    else :
        u [ ord ( s [ i ] ) - 97 ] -= 1
fl = True
po = 0
ne = 0
for i in range ( 26 ) :
    if ( u [ i ] > 0 ) :
        po += u [ i ]
    if ( u [ i ] < 0 ) :
        ne += u [ i ]
if ( po == 0 and ne == 0 ) :
    print ( " YES " )
elif ( po == 1 and ne == 0 ) :
    print ( " YES " )
elif ( po == 0 and ne == - 1 ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Accumulator variables: ne, po
Iterator variables: i
Boolean variables: fl
Python program:
class pair :
    first = 0
    second = 0
    def __init__ ( self , a , b ) :
        self . first = a
        self . second = b
def solve ( v , n ) :
    ans = 0 ; ul = 0 ; ll = 0 ;
    ll = v [ 0 ] . first
    ul = v [ 0 ] . second
    ans = 0
    for i in range ( 1 , n ) :
        if ( v [ i ] . first <= ul and v [ i ] . first >= ll ) or ( v [ i ] . second >= ll and v [ i ] . second <= ul ) :
            if v [ i ] . first > ll :
                ll = v [ i ] . first
            if v [ i ] . second < ul :
                ul = v [ i ] . second ;
        elif v [ i ] . first > ul :
            ans += abs ( ul - v [ i ] . first )
            ul = v [ i ] . first
            ll = v [ i ] . first
        elif v [ i ] . second < ll :
            ans += abs ( ll - v [ i ] . second ) ;
            ul = v [ i ] . second ;
            ll = v [ i ] . second ;
    return ans
v = [ pair ( 1 , 3 ) , pair ( 2 , 5 ) , pair ( 6 , 8 ) , pair ( 1 , 2 ) , pair ( 2 , 3 ) ]
n = len ( v )
print ( solve ( v , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Class/struct names: pair
Python program:
import math as mt
def preProcess ( n ) :
    preProcessedCubes = list ( )
    for i in range ( 1 , mt . ceil ( n ** ( 1. / 3. ) ) ) :
        iThCube = i ** 3
        cubeString = str ( iThCube )
        preProcessedCubes . append ( cubeString )
    return preProcessedCubes
def findLargestCubeUtil ( num , preProcessedCubes ) :
    preProcessedCubes = preProcessedCubes [ : : - 1 ]
    totalCubes = len ( preProcessedCubes )
    for i in range ( totalCubes ) :
        currCube = preProcessedCubes [ i ]
        digitsInCube = len ( currCube )
        index = 0
        digitsInNumber = len ( num )
        for j in range ( digitsInNumber ) :
            if ( num [ j ] == currCube [ index ] ) :
                index += 1
            if ( digitsInCube == index ) :
                return currCube
    return " Not ▁ Possible "
def findLargestCube ( n ) :
    preProcessedCubes = preProcess ( n )
    num = str ( n )
    ans = findLargestCubeUtil ( num , preProcessedCubes )
    print ( " Largest ▁ Cube ▁ that ▁ can ▁ be ▁ formed ▁ from " , n , " is " , ans )
n = 4125
findLargestCube ( n )
n = 876
findLargestCube ( n )

Index/key variables: i, index, j
Accumulator variables: preProcessedCubes
Iterator variables: i, j