dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
dp = [ [ [ - 1 for i in range ( 10 ) ] for col in range ( 20 ) ] for row in range ( 100 ) ]
def countOfNumbers ( digit , prev1 , prev2 , n ) :
    if ( digit == n + 1 ) :
        return 1
    val = dp [ digit ] [ prev1 ] [ prev2 ]
    if ( val != - 1 ) :
        return val
    val = 0
    if ( digit == 1 ) :
        start = 1
        if ( n == 1 ) :
            start = 0
        for i in range ( start , 10 ) :
            val += countOfNumbers ( digit + 1 , i , prev1 , n )
    elif ( digit == 2 ) :
        for i in range ( 0 , 10 ) :
            val += countOfNumbers ( digit + 1 , i , prev1 , n )
    else :
        mean = prev1
        current = ( 2 * mean ) - prev2
        if ( current >= 0 and current <= 9 ) :
            val += countOfNumbers ( digit + 1 , current , prev1 , n )
        if ( ( current + 1 ) >= 0 and ( current + 1 ) <= 9 ) :
            val += countOfNumbers ( digit + 1 , current + 1 , prev1 , n )
    return val
n = 2
print ( countOfNumbers ( 1 , 0 , 0 , n ) )

Index/key variables: digit, prev1, prev2
Accumulator variables: val
Iterator variables: i
Python program:
dp = [ [ [ - 1 for i in range ( 10 ) ] for j in range ( 10 ) ] for k in range ( 50 ) ]
def countOfNumbers ( digit , prev1 , prev2 , N ) :
    if ( digit == N + 1 ) :
        return 1
    if ( dp [ digit ] [ prev1 ] [ prev2 ] != - 1 ) :
        return dp [ digit ] [ prev1 ] [ prev2 ]
    dp [ digit ] [ prev1 ] [ prev2 ] = 0
    if ( digit == 1 ) :
        term = 0 if N == 1 else 1
        for j in range ( term , 10 , 1 ) :
            dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N )
    elif ( digit == 2 ) :
        for j in range ( 10 ) :
            dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N )
    else :
        for j in range ( abs ( prev1 - prev2 ) + 1 ) :
            dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N )
    return dp [ digit ] [ prev1 ] [ prev2 ]
if __name__ == ' _ _ main _ _ ' :
    N = 3
    print ( countOfNumbers ( 1 , 0 , 0 , N ) )

Index/key variables: digit, prev1, prev2
Iterator variables: j
Python program:
def FindMaxS ( X , Y , Z , n ) :
    global A , B , C
    if ( X < 0 or Y < 0 or Z < 0 ) :
        return - 10 ** 9
    if ( n < 0 ) :
        return 0
    ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 )
    ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 )
    co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 )
    no = FindMaxS ( X , Y , Z , n - 1 )
    maximum = max ( ch , max ( ca , max ( co , no ) ) )
    return maximum
if __name__ == ' _ _ main _ _ ' :
    X = 1
    Y = 1
    Z = 1
    A = [ 10 , 0 , 5 ]
    B = [ 5 , 10 , 0 ]
    C = [ 0 , 5 , 10 ]
    n = len ( B )
    print ( FindMaxS ( X , Y , Z , n - 1 ) )

