dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findMean ( a , n ) :
    sum = 0
    for i in range ( 0 , n ) :
        sum += a [ i ]
    return float ( sum / n )
def findMedian ( a , n ) :
    sorted ( a )
    if n % 2 != 0 :
        return float ( a [ int ( n / 2 ) ] )
    return float ( ( a [ int ( ( n - 1 ) / 2 ) ] + a [ int ( n / 2 ) ] ) / 2.0 )
a = [ 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 ]
n = len ( a )
print ( " Mean ▁ = " , findMean ( a , n ) )
print ( " Median ▁ = " , findMedian ( a , n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def sumOfLeftLeaves ( root ) :
    if ( root is None ) :
        return
    stack = [ ]
    stack . append ( root )
    sum = 0
    while len ( stack ) > 0 :
        currentNode = stack . pop ( )
        if currentNode . left is not None :
            stack . append ( currentNode . left )
            if currentNode . left . left is None and currentNode . left . right is None :
                sum = sum + currentNode . left . data
        if currentNode . right is not None :
            stack . append ( currentNode . right )
    return sum
root = Tree ( 20 ) ;
root . left = Tree ( 9 ) ;
root . right = Tree ( 49 ) ;
root . right . left = Tree ( 23 ) ;
root . right . right = Tree ( 52 ) ;
root . right . right . left = Tree ( 50 ) ;
root . left . left = Tree ( 5 ) ;
root . left . right = Tree ( 12 ) ;
root . left . right . right = Tree ( 12 ) ;
print ( ' Sum ▁ of ▁ left ▁ leaves ▁ is ▁ { } ' . format ( sumOfLeftLeaves ( root ) ) )

Accumulator variables: stack
Class/struct names: Node
Python program:
def findMax ( a , dp , i , flag ) :
    if ( i == len ( a ) ) :
        return 0
    if ( dp [ i ] [ flag ] != - 1 ) :
        return dp [ i ] [ flag ]
    ans = 0
    if ( flag == 0 ) :
        ans = max ( findMax ( a , dp , i + 1 , 0 ) , a [ i ] + findMax ( a , dp , i + 1 , 1 ) )
    else :
        ans = max ( findMax ( a , dp , i + 1 , 1 ) , - 1 * a [ i ] + findMax ( a , dp , i + 1 , 0 ) )
    dp [ i ] [ flag ] = ans
    return ans
def findMaxSumUtil ( arr , N ) :
    dp = [ [ - 1 for i in range ( 2 ) ] for i in range ( N ) ]
    print ( findMax ( arr , dp , 0 , 0 ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 1 , 2 ]
    N = len ( arr )
    findMaxSumUtil ( arr , N )

Index/key variables: flag, i
Python program:
def findWinner ( s ) :
    vowels_count = 0
    consonants_count = 0
    p = len ( s )
    for i in range ( 0 , p ) :
        if ( s [ i ] == ' a ' or s [ i ] == ' e ' or s [ i ] == ' i ' or s [ i ] == ' o ' or s [ i ] == ' u ' ) :
            vowels_count = vowels_count + 1
        else :
            consonants_count = consonants_count + 1
    if ( vowels_count == 0 ) :
        if ( consonants_count % 2 == 0 ) :
            print ( " Player ▁ B " )
        else :
            print ( " Player ▁ A " )
    elif ( vowels_count == 1 and consonants_count % 2 != 0 ) :
        print ( " Player ▁ A " )
    else :
        print ( " D " )
s = " abcd "
findWinner ( s )

Index/key variables: i
Iterator variables: i
Python program:
def prefix_sum ( arr , n ) :
    pre_sum = list ( )
    pre_sum . append ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        pre_sum . append ( pre_sum [ i - 1 ] + arr [ i ] )
    return pre_sum
def maxMerge ( maxi , cand ) :
    k = len ( maxi )
    j = 0
    for i in range ( k ) :
        if ( cand [ j ] > maxi [ i ] ) :
            maxi . insert ( i , cand [ j ] )
            del maxi [ - 1 ]
            j += 1
def insertMini ( mini , pre_sum ) :
    k = len ( mini )
    for i in range ( k ) :
        if ( pre_sum < mini [ i ] ) :
            mini . insert ( i , pre_sum )
            del mini [ - 1 ]
            break
def kMaxOvSubArray ( arr , k ) :
    n = len ( arr )
    pre_sum = prefix_sum ( arr , n )
    mini = [ float ( ' inf ' ) for i in range ( k ) ]
    mini [ 0 ] = 0
    maxi = [ - float ( ' inf ' ) for i in range ( k ) ]
    cand = [ 0 for i in range ( k ) ]
    for i in range ( n ) :
        for j in range ( k ) :
            cand [ j ] = pre_sum [ i ] - mini [ j ]
        maxMerge ( maxi , cand )
        insertMini ( mini , pre_sum [ i ] )
    for ele in maxi :
        print ( ele , end = ' ▁ ' )
    print ( ' ' )
arr1 = [ 4 , - 8 , 9 , - 4 , 1 , - 8 , - 1 , 6 ]
k1 = 4
kMaxOvSubArray ( arr1 , k1 )
arr2 = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ]
k2 = 3
kMaxOvSubArray ( arr2 , k2 )

Index/key variables: i, j
Accumulator variables: pre_sum
Iterator variables: ele, i, j
Python program:
def printSmall ( arr , n , k ) :
    for i in range ( k , n ) :
        max_var = arr [ k - 1 ]
        pos = k - 1
        for j in range ( k - 2 , - 1 , - 1 ) :
            if ( arr [ j ] > max_var ) :
                max_var = arr [ j ]
                pos = j
        if ( max_var > arr [ i ] ) :
            j = pos
            while ( j < k - 1 ) :
                arr [ j ] = arr [ j + 1 ]
                j += 1
            arr [ k - 1 ] = arr [ i ]
    for i in range ( 0 , k ) :
        print ( arr [ i ] , end = " ▁ " )
arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ]
n = len ( arr )
k = 5
printSmall ( arr , n , k )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import sys
def kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :
    if ( k > n1 * n2 ) :
        print ( " k ▁ pairs ▁ don ' t ▁ exist " )
        return
    index2 = [ 0 for i in range ( n1 ) ]
    while ( k > 0 ) :
        min_sum = sys . maxsize
        min_index = 0
        for i1 in range ( 0 , n1 , 1 ) :
            if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :
                min_index = i1
                min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]
        print ( " ( " , arr1 [ min_index ] , " , " , arr2 [ index2 [ min_index ] ] , " ) " , end = " ▁ " )
        index2 [ min_index ] += 1
        k -= 1
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 1 , 3 , 11 ]
    n1 = len ( arr1 )
    arr2 = [ 2 , 4 , 8 ]
    n2 = len ( arr2 )
    k = 4
    kSmallestPair ( arr1 , n1 , arr2 , n2 , k )

