dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
N = 100
n = 3
m = 4
def maxPlus ( arr ) :
    ans = 0
    left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    up = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    down = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]
    for i in range ( n ) :
        for j in range ( m ) :
            left [ i ] [ j ] = ( max ( 0 , ( left [ i ] [ j - 1 ] if j else 0 ) ) + arr [ i ] [ j ] )
            up [ i ] [ j ] = ( max ( 0 , ( up [ i - 1 ] [ j ] if i else 0 ) ) + arr [ i ] [ j ] )
    for i in range ( n ) :
        for j in range ( m ) :
            right [ i ] [ j ] = max ( 0 , ( 0 if ( j + 1 == m ) else right [ i ] [ j + 1 ] ) ) + arr [ i ] [ j ]
            down [ i ] [ j ] = max ( 0 , ( 0 if ( i + 1 == n ) else down [ i + 1 ] [ j ] ) ) + arr [ i ] [ j ]
    for i in range ( 1 , n - 1 ) :
        for j in range ( 1 , m - 1 ) :
            ans = max ( ans , up [ i - 1 ] [ j ] + down [ i + 1 ] [ j ] + left [ i ] [ j - 1 ] + right [ i ] [ j + 1 ] + arr [ i ] [ j ] )
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 1 , 1 , 1 ] , [ - 6 , 1 , 1 , - 4 ] , [ 1 , 1 , 1 , 1 ] ]
    print ( maxPlus ( arr ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countStaircases ( N ) :
    memo = [ [ 0 for x in range ( N + 5 ) ] for y in range ( N + 5 ) ]
    for i in range ( N + 1 ) :
        for j in range ( N + 1 ) :
            memo [ i ] [ j ] = 0
    memo [ 3 ] [ 2 ] = memo [ 4 ] [ 2 ] = 1
    for i in range ( 5 , N + 1 ) :
        for j in range ( 2 , i + 1 ) :
            if ( j == 2 ) :
                memo [ i ] [ j ] = memo [ i - j ] [ j ] + 1
            else :
                memo [ i ] [ j ] = ( memo [ i - j ] [ j ] + memo [ i - j ] [ j - 1 ] )
    answer = 0
    for i in range ( 1 , N + 1 ) :
        answer = answer + memo [ N ] [ i ]
    return answer
if __name__ == " _ _ main _ _ " :
    N = 7
    print ( countStaircases ( N ) )

Index/key variables: N, i, j
Iterator variables: i, j
Python program:
def maxCost ( a , n , l , r ) :
    mx = 0
    for i in range ( n ) :
        mx = max ( mx , a [ i ] )
    count = [ 0 ] * ( mx + 1 )
    for i in range ( n ) :
        count [ a [ i ] ] += 1
    res = [ 0 ] * ( mx + 1 )
    res [ 0 ] = 0
    l = min ( l , r )
    for num in range ( 1 , mx + 1 ) :
        k = max ( num - l - 1 , 0 )
        res [ num ] = max ( res [ num - 1 ] , num * count [ num ] + res [ k ] )
    return res [ mx ]
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 1 , 2 , 3 , 2 , 2 , 1 ]
    l , r = 1 , 1
    n = len ( a )
    print ( maxCost ( a , n , l , r ) )

Index/key variables: i, k, mx, num
Iterator variables: i, num
Python program:
def countPaths ( m , n ) :
    dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( 1 , m + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if ( i == 1 or j == 1 ) :
                dp [ i ] [ j ] = 1
            else :
                dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] )
    return dp [ m ] [ n ]
