dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def minPoints ( points ) :
    points . sort ( key = lambda x : x [ 1 ] )
    coordinates = [ ]
    i = 0
    while i < n :
        seg = points [ i ] [ 1 ]
        coordinates . append ( seg )
        p = i + 1
        if p >= n :
            break
        arrived = points [ p ] [ 0 ]
        while seg >= arrived :
            p += 1
            if p >= n :
                break
            arrived = points [ p ] [ 0 ]
        i = p
    for point in coordinates :
        print ( point , end = " ▁ " )
n = 4
start = [ 4 , 1 , 2 , 5 ]
end = [ 7 , 3 , 5 , 6 ]
points = [ ]
for i in range ( n ) :
    tu = ( start [ i ] , end [ i ] )
    points . append ( tu )
minPoints ( points )

Index/key variables: i, p
Accumulator variables: coordinates, points
Iterator variables: i, point
Python program:
import sys
def solve ( Str , K ) :
    n = len ( Str )
    dp = [ [ 0 for i in range ( n ) ] for j in range ( K ) ]
    if ( n < K ) :
        return - 1
    elif ( n == K ) :
        return 0
    zeroes = 0
    ones = 0
    for i in range ( n ) :
        if ( Str [ i ] == '0' ) :
            zeroes += 1
        else :
            ones += 1
        dp [ 0 ] [ i ] = ones * zeroes
    for s in range ( 1 , K ) :
        for i in range ( n ) :
            dp [ s ] [ i ] = sys . maxsize
            ones = 0
            zeroes = 0
            for k in range ( i , - 1 , - 1 ) :
                if ( Str [ k ] == '0' ) :
                    zeroes += 1
                else :
                    ones += 1
                temp = 0
                if ( k - 1 >= 0 ) :
                    temp = ones * zeroes + dp [ s - 1 ] [ k - 1 ]
                else :
                    temp = sys . maxsize
                dp [ s ] [ i ] = min ( dp [ s ] [ i ] , temp )
    if ( dp [ K - 1 ] [ n - 1 ] == sys . maxsize ) :
        return - 1
    else :
        return dp [ K - 1 ] [ n - 1 ]
S = "0101"
K = 2
print ( solve ( S , K ) )