Index/key variables: i1, min_index
Accumulator variables: k
Iterator variables: i1
Python program:
def maxSubset ( arr , N , X ) :
    arr . sort ( reverse = True )
    counter = 0
    sz = 0
    for i in range ( N ) :
        sz += 1
        if ( arr [ i ] * sz >= X ) :
            counter += 1
            sz = 0
    return counter
arr = [ 7 , 11 , 2 , 9 , 5 ]
N = len ( arr )
X = 10
print ( maxSubset ( arr , N , X ) )

Index/key variables: i
Accumulator variables: counter, sz
Iterator variables: i
Python program:
import sys
def maximumModuloValue ( A , n ) :
    mn = sys . maxsize
    for i in range ( n ) :
        mn = min ( A [ i ] , mn )
    return mn
A = [ 7 , 10 , 12 ]
n = len ( A )
print ( maximumModuloValue ( A , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def updateQuery ( from_x , from_y , to_x , to_y , k , aux ) :
    aux [ from_x ] [ from_y ] += k
    if ( to_x + 1 < 3 ) :
        aux [ to_x + 1 ] [ from_y ] -= k
    if ( to_x + 1 < 3 and to_y + 1 < 4 ) :
        aux [ to_x + 1 ] [ to_y + 1 ] += k
    if ( to_y + 1 < 4 ) :
        aux [ from_x ] [ to_y + 1 ] -= k
    return aux
def updatematrix ( mat , aux ) :
    for i in range ( 3 ) :
        for j in range ( 1 , 4 ) :
            aux [ i ] [ j ] += aux [ i ] [ j - 1 ]
    for i in range ( 4 ) :
        for j in range ( 1 , 3 ) :
            aux [ j ] [ i ] += aux [ j - 1 ] [ i ]
    for i in range ( 3 ) :
        for j in range ( 4 ) :
            mat [ i ] [ j ] += aux [ i ] [ j ]
    return mat
def printmatrix ( mat ) :
    for i in range ( 3 ) :
        for j in range ( 4 ) :
            print ( mat [ i ] [ j ] , end = " ▁ " )
        print ( )
def matrixQuery ( mat , Q , q ) :
    aux = [ [ 0 for i in range ( 4 ) ] for i in range ( 3 ) ]
    for i in range ( Q ) :
        updateQuery ( q [ i ] [ 0 ] , q [ i ] [ 1 ] , q [ i ] [ 2 ] , q [ i ] [ 3 ] , q [ i ] [ 4 ] , aux )
    updatematrix ( mat , aux )
    printmatrix ( mat )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 0 , 1 , 2 ] , [ 0 , 2 , 4 , 1 ] , [ 1 , 2 , 1 , 0 ] ]
    Q = 1
    q = [ [ 0 , 0 , 1 , 1 , 2 ] ]
    matrixQuery ( mat , Q , q )

