dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def TrinomialValue ( dp , n , k ) :
    if k < 0 :
        k = - k
    if dp [ n ] [ k ] != 0 :
        return dp [ n ] [ k ]
    if n == 0 and k == 0 :
        return 1
    if k < - n or k > n :
        return 0
    return ( TrinomialValue ( dp , n - 1 , k - 1 ) + TrinomialValue ( dp , n - 1 , k ) + TrinomialValue ( dp , n - 1 , k + 1 ) )
def printTrinomial ( n ) :
    dp = [ [ 0 ] * 10 ] * 10
    for i in range ( n ) :
        for j in range ( - i , 1 ) :
            print ( TrinomialValue ( dp , i , j ) , end = " ▁ " )
        for j in range ( 1 , i + 1 ) :
            print ( TrinomialValue ( dp , i , j ) , end = " ▁ " )
        print ( " " , end = ' ' )
n = 4
printTrinomial ( n )

Index/key variables: k, n
Iterator variables: i, j
Python program:
def sumOfLargePrimeFactor ( n ) :
    prime = [ 0 ] * ( n + 1 )
    sum = 0
    max = int ( n / 2 )
    for p in range ( 2 , max + 1 ) :
        if prime [ p ] == 0 :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = p
    for p in range ( 2 , n + 1 ) :
        if prime [ p ] :
            sum += prime [ p ]
        else :
            sum += p
    return sum
n = 12
print ( " Sum ▁ = " , sumOfLargePrimeFactor ( n ) )

