dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
MAX = 300
def checkFunc ( i , j , st ) :
    if ( st [ i ] == ' ( ' and st [ j ] == ' ) ' ) :
        return 1
    if ( st [ i ] == ' ( ' and st [ j ] == ' ? ' ) :
        return 1
    if ( st [ i ] == ' ? ' and st [ j ] == ' ) ' ) :
        return 1
    if ( st [ i ] == ' [ ' and st [ j ] == ' ] ' ) :
        return 1
    if ( st [ i ] == ' [ ' and st [ j ] == ' ? ' ) :
        return 1
    if ( st [ i ] == ' ? ' and st [ j ] == ' ] ' ) :
        return 1
    if ( st [ i ] == ' { ' and st [ j ] == ' } ' ) :
        return 1
    if ( st [ i ] == ' { ' and st [ j ] == ' ? ' ) :
        return 1
    if ( st [ i ] == ' ? ' and st [ j ] == ' } ' ) :
        return 1
    return 0
def countRec ( start , end , dp , st ) :
    sum = 0
    if ( start > end ) :
        return 1
    if ( dp [ start ] [ end ] != - 1 ) :
        return dp [ start ] [ end ]
    r = 0
    for i in range ( start + 1 , end + 1 , 2 ) :
        if ( checkFunc ( start , i , st ) ) :
            sum = ( sum + countRec ( start + 1 , i - 1 , dp , st ) * countRec ( i + 1 , end , dp , st ) )
        elif ( st [ start ] == ' ? ' and st [ i ] == ' ? ' ) :
            sum = ( sum + countRec ( start + 1 , i - 1 , dp , st ) * countRec ( i + 1 , end , dp , st ) * 3 )
    dp [ start ] [ end ] = sum
    return dp [ start ] [ end ]
def countWays ( st ) :
    n = len ( st )
    if ( n % 2 == 1 ) :
        return 0
    dp = [ [ - 1 for i in range ( MAX ) ] for i in range ( MAX ) ]
    return countRec ( 0 , n - 1 , dp , st )
if __name__ == " _ _ main _ _ " :
    st = " ( ? ( [ ? ) ] ? } ? "
    print ( countWays ( st ) )

Index/key variables: end, i, j, start
Iterator variables: i
Python program:
dp = [ [ [ [ - 1 , - 1 ] for i in range ( 64 ) ] for j in range ( 64 ) ] for k in range ( 64 ) ]
def func ( third , seta , setb , carry , number ) :
    if dp [ third ] [ seta ] [ setb ] [ carry ] != - 1 :
        return dp [ third ] [ seta ] [ setb ] [ carry ]
    shift = number >> third
    if ( shift == 0 and seta == 0 and setb == 0 and carry == 0 ) :
        return 1
    if ( shift == 0 or seta < 0 or setb < 0 ) :
        return 0
    mask = shift & 1
    dp [ third ] [ seta ] [ setb ] [ carry ] = 0
    if ( mask ) and carry :
        dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta , setb , 0 , number ) + func ( third + 1 , seta - 1 , setb - 1 , 1 , number )
    elif mask and not carry :
        dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta - 1 , setb , 0 , number ) + func ( third + 1 , seta , setb - 1 , 0 , number )
    elif not mask and carry :
        dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta - 1 , setb , 1 , number ) + func ( third + 1 , seta , setb - 1 , 1 , number )
    elif not mask and not carry :
        dp [ third ] [ seta ] [ setb ] [ carry ] += func ( third + 1 , seta , setb , 0 , number ) + func ( third + 1 , seta - 1 , setb - 1 , 1 , number )
    return dp [ third ] [ seta ] [ setb ] [ carry ]
def possibleSwaps ( a , b , c ) :
    ans = func ( 0 , a , b , 0 , c )
    return ans
if __name__ == " _ _ main _ _ " :
    x , y , c = 2 , 2 , 20
    print ( possibleSwaps ( x , y , c ) )