Index/key variables: n
Python program:
def replace ( arr , n ) :
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ i ] >= 0 and arr [ j ] >= 0 and arr [ i ] % 2 == 0 and arr [ j ] % 2 != 0 ) :
                tmp = arr [ i ]
                arr [ i ] = arr [ j ]
                arr [ j ] = tmp
                arr [ j ] = - arr [ j ]
                break
            elif ( arr [ i ] >= 0 and arr [ j ] >= 0 and arr [ i ] % 2 != 0 and arr [ j ] % 2 == 0 ) :
                tmp = arr [ i ]
                arr [ i ] = arr [ j ]
                arr [ j ] = tmp
                arr [ j ] = - arr [ j ]
                break
    for i in range ( n ) :
        arr [ i ] = abs ( arr [ i ] )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 2 , 4 ]
    n = len ( arr )
    replace ( arr , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def gethalfCount ( root ) :
    if root == None :
        return 0
    res = 0
    if ( root . left == None and root . right != None ) or ( root . left != None and root . right == None ) :
        res += 1
    res += ( gethalfCount ( root . left ) + gethalfCount ( root . right ) )
    return res
root = newNode ( 2 )
root . left = newNode ( 7 )
root . right = newNode ( 5 )
root . left . right = newNode ( 6 )
root . left . right . left = newNode ( 1 )
root . left . right . right = newNode ( 11 )
root . right . right = newNode ( 9 )
root . right . right . left = newNode ( 4 )
print ( gethalfCount ( root ) )

Class/struct names: newNode
Python program:
def minimumCostToMergeK ( arr , K ) :
    N = len ( arr )
    if ( N - 1 ) % ( K - 1 ) != 0 :
        return - 1
    prefixSum = [ 0 ] * ( N + 1 )
    for i in range ( 1 , N + 1 ) :
        prefixSum [ i ] = ( prefixSum [ i - 1 ] + arr [ i - 1 ] )
    dp = [ [ 0 ] * N for _ in range ( N ) ]
    for L in range ( K , N + 1 ) :
        for i in range ( N - L + 1 ) :
            j = i + L - 1
            if L > K :
                dp [ i ] [ j ] = ( min ( [ dp [ i ] [ x ] + dp [ x + 1 ] [ j ] for x in range ( i , j , K - 1 ) ] ) )
            if ( L - 1 ) % ( K - 1 ) == 0 :
                dp [ i ] [ j ] += ( prefixSum [ j + 1 ] - prefixSum [ i ] )
    return dp [ 0 ] [ N - 1 ]
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 5 , 1 , 2 , 6 ]
    K = 3
print ( minimumCostToMergeK ( arr , K ) )

Index/key variables: i, j, x
Iterator variables: L, i
Python program:
def Max_Sum ( arr , K , N ) :
    dp = [ 0 ] * ( N + 1 )
    prefix = [ None ] * ( N + 1 )
    prefix [ 0 ] = 0
    for i in range ( 1 , N + 1 ) :
        prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ]
    dp [ 0 ] = 0
    for i in range ( 1 , K ) :
        dp [ i ] = prefix [ i ]
    for i in range ( K , N + 1 ) :
        for j in range ( i , i - K , - 1 ) :
            dp [ i ] = max ( dp [ i ] , dp [ j - 1 ] + prefix [ i ] - prefix [ j ] )
    return dp [ N ]
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 12 , 22 , 18 , 34 , 12 , 25 ]
    N = len ( arr )
    K = 5
    print ( Max_Sum ( arr , K , N ) )