if __name__ == " _ _ main _ _ " :
    n = 5
    m = 5
    print ( countPaths ( n , m ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
dp = [ [ 0 for i in range ( 1000 ) ] for i in range ( 1000 ) ]
def createPalindrome ( input , isOdd ) :
    n = input
    palin = input
    if ( isOdd ) :
        n //= 10
    while ( n > 0 ) :
        palin = palin * 10 + ( n % 10 )
        n //= 10
    return palin
def generatePalindromes ( N ) :
    palindromes = [ ]
    number = 0
    for j in range ( 2 ) :
        i = 1
        number = createPalindrome ( i , j )
        while number <= N :
            number = createPalindrome ( i , j )
            palindromes . append ( number )
            i += 1
    return palindromes
def minimumSubsetSize ( A , i , j , N ) :
    if ( not N ) :
        return 0
    if ( i > j or A [ i ] > N ) :
        return 10 ** 9
    if ( dp [ i ] [ N ] ) :
        return dp [ i ] [ N ]
    dp [ i ] [ N ] = min ( 1 + minimumSubsetSize ( A , i + 1 , j , N - A [ i ] ) , minimumSubsetSize ( A , i + 1 , j , N ) )
    return dp [ i ] [ N ]
def minimumNoOfPalindromes ( N ) :
    palindromes = generatePalindromes ( N )
    palindromes = sorted ( palindromes )
    return minimumSubsetSize ( palindromes , 0 , len ( palindromes ) - 1 , N )
N = 65
print ( minimumNoOfPalindromes ( N ) )

Index/key variables: N, i
Accumulator variables: n, palindromes
Iterator variables: j
Python program:
def binomialCoeff ( n , k ) :
    res = 1 ;
    if ( k > n - k ) :
        k = n - k ;
    for i in range ( k ) :
        res *= ( n - i ) ;
        res /= ( i + 1 ) ;
    return res ;
def catalan ( n ) :
    c = binomialCoeff ( 2 * n , n ) ;
    return int ( c / ( n + 1 ) ) ;
n = 3 ;
print ( catalan ( n ) ) ;

Accumulator variables: res
Iterator variables: i
Python program:
def alternateFib ( n ) :
    if ( n < 0 ) :
        return - 1 ;
    f1 = 0 ;
    f2 = 1 ;
    print ( f1 , end = " ▁ " ) ;
    for i in range ( 2 , n + 1 ) :
        f3 = f2 + f1 ;
        if ( i % 2 == 0 ) :
            print ( f3 , end = " ▁ " ) ;
        f1 = f2 ;
        f2 = f3 ;
N = 15 ;
alternateFib ( N ) ;

Iterator variables: i
Python program:
def totalWays ( N , M , X ) :
    dp = [ [ 0 for i in range ( 2 ) ] for j in range ( N + 1 ) ]
    if ( X == 1 ) :
        dp [ 0 ] [ 0 ] = 1
    else :
        dp [ 0 ] [ 1 ] = 0
    if ( X == 1 ) :
        dp [ 1 ] [ 0 ] = 0
        dp [ 1 ] [ 1 ] = M - 1
    else :
        dp [ 1 ] [ 0 ] = 1
        dp [ 1 ] [ 1 ] = ( M - 2 )
    for i in range ( 2 , N ) :
        dp [ i ] [ 0 ] = dp [ i - 1 ] [ 1 ]
        dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] * ( M - 1 ) + dp [ i - 1 ] [ 1 ] * ( M - 2 )
    return dp [ N - 1 ] [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    N = 4
    M = 3
    X = 2
    print ( totalWays ( N , M , X ) )

Index/key variables: i
Iterator variables: i
Python program:
term = [ 0 for i in range ( 1000 ) ]
def fib ( n ) :
    if n <= 1 :
        return n
    if term [ n ] != 0 :
        return term [ n ]
    else :
        term [ n ] = fib ( n - 1 ) + fib ( n - 2 )
        return term [ n ]
n = 6
print ( fib ( n ) )

Index/key variables: n
Python program:
dp = [ [ - 1 for i in range ( 8101 ) ] for i in range ( 901 ) ]
def minimumNumberOfDigits ( a , b ) :
    if ( a > b or a < 0 or b < 0 or a > 900 or b > 8100 ) :
        return - 1
    if ( a == 0 and b == 0 ) :
        return 0
    if ( dp [ a ] [ b ] != - 1 ) :
        return dp [ a ] [ b ]
    ans = 101
    for i in range ( 9 , 0 , - 1 ) :
        k = minimumNumberOfDigits ( a - i , b - ( i * i ) )
        if ( k != - 1 ) :
            ans = min ( ans , k + 1 )
    dp [ a ] [ b ] = ans
    return ans
def printSmallestNumber ( a , b ) :
    for i in range ( 901 ) :
        for j in range ( 8101 ) :
            dp [ i ] [ j ] = - 1
    dp [ 0 ] [ 0 ] = 0
    k = minimumNumberOfDigits ( a , b )
    if ( k == - 1 or k > 100 ) :
        print ( - 1 , end = ' ' )
    else :
        while ( a > 0 and b > 0 ) :
            for i in range ( 1 , 10 ) :
                if ( a >= i and b >= i * i and 1 + dp [ a - i ] [ b - i * i ] == dp [ a ] [ b ] ) :
                    print ( i , end = ' ' )
                    a -= i
                    b -= i * i
                    break
if __name__ == ' _ _ main _ _ ' :
    a = 18
    b = 162
    printSmallestNumber ( a , b )

Index/key variables: a, b, i, j
Iterator variables: i, j
Python program:
MAX = 100 ;
def binomialCoeff ( n , k ) :
    C = [ 0 ] * ( k + 1 ) ;
    for i in range ( 1 , n + 1 ) :
        for j in range ( min ( i , k ) , 0 , - 1 ) :
            C [ j ] = C [ j ] + C [ j - 1 ] ;
    return C [ k ] ;
def sumOfproduct ( n ) :
    return binomialCoeff ( 2 * n , n - 1 ) ;
n = 3 ;
print ( sumOfproduct ( n ) ) ;

Index/key variables: j, k
Iterator variables: i, j
Python program:
MAX = 100
def check ( i , add , n , k , a , dp ) :
    if add <= 0 :
        return False
    if i >= n :
        if add == k :
            return True
        return False
    if dp [ i ] [ add ] != - 1 :
        return dp [ i ] [ add ]
    dp [ i ] [ add ] = ( check ( i + 1 , add - 2 * a [ i ] , n , k , a , dp ) or check ( i + 1 , add , n , k , a , dp ) )
    dp [ i ] [ add ] = ( check ( i + 1 , add - ( i + 1 ) , n , k , a , dp ) or dp [ i ] [ add ] )
    dp [ i ] [ add ] = ( check ( i + 1 , add + i + 1 , n , k , a , dp ) or dp [ i ] [ add ] )
    return dp [ i ] [ add ]
def wrapper ( n , k , a ) :
    add = 0
    for i in range ( n ) :
        add += a [ i ]
    dp = [ - 1 ] * MAX
    for i in range ( MAX ) :
        dp [ i ] = [ - 1 ] * MAX
    return check ( 0 , add , n , k , a , dp )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 3 , 4 ]
    n = 4
    k = 5
    print ( " Yes " ) if wrapper ( n , k , a ) else print ( " No " )

Index/key variables: add, i
Iterator variables: i
Python program:
def fib ( n ) :
    a = 0
    b = 1
    if ( n >= 0 ) :
        print ( a , end = ' ▁ ' )
    if ( n >= 1 ) :
        print ( b , end = ' ▁ ' )
    for i in range ( 2 , n + 1 ) :
        c = a + b
        print ( c , end = ' ▁ ' )
        a = b
        b = c
fib ( 9 )

Iterator variables: i
Python program:
def pre_compute ( a , n , index , k ) :
    dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
    for i in range ( n ) :
        if a [ i ] > a [ 0 ] :
            dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]
        else :
            dp [ 0 ] [ i ] = a [ i ]
    for i in range ( 1 , n ) :
        for j in range ( n ) :
            if a [ j ] > a [ i ] and j > i :
                if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :
                    dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]
                else :
                    dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
            else :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
    return dp [ index ] [ k ]