Index/key variables: carry, seta, setb, third
Python program:
def calculateEvenSum ( n ) :
    if n <= 0 :
        return 0
    fibo = [ 0 ] * ( 2 * n + 1 )
    fibo [ 0 ] , fibo [ 1 ] = 0 , 1
    sum = 0
    for i in range ( 2 , 2 * n + 1 ) :
        fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]
        if i % 2 == 0 :
            sum += fibo [ i ]
    return sum
if __name__ == " _ _ main _ _ " :
    n = 8
    print ( " Even ▁ indexed ▁ Fibonacci ▁ Sum ▁ upto " , n , " terms : " , calculateEvenSum ( n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
MAX = 1000 ;
f = [ 0 ] * MAX ;
def fib ( n ) :
    if ( n == 0 ) :
        return 0 ;
    if ( n == 1 or n == 2 ) :
        f [ n ] = 1 ;
        return f [ n ] ;
    if ( f [ n ] ) :
        return f [ n ] ;
    k = ( n + 1 ) // 2 if ( n % 2 == 1 ) else n // 2 ;
    f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) if ( n % 2 == 1 ) else ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;
    return f [ n ] ;
def calculateEvenSum ( n ) :
    return ( fib ( 2 * n + 1 ) - 1 ) ;
if __name__ == ' _ _ main _ _ ' :
    n = 8 ;
    print ( " Even ▁ indexed ▁ Fibonacci ▁ Sum ▁ upto " , n , " terms : " , calculateEvenSum ( n ) ) ;

Index/key variables: n
Python program:
MAX = 32768
arr = [ None ] * ( 2 * MAX )
def gouldSequence ( ) :
    arr [ 0 ] = 1
    i = 1
    p = 1
    while i <= MAX :
        j = 0
        while j < i :
            arr [ i + j ] = 2 * arr [ j ]
            j += 1
        i = ( 1 << p )
        p += 1
def printSequence ( n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    gouldSequence ( )
    n = 16
    printSequence ( n )

Index/key variables: i, j
Accumulator variables: p
Iterator variables: i
Python program:
def factorial ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res *= i
    return res
def countWays ( m , n ) :
    m = m - 1
    n = n - 1
    return ( factorial ( m + n ) // ( factorial ( m ) * factorial ( n ) ) )
m = 5
n = 5
result = countWays ( m , n )
print ( result )

Accumulator variables: res
Iterator variables: i
Python program:
def MatrixChainOrder ( p , n ) :
    dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
    for i in range ( 1 , n ) :
        dp [ i ] [ i ] = 0
    for L in range ( 1 , n - 1 ) :
        for i in range ( n - L ) :
            dp [ i ] [ i + L ] = min ( dp [ i + 1 ] [ i + L ] + p [ i - 1 ] * p [ i ] * p [ i + L ] , dp [ i ] [ i + L - 1 ] + p [ i - 1 ] * p [ i + L - 1 ] * p [ i + L ] )
    return dp [ 1 ] [ n - 1 ]
arr = [ 10 , 20 , 30 , 40 , 30 ]
size = len ( arr )
print ( " Minimum ▁ number ▁ of ▁ multiplications ▁ is " , MatrixChainOrder ( arr , size ) )

Index/key variables: i
Iterator variables: L, i
Python program:
def CommomSubsequencesCount ( s , t ) :
    n1 = len ( s )
    n2 = len ( t )
    dp = [ [ 0 for i in range ( n2 + 1 ) ] for i in range ( n1 + 1 ) ]
    for i in range ( 1 , n1 + 1 ) :
        for j in range ( 1 , n2 + 1 ) :
            if ( s [ i - 1 ] == t [ j - 1 ] ) :
                dp [ i ] [ j ] = ( 1 + dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j ] )
            else :
                dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j ] - dp [ i - 1 ] [ j - 1 ] )
    return dp [ n1 ] [ n2 ]
s = " ajblqcpdz "
t = " aefcnbtdi "
print ( CommomSubsequencesCount ( s , t ) )

