dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def getSum ( BITree , index ) :
    ans = 0
    index += 1
    while ( index > 0 ) :
        ans += BITree [ index ]
        index -= index & ( - index )
    return ans
def updateBIT ( BITree , n , index , val ) :
    index = index + 1
    while ( index <= n ) :
        BITree [ index ] += val
        index += index & ( - index )
def constructBITree ( arr , n ) :
    BITree = [ 0 ] * ( n + 1 )
    for i in range ( n + 1 ) :
        BITree [ i ] = 0
    for i in range ( n ) :
        updateBIT ( BITree , n , i , arr [ i ] )
    return BITree
def getLowerBound ( BITree , arr , n , k ) :
    lb = - 1
    l = 0
    r = n - 1
    while ( l <= r ) :
        mid = l + ( r - l ) // 2
        if ( getSum ( BITree , mid ) >= k ) :
            r = mid - 1
            lb = mid
        else :
            l = mid + 1
    return lb
def performQueries ( A , n , q ) :
    BITree = constructBITree ( A , n )
    for i in range ( len ( q ) ) :
        id = q [ i ] [ 0 ]
        if ( id == 1 ) :
            idx = q [ i ] [ 1 ]
            val = q [ i ] [ 2 ]
            A [ idx ] += val
            updateBIT ( BITree , n , idx , val )
        else :
            k = q [ i ] [ 1 ]
            lb = getLowerBound ( BITree , A , n , k )
            print ( lb )
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 2 , 3 , 5 , 8 ]
    n = len ( A )
    q = [ [ 1 , 0 , 2 ] , [ 2 , 5 , 0 ] , [ 1 , 3 , 5 ] ]
    performQueries ( A , n , q )

Index/key variables: i, idx, index
Accumulator variables: ans
Iterator variables: i
Python program:
cnt = 0
def dfs ( val , cost , tr , u , s ) :
    global cnt
    s = s + cost [ u ]
    if ( s < 0 ) :
        s = 0
    if ( s > val [ u ] ) :
        return
    cnt += 1
    for i in range ( 0 , len ( tr [ u ] ) ) :
        dfs ( val , cost , tr , tr [ u ] [ i ] , s )
if __name__ == " _ _ main _ _ " :
    n = 9
    val = [ 88 , 22 , 83 , 14 , 95 , 91 , 98 , 53 , 11 ]
    cost = [ - 1 , 24 , - 8 , 67 , 64 , 65 , 12 , - 80 , 8 ]
    tr = [ [ ] for i in range ( n + 1 ) ]
    tr [ 0 ] . append ( 3 )
    tr [ 0 ] . append ( 4 )
    tr [ 4 ] . append ( 6 )
    tr [ 6 ] . append ( 2 )
    tr [ 2 ] . append ( 1 )
    tr [ 2 ] . append ( 8 )
    tr [ 8 ] . append ( 5 )
    tr [ 5 ] . append ( 7 )
    dfs ( val , cost , tr , 0 , 0 )
    print ( n - cnt )

Index/key variables: i, u
Iterator variables: i
Python program:
from collections import deque
def BFS ( mat , row , col ) :
    area = 0
    Q = deque ( )
    Q . append ( [ row , col ] )
    while ( len ( Q ) > 0 ) :
        it = Q . popleft ( )
        r , c = it [ 0 ] , it [ 1 ]
        if ( r < 0 or c < 0 or r > 4 or c > 4 ) :
            continue
        if ( mat [ r ] == 0 ) :
            continue
        if ( mat [ r ] == 1 ) :
            mat [ r ] = 0
            area += 1
        Q . append ( [ r + 1 , c ] )
        Q . append ( [ r - 1 , c ] )
        Q . append ( [ r , c + 1 ] )
        Q . append ( [ r , c - 1 ] )
    return area
def sizeOfConnections ( mat ) :
    result = [ ]
    for row in range ( 5 ) :
        for col in range ( 5 ) :
            if ( mat [ row ] [ col ] == 1 ) :
                area = BFS ( mat , row , col ) ;
                result . append ( area )
    for val in result :
        print ( val , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 , 1 ] , [ 1 , 0 , 0 , 1 , 1 ] , [ 1 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 1 , 1 , 1 ] ]
    sizeOfConnections ( mat )

