dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findMaxJumps ( arr , N ) :
    dp = [ 0 for i in range ( N ) ]
    ans = 0
    i = N - 1
    while ( i >= 0 ) :
        dp [ i ] = arr [ i ]
        j = i + arr [ i ]
        if ( j < N ) :
            dp [ i ] = dp [ i ] + dp [ j ]
        ans = max ( ans , dp [ i ] )
        i -= 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 5 , 7 , 9 ]
    N = len ( arr )
    findMaxJumps ( arr , N )

Index/key variables: i, j
Python program:
dp = [ [ [ - 1 for x in range ( 2 ) ] for y in range ( 10 ) ] for z in range ( 100 ) ]
def solve ( i , n , prev , sign ) :
    if ( i == n ) :
        return 1
    val = dp [ i ] [ prev ] [ sign ]
    if ( val != - 1 ) :
        return val
    val = 0
    if ( i == 0 ) :
        if ( n == 1 ) :
            digit = 0
        else :
            digit = 1
        while digit <= 9 :
            val += solve ( i + 1 , n , digit , sign )
            digit += 1
    elif ( i == 1 ) :
        for digit in range ( 10 ) :
            if ( digit != prev ) :
                val += solve ( i + 1 , n , digit , ( digit > prev ) )
    else :
        if ( sign == 1 ) :
            for digit in range ( prev - 1 , - 1 , - 1 ) :
                val += solve ( i + 1 , n , digit , 0 )
        else :
            for digit in range ( prev + 1 , 10 ) :
                val += solve ( i + 1 , n , digit , 1 )
    return val
def countNdigitNumber ( N ) :
    print ( solve ( 0 , N , 0 , 0 ) )
if __name__ == " _ _ main _ _ " :
    N = 3
    countNdigitNumber ( N )

Index/key variables: i, prev, sign
Accumulator variables: val
Iterator variables: digit
Python program:
def Count ( N , L , R ) :
    dp = [ [ 0 for i in range ( R - L + 1 ) ] for i in range ( N ) ]
    ans = 0
    for i in range ( N ) :
        dp [ i ] [ 0 ] = 1
    for i in range ( 1 , len ( dp [ 0 ] ) ) :
        dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 1
    ans = dp [ 0 ] [ R - L ]
    for i in range ( 1 , N ) :
        for j in range ( 1 , len ( dp [ 0 ] ) ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ]
        ans += dp [ i ] [ R - L ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 3
    L = 6
    R = 9
    print ( Count ( N , L , R ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def largestCommonSubarray ( arr , n , m ) :
    dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n ) ]
    for i in range ( n ) :
        for j in range ( m ) :
            dp [ i ] [ arr [ i ] [ j ] ] = j
    ans = 1
    len1 = 1
    for i in range ( 1 , m , 1 ) :
        check = True
        for j in range ( 1 , n , 1 ) :
            if ( dp [ j ] [ arr [ 0 ] [ i - 1 ] ] + 1 != dp [ j ] [ arr [ 0 ] [ i ] ] ) :
                check = False
                break
        if ( check ) :
            len1 += 1
            ans = max ( ans , len1 )
        else :
            len1 = 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    n = 4
    m = 5
    arr = [ [ 4 , 5 , 1 , 2 , 3 , 6 , 7 ] , [ 1 , 2 , 4 , 5 , 7 , 6 , 3 ] , [ 2 , 7 , 3 , 4 , 5 , 1 , 6 ] ]
    N = len ( arr )
    M = len ( arr [ 0 ] )
    print ( largestCommonSubarray ( arr , N , M ) )

Index/key variables: i, j
Accumulator variables: len1
Iterator variables: i, j
Boolean variables: check
Python program:
def MaximumSum ( a , b , n ) :
    dp = [ [ - 1 for j in range ( 2 ) ] for i in range ( n ) ]
    dp [ 0 ] [ 0 ] = a [ 0 ]
    dp [ 0 ] [ 1 ] = b [ 0 ]
    for i in range ( 1 , n ) :
        dp [ i ] [ 0 ] = max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + a [ i ]
        dp [ i ] [ 1 ] = max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] )
        if ( i - 2 >= 0 ) :
            dp [ i ] [ 1 ] = max ( dp [ i ] [ 1 ] , max ( dp [ i - 2 ] [ 0 ] , dp [ i - 2 ] [ 1 ] ) + b [ i ] )
        else :
            dp [ i ] [ 1 ] = max ( dp [ i ] [ 1 ] , b [ i ] )
    return max ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] )