Index/key variables: from_x, from_y, i, j
Iterator variables: i, j
Python program:
from collections import deque
class Node :
    def __init__ ( self , x ) :
        self . key = x
        self . left = None
        self . right = None
def sumOfLeftLeaves ( root ) :
    if ( root == None ) :
        return 0
    q = deque ( )
    q . append ( [ root , 0 ] )
    sum = 0
    while ( len ( q ) > 0 ) :
        temp = q [ 0 ] [ 0 ]
        is_left_child = q [ 0 ] [ 1 ]
        q . popleft ( )
        if ( not temp . left and not temp . right and is_left_child ) :
            sum = sum + temp . key
        if ( temp . left ) :
            q . append ( [ temp . left , 1 ] )
        if ( temp . right ) :
            q . append ( [ temp . right , 0 ] )
    return sum
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 20 )
    root . left = Node ( 9 )
    root . right = Node ( 49 )
    root . right . left = Node ( 23 )
    root . right . right = Node ( 52 )
    root . right . right . left = Node ( 50 )
    root . left . left = Node ( 5 )
    root . left . right = Node ( 12 )
    root . left . right . right = Node ( 12 )
    print ( " Sum ▁ of ▁ left ▁ leaves ▁ is " , sumOfLeftLeaves ( root ) )

Accumulator variables: q
Class/struct names: Node
Python program:
def countNestedPolygons ( sides ) :
    count = 0
    while ( sides > 5 ) :
        sides //= 2
        count += 1
    return count
N = 12
print ( countNestedPolygons ( N ) )