a = [ 1 , 101 , 2 , 3 , 100 , 4 , 5 ]
n = len ( a )
index = 4
k = 6
print ( pre_compute ( a , n , index , k ) )

Index/key variables: i, index, j, k
Iterator variables: i, j
Python program:
def gen ( n ) :
    S = [ 0 , 1 ]
    for i in range ( 2 , n + 1 ) :
        if i % 2 == 0 :
            S . append ( 4 * S [ int ( i / 2 ) ] ) ;
        else :
            S . append ( 4 * S [ int ( i / 2 ) ] + 1 ) ;
    z = S [ n ] ;
    return z ;
def moserDeBruijn ( n ) :
    for i in range ( n ) :
        print ( gen ( i ) , end = " ▁ " )
n = 15
print ( " First " , n , " terms ▁ of ▁ " , " Moser - de ▁ Brujn ▁ Sequence : " )
moserDeBruijn ( n )

Index/key variables: n
Accumulator variables: S
Iterator variables: i
Python program:
INT_MAX = 100000000
def minimalSteps ( s , n ) :
    dp = [ INT_MAX for i in range ( n ) ]
    s1 = " "
    s2 = " "
    dp [ 0 ] = 1
    s1 += s [ 0 ]
    for i in range ( 1 , n ) :
        s1 += s [ i ]
        s2 = s [ i + 1 : i + 1 + i + 1 ]
        dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )
        if ( s1 == s2 ) :
            dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )
    return dp [ n - 1 ]
