dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def maxProfit ( n , k , prices ) :
    ans = 0
    buy = 0
    sell = 0
    transaction = [ ]
    profits = [ ]
    while ( sell < n ) :
        buy = sell
        while ( buy < n - 1 and prices [ buy ] >= prices [ buy + 1 ] ) :
            buy += 1
        sell = buy + 1
        while ( sell < n and prices [ sell ] >= prices [ sell - 1 ] ) :
            sell += 1
        while ( len ( transaction ) != 0 and prices [ buy ] < prices [ transaction [ len ( transaction ) - 1 ] [ 0 ] ] ) :
            p = transaction [ len ( transaction ) - 1 ]
            profits . append ( prices [ p [ 1 ] - 1 ] - prices [ p [ 0 ] ] )
            transaction . remove ( transaction [ len ( transaction ) - 1 ] )
        profits . sort ( reverse = True )
        while ( len ( transaction ) != 0 and prices [ sell - 1 ] > prices [ transaction [ len ( transaction ) - 1 ] [ 1 ] - 1 ] ) :
            p = transaction [ len ( transaction ) - 1 ]
            profits . append ( prices [ p [ 1 ] - 1 ] - prices [ buy ] )
            buy = p [ 0 ]
            transaction . remove ( transaction [ len ( transaction ) - 1 ] )
        transaction . append ( [ buy , sell ] )
    profits . sort ( reverse = True )
    while ( len ( transaction ) != 0 ) :
        profits . append ( prices [ transaction [ len ( transaction ) - 1 ] [ 1 ] - 1 ] - prices [ transaction [ len ( transaction ) - 1 ] [ 0 ] ] )
        transaction . remove ( transaction [ len ( transaction ) - 1 ] )
    profits . sort ( reverse = True )
    while ( k != 0 and len ( profits ) != 0 ) :
        ans += profits [ 0 ]
        profits . remove ( profits [ 0 ] )
        k -= 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    k = 3
    prices = [ 1 , 12 , 10 , 7 , 10 , 13 , 11 , 10 , 7 , 6 , 9 ]
    n = len ( prices )
    print ( " Maximum ▁ profit ▁ is " , maxProfit ( n , k , prices ) )

Index/key variables: buy, sell
Accumulator variables: ans, k, profits, transaction
Python program:
def findSum ( L , R ) :
    arr = [ ]
    i = 0
    x = 2
    k = 0
    while ( i <= R ) :
        arr . insert ( k , i + x )
        k += 1
        if ( i + 1 <= R ) :
            arr . insert ( k , i + 1 + x )
        k += 1
        x *= - 1
        i += 2
    sum = 0
    for i in range ( L , R + 1 ) :
        sum += arr [ i ]
    return sum
L = 0
R = 5
print ( findSum ( L , R ) )

Index/key variables: i
Accumulator variables: k, sum, x
Iterator variables: i
Python program:
def GCD ( a , b ) :
    if ( b == 0 ) :
        return a
    return GCD ( b , a % b )