Index/key variables: N, i, j
Iterator variables: i, j
Python program:
def binomialCoeff ( n , k ) :
    C = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( min ( i , k ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )
    return C [ n ] [ k ]
def waysToSplitN ( k , n , P ) :
    new_N = n - k * P
    return binomialCoeff ( new_N + k - 1 , new_N )
K = 3
N = 8
P = 2
print ( waysToSplitN ( K , N , P ) )

Index/key variables: i, j, k, n
Iterator variables: i, j
Python program:
def solve ( a ) :
    n = len ( a )
    dp = [ 0 ] * ( n + 1 )
    val = [ 0 ] * ( n + 1 )
    for i in range ( n - 1 , - 1 , - 1 ) :
        sum = a [ i ]
        j = i
        while ( j + 1 < n and sum < val [ j + 1 ] ) :
            j += 1
            sum += a [ j ]
        dp [ i ] = ( j - i ) + dp [ j + 1 ]
        val [ i ] = sum
    return dp [ 0 ]
arr = [ 1 , 5 , 3 , 9 , 1 ]
print ( solve ( arr ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i
Python program:
def distinctSimilarSubstrings ( str ) :
    n = len ( str )
    if ( n <= 1 ) :
        return 0
    dp = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]
    substrings = set ( )
    for j in range ( n - 1 , - 1 , - 1 ) :
        for i in range ( j - 1 , - 1 , - 1 ) :
            if ( str [ i ] == str [ j ] ) :
                dp [ i ] [ j ] = dp [ i + 1 ] [ j + 1 ] + 1
            else :
                dp [ i ] [ j ] = 0
            if ( dp [ i ] [ j ] >= j - i ) :
                substrings . add ( str [ i : j - i ] )
    return len ( substrings )
str = " geeksgeeksforgeeks "
print ( distinctSimilarSubstrings ( str ) )

Index/key variables: i, j
Accumulator variables: substrings
Iterator variables: i, j
Python program:
def initialise ( V ) :
    global dis , Next
    for i in range ( V ) :
        for j in range ( V ) :
            dis [ i ] [ j ] = graph [ i ] [ j ]
            if ( graph [ i ] [ j ] == INF ) :
                Next [ i ] [ j ] = - 1
            else :
                Next [ i ] [ j ] = j
def constructPath ( u , v ) :
    global graph , Next
    if ( Next [ u ] [ v ] == - 1 ) :
        return { }
    path = [ u ]
    while ( u != v ) :
        u = Next [ u ] [ v ]
        path . append ( u )
    return path
def floydWarshall ( V ) :
    global dist , Next
    for k in range ( V ) :
        for i in range ( V ) :
            for j in range ( V ) :
                if ( dis [ i ] [ k ] == INF or dis [ k ] [ j ] == INF ) :
                    continue
                if ( dis [ i ] [ j ] > dis [ i ] [ k ] + dis [ k ] [ j ] ) :
                    dis [ i ] [ j ] = dis [ i ] [ k ] + dis [ k ] [ j ]
                    Next [ i ] [ j ] = Next [ i ] [ k ]
def printPath ( path ) :
    n = len ( path )
    for i in range ( n - 1 ) :
        print ( path [ i ] , end = " ▁ - > ▁ " )
    print ( path [ n - 1 ] )
if __name__ == ' _ _ main _ _ ' :
    MAXM , INF = 100 , 10 ** 7
    dis = [ [ - 1 for i in range ( MAXM ) ] for i in range ( MAXM ) ]
    Next = [ [ - 1 for i in range ( MAXM ) ] for i in range ( MAXM ) ]
    V = 4
    graph = [ [ 0 , 3 , INF , 7 ] , [ 8 , 0 , 2 , INF ] , [ 5 , INF , 0 , 1 ] , [ 2 , INF , INF , 0 ] ]
    initialise ( V )
    floydWarshall ( V )
    path = [ ]
    print ( " Shortest ▁ path ▁ from ▁ 1 ▁ to ▁ 3 : ▁ " , end = " " )
    path = constructPath ( 1 , 3 )
    printPath ( path )
    print ( " Shortest ▁ path ▁ from ▁ 0 ▁ to ▁ 2 : ▁ " , end = " " )
    path = constructPath ( 0 , 2 )
    printPath ( path )
    print ( " Shortest ▁ path ▁ from ▁ 3 ▁ to ▁ 2 : ▁ " , end = " " )
    path = constructPath ( 3 , 2 )
    printPath ( path )

Index/key variables: i, j, k, u, v
Accumulator variables: path
Iterator variables: i, j, k
Python program:
vp = [ [ ] for i in range ( 2009 ) ]
def finding_factors ( n ) :
    i = 1
    a = 0
    global vp
    while ( i * i <= n ) :
        if ( n % i == 0 ) :
            if ( i * i == n ) :
                vp [ n ] . append ( i )
            else :
                vp [ n ] . append ( i )
                vp [ n ] . append ( int ( n / i ) )
        i += 1
def countSeq ( N , K ) :
    i = 0
    j = 0
    k = 0
    dp = [ [ 0 for i in range ( 109 ) ] for j in range ( 109 ) ]
    for i in range ( 1 , N + 1 ) :
        finding_factors ( i )
        dp [ 0 ] [ i ] = 0
        dp [ 1 ] [ i ] = 1
    for i in range ( 2 , K + 1 ) :
        for j in range ( 1 , N + 1 ) :
            Sum = 0
            for k in range ( len ( vp [ j ] ) ) :
                Sum += dp [ i - 1 ] [ vp [ j ] [ k ] ]
            dp [ i ] [ j ] = Sum
    ans = 0
    for j in range ( 1 , N + 1 ) :
        ans += dp [ K ] [ j ]
    return ans
N = 3
K = 2
print ( countSeq ( N , K ) )

Index/key variables: K, i, j, k, n
Accumulator variables: Sum, ans
Iterator variables: i, j, k
Python program:
def MAX_value ( arr ) :
    row = len ( arr )
    col = len ( arr )
    dp = [ [ 0 for i in range ( col ) ] for j in range ( row ) ]
    i , j = 0 , 0
    c , p = arr [ 0 ] [ 0 ] , 0
    d = row
    for i in range ( d ) :
        for j in range ( d ) :
            if ( c < arr [ i ] [ j ] ) :
                c = arr [ i ] [ j ]
            if ( i == 0 or j == 0 ) :
                dp [ i ] [ j ] = 1
            else :
                if ( arr [ i - 1 ] [ j - 1 ] == arr [ i ] [ j ] and arr [ i - 1 ] [ j ] == arr [ i ] [ j ] and arr [ i ] [ j - 1 ] == arr [ i ] [ j ] ) :
                    dp [ i ] [ j ] = min ( dp [ i - 1 ] [ j - 1 ] , min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ) + 1
                else :
                    dp [ i ] [ j ] = 1
    for i in range ( d ) :
        for j in range ( d ) :
            if ( arr [ i ] [ j ] == c ) :
                if ( p < dp [ i ] [ j ] ) :
                    p = dp [ i ] [ j ]
    return p * p
arr = [ [ 9 , 9 , 3 , 3 , 4 , 4 ] , [ 9 , 9 , 7 , 7 , 7 , 4 ] , [ 1 , 2 , 7 , 7 , 7 , 4 ] , [ 4 , 4 , 7 , 7 , 7 , 4 ] , [ 5 , 5 , 1 , 1 , 2 , 7 ] , [ 2 , 7 , 1 , 1 , 4 , 4 ] ]
print ( MAX_value ( arr ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
from math import log10 , log
def smallestNum ( n ) :
    res = 1
    i = 2
    while ( True ) :
        length = int ( log10 ( i ) + 1 )
        if ( length == n ) :
            return int ( log ( i ) // log ( 2 ) )
        i *= 2
n = 4
print ( smallestNum ( n ) )

Accumulator variables: i
Python program:
import math
N = 100005 ;
level = [ 0 for i in range ( N ) ]
LG = 20 ;
dp = [ [ 0 for j in range ( N ) ] for i in range ( LG ) ]
mx = [ [ 0 for j in range ( N ) ] for i in range ( LG ) ]
v = [ [ ] for i in range ( N ) ]
n = 0
def dfs_lca ( a , par , lev ) :
    dp [ 0 ] [ a ] = par ;
    level [ a ] = lev ;
    for i in v [ a ] :
        if ( i [ 0 ] == par ) :
            continue ;
        mx [ 0 ] [ i [ 0 ] ] = i [ 1 ] ;
        dfs_lca ( i [ 0 ] , a , lev + 1 ) ;
def find_ancestor ( ) :
    for i in range ( 1 , 16 ) :
        for j in range ( 1 , n + 1 ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ;
            mx [ i ] [ j ] = max ( mx [ i - 1 ] [ j ] , mx [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ) ;
def getMax ( a , b ) :
    if ( level [ b ] < level [ a ] ) :
        a , b = b , a
    ans = 0 ;
    diff = level [ b ] - level [ a ] ;
    while ( diff > 0 ) :
        log = int ( math . log2 ( diff ) ) ;
        ans = max ( ans , mx [ log ] [ b ] ) ;
        b = dp [ log ] [ b ] ;
        diff -= ( 1 << log ) ;
    while ( a != b ) :
        i = int ( math . log2 ( level [ a ] ) ) ;
        while ( i > 0 and dp [ i ] [ a ] == dp [ i ] [ b ] ) :
            i -= 1
        ans = max ( ans , mx [ i ] [ a ] ) ;
        ans = max ( ans , mx [ i ] [ b ] ) ;
        a = dp [ i ] [ a ] ;
        b = dp [ i ] [ b ] ;
    return ans ;
def compute_lca ( ) :
    dfs_lca ( 1 , 0 , 0 ) ;
    find_ancestor ( ) ;
if __name__ == " _ _ main _ _ " :
    n = 5 ;
    v [ 1 ] . append ( [ 2 , 2 ] ) ;
    v [ 2 ] . append ( [ 1 , 2 ] ) ;
    v [ 1 ] . append ( [ 3 , 5 ] ) ;
    v [ 3 ] . append ( [ 1 , 5 ] ) ;
    v [ 3 ] . append ( [ 4 , 3 ] ) ;
    v [ 4 ] . append ( [ 3 , 4 ] ) ;
    v [ 3 ] . append ( [ 5 , 1 ] ) ;
    v [ 5 ] . append ( [ 3 , 1 ] ) ;
    compute_lca ( ) ;
    queries = [ [ 3 , 5 ] , [ 2 , 3 ] , [ 2 , 4 ] ]
    q = 3 ;
    for i in range ( q ) :
        max_edge = getMax ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ;
        print ( max_edge )

Index/key variables: a, b, i, j, log
Accumulator variables: diff
Iterator variables: i, j
Python program:
class newNode ( ) :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def getfullCount ( root ) :
    if ( root == None ) :
        return 0
    res = 0
    if ( root . left and root . right ) :
        res += 1
    res += ( getfullCount ( root . left ) + getfullCount ( root . right ) )
    return res
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 2 )
    root . left = newNode ( 7 )
    root . right = newNode ( 5 )
    root . left . right = newNode ( 6 )
    root . left . right . left = newNode ( 1 )
    root . left . right . right = newNode ( 11 )
    root . right . right = newNode ( 9 )
    root . right . right . left = newNode ( 4 )
    print ( getfullCount ( root ) )

Class/struct names: newNode
Python program:
def maxDistance ( grid ) :
    if ( len ( grid ) == 0 ) :
        return - 1
    N = len ( grid )
    INF = 1000000
    if grid [ 0 ] [ 0 ] == 1 :
        grid [ 0 ] [ 0 ] = 0
    else :
        grid [ 0 ] [ 0 ] = INF
    for i in range ( 1 , N ) :
        if grid [ 0 ] [ i ] == 1 :
            grid [ 0 ] [ i ] = 0
        else :
            grid [ 0 ] [ i ] = grid [ 0 ] [ i - 1 ] + 1
    for i in range ( 1 , N ) :
        if grid [ i ] [ 0 ] == 1 :
            grid [ i ] [ 0 ] = 0
        else :
            grid [ i ] [ 0 ] = grid [ i - 1 ] [ 0 ] + 1
    for i in range ( 1 , N ) :
        for j in range ( 1 , N ) :
            if grid [ i ] [ j ] == 1 :
                grid [ i ] [ j ] = 0
            else :
                grid [ i ] [ j ] = min ( grid [ i - 1 ] [ j ] , grid [ i ] [ j - 1 ] + 1 )
    if ( grid [ N - 1 ] [ N - 1 ] >= INF ) :
        return - 1
    maxi = grid [ N - 1 ] [ N - 1 ]
    for i in range ( N - 2 , - 1 , - 1 ) :
        grid [ N - 1 ] [ i ] = min ( grid [ N - 1 ] [ i ] , grid [ N - 1 ] [ i + 1 ] + 1 )
        maxi = max ( grid [ N - 1 ] [ i ] , maxi )
    for i in range ( N - 2 , - 1 , - 1 ) :
        grid [ i ] [ N - 1 ] = min ( grid [ i ] [ N - 1 ] , grid [ i + 1 ] [ N - 1 ] + 1 )
        maxi = max ( grid [ i ] [ N - 1 ] , maxi + 1 )
    for i in range ( N - 2 , - 1 , - 1 ) :
        for j in range ( N - 2 , - 1 , - 1 ) :
            grid [ i ] [ j ] = min ( grid [ i ] [ j ] , min ( grid [ i + 1 ] [ j ] + 1 , grid [ i ] [ j + 1 ] + 1 ) )
            maxi = max ( grid [ i ] [ j ] , maxi )
    if maxi == 0 :
        return - 1
    else :
        return maxi
arr = [ [ 0 , 0 , 1 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ]
print ( maxDistance ( arr ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findCost ( cost_mat , N , M ) :
    dp = [ [ 0 ] * M for _ in range ( M ) ]
    dp [ 0 ] = cost_mat [ 0 ]
    for row in range ( 1 , N ) :
        for curr_col in range ( M ) :
            val = 999999999
            for prev_col in range ( M ) :
                if curr_col != prev_col :
                    val = min ( val , dp [ row - 1 ] [ prev_col ] )
            dp [ row ] [ curr_col ] = val + cost_mat [ row ] [ curr_col ]
    return min ( dp [ - 1 ] )
if __name__ == " _ _ main _ _ " :
    N = 4
    M = 4
    cost_mat = [ [ 4 , 5 , 3 , 2 ] , [ 6 , 2 , 8 , 1 ] , [ 6 , 2 , 2 , 1 ] , [ 0 , 5 , 5 , 1 ] ]
    print ( findCost ( cost_mat , N , M ) )

Index/key variables: curr_col, prev_col, row
Iterator variables: curr_col, prev_col, row
Python program:
def getPrimesFromSeive ( primes ) :
    prime = [ True ] * ( 1000001 )
    prime [ 0 ] , prime [ 1 ] = False , False
    i = 2
    while ( i * i <= 1000000 ) :
        if ( prime [ i ] == True ) :
            for j in range ( i * i , 1000001 , i ) :
                prime [ j ] = False
        i += 1
    for i in range ( 2 , 1000001 ) :
        if ( prime [ i ] == True ) :
            primes . append ( str ( i ) )
def splitIntoPrimes ( number ) :
    numLen = len ( number )
    splitDP = [ - 1 ] * ( numLen + 1 )
    primes = [ ]
    getPrimesFromSeive ( primes )
    for i in range ( 1 , numLen + 1 ) :
        if ( i <= 6 and ( number [ 0 : i ] in primes ) ) :
            splitDP [ i ] = 1
        if ( splitDP [ i ] != - 1 ) :
            j = 1
            while ( j <= 6 and ( i + j <= numLen ) ) :
                if ( number [ i : i + j ] in primes ) :
                    if ( splitDP [ i + j ] == - 1 ) :
                        splitDP [ i + j ] = 1 + splitDP [ i ]
                    else :
                        splitDP [ i + j ] = min ( splitDP [ i + j ] , 1 + splitDP [ i ] )
                j += 1
    return splitDP [ numLen ]
print ( splitIntoPrimes ( "13499315" ) )
print ( splitIntoPrimes ( "43" ) )

Index/key variables: i, j, numLen
Accumulator variables: primes
Iterator variables: i, j
Python program:
import sys
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
        self . nextRight = None
    def __str__ ( self ) :
        return ' { } ' . format ( self . data )
def connect ( root ) :
    queue = [ ]
    queue . append ( root )
    queue . append ( None )
    while queue :
        p = queue . pop ( 0 )
        if p :
            p . nextRight = queue [ 0 ]
            if p . left :
                queue . append ( p . left )
            if p . right :
                queue . append ( p . right )
        elif queue :
            queue . append ( None )
def main ( ) :
    root = Node ( 10 )
    root . left = Node ( 8 )
    root . right = Node ( 2 )
    root . left . left = Node ( 3 )
    root . right . right = Node ( 90 )
    connect ( root )
    print ( " Following are populated nextRight pointers in " 	 " the tree ( - 1 is printed if there is no nextRight ) " )
    if ( root . nextRight != None ) :
        print ( " nextRight of % d is % d " % ( root . data , root . nextRight . data ) )
    else :
        print ( " nextRight of % d is % d " % ( root . data , - 1 ) )
    if ( root . left . nextRight != None ) :
        print ( " nextRight of % d is % d " % ( root . left . data , root . left . nextRight . data ) )
    else :
        print ( " nextRight of % d is % d " % ( root . left . data , - 1 ) )
    if ( root . right . nextRight != None ) :
        print ( " nextRight of % d is % d " % ( root . right . data , root . right . nextRight . data ) )
    else :
        print ( " nextRight of % d is % d " % ( root . right . data , - 1 ) )
    if ( root . left . left . nextRight != None ) :
        print ( " nextRight of % d is % d " % ( root . left . left . data , root . left . left . nextRight . data ) )
    else :
        print ( " nextRight of % d is % d " % ( root . left . left . data , - 1 ) )
    if ( root . right . right . nextRight != None ) :
        print ( " nextRight of % d is % d " % ( root . right . right . data , root . right . right . nextRight . data ) )
    else :
        print ( " nextRight of % d is % d " % ( root . right . right . data , - 1 ) )
    print ( )
if __name__ == " _ _ main _ _ " :
    main ( )
def printLevelByLevel ( root ) :
    if root :
        node = root
        while node :
            print ( ' { } ' . format ( node . data ) , end = ' ▁ ' )
            node = node . nextRight
        print ( )
        if root . left :
            printLevelByLevel ( root . left )
        else :
            printLevelByLevel ( root . right )
def inorder ( root ) :
    if root :
        inorder ( root . left )
        print ( root . data , end = ' ▁ ' )
        inorder ( root . right )

Accumulator variables: queue
Class/struct names: Node
Python program:
MOD = 1000000007 ;
def modInv ( a , p = MOD - 2 ) :
    s = 1 ;
    while ( p != 1 ) :
        if ( p % 2 ) :
            s = ( s * a ) % MOD ;
        a = ( a * a ) % MOD ;
        p //= 2 ;
    return ( a * s ) % MOD ;
def findCnt ( x , y ) :
    ans = 0 ;
    fact = [ 1 ] * ( len ( y ) + 1 ) ;
    for i in range ( 1 , len ( y ) ) :
        fact [ i ] = ( fact [ i - 1 ] * i ) % MOD ;
    for i in range ( len ( y ) ) :
        if ( y [ i ] == x ) :
            ans += ( modInv ( fact [ i ] ) * modInv ( fact [ len ( y ) - i - 1 ] ) ) % MOD ;
            ans %= MOD ;
    ans *= fact [ ( len ( y ) - 1 ) ] ;
    ans %= MOD ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    x = ' a ' ;
    y = " xxayy " ;
    print ( findCnt ( x , y ) ) ;

Index/key variables: i
Accumulator variables: ans, p
Iterator variables: i
Python program:
def findSubSeq ( arr , n ) :
    arr . sort ( ) ;
    count = [ 1 ] * n ;
    prev = [ - 1 ] * n ;
    max = 0 ;
    maxprev = - 1 ;
    for i in range ( n ) :
        for j in range ( i - 1 , - 1 , - 1 ) :
            if ( arr [ i ] % arr [ j ] == 0 and count [ j ] + 1 > count [ i ] ) :
                count [ i ] = count [ j ] + 1 ;
                prev [ i ] = j ;
        if ( max < count [ i ] ) :
            max = count [ i ] ;
            maxprev = i ;
    i = maxprev ;
    while ( i >= 0 ) :
        if ( arr [ i ] != - 1 ) :
            print ( arr [ i ] , end = " ▁ " ) ;
        i = prev [ i ] ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    findSubSeq ( arr , n ) ;

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