dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countPairsWithDiffK ( arr , n , k ) :
    count = 0
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :
                count += 1
    return count
arr = [ 1 , 5 , 3 , 4 , 2 ]
n = len ( arr )
k = 3
print ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ diff ▁ is ▁ " , countPairsWithDiffK ( arr , n , k ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def binarySearch ( arr , low , high , x ) :
    if ( high >= low ) :
        mid = low + ( high - low ) // 2
        if x == arr [ mid ] :
            return ( mid )
        elif ( x > arr [ mid ] ) :
            return binarySearch ( arr , ( mid + 1 ) , high , x )
        else :
            return binarySearch ( arr , low , ( mid - 1 ) , x )
    return - 1
def countPairsWithDiffK ( arr , n , k ) :
    count = 0
    arr . sort ( )
    for i in range ( 0 , n - 2 ) :
        if ( binarySearch ( arr , i + 1 , n - 1 , arr [ i ] + k ) != - 1 ) :
            count += 1
    return count
arr = [ 1 , 5 , 3 , 4 , 2 ]
n = len ( arr )
k = 3
print ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ diff ▁ is ▁ " , countPairsWithDiffK ( arr , n , k ) )

Index/key variables: i, mid
Accumulator variables: count
Iterator variables: i
Python program:
def countPairsWithDiffK ( arr , n , k ) :
    count = 0
    arr . sort ( )
    l = 0
    r = 0
    while r < n :
        if arr [ r ] - arr [ l ] == k :
            count += 1
            l += 1
            r += 1
        elif arr [ r ] - arr [ l ] > k :
            l += 1
        else :
            r += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 5 , 3 , 4 , 2 ]
    n = len ( arr )
    k = 3
    print ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ diff ▁ is ▁ " , countPairsWithDiffK ( arr , n , k ) )

Index/key variables: l, r
Accumulator variables: count
Python program:
import math
def totalSubSets ( n , l , r ) :
    MOD = 1000000007 ;
    zero = ( math . floor ( r / 3 ) - math . ceil ( l / 3 ) + 1 ) ;
    one = ( math . floor ( ( r - 1 ) / 3 ) - math . ceil ( ( l - 1 ) / 3 ) + 1 ) ;
    two = ( math . floor ( ( r - 2 ) / 3 ) - math . ceil ( ( l - 2 ) / 3 ) + 1 ) ;
    dp = [ [ 0 for x in range ( 3 ) ] for y in range ( n ) ]
    dp [ 0 ] [ 0 ] = zero ;
    dp [ 0 ] [ 1 ] = one ;
    dp [ 0 ] [ 2 ] = two ;
    for i in range ( 1 , n ) :
        dp [ i ] [ 0 ] = ( ( dp [ i - 1 ] [ 0 ] * zero ) + ( dp [ i - 1 ] [ 1 ] * two ) + ( dp [ i - 1 ] [ 2 ] * one ) ) % MOD ;
        dp [ i ] [ 1 ] = ( ( dp [ i - 1 ] [ 0 ] * one ) + ( dp [ i - 1 ] [ 1 ] * zero ) + ( dp [ i - 1 ] [ 2 ] * two ) ) % MOD ;
        dp [ i ] [ 2 ] = ( ( dp [ i - 1 ] [ 0 ] * two ) + ( dp [ i - 1 ] [ 1 ] * one ) + ( dp [ i - 1 ] [ 2 ] * zero ) ) % MOD ;
    return dp [ n - 1 ] [ 0 ] ;