def FillPrefixSuffix ( prefix , arr , suffix , n ) :
    prefix [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        prefix [ i ] = GCD ( prefix [ i - 1 ] , arr [ i ] )
    suffix [ n - 1 ] = arr [ n - 1 ]
    for i in range ( n - 2 , - 1 , - 1 ) :
        suffix [ i ] = GCD ( suffix [ i + 1 ] , arr [ i ] )
def GCDoutsideRange ( l , r , prefix , suffix , n ) :
    if ( l == 0 ) :
        return suffix [ r + 1 ]
    if ( r == n - 1 ) :
        return prefix [ l - 1 ]
    return GCD ( prefix [ l - 1 ] , suffix [ r + 1 ] )
arr = [ 2 , 6 , 9 ]
n = len ( arr )
prefix = [ ]
suffix = [ ]
for i in range ( n + 1 ) :
    prefix . append ( 0 )
    suffix . append ( 0 )
FillPrefixSuffix ( prefix , arr , suffix , n )
l = 0
r = 0
print ( GCDoutsideRange ( l , r , prefix , suffix , n ) )
l = 1
r = 1
print ( GCDoutsideRange ( l , r , prefix , suffix , n ) )
l = 1
r = 2
print ( GCDoutsideRange ( l , r , prefix , suffix , n ) )

Index/key variables: i
Accumulator variables: prefix, suffix
Iterator variables: i
Python program:
import heapq
def check ( A , B , N ) :
    pq1 = [ ]
    pq2 = [ ]
    for i in range ( N ) :
        heapq . heappush ( pq1 , - A [ i ] )
    for i in range ( N ) :
        heapq . heappush ( pq2 , - B [ i ] )
    c = 0
    for i in range ( N ) :
        if - pq1 [ 0 ] > - pq2 [ 0 ] :
            c += 1
            heapq . heappop ( pq1 )
            heapq . heappop ( pq2 )
        else :
            if len ( pq2 ) == 0 :
                break
            heapq . heappop ( pq2 )
    return ( c )
A = [ 10 , 3 , 7 , 5 , 8 ]
B = [ 8 , 6 , 2 , 5 , 9 ]
N = len ( A )
print ( check ( A , B , N ) )

Index/key variables: i
Accumulator variables: c
Iterator variables: i
Python program:
MAX = 10001
def update ( idx , blk , val , bit ) :
    while idx < MAX :
        bit [ blk ] [ idx ] += val
        idx += ( idx & - idx )
def query ( l , r , k , arr , blk_sz , bit ) :
    summ = 0
    while l < r and l % blk_sz != 0 and l != 0 :
        if arr [ l ] <= k :
            summ += 1
        l += 1
    while l + blk_sz <= r :
        idx = k
        while idx > 0 :
            summ += bit [ l // blk_sz ] [ idx ]
            idx -= ( idx & - idx )
        l += blk_sz
    while l <= r :
        if arr [ l ] <= k :
            summ += 1
        l += 1
    return summ
def preprocess ( arr , blk_sz , n , bit ) :
    for i in range ( n ) :
        update ( arr [ i ] , i // blk_sz , 1 , bit )
def preprocessUpdate ( i , v , blk_sz , arr , bit ) :
    update ( arr [ i ] , i // blk_sz , - 1 , bit )
    update ( v , i // blk_sz , 1 , bit )
    arr [ i ] = v
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 1 , 2 , 3 , 4 ]
    n = len ( arr )
    from math import sqrt
    blk_sz = int ( sqrt ( n ) )
    bit = [ [ 0 for i in range ( MAX ) ] for j in range ( blk_sz + 1 ) ]
    preprocess ( arr , blk_sz , n , bit )
    print ( query ( 1 , 3 , 1 , arr , blk_sz , bit ) )
    preprocessUpdate ( 3 , 10 , blk_sz , arr , bit )
    print ( query ( 3 , 3 , 4 , arr , blk_sz , bit ) )
    preprocessUpdate ( 2 , 1 , blk_sz , arr , bit )
    preprocessUpdate ( 0 , 2 , blk_sz , arr , bit )
    print ( query ( 0 , 4 , 5 , arr , blk_sz , bit ) )

Index/key variables: blk, i, idx, l
Accumulator variables: summ
Iterator variables: i
Python program:
def countInRange ( arr , n , x , y ) :
    count = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] >= x and arr [ i ] <= y ) :
            count += 1
    return count
arr = [ 1 , 3 , 4 , 9 , 10 , 3 ]
n = len ( arr )
i = 1
j = 4
print ( countInRange ( arr , n , i , j ) )
i = 9
j = 12
print ( countInRange ( arr , n , i , j ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def dijkstra ( s , d , gr ) :
    if ( s == d ) :
        return 0 ;
    pq = [ ] ;
    pq . append ( ( 1 , s ) ) ;
    v = [ 0 ] * ( len ( gr ) + 1 ) ;
    while ( len ( pq ) != 0 ) :
        curr = pq [ 0 ] [ 1 ] ;
        dist = pq [ 0 ] [ 0 ] ;
        pq . pop ( ) ;
        if ( v [ curr ] ) :
            continue ;
        v [ curr ] = 1 ;
        if ( curr == d ) :
            return dist ;
        for it in gr [ curr ] :
            if it not in pq :
                pq . insert ( 0 , ( dist * it [ 1 ] , it [ 0 ] ) ) ;
    return - 1 ;
if __name__ == " _ _ main _ _ " :
    n = 3 ;
    gr = { } ;
    gr [ 1 ] = [ ( 3 , 9 ) ] ;
    gr [ 2 ] = [ ( 3 , 1 ) ] ;
    gr [ 1 ] . append ( ( 2 , 5 ) ) ;
    gr [ 3 ] = [ ] ;
    s = 1 ; d = 3 ;
    print ( dijkstra ( s , d , gr ) ) ;

Index/key variables: curr
Iterator variables: it
Python program:
from math import pow
def precompute ( arr , n , pre ) :
    pre [ n - 1 ] = arr [ n - 1 ] * pow ( 2 , 0 )
    i = n - 2
    while ( i >= 0 ) :
        pre [ i ] = ( pre [ i + 1 ] + arr [ i ] * ( 1 << ( n - 1 - i ) ) )
        i -= 1
def decimalOfSubarr ( arr , l , r , n , pre ) :
    if ( r != n - 1 ) :
        return ( ( pre [ l ] - pre [ r + 1 ] ) / ( 1 << ( n - 1 - r ) ) )
    return pre [ l ] / ( 1 << ( n - 1 - r ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 1 , 0 , 1 , 1 ]
    n = len ( arr )
    pre = [ 0 for i in range ( n ) ]
    precompute ( arr , n , pre )
    print ( int ( decimalOfSubarr ( arr , 2 , 4 , n , pre ) ) )
    print ( int ( decimalOfSubarr ( arr , 4 , 5 , n , pre ) ) )

Index/key variables: i, l
Python program:
def answerQuery ( a , n , l , r ) :
    count = 0
    l = l - 1
    for i in range ( l , r , 1 ) :
        element = a [ i ]
        divisors = 0
        for j in range ( l , r , 1 ) :
            if ( a [ j ] % a [ i ] == 0 ) :
                divisors += 1
            else :
                break
        if ( divisors == ( r - l ) ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 2 , 3 , 5 ]
    n = len ( a )
    l = 1
    r = 4
    print ( answerQuery ( a , n , l , r ) )
    l = 2
    r = 4
    print ( answerQuery ( a , n , l , r ) )

Index/key variables: i, j
Accumulator variables: count, divisors
Iterator variables: i, j
Python program:
def minBinary ( n ) :
    digit = [ 0 for i in range ( 3 ) ]
    len = 0
    while ( n > 0 ) :
        digit [ len ] = n % 10
        len += 1
        n //= 10
    digit = digit [ : : - 1 ]
    ans = 0
    for i in range ( len ) :
        ans = max ( ans , digit [ i ] )
    print ( " Minimum ▁ Number ▁ of ▁ binary ▁ strings ▁ needed : " , ans )
    for i in range ( 1 , ans + 1 , 1 ) :
        num = 0
        for j in range ( 0 , len , 1 ) :
            if ( digit [ j ] > 0 ) :
                num = num * 10 + 1
                digit [ j ] -= 1
            else :
                num *= 10
        print ( num , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    n = 564
    minBinary ( n )

Index/key variables: i, j, len
Accumulator variables: n, num
Iterator variables: i, j
Python program:
import math
one = [ [ 0 for x in range ( 32 ) ] for y in range ( 100001 ) ]
MAX = 2147483647
def make_prefix ( A , n ) :
    global one , MAX
    for j in range ( 0 , 32 ) :
        one [ 0 ] [ j ] = 0
    for i in range ( 1 , n + 1 ) :
        a = A [ i - 1 ]
        for j in range ( 0 , 32 ) :
            x = int ( math . pow ( 2 , j ) )
            if ( a & x ) :
                one [ i ] [ j ] = 1 + one [ i - 1 ] [ j ]
            else :
                one [ i ] [ j ] = one [ i - 1 ] [ j ]
def Solve ( L , R ) :
    global one , MAX
    l = L
    r = R
    tot_bits = r - l + 1
    X = MAX
    for i in range ( 0 , 31 ) :
        x = one [ r ] [ i ] - one [ l - 1 ] [ i ]
        if ( x >= ( tot_bits - x ) ) :
            ith_bit = pow ( 2 , i )
            X = X ^ ith_bit
    return X
n = 5
q = 3
A = [ 210 , 11 , 48 , 22 , 133 ]
L = [ 1 , 4 , 2 ]
R = [ 3 , 14 , 4 ]
make_prefix ( A , n )
for j in range ( 0 , q ) :
    print ( Solve ( L [ j ] , R [ j ] ) , end = " " )

Index/key variables: i, j, r
Iterator variables: i, j
Python program:
def type1 ( arr , start , limit ) :
    for i in range ( start , limit + 1 ) :
        arr [ i ] += 1
def type2 ( arr , query , start , limit ) :
    for i in range ( start , limit + 1 ) :
        if ( query [ i ] [ 0 ] == 1 ) :
            type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] )
        elif ( query [ i ] [ 0 ] == 2 ) :
            type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] )
n = 5
m = 5
arr = [ 0 for i in range ( n + 1 ) ]
temp = [ 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 ]
query = [ [ 0 for i in range ( 3 ) ] for j in range ( 6 ) ]
j = 0
for i in range ( 1 , m + 1 ) :
    query [ i ] [ 0 ] = temp [ j ]
    j += 1
    query [ i ] [ 1 ] = temp [ j ]
    j += 1
    query [ i ] [ 2 ] = temp [ j ]
    j += 1
for i in range ( 1 , m + 1 ) :
    if ( query [ i ] [ 0 ] == 1 ) :
        type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] )
    elif ( query [ i ] [ 0 ] == 2 ) :
        type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] )