Index/key variables: i, k, s
Accumulator variables: ones, zeroes
Iterator variables: i, k, s
Python program:
import numpy as np
MAX = 100000
bitscount = 32
prefix_count = np . zeros ( ( bitscount , MAX ) ) ;
def findPrefixCount ( arr , n ) :
    for i in range ( 0 , bitscount ) :
        prefix_count [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ;
        for j in range ( 1 , n ) :
            prefix_count [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ;
            prefix_count [ i ] [ j ] += prefix_count [ i ] [ j - 1 ] ;
def rangeOr ( l , r ) :
    ans = 0 ;
    for i in range ( bitscount ) :
        x = 0 ;
        if ( l == 0 ) :
            x = prefix_count [ i ] [ r ] ;
        else :
            x = prefix_count [ i ] [ r ] - prefix_count [ i ] [ l - 1 ] ;
        if ( x == r - l + 1 ) :
            ans = ( ans | ( 1 << i ) ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 5 , 3 , 5 , 2 , 3 ] ;
    n = len ( arr ) ;
    findPrefixCount ( arr , n ) ;
    queries = [ [ 1 , 3 ] , [ 4 , 5 ] ] ;
    q = len ( queries ) ;
    for i in range ( q ) :
        print ( rangeOr ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) ;

Index/key variables: i, j, r
Iterator variables: i, j
Python program:
def dfs ( node , adj , dp , vis ) :
    vis [ node ] = True
    for i in range ( 0 , len ( adj [ node ] ) ) :
        if not vis [ adj [ node ] [ i ] ] :
            dfs ( adj [ node ] [ i ] , adj , dp , vis )
        dp [ node ] = max ( dp [ node ] , 1 + dp [ adj [ node ] [ i ] ] )
def addEdge ( adj , u , v ) :
    adj [ u ] . append ( v )
def findLongestPath ( adj , n ) :
    dp = [ 0 ] * ( n + 1 )
    vis = [ False ] * ( n + 1 )
    for i in range ( 1 , n + 1 ) :
        if not vis [ i ] :
            dfs ( i , adj , dp , vis )
    ans = 0
    for i in range ( 1 , n + 1 ) :
        ans = max ( ans , dp [ i ] )
    return ans
if __name__ == " _ _ main _ _ " :
    n = 5
    adj = [ [ ] for i in range ( n + 1 ) ]
    addEdge ( adj , 1 , 2 )
    addEdge ( adj , 1 , 3 )
    addEdge ( adj , 3 , 2 )
    addEdge ( adj , 2 , 4 )
    addEdge ( adj , 3 , 4 )
    print ( findLongestPath ( adj , n ) )

Index/key variables: i, node, u
Iterator variables: i
Python program:
def findLongest ( a , n , present , previous ) :
    if present == n :
        return 0
    elif previous != - 1 :
        if dp [ present ] [ previous ] != - 1 :
            return dp [ present ] [ previous ]
    ans = 0
    if previous == - 1 :
        ans = 1 + findLongest ( a , n , present + 1 , present )
        ans = max ( ans , findLongest ( a , n , present + 1 , previous ) )
    else :
        h1 = a [ previous ] [ 0 ]
        h2 = a [ present ] [ 0 ]
        w1 = a [ previous ] [ 1 ]
        w2 = a [ present ] [ 1 ]
        if h1 <= h2 and w1 <= w2 :
            ans = max ( ans , findLongest ( a , n , present + 1 , previous ) )
        else :
            ans = 1 + findLongest ( a , n , present + 1 , present )
            ans = max ( ans , findLongest ( a , n , present + 1 , previous ) )
    dp [ present ] [ previous ] = ans
    return ans
def getLongest ( a , n ) :
    a . sort ( )
    ans = findLongest ( a , n , 0 , - 1 )
    return ans
if __name__ == " _ _ main _ _ " :
    a = [ [ 1 , 5 ] , [ 2 , 4 ] , [ 1 , 1 ] , [ 3 , 3 ] ]
    N = 10
    dp = [ [ - 1 for i in range ( N ) ] for j in range ( N ) ]
    n = len ( a )
    print ( getLongest ( a , n ) )

Index/key variables: present, previous
Python program:
import math as mt
N = 100005
MAX = 1000002
lpd = [ 0 for i in range ( MAX ) ]
def preCompute ( ) :
    lpd [ 0 ] , lpd [ 1 ] = 1 , 1
    for i in range ( 2 , mt . ceil ( mt . sqrt ( MAX ) ) ) :
        for j in range ( 2 * i , MAX , i ) :
            if ( lpd [ j ] == 0 ) :
                lpd [ j ] = i
    for i in range ( 2 , MAX ) :
        if ( lpd [ i ] == 0 ) :
            lpd [ i ] = i
def maxLengthSubsequence ( arr , n ) :
    dp = [ 1 for i in range ( N + 1 ) ]
    pos = dict ( )
    for i in range ( 0 , n ) :
        while ( arr [ i ] > 1 ) :
            p = lpd [ arr [ i ] ]
            if ( p in pos . keys ( ) ) :
                dp [ i ] = max ( dp [ i ] , 1 + dp [ pos [ p ] ] )
            pos [ p ] = i
            while ( arr [ i ] % p == 0 ) :
                arr [ i ] //= p
    ans = 1
    for i in range ( 0 , n + 1 ) :
        ans = max ( ans , dp [ i ] )
    return ans
arr = [ 13 , 2 , 8 , 6 , 3 , 1 , 9 ]
n = len ( arr )
preCompute ( )
print ( maxLengthSubsequence ( arr , n ) )

Index/key variables: i, j, p
Iterator variables: i, j
Python program:
MAX = 10
F = [ [ [ - 1 for i in range ( MAX ) ] for j in range ( MAX ) ] for k in range ( MAX ) ]
def noOfAssignments ( S , n , i , c_x , c_y ) :
    if F [ i ] [ c_x ] [ c_y ] != - 1 :
        return F [ i ] [ c_x ] [ c_y ]
    if i == n :
        F [ i ] [ c_x ] [ c_y ] = not c_x and not c_y
        return F [ i ] [ c_x ] [ c_y ]
    if S [ i ] == ' ( ' :
        F [ i ] [ c_x ] [ c_y ] = noOfAssignments ( S , n , i + 1 , c_x + 1 , c_y ) + noOfAssignments ( S , n , i + 1 , c_x , c_y + 1 )
        return F [ i ] [ c_x ] [ c_y ]
    F [ i ] [ c_x ] [ c_y ] = 0
    if c_x :
        F [ i ] [ c_x ] [ c_y ] += noOfAssignments ( S , n , i + 1 , c_x - 1 , c_y )
    if c_y :
        F [ i ] [ c_x ] [ c_y ] += noOfAssignments ( S , n , i + 1 , c_x , c_y - 1 )
    return F [ i ] [ c_x ] [ c_y ]
if __name__ == " _ _ main _ _ " :
    S = " ( ( ) ) "
    n = len ( S )
    print ( noOfAssignments ( S , n , 0 , 0 , 0 ) )

Index/key variables: c_x, c_y, i
Python program:
def countOddNumber ( row_num ) :
    count = 0
    while row_num != 0 :
        count += row_num & 1
        row_num >>= 1
    return ( 1 << count )
def gouldSequence ( n ) :
    for row_num in range ( 0 , n ) :
        print ( countOddNumber ( row_num ) , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    n = 16
    gouldSequence ( n )

Accumulator variables: count
Iterator variables: row_num
Python program:
def solve ( i , tight , sum_so_far , Sum , number , length ) :
    if i == length :
        if sum_so_far == Sum :
            return 1
        else :
            return 0
    ans = dp [ i ] [ tight ] [ sum_so_far ]
    if ans != - 1 :
        return ans
    ans = 0
    for currdigit in range ( 0 , 10 ) :
        currdigitstr = str ( currdigit )
        if not tight and currdigitstr > number [ i ] :
            break
        ntight = tight or currdigitstr < number [ i ]
        nsum_so_far = sum_so_far + currdigit
        ans += solve ( i + 1 , ntight , nsum_so_far , Sum , number , length )
    return ans
if __name__ == " _ _ main _ _ " :
    count , Sum = 0 , 4
    number = "100"
    dp = [ [ [ - 1 for i in range ( 162 ) ] for j in range ( 2 ) ] for k in range ( 18 ) ]
    print ( solve ( 0 , 0 , 0 , Sum , number , len ( number ) ) )

Index/key variables: i, sum_so_far, tight
Accumulator variables: ans
Iterator variables: currdigit
Python program:
def lds ( arr , n ) :
    lds = [ 0 for i in range ( n ) ]
    lds [ 0 ] = 1
    for i in range ( n ) :
        lds [ i ] = 1
        for j in range ( i ) :
            if ( lds [ j ] != 0 and arr [ i ] % arr [ j ] == 0 ) :
                lds [ i ] = max ( lds [ i ] , lds [ j ] + 1 )
    return max ( lds )
arr = [ 2 , 11 , 16 , 12 , 36 , 60 , 71 , 17 , 29 , 144 , 288 , 129 , 432 , 993 ]
print ( " Length ▁ of ▁ lds ▁ is " , lds ( arr , len ( arr ) ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def lcs ( X , Y , Z , m , n , o ) :
    global arr
    if ( m == 0 or n == 0 or o == 0 ) :
        return 0
    if ( arr [ m - 1 ] [ n - 1 ] [ o - 1 ] != - 1 ) :
        return arr [ m - 1 ] [ n - 1 ] [ o - 1 ]
    if ( X [ m - 1 ] == Y [ n - 1 ] and Y [ n - 1 ] == Z [ o - 1 ] ) :
        arr [ m - 1 ] [ n - 1 ] [ o - 1 ] = 1 + lcs ( X , Y , Z , m - 1 , n - 1 , o - 1 )
        return arr [ m - 1 ] [ n - 1 ] [ o - 1 ]
    else :
        arr [ m - 1 ] [ n - 1 ] [ o - 1 ] = max ( lcs ( X , Y , Z , m , n - 1 , o ) , max ( lcs ( X , Y , Z , m - 1 , n , o ) , lcs ( X , Y , Z , m , n , o - 1 ) ) )
        return arr [ m - 1 ] [ n - 1 ] [ o - 1 ]
arr = [ [ [ 0 for k in range ( 100 ) ] for j in range ( 100 ) ] for i in range ( 100 ) ]
for i in range ( 100 ) :
    for j in range ( 100 ) :
        for k in range ( 100 ) :
            arr [ i ] [ j ] [ k ] = - 1
X = " geeks "
Y = " geeksfor "
Z = " geeksforgeeks "
m = len ( X )
n = len ( Y )
o = len ( Z )
print ( " Length ▁ of ▁ LCS ▁ is ▁ " , lcs ( X , Y , Z , m , n , o ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def printProbabilities ( n , left ) :
    right = 1 - left ;
    arr = [ [ 0 for j in range ( 2 * n + 1 ) ] for i in range ( n + 1 ) ]
    arr [ 1 ] [ n + 1 ] = right ;
    arr [ 1 ] [ n - 1 ] = left ;
    for i in range ( 2 , n + 1 ) :
        for j in range ( 1 , 2 * n + 1 ) :
            arr [ i ] [ j ] += ( arr [ i - 1 ] [ j - 1 ] * right ) ;
        for j in range ( 2 * n - 1 , - 1 , - 1 ) :
            arr [ i ] [ j ] += ( arr [ i - 1 ] [ j + 1 ] * left ) ;
    for i in range ( 2 * n + 1 ) :
        print ( " { :5.4f } ▁ " . format ( arr [ n ] [ i ] ) , end = ' ▁ ' ) ;
if __name__ == " _ _ main _ _ " :
    n = 2 ;
    left = 0.5 ;
    printProbabilities ( n , left ) ;

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
from math import gcd as __gcd
from collections import deque as queue
def minStepsNeeded ( k , d1 , d2 , x ) :
    gcd = __gcd ( d1 , d2 )
    if ( ( k - x ) % gcd != 0 ) :
        return - 1
    q = queue ( )
    visited = dict ( )
    q . appendleft ( [ k , 0 ] )
    visited [ k ] = 1
    while ( len ( q ) > 0 ) :
        sr = q . pop ( )
        s , stp = sr [ 0 ] , sr [ 1 ]
        if ( s == x ) :
            return stp
        if ( s + d1 not in visited ) :
            q . appendleft ( [ ( s + d1 ) , stp + 1 ] )
            visited [ ( s + d1 ) ] = 1
        if ( s + d2 not in visited ) :
            q . appendleft ( [ ( s + d2 ) , stp + 1 ] )
            visited [ ( s + d2 ) ] = 1
        if ( s - d1 not in visited ) :
            q . appendleft ( [ ( s - d1 ) , stp + 1 ] )
            visited [ ( s - d1 ) ] = 1
        if ( s - d2 not in visited ) :
            q . appendleft ( [ ( s - d2 ) , stp + 1 ] )
            visited [ ( s - d2 ) ] = 1
k = 10
d1 = 4
d2 = 6
x = 8
print ( minStepsNeeded ( k , d1 , d2 , x ) )

Index/key variables: k
Python program:
def countWays ( n ) :
    A = [ 0 ] * ( n + 1 )
    B = [ 0 ] * ( n + 1 )
    A [ 0 ] = 1
    A [ 1 ] = 0
    B [ 0 ] = 0
    B [ 1 ] = 1
    for i in range ( 2 , n + 1 ) :
        A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]
        B [ i ] = A [ i - 1 ] + B [ i - 2 ]
    return A [ n ]
n = 8
print ( countWays ( n ) )

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

Index/key variables: x
Accumulator variables: dp
Iterator variables: i
Python program:
def findLongestRepeatingSubSeq ( str ) :
    n = len ( str )
    dp = [ [ 0 for k in range ( n + 1 ) ] for l in range ( n + 1 ) ]
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :
                dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]
            else :
                dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )
    return dp [ n ] [ n ]

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
import numpy as np
def waysToArrange ( N , K , k ) :
    C = np . zeros ( ( N + 1 , N + 1 ) )
    for i in range ( N + 1 ) :
        for j in range ( i + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )
    dp = np . zeros ( ( K + 1 ) )
    count = 0
    dp [ 0 ] = 1
    for i in range ( K ) :
        dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )
        count += k [ i ]
    return dp [ K ]
if __name__ == " _ _ main _ _ " :
    N = 4
    k = [ 2 , 2 ]
    K = len ( k )
    print ( int ( waysToArrange ( N , K , k ) ) )

Index/key variables: K, i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
SIZE = 100
MAX = 10000000
def minCells ( mat , m , n ) :
    dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]
    dp [ 0 ] [ 0 ] = 1
    for i in range ( m ) :
        for j in range ( n ) :
            if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :
                dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1
            if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :
                dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1
    if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :
        return dp [ m - 1 ] [ n - 1 ]
    return - 1
mat = [ [ 2 , 3 , 2 , 1 , 4 ] , [ 3 , 2 , 5 , 8 , 2 ] , [ 1 , 1 , 2 , 2 , 1 ] ]
m = 3
n = 5
print ( " Minimum ▁ number ▁ of ▁ cells ▁ = ▁ " , minCells ( mat , m , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
res = [ ]
def GetCeilIndex ( arr , T , l , r , key ) :
    while ( r - l > 1 ) :
        m = l + ( r - l ) // 2 ;
        if ( arr [ T [ m ] ] >= key ) :
            r = m
        else :
            l = m
    return r
def LIS ( arr , n ) :
    for i in range ( 1 , n ) :
        if ( arr [ i ] < arr [ tailIndices [ 0 ] ] ) :
            tailIndices [ 0 ] = i
        elif ( arr [ i ] > arr [ tailIndices [ leN - 1 ] ] ) :
            prevIndices [ i ] = tailIndices [ leN - 1 ]
            tailIndices [ leN ] = i
            leN += 1
        else :
            pos = GetCeilIndex ( arr , tailIndices , - 1 , leN - 1 , arr [ i ] )
            prevIndices [ i ] = tailIndices [ pos - 1 ]
            tailIndices [ pos ] = i
    i = tailIndices [ leN - 1 ]
    while ( i >= 0 ) :
        res . append ( arr [ i ] )
        i = prevIndices [ i ]
def longestBitonic ( arr1 , n1 , arr2 , n2 ) :
    global res
    LIS ( arr1 , n1 )
    res = res [ : : - 1 ]
    arr2 = arr2 [ : : - 1 ]
    LIS ( arr2 , n2 )
    for i in res :
        print ( i , end = " ▁ " )
arr1 = [ 1 , 2 , 4 , 3 , 2 ]
arr2 = [ 8 , 6 , 4 , 7 , 8 , 9 ]
n1 = len ( arr1 )
n2 = len ( arr2 )
longestBitonic ( arr1 , n1 , arr2 , n2 ) ;

Index/key variables: i, leN, m, pos
Accumulator variables: res
Iterator variables: i
Python program:
R = 3
C = 3
def cal ( ones , x , y , k ) :
    return ( ones [ x + k - 1 ] [ y + k - 1 ] - ones [ x - 1 ] [ y + k - 1 ] - ones [ x + k - 1 ] [ y - 1 ] + ones [ x - 1 ] [ y - 1 ] )
def sol ( mat ) :
    ans = 0
    ones = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]
    for i in range ( 1 , R + 1 , 1 ) :
        for j in range ( 1 , C + 1 , 1 ) :
            ones [ i ] [ j ] = ( ones [ i - 1 ] [ j ] + ones [ i ] [ j - 1 ] - ones [ i - 1 ] [ j - 1 ] + ( mat [ i - 1 ] [ j - 1 ] == 1 ) )
    for k in range ( 1 , min ( R , C ) + 1 , 1 ) :
        for i in range ( 1 , R - k + 2 , 1 ) :
            for j in range ( 1 , C - k + 2 , 1 ) :
                ans = max ( ans , ( ones [ R ] [ C ] + k * k - 2 * cal ( ones , i , j , k ) ) )
    return ans
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 0 , 0 , 1 ] , [ 0 , 0 , 1 ] , [ 1 , 0 , 1 ] ]
    print ( sol ( mat ) )

Index/key variables: C, R, i, j
Iterator variables: i, j, k
Python program:
from queue import Queue
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def maxNodeLevel ( root ) :
    if ( root == None ) :
        return - 1
    q = Queue ( )
    q . put ( root )
    level = 0
    Max = - 999999999999
    level_no = 0
    while ( 1 ) :
        NodeCount = q . qsize ( )
        if ( NodeCount == 0 ) :
            break
        if ( NodeCount > Max ) :
            Max = NodeCount
            level_no = level
        while ( NodeCount > 0 ) :
            Node = q . queue [ 0 ]
            q . get ( )
            if ( Node . left != None ) :
                q . put ( Node . left )
            if ( Node . right != None ) :
                q . put ( Node . right )
            NodeCount -= 1
        level += 1
    return level_no
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 2 )
    root . left = newNode ( 1 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 6 )
    root . right . right = newNode ( 8 )
    root . left . right . left = newNode ( 5 )
    print ( " Level ▁ having ▁ Maximum ▁ number ▁ of ▁ Nodes ▁ : ▁ " , maxNodeLevel ( root ) )