Accumulator variables: count, sides
Python program:
def print2largest ( arr , arr_size ) :
    if ( arr_size < 2 ) :
        print ( " ▁ Invalid ▁ Input ▁ " ) ;
        return ;
    largest = second = - 2454635434 ;
    for i in range ( 0 , arr_size ) :
        largest = max ( largest , arr [ i ] ) ;
    for i in range ( 0 , arr_size ) :
        if ( arr [ i ] != largest ) :
            second = max ( second , arr [ i ] ) ;
    if ( second == - 2454635434 ) :
        print ( " There ▁ is ▁ no ▁ second ▁ " + " largest ▁ element " ) ;
    else :
        print ( " The ▁ second ▁ largest ▁ " +   " element is " , second ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 35 , 1 , 10 , 34 , 1 ] ;
    n = len ( arr ) ;
    print2largest ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def print2largest ( arr , arr_size ) :
    if ( arr_size < 2 ) :
        print ( " ▁ Invalid ▁ Input ▁ " )
        return
    first = second = - 2147483648
    for i in range ( arr_size ) :
        if ( arr [ i ] > first ) :
            second = first
            first = arr [ i ]
        elif ( arr [ i ] > second and arr [ i ] != first ) :
            second = arr [ i ]
    if ( second == - 2147483648 ) :
        print ( " There ▁ is ▁ no ▁ second ▁ largest ▁ element " )
    else :
        print ( " The ▁ second ▁ largest ▁ element ▁ is " , second )
arr = [ 12 , 35 , 1 , 10 , 34 , 1 ]
n = len ( arr )
print2largest ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def queryResult ( prefix , Q ) :
    l = Q [ 0 ]
    r = Q [ 1 ]
    if ( l == 0 ) :
        xorval = prefix [ r ]
        print ( bin ( xorval ) . count ( '1' ) )
    else :
        xorval = prefix [ r ] ^ prefix [ l - 1 ]
        print ( bin ( xorval ) . count ( '1' ) )
def calculateCount ( S , Q , m ) :
    n = len ( S )
    arr = [ 0 ] * n
    for i in range ( n ) :
        arr [ i ] = ( 1 << ( ord ( S [ i ] ) - ord ( ' a ' ) ) )
    prefix = [ 0 ] * n
    x = 0
    for i in range ( n ) :
        x ^= arr [ i ]
        prefix [ i ] = x
    for i in range ( m ) :
        queryResult ( prefix , Q [ i ] )
if __name__ == ' _ _ main _ _ ' :
    S = " geeksforgeeks "
    Q = [ [ 2 , 4 ] , [ 0 , 3 ] , [ 0 , 12 ] ]
    calculateCount ( S , Q , 3 )

Index/key variables: i, r
Accumulator variables: x
Iterator variables: i
Python program:
def UniqueMatrix ( N ) :
    element_value = 1
    i = 0
    while ( i < N ) :
        if ( i % 2 == 0 ) :
            for f in range ( element_value , element_value + N , 1 ) :
                print ( f , end = ' ▁ ' )
            element_value += N
        else :
            for k in range ( element_value + N - 1 , element_value - 1 , - 1 ) :
                print ( k , end = ' ▁ ' )
            element_value += N
        print ( )
        i = i + 1
N = 4
UniqueMatrix ( N )

Accumulator variables: element_value
Iterator variables: f, k
Python program:
class pair :
    def __init__ ( self ) :
        self . min = 0
        self . max = 0
def getMinMax ( arr : list , n : int ) -> pair :
    minmax = pair ( )
    if n == 1 :
        minmax . max = arr [ 0 ]
        minmax . min = arr [ 0 ]
        return minmax
    if arr [ 0 ] > arr [ 1 ] :
        minmax . max = arr [ 0 ]
        minmax . min = arr [ 1 ]
    else :
        minmax . max = arr [ 1 ]
        minmax . min = arr [ 0 ]
    for i in range ( 2 , n ) :
        if arr [ i ] > minmax . max :
            minmax . max = arr [ i ]
        elif arr [ i ] < minmax . min :
            minmax . min = arr [ i ]
    return minmax
if __name__ == " _ _ main _ _ " :
    arr = [ 1000 , 11 , 445 , 1 , 330 , 3000 ]
    arr_size = 6
    minmax = getMinMax ( arr , arr_size )
    print ( " Minimum ▁ element ▁ is " , minmax . min )
    print ( " Maximum ▁ element ▁ is " , minmax . max )