Index/key variables: col, r, row
Accumulator variables: Q, area, result
Iterator variables: col, row, val
Python program:
def maxLen ( A , N ) :
    v = [ ]
    i = 0
    while i < N :
        if ( A [ i ] == 1 ) :
            s = i
            while ( i < N and A [ i ] == 1 ) :
                i += 1
            le = i - s
            v . append ( [ le , s , i - 1 ] )
        i += 1
    if ( len ( v ) == 0 ) :
        return - 1
    ans = 0
    for i in range ( len ( v ) - 1 ) :
        ans = max ( ans , v [ i ] [ 0 ] )
        if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 2 ) :
            ans = max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] )
        if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 1 ) :
            ans = max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] - 1 )
    ans = max ( v [ len ( v ) - 1 ] [ 0 ] , ans )
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 0 , 1 , 0 , 0 , 1 ]
    N = len ( arr )
    print ( maxLen ( arr , N ) )

Index/key variables: i
Accumulator variables: v
Iterator variables: i
Python program:
t = 0
n = 0
m = 0
a = 0
s = [ ]
tsort = [ ]
adj = [ [ ] for i in range ( 100001 ) ]
visited = [ False for i in range ( 100001 ) ]
def dfs ( u ) :
    visited [ u ] = 1
    for it in adj [ u ] :
        if ( visited [ it ] == 0 ) :
            dfs ( it )
    s . append ( u )
def check_cycle ( ) :
    pos = dict ( )
    ind = 0
    while ( len ( s ) != 0 ) :
        pos [ s [ - 1 ] ] = ind
        tsort . append ( s [ - 1 ] )
        ind += 1
        s . pop ( )
    for i in range ( n ) :
        for it in adj [ i ] :
            first = 0 if i not in pos else pos [ i ]
            second = 0 if it not in pos else pos [ it ]
            if ( first > second ) :
                return True
    return False
def addEdge ( u , v ) :
    adj [ u ] . append ( v )
if __name__ == " _ _ main _ _ " :
    n = 4
    m = 5
    addEdge ( 0 , 1 )
    addEdge ( 0 , 2 )
    addEdge ( 1 , 2 )
    addEdge ( 2 , 0 )
    addEdge ( 2 , 3 )
    for i in range ( n ) :
        if ( visited [ i ] == False ) :
            dfs ( i )
    if ( check_cycle ( ) ) :
        print ( ' Yes ' )
    else :
        print ( ' No ' )

