dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def maxSumArrangement ( A , R , N , M ) :
    count = [ 0 for i in range ( N ) ]
    for i in range ( M ) :
        l = R [ i ] [ 0 ]
        r = R [ i ] [ 1 ] + 1
        l = l - 1
        r = r - 1
        count [ l ] = count [ l ] + 1
        if ( r < N ) :
            count [ r ] = count [ r ] - 1
    for i in range ( 1 , N ) :
        count [ i ] = count [ i ] + count [ i - 1 ]
    ans = 0
    count . sort ( )
    A . sort ( )
    for i in range ( N - 1 , - 1 , - 1 ) :
        ans = ans + A [ i ] * count [ i ]
    return ans
A = [ 2 , 6 , 10 , 1 , 5 , 6 ]
R = [ [ 1 , 3 ] , [ 4 , 6 ] , [ 3 , 4 ] ]
N = len ( A )
M = len ( R )
print ( maxSumArrangement ( A , R , N , M ) )

Index/key variables: i, l, r
Iterator variables: i
Python program:
import math
def findFactors ( n , k ) :
    factors = [ ]
    sqt = ( int ) ( math . sqrt ( k ) )
    for i in range ( 1 , sqt ) :
        if ( k % i == 0 ) :
            if ( k // i == i and i <= n ) :
                factors . append ( i )
            else :
                if ( i <= n ) :
                    factors . append ( i )
                if ( k // i <= n ) :
                    factors . append ( k // i )
    return factors
def findDigitSum ( a ) :
    for i in range ( len ( a ) ) :
        c = 0
        while ( a [ i ] > 0 ) :
            c += a [ i ] % 10
            a [ i ] = a [ i ] // 10
        a [ i ] = c
    return a
def findMMaxDistinctDigitSum ( distinctDigitSum , m ) :
    sum = 0
    i = len ( distinctDigitSum ) - 1
    while ( i >= 0 and m > 0 ) :
        sum += distinctDigitSum [ i ]
        i -= 1
        m -= 1
    return sum
def findDistinctMnumbers ( n , k , m ) :
    factors = findFactors ( n , k )
    digitSum = findDigitSum ( factors )
    digitSum . sort ( )
    ip = list ( set ( digitSum ) )
    return findMMaxDistinctDigitSum ( ip , m )
if __name__ == " _ _ main _ _ " :
    n = 100
    k = 80
    m = 4
    print ( findDistinctMnumbers ( n , k , m ) )

Index/key variables: i
Accumulator variables: c, factors, m, sum
Iterator variables: i
Python program:
objects = [ ]
hash = dict ( )
def partition ( l , r ) :
    global objects , hash
    j = l - 1
    last_element = hash [ objects [ r ] ]
    for i in range ( l , r ) :
        if ( hash [ objects [ i ] ] <= last_element ) :
            j += 1
            ( objects [ i ] , objects [ j ] ) = ( objects [ j ] , objects [ i ] )
    j += 1
    ( objects [ j ] , objects [ r ] ) = ( objects [ r ] , objects [ j ] )
    return j
def quicksort ( l , r ) :
    if ( l < r ) :
        mid = partition ( l , r )
        quicksort ( l , mid - 1 )
        quicksort ( mid + 1 , r )
def sortObj ( ) :
    global objects , hash
    hash [ " blue " ] = 1
    hash [ " red " ] = 2
    hash [ " yellow " ] = 3
    quicksort ( 0 , int ( len ( objects ) - 1 ) )
    for i in objects :
        print ( i , end = " ▁ " )
objects = [ " red " , " blue " , " red " , " yellow " , " blue " ]
sortObj ( )

Index/key variables: i, j, r
Iterator variables: i
Python program:
def productOfDigit ( n ) :
    product = 1 ;
    while ( n > 0 ) :
        product *= ( n % 10 ) ;
        n = n // 10 ;
    return product ;
def sortArr ( arr , n ) :
    vp = [ ] ;
    for i in range ( n ) :
        vp . append ( ( productOfDigit ( arr [ i ] ) , arr [ i ] ) ) ;
    vp . sort ( ) ;
    for i in range ( len ( vp ) ) :
        print ( vp [ i ] [ 1 ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 10 , 102 , 31 , 15 ] ;
    n = len ( arr ) ;
    sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: product, vp
Iterator variables: i
Python program:
def maxWater ( height , n ) :
    maximum = 0 ;
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            current = min ( height [ i ] , height [ j ] ) * ( j - i - 1 ) ;
            maximum = max ( maximum , current ) ;
    return maximum ;
if __name__ == " _ _ main _ _ " :
    height = [ 2 , 1 , 3 , 4 , 6 , 5 ] ;
    n = len ( height ) ;
    print ( maxWater ( height , n ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
from math import sqrt
def checkDivisors ( a , n ) :
    X = max ( a )
    b = [ ]
    for i in range ( 1 , int ( sqrt ( X ) ) + 1 ) :
        if ( X % i == 0 ) :
            b . append ( i )
            if ( X // i != i ) :
                b . append ( X // i )
    if ( len ( b ) != n ) :
        return False
    a . sort ( reverse = False )
    b . sort ( reverse = False )
    for i in range ( n ) :
        if ( b [ i ] != a [ i ] ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    arr = [ 8 , 1 , 2 , 12 , 48 , 6 , 4 , 24 , 16 , 3 ]
    N = len ( arr )
    if ( checkDivisors ( arr , N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: b
Iterator variables: i
Python program:
def findKthNode ( u , v , n , val , V , k ) :
    g = [ [ ] for i in range ( V ) ]
    for i in range ( 0 , n ) :
        g [ u [ i ] ] . append ( ( val [ v [ i ] ] , v [ i ] ) )
        g [ v [ i ] ] . append ( ( val [ u [ i ] ] , u [ i ] ) )
    for i in range ( 0 , V ) :
        if len ( g [ i ] ) > 0 :
            g [ i ] . sort ( )
        if k <= len ( g [ i ] ) :
            print ( g [ i ] [ - k ] [ 1 ] )
        else :
            print ( " - 1" )
    return
if __name__ == " _ _ main _ _ " :
    V = 3
    val = [ 2 , 4 , 3 ]
    u = [ 0 , 0 , 1 ]
    v = [ 2 , 1 , 2 ]
    n , k = len ( u ) , 2
    findKthNode ( u , v , n , val , V , k )

Index/key variables: i
Iterator variables: i
Python program:
def findSquare ( n ) :
    points = [ [ 1 , 2 ] , [ - 3 , 4 ] , [ 1 , 78 ] , [ - 3 , - 7 ] ]
    a = [ None ] * n
    for i in range ( 0 , n ) :
        x = points [ i ] [ 0 ]
        y = points [ i ] [ 1 ]
        a [ i ] = max ( abs ( x ) , abs ( y ) )
    a . sort ( )
    index = n // 2 - 1
    print ( " Minimum ▁ M ▁ required ▁ is : " , a [ index ] )
if __name__ == " _ _ main _ _ " :
    N = 4
    findSquare ( N )

Index/key variables: i, index
Iterator variables: i
Python program:
def findpath ( graph , n ) :
    numofadj = [ ]
    for i in range ( n ) :
        numofadj . append ( sum ( graph [ i ] ) )
    startpoint , numofodd = 0 , 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( numofadj [ i ] % 2 == 1 ) :
            numofodd += 1
            startpoint = i
    if ( numofodd > 2 ) :
        print ( " No ▁ Solution " )
        return
    stack = [ ]
    path = [ ]
    cur = startpoint
    while ( len ( stack ) > 0 or sum ( graph [ cur ] ) != 0 ) :
        if ( sum ( graph [ cur ] ) == 0 ) :
            path . append ( cur )
            cur = stack [ - 1 ]
            del stack [ - 1 ]
        else :
            for i in range ( n ) :
                if ( graph [ cur ] [ i ] == 1 ) :
                    stack . append ( cur )
                    graph [ cur ] [ i ] = 0
                    graph [ i ] [ cur ] = 0
                    cur = i
                    break
    for ele in path :
        print ( ele , end = " ▁ - > ▁ " )
    print ( cur )
if __name__ == ' _ _ main _ _ ' :
    graph1 = [ [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 0 , 0 ] , [ 1 , 0 , 0 , 0 , 0 ] ]
    n = len ( graph1 )
    findpath ( graph1 , n )
    graph2 = [ [ 0 , 1 , 0 , 1 , 1 ] , [ 1 , 0 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 1 , 1 ] , [ 1 , 1 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 0 , 0 ] ]
    n = len ( graph2 )
    findpath ( graph2 , n )
    graph3 = [ [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 1 ] , [ 0 , 1 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 0 , 1 ] , [ 1 , 1 , 0 , 1 , 0 ] ]
    n = len ( graph3 )
    findpath ( graph3 , n )

Index/key variables: cur, i
Accumulator variables: numofadj, numofodd, path, stack
Iterator variables: ele, i
Python program:
def minSum ( arr , n ) :
    arr . sort ( ) ;
    x = arr [ n // 2 ] ;
    sum = 0 ;
    for i in range ( n ) :
        sum += abs ( arr [ i ] - x ) ;
    return sum ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 9 , 3 , 6 ] ;
    n = len ( arr )
    print ( minSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def odd_even ( n ) :
    odd_indexes = [ ]
    even_indexes = [ ]
    for i in range ( len ( n ) ) :
        if i % 2 == 0 : odd_indexes . append ( n [ i ] )
        else : even_indexes . append ( n [ i ] )
    for i in sorted ( odd_indexes ) : print ( i , end = " ▁ " )
    for i in sorted ( even_indexes ) : print ( i , end = " ▁ " )
n = [ 3 , 2 , 7 , 6 , 8 ]
odd_even ( n )

Index/key variables: i
Accumulator variables: even_indexes, odd_indexes
Iterator variables: i
Python program:
def countPairs ( a , n ) :
    mp = dict . fromkeys ( a , 0 )
    for i in range ( n ) :
        mp [ a [ i ] ] += 1
    a . sort ( reverse = True )
    count = 0
    for i in range ( n ) :
        if ( mp [ a [ i ] ] < 1 ) :
            continue
        cur = 1
        while ( cur <= a [ i ] ) :
            cur = cur << 1
        if ( cur - a [ i ] in mp . keys ( ) ) :
            if ( cur - a [ i ] == a [ i ] and mp [ a [ i ] ] == 1 ) :
                continue
            count += 1
            mp [ cur - a [ i ] ] -= 1
            mp [ a [ i ] ] -= 1
    return count
if __name__ == " _ _ main _ _ " :
    a = [ 3 , 11 , 14 , 5 , 13 ]
    n = len ( a )
    print ( countPairs ( a , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def countMaxPos ( arr ) :
    n = len ( arr )
    Map = { }
    for x in arr :
        if x in Map :
            Map [ x ] += 1
        else :
            Map [ x ] = 1
    max_freq = 0
    for entry in Map :
        max_freq = max ( max_freq , Map [ entry ] )
    return n - max_freq
if __name__ == " _ _ main _ _ " :
    arr = [ 20 , 30 , 10 , 50 , 40 ]
    print ( countMaxPos ( arr ) )

Index/key variables: entry, x
Iterator variables: entry, x
Python program:
def anyPermutation ( A , B , n ) :
    Ap , Bp = [ ] , [ ]
    for i in range ( 0 , n ) :
        Ap . append ( [ A [ i ] , i ] )
    for i in range ( 0 , n ) :
        Bp . append ( [ B [ i ] , i ] )
    Ap . sort ( )
    Bp . sort ( )
    i , j = 0 , 0 ,
    ans = [ 0 ] * n
    remain = [ ]
    while i < n and j < n :
        if Ap [ i ] [ 0 ] > Bp [ j ] [ 0 ] :
            ans [ Bp [ j ] [ 1 ] ] = Ap [ i ] [ 0 ]
            i += 1
            j += 1
        else :
            remain . append ( i )
            i += 1
    j = 0
    for i in range ( 0 , n ) :
        if ans [ i ] == 0 :
            ans [ i ] = Ap [ remain [ j ] ] [ 0 ]
            j += 1
    for i in range ( 0 , n ) :
        print ( ans [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    A = [ 12 , 24 , 8 , 32 ]
    B = [ 13 , 25 , 32 , 11 ]
    n = len ( A )
    anyPermutation ( A , B , n )

Index/key variables: i, j
Accumulator variables: Ap, Bp, remain
Iterator variables: i
Python program:
def sortMultiples ( arr , n , x ) :
    v = [ ]
    for i in range ( 0 , n , 1 ) :
        if ( arr [ i ] % x == 0 ) :
            v . append ( arr [ i ] )
    v . sort ( reverse = False )
    j = 0
    for i in range ( 0 , n , 1 ) :
        if ( arr [ i ] % x == 0 ) :
            arr [ i ] = v [ j ]
            j += 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 125 , 3 , 15 , 6 , 100 , 5 ]
    x = 5
    n = len ( arr )
    sortMultiples ( arr , n , x )
    for i in range ( 0 , n , 1 ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Accumulator variables: v
Iterator variables: i
Python program:
def absSumDidd ( a , n ) :
    a . sort ( )
    midValue = a [ ( int ) ( n // 2 ) ]
    sum = 0
    for i in range ( n ) :
        sum = sum + abs ( a [ i ] - midValue )
    return sum
arr = [ 5 , 11 , 14 , 10 , 17 , 15 ]
n = len ( arr )
print ( absSumDidd ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def printRLE ( s ) :
    i = 0
    while ( i < len ( s ) - 1 ) :
        count = 1
        while s [ i ] == s [ i + 1 ] :
            i += 1
            count += 1
            if i + 1 == len ( s ) :
                break
        print ( str ( s [ i ] ) + str ( count ) , end = " ▁ " )
        i += 1
    print ( )
if __name__ == " _ _ main _ _ " :
    printRLE ( " GeeeEEKKKss " )
    printRLE ( " cccc0ddEEE " )

Index/key variables: i
Accumulator variables: count
Python program:
M = 26
def dfs ( g , u , visit ) :
    visit [ u ] = True
    for i in range ( len ( g [ u ] ) ) :
        if ( not visit [ g [ u ] [ i ] ] ) :
            dfs ( g , g [ u ] [ i ] , visit )
def isConnected ( g , mark , s ) :
    visit = [ False for i in range ( M ) ]
    dfs ( g , s , visit )
    for i in range ( M ) :
        if ( mark [ i ] and ( not visit [ i ] ) ) :
            return False
    return True
def possibleOrderAmongString ( arr , N ) :
    g = { }
    mark = [ False for i in range ( M ) ]
    In = [ 0 for i in range ( M ) ]
    out = [ 0 for i in range ( M ) ]
    for i in range ( N ) :
        f = ( ord ( arr [ i ] [ 0 ] ) - ord ( ' a ' ) )
        l = ( ord ( arr [ i ] [ - 1 ] ) - ord ( ' a ' ) )
        mark [ f ] = True
        mark [ l ] = True
        In [ l ] += 1
        out [ f ] += 1
        if f not in g :
            g [ f ] = [ ]
        g [ f ] . append ( l )
    for i in range ( M ) :
        if ( In [ i ] != out [ i ] ) :
            return False
    return isConnected ( g , mark , ord ( arr [ 0 ] [ 0 ] ) - ord ( ' a ' ) )
arr = [ " ab " , " bc " , " cd " , " de " , " ed " , " da " ]
N = len ( arr )
if ( possibleOrderAmongString ( arr , N ) == False ) :
    print ( " Ordering ▁ not ▁ possible " )
else :
    print ( " Ordering ▁ is ▁ possible " )

Index/key variables: f, i, l, u
Iterator variables: i
Python program:
def root ( arr , i ) :
    while ( arr [ i ] != i ) :
        arr [ i ] = arr [ arr [ i ] ]
        i = arr [ i ]
    return i
def weighted_union ( arr , rank , a , b ) :
    root_a = root ( arr , a )
    root_b = root ( arr , b )
    if ( rank [ root_a ] < rank [ root_b ] ) :
        arr [ root_a ] = arr [ root_b ]
        rank [ root_b ] += rank [ root_a ]
    else :
        arr [ root_b ] = arr [ root_a ]
        rank [ root_a ] += rank [ root_b ]
def areSame ( arr , a , b ) :
    return ( root ( arr , a ) == root ( arr , b ) )
def query ( type , x , y , arr , rank ) :
    if ( type == 1 ) :
        if ( areSame ( arr , x , y ) == True ) :
            print ( " Yes " )
        else :
            print ( " No " )
    elif ( type == 2 ) :
        if ( areSame ( arr , x , y ) == False ) :
            weighted_union ( arr , rank , x , y )
if __name__ == ' _ _ main _ _ ' :
    n = 7
    arr = [ None ] * n
    rank = [ None ] * n
    for i in range ( n ) :
        arr [ i ] = i
        rank [ i ] = 1
    q = 11
    query ( 1 , 0 , 1 , arr , rank )
    query ( 2 , 0 , 1 , arr , rank )
    query ( 2 , 1 , 2 , arr , rank )
    query ( 1 , 0 , 2 , arr , rank )
    query ( 2 , 0 , 2 , arr , rank )
    query ( 2 , 2 , 3 , arr , rank )
    query ( 2 , 3 , 4 , arr , rank )
    query ( 1 , 0 , 5 , arr , rank )
    query ( 2 , 4 , 5 , arr , rank )
    query ( 2 , 5 , 6 , arr , rank )
    query ( 1 , 2 , 6 , arr , rank )

Index/key variables: i, root_a, root_b
Iterator variables: i
Python program:
def bpm ( table , u , seen , matchR ) :
    global M , N
    for v in range ( N ) :
        if ( table [ u ] [ v ] > 0 and not seen [ v ] ) :
            seen [ v ] = True
            if ( matchR [ v ] < 0 or bpm ( table , matchR [ v ] , seen , matchR ) ) :
                matchR [ v ] = u
                return True
    return False
def maxBPM ( table ) :
    global M , N
    matchR = [ - 1 ] * N
    result = 0
    for u in range ( M ) :
        seen = [ 0 ] * N
        if ( bpm ( table , u , seen , matchR ) ) :
            result += 1
    print ( " The ▁ number ▁ of ▁ maximum ▁ packets ▁ sent " , " in ▁ the ▁ time ▁ slot ▁ is " , result )
    for x in range ( N ) :
        if ( matchR [ x ] + 1 != 0 ) :
            print ( " T " , matchR [ x ] + 1 , " - > ▁ R " , x + 1 )
    return result
M = 3
N = 4
table = [ [ 0 , 2 , 0 ] , [ 3 , 0 , 1 ] , [ 2 , 4 , 0 ] ]
max_flow = maxBPM ( table )

Index/key variables: u, v, x
Accumulator variables: result
Iterator variables: u, v, x
Python program:
if ( inMST [ v ] == False and key [ v ] > weight ) :
    key [ v ] = weight
    pq . append ( [ key [ v ] , v ] )
    parent [ v ] = u

Index/key variables: v
Python program:
def addEdge ( adj , u , v , wt ) :
    adj [ u ] . append ( [ v , wt ] )
    adj [ v ] . append ( [ u , wt ] )
    return adj
def printGraph ( adj , V ) :
    v , w = 0 , 0
    for u in range ( V ) :
        print ( " Node " , u , " makes ▁ an ▁ edge ▁ with " )
        for it in adj [ u ] :
            v = it [ 0 ]
            w = it [ 1 ]
            print ( " TABSYMBOL Node " , v , " with ▁ edge ▁ weight ▁ = " , w )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    V = 5
    adj = [ [ ] for i in range ( V ) ]
    adj = addEdge ( adj , 0 , 1 , 10 )
    adj = addEdge ( adj , 0 , 4 , 20 )
    adj = addEdge ( adj , 1 , 2 , 30 )
    adj = addEdge ( adj , 1 , 3 , 40 )
    adj = addEdge ( adj , 1 , 4 , 50 )
    adj = addEdge ( adj , 2 , 3 , 60 )
    adj = addEdge ( adj , 3 , 4 , 70 )
    printGraph ( adj , V )

Index/key variables: u, v
Iterator variables: it, u
Python program:
def maxindex ( dist , n ) :
    mi = 0
    for i in range ( n ) :
        if ( dist [ i ] > dist [ mi ] ) :
            mi = i
    return mi
def selectKcities ( n , weights , k ) :
    dist = [ 0 ] * n
    centers = [ ]
    for i in range ( n ) :
        dist [ i ] = 10 ** 9
    max = 0
    for i in range ( k ) :
        centers . append ( max )
        for j in range ( n ) :
            dist [ j ] = min ( dist [ j ] , weights [ max ] [ j ] )
        max = maxindex ( dist , n )
    print ( dist [ max ] )
    for i in centers :
        print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    n = 4
    weights = [ [ 0 , 4 , 8 , 5 ] , [ 4 , 0 , 10 , 7 ] , [ 8 , 10 , 0 , 9 ] , [ 5 , 7 , 9 , 0 ] ]
    k = 2
    selectKcities ( n , weights , k )

Index/key variables: i, j, max, mi
Accumulator variables: centers
Iterator variables: i, j
Python program:
def printCircuit ( adj ) :
    edge_count = dict ( )
    for i in range ( len ( adj ) ) :
        edge_count [ i ] = len ( adj [ i ] )
    if len ( adj ) == 0 :
        return
    curr_path = [ ]
    circuit = [ ]
    curr_path . append ( 0 )
    curr_v = 0
    while len ( curr_path ) :
        if edge_count [ curr_v ] :
            curr_path . append ( curr_v )
            next_v = adj [ curr_v ] [ - 1 ]
            edge_count [ curr_v ] -= 1
            adj [ curr_v ] . pop ( )
            curr_v = next_v
        else :
            circuit . append ( curr_v )
            curr_v = curr_path [ - 1 ]
            curr_path . pop ( )
    for i in range ( len ( circuit ) - 1 , - 1 , - 1 ) :
        print ( circuit [ i ] , end = " " )
        if i :
            print ( " ▁ - > ▁ " , end = " " )
if __name__ == " _ _ main _ _ " :
    adj1 = [ 0 ] * 3
    for i in range ( 3 ) :
        adj1 [ i ] = [ ]
    adj1 [ 0 ] . append ( 1 )
    adj1 [ 1 ] . append ( 2 )
    adj1 [ 2 ] . append ( 0 )
    printCircuit ( adj1 )
    print ( )
    adj2 = [ 0 ] * 7
    for i in range ( 7 ) :
        adj2 [ i ] = [ ]
    adj2 [ 0 ] . append ( 1 )
    adj2 [ 0 ] . append ( 6 )
    adj2 [ 1 ] . append ( 2 )
    adj2 [ 2 ] . append ( 0 )
    adj2 [ 2 ] . append ( 3 )
    adj2 [ 3 ] . append ( 4 )
    adj2 [ 4 ] . append ( 2 )
    adj2 [ 4 ] . append ( 5 )
    adj2 [ 5 ] . append ( 0 )
    adj2 [ 6 ] . append ( 4 )
    printCircuit ( adj2 )
    print ( )

Index/key variables: curr_v, i
Accumulator variables: circuit, curr_path
Iterator variables: i
Python program:
V = 4
def multiply ( A , B , C ) :
    global V
    for i in range ( V ) :
        for j in range ( V ) :
            C [ i ] [ j ] = 0
            for k in range ( V ) :
                C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ]
def getTrace ( graph ) :
    global V
    trace = 0
    for i in range ( V ) :
        trace += graph [ i ] [ i ]
    return trace
def triangleInGraph ( graph ) :
    global V
    aux2 = [ [ None ] * V for i in range ( V ) ]
    aux3 = [ [ None ] * V for i in range ( V ) ]
    for i in range ( V ) :
        for j in range ( V ) :
            aux2 [ i ] [ j ] = aux3 [ i ] [ j ] = 0
    multiply ( graph , graph , aux2 )
    multiply ( graph , aux2 , aux3 )
    trace = getTrace ( aux3 )
    return trace // 6
graph = [ [ 0 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 1 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] ]
print ( " Total ▁ number ▁ of ▁ Triangle ▁ in ▁ Graph ▁ : " , triangleInGraph ( graph ) )

Index/key variables: i, j, k
Accumulator variables: trace
Iterator variables: i, j, k
Python program:
fwd = [ 0 ] * 100
bwd = [ 0 ] * 100
def preProcess ( a , b ) :
    n = len ( a )
    j = 0
    for i in range ( 1 , len ( a ) + 1 ) :
        if j < len ( b ) and a [ i - 1 ] == b [ j ] :
            j += 1
        fwd [ i ] = j
    j = 0
    for i in range ( len ( a ) , 0 , - 1 ) :
        if ( j < len ( b ) and a [ i - 1 ] == b [ len ( b ) - j - 1 ] ) :
            j += 1
        bwd [ i ] = j
def query ( a , b , x , y ) :
    if ( x - 1 + len ( a ) - y ) < len ( b ) :
        print ( " No " )
        return
    if ( fwd [ x - 1 ] + bwd [ y + 1 ] ) >= len ( b ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == " _ _ main _ _ " :
    a = " abcabcxy "
    b = " acy "
    preProcess ( a , b )
    x = 2
    y = 5
    query ( a , b , x , y )
    x = 3
    y = 6
    query ( a , b , x , y )

Index/key variables: i, j
Iterator variables: i
Python program:
def findOccurrences ( str , substr ) :
    counter = 0
    for i in range ( 0 , len ( str ) ) :
        if ( str [ i ] == substr [ 0 ] ) :
            for j in range ( i + 1 , len ( str ) ) :
                if ( str [ j ] == substr [ 1 ] ) :
                    for k in range ( j + 1 , len ( str ) ) :
                        if ( str [ k ] == substr [ 2 ] ) :
                            counter = counter + 1
    return counter
str = " GFGFGYSYIOIWIN "
substr = " GFG "
print ( findOccurrences ( str , substr ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def findOccurrences ( str1 , substr ) :
    n = len ( str1 )
    preLeft = [ 0 for i in range ( n ) ]
    preRight = [ 0 for i in range ( n ) ]
    if ( str1 [ 0 ] == substr [ 0 ] ) :
        preLeft [ 0 ] += 1
    for i in range ( 1 , n ) :
        if ( str1 [ i ] == substr [ 0 ] ) :
            preLeft [ i ] = preLeft [ i - 1 ] + 1
        else :
            preLeft [ i ] = preLeft [ i - 1 ]
    if ( str1 [ n - 1 ] == substr [ 2 ] ) :
        preRight [ n - 1 ] += 1
    i = n - 2
    while ( i >= 0 ) :
        if ( str1 [ i ] == substr [ 2 ] ) :
            preRight [ i ] = preRight [ i + 1 ] + 1
        else :
            preRight [ i ] = preRight [ i + 1 ]
        i -= 1
    counter = 0
    for i in range ( 1 , n - 1 ) :
        if ( str1 [ i ] == str1 [ 1 ] ) :
            total = preLeft [ i - 1 ] * preRight [ i + 1 ]
            counter += total
    return counter
if __name__ == ' _ _ main _ _ ' :
    str1 = " GFGFGYSYIOIWIN "
    substr = " GFG "
    print ( findOccurrences ( str1 , substr ) )

Index/key variables: i
Accumulator variables: counter
Iterator variables: i
Python program:
def compute ( st , n ) :
    reverseAlphabet = " zyxwvutsrqponmlkjihgfedcba "
    l = len ( st )
    answer = " "
    for i in range ( 0 , n ) :
        answer = answer + st [ i ] ;
    for i in range ( n , l ) :
        answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( ' a ' ) ] ) ;
    return answer ;
st = " pneumonia "
n = 4
answer = compute ( st , n - 1 )
print ( answer )

Index/key variables: i
Iterator variables: i