Index/key variables: i
Iterator variables: i
Class/struct names: pair
Python program:
def SumNodes ( l ) :
    leafNodeCount = pow ( 2 , l - 1 )
    vec = [ [ ] for i in range ( l ) ]
    for i in range ( 1 , leafNodeCount + 1 ) :
        vec [ l - 1 ] . append ( i )
    for i in range ( l - 2 , - 1 , - 1 ) :
        k = 0
        while ( k < len ( vec [ i + 1 ] ) - 1 ) :
            vec [ i ] . append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )
            k += 2
    Sum = 0
    for i in range ( l ) :
        for j in range ( len ( vec [ i ] ) ) :
            Sum += vec [ i ] [ j ]
    return Sum
if __name__ == ' _ _ main _ _ ' :
    l = 3
    print ( SumNodes ( l ) )

Index/key variables: i, j, k
Accumulator variables: Sum
Iterator variables: i, j
Python program:
def getMinMax ( arr ) :
    n = len ( arr )
    if ( n % 2 == 0 ) :
        mx = max ( arr [ 0 ] , arr [ 1 ] )
        mn = min ( arr [ 0 ] , arr [ 1 ] )
        i = 2
    else :
        mx = mn = arr [ 0 ]
        i = 1
    while ( i < n - 1 ) :
        if arr [ i ] < arr [ i + 1 ] :
            mx = max ( mx , arr [ i + 1 ] )
            mn = min ( mn , arr [ i ] )
        else :
            mx = max ( mx , arr [ i ] )
            mn = min ( mn , arr [ i + 1 ] )
        i += 2
    return ( mx , mn )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1000 , 11 , 445 , 1 , 330 , 3000 ]
    mx , mn = getMinMax ( arr )
    print ( " Minimum ▁ element ▁ is " , mn )
    print ( " Maximum ▁ element ▁ is " , mx )

Index/key variables: i
Python program:
def printQuerySum ( arr , Q ) :
    for q in Q :
        L , R = q
        s = 0
        for i in range ( L , R + 1 ) :
            s += arr [ i ]
        print ( " Sum ▁ of " , q , " is " , s )
arr = [ 1 , 1 , 2 , 1 , 3 , 4 , 5 , 2 , 8 ]
Q = [ [ 0 , 4 ] , [ 1 , 3 ] , [ 2 , 4 ] ]
printQuerySum ( arr , Q )