s = " aaaaaaaa "
n = len ( s )
print ( minimalSteps ( s , n ) )

Index/key variables: i
Accumulator variables: s1
Iterator variables: i
Python program:
def func ( n , m , A ) :
    ModArray = [ 0 ] * n
    Sum = 0
    for i in range ( n ) :
        ModArray [ i ] = A [ i ] % m
        Sum += ModArray [ i ]
    Sum = Sum % m
    if ( Sum % m == 0 ) :
        print ( " True " )
        return
    if ( Sum % 2 != 0 ) :
        print ( " False " )
    else :
        ModArray . pop ( 0 )
        i = 0
        j = len ( ModArray ) - 1
        ModArray . sort ( )
        Sum = Sum // 2
        while ( i <= j ) :
            s = ModArray [ i ] + ModArray [ j ]
            if ( s == Sum ) :
                i1 = i
                i2 = j
                print ( " True " )
                break
            elif ( s > Sum ) :
                j -= 1
            else :
                i += 1
m = 2
a = [ 1 , 3 , 9 ]
n = len ( a )
func ( n , m , a )

Index/key variables: i, j
Accumulator variables: Sum
Iterator variables: i
Python program:
def Golomb ( n ) :
    dp = [ 0 ] * ( n + 1 )
    dp [ 1 ] = 1
    print ( dp [ 1 ] , end = " ▁ " )
    for i in range ( 2 , n + 1 ) :
        dp [ i ] = 1 + dp [ i - dp [ dp [ i - 1 ] ] ]
        print ( dp [ i ] , end = " ▁ " )
n = 9
Golomb ( n )

Index/key variables: i
Iterator variables: i
Python program:
N = 1000
def arrangeBraces ( n , pos , k ) :
    h = [ False for i in range ( N ) ]
    dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]
    for i in range ( k ) :
        h [ pos [ i ] ] = 1
    dp [ 0 ] [ 0 ] = 1
    for i in range ( 1 , 2 * n + 1 ) :
        for j in range ( 2 * n + 1 ) :
            if ( h [ i ] ) :
                if ( j != 0 ) :
                    dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]
                else :
                    dp [ i ] [ j ] = 0
            else :
                if ( j != 0 ) :
                    dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )
                else :
                    dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]
    return dp [ 2 * n ] [ 0 ]