Accumulator variables: NodeCount, level
Class/struct names: newNode
Python program:
def getMinSteps ( n ) :
    table = [ 0 ] * ( n + 1 )
    for i in range ( n + 1 ) :
        table [ i ] = n - i
    for i in range ( n , 0 , - 1 ) :
        if ( not ( i % 2 ) ) :
            table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )
        if ( not ( i % 3 ) ) :
            table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )
    return table [ 1 ]
if __name__ == " _ _ main _ _ " :
    n = 14
    print ( getMinSteps ( n ) )

Index/key variables: i
Iterator variables: i
Python program:
def catalanDP ( n ) :
    catalan = [ 1 for i in range ( n + 1 ) ]
    for i in range ( 2 , n + 1 ) :
        catalan [ i ] = 0
        for j in range ( i ) :
            catalan [ i ] += ( catalan [ j ] * catalan [ i - j - 1 ] )
    return catalan [ n ]
def countWays ( n ) :
    if ( n & 1 ) :
        print ( " Invalid " )
        return 0
    return catalanDP ( n // 2 )
print ( countWays ( 6 ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def countDer ( n ) :
    der = [ 0 for i in range ( n + 1 ) ]
    der [ 1 ] = 0
    der [ 2 ] = 1
    for i in range ( 3 , n + 1 ) :
        der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )
    return der [ n ]
n = 4
print ( " Count ▁ of ▁ Derangements ▁ is ▁ " , countDer ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def countSol ( coeff , n , rhs ) :
    dp = [ 0 for i in range ( rhs + 1 ) ]
    dp [ 0 ] = 1
    for i in range ( n ) :
        for j in range ( coeff [ i ] , rhs + 1 ) :
            dp [ j ] += dp [ j - coeff [ i ] ]
    return dp [ rhs ]
coeff = [ 2 , 2 , 5 ]
rhs = 4
n = len ( coeff )
print ( countSol ( coeff , n , rhs ) )

Index/key variables: i, j, rhs
Iterator variables: i, j
Python program:
INT_MIN = - 2147483648
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def largestValueInEachLevel ( root ) :
    if ( not root ) :
        return
    q = [ ]
    nc = 10
    max = 0
    q . append ( root )
    while ( 1 ) :
        nc = len ( q )
        if ( nc == 0 ) :
            break
        max = INT_MIN
        while ( nc ) :
            front = q [ 0 ]
            q = q [ 1 : ]
            if ( max < front . data ) :
                max = front . data
            if ( front . left ) :
                q . append ( front . left )
            if ( front . right != None ) :
                q . append ( front . right )
            nc -= 1
        print ( max , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 4 )
    root . left = newNode ( 9 )
    root . right = newNode ( 2 )
    root . left . left = newNode ( 3 )
    root . left . right = newNode ( 5 )
    root . right . right = newNode ( 7 )
    largestValueInEachLevel ( root )

Accumulator variables: nc, q
Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
        self . next = None
next = None
def populateNext ( p ) :
    global next
    if ( p != None ) :
        populateNext ( p . right )
        p . next = next
        next = p
        populateNext ( p . left )
def newnode ( data ) :
    node = Node ( 0 )
    node . data = data
    node . left = None
    node . right = None
    node . next = None
    return ( node )
root = newnode ( 10 )
root . left = newnode ( 8 )
root . right = newnode ( 12 )
root . left . left = newnode ( 3 )
p = populateNext ( root )
ptr = root . left . left
while ( ptr != None ) :
    out = 0
    if ( ptr . next != None ) :
        out = ptr . next . data
    else :
        out = - 1
    print ( " Next ▁ of " , ptr . data , " is " , out )
    ptr = ptr . next

Class/struct names: Node
Python program:
def maxProd ( n ) :
    if ( n == 2 or n == 3 ) :
        return ( n - 1 )
    res = 1
    while ( n > 4 ) :
        n -= 3 ;
        res *= 3 ;
    return ( n * res )
print ( " Maximum ▁ Product ▁ is ▁ " , maxProd ( 10 ) ) ;

Accumulator variables: n, res
Python program:
def findWays ( m , n , x ) :
    table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]
    for j in range ( 1 , min ( m + 1 , x + 1 ) ) :
        table [ 1 ] [ j ] = 1
    for i in range ( 2 , n + 1 ) :
        for j in range ( 1 , x + 1 ) :
            for k in range ( 1 , min ( m + 1 , j ) ) :
                table [ i ] [ j ] += table [ i - 1 ] [ j - k ]
    return table [ - 1 ] [ - 1 ]
print ( findWays ( 4 , 2 , 1 ) )
print ( findWays ( 2 , 2 , 3 ) )
print ( findWays ( 6 , 3 , 8 ) )
print ( findWays ( 4 , 2 , 5 ) )
print ( findWays ( 4 , 3 , 5 ) )

Index/key variables: i, j
Iterator variables: i, j, k
Python program:
def findWays ( f , d , s ) :
    mem = [ [ 0 for i in range ( s + 1 ) ] for j in range ( d + 1 ) ]
    mem [ 0 ] [ 0 ] = 1
    for i in range ( 1 , d + 1 ) :
        for j in range ( 1 , s + 1 ) :
            mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ]
            if j - f - 1 >= 0 :
                mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ]
    return mem [ d ] [ s ]
print ( findWays ( 4 , 2 , 1 ) )
print ( findWays ( 2 , 2 , 3 ) )
print ( findWays ( 6 , 3 , 8 ) )
print ( findWays ( 4 , 2 , 5 ) )
print ( findWays ( 4 , 3 , 5 ) )

Index/key variables: d, i, j, s
Iterator variables: i, j