Index/key variables: i
Accumulator variables: s
Iterator variables: i, q
Python program:
def findways ( s , x ) :
    if ( x > len ( s ) ) :
        return 0
    n = len ( s )
    freq = [ 0 ] * 26
    for i in range ( n ) :
        freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    se = set ( )
    for i in range ( 26 ) :
        if ( freq [ i ] > 0 ) :
            se . add ( freq [ i ] )
    ans = 1
    for i in range ( x // 2 ) :
        count = 0
        for u in se :
            if ( u >= 2 ) :
                count += 1
        if ( count == 0 ) :
            return 0
        else :
            ans *= count
        p = list ( se )
        val = p [ - 1 ]
        p . pop ( - 1 )
        se = set ( p )
        if ( val > 2 ) :
            se . add ( val - 2 )
    if ( x % 2 != 0 ) :
        count = 0
        for u in se :
            if ( u > 0 ) :
                count += 1
        ans = ans * count
    return ans
if __name__ == ' _ _ main _ _ ' :
    s = " aaa "
    x = 2
    print ( findways ( s , x ) )

Index/key variables: i
Accumulator variables: ans, count, se
Iterator variables: i, u
Python program:
def FindIfPossible ( n , a , b ) :
    if ( b % a ) != 0 :
        if n == 1 :
            return 0
        elif ( n % b ) != 0 :
            return - 1
        else :
            return int ( n / b )
    c = b / a
    x = 0
    y = 0
    while ( n % b == 0 ) :
        n /= b
        x += 1
    while ( n % c == 0 ) :
        n /= c
        y += 1
    if n == 1 :
        total_steps = x + 2 * y
        return total_steps
    else :
        return - 1
n = 48
a = 3
b = 12
print ( FindIfPossible ( n , a , b ) )

Accumulator variables: n, x, y
Python program:
from math import sqrt
MAXN = 10000
SQRSIZE = 100
arr = [ 0 ] * ( MAXN )
block = [ 0 ] * ( SQRSIZE )
blk_sz = 0
def update ( idx , val ) :
    blockNumber = idx // blk_sz
    block [ blockNumber ] += val - arr [ idx ]
    arr [ idx ] = val
def query ( l , r ) :
    sum = 0
    while ( l < r and l % blk_sz != 0 and l != 0 ) :
        sum += arr [ l ]
        l += 1
    while ( l + blk_sz <= r ) :
        sum += block [ l // blk_sz ]
        l += blk_sz
    while ( l <= r ) :
        sum += arr [ l ]
        l += 1
    return sum
def preprocess ( input , n ) :
    blk_idx = - 1
    global blk_sz
    blk_sz = int ( sqrt ( n ) )
    for i in range ( n ) :
        arr [ i ] = input [ i ] ;
        if ( i % blk_sz == 0 ) :
            blk_idx += 1 ;
        block [ blk_idx ] += arr [ i ]
input = [ 1 , 5 , 2 , 4 , 6 , 1 , 3 , 5 , 7 , 10 ]
n = len ( input )
preprocess ( input , n )
print ( " query ( 3,8 ) ▁ : ▁ " , query ( 3 , 8 ) )
print ( " query ( 1,6 ) ▁ : ▁ " , query ( 1 , 6 ) )
update ( 8 , 0 )
print ( " query ( 8,8 ) ▁ : ▁ " , query ( 8 , 8 ) )

Index/key variables: blk_idx, blockNumber, i, idx, l
Accumulator variables: sum
Iterator variables: i
Python program:
MAX = 500
lookup = [ [ 0 for j in range ( MAX ) ] for i in range ( MAX ) ]
class Query :
    def __init__ ( self , L , R ) :
        self . L = L
        self . R = R
def preprocess ( arr , n ) :
    for i in range ( n ) :
        lookup [ i ] [ i ] = i ;
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ lookup [ i ] [ j - 1 ] ] < arr [ j ] ) :
                lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ] ;
            else :
                lookup [ i ] [ j ] = j ;
def RMQ ( arr , n , q , m ) :
    preprocess ( arr , n ) ;
    for i in range ( m ) :
        L = q [ i ] . L
        R = q [ i ] . R ;
        print ( " Minimum ▁ of ▁ [ " + str ( L ) + " , ▁ " + str ( R ) + " ] ▁ is ▁ " + str ( arr [ lookup [ L ] [ R ] ] ) )
if __name__ == " _ _ main _ _ " :
    a = [ 7 , 2 , 3 , 0 , 5 , 10 , 3 , 12 , 18 ]
    n = len ( a )
    q = [ Query ( 0 , 4 ) , Query ( 4 , 7 ) , Query ( 7 , 8 ) ]
    m = len ( q )
    RMQ ( a , n , q , m ) ;

Index/key variables: L, R, i, j
Iterator variables: i, j
Class/struct names: Query
Python program:
def findMinimumHike ( ratings , employees ) :
    hikes = [ 1 for i in range ( employees ) ]
    for i in range ( 1 , employees ) :
        if ( ratings [ i - 1 ] < ratings [ i ] and hikes [ i - 1 ] >= hikes [ i ] ) :
            hikes [ i ] = hikes [ i - 1 ] + 1 ;
    for i in range ( employees - 2 , - 1 , - 1 ) :
        if ( ratings [ i ] > ratings [ i + 1 ] and hikes [ i + 1 ] >= hikes [ i ] ) :
            hikes [ i ] = hikes [ i + 1 ] + 1 ;
    return hikes