Index/key variables: i, it, u
Accumulator variables: ind, tsort
Iterator variables: i, it
Python program:
def printNewArray ( a , n ) :
    v = [ ]
    for i in range ( n ) :
        v . append ( ( a [ i ] , i ) )
    v . sort ( )
    ans = [ 0 ] * n
    for i in range ( n ) :
        ans [ v [ ( i + 1 ) % n ] [ 1 ] ] = v [ i ] [ 0 ]
    for i in range ( n ) :
        print ( ans [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    a = [ 4 , 1 , 2 , 5 , 3 ]
    n = len ( a )
    printNewArray ( a , n )

Index/key variables: i
Accumulator variables: v
Iterator variables: i
Python program:
import sys
def min_remove ( arr , n , k ) :
    arr . sort ( )
    ans = sys . maxsize
    for i in range ( n ) :
        for j in range ( i , n ) :
            if ( arr [ j ] - arr [ i ] <= k ) :
                ans = min ( ans , n - j + i - 1 )
    return ans
if __name__ == " _ _ main _ _ " :
    k = 3
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    n = len ( arr )
    print ( min_remove ( arr , n , k ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def solve ( arr , n ) :
    countzeroes = 0 ;
    countones = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] == 0 ) :
            countzeroes += 1 ;
        else :
            countones += 1 ;
    if ( abs ( countzeroes - countones ) == 1 ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 1 , 0 , 0 , 1 , 1 , 1 ] ;
    n = len ( arr ) ;
    solve ( arr , n ) ;

Index/key variables: i
Accumulator variables: countones, countzeroes
Iterator variables: i
Python program:
def bs ( a , n , ele ) :
    start = 0
    end = n - 1
    ch = ' @ '
    while ( start <= end ) :
        mid = start + ( end - start ) // 2 ;
        if ( ar [ mid ] == ele ) :
            end = mid - 1
        elif ( ar [ mid ] < ele ) :
            ch = ar [ mid ]
            start = mid + 1 ;
        else :
            end = mid - 1 ;
    return ch
if __name__ == ' _ _ main _ _ ' :
    ar = [ ' e ' , ' g ' , ' t ' , ' y ' ]
    n = len ( ar )
    K = ' u ' ;
    ch = bs ( ar , n , K ) ;
    if ( ch == ' @ ' ) :
        print ( ' - 1' )
    else :
        print ( ch )

Index/key variables: mid
Python program:
def findMaxLen ( a , k ) :
    n = len ( a )
    a . sort ( )
    vis = [ 0 ] * n
    mp = { }
    for i in range ( n ) :
        mp [ a [ i ] ] = i
    c = 0
    for i in range ( n ) :
        if ( vis [ i ] == False ) :
            check = a [ i ] * k
            if ( check in mp . keys ( ) ) :
                c += 1
                vis [ mp [ check ] ] = True
    return n - c
if __name__ == ' _ _ main _ _ ' :
    K = 3
    arr = [ 1 , 4 , 3 , 2 ]
    print ( findMaxLen ( arr , K ) )

Index/key variables: check, i
Accumulator variables: c
Iterator variables: i
Python program:
def getPrefixLength ( srcStr , targetStr ) :
    if ( len ( targetStr ) == 0 ) :
        return 0
    srcStr = srcStr . lower ( )
    targetStr = targetStr . lower ( )
    dictCount = dict ( [ ] )
    nUnique = 0
    for ch in targetStr :
        if ( ch not in dictCount ) :
            nUnique += 1
            dictCount [ ch ] = 0
        dictCount [ ch ] += 1
    for i in range ( len ( srcStr ) ) :
        ch = srcStr [ i ]
        if ( ch not in dictCount ) :
            continue
        dictCount [ ch ] -= 1
        if ( dictCount [ ch ] == 0 ) :
            nUnique -= 1
        if ( nUnique == 0 ) :
            return ( i + 1 )
    return - 1
if __name__ == " _ _ main _ _ " :
    S = " MarvoloGaunt "
    T = " Tom "
    print ( getPrefixLength ( S , T ) )

Index/key variables: ch, i
Accumulator variables: nUnique
Iterator variables: ch, i
Python program:
def check ( st , mid , a ) :
    n = len ( st )
    previous = - 1
    for i in range ( n ) :
        if ( st [ i ] == chr ( a ) ) :
            if ( i - previous > mid ) :
                return False
            previous = i
    if ( i - previous > mid ) :
        return False
    else :
        return True
def possible ( st , mid ) :
    for i in range ( 26 ) :
        if ( check ( st , mid , i + ord ( ' a ' ) ) ) :
            return True
    return False
def findMinLength ( st ) :
    low = 1
    high = len ( st )
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( possible ( st , mid ) ) :
            high = mid - 1
        else :
            low = mid + 1
    return high + 1
def ifAllDistinct ( st ) :
    s = [ ]
    for c in st :
        s . append ( c )
    return len ( set ( s ) ) == len ( st )
if __name__ == " _ _ main _ _ " :
    st = " geeksforgeeks "
    if ( ifAllDistinct ( st ) ) :
        print ( " - 1" )
    else :
        print ( findMinLength ( st ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: c, i
Python program:
def solve ( A , N ) :
    i = 0
    k = 0
    for j in range ( 1 , N ) :
        tempK = ( min ( A [ i ] , A [ j ] ) // ( j - i ) )
        if ( tempK > k ) :
            k = tempK
        if ( A [ j ] >= A [ i ] // ( j - i ) ) :
            i = j
    return k
if __name__ == " _ _ main _ _ " :
    A = [ 10 , 5 , 12 , 15 , 8 ]
    N = len ( A ) ;
    print ( solve ( A , N ) )

Index/key variables: i, j
Iterator variables: j
Python program:
def split ( arr , n ) :
    arr . sort ( )
    count = 1
    for i in range ( 1 , n ) :
        if ( arr [ i ] - arr [ i - 1 ] == 1 ) :
            count = 2
            break
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 6 ]
    n = len ( arr )
    split ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def check ( str1 , str2 ) :
    mark = [ False for i in range ( 26 ) ]
    n = len ( str1 )
    m = len ( str2 )
    for i in range ( n ) :
        mark [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] = True
    for i in range ( m ) :
        if ( mark [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] ) :
            return True ;
    return False
if __name__ == " _ _ main _ _ " :
    str1 = " abca "
    str2 = " efad "
    if ( check ( str1 , str2 ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Iterator variables: i
Python program:
from math import sqrt
def FindPairs ( n , k ) :
    print ( 1 , n )
    k -= 1
    for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            print ( 1 , i )
            k -= 1
            if ( k == 0 ) :
                break
            if ( i != n // i ) :
                print ( 1 , n // i )
                k -= 1
            if ( k == 0 ) :
                break
if __name__ == ' _ _ main _ _ ' :
    N = 100
    K = 5
    FindPairs ( N , K )

Accumulator variables: k
Iterator variables: i
Python program:
def PermuteTheArray ( A , n ) :
    arr = [ 0 ] * n
    for i in range ( n ) :
        arr [ A [ i ] - 1 ] = i
    mini = n
    maxi = 0
    count = 0
    for i in range ( n ) :
        mini = min ( mini , arr [ i ] )
        maxi = max ( maxi , arr [ i ] )
        if ( maxi - mini == i ) :
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    A = [ 4 , 5 , 1 , 3 , 2 , 6 ]
    print ( PermuteTheArray ( A , 6 ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findLargest ( beg , end , arr , n ) :
    if ( beg == end ) :
        compared = [ 0 ] * n
        compared [ 0 ] = 1
        compared [ 1 ] = arr [ beg ]
        return compared
    compared1 = findLargest ( beg , ( beg + end ) // 2 , arr , n )
    compared2 = findLargest ( ( beg + end ) // 2 + 1 , end , arr , n )
    if ( compared1 [ 1 ] > compared2 [ 1 ] ) :
        k = compared1 [ 0 ] + 1
        compared1 [ 0 ] = k
        compared1 [ k ] = compared2 [ 1 ]
        return compared1
    else :
        k = compared2 [ 0 ] + 1
        compared2 [ 0 ] = k
        compared2 [ k ] = compared1 [ 1 ]
        return compared2
def findSecondLargest ( end , arr ) :
    compared1 = findLargest ( 0 , end - 1 , arr , end )
    compared2 = findLargest ( 2 , compared1 [ 0 ] + 2 , compared1 , compared1 [ 0 ] )
    print ( compared2 [ 1 ] )
N = 10
arr = [ 20 , 1990 , 12 , 1110 , 1 , 59 , 12 , 15 , 120 , 1110 ]
findSecondLargest ( N , arr )

Index/key variables: beg, k
Python program:
def CountsubString ( strr , n ) :
    c = 0
    for len in range ( n + 1 ) :
        for i in range ( n - len ) :
            j = i + len - 1
            temp = strr [ i ]
            f = 0
            if ( j == i ) :
                c += 1
                continue
            k = i + 1
            while ( k <= j and temp > strr [ k ] ) :
                temp = strr [ k ]
                k += 1
            if ( k > j ) :
                c += 1
                f = 2
            while ( k <= j and f != 2 and temp < strr [ k ] ) :
                temp = strr [ k ]
                k += 1
            if ( k > j and f != 2 ) :
                c += 1
                f = 0
    return c
if __name__ == ' _ _ main _ _ ' :
    strr = " bade "
    print ( CountsubString ( strr , len ( strr ) ) )

Index/key variables: i, k
Accumulator variables: c
Iterator variables: i, len
Python program:
import math
def isSubsetSum ( arr , n , sum ) :
    subset = [ [ True for x in range ( sum + 1 ) ] for y in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        subset [ i ] [ 0 ] = True
    for i in range ( 1 , sum + 1 ) :
        subset [ 0 ] [ i ] = False
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , sum + 1 ) :
            if ( j < arr [ i - 1 ] ) :
                subset [ i ] [ j ] = subset [ i - 1 ] [ j ]
            if ( j >= arr [ i - 1 ] ) :
                subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - arr [ i - 1 ] ] )
    return subset [ n ] [ sum ]
def findSum ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    val = int ( math . sqrt ( sum ) )
    for i in range ( val , - 1 , - 1 ) :
        if ( isSubsetSum ( arr , n , i * i ) ) :
            return i * i
    return 0
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
    n = len ( arr )
    print ( findSum ( arr , n ) )

Index/key variables: i, j, n, sum
Iterator variables: i, j
Python program:
def findsubArray ( arr , N , K ) :
    res = N + 1
    for i in range ( 0 , N ) :
        curr_prad = 1
        for j in range ( i , N ) :
            curr_prad = curr_prad * arr [ j ]
            if ( curr_prad % N == K and res > ( j - i + 1 ) ) :
                res = min ( res , j - i + 1 )
                break
    if res == N + 1 :
        return 0
    else :
        return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 2 , 3 ]
    N = len ( arr )
    K = 1
    answer = findsubArray ( arr , N , K )
    if ( answer != 0 ) :
        print ( answer )
    else :
        print ( - 1 )

Index/key variables: j
Iterator variables: i, j
Python program:
import queue
def maximumCount ( A , B , n ) :
    q = queue . Queue ( )
    s = set ( )
    for i in range ( n ) :
        s . add ( B [ i ] )
        q . put ( B [ i ] )
    count = 0
    for i in range ( n ) :
        if ( A [ i ] not in s ) :
            continue
        while ( q . qsize ( ) > 0 and q . queue [ 0 ] != A [ i ] ) :
            s . remove ( q . queue [ 0 ] ) ;
            q . get ( )
            count += 1
        if ( A [ i ] == q . queue [ 0 ] ) :
            q . get ( )
            s . remove ( A [ i ] )
        if ( q . qsize ( ) == 0 ) :
            break
    print ( count )
N = 4
A = [ 1 , 2 , 3 , 4 ]
B = [ 1 , 2 , 4 , 3 ]
maximumCount ( A , B , N )

Index/key variables: i
Accumulator variables: count, s
Iterator variables: i
Python program:
N = 3
M = 3
def checkBitonic ( arr , n ) :
    i , j , f = 0 , 0 , 0
    for i in range ( 1 , n ) :
        if ( arr [ i ] > arr [ i - 1 ] ) :
            continue
        if ( arr [ i ] == arr [ i - 1 ] ) :
            return False
        else :
            f = 1
            break
    if ( i == n ) :
        return True
    for j in range ( i + 1 , n ) :
        if ( arr [ j ] < arr [ j - 1 ] ) :
            continue
        if ( arr [ i ] == arr [ i - 1 ] ) :
            return False
        else :
            if ( f == 1 ) :
                return False
    return True
def check ( arr ) :
    f = 0
    for i in range ( N ) :
        if ( not checkBitonic ( arr [ i ] , M ) ) :
            print ( " NO " )
            return
    i = 0
    for i in range ( N ) :
        temp = [ 0 ] * N
        for j in range ( N ) :
            temp [ j ] = arr [ j ] [ i ]
        if ( not checkBitonic ( temp , N ) ) :
            print ( " NO " )
            return
    print ( " YES " )
if __name__ == ' _ _ main _ _ ' :
    m = [ [ 1 , 2 , 3 ] , [ 3 , 4 , 5 ] , [ 2 , 6 , 4 ] ]
    check ( m )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import sys
import math
def getMaxGcd ( N ) :
    maxGcd = - sys . maxsize - 1
    for i in range ( 1 , int ( math . sqrt ( N ) ) + 1 ) :
        if ( N % i == 0 ) :
            A = i
            B = N // i
            maxGcd = max ( maxGcd , math . gcd ( A , B ) )
    return maxGcd
N = 18
print ( getMaxGcd ( N ) )

Iterator variables: i
Python program:
def can_place ( A , n , B , mid ) :
    count = 1
    last_position = A [ 0 ]
    for i in range ( 1 , n ) :
        if ( A [ i ] - last_position >= mid ) :
            last_position = A [ i ]
            count = count + 1
            if ( count == B ) :
                return bool ( True )
    return bool ( False )
def find_min_difference ( A , n , B ) :
    A . sort ( )
    s = 0
    e = A [ n - 1 ] - A [ 0 ]
    ans = 0
    while ( s <= e ) :
        mid = ( int ) ( ( s + e ) / 2 )
        if ( can_place ( A , n , B , mid ) ) :
            ans = mid
            s = mid + 1
        else :
            e = mid - 1
    return ans
A = [ 1 , 2 , 3 , 5 ]
n = len ( A )
B = 3
min_difference = find_min_difference ( A , n , B )
print ( min_difference )

Index/key variables: i
Iterator variables: i
Python program:
from collections import defaultdict
def countTriplets ( A , N ) :
    ans = 0
    map = defaultdict ( lambda : 0 )
    for j in range ( N - 2 , 0 , - 1 ) :
        map [ A [ j + 1 ] ] += 1
        for i in range ( j ) :
            target = A [ i ] * A [ j ]
            if ( target in map . keys ( ) ) :
                ans += map [ target ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    A = [ 2 , 3 , 4 , 6 , 12 ]
    print ( countTriplets ( A , N ) )

Index/key variables: i, j, target
Accumulator variables: ans
Iterator variables: i, j
Python program:
from collections import defaultdict
def MissingPoint ( V , N ) :
    mp = defaultdict ( lambda : 0 )
    for i in range ( len ( V ) ) :
        mp [ V [ i ] [ 0 ] ] += 1
    for it in mp . keys ( ) :
        if ( mp [ it ] % 2 == 1 ) :
            x = it
            break
    del mp
    mp = defaultdict ( lambda : 0 )
    for i in range ( len ( V ) ) :
        mp [ V [ i ] [ 1 ] ] += 1
    for it in mp . keys ( ) :
        if ( mp [ it ] % 2 == 1 ) :
            y = it
            break
    print ( x , y )
if __name__ == ' _ _ main _ _ ' :
    N = 2
    V = [ ]
    V . append ( [ 1 , 1 ] )
    V . append ( [ 1 , 2 ] )
    V . append ( [ 4 , 6 ] )
    V . append ( [ 2 , 1 ] )
    V . append ( [ 9 , 6 ] )
    V . append ( [ 9 , 3 ] )
    V . append ( [ 4 , 3 ] )
    MissingPoint ( V , N )

Index/key variables: i, it
Iterator variables: i, it
Python program:
def sign ( x ) :
    if ( x > 0 ) :
        return 1
    else :
        return - 1
def findMaxSum ( arr , size ) :
    max_sum = 0
    i = 0
    while i < size :
        pres = arr [ i ]
        j = i
        while ( j < size and ( sign ( arr [ i ] ) == sign ( arr [ j ] ) ) ) :
            pres = max ( pres , arr [ j ] )
            j += 1
        max_sum = max_sum + pres
        i = j - 1
        i += 1
    return max_sum
if __name__ == " _ _ main _ _ " :
    arr = [ - 2 , 8 , 3 , 8 , - 4 , - 15 , 5 , - 2 , - 3 , 1 ]
    size = len ( arr )
    print ( findMaxSum ( arr , size ) )

Index/key variables: i, j
Python program:
from collections import defaultdict
def groupInKConsecutive ( arr , K ) :
    count = defaultdict ( int )
    for h in arr :
        count [ h ] += 1
    for key , value in count . items ( ) :
        cur = key
        n = value
        if ( n > 0 ) :
            for i in range ( 1 , K ) :
                if ( ( cur + i ) not in count ) :
                    return False
                count [ cur + i ] -= n
                if ( count [ cur + i ] < 0 ) :
                    return False
    return True
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 6 , 2 , 3 , 4 , 7 , 8 ]
    k = 3
    if ( groupInKConsecutive ( arr , k ) ) :
        print ( " True " )
    else :
        print ( " False " )

Index/key variables: h
Iterator variables: h, i, key, value
Python program:
def countSubAllOnes ( s ) :
    l , r , ans = 0 , 0 , 0
    while ( l <= r ) :
        if ( r == len ( s ) ) :
            ans += ( ( r - l ) * ( r - l + 1 ) ) // 2
            break
        if ( s [ r ] == '1' ) :
            r += 1
        else :
            ans += ( ( r - l ) * ( r - l + 1 ) ) // 2
            l = r + 1
            r += 1
    return ans
def flip ( s ) :
    arr = list ( s )
    for i in range ( len ( s ) ) :
        if ( arr [ i ] == '1' ) :
            arr [ i ] = '0'
        else :
            arr [ i ] = '1'
    s = ' ' . join ( arr )
    return s
def countSubAllZerosOnes ( s ) :
    only_1s = countSubAllOnes ( s )
    s = flip ( s )
    only_0s = countSubAllOnes ( s )
    return only_0s + only_1s
if __name__ == " _ _ main _ _ " :
    s = "011"
    print ( countSubAllZerosOnes ( s ) )

Index/key variables: i, r
Accumulator variables: ans
Iterator variables: i
Python program:
def count_elements ( arr ) :
    count = 1
    max = arr [ 0 ]
    for i in range ( 1 , len ( arr ) ) :
        if arr [ i ] > max :
            count += 1
            max = arr [ i ]
    return count
arr = [ 2 , 1 , 4 , 6 , 3 ]
print ( count_elements ( arr ) )

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