n = 3
pos = [ 2 , ] ;
k = len ( pos )
print ( arrangeBraces ( n , pos , k ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findLength ( string , n ) :
    current_sum = 0
    max_sum = 0
    for i in range ( n ) :
        current_sum += ( 1 if string [ i ] == '0' else - 1 )
        if current_sum < 0 :
            current_sum = 0
        max_sum = max ( current_sum , max_sum )
    return max_sum if max_sum else 0
s = "11000010001"
n = 11
print ( findLength ( s , n ) )

Index/key variables: i
Accumulator variables: current_sum
Iterator variables: i
Python program:
DP_s = 9
def getNumStrictMonotone ( ln ) :
    DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]
    for i in range ( DP_s ) :
        DP [ 0 ] [ i ] = i + 1
    for i in range ( 1 , ln ) :
        for j in range ( 1 , DP_s ) :
            DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]
    return DP [ ln - 1 ] [ DP_s - 1 ]
print ( getNumStrictMonotone ( 2 ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def chordCnt ( A ) :
    n = 2 * A
    dpArray = [ 0 ] * ( n + 1 )
    dpArray [ 0 ] = 1
    dpArray [ 2 ] = 1
    for i in range ( 4 , n + 1 , 2 ) :
        for j in range ( 0 , i - 1 , 2 ) :
            dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )
    return int ( dpArray [ n ] )
N = 2
print ( chordCnt ( N ) )
N = 1
print ( chordCnt ( N ) )
N = 4
print ( chordCnt ( N ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
row = 5
col = 5
def isPath ( arr ) :
    arr [ 0 ] [ 0 ] = 1
    for i in range ( 1 , row ) :
        if ( arr [ i ] [ 0 ] != - 1 ) :
            arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]
    for j in range ( 1 , col ) :
        if ( arr [ 0 ] [ j ] != - 1 ) :
            arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]
    for i in range ( 1 , row ) :
        for j in range ( 1 , col ) :
            if ( arr [ i ] [ j ] != - 1 ) :
                arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )
    return ( arr [ row - 1 ] [ col - 1 ] == 1 )
arr = [ [ 0 , 0 , 0 , - 1 , 0 ] , [ - 1 , 0 , 0 , - 1 , - 1 ] , [ 0 , 0 , 0 , - 1 , 0 ] , [ - 1 , 0 , - 1 , 0 , - 1 ] , [ 0 , 0 , - 1 , 0 , 0 ] ]
if ( isPath ( arr ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def nswp ( n ) :
    dp = [ 1 for x in range ( n + 1 ) ] ;
    for i in range ( 2 , n + 1 ) :
        dp [ i ] = ( 2 * dp [ i - 1 ] + dp [ i - 2 ] ) ;
    return dp [ n ] ;
n = 3 ;
print ( nswp ( n ) ) ;

Index/key variables: i, n
Iterator variables: i
Python program:
MAX = 256
def numberofways ( A , B , N , M ) :
    pos = [ [ ] for _ in range ( MAX ) ]
    for i in range ( M ) :
        pos [ ord ( B [ i ] ) ] . append ( i + 1 )
    dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]
    for i in range ( 1 , N + 1 ) :
        for j in range ( 1 , M + 1 ) :
            if A [ i - 1 ] == B [ j - 1 ] :
                dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1
            else :
                dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )
    LCS = dpl [ N ] [ M ]
    dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]
    for i in range ( N , 0 , - 1 ) :
        for j in range ( M , 0 , - 1 ) :
            if A [ i - 1 ] == B [ j - 1 ] :
                dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1
            else :
                dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )
    ans = 0
    for i in range ( N + 1 ) :
        for j in range ( MAX ) :
            for x in pos [ j ] :
                if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :
                    ans += 1
                    break
    return ans
if __name__ == " _ _ main _ _ " :
    A = " aa "
    B = " baaa "
    N = len ( A )
    M = len ( B )
    print ( numberofways ( A , B , N , M ) )