for i in range ( 1 , n + 1 ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i
Python program:
def record_sum ( record , l , r , n , adder ) :
    for i in range ( l , r + 1 ) :
        record [ i ] += adder
n = 5
m = 5
arr = [ 0 ] * n
query = [ [ 1 , 1 , 2 ] , [ 1 , 4 , 5 ] , [ 2 , 1 , 2 ] , [ 2 , 1 , 3 ] , [ 2 , 3 , 4 ] ]
record = [ 0 ] * m
for i in range ( m - 1 , - 1 , - 1 ) :
    if ( query [ i ] [ 0 ] == 2 ) :
        record_sum ( record , query [ i ] [ 1 ] - 1 , query [ i ] [ 2 ] - 1 , m , record [ i ] + 1 )
    else :
        record_sum ( record , i , i , m , 1 )
for i in range ( m ) :
    if ( query [ i ] [ 0 ] == 1 ) :
        record_sum ( arr , query [ i ] [ 1 ] - 1 , query [ i ] [ 2 ] - 1 , n , record [ i ] )
for i in range ( n ) :
    print ( arr [ i ] , end = ' ▁ ' )

Index/key variables: i
Iterator variables: i
Python program:
import math
max = 10000
def update ( arr , l ) :
    arr [ l ] += arr [ l - 1 ]
def record_func ( block_size , block , record , l , r , value ) :
    while ( l < r and l % block_size != 0 and l != 0 ) :
        record [ l ] += value
        l += 1
    while ( l + block_size <= r + 1 ) :
        block [ l // block_size ] += value
        l += block_size
    while ( l <= r ) :
        record [ l ] += value
        l += 1
def print_array ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    n = 5
    m = 5
    arr = [ 0 ] * n
    record = [ 0 ] * m
    block_size = ( int ) ( math . sqrt ( m ) )
    block = [ 0 ] * max
    command = [ [ 1 , 1 , 2 ] , [ 1 , 4 , 5 ] , [ 2 , 1 , 2 ] , [ 2 , 1 , 3 ] , [ 2 , 3 , 4 ] ]
    for i in range ( m - 1 , - 1 , - 1 ) :
        if ( command [ i ] [ 0 ] == 2 ) :
            x = i // ( block_size )
            record_func ( block_size , block , record , command [ i ] [ 1 ] - 1 , command [ i ] [ 2 ] - 1 , ( block [ x ] + record [ i ] + 1 ) )
        else :
            record [ i ] += 1
    for i in range ( m ) :
        check = ( i // block_size )
        record [ i ] += block [ check ]
    for i in range ( m ) :
        if ( command [ i ] [ 0 ] == 1 ) :
            arr [ command [ i ] [ 1 ] - 1 ] += record [ i ]
            if ( ( command [ i ] [ 2 ] - 1 ) < n - 1 ) :
                arr [ ( command [ i ] [ 2 ] ) ] -= record [ i ]
    for i in range ( 1 , n ) :
        update ( arr , i )
    print_array ( arr , n )

Index/key variables: check, i, l, x
Iterator variables: i
Python program:
class Query :
    def __init__ ( self , L , R , X ) :
        self . L = L
        self . R = R
        self . X = X
maxn = 100
root = [ 0 ] * maxn
def find ( x ) :
    if x == root [ x ] :
        return x
    else :
        root [ x ] = find ( root [ x ] )
        return root [ x ]
def uni ( x , y ) :
    p = find ( x )
    q = find ( y )
    if p != q :
        root [ p ] = root [ q ]
def initialize ( a , n , q , m ) :
    for i in range ( n ) :
        root [ i ] = i
    for i in range ( 1 , n ) :
        if a [ i ] == a [ i - 1 ] :
            uni ( i , i - 1 )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 1 , 5 , 4 , 5 ]
    n = len ( a )
    q = [ Query ( 0 , 2 , 2 ) , Query ( 1 , 4 , 1 ) , Query ( 2 , 4 , 5 ) ]
    m = len ( q )
    initialize ( a , n , q , m )
    for i in range ( m ) :
        flag = False
        l = q [ i ] . L
        r = q [ i ] . R
        x = q [ i ] . X
        p = r
        while p >= l :
            if a [ p ] == x :
                flag = True
                break
            p = find ( p ) - 1
        if flag :
            print ( " % d ▁ exists ▁ between ▁ [ % d , ▁ % d ] " % ( x , l , r ) )
        else :
            print ( " % d ▁ does ▁ not ▁ exists ▁ between ▁ [ % d , ▁ % d ] " % ( x , l , r ) )

Index/key variables: i, p, q, x
Iterator variables: i
Boolean variables: flag
Class/struct names: Query
Python program:
def findCountOfPairs ( a , b , n ) :
    ans = 0
    for i in range ( 1 , a + 1 ) :
        ans += b // n
        ans += 1 if ( i % n + b % n ) >= n else 0
    return ans
a = 5 ; b = 13 ; n = 3
print ( findCountOfPairs ( a , b , n ) )

Accumulator variables: ans
Iterator variables: i
Python program:
def findCountOfPairs ( a , b , n ) :
    if ( a > b ) :
        a , b = b , a
    temp = 1
    count = 0
    i = n
    while ( temp > 0 ) :
        if ( a >= i ) :
            temp = i - 1
        elif ( b >= i ) :
            temp = a
        elif ( i > b ) :
            temp = a - ( i - b ) + 1
        if ( temp > 0 ) :
            count += temp
        i += n
    return count
a = 5
b = 13
n = 3
print ( findCountOfPairs ( a , b , n ) )

Accumulator variables: count, i
Python program:
import math as mt
def solveQuery ( start , end , arr ) :
    frequency = dict ( )
    for i in range ( start , end + 1 ) :
        if arr [ i ] in frequency . keys ( ) :
            frequency [ arr [ i ] ] += 1
        else :
            frequency [ arr [ i ] ] = 1
    count = 0
    for x in frequency :
        if x == frequency [ x ] :
            count += 1
    return count
A = [ 1 , 2 , 2 , 3 , 3 , 3 ]
n = len ( A )
queries = [ [ 0 , 1 ] , [ 1 , 1 ] , [ 0 , 2 ] , [ 1 , 3 ] , [ 3 , 5 ] , [ 0 , 5 ] ]
q = len ( queries )
for i in range ( q ) :
    start = queries [ i ] [ 0 ]
    end = queries [ i ] [ 1 ]
    print ( " Answer ▁ for ▁ Query ▁ " , ( i + 1 ) , " ▁ = ▁ " , solveQuery ( start , end , A ) )

Index/key variables: i, x
Accumulator variables: count
Iterator variables: i, x
Python program:
def minItems ( k , r ) :
    for i in range ( 1 , 10 ) :
        if ( ( i * k - r ) % 10 == 0 or ( i * k ) % 10 == 0 ) :
            return i
    return 10 ;
if __name__ == " _ _ main _ _ " :
    k , r = 15 , 2 ;
    print ( minItems ( k , r ) )

Iterator variables: i
Python program:
def answer_query ( a , n , l , r ) :
    count = 0
    for i in range ( l , r ) :
        if ( a [ i ] == a [ i + 1 ] ) :
            count += 1
    return count
a = [ 1 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 ]
n = len ( a )
L = 1
R = 8
print ( answer_query ( a , n , L , R ) )
L = 0
R = 4
print ( answer_query ( a , n , L , R ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
from collections import deque
class Node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
grid = { }
def addConsideringGrid ( root , level , index ) :
    global grid
    if ( root == None ) :
        return
    grid [ level - index ] = ( grid . get ( level - index , 0 ) + root . data )
    addConsideringGrid ( root . left , level + 1 , index - 1 )
    addConsideringGrid ( root . right , level + 1 , index + 1 )
def diagonalSum ( root ) :
    addConsideringGrid ( root , 0 , 0 )
    ans = [ ]
    for x in grid :
        ans . append ( grid [ x ] )
    return ans
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . left . left = Node ( 9 )
    root . left . right = Node ( 6 )
    root . right . left = Node ( 4 )
    root . right . right = Node ( 5 )
    root . right . left . right = Node ( 7 )
    root . right . left . left = Node ( 12 )
    root . left . right . left = Node ( 11 )
    root . left . left . right = Node ( 10 )
    v = diagonalSum ( root )
    for i in v :
        print ( i , end = " ▁ " )

Index/key variables: x
Accumulator variables: ans
Iterator variables: i, x
Class/struct names: Node
Python program:
N = 1000
prefixans = [ 0 ] * N ;
def countIndex ( a , n ) :
    global N , prefixans
    for i in range ( 0 , n - 1 ) :
        if ( a [ i ] == a [ i + 1 ] ) :
            prefixans [ i ] = 1
        if ( i != 0 ) :
            prefixans [ i ] = ( prefixans [ i ] + prefixans [ i - 1 ] )
def answer_query ( l , r ) :
    global N , prefixans
    if ( l == 0 ) :
        return prefixans [ r - 1 ]
    else :
        return ( prefixans [ r - 1 ] - prefixans [ l - 1 ] )
a = [ 1 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 ]
n = len ( a )
countIndex ( a , n )
L = 1
R = 8
print ( answer_query ( L , R ) )
L = 0
R = 4
print ( answer_query ( L , R ) )

Index/key variables: i
Iterator variables: i
Python program:
def primeSubarrays ( A , n ) :
    max_val = 10 ** 7
    prime = [ True ] * ( max_val + 1 )
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , int ( max_val ** ( 0.5 ) ) + 1 ) :
        if prime [ p ] == True :
            for i in range ( 2 * p , max_val + 1 , p ) :
                prime [ i ] = False
    cnt = 0
    for i in range ( 0 , n - 1 ) :
        val = A [ i ]
        for j in range ( i + 1 , n ) :
            val += A [ j ]
            if prime [ val ] == True :
                cnt += 1
    return cnt
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 2 , 3 , 4 , 5 ]
    n = len ( A )
    print ( primeSubarrays ( A , n ) )

Index/key variables: i, j, p, val
Accumulator variables: cnt
Iterator variables: i, j, p
Python program:
def repeated_digit ( n ) :
    a = [ ]
    while n != 0 :
        d = n % 10
        if d in a :
            return 0
        a . append ( d )
        n = n // 10
    return 1
def calculate ( L , R ) :
    answer = 0
    for i in range ( L , R + 1 ) :
        answer = answer + repeated_digit ( i )
    return answer
L = 1
R = 100
print ( calculate ( L , R ) )

Accumulator variables: a
Iterator variables: i
Python program:
def countMinSwaps ( st ) :
    min_swaps = 0
    odd_0 , even_0 = 0 , 0
    odd_1 , even_1 = 0 , 0
    n = len ( st )
    for i in range ( 0 , n ) :
        if i % 2 == 0 :
            if st [ i ] == "1" :
                even_1 += 1
            else :
                even_0 += 1
        else :
            if st [ i ] == "1" :
                odd_1 += 1
            else :
                odd_0 += 1
    cnt_swaps_1 = min ( even_0 , odd_1 )
    cnt_swaps_2 = min ( even_1 , odd_0 )
    return min ( cnt_swaps_1 , cnt_swaps_2 )
if __name__ == " _ _ main _ _ " :
    st = "000111"
    print ( countMinSwaps ( st ) )

Index/key variables: i
Accumulator variables: even_0, even_1, odd_0, odd_1
Iterator variables: i
Python program:
MAX = 1000
Prefix = [ 0 ]
def repeated_digit ( n ) :
    a = [ ]
    while n != 0 :
        d = n % 10
        if d in a :
            return 0
        a . append ( d )
        n = n // 10
    return 1
def pre_calculation ( MAX ) :
    global Prefix
    Prefix . append ( repeated_digit ( 1 ) )
    for i in range ( 2 , MAX + 1 ) :
        Prefix . append ( repeated_digit ( i ) + Prefix [ i - 1 ] )
def calculate ( L , R ) :
    return Prefix [ R ] - Prefix [ L - 1 ]
pre_calculation ( MAX )
L = 1
R = 100
print ( calculate ( L , R ) )

Index/key variables: R
Accumulator variables: Prefix, a
Iterator variables: i
Python program:
def initializeDiffArray ( A ) :
    n = len ( A )
    D = [ 0 for i in range ( 0 , n + 1 ) ]
    D [ 0 ] = A [ 0 ] ; D [ n ] = 0
    for i in range ( 1 , n ) :
        D [ i ] = A [ i ] - A [ i - 1 ]
    return D
def update ( D , l , r , x ) :
    D [ l ] += x
    D [ r + 1 ] -= x
def printArray ( A , D ) :
    for i in range ( 0 , len ( A ) ) :
        if ( i == 0 ) :
            A [ i ] = D [ i ]
        else :
            A [ i ] = D [ i ] + A [ i - 1 ]
        print ( A [ i ] , end = " ▁ " )
    print ( " " )
A = [ 10 , 5 , 20 , 40 ]
D = initializeDiffArray ( A )
update ( D , 0 , 1 , 10 )
printArray ( A , D )
update ( D , 1 , 3 , 20 )
update ( D , 2 , 2 , 30 )
printArray ( A , D )

Index/key variables: i, l, n
Iterator variables: i
Python program:
def solve ( arr , n ) :
    ans = [ [ 0 for i in range ( n ) ] for j in range ( n ) ]
    for i in range ( n ) :
        for j in range ( n ) :
            ans [ i ] [ j ] = arr [ j ] [ ( i + j ) % n ]
    return ans
def show ( arr , n ) :
    res = solve ( arr , n )
    for i in range ( n ) :
        for j in range ( n ) :
            print ( res [ i ] [ j ] , end = " ▁ " )
        print ( )
def makeArray ( n ) :
    arr = [ [ 0 for i in range ( n ) ] for j in range ( n ) ]
    c = 1
    for i in range ( n ) :
        for j in range ( n ) :
            arr [ i ] [ j ] = c
            c += 1
    return arr
n = 5
arr = makeArray ( n )
show ( arr , n )

Index/key variables: i, j
Accumulator variables: c
Iterator variables: i, j
Python program:
def maxSubArraySum ( a , size ) :
    max_so_far = a [ 0 ]
    max_ending_here = 0
    for i in range ( 0 , size ) :
        max_ending_here = max_ending_here + a [ i ]
        if max_ending_here < 0 :
            max_ending_here = 0
        elif ( max_so_far < max_ending_here ) :
            max_so_far = max_ending_here
    return max_so_far

Index/key variables: i
Iterator variables: i
Python program:
def findMinRooms ( slots , n , m ) :
    counts = [ 0 ] * m ;
    for i in range ( n ) :
        for j in range ( m ) :
            if ( slots [ i ] [ j ] == '1' ) :
                counts [ j ] += 1 ;
    return max ( counts ) ;
n = 3 ;
m = 7 ;
slots = [ "0101011" , "0011001" , "0110111" ] ;
print ( findMinRooms ( slots , n , m ) ) ;

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