data = [ 5 , 3 , 4 , 2 , 1 , 6 ]
result = findMinimumHike ( data , len ( data ) )
print ( result )
data = [ 1 , 3 , 5 , 4 ]
result = findMinimumHike ( data , len ( data ) )
print ( result )
data = [ 1 , 4 ]
result = findMinimumHike ( data , len ( data ) )
print ( result )

Index/key variables: i
Iterator variables: i
Python program:
from math import log2
MAX = 500
lookup = [ [ 0 for i in range ( 500 ) ] for j in range ( 500 ) ]
class Query :
    def __init__ ( self , l , r ) :
        self . L = l
        self . R = r
def preprocess ( arr : list , n : int ) :
    global lookup
    for i in range ( n ) :
        lookup [ i ] [ 0 ] = i
    j = 1
    while ( 1 << j ) <= n :
        i = 0
        while i + ( 1 << j ) - 1 < n :
            if ( arr [ lookup [ i ] [ j - 1 ] ] < arr [ lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ] ) :
                lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ]
            else :
                lookup [ i ] [ j ] = lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ]
            i += 1
        j += 1
def query ( arr : list , L : int , R : int ) -> int :
    global lookup
    j = int ( log2 ( R - L + 1 ) )
    if ( arr [ lookup [ L ] [ j ] ] <= arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ) :
        return arr [ lookup [ L ] [ j ] ]
    else :
        return arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ]
def RMQ ( arr : list , n : int , q : list , m : int ) :
    preprocess ( arr , n )
    for i in range ( m ) :
        L = q [ i ] . L
        R = q [ i ] . R
        print ( " Minimum ▁ of ▁ [ % d , ▁ % d ] ▁ is ▁ % d " % ( L , R , query ( arr , L , R ) ) )
if __name__ == " _ _ main _ _ " :
    a = [ 7 , 2 , 3 , 0 , 5 , 10 , 3 , 12 , 18 ]
    n = len ( a )
    q = [ Query ( 0 , 4 ) , Query ( 4 , 7 ) , Query ( 7 , 8 ) ]
    m = len ( q )
    RMQ ( a , n , q , m )

Index/key variables: L, i, j
Iterator variables: i
Class/struct names: Query
Python program:
dp = [ [ - 1 for i in range ( 27 ) ] for j in range ( 100005 ) ] ;
def calculate ( pos , prev , s ) :
    if ( pos == len ( s ) ) :
        return 0 ;
    if ( dp [ pos ] [ prev ] != - 1 ) :
        return dp [ pos ] [ prev ] ;
    val = 0 ;
    if ( ord ( s [ pos ] ) - ord ( ' a ' ) + 1 != prev ) :
        val = max ( val , 1 + calculate ( pos + 1 , ord ( s [ pos ] ) - ord ( ' a ' ) + 1 , s ) ) ;
    val = max ( val , calculate ( pos + 1 , prev , s ) ) ;
    dp [ pos ] [ prev ] = val ;
    return dp [ pos ] [ prev ] ;
def longestSubsequence ( s ) :
    n = len ( s ) ;
    return calculate ( 0 , 0 , s ) ;
if __name__ == ' _ _ main _ _ ' :
    str = " ababa " ;
    print ( longestSubsequence ( str ) ) ;

Index/key variables: pos, prev
Python program:
def add ( arr , N , lo , hi , val ) :
    arr [ lo ] += val
    if ( hi != N - 1 ) :
        arr [ hi + 1 ] -= val
def updateArray ( arr , N ) :
    for i in range ( 1 , N ) :
        arr [ i ] += arr [ i - 1 ]
def printArr ( arr , N ) :
    updateArray ( arr , N )
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
N = 6
arr = [ 0 for i in range ( N ) ]
add ( arr , N , 0 , 2 , 100 )
add ( arr , N , 1 , 5 , 100 )
add ( arr , N , 2 , 3 , 100 )
printArr ( arr , N )

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