Index/key variables: M, N, i, j
Accumulator variables: ans
Iterator variables: i, j, x
Python program:
def lcs ( X , Y , m , n ) :
    L = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
    for i in range ( m + 1 ) :
        for j in range ( n + 1 ) :
            if ( i == 0 or j == 0 ) :
                L [ i ] [ j ] = 0
            elif ( X [ i - 1 ] == Y [ j - 1 ] ) :
                L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 2 * ( ord ( X [ i - 1 ] ) - 48 )
            else :
                L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] )
    return L [ m ] [ n ]
def findMinCost ( X , Y ) :
    m = len ( X )
    n = len ( Y )
    cost = 0
    for i in range ( m ) :
        cost += ord ( X [ i ] ) - 48
    for i in range ( n ) :
        cost += ord ( Y [ i ] ) - 48
    ans = cost - lcs ( X , Y , m , n )
    return ans
X = "3759"
Y = "9350"
print ( " Minimum ▁ Cost ▁ to ▁ make ▁ two ▁ strings ▁ " , " identical ▁ is ▁ = ▁ " , findMinCost ( X , Y ) )

Index/key variables: i, j, m, n
Accumulator variables: cost
Iterator variables: i, j
Python program:
def isSubSeqDivisible ( st ) :
    l = len ( st )
    arr = [ int ( ch ) for ch in st ]
    for i in range ( 0 , l ) :
        for j in range ( i , l ) :
            for k in range ( j , l ) :
                if ( arr [ i ] % 8 == 0 ) :
                    return True
                elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :
                    return True
                elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :
                    return True
    return False