Index/key variables: i, j, n1, n2
Iterator variables: i, j
Python program:
def createPalindrome ( _input , isOdd ) :
    n = palin = _input
    if isOdd :
        n //= 10
    while n > 0 :
        palin = palin * 10 + ( n % 10 )
        n //= 10
    return palin
def generatePalindromes ( N ) :
    palindromes = [ ]
    for j in range ( 0 , 2 ) :
        i = 1
        number = createPalindrome ( i , j )
        while number <= N :
            palindromes . append ( number )
            i += 1
            number = createPalindrome ( i , j )
    return palindromes
def minimumNoOfPalindromes ( N ) :
    b = a = str ( N )
    b = b [ : : - 1 ]
    if a == b :
        return 1
    palindromes = generatePalindromes ( N )
    palindromes . sort ( )
    l , r = 0 , len ( palindromes ) - 1
    while l < r :
        if palindromes [ l ] + palindromes [ r ] == N :
            return 2
        elif palindromes [ l ] + palindromes [ r ] < N :
            l += 1
        else :
            r -= 1
    return 3
if __name__ == " _ _ main _ _ " :
    N = 65
    print ( minimumNoOfPalindromes ( N ) )

Index/key variables: l, r
Accumulator variables: i, n, palindromes
Iterator variables: j
Python program:
def lcs ( dp , a , b , m , n ) :
    for i in range ( 100 ) :
        for j in range ( 100 ) :
            dp [ i ] [ j ] = - 1
    if ( m < 0 or n < 0 ) :
        return 0
    if ( dp [ m ] [ n ] != - 1 ) :
        return dp [ m ] [ n ]
    ans = 0
    if ( a [ m ] == b [ n ] ) :
        ans = ( ord ( a [ m ] ) - 48 ) + lcs ( dp , a , b , m - 1 , n - 1 )
    else :
        ans = max ( lcs ( dp , a , b , m - 1 , n ) , lcs ( dp , a , b , m , n - 1 ) )
    dp [ m ] [ n ] = ans
    return ans
def costOfString ( s ) :
    cost = 0
    for i in range ( len ( s ) ) :
        cost += ( ord ( s [ i ] ) - 48 )
    return cost
if __name__ == " _ _ main _ _ " :
    a = "9142"
    b = "1429"
    dp = [ [ 0 for x in range ( 101 ) ] for y in range ( 101 ) ]
    print ( costOfString ( a ) + costOfString ( b ) - 2 * lcs ( dp , a , b , len ( a ) - 1 , len ( b ) - 1 ) )

Index/key variables: i, j, m, n
Accumulator variables: cost
Iterator variables: i, j
Python program:
def countPartitions ( n , k ) :
    dp = [ [ 0 ] * 201 ] * 201
    for i in range ( n + 1 ) :
        for j in range ( n + 1 ) :
            dp [ i ] [ j ] = - 1
    if ( dp [ n ] [ k ] >= 0 ) :
        return dp [ n ] [ k ]
    if ( n < k ) :
        return 0
    if ( n < 2 * k ) :
        return 1
    answer = 1
    for i in range ( k , n ) :
        answer = ( answer + countPartitions ( n - i , i ) )
    dp [ n ] [ k ] = answer
    return answer
n = 10
k = 3
print ( " Total ▁ Aggregate ▁ sum ▁ of ▁ all ▁ " " Valid ▁ Partitions : ▁ " , countPartitions ( n , k ) * n )

Index/key variables: i, j, k, n
Iterator variables: i, j
Python program:
from math import gcd
def makePairs ( pairs , a , b ) :
    for i in range ( a , b + 1 , 1 ) :
        sumOfDigits = 0
        k = i
        while ( k > 0 ) :
            sumOfDigits += k % 10
            k = int ( k / 10 )
        if ( sumOfDigits <= 162 ) :
            pairs . append ( sumOfDigits )