n = 5 ;
l = 10 ;
r = 100 ;
print ( totalSubSets ( n , l , r ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
r = 4
c = 4
def findmatch ( mat , pat , x , y , nrow , ncol , level ) :
    l = len ( pat )
    if ( level == l ) :
        return True
    if ( x < 0 or y < 0 or x >= nrow or y >= ncol ) :
        return False
    if ( mat [ x ] [ y ] == pat [ level ] ) :
        temp = mat [ x ] [ y ]
        mat [ x ] . replace ( mat [ x ] [ y ] , ' # ' )
        res = ( findmatch ( mat , pat , x - 1 , y , nrow , ncol , level + 1 ) | findmatch ( mat , pat , x + 1 , y , nrow , ncol , level + 1 ) | findmatch ( mat , pat , x , y - 1 , nrow , ncol , level + 1 ) | findmatch ( mat , pat , x , y + 1 , nrow , ncol , level + 1 ) )
        mat [ x ] . replace ( mat [ x ] [ y ] , temp )
        return res
        return False
def checkMatch ( mat , pat , nrow , ncol ) :
    l = len ( pat )
    if ( l > nrow * ncol ) :
        return False
    for i in range ( nrow ) :
        for j in range ( ncol ) :
            if ( mat [ i ] [ j ] == pat [ 0 ] ) :
                if ( findmatch ( mat , pat , i , j , nrow , ncol , 0 ) ) :
                    return True
    return False
if __name__ == " _ _ main _ _ " :
    grid = [ " axmy " , " bgdf " , " xeet " , " raks " ]
    if ( checkMatch ( grid , " geeks " , r , c ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j, level, x, y
Iterator variables: i, j
Python program:
def constructArr ( arr , pair , n ) :
    arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2
    for i in range ( 1 , n ) :
        arr [ i ] = pair [ i - 1 ] - arr [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    pair = [ 15 , 13 , 11 , 10 , 12 , 10 , 9 , 8 , 7 , 5 ]
    n = 5
    arr = [ 0 ] * n
    constructArr ( arr , pair , n )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def gouldSequence ( n ) :
    for row_num in range ( 1 , n ) :
        count = 1
        c = 1
        for i in range ( 1 , row_num ) :
            c = c * ( row_num - i ) / i
            if ( c % 2 == 1 ) :
                count += 1
        print ( count , end = " ▁ " )
n = 16 ;
gouldSequence ( n )

Accumulator variables: count
Iterator variables: i, row_num
Python program:
M = 100
N = 100
def find_min_odd_cost ( given , m , n ) :
    floor = [ [ 0 for i in range ( M ) ] for i in range ( N ) ]
    min_odd_cost = 0
    i , j , temp = 0 , 0 , 0
    for j in range ( n ) :
        floor [ 0 ] [ j ] = given [ 0 ] [ j ]
    for i in range ( 1 , m ) :
        for j in range ( n ) :
            if ( j == 0 ) :
                floor [ i ] [ j ] = given [ i ] [ j ] ;
                floor [ i ] [ j ] += min ( floor [ i - 1 ] [ j ] , floor [ i - 1 ] [ j + 1 ] )
            elif ( j == n - 1 ) :
                floor [ i ] [ j ] = given [ i ] [ j ] ;
                floor [ i ] [ j ] += min ( floor [ i - 1 ] [ j ] , floor [ i - 1 ] [ j - 1 ] )
            else :
                temp = min ( floor [ i - 1 ] [ j ] , floor [ i - 1 ] [ j - 1 ] )
                temp = min ( temp , floor [ i - 1 ] [ j + 1 ] )
                floor [ i ] [ j ] = given [ i ] [ j ] + temp
    min_odd_cost = 10 ** 9
    for j in range ( n ) :
        if ( floor [ n - 1 ] [ j ] % 2 == 1 ) :
            if ( min_odd_cost > floor [ n - 1 ] [ j ] ) :
                min_odd_cost = floor [ n - 1 ] [ j ]
    if ( min_odd_cost == - 10 ** 9 ) :
        return - 1 ;
    return min_odd_cost
m , n = 5 , 5
given = [ [ 1 , 2 , 3 , 4 , 6 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 100 , 2 , 3 , 4 , 5 ] ]
print ( " Minimum ▁ odd ▁ cost ▁ is " , find_min_odd_cost ( given , m , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def minMaxProduct ( arr1 , arr2 , n1 , n2 ) :
    max = arr1 [ 0 ]
    min = arr2 [ 0 ]
    i = 1
    while ( i < n1 and i < n2 ) :
        if ( arr1 [ i ] > max ) :
            max = arr1 [ i ]
        if ( arr2 [ i ] < min ) :
            min = arr2 [ i ]
        i += 1
    while ( i < n1 ) :
        if ( arr1 [ i ] > max ) :
            max = arr1 [ i ]
            i += 1
    while ( i < n2 ) :
        if ( arr2 [ i ] < min ) :
            min = arr2 [ i ]
            i += 1
    return max * min
arr1 = [ 10 , 2 , 3 , 6 , 4 , 1 ]
arr2 = [ 5 , 1 , 4 , 2 , 6 , 9 ]
n1 = len ( arr1 )
n2 = len ( arr1 )
print ( minMaxProduct ( arr1 , arr2 , n1 , n2 ) )

Index/key variables: i
Python program:
def findElement ( arr , n , key ) :
    for i in range ( n ) :
        if ( arr [ i ] == key ) :
            return i
    return - 1
arr = [ 12 , 34 , 10 , 6 , 40 ]
n = len ( arr )
key = 40
index = findElement ( arr , n , key )
if index != - 1 :
    print ( " element ▁ found ▁ at ▁ position : ▁ " + str ( index + 1 ) )
else :
    print ( " element ▁ not ▁ found " )

Index/key variables: i
Iterator variables: i
Python program:
def binarySearch ( arr , low , high , key ) :
    if ( high < low ) :
        return - 1
    mid = ( low + high ) // 2
    if ( key == arr [ mid ] ) :
        return mid
    if ( key > arr [ mid ] ) :
        return binarySearch ( arr , ( mid + 1 ) , high , key )
    return binarySearch ( arr , low , ( mid - 1 ) , key )
def deleteElement ( arr , n , key ) :
    pos = binarySearch ( arr , 0 , n - 1 , key )
    if ( pos == - 1 ) :
        print ( " Element ▁ not ▁ found " )
        return n
    for i in range ( pos , n - 1 ) :
        arr [ i ] = arr [ i + 1 ]
    return n - 1
arr = [ 10 , 20 , 30 , 40 , 50 ]
n = len ( arr )
key = 30
print ( " Array ▁ before ▁ deletion " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )
n = deleteElement ( arr , n , key )
print ( " Array after deletion " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, mid
Iterator variables: i
Python program:
MAX = 100
N = 5
M = 4
def solveQuery ( n , m , mat , q , a , binary ) :
    dp = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]
    max = 1
    for i in range ( n ) :
        for j in range ( m ) :
            if ( i == 0 or j == 0 ) :
                dp [ i ] [ j ] = 1
            elif ( ( mat [ i ] [ j ] == mat [ i - 1 ] [ j ] ) and ( mat [ i ] [ j ] == mat [ i ] [ j - 1 ] ) and ( mat [ i ] [ j ] == mat [ i - 1 ] [ j - 1 ] ) ) :
                dp [ i ] [ j ] = ( min ( dp [ i - 1 ] [ j ] , min ( dp [ i - 1 ] [ j - 1 ] , dp [ i ] [ j - 1 ] ) ) + 1 )
                if ( max < dp [ i ] [ j ] ) :
                    max = dp [ i ] [ j ]
            else :
                dp [ i ] [ j ] = 1
    freq0 = [ 0 ] * MAX
    freq1 = [ 0 ] * MAX
    for i in range ( n ) :
        for j in range ( m ) :
            if ( mat [ i ] [ j ] == 0 ) :
                freq0 [ dp [ i ] [ j ] ] += 1
            else :
                freq1 [ dp [ i ] [ j ] ] += 1
    for i in range ( max - 1 , - 1 , - 1 ) :
        freq0 [ i ] += freq0 [ i + 1 ]
        freq1 [ i ] += freq1 [ i + 1 ]
    for i in range ( q ) :
        if ( binary [ i ] == 0 ) :
            print ( freq0 [ a [ i ] ] )
        else :
            print ( freq1 [ a [ i ] ] )
if __name__ == " _ _ main _ _ " :
    n = 5
    m = 4
    mat = [ [ 0 , 0 , 1 , 1 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , [ 0 , 1 , 1 , 1 ] ]
    q = 2
    a = [ 2 , 2 ]
    binary = [ 1 , 0 ]
    solveQuery ( n , m , mat , q , a , binary )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findSDSFunc ( n ) :
    DP = [ 0 ] * ( n + 1 )
    DP [ 0 ] = 0
    DP [ 1 ] = 1
    for i in range ( 2 , n + 1 ) :
        if ( int ( i % 2 ) == 0 ) :
            DP [ i ] = DP [ int ( i / 2 ) ]
        else :
            DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )
    return DP [ n ]
n = 15
print ( findSDSFunc ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
dp = [ 0 ] * 100
def dfs ( a , v , u , parent ) :
    dp [ u ] = a [ u - 1 ]
    maximum = 0
    for child in v [ u ] :
        if child == parent :
            continue
        dfs ( a , v , child , u )
        maximum = max ( maximum , dp [ child ] )
    dp [ u ] += maximum
def maximumValue ( a , v ) :
    dfs ( a , v , 1 , 0 )
    return dp [ 1 ]
def main ( ) :
    n = 14
    v = { }
    for i in range ( n + 1 ) :
        v [ i ] = [ ]
    v [ 1 ] . append ( 2 ) , v [ 2 ] . append ( 1 )
    v [ 1 ] . append ( 3 ) , v [ 3 ] . append ( 1 )
    v [ 1 ] . append ( 4 ) , v [ 4 ] . append ( 1 )
    v [ 2 ] . append ( 5 ) , v [ 5 ] . append ( 2 )
    v [ 2 ] . append ( 6 ) , v [ 6 ] . append ( 2 )
    v [ 3 ] . append ( 7 ) , v [ 7 ] . append ( 3 )
    v [ 4 ] . append ( 8 ) , v [ 8 ] . append ( 4 )
    v [ 4 ] . append ( 9 ) , v [ 9 ] . append ( 4 )
    v [ 4 ] . append ( 10 ) , v [ 10 ] . append ( 4 )
    v [ 5 ] . append ( 11 ) , v [ 11 ] . append ( 5 )
    v [ 5 ] . append ( 12 ) , v [ 12 ] . append ( 5 )
    v [ 7 ] . append ( 13 ) , v [ 13 ] . append ( 7 )
    v [ 7 ] . append ( 14 ) , v [ 14 ] . append ( 7 )
    a = [ 3 , 2 , 1 , 10 , 1 , 3 , 9 , 1 , 5 , 3 , 4 , 5 , 9 , 8 ]
    print ( maximumValue ( a , v ) )
main ( )

Index/key variables: child, i, u
Iterator variables: child, i
Python program:
def Jacobsthal ( n ) :
    dp = [ 0 ] * ( n + 1 )
    dp [ 0 ] = 0
    dp [ 1 ] = 1
    for i in range ( 2 , n + 1 ) :
        dp [ i ] = dp [ i - 1 ] + 2 * dp [ i - 2 ]
    return dp [ n ]
def Jacobsthal_Lucas ( n ) :
    dp = [ 0 ] * ( n + 1 )
    dp [ 0 ] = 2
    dp [ 1 ] = 1
    for i in range ( 2 , n + 1 ) :
        dp [ i ] = dp [ i - 1 ] + 2 * dp [ i - 2 ] ;
    return dp [ n ]
n = 5
print ( " Jacobsthal ▁ number : " , Jacobsthal ( n ) )
print ( " Jacobsthal - Lucas ▁ number : " , Jacobsthal_Lucas ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
depth = 16
ways = [ [ [ 0 for i in range ( 17 ) ] for i in range ( 17 ) ] for i in range ( 17 ) ]
def preprocess ( list , steps ) :
    ways [ 0 ] [ 8 ] [ 8 ] = 1
    for N in range ( 1 , 16 , 1 ) :
        for i in range ( 1 , depth , 1 ) :
            for j in range ( 1 , depth , 1 ) :
                ways [ N ] [ i ] [ j ] = ( ways [ N - 1 ] [ i ] [ j + 1 ] + ways [ N - 1 ] [ i ] [ j - 1 ] + ways [ N - 1 ] [ i + 1 ] [ j ] + ways [ N - 1 ] [ i - 1 ] [ j ] + ways [ N - 1 ] [ i + 1 ] [ j - 1 ] + ways [ N - 1 ] [ i - 1 ] [ j + 1 ] )
        list [ N ] = ways [ N ] [ 8 ] [ 8 ]
    print ( " Number ▁ of ▁ walks ▁ possible ▁ is / are " , list [ steps ] )
if __name__ == ' _ _ main _ _ ' :
    list = [ 0 for i in range ( 16 ) ]
    steps = 4
    preprocess ( list , steps )

Index/key variables: N, i, j, steps
Iterator variables: N, i, j
Python program:
N = 105
R = 3
C = 4
def maximumValue ( n , m , p , grid ) :
    dp = [ [ [ False for i in range ( N ) ] for j in range ( N ) ] for k in range ( N ) ]
    for i in range ( n ) :
        for j in range ( m ) :
            k = grid [ i ] [ j ]
            while ( k <= p ) :
                if ( i == 0 and j == 0 ) :
                    if ( k == grid [ i ] [ j ] ) :
                        dp [ i ] [ j ] [ k ] = True
                elif ( i == 0 ) :
                    dp [ i ] [ j ] [ k ] = ( dp [ i ] [ j ] [ k ] or dp [ i ] [ j - 1 ] [ k - grid [ i ] [ j ] ] )
                elif ( j == 0 ) :
                    dp [ i ] [ j ] [ k ] = ( dp [ i ] [ j ] [ k ] or dp [ i - 1 ] [ j ] [ k - grid [ i ] [ j ] ] )
                else :
                    dp [ i ] [ j ] [ k ] = ( dp [ i ] [ j ] [ k ] or dp [ i ] [ j - 1 ] [ k - grid [ i ] [ j ] ] )
                    dp [ i ] [ j ] [ k ] = ( dp [ i ] [ j ] [ k ] or dp [ i - 1 ] [ j ] [ k - grid [ i ] [ j ] ] )
                    dp [ i ] [ j ] [ k ] = ( dp [ i ] [ j ] [ k ] or dp [ i - 1 ] [ j - 1 ] [ k - grid [ i ] [ j ] ] )
                k += 1
    ans = k
    while ( ans >= 0 ) :
        if ( dp [ n - 1 ] [ m - 1 ] [ ans ] ) :
            break
        ans -= 1
    return ans
n = 3
m = 4
p = 9
grid = [ [ 2 , 3 , 4 , 1 ] , [ 6 , 5 , 5 , 3 ] , [ 5 , 2 , 3 , 4 ] ]
print ( maximumValue ( n , m , p , grid ) )

Index/key variables: ans, i, j, k
Iterator variables: i, j
Python program:
def answer ( n ) :
    dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ] ;
    if ( n == 1 ) :
        return 10 ;
    for j in range ( 10 ) :
        dp [ 1 ] [ j ] = 1 ;
    for i in range ( 2 , n + 1 ) :
        for j in range ( 10 ) :
            if ( j == 0 ) :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;
            elif ( j == 9 ) :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;
            else :
                dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ) ;
    sum = 0 ;
    for j in range ( 1 , 10 ) :
        sum = sum + dp [ n ] [ j ] ;
    return sum ;
n = 2 ;
print ( answer ( n ) ) ;

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def lcs_ ( X , Y ) :
    m = len ( X )
    n = len ( Y )
    L = [ [ 0 ] * ( n + 1 ) ] * ( m + 1 )
    for i in range ( n + 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 ] ) ;
    index = L [ m ] [ n ] ;
    lcs = [ "   " ] * ( index + 1 )
    i , j = m , n
    while ( i > 0 and j > 0 ) :
        if ( X [ i - 1 ] == Y [ j - 1 ] ) :
            lcs [ index - 1 ] = X [ i - 1 ]
            i -= 1
            j -= 1
            index -= 1
        elif ( L [ i - 1 ] [ j ] > L [ i ] [ j - 1 ] ) :
            i -= 1
        else :
            j -= 1
    ans = " "
    for x in range ( len ( lcs ) ) :
        ans += lcs [ x ]
    return ans
def longestPalSubseq ( string ) :
    rev = string [ : : - 1 ]
    return lcs_ ( string , rev )
if __name__ == " _ _ main _ _ " :
    string = " GEEKSFORGEEKS " ;
    print ( longestPalSubseq ( string ) )

Index/key variables: i, j, m, n, x
Accumulator variables: ans, index
Iterator variables: i, j, x
Python program:
def productSubSeqCount ( arr , k ) :
    n = len ( arr )
    dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( k + 1 ) ]
    for i in range ( 1 , k + 1 ) :
        for j in range ( 1 , n + 1 ) :
            dp [ i ] [ j ] = dp [ i ] [ j - 1 ]
            if arr [ j - 1 ] <= i and arr [ j - 1 ] > 0 :
                dp [ i ] [ j ] += dp [ i // arr [ j - 1 ] ] [ j - 1 ] + 1
    return dp [ k ] [ n ]
A = [ 1 , 2 , 3 , 4 ]
k = 10
print ( productSubSeqCount ( A , k ) )

Index/key variables: i, j, k, n
Iterator variables: i, j
Python program:
dp = [ [ 0 for i in range ( 15001 ) ] for j in range ( 1001 ) ]
def computeDpArray ( arr , n ) :
    for i in range ( n ) :
        for j in range ( 1 , 15001 , 1 ) :
            if ( i == 0 ) :
                dp [ i ] [ j ] = ( j == arr [ i ] )
            else :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + ( arr [ i ] == j )
def countTripletSum ( arr , n ) :
    computeDpArray ( arr , n )
    ans = 0
    for i in range ( 0 , n - 2 , 1 ) :
        for j in range ( i + 1 , n - 1 , 1 ) :
            for k in range ( 1 , 25 , 1 ) :
                cube = k * k * k
                rem = cube - ( arr [ i ] + arr [ j ] )
                if ( rem > 0 ) :
                    ans += dp [ n - 1 ] [ rem ] - dp [ j ] [ rem ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , 1 , 20 , 6 ]
    n = len ( arr )
    print ( countTripletSum ( arr , n ) )

Index/key variables: i, j, rem
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
INT_MIN = - 2147483648
def isPresent ( B , m , x ) :
    for i in range ( 0 , m ) :
        if B [ i ] == x :
            return True
    return False
def findMaxSubarraySumUtil ( A , B , n , m ) :
    max_so_far = INT_MIN
    curr_max = 0
    for i in range ( 0 , n ) :
        if isPresent ( B , m , A [ i ] ) == True :
            curr_max = 0
            continue
        curr_max = max ( A [ i ] , curr_max + A [ i ] )
        max_so_far = max ( max_so_far , curr_max )
    return max_so_far
def findMaxSubarraySum ( A , B , n , m ) :
    maxSubarraySum = findMaxSubarraySumUtil ( A , B , n , m )
    if maxSubarraySum == INT_MIN :
        print ( ' Maximum ▁ Subarray ▁ Sum ▁ cant ▁ be ▁ found ' )
    else :
        print ( ' The ▁ Maximum ▁ Subarray ▁ Sum ▁ = ' , maxSubarraySum )
A = [ 3 , 4 , 5 , - 4 , 6 ]
B = [ 1 , 8 , 5 ]
n = len ( A )
m = len ( B )
findMaxSubarraySum ( A , B , n , m )

Index/key variables: i
Iterator variables: i
Python program:
import numpy as np
def nonDecNums ( n ) :
    a = np . zeros ( ( n + 1 , 10 ) )
    for i in range ( 10 ) :
        a [ 0 ] [ i ] = 1
    for i in range ( 1 , n + 1 ) :
        a [ i ] [ 9 ] = 1
    for i in range ( 1 , n + 1 ) :
        for j in range ( 8 , - 1 , - 1 ) :
            a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]
    return int ( a [ n ] [ 0 ] )
if __name__ == " _ _ main _ _ " :
    n = 2
    print ( " Non - decreasing ▁ digits ▁ = ▁ " , nonDecNums ( n ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def countBT ( h ) :
    MOD = 1000000007
    dp = [ 0 for i in range ( h + 1 ) ]
    dp [ 0 ] = 1
    dp [ 1 ] = 1
    for i in range ( 2 , h + 1 ) :
        dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD
    return dp [ h ]
h = 3
print ( " No . ▁ of ▁ balanced ▁ binary ▁ trees ▁ of ▁ height ▁ " + str ( h ) + " ▁ is : ▁ " + str ( countBT ( h ) ) )

Index/key variables: h, i
Iterator variables: i
Python program:
import sys
def findMaxSubarraySum ( A , B ) :
    m = dict ( )
    for i in range ( len ( B ) ) :
        if B [ i ] not in m :
            m [ B [ i ] ] = 0
        m [ B [ i ] ] = 1
    max_so_far = - sys . maxsize - 1
    currmax = 0
    for i in range ( len ( A ) ) :
        if ( currmax < 0 or ( A [ i ] in m and m [ A [ i ] ] == 1 ) ) :
            currmax = 0
            continue
        currmax = max ( A [ i ] , A [ i ] + currmax )
        if ( max_so_far < currmax ) :
            max_so_far = currmax
    return max_so_far
if __name__ == ' _ _ main _ _ ' :
    a = [ 3 , 4 , 5 , - 4 , 6 ]
    b = [ 1 , 8 , 5 ]
    print ( findMaxSubarraySum ( a , b ) )

Index/key variables: i
Iterator variables: i
Python program:
def equilibrium ( arr ) :
    leftsum = 0
    rightsum = 0
    n = len ( arr )
    for i in range ( n ) :
        leftsum = 0
        rightsum = 0
        for j in range ( i ) :
            leftsum += arr [ j ]
        for j in range ( i + 1 , n ) :
            rightsum += arr [ j ]
        if leftsum == rightsum :
            return i
    return - 1
arr = [ - 7 , 1 , 5 , 2 , - 4 , 3 , 0 ]
print ( equilibrium ( arr ) )

Index/key variables: j
Accumulator variables: leftsum, rightsum
Iterator variables: i, j
Python program:
import numpy as np
def countEndless ( input_mat , n ) :
    row = np . zeros ( ( n , n ) )
    col = np . zeros ( ( n , n ) )
    for j in range ( n ) :
        isEndless = 1
        for i in range ( n - 1 , - 1 , - 1 ) :
            if ( input_mat [ i ] [ j ] == 0 ) :
                isEndless = 0
            col [ i ] [ j ] = isEndless
    for i in range ( n ) :
        isEndless = 1
        for j in range ( n - 1 , - 1 , - 1 ) :
            if ( input_mat [ i ] [ j ] == 0 ) :
                isEndless = 0
            row [ i ] [ j ] = isEndless
    ans = 0
    for i in range ( n ) :
        for j in range ( 1 , n ) :
            if ( row [ i ] [ j ] and col [ i ] [ j ] ) :
                ans += 1
            print ( ans )
    return ans
if __name__ == " _ _ main _ _ " :
    input_mat = [ [ 1 , 0 , 1 , 1 ] , [ 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , [ 0 , 1 , 1 , 0 ] ]
    n = 4
    print ( countEndless ( input_mat , n ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def equilibrium ( arr ) :
    total_sum = sum ( arr )
    leftsum = 0
    for i , num in enumerate ( arr ) :
        total_sum -= num
        if leftsum == total_sum :
            return i
        leftsum += num
    return - 1
arr = [ - 7 , 1 , 5 , 2 , - 4 , 3 , 0 ]
print ( ' First ▁ equilibrium ▁ index ▁ is ▁ ' , equilibrium ( arr ) )

Accumulator variables: leftsum, total_sum
Iterator variables: i, num
Python program:
def sumOfSubstrings ( num ) :
    n = len ( num )
    sumofdigit = [ ]
    sumofdigit . append ( int ( num [ 0 ] ) )
    res = sumofdigit [ 0 ]
    for i in range ( 1 , n ) :
        numi = int ( num [ i ] )
        sumofdigit . append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )
        res += sumofdigit [ i ]
    return res
num = "1234"
print ( sumOfSubstrings ( num ) )

Index/key variables: i
Accumulator variables: res, sumofdigit
Iterator variables: i
Python program:
def sumOfSubstrings ( num ) :
    n = len ( num )
    prev = int ( num [ 0 ] )
    res = prev
    current = 0
    for i in range ( 1 , n ) :
        numi = int ( num [ i ] )
        current = ( i + 1 ) * numi + 10 * prev
        res += current
    return res
num = "1234"
print ( sumOfSubstrings ( num ) )

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