st = "3144"
if ( isSubSeqDivisible ( st ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
Str = "129365"
mp = { }
no = 8
while ( no < 100 ) :
    no = no + 8
    mp [ ( no // 10 ) % 10 ] = no % 10
visited = [ False ] * 10
for i in range ( len ( Str ) - 1 , - 1 , - 1 ) :
    if ( Str [ i ] == '8' ) :
        print ( " Yes " , end = " " )
        break
    if visited [ mp [ ord ( Str [ i ] ) - ord ( '0' ) ] ] :
        print ( " Yes " , end = " " )
        break
    visited [ ord ( Str [ i ] ) - ord ( '0' ) ] = True
if ( i == - 1 ) :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def maxLength ( s , n ) :
    dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
    for i in range ( n - 1 ) :
        if ( s [ i ] == ' ( ' and s [ i + 1 ] == ' ) ' ) :
            dp [ i ] [ i + 1 ] = 2
    for l in range ( 2 , n ) :
        i = - 1
        for j in range ( l , n ) :
            i += 1
            if ( s [ i ] == ' ( ' and s [ j ] == ' ) ' ) :
                dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]
            for k in range ( i , j ) :
                dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )
    return dp [ 0 ] [ n - 1 ]
s = " ( ) ( ( ( ( ( ( ) "
n = len ( s )
print ( maxLength ( s , n ) )

Index/key variables: i, j, k
Iterator variables: i, j, k, l
Python program:
def maxSumBitonicSubArr ( arr , n ) :
    max_sum = - 10 ** 9
    i = 0
    while ( i < n ) :
        j = i
        while ( j + 1 < n and arr [ j ] < arr [ j + 1 ] ) :
            j += 1
        while ( i < j and arr [ i ] <= 0 ) :
            i += 1
        k = j
        while ( k + 1 < n and arr [ k ] > arr [ k + 1 ] ) :
            k += 1
        last = k
        while ( k > j and arr [ k ] <= 0 ) :
            k -= 1
        nn = arr [ i : j + 1 ]
        sum_inc = sum ( nn )
        nn = arr [ j : k + 1 ]
        sum_dec = sum ( nn )
        sum_all = sum_inc + sum_dec - arr [ j ]
        max_sum = max ( [ max_sum , sum_inc , sum_dec , sum_all ] )
        i = max ( last , i + 1 )
    return max_sum
arr = [ 5 , 3 , 9 , 2 , 7 , 6 , 4 ]
n = len ( arr )
print ( " Maximum ▁ Sum ▁ = ▁ " , maxSumBitonicSubArr ( arr , n ) )
arr2 = [ 1 , 2 , 3 , 4 , 5 ]
n2 = len ( arr2 )
print ( " Maximum ▁ Sum ▁ = ▁ " , maxSumBitonicSubArr ( arr2 , n2 ) )
arr3 = [ 5 , 4 , 3 , 2 , 1 ]
n3 = len ( arr3 )
print ( " Maximum ▁ Sum ▁ = ▁ " , maxSumBitonicSubArr ( arr3 , n3 ) )
arr4 = [ 5 , 5 , 5 , 5 ]
n4 = len ( arr4 )
print ( " Maximum ▁ Sum ▁ = ▁ " , maxSumBitonicSubArr ( arr4 , n4 ) )
arr5 = [ - 1 , 0 , 1 , 2 , 3 , 1 , 0 , - 1 , - 10 ]
n5 = len ( arr5 )
print ( " Maximum ▁ Sum ▁ = ▁ " , maxSumBitonicSubArr ( arr5 , n5 ) )
arr6 = [ - 1 , 0 , 1 , 2 , 0 , - 1 , - 2 , 0 , 1 , 3 ]
n6 = len ( arr6 )
print ( " Maximum ▁ Sum ▁ = ▁ " , maxSumBitonicSubArr ( arr6 , n6 ) )

Index/key variables: i, j, k
Python program:
MAX = 300
dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]
def minimumSquare ( m , n ) :
    vertical_min = 10000000000
    horizontal_min = 10000000000
    if n == 13 and m == 11 :
        return 6
    if m == 13 and n == 11 :
        return 6
    if m == n :
        return 1
    if dp [ m ] [ n ] != 0 :
        return dp [ m ] [ n ]
    for i in range ( 1 , m // 2 + 1 ) :
        horizontal_min = min ( minimumSquare ( i , n ) + minimumSquare ( m - i , n ) , horizontal_min )
    for j in range ( 1 , n // 2 + 1 ) :
        vertical_min = min ( minimumSquare ( m , j ) + minimumSquare ( m , n - j ) , vertical_min )
    dp [ m ] [ n ] = min ( vertical_min , horizontal_min )
    return dp [ m ] [ n ]
if __name__ == ' _ _ main _ _ ' :
    m = 30
    n = 35
    print ( minimumSquare ( m , n ) )

Index/key variables: m, n
Iterator variables: i, j
Python program:
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
def nCr ( n , r ) :
    return fact ( n ) // ( ( fact ( r ) * fact ( n - r ) ) )
n = 2
print ( " Number ▁ of ▁ Non - Decreasing ▁ digits : ▁ " , nCr ( n + 9 , 9 ) )

Iterator variables: i
Python program:
def countWays ( n , k ) :
    total = k
    mod = 1000000007
    same , diff = 0 , k
    for i in range ( 2 , n + 1 ) :
        same = diff
        diff = total * ( k - 1 )
        diff = diff % mod
        total = ( same + diff ) % mod
    return total
if __name__ == " _ _ main _ _ " :
    n , k = 3 , 2
    print ( countWays ( n , k ) )

Iterator variables: i
Python program:
def maxSumWithK ( a , n , k ) :
    maxSum = [ 0 for i in range ( n ) ]
    maxSum [ 0 ] = a [ 0 ]
    curr_max = a [ 0 ]
    for i in range ( 1 , n ) :
        curr_max = max ( a [ i ] , curr_max + a [ i ] )
        maxSum [ i ] = curr_max
    sum = 0
    for i in range ( k ) :
        sum += a [ i ]
    result = sum
    for i in range ( k , n ) :
        sum = sum + a [ i ] - a [ i - k ]
        result = max ( result , sum )
        result = max ( result , sum + maxSum [ i - k ] )
    return result
a = [ 1 , 2 , 3 , - 10 , - 3 ]
k = 4
n = len ( a )
print ( maxSumWithK ( a , n , k ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i