def countCoPrime ( a , b ) :
    pairs = [ ]
    makePairs ( pairs , a , b )
    count = 0
    for i in range ( 0 , len ( pairs ) , 1 ) :
        for j in range ( i + 1 , len ( pairs ) , 1 ) :
            if ( gcd ( pairs [ i ] , pairs [ j ] ) == 1 ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    a = 12
    b = 15
    print ( countCoPrime ( a , b ) )

Index/key variables: i, j
Accumulator variables: count, pairs, sumOfDigits
Iterator variables: i, j
Python program:
import math
def recursive ( idx , sum , tight , st , dp , num ) :
    if ( idx == num ) :
        return sum == 0
    if ( dp [ idx ] [ tight ] [ sum ] != - 1 ) :
        return dp [ idx ] [ tight ] [ sum ]
    ans = 0
    for d in range ( 10 ) :
        newTight = False
        if ( tight and ord ( st [ idx ] ) - ord ( '0' ) < d ) :
            continue
        if ( tight and ord ( st [ idx ] ) - ord ( '0' ) == d ) :
            newTight = True
        if ( sum >= d ) :
            ans += recursive ( idx + 1 , sum - d , newTight , st , dp , num )
    dp [ idx ] [ tight ] [ sum ] = ans
    return dp [ idx ] [ tight ] [ sum ]
def formArray ( N ) :
    dp = [ [ [ - 1 for x in range ( 166 ) ] for y in range ( 2 ) ] for z in range ( 20 ) ]
    st = str ( N )
    num = len ( st )
    arr = [ ]
    for i in range ( 1 , 163 ) :
        arr . append ( recursive ( 0 , i , 1 , st , dp , num ) )
    return arr
def findPair ( a , b ) :
    arr_smaller = formArray ( a - 1 )
    arr_greater = formArray ( b )
    for i in range ( len ( arr_greater ) ) :
        arr_greater [ i ] -= arr_smaller [ i ]
    ans = 0
    for i in range ( 1 , 163 ) :
        for j in range ( i + 1 , 163 ) :
            if ( math . gcd ( i , j ) == 1 ) :
                ans = ( ans + arr_greater [ i - 1 ] * arr_greater [ j - 1 ] )
    return ans
if __name__ == " _ _ main _ _ " :
    a = 12
    b = 15
    print ( findPair ( a , b ) )

Index/key variables: i, idx, sum, tight
Accumulator variables: ans, arr
Iterator variables: d, i, j
Boolean variables: newTight
Python program:
import math
def factors ( n ) :
    v = [ ]
    v . append ( 1 )
    sqt = int ( math . sqrt ( n ) )
    for i in range ( 2 , sqt + 1 ) :
        if ( n % i == 0 ) :
            v . append ( i )
            if ( n // i != i ) :
                v . append ( n // i )
    return v
def check ( n ) :
    v = [ ]
    v = factors ( n )
    v . sort ( )
    r = len ( v )
    subset = [ [ 0 for i in range ( n + 1 ) ] for j in range ( r + 1 ) ]
    for i in range ( r + 1 ) :
        subset [ i ] [ 0 ] = True
    for i in range ( 1 , n + 1 ) :
        subset [ 0 ] [ i ] = False
    for i in range ( 1 , r + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if ( j < v [ i - 1 ] ) :
                subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;
            else :
                subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - v [ i - 1 ] ] )
    if ( ( subset [ r ] [ n ] ) == 0 ) :
        return False
    else :
        return True
if __name__ == " _ _ main _ _ " :
    n = 40
    if ( check ( n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j, n, r
Accumulator variables: v
Iterator variables: i, j
Python program:
fib = [ 0 ] * 43
def fibonacci ( ) :
    fib [ 0 ] = 1
    fib [ 1 ] = 2
    for i in range ( 2 , 43 ) :
        fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ]
def rec ( x , y , last ) :
    if y == 0 :
        if x == 0 :
            return 1
        return 0
    Sum , i = 0 , last
    while i >= 0 and fib [ i ] * y >= x :
        if fib [ i ] > x :
            i -= 1
            continue
        Sum += rec ( x - fib [ i ] , y - 1 , i )
        i -= 1
    return Sum
if __name__ == " _ _ main _ _ " :
    fibonacci ( )
    n , k = 13 , 3
    print ( " Possible ▁ ways ▁ are : " , rec ( n , k , 42 ) )

Index/key variables: i
Accumulator variables: Sum
Iterator variables: i
Python program:
def minimumCost ( cost , n ) :
    dp = [ None ] * n
    if n == 1 :
        return cost [ 0 ]
    dp [ 0 ] = cost [ 0 ]
    dp [ 1 ] = cost [ 1 ]
    for i in range ( 2 , n ) :
        dp [ i ] = min ( dp [ i - 1 ] , dp [ i - 2 ] ) + cost [ i ]
    return min ( dp [ n - 2 ] , dp [ n - 1 ] )
if __name__ == " _ _ main _ _ " :
    a = [ 16 , 19 , 10 , 12 , 18 ]
    n = len ( a )
    print ( minimumCost ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def minimumCost ( cost , n ) :
    dp1 = 0
    dp2 = 0
    for i in range ( n ) :
        dp0 = cost [ i ] + min ( dp1 , dp2 )
        dp2 = dp1
        dp1 = dp0
    return min ( dp1 , dp2 )
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 5 , 3 , 1 , 7 , 3 , 4 ]
    n = len ( a )
    print ( minimumCost ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
size = 1000 ;
def maxCost ( a , m , n , dp ) :
    if ( n < 0 or m < 0 ) :
        return int ( - 1e9 ) ;
    elif ( m == 0 and n == 0 ) :
        return 0 ;
    elif ( dp [ m ] [ n ] != - 1 ) :
        return dp [ m ] [ n ] ;
    else :
        num = m + n ;
        if ( ( num & ( num - 1 ) ) == 0 ) :
            dp [ m ] [ n ] = a [ m ] [ n ] + maxCost ( a , m - 1 , n - 1 , dp ) ;
            return dp [ m ] [ n ] ;
        else :
            dp [ m ] [ n ] = ( a [ m ] [ n ] + max ( maxCost ( a , m - 1 , n , dp ) , maxCost ( a , m , n - 1 , dp ) ) ) ;
            return dp [ m ] [ n ] ;
def answer ( a , n ) :
    dp = [ [ 0 for i in range ( size ) ] for j in range ( size ) ] ;
    for i in range ( size ) :
        for j in range ( size ) :
            dp [ i ] [ j ] = - 1 ;
    return maxCost ( a , n - 1 , n - 1 , dp ) ;
if __name__ == ' _ _ main _ _ ' :
    a = [ [ 1 , 2 , 3 , 1 ] , [ 4 , 5 , 6 , 1 ] , [ 7 , 8 , 9 , 1 ] , [ 1 , 1 , 1 , 1 ] ] ;
    n = 4 ;
    print ( answer ( a , n ) ) ;

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def editDistanceWith2Ops ( X , Y ) :
    m = len ( X )
    n = len ( Y )
    L = [ [ 0 for x in range ( n + 1 ) ] for y 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 ] + 1
            else :
                L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] )
    lcs = L [ m ] [ n ]
    return ( m - lcs ) + ( n - lcs )
if __name__ == " _ _ main _ _ " :
    X = " abc "
    Y = " acd "
    print ( editDistanceWith2Ops ( X , Y ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def countPaths ( n ) :
    zB = 1
    zADC = 0
    for i in range ( 1 , n + 1 ) :
        nzB = zADC * 3
        nzADC = ( zADC * 2 + zB )
        zB = nzB
        zADC = nzADC
    return zB
n = 3
print ( countPaths ( n ) )

Iterator variables: i
Python program:
def sumSubSequence ( arr , length , m ) :
    summ = 0
    for i in arr :
        summ += i
    dp = [ [ 0 for i in range ( summ + 1 ) ] for j in range ( length + 1 ) ]
    for i in range ( length + 1 ) :
        dp [ i ] [ 0 ] += 1
    for i in range ( 1 , length + 1 ) :
        dp [ i ] [ arr [ i - 1 ] ] += 1
        for j in range ( 1 , summ + 1 ) :
            if dp [ i - 1 ] [ j ] > 0 :
                dp [ i ] [ j ] += 1
                dp [ i ] [ j + arr [ i - 1 ] ] += 1
    count = 0
    for i in range ( 1 , summ + 1 ) :
        if dp [ length ] [ i ] > 0 :
            if i % m == 0 :
                count += dp [ length ] [ i ]
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 ]
    m = 3
    length = len ( arr )
    print ( sumSubSequence ( arr , length , m ) )

Index/key variables: i, j, length
Accumulator variables: count, summ
Iterator variables: i, j
Python program:
def lds ( arr , n ) :
    lds = [ 0 ] * n
    max = 0
    for i in range ( n ) :
        lds [ i ] = 1
    for i in range ( 1 , n ) :
        for j in range ( i ) :
            if ( arr [ i ] < arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :
                lds [ i ] = lds [ j ] + 1
    for i in range ( n ) :
        if ( max < lds [ i ] ) :
            max = lds [ i ]
    return max
if __name__ == " _ _ main _ _ " :
    arr = [ 15 , 27 , 14 , 38 , 63 , 55 , 46 , 65 , 85 ]
    n = len ( arr )
    print ( " Length ▁ of ▁ LDS ▁ is " , lds ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
MAX = 100
def CountDecreasingPathsCell ( mat , dp , n , x , y ) :
    if ( dp [ x ] [ y ] != - 1 ) :
        return dp [ x ] [ y ]
    delta = [ [ 0 , 1 ] , [ 1 , 0 ] , [ - 1 , 0 ] , [ 0 , - 1 ] ]
    newx , newy = 0 , 0
    ans = 1
    for i in range ( 4 ) :
        newx = x + delta [ i ] [ 0 ]
        newy = y + delta [ i ] [ 1 ]
        if ( newx >= 0 and newx < n and newy >= 0 and newy < n and mat [ newx ] [ newy ] < mat [ x ] [ y ] ) :
            ans += CountDecreasingPathsCell ( mat , dp , n , newx , newy )
    dp [ x ] [ y ] = ans
    return dp [ x ] [ y ]
def countDecreasingPathsMatrix ( n , mat ) :
    dp = [ ]
    for i in range ( n ) :
        l = [ ]
        for j in range ( n ) :
            l . append ( - 1 )
        dp . append ( l )
    sum = 0
    for i in range ( n ) :
        for j in range ( n ) :
            sum += CountDecreasingPathsCell ( mat , dp , n , i , j )
    return sum
n = 2
mat = [ [ 1 , 2 ] , [ 1 , 3 ] ]
print ( countDecreasingPathsMatrix ( n , mat ) )

Index/key variables: i, newx, newy, x, y
Accumulator variables: ans, dp, l, sum
Iterator variables: i, j
Python program:
MAX = 100 ;
def binomialCoeff ( C , n ) :
    for i in range ( 1 , n + 1 ) :
        for j in range ( min ( i , n ) , 0 , - 1 ) :
            C [ j ] = C [ j ] + C [ j - 1 ] ;
    return C ;
def sumOfproduct ( n ) :
    sum = 0 ;
    C = [ 0 ] * MAX ;
    C = binomialCoeff ( C , n ) ;
    for i in range ( n + 1 ) :
        sum += C [ i ] * C [ i + 1 ] ;
    return sum ;
n = 3 ;
print ( sumOfproduct ( n ) ) ;

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
MAX = 100
def binomialCoeff ( n , C ) :
    for i in range ( 1 , n + 1 ) :
        for j in range ( min ( i , n ) , - 1 , - 1 ) :
            C [ j ] = C [ j ] + C [ j - 1 ]
def summation ( n ) :
    C = [ 0 ] * MAX
    binomialCoeff ( n , C )
    sum = 0
    for i in range ( n + 1 ) :
        sum += ( i * C [ i ] )
    return sum
if __name__ == " _ _ main _ _ " :
    n = 2
    print ( summation ( n ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
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 countArray ( N , K ) :
    return binomialCoeff ( K - 1 , N - 1 ) ;
N = 2 ;
K = 3 ;
print ( countArray ( N , K ) ) ;

Index/key variables: j, k
Iterator variables: i, j
Python program:
N = 100
def count ( n , c , a , b ) :
    need = [ 0 for i in range ( N ) ]
    for i in range ( 0 , n , 1 ) :
        a [ i + n ] = a [ i ]
        b [ i + n ] = b [ i ]
    s = 0
    tank = 0
    for i in range ( 0 , 2 * n , 1 ) :
        tank += a [ i ]
        tank = min ( tank , c )
        tank -= b [ i ]
        if ( tank < 0 ) :
            tank = 0
            s = i + 1
    if ( s >= n ) :
        return 0
    ans = 1
    need [ s + n ] = 0
    for i in range ( 1 , n , 1 ) :
        id = s + n - i
        need [ id ] = max ( 0 , need [ id + 1 ] + b [ id ] - min ( a [ id ] , c ) )
        if ( need [ id ] == 0 ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    n = 3
    c = 3
    a = [ 3 , 1 , 2 , 0 , 0 , 0 ]
    b = [ 2 , 2 , 2 , 0 , 0 , 0 ]
    print ( count ( n , c , a , b ) )

Index/key variables: i, id
Accumulator variables: ans, tank
Iterator variables: i
Python program:
def largestSumOfAverages ( A , K ) :
    n = len ( A ) ;
    pre_sum = [ 0 ] * ( n + 1 ) ;
    pre_sum [ 0 ] = 0 ;
    for i in range ( n ) :
        pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;
    dp = [ 0 ] * n ;
    sum = 0 ;
    for i in range ( n ) :
        dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;
    for k in range ( K - 1 ) :
        for i in range ( n ) :
            for j in range ( i + 1 , n ) :
                dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;
    return int ( dp [ 0 ] ) ;
A = [ 9 , 1 , 2 , 3 , 9 ] ;
print ( largestSumOfAverages ( A , K ) ) ;

Index/key variables: i, j, n
Iterator variables: i, j, k
Python program:
N = 105
M = 1001
INF = - 1111111111
def maxSum ( arr ) :
    dp = [ [ - 1 for x in range ( M ) ] for y in range ( N ) ]
    current_arr = [ 0 ] * M
    maxsum = [ 0 ] * M
    current_arr [ 0 ] = 0
    dp [ 0 ] [ 0 ] = 0
    for i in range ( 1 , 6 ) :
        len = arr [ i - 1 ] [ 0 ]
        for j in range ( 1 , len + 1 ) :
            current_arr [ j ] = arr [ i - 1 ] [ j ]
            current_arr [ j ] += current_arr [ j - 1 ]
            maxsum [ j ] = INF
        j = 1
        while j <= len and j <= 6 :
            for k in range ( 1 , len + 1 ) :
                if ( j + k - 1 <= len ) :
                    maxsum [ j ] = max ( maxsum [ j ] , current_arr [ j + k - 1 ] - current_arr [ k - 1 ] )
            j += 1
        for j in range ( 7 ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
        for j in range ( 1 , 7 ) :
            cur = 1
            while cur <= j and cur <= len :
                dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - cur ] + maxsum [ cur ] )
                cur += 1
    ans = 0
    for i in range ( 7 ) :
        ans = max ( ans , dp [ 5 ] [ i ] )
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ [ 3 , 2 , 3 , 5 ] , [ 2 , 7 , - 1 ] , [ 2 , 8 , 10 ] , [ 4 , 5 , 2 , 6 , 1 ] , [ 3 , 2 , 3 , - 2 ] ]
    print ( " Maximum ▁ sum ▁ can ▁ be ▁ obtained " , " is ▁ : ▁ " , maxSum ( arr ) )

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