if __name__ == ' _ _ main _ _ ' :
    A = [ 10 , 1 , 10 , 10 ]
    B = [ 5 , 50 , 1 , 5 ]
    N = len ( A )
    print ( MaximumSum ( A , B , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def noOfbarsVisibleFromLeft ( v ) :
    last = 0
    ans = 0
    for u in v :
        if ( last < u ) :
            ans += 1
            last = u
    return ans
def nextPermutation ( nums ) :
    i = len ( nums ) - 2
    while i > - 1 :
        if nums [ i ] < nums [ i + 1 ] :
            j = len ( nums ) - 1
            while j > i :
                if nums [ j ] > nums [ i ] :
                    break
                j -= 1
            nums [ i ] , nums [ j ] = nums [ j ] , nums [ i ]
            break
        i -= 1
    nums [ i + 1 : ] = reversed ( nums [ i + 1 : ] )
    return nums
def KvisibleFromLeft ( N , K ) :
    v = [ 0 ] * ( N )
    for i in range ( N ) :
        v [ i ] = i + 1
    ans = 0
    temp = list ( v )
    while True :
        if ( noOfbarsVisibleFromLeft ( v ) == K ) :
            ans += 1
        v = nextPermutation ( v )
        if v == temp :
            break
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 2
    print ( KvisibleFromLeft ( N , K ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, u
Python program:
def KvisibleFromLeft ( N , K ) :
    if ( N == K ) :
        return 1
    if ( K == 1 ) :
        ans = 1
        for i in range ( 1 , N , 1 ) :
            ans *= i
        return ans
    return KvisibleFromLeft ( N - 1 , K - 1 ) + ( N - 1 ) * KvisibleFromLeft ( N - 1 , K )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 2
    print ( KvisibleFromLeft ( N , K ) )

Accumulator variables: ans
Iterator variables: i
Python program:
def minimumDeletions ( A , N ) :
    ans = 10 ** 8
    for i in range ( 1 , ( 1 << N ) ) :
        temp = [ ]
        for j in range ( N ) :
            if ( ( i & ( 1 << j ) ) != 0 ) :
                temp . append ( A [ j ] )
        flag = 0
        for j in range ( 1 , len ( temp ) ) :
            if ( temp [ j ] < temp [ j - 1 ] ) :
                flag = 1
        for j in range ( 1 , len ( temp ) - 1 ) :
            if ( temp [ j ] - temp [ j - 1 ] > temp [ j + 1 ] - temp [ j ] ) :
                flag = 1
        if ( flag == 0 ) :
            ans = min ( ans , N - len ( temp ) )
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 4 , 5 , 7 , 20 , 21 ]
    N = len ( A )
    print ( minimumDeletions ( A , N ) )

Index/key variables: j
Accumulator variables: temp
Iterator variables: i, j
Python program:
def maximumSum ( A , N , K , D ) :
    ans = 0
    for i in range ( ( 1 << N ) ) :
        sum = 0
        c = 0
        for j in range ( N ) :
            if ( i >> j & 1 ) :
                sum += A [ j ]
                c += 1
        if ( sum % D == 0 and c <= K ) :
            ans = max ( ans , sum )
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 3
    D = 7
    A = [ 1 , 11 , 5 , 5 , 18 ]
    print ( maximumSum ( A , N , K , D ) )

Index/key variables: j
Accumulator variables: c, sum
Iterator variables: i, j
Python program:
def longestSubsequence ( X , Y ) :
    n = len ( X )
    m = len ( Y )
    mat = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( 0 , n + 1 ) :
        for j in range ( 0 , m + 1 ) :
            if ( i == 0 or j == 0 ) :
                mat [ i ] [ j ] = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            if ( X [ i - 1 ] == Y [ j - 1 ] ) :
                mat [ i ] [ j ] = 1 + mat [ i - 1 ] [ j - 1 ]
            else :
                mat [ i ] [ j ] = mat [ i - 1 ] [ j ]
    len1 = 0
    col = 0
    for i in range ( 0 , m + 1 ) :
        if ( mat [ n ] [ i ] > len1 ) :
            len1 = mat [ n ] [ i ]
            col = i
    res = " "
    i = n
    j = col
    while ( len1 > 0 ) :
        if ( X [ i - 1 ] == Y [ j - 1 ] ) :
            res = X [ i - 1 ] + res
            i -= 1
            j -= 1
            len1 -= 1
        else :
            i -= 1
    return res
X = " ABCD "
Y = " ACDBDCD "
print ( longestSubsequence ( X , Y ) )

Index/key variables: i, j, n
Accumulator variables: len1
Iterator variables: i, j
Python program:
sz = 1001
ok = [ [ 0 for i in range ( sz ) ] for i in range ( sz ) ]
dp = [ [ 0 for i in range ( sz ) ] for i in range ( sz ) ]
def minInvalidAreaUtil ( l , b ) :
    global dp , ok
    if ( dp [ l ] [ b ] == - 1 ) :
        if ( ok [ l ] [ b ] ) :
            dp [ l ] [ b ] = 0
            return dp [ l ] [ b ]
        ans = l * b
        for i in range ( 1 , b ) :
            ans = min ( ans , minInvalidAreaUtil ( l , i ) + minInvalidAreaUtil ( l , b - i ) )
        for i in range ( 1 , l ) :
            ans = min ( ans , minInvalidAreaUtil ( i , b ) + minInvalidAreaUtil ( l - i , b ) )
        dp [ l ] [ b ] = ans
    return dp [ l ] [ b ]
def minInvalidArea ( N , M , dimensions ) :
    global dp , ok
    K = len ( dimensions )
    for i in range ( K ) :
        ok [ dimensions [ i ] [ 0 ] ] [ dimensions [ i ] [ 1 ] ] = 1
        ok [ dimensions [ i ] [ 1 ] ] [ dimensions [ i ] [ 0 ] ] = 1
    for i in range ( sz ) :
        for j in range ( sz ) :
            dp [ i ] [ j ] = - 1
    minArea = minInvalidAreaUtil ( N , M )
    print ( minArea )
if __name__ == ' _ _ main _ _ ' :
    N , M = 10 , 10
    dimensions = [ [ 3 , 5 ] ]
    minInvalidArea ( N , M , dimensions )

Index/key variables: b, i, j, l
Iterator variables: i, j
Python program:
def countPairs ( arr ) :
    N = len ( arr )
    ans = 0
    M = { }
    for i in range ( len ( arr ) ) :
        if arr [ i ] in M :
            M [ arr [ i ] ] . append ( i )
        else :
            M [ arr [ i ] ] = [ i ]
    for key , value in M . items ( ) :
        v = value
        sum1 = 0
        for j in range ( len ( v ) ) :
            ans += ( sum1 * ( N - v [ j ] ) )
            sum1 += v [ j ] + 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 1 ]
    countPairs ( arr )

Index/key variables: i, j
Accumulator variables: ans, sum1
Iterator variables: i, j, key, value
Python program:
def countAlternatingSubstrings ( S , N ) :
    dp = [ [ 0 for i in range ( N ) ] for i in range ( 2 ) ]
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( i == N - 1 ) :
            if ( S [ i ] == '1' ) :
                dp [ 1 ] [ i ] = 1
            else :
                dp [ 0 ] [ i ] = 1
        else :
            if ( S [ i ] == '0' ) :
                dp [ 0 ] [ i ] = 1 + dp [ 1 ] [ i + 1 ]
            else :
                dp [ 1 ] [ i ] = 1 + dp [ 0 ] [ i + 1 ]
    ans = 0
    for i in range ( N ) :
        ans += max ( dp [ 0 ] [ i ] , dp [ 1 ] [ i ] )
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = "0010"
    N = len ( S )
    print ( countAlternatingSubstrings ( S , N ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def solve ( A , N , K ) :
    sum = 0
    c = 0
    for i in range ( N ) :
        sum += A [ i ]
        if ( A [ i ] == 0 ) :
            c += 1
    if ( K > sum or ( sum + K ) % 2 ) :
        return 0
    sum = ( sum + K ) // 2
    dp = [ [ 0 for i in range ( sum + 1 ) ] for j in range ( N + 1 ) ]
    for i in range ( sum + 1 ) :
        dp [ 0 ] [ i ] = 0
    for i in range ( N + 1 ) :
        dp [ i ] [ 0 ] = 1
    for i in range ( 1 , N + 1 , 1 ) :
        for j in range ( 1 , sum + 1 , 1 ) :
            if ( A [ i - 1 ] <= j and A [ i - 1 ] ) :
                dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - A [ i - 1 ] ] )
            else :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
    return dp [ N ] [ sum ] + pow ( 2 , c )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 1 , 2 , 3 ]
    N = len ( A )
    K = 3
    print ( solve ( A , N , K ) )

Index/key variables: N, i, j, sum
Accumulator variables: c
Iterator variables: i, j
Python program:
def maximizeAnd ( i , mask , A , B , N , dp ) :
    if ( i == N ) :
        return 0
    if ( dp [ i ] [ mask ] != - 1 ) :
        return dp [ i ] [ mask ]
    for j in range ( N ) :
        if ( ( mask & ( 1 << j ) ) == 0 ) :
            dp [ i ] [ mask ] = max ( dp [ i ] [ mask ] , ( A [ i ] & B [ j ] ) + maximizeAnd ( i + 1 , mask | ( 1 << j ) , A , B , N , dp ) )
    return dp [ i ] [ mask ]
def maximizeAndUtil ( A , B , N ) :
    temp = [ - 1 for i in range ( 1 << N + 1 ) ]
    dp = [ temp for i in range ( N ) ]
    return maximizeAnd ( 0 , 0 , A , B , N , dp )
if __name__ == ' _ _ main _ _ ' :
    A = [ 3 , 5 , 7 , 11 ]
    B = [ 2 , 6 , 10 , 12 ]
    N = len ( A )
    print ( maximizeAndUtil ( A , B , N ) )

Index/key variables: i, j, mask
Iterator variables: j
Python program:
def maximumStonesUtil ( arr , n , i , dp ) :
    if ( i >= n ) :
        return 0
    ans = dp [ i ]
    if ( ans != - 1 ) :
        return ans
    ans = - 2 ** 31
    ans = max ( ans , arr [ i ] - maximumStonesUtil ( arr , n , i + 1 , dp ) )
    if ( i + 1 < n ) :
        ans = max ( ans , arr [ i ] + arr [ i + 1 ] - maximumStonesUtil ( arr , n , i + 2 , dp ) )
    if ( i + 2 < n ) :
        ans = max ( ans , arr [ i ] + arr [ i + 1 ] + arr [ i + 2 ] - maximumStonesUtil ( arr , n , i + 3 , dp ) )
    return ans
def maximumStones ( arr , n ) :
    dp = [ - 1 ] * n
    res = maximumStonesUtil ( arr , n , 0 , dp )
    if ( res > 0 ) :
        return " Player1"
    elif ( res < 0 ) :
        return " Player2"
    else :
        return " Tie "
arr = [ 1 , 2 , 3 , 7 ]
n = len ( arr )
print ( maximumStones ( arr , n ) )

Index/key variables: i
Python program:
def numberOfWays ( N ) :
    DP = [ [ 0 for i in range ( 5 ) ] for i in range ( N + 1 ) ]
    DP [ 1 ] [ 1 ] = 1
    DP [ 1 ] [ 2 ] = 1
    DP [ 1 ] [ 3 ] = 1
    DP [ 1 ] [ 4 ] = 1
    for i in range ( 2 , N + 1 ) :
        if ( i - 1 > 0 and DP [ i - 1 ] [ 1 ] > 0 ) :
            DP [ i ] [ 1 ] = DP [ i - 1 ] [ 4 ]
        if ( i - 2 > 0 and DP [ i - 2 ] [ 2 ] > 0 ) :
            DP [ i ] [ 2 ] = DP [ i - 2 ] [ 4 ]
        if ( i - 3 > 0 and DP [ i - 3 ] [ 3 ] > 0 ) :
            DP [ i ] [ 3 ] = DP [ i - 3 ] [ 4 ]
        DP [ i ] [ 4 ] = ( DP [ i ] [ 1 ] + DP [ i ] [ 2 ] + DP [ i ] [ 3 ] )
    return DP [ N ] [ 4 ]
if __name__ == ' _ _ main _ _ ' :
    N = 15
    print ( numberOfWays ( N ) )

Index/key variables: N, i
Iterator variables: i
Python program:
def maximumSum ( arr , n ) :
    preSum = [ 0 ] * n
    sum = 0
    maxSum = 0
    for i in range ( n ) :
        sum = max ( arr [ i ] , sum + arr [ i ] )
        maxSum = max ( maxSum , sum )
        preSum [ i ] = maxSum
    sum = 0
    maxSum = 0
    postSum = [ 0 ] * ( n + 1 )
    for i in range ( n - 1 , - 1 , - 1 ) :
        sum = max ( arr [ i ] , sum + arr [ i ] )
        maxSum = max ( maxSum , sum )
        postSum [ i ] = maxSum
    ans = 0
    for i in range ( n ) :
        ans = max ( ans , preSum [ i ] + postSum [ i + 1 ] )
    print ( ans )
arr = [ 7 , 6 , - 1 , - 4 , - 5 , 7 , 1 ]
N = len ( arr )
maximumSum ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def lisOtimised ( s ) :
    dp = [ 0 ] * 30
    N = len ( s )
    lis = - 10 ** 9
    for i in range ( N ) :
        val = ord ( s [ i ] ) - ord ( ' a ' )
        curr = 0
        for j in range ( val ) :
            curr = max ( curr , dp [ j ] )
        curr += 1
        lis = max ( lis , curr )
        dp [ val ] = max ( dp [ val ] , curr )
    return lis
if __name__ == ' _ _ main _ _ ' :
    s = " fdryutiaghfse "
    print ( lisOtimised ( s ) )

Index/key variables: i, j, val
Accumulator variables: curr
Iterator variables: i, j
Python program:
MAX = 1e9
def MinimumLength ( A , N , K ) :
    A . sort ( )
    suffix = [ 0 ] * ( N + 1 )
    for i in range ( N - 1 , - 1 , - 1 ) :
        suffix [ i ] = suffix [ i + 1 ] + A [ i ]
    dp = [ [ 0 ] * ( K + 1 ) ] * ( N + 1 )
    for i in range ( N + 1 ) :
        for j in range ( K + 1 ) :
            dp [ i ] [ j ] = MAX
    dp [ N ] [ 0 ] = 0
    for i in range ( N - 1 , - 1 , - 1 ) :
        for j in range ( K , - 1 , - 1 ) :
            if ( j <= A [ i ] ) :
                dp [ i ] [ j ] = A [ i ]
                continue
            if ( dp [ i + 1 ] [ j - A [ i ] ] == MAX ) :
                dp [ i ] [ j ] = MAX
            else :
                dp [ i ] [ j ] = min ( dp [ i + 1 ] [ j ] , dp [ i + 1 ] [ j - A [ i ] ] + A [ i ] )
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( suffix [ i ] - dp [ i ] [ K ] >= K ) :
            return N - i
    return - 1
arr = [ 7 , 4 , 5 , 6 , 8 ]
K = 13
N = len ( arr )
print ( MinimumLength ( arr , N , K ) )

Index/key variables: K, N, i, j
Iterator variables: i, j
Python program:
dp = [ 0 ] * 20
ans = 0
def insertVector ( mask ) :
    global dp , ans
    for i in range ( 20 ) :
        if ( ( mask & 1 << i ) == 0 ) :
            continue
        if ( not dp [ i ] ) :
            dp [ i ] = mask
            ans += 1
            return
        mask ^= dp [ i ]
def maxSizeSet ( arr , N ) :
    for i in range ( N ) :
        insertVector ( arr [ i ] )
    print ( ( 1 << ans ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    N = len ( arr )
    maxSizeSet ( arr , N )

Index/key variables: i
Accumulator variables: ans, mask
Iterator variables: i
Python program:
def maxSum ( arr , N , K ) :
    dp = [ 0 for i in range ( N + 2 ) ]
    maxval = 0
    i = N - 1
    while ( i >= 0 ) :
        if ( ( i + K * arr [ i ] ) >= N ) :
            dp [ i ] = arr [ i ]
        else :
            dp [ i ] = dp [ i + K * arr [ i ] ] + arr [ i ]
        maxval = max ( maxval , dp [ i ] )
        i -= 1
    print ( maxval )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 3 , 1 , 2 ]
    N = len ( arr )
    K = 3
    maxSum ( arr , N , K )

Index/key variables: i
Python program:
def maxSubmatrixSum ( matrix ) :
    r = len ( matrix )
    c = len ( matrix [ 0 ] )
    maxSubmatrix = 0
    for i in range ( r ) :
        for j in range ( c ) :
            for k in range ( i , r ) :
                for l in range ( j , c ) :
                    sumSubmatrix = 0
                    for m in range ( i , k + 1 ) :
                        for n in range ( j , l + 1 ) :
                            sumSubmatrix += matrix [ m ] [ n ]
                    maxSubmatrix = max ( maxSubmatrix , sumSubmatrix )
    print ( maxSubmatrix )
if __name__ == ' _ _ main _ _ ' :
    matrix = [ [ 0 , - 2 , - 7 , 0 ] , [ 9 , 2 , - 6 , 2 ] , [ - 4 , 1 , - 4 , 1 ] , [ - 1 , 8 , 0 , - 2 ] ]
    maxSubmatrixSum ( matrix )

Index/key variables: m, n
Accumulator variables: sumSubmatrix
Iterator variables: i, j, k, l, m, n
Python program:
def maximumSubsetSum ( arr1 , arr2 , length ) :
    dp = [ 0 ] * ( length + 1 )
    if ( length == 1 ) :
        print ( max ( arr1 [ 0 ] , arr2 [ 0 ] ) )
        return
    if ( length == 2 ) :
        print ( max ( max ( arr1 [ 1 ] , arr2 [ 1 ] ) , max ( arr1 [ 0 ] , arr2 [ 0 ] ) ) )
        return
    else :
        dp [ 0 ] = max ( arr1 [ 0 ] , arr2 [ 0 ] )
        dp [ 1 ] = max ( max ( arr1 [ 1 ] , arr2 [ 1 ] ) , max ( arr1 [ 0 ] , arr2 [ 0 ] ) )
        index = 2
        while ( index < length ) :
            dp [ index ] = max ( max ( arr1 [ index ] , arr2 [ index ] ) , max ( max ( arr1 [ index ] + dp [ index - 2 ] , arr2 [ index ] + dp [ index - 2 ] ) , dp [ index - 1 ] ) )
            index += 1
        print ( dp [ length - 1 ] )
arr1 = [ - 1 , - 2 , 4 , - 4 , 5 ]
arr2 = [ - 1 , - 2 , - 3 , 4 , 10 ]
length = 5
maximumSubsetSum ( arr1 , arr2 , length )

Index/key variables: index
Python program:
def minAtEachIndex ( n , arr ) :
    dp1 = [ 0 ] * n
    dp2 = [ 0 ] * n
    i = 0
    dp1 [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        dp1 [ i ] = min ( arr [ i ] , dp1 [ i - 1 ] + 1 )
    dp2 [ n - 1 ] = arr [ n - 1 ]
    for i in range ( n - 2 , - 1 , - 1 ) :
        dp2 [ i ] = min ( arr [ i ] , dp2 [ i + 1 ] + 1 )
    v = [ ]
    for i in range ( 0 , n ) :
        v . append ( min ( dp1 [ i ] , dp2 [ i ] ) )
    for x in v :
        print ( x , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 4 , 2 , 5 , 3 ]
    N = len ( arr )
    minAtEachIndex ( N , arr )

Index/key variables: i
Accumulator variables: v
Iterator variables: i, x
Python program:
def totalArrays ( N , M ) :
    end_with_one = [ 0 ] * ( N + 1 ) ;
    end_not_with_one = [ 0 ] * ( N + 1 ) ;
    end_with_one [ 0 ] = 1 ;
    end_not_with_one [ 0 ] = 0 ;
    end_with_one [ 1 ] = 0 ;
    end_not_with_one [ 1 ] = M - 1 ;
    for i in range ( 2 , N ) :
        end_with_one [ i ] = end_not_with_one [ i - 1 ] ;
        end_not_with_one [ i ] = end_with_one [ i - 1 ] * ( M - 1 ) + end_not_with_one [ i - 1 ] * ( M - 2 ) ;
    return end_with_one [ N - 1 ] ;
if __name__ == ' _ _ main _ _ ' :
    N = 3 ;
    M = 3 ;
    temp = totalArrays ( N , M ) ;
    ans = M * temp ;
    print ( ans ) ;

Index/key variables: i
Iterator variables: i
Python program:
def prodOfDigit ( N ) :
    res = 1
    while ( N ) :
        res = res * ( N % 10 )
        N //= 10
    return res
def cntNumRange ( L , R , K ) :
    cnt = 0
    for i in range ( L , R + 1 ) :
        if ( prodOfDigit ( i ) == K ) :
            cnt += 1
    return cnt
if __name__ == ' _ _ main _ _ ' :
    L , R , K = 20 , 10000 , 14
    print ( cntNumRange ( L , R , K ) )

Accumulator variables: N, cnt
Iterator variables: i
Python program:
def findMedXOR ( mat , N , M ) :
    dp = [ [ 0 for i in range ( M ) ] for j in range ( N ) ] ;
    med = [ 0 ] * ( N * M ) ;
    dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;
    med [ 0 ] = dp [ 0 ] [ 0 ] ;
    len = 1 ;
    for i in range ( 1 , N ) :
        dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ^ mat [ i ] [ 0 ] ;
        med [ len ] = dp [ i ] [ 0 ] ;
        len += 1 ;
    for i in range ( 1 , M ) :
        dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ^ mat [ 0 ] [ i ] ;
        med [ len ] = dp [ 0 ] [ i ] ;
        len += 1
    for i in range ( 1 , N ) :
        for j in range ( 1 , M ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ^ dp [ i ] [ j - 1 ] ^ dp [ i - 1 ] [ j - 1 ] ^ mat [ i ] [ j ] ;
            med [ len ] = dp [ i ] [ j ] ;
            len += 1
    med . sort ( ) ;
    if ( len % 2 == 0 ) :
        return ( med [ ( len // 2 ) ] + med [ ( len // 2 ) - 1 ] ) / 2.0 ;
    return med [ len // 2 ] ;
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 2 ] , [ 2 , 3 ] ] ;
    N = len ( mat [ 0 ] ) ;
    M = 2 ;
    print ( findMedXOR ( mat , N , M ) ) ;

Index/key variables: i, j, len
Iterator variables: i, j
Python program:
def countWaysToTileBoard ( N ) :
    dp = [ 0 ] * ( N + 1 )
    dp [ 0 ] = 1
    dp [ 1 ] = 2
    for i in range ( 2 , N + 1 ) :
        dp [ i ] = ( 2 * dp [ i - 1 ] + dp [ i - 2 ] )
    print ( dp [ N ] )
if __name__ == " _ _ main _ _ " :
    N = 2
    countWaysToTileBoard ( N )

Index/key variables: N, i
Iterator variables: i
Python program:
def FindSub ( string , res , i ) :
    if ( i == len ( string ) ) :
        if ( len ( res ) > 0 ) :
            print ( res , end = " ▁ " ) ;
        return ;
    ch = string [ i ] ;
    FindSub ( string , res , i + 1 ) ;
    FindSub ( string , res + ch , i + 1 ) ;
    FindSub ( string , res + str ( ord ( ch ) ) , i + 1 ) ;
if __name__ == " _ _ main _ _ " :
    string = " ab " ;
    res = " " ;
    N = len ( string ) ;
    FindSub ( string , res , 0 ) ;

Index/key variables: i