Index/key variables: i, p
Accumulator variables: sum
Iterator variables: i, p
Python program:
def isPowerOf2 ( sttr ) :
    len_str = len ( sttr ) ;
    sttr = list ( sttr ) ;
    num = 0 ;
    if ( len_str == 1 and sttr [ len_str - 1 ] == '1' ) :
        return 0 ;
    while ( len_str != 1 or sttr [ len_str - 1 ] != '1' ) :
        if ( ( ord ( sttr [ len_str - 1 ] ) - ord ( '0' ) ) % 2 == 1 ) :
            return 0 ;
        j = 0 ;
        for i in range ( len_str ) :
            num = num * 10 + ( ord ( sttr [ i ] ) - ord ( '0' ) ) ;
            if ( num < 2 ) :
                if ( i != 0 ) :
                    sttr [ j ] = '0' ;
                    j += 1 ;
                continue ;
            sttr [ j ] = chr ( ( num // 2 ) + ord ( '0' ) ) ;
            j += 1 ;
            num = ( num ) - ( num // 2 ) * 2 ;
        len_str = j ;
    return 1 ;
str1 = "124684622466842024680246842024662202000002" ;
str2 = "1" ;
str3 = "128" ;
print ( " " , isPowerOf2 ( str1 ) ,   " " , isPowerOf2 ( str2 ) ,   " " , isPowerOf2 ( str3 ) ) ;

Index/key variables: i, j
Iterator variables: i
Python program:
def counDivisors ( X ) :
    count = 0
    for i in range ( 1 , X + 1 ) :
        if ( X % i == 0 ) :
            count += 1
    return count
def countDivisorsMult ( arr , n ) :
    mul = 1
    for i in range ( n ) :
        mul *= arr [ i ]
    return counDivisors ( mul )
arr = [ 2 , 4 , 6 ]
n = len ( arr )
print ( countDivisorsMult ( arr , n ) )

Index/key variables: i
Accumulator variables: count, mul
Iterator variables: i
Python program:
from collections import defaultdict
def SieveOfEratosthenes ( largest , prime ) :
    isPrime = [ True ] * ( largest + 1 )
    p = 2
    while p * p <= largest :
        if ( isPrime [ p ] == True ) :
            for i in range ( p * 2 , largest + 1 , p ) :
                isPrime [ i ] = False
        p += 1
    for p in range ( 2 , largest + 1 ) :
        if ( isPrime [ p ] ) :
            prime . append ( p )
def countDivisorsMult ( arr , n ) :
    largest = max ( arr )
    prime = [ ]
    SieveOfEratosthenes ( largest , prime )
    mp = defaultdict ( int )
    for i in range ( n ) :
        for j in range ( len ( prime ) ) :
            while ( arr [ i ] > 1 and arr [ i ] % prime [ j ] == 0 ) :
                arr [ i ] //= prime [ j ]
                mp [ prime [ j ] ] += 1
        if ( arr [ i ] != 1 ) :
            mp [ arr [ i ] ] += 1
    res = 1
    for it in mp . values ( ) :
        res *= ( it + 1 )
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 6 ]
    n = len ( arr )
    print ( countDivisorsMult ( arr , n ) )

Index/key variables: i, j, p
Accumulator variables: prime, res
Iterator variables: i, it, j, p
Python program:
from math import sqrt
def findPrimeNos ( L , R , M ) :
    for i in range ( L , R + 1 ) :
        M [ i ] = M . get ( i , 0 ) + 1
    if ( 1 in M ) :
        M . pop ( 1 )
    for i in range ( 2 , int ( sqrt ( R ) ) + 1 , 1 ) :
        multiple = 2
        while ( ( i * multiple ) <= R ) :
            if ( ( i * multiple ) in M ) :
                M . pop ( i * multiple )
            multiple += 1
def getPrimePairs ( L , R , K ) :
    M = { }
    findPrimeNos ( L , R , M )
    for key , values in M . items ( ) :
        if ( ( key + K ) in M ) :
            print ( " ( " , key , " , " , key + K , " ) " , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    L = 1
    R = 19
    K = 6
    getPrimePairs ( L , R , K )

Index/key variables: i
Accumulator variables: multiple
Iterator variables: i, key, values
Python program:
def freqPairs ( arr , n ) :
    max = arr [ 0 ]
    for i in range ( len ( arr ) ) :
        if arr [ i ] > max :
            max = arr [ i ]
    freq = [ 0 for i in range ( max + 1 ) ]
    count = 0
    for i in range ( n ) :
        freq [ arr [ i ] ] += 1
    for i in range ( n ) :
        for j in range ( 2 * arr [ i ] , max + 1 , arr [ i ] ) :
            if ( freq [ j ] >= 1 ) :
                count += freq [ j ]
        if ( freq [ arr [ i ] ] > 1 ) :
            count += freq [ arr [ i ] ] - 1
            freq [ arr [ i ] ] -= 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 4 , 2 , 6 ]
    n = len ( arr )
    print ( freqPairs ( arr , n ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def printNthElement ( n ) :
    arr = [ 0 ] * ( n + 1 ) ;
    arr [ 1 ] = 3
    arr [ 2 ] = 5
    for i in range ( 3 , n + 1 ) :
        if ( i % 2 != 0 ) :
            arr [ i ] = arr [ i // 2 ] * 10 + 3
        else :
            arr [ i ] = arr [ ( i // 2 ) - 1 ] * 10 + 5
    return arr [ n ]
n = 6
print ( printNthElement ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def series ( A , X , n ) :
    term = pow ( A , n )
    print ( term , end = " ▁ " )
    for i in range ( 1 , n + 1 ) :
        term = int ( term * X * ( n - i + 1 ) / ( i * A ) )
        print ( term , end = " ▁ " )
A = 3 ; X = 4 ; n = 5
series ( A , X , n )

Iterator variables: i
Python program:
def counLastDigitK ( low , high , k ) :
    count = 0
    for i in range ( low , high + 1 ) :
        if ( i % 10 == k ) :
            count += 1
    return count
low = 3
high = 35
k = 3
print ( counLastDigitK ( low , high , k ) )

Accumulator variables: count
Iterator variables: i
Python program:
import math
def printTaxicab2 ( N ) :
    i , count = 1 , 0
    while ( count < N ) :
        int_count = 0
        for j in range ( 1 , math . ceil ( pow ( i , 1.0 / 3 ) ) + 1 ) :
            for k in range ( j + 1 , math . ceil ( pow ( i , 1.0 / 3 ) ) + 1 ) :
                if ( j * j * j + k * k * k == i ) :
                    int_count += 1
        if ( int_count == 2 ) :
            count += 1
            print ( count , " ▁ " , i )
        i += 1
N = 5
printTaxicab2 ( N )

Accumulator variables: count, i, int_count
Iterator variables: j, k
Python program:
def isPrime ( n ) :
    if n <= 1 :
        return False
    for i in range ( 2 , n ) :
        if n % i == 0 :
            return False
    return True
def findPrime ( n ) :
    num = n + 1
    while ( num ) :
        if isPrime ( num ) :
            return num
        num += 1
    return 0
def minNumber ( arr ) :
    s = 0
    for i in range ( 0 , len ( arr ) ) :
        s += arr [ i ]
    if isPrime ( s ) :
        return 0
    num = findPrime ( s )
    return num - s
arr = [ 2 , 4 , 6 , 8 , 12 ]
print ( minNumber ( arr ) )

Index/key variables: i
Accumulator variables: num, s
Iterator variables: i
Python program:
def fact ( n ) :
    if ( n == 0 ) :
        return 1
    return n * fact ( n - 1 )
def div ( x ) :
    ans = 0 ;
    for i in range ( 1 , x + 1 ) :
        if ( x % i == 0 ) :
            ans += i
    return ans
def sumFactDiv ( n ) :
    return div ( fact ( n ) )
n = 4
print ( sumFactDiv ( n ) )

Accumulator variables: ans
Iterator variables: i
Python program:
allPrimes = [ ] ;
def sieve ( n ) :
    prime = [ True ] * ( n + 1 ) ;
    p = 2 ;
    while ( p * p <= n ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = False ;
        p += 1 ;
    for p in range ( 2 , n + 1 ) :
        if ( prime [ p ] ) :
            allPrimes . append ( p ) ;
def factorialDivisors ( n ) :
    result = 1 ;
    for i in range ( len ( allPrimes ) ) :
        p = allPrimes [ i ] ;
        exp = 0 ;
        while ( p <= n ) :
            exp = exp + int ( n / p ) ;
            p = p * allPrimes [ i ] ;
        result = int ( result * ( pow ( allPrimes [ i ] , exp + 1 ) - 1 ) / ( allPrimes [ i ] - 1 ) ) ;
    return result ;
print ( factorialDivisors ( 4 ) ) ;

Index/key variables: i, p
Accumulator variables: allPrimes
Iterator variables: i, p
Python program:
def checkPandigital ( b , n ) :
    if ( len ( n ) < b ) :
        return 0 ;
    hash = [ 0 ] * b ;
    for i in range ( len ( n ) ) :
        if ( n [ i ] >= '0' and n [ i ] <= '9' ) :
            hash [ ord ( n [ i ] ) - ord ( '0' ) ] = 1 ;
        elif ( ord ( n [ i ] ) - ord ( ' A ' ) <= b - 11 ) :
            hash [ ord ( n [ i ] ) - ord ( ' A ' ) + 10 ] = 1 ;
    for i in range ( b ) :
        if ( hash [ i ] == 0 ) :
            return 0 ;
    return 1 ;
b = 13 ;
n = "1298450376ABC " ;
if ( checkPandigital ( b , n ) ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;

Index/key variables: i
Iterator variables: i
Python program:
MAX = 10000 ;
prodDig = [ 0 ] * MAX ;
def getDigitProduct ( x ) :
    if ( x < 10 ) :
        return x ;
    if ( prodDig [ x ] != 0 ) :
        return prodDig [ x ] ;
    prod = ( int ( x % 10 ) * getDigitProduct ( int ( x / 10 ) ) ) ;
    prodDig [ x ] = prod ;
    return prod ;
def findSeed ( n ) :
    res = [ ] ;
    for i in range ( 1 , int ( n / 2 + 2 ) ) :
        if ( i * getDigitProduct ( i ) == n ) :
            res . append ( i ) ;
    if ( len ( res ) == 0 ) :
        print ( " NO ▁ seed ▁ exists " ) ;
        return ;
    for i in range ( len ( res ) ) :
        print ( res [ i ] , end = " ▁ " ) ;
n = 138 ;
findSeed ( n ) ;

Index/key variables: i, x
Accumulator variables: res
Iterator variables: i
Python program:
from math import sqrt
def maxPrimefactorNum ( N ) :
    arr = [ 0 for i in range ( N + 5 ) ]
    for i in range ( 2 , int ( sqrt ( N ) ) + 1 , 1 ) :
        if ( arr [ i ] == 0 ) :
            for j in range ( 2 * i , N + 1 , i ) :
                arr [ j ] += 1
        arr [ i ] = 1
    maxval = 0
    maxint = 1
    for i in range ( 1 , N + 1 , 1 ) :
        if ( arr [ i ] > maxval ) :
            maxval = arr [ i ]
            maxint = i
    return maxint
if __name__ == ' _ _ main _ _ ' :
    N = 40
    print ( maxPrimefactorNum ( N ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def SubArraySum ( arr , n ) :
    result = 0
    for i in range ( 0 , n ) :
        result += ( arr [ i ] * ( i + 1 ) * ( n - i ) )
    return result
arr = [ 1 , 2 , 3 ]
n = len ( arr )
print ( " Sum ▁ of ▁ SubArray ▁ : ▁ " , SubArraySum ( arr , n ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def highestPowerof2 ( n ) :
    res = 0 ;
    for i in range ( n , 0 , - 1 ) :
        if ( ( i & ( i - 1 ) ) == 0 ) :
            res = i ;
            break ;
    return res ;
n = 10 ;
print ( highestPowerof2 ( n ) ) ;

Iterator variables: i
Python program:
def findPairs ( n ) :
    cubeRoot = pow ( n , 1.0 / 3.0 ) ;
    s = { }
    for x in range ( int ( cubeRoot ) ) :
        for y in range ( x + 1 , int ( cubeRoot ) + 1 ) :
            sum = x * x * x + y * y * y ;
            if ( sum != n ) :
                continue ;
            if sum in s . keys ( ) :
                print ( " ( " + str ( s [ sum ] [ 0 ] ) + " , ▁ " + str ( s [ sum ] [ 1 ] ) + " ) ▁ and ▁ ( " + str ( x ) + " , ▁ " + str ( y ) + " ) " +   " " )
            else :
                s [ sum ] = [ x , y ]
if __name__ == " _ _ main _ _ " :
    n = 13832
    findPairs ( n )

Index/key variables: sum
Iterator variables: x, y
Python program:
import math
def printDivisors ( n ) :
    list = [ ]
    for i in range ( 1 , int ( math . sqrt ( n ) + 1 ) ) :
        if ( n % i == 0 ) :
            if ( n / i == i ) :
                print ( i , end = " ▁ " )
            else :
                print ( i , end = " ▁ " )
                list . append ( int ( n / i ) )
    for i in list [ : : - 1 ] :
        print ( i , end = " ▁ " )
print ( " The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ " )
printDivisors ( 100 )

Accumulator variables: list
Iterator variables: i
Python program:
from math import *
def printDivisors ( n ) :
    i = 1
    while ( i * i < n ) :
        if ( n % i == 0 ) :
            print ( i , end = " ▁ " )
        i += 1
    for i in range ( int ( sqrt ( n ) ) , 0 , - 1 ) :
        if ( n % i == 0 ) :
            print ( n // i , end = " ▁ " )
print ( " The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ " )
printDivisors ( 100 )

Iterator variables: i
Python program:
def SieveOfAtkin ( limit ) :
    if ( limit > 2 ) :
        print ( 2 , end = " ▁ " )
    if ( limit > 3 ) :
        print ( 3 , end = " ▁ " )
    sieve = [ False ] * limit
    for i in range ( 0 , limit ) :
        sieve [ i ] = False
    x = 1
    while ( x * x < limit ) :
        y = 1
        while ( y * y < limit ) :
            n = ( 4 * x * x ) + ( y * y )
            if ( n <= limit and ( n % 12 == 1 or n % 12 == 5 ) ) :
                sieve [ n ] ^= True
            n = ( 3 * x * x ) + ( y * y )
            if ( n <= limit and n % 12 == 7 ) :
                sieve [ n ] ^= True
            n = ( 3 * x * x ) - ( y * y )
            if ( x > y and n <= limit and n % 12 == 11 ) :
                sieve [ n ] ^= True
            y += 1
        x += 1
    r = 5
    while ( r * r < limit ) :
        if ( sieve [ r ] ) :
            for i in range ( r * r , limit , r * r ) :
                sieve [ i ] = False
    for a in range ( 5 , limit ) :
        if ( sieve [ a ] ) :
            print ( a , end = " ▁ " )
limit = 20
SieveOfAtkin ( limit )

Index/key variables: a, i, n, r
Accumulator variables: x, y
Iterator variables: a, i
Python program:
import math
def isLucky ( n ) :
    ar = [ 0 ] * 10
    while ( n > 0 ) :
        digit = math . floor ( n % 10 )
        if ( ar [ digit ] ) :
            return 0
        ar [ digit ] = 1
        n = n / 10
    return 1
arr = [ 1291 , 897 , 4566 , 1232 , 80 , 700 ]
n = len ( arr )
for i in range ( 0 , n ) :
    k = arr [ i ]
    if ( isLucky ( k ) ) :
        print ( k , " ▁ is ▁ Lucky ▁ " )
    else :
        print ( k , " ▁ is ▁ not ▁ Lucky ▁ " )

Index/key variables: digit, i
Iterator variables: i
Python program:
def RecursiveFunction ( ref , bit ) :
    if ( len ( ref ) == 0 or bit < 0 ) :
        return 0 ;
    curr_on = [ ]
    curr_off = [ ]
    for i in range ( len ( ref ) ) :
        if ( ( ( ref [ i ] >> bit ) & 1 ) == 0 ) :
            curr_off . append ( ref [ i ] )
        else :
            curr_on . append ( ref [ i ] )
    if ( len ( curr_off ) == 0 ) :
        return RecursiveFunction ( curr_on , bit - 1 )
    if ( len ( curr_on ) == 0 ) :
        return RecursiveFunction ( curr_off , bit - 1 )
    return ( min ( RecursiveFunction ( curr_off , bit - 1 ) , RecursiveFunction ( curr_on , bit - 1 ) ) + ( 1 << bit ) )
def PrintMinimum ( a , n ) :
    v = [ ]
    for i in range ( n ) :
        v . append ( a [ i ] )
    print ( RecursiveFunction ( v , 30 ) )
arr = [ 3 , 2 , 1 ]
size = len ( arr )
PrintMinimum ( arr , size )

Index/key variables: i
Accumulator variables: curr_off, curr_on, v
Iterator variables: i
Python program:
def cntElements ( arr , n ) :
    cnt = 0
    for i in range ( n - 2 ) :
        if ( arr [ i ] == ( arr [ i + 1 ] ^ arr [ i + 2 ] ) ) :
            cnt += 1
    return cnt
arr = [ 4 , 2 , 1 , 3 , 7 , 8 ]
n = len ( arr )
print ( cntElements ( arr , n ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def xor_triplet ( arr , n ) :
    ans = 0 ;
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            for k in range ( j , n ) :
                xor1 = 0 ; xor2 = 0 ;
                for x in range ( i , j ) :
                    xor1 ^= arr [ x ] ;
                for x in range ( j , k + 1 ) :
                    xor2 ^= arr [ x ] ;
                if ( xor1 == xor2 ) :
                    ans += 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    print ( xor_triplet ( arr , n ) ) ;

Index/key variables: x
Accumulator variables: ans, xor1, xor2
Iterator variables: i, j, k, x
Python program:
N = 100005
Ideal_pair = 0
al = [ [ ] for i in range ( 100005 ) ]
bit = [ 0 for i in range ( N ) ]
root_node = [ 0 for i in range ( N ) ]
def bit_q ( i , j ) :
    sum = 0
    while ( j > 0 ) :
        sum += bit [ j ]
        j -= ( j & ( j * - 1 ) )
    i -= 1
    while ( i > 0 ) :
        sum -= bit [ i ]
        i -= ( i & ( i * - 1 ) )
    return sum
def bit_up ( i , diff ) :
    while ( i <= n ) :
        bit [ i ] += diff
        i += i & - i
def dfs ( node , x ) :
    Ideal_pair = x
    Ideal_pair += bit_q ( max ( 1 , node - k ) , min ( n , node + k ) )
    bit_up ( node , 1 )
    for i in range ( len ( al [ node ] ) ) :
        Ideal_pair = dfs ( al [ node ] [ i ] , Ideal_pair )
    bit_up ( node , - 1 )
    return Ideal_pair
def initialise ( ) :
    Ideal_pair = 0 ;
    for i in range ( n + 1 ) :
        root_node [ i ] = True
        bit [ i ] = 0
def Add_Edge ( x , y ) :
    al [ x ] . append ( y )
    root_node [ y ] = False
def Idealpairs ( ) :
    r = - 1
    for i in range ( 1 , n + 1 , 1 ) :
        if ( root_node [ i ] ) :
            r = i
            break
    Ideal_pair = dfs ( r , 0 )
    return Ideal_pair
if __name__ == ' _ _ main _ _ ' :
    n = 6
    k = 3
    initialise ( )
    Add_Edge ( 1 , 2 )
    Add_Edge ( 1 , 3 )
    Add_Edge ( 3 , 4 )
    Add_Edge ( 3 , 5 )
    Add_Edge ( 3 , 6 )
    print ( Idealpairs ( ) )

Index/key variables: i, j, node, x, y
Accumulator variables: sum
Iterator variables: i
Python program:
def setBitNumber ( n ) :
    if ( n == 0 ) :
        return 0 ;
    msb = 0 ;
    n = int ( n / 2 ) ;
    while ( n > 0 ) :
        n = int ( n / 2 ) ;
        msb += 1 ;
    return ( 1 << msb ) ;
n = 0 ;
print ( setBitNumber ( n ) ) ;

Accumulator variables: msb
Python program:
def countTrailingZero ( x ) :
    count = 0
    while ( ( x & 1 ) == 0 ) :
        x = x >> 1
        count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    print ( countTrailingZero ( 11 ) )

Accumulator variables: count
Python program:
def countNumbers ( L , R , K ) :
    list = [ ]
    for i in range ( L , R + 1 ) :
        if ( isPalindrome ( i ) ) :
            list . append ( i )
    count = 0
    for i in range ( len ( list ) ) :
        right_index = search ( list , list [ i ] + K - 1 )
        if ( right_index != - 1 ) :
            count = max ( count , right_index - i + 1 )
    return count
def search ( list , num ) :
    low , high = 0 , len ( list ) - 1
    ans = - 1
    while ( low <= high ) :
        mid = low + ( high - low ) // 2
        if ( list [ mid ] <= num ) :
            ans = mid
            low = mid + 1
        else :
            high = mid - 1
    return ans
def isPalindrome ( n ) :
    rev = 0
    temp = n
    while ( n > 0 ) :
        rev = rev * 10 + n % 10
        n //= 10
    return rev == temp
if __name__ == ' _ _ main _ _ ' :
    L , R = 98 , 112
    K = 13
    print ( countNumbers ( L , R , K ) )

Index/key variables: i, mid
Accumulator variables: list, n
Iterator variables: i
Python program:
def findMaximumSum ( a , n ) :
    prev_smaller = findPrevious ( a , n )
    next_smaller = findNext ( a , n )
    max_value = 0
    for i in range ( n ) :
        max_value = max ( max_value , a [ i ] * ( next_smaller [ i ] - prev_smaller [ i ] - 1 ) )
    return max_value
def findPrevious ( a , n ) :
    ps = [ 0 ] * n
    ps [ 0 ] = - 1
    stack = [ ]
    stack . append ( 0 )
    for i in range ( 1 , n ) :
        while len ( stack ) > 0 and a [ stack [ - 1 ] ] >= a [ i ] :
            stack . pop ( )
        ps [ i ] = stack [ - 1 ] if len ( stack ) > 0 else - 1
        stack . append ( i )
    return ps
def findNext ( a , n ) :
    ns = [ 0 ] * n
    ns [ n - 1 ] = n
    stack = [ ]
    stack . append ( n - 1 )
    for i in range ( n - 2 , - 1 , - 1 ) :
        while ( len ( stack ) > 0 and a [ stack [ - 1 ] ] >= a [ i ] ) :
            stack . pop ( )
        ns [ i ] = stack [ - 1 ] if len ( stack ) > 0 else n
        stack . append ( i )
    return ns
n = 3
a = [ 80 , 48 , 82 ]
print ( findMaximumSum ( a , n ) )

Index/key variables: i
Accumulator variables: stack
Iterator variables: i
Python program:
MAX = 256
def compare ( arr1 , arr2 ) :
    global MAX
    for i in range ( MAX ) :
        if ( arr1 [ i ] != arr2 [ i ] ) :
            return False
    return True
def search ( pat , txt ) :
    M = len ( pat )
    N = len ( txt )
    countP = [ 0 for i in range ( MAX ) ]
    countTW = [ 0 for i in range ( MAX ) ]
    for i in range ( M ) :
        countP [ ord ( pat [ i ] ) ] += 1
        countTW [ ord ( txt [ i ] ) ] += 1
    for i in range ( M , N ) :
        if ( compare ( countP , countTW ) ) :
            return True
        countTW [ ord ( txt [ i ] ) ] += 1
        countTW [ ord ( txt [ i - M ] ) ] -= 1
    if ( compare ( countP , countTW ) ) :
        return True
        return False
txt = " BACDGABCDA "
pat = " ABCD "
if ( search ( pat , txt ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def insertionSort ( arr ) :
    for i in range ( 1 , len ( arr ) ) :
        key = arr [ i ]
        j = i - 1
        while j >= 0 and key < arr [ j ] :
            arr [ j + 1 ] = arr [ j ]
            j -= 1
        arr [ j + 1 ] = key
arr = [ 12 , 11 , 13 , 5 , 6 ]
insertionSort ( arr )
for i in range ( len ( arr ) ) :
    print ( " % ▁ d " % arr [ i ] )

Index/key variables: i, j
Iterator variables: i
Python program:
def validPermutations ( str ) :
    m = { }
    count = len ( str )
    ans = 0
    for i in range ( len ( str ) ) :
        if ( str [ i ] in m ) :
            m [ str [ i ] ] += 1
        else :
            m [ str [ i ] ] = 1
    for i in range ( len ( str ) ) :
        ans += count - m [ str [ i ] ]
        m [ str [ i ] ] -= 1
        count -= 1
    return ans + 1
if __name__ == ' _ _ main _ _ ' :
    str = " sstt "
    print ( validPermutations ( str ) )

Index/key variables: i
Accumulator variables: ans, count
Iterator variables: i
Python program:
def replaceConsonants ( string ) :
    res = " " ;
    i = 0 ; count = 0 ;
    while ( i < len ( string ) ) :
        if ( string [ i ] != ' a ' and string [ i ] != ' e ' and string [ i ] != ' i ' and string [ i ] != ' o ' and string [ i ] != ' u ' ) :
            i += 1 ;
            count += 1 ;
        else :
            if ( count > 0 ) :
                res += str ( count ) ;
            res += string [ i ] ;
            i += 1
            count = 0 ;
    if ( count > 0 ) :
        res += str ( count ) ;
    return res ;
if __name__ == " _ _ main _ _ " :
    string = " abcdeiop " ;
    print ( replaceConsonants ( string ) ) ;

Index/key variables: i
Accumulator variables: count, res
Python program:
def isVowel ( c ) :
    return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' )
def encryptString ( s , n , k ) :
    countVowels = 0
    countConsonants = 0
    ans = " "
    for l in range ( n - k + 1 ) :
        countVowels = 0
        countConsonants = 0
        for r in range ( l , l + k ) :
            if ( isVowel ( s [ r ] ) == True ) :
                countVowels += 1
            else :
                countConsonants += 1
        ans += ( str ) ( countVowels * countConsonants )
    return ans
if __name__ == ' _ _ main _ _ ' :
    s = " hello "
    n = len ( s )
    k = 2
    print ( encryptString ( s , n , k ) )

Index/key variables: r
Accumulator variables: ans, countConsonants, countVowels
Iterator variables: l, r