dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
arr = [ ' a ' , ' b ' , ' c ' ]
def findString ( n , k , s1 , s2 ) :
    s3 = s2
    s3 = list ( s3 )
    d = 0
    for i in range ( len ( s1 ) ) :
        if ( s1 [ i ] != s2 [ i ] ) :
            d += 1
    if ( ( d + 1 ) // 2 > k ) :
        print ( " - 1" )
        return
    else :
        if ( k <= d ) :
            X = d - k
            T = 2 * k - d
            for i in range ( len ( s3 ) ) :
                if ( s1 [ i ] != s2 [ i ] ) :
                    if ( T > 0 ) :
                        for j in range ( 3 ) :
                            if ( arr [ j ] != s1 [ i ] and arr [ j ] != s2 [ i ] ) :
                                s3 [ i ] = arr [ j ]
                                T -= 1
                                break
                    elif ( X > 0 ) :
                        s3 [ i ] = s1 [ i ]
                        X -= 1
            print ( " " . join ( s3 ) )
        else :
            for i in range ( len ( s1 ) ) :
                if ( s1 [ i ] != s3 [ i ] ) :
                    for j in range ( 3 ) :
                        if ( arr [ j ] != s1 [ i ] and arr [ j ] != s3 [ i ] ) :
                            s3 [ i ] = arr [ j ]
                            k -= 1
                            break
            for i in range ( len ( s1 ) ) :
                if ( s1 [ i ] == s3 [ i ] and k ) :
                    for j in range ( 3 ) :
                        if ( arr [ j ] != s1 [ i ] and arr [ j ] != s3 [ i ] ) :
                            s3 [ i ] = arr [ j ]
                            k -= 1
                            break
            print ( " " . join ( s3 ) )
if __name__ == " _ _ main _ _ " :
    N = 4
    k = 2
    S1 = " zzyy "
    S2 = " zxxy "
    findString ( N , k , S1 , S2 )

Index/key variables: i, j
Accumulator variables: T, X, d, k
Iterator variables: i, j
Python program:
import math ;
def findSolutions ( N ) :
    count = 0 ;
    for i in range ( 1 , int ( math . sqrt ( N ) ) + 1 ) :
        if ( N % i == 0 ) :
            if ( ( i + N // i ) % 2 == 0 ) :
                count += 1 ;
    print ( 4 * count ) ;
N = 80 ;
findSolutions ( N ) ;

Accumulator variables: count
Iterator variables: i
Python program:
def countTriplets ( color ) :
    result = 0 ; Blue_Count = 0 ;
    Red_Count = 0 ;
    for c in color :
        if ( c == ' B ' ) :
            Blue_Count += 1 ;
    for c in color :
        if ( c == ' B ' ) :
            Blue_Count -= 1 ;
        if ( c == ' R ' ) :
            Red_Count += 1 ;
        if ( c == ' G ' ) :
            result += Red_Count * Blue_Count ;
    return result ;
if __name__ == " _ _ main _ _ " :
    color = " RRGGBBRGGBB " ;
    print ( countTriplets ( color ) ) ;

Accumulator variables: Blue_Count, Red_Count, result
Iterator variables: c
Python program:
def naive_find_x ( N ) :
    c = 0
    for i in range ( 1 , N ) :
        c += i * i * i
        if c >= N :
            break
    return i
if __name__ == " _ _ main _ _ " :
    N = 100
    print ( naive_find_x ( N ) )

Accumulator variables: c
Iterator variables: i
Python program:
def minpoint ( arr , n , k ) :
    min_point = 0
    for i in range ( 1 , k - 1 ) :
        if ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) :
            min_point += 1
    final_point = min_point
    for i in range ( k , n ) :
        if ( arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) + 1 ] and arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) - 1 ] ) :
            min_point -= 1
        if ( arr [ i - 1 ] < arr [ i ] and arr [ i - 1 ] < arr [ i - 2 ] ) :
            min_point += 1
        if ( min_point > final_point ) :
            final_point = min_point
    print ( final_point )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 1 , 4 , 2 , 3 , 4 , 1 , 2 ]
    n = len ( arr )
    k = 4
    minpoint ( arr , n , k )

Index/key variables: i
Accumulator variables: min_point
Iterator variables: i
Python program:
def CountStrings ( s ) :
    size = len ( s )
    count = [ 0 ] * 26
    visited = [ False ] * 26
    for i in range ( size ) :
        for j in range ( len ( s [ i ] ) ) :
            if visited [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] == False :
                count [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] += 1
            visited [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] = True
        for j in range ( len ( s [ i ] ) ) :
            visited [ ord ( s [ i ] [ j ] ) - ord ( ' a ' ) ] = False
    for i in range ( 26 ) :
        print ( count [ i ] , end = ' ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    s = [ " i " , " will " , " practice " , " everyday " ]
    CountStrings ( s )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findSubArray ( a , n , k ) :
    pref = [ 0 for i in range ( n ) ]
    pref [ 0 ] = 0
    for i in range ( 1 , n - 1 , 1 ) :
        pref [ i ] = pref [ i - 1 ]
        if ( a [ i ] > a [ i - 1 ] and a [ i ] > a [ i + 1 ] ) :
            pref [ i ] += 1
    peak = 0
    left = 0
    for i in range ( 0 , n - k + 1 , 1 ) :
        if ( pref [ i + k - 2 ] - pref [ i ] > peak ) :
            peak = pref [ i + k - 2 ] - pref [ i ]
            left = i
    print ( " Left ▁ = " , left + 1 )
    print ( " Right ▁ = " , left + k )
    print ( " Peak ▁ = " , peak )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 3 , 2 , 1 ]
    n = len ( arr )
    k = 3
    findSubArray ( arr , n , k )

Index/key variables: i
Iterator variables: i
Python program:
def distanceSort ( arr , K , n ) :
    vd = [ [ ] for i in range ( n ) ]
    for i in range ( n ) :
        if ( arr [ i ] == K ) :
            pos = i
            break
    i = pos - 1
    j = pos + 1
    vd [ 0 ] . append ( arr [ pos ] )
    while ( i >= 0 ) :
        vd [ pos - i ] . append ( arr [ i ] )
        i -= 1
    while ( j < n ) :
        vd [ j - pos ] . append ( arr [ j ] )
        j += 1
    for i in range ( max ( pos , n - pos - 1 ) + 1 ) :
        vd [ i ] . sort ( reverse = False )
        for element in vd [ i ] :
            print ( element , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 14 , 1101 , 10 , 35 , 0 ]
    K = 35
    n = len ( arr )
    distanceSort ( arr , K , n )

Index/key variables: i, j, pos
Iterator variables: element, i
Python program:
def countTriplets ( a , n , x ) :
    answer = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            for k in range ( j + 1 , n ) :
                temp = [ ]
                temp . append ( a [ i ] )
                temp . append ( a [ j ] )
                temp . append ( a [ k ] )
                temp . sort ( )
                if ( temp [ 0 ] < temp [ 1 ] and temp [ 1 ] < temp [ 2 ] and temp [ 0 ] * temp [ 1 ] * temp [ 2 ] <= x ) :
                    answer += 1
    return answer
A = [ 3 , 2 , 5 , 7 ]
N = len ( A )
X = 42
print ( countTriplets ( A , N , X ) )

Index/key variables: i, j, k
Accumulator variables: answer, temp
Iterator variables: i, j, k
Python program:
def findMaxMatrixSize ( arr , K ) :
    n = len ( arr )
    m = len ( arr [ 0 ] )
    sum = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( m + 1 ) :
            if ( i == 0 or j == 0 ) :
                sum [ i ] [ j ] = 0
                continue
            sum [ i ] [ j ] = arr [ i - 1 ] [ j - 1 ] + sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ]
    ans = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            if ( i + ans - 1 > n or j + ans - 1 > m ) :
                break
            mid = ans
            lo = ans
            hi = min ( n - i + 1 , m - j + 1 )
            while ( lo < hi ) :
                mid = ( hi + lo + 1 ) // 2
                if ( sum [ i + mid - 1 ] [ j + mid - 1 ] + sum [ i - 1 ] [ j - 1 ] - sum [ i + mid - 1 ] [ j - 1 ] - sum [ i - 1 ] [ j + mid - 1 ] <= K ) :
                    lo = mid
                else :
                    hi = mid - 1
            ans = max ( ans , lo )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 1 , 3 , 2 , 4 , 3 , 2 ] , [ 1 , 1 , 3 , 2 , 4 , 3 , 2 ] , [ 1 , 1 , 3 , 2 , 4 , 3 , 2 ] ]
    K = 4
    findMaxMatrixSize ( arr , K )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def FindRank ( arr , length ) :
    print ( 1 , end = " ▁ " )
    for i in range ( 1 , length ) :
        rank = 1
        for j in range ( 0 , i ) :
            if ( arr [ j ] > arr [ i ] ) :
                rank = rank + 1
        print ( rank , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 88 , 14 , 69 , 30 , 29 , 89 ]
    length = len ( arr )
    FindRank ( arr , length )

Index/key variables: i, j
Iterator variables: i, j
Python program:
from collections import defaultdict
def longestPermutation ( a , n ) :
    freq = defaultdict ( int )
    for i in range ( n ) :
        freq [ a [ i ] ] += 1
    length = 0
    for i in range ( 1 , n + 1 ) :
        if ( freq [ i ] == 0 ) :
            break
        length += 1
    return length
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 2 , 1 , 6 , 5 ]
    n = len ( arr )
    print ( longestPermutation ( arr , n ) )

Index/key variables: i
Accumulator variables: length
Iterator variables: i
Python program:
MAX = 10005
fib = set ( )
def fibonacci ( ) :
    global fib
    global MAX
    prev = 0
    curr = 1
    l = 2
    fib . add ( prev )
    fib . add ( curr )
    while ( l <= MAX ) :
        temp = curr + prev
        fib . add ( temp )
        prev = curr
        curr = temp
        l += 1
def findFibonacci ( N ) :
    global fib
    i = N // 2
    while ( i > 1 ) :
        if ( i in fib and ( N - i ) in fib ) :
            print ( i , ( N - i ) )
            return
        i -= 1
    print ( " - 1" )
if __name__ == ' _ _ main _ _ ' :
    fibonacci ( )
    sum = 199
    findFibonacci ( sum )

Accumulator variables: fib, i, l
Python program:
MAX = 100005
fibonacci = set ( )
def createHash ( ) :
    global fibonacci
    prev , curr = 0 , 1
    fibonacci . add ( prev )
    fibonacci . add ( curr )
    while ( curr <= MAX ) :
        temp = curr + prev
        if temp <= MAX :
            fibonacci . add ( temp )
        prev = curr
        curr = temp
def checkArray ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        if ( arr [ i ] in fibonacci ) :
            sum += arr [ i ]
    if ( sum in fibonacci ) :
        return True
    return False
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 8 , 2 ]
    n = len ( arr )
    createHash ( )
    if ( checkArray ( arr , n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: fibonacci, sum
Iterator variables: i
Python program:
MAX = 1000005
fibUpto = [ 0 ] * ( MAX + 1 )
def compute ( sz ) :
    isFib = [ False ] * ( sz + 1 )
    prev = 0
    curr = 1
    isFib [ prev ] = True
    isFib [ curr ] = True
    while ( curr <= sz ) :
        temp = curr + prev
        if ( temp <= sz ) :
            isFib [ temp ] = True
        prev = curr
        curr = temp
    fibUpto [ 0 ] = 1
    for i in range ( 1 , sz + 1 ) :
        fibUpto [ i ] = fibUpto [ i - 1 ]
        if ( isFib [ i ] ) :
            fibUpto [ i ] += 1
def countOfNumbers ( N , K ) :
    compute ( N )
    low , high , ans = 1 , N , 0
    while ( low <= high ) :
        mid = ( low + high ) >> 1
        if ( mid - fibUpto [ mid ] >= K ) :
            ans = mid
            high = mid - 1
        else :
            low = mid + 1
    if ( ans ) :
        return ( N - ans + 1 )
    return 0
if __name__ == " _ _ main _ _ " :
    N = 10
    K = 3
    print ( countOfNumbers ( N , K ) )

Index/key variables: curr, i, mid, prev, temp
Iterator variables: i
Python program:
N = 100000
def createHash ( hash , maxElement ) :
    prev = 0
    curr = 1
    hash . add ( prev )
    hash . add ( curr )
    while ( curr <= maxElement ) :
        temp = curr + prev
        hash . add ( temp )
        prev = curr
        curr = temp
def longestFibSubarray ( arr , n ) :
    max_val = max ( arr )
    hash = { int }
    createHash ( hash , max_val )
    left = [ 0 for i in range ( n ) ]
    right = [ 0 for i in range ( n ) ]
    fibcount = 0
    res = - 1
    for i in range ( n ) :
        left [ i ] = fibcount
        if ( arr [ i ] in hash ) :
            fibcount += 1
        else :
            fibcount = 0
    fibcount = 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        right [ i ] = fibcount
        if ( arr [ i ] in hash ) :
            fibcount += 1
        else :
            fibcount = 0
    for i in range ( 0 , n ) :
        res = max ( res , left [ i ] + right [ i ] )
    return res
arr = [ 2 , 8 , 5 , 7 , 3 , 5 , 7 ]
n = len ( arr )
print ( longestFibSubarray ( arr , n ) )

Index/key variables: i
Accumulator variables: fibcount, hash
Iterator variables: i
Python program:
from math import sqrt
def isPrime ( N ) :
    if ( N < 2 ) :
        return False
    if ( N < 4 ) :
        return True
    if ( ( N & 1 ) == 0 ) :
        return False
    if ( N % 3 == 0 ) :
        return False
    curr = 5
    s = sqrt ( N )
    while ( curr <= s ) :
        if ( N % curr == 0 ) :
            return False
        curr += 2
        if ( N % curr == 0 ) :
            return False
        curr += 4
    return True
def check ( s , p , prefix_sum , n ) :
    satisfies = True
    for i in range ( n ) :
        if ( i + s - 1 >= n ) :
            break
        if ( i - 1 >= 0 ) :
            x = prefix_sum [ i - 1 ]
        else :
            x = 0
        if ( prefix_sum [ i + s - 1 ] - x < p ) :
            satisfies = False
    return satisfies
def minimumWindowSize ( x , y , p ) :
    prefix_sum = [ 0 ] * ( y - x + 1 )
    for i in range ( x , y + 1 ) :
        if ( isPrime ( i ) ) :
            prefix_sum [ i - x ] = 1
    for i in range ( 1 , y - x + 1 ) :
        prefix_sum [ i ] += prefix_sum [ i - 1 ]
    low = 1
    high = y - x + 1
    while ( high - low > 1 ) :
        mid = ( low + high ) // 2
        if ( check ( mid , p , prefix_sum , y - x + 1 ) ) :
            high = mid
        else :
            low = mid
    if ( check ( low , p , prefix_sum , y - x + 1 ) ) :
        return low
    return high
x = 12
y = 42
p = 3
print ( minimumWindowSize ( x , y , p ) )

Index/key variables: i
Accumulator variables: curr
Iterator variables: i
Boolean variables: satisfies
Python program:
def xorOfSum ( a , n ) :
    answer = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            answer ^= ( a [ i ] + a [ j ] )
    return answer
if __name__ == ' _ _ main _ _ ' :
    n = 3
    A = [ 1 , 2 , 3 ]
    print ( xorOfSum ( A , n ) )

Index/key variables: i, j
Accumulator variables: answer
Iterator variables: i, j
Python program:
N = 4
M = 5
def preProcess ( mat , aux ) :
    for i in range ( M ) :
        aux [ 0 ] [ i ] = mat [ 0 ] [ i ]
    for i in range ( 1 , N ) :
        for j in range ( M ) :
            aux [ i ] [ j ] = ( mat [ i ] [ j ] + aux [ i - 1 ] [ j ] )
    for i in range ( N ) :
        for j in range ( 1 , M ) :
            aux [ i ] [ j ] += aux [ i ] [ j - 1 ]
def sumQuery ( aux , tli , tlj , rbi , rbj ) :
    res = aux [ rbi ] [ rbj ]
    if ( tli > 0 ) :
        res = res - aux [ tli - 1 ] [ rbj ]
    if ( tlj > 0 ) :
        res = res - aux [ rbi ] [ tlj - 1 ]
    if ( tli > 0 and tlj > 0 ) :
        res = ( res + aux [ tli - 1 ] [ tlj - 1 ] )
    return res
def maximumSquareSize ( mat , K ) :
    aux = [ [ 0 for x in range ( M ) ] for y in range ( N ) ]
    preProcess ( mat , aux )
    for i in range ( min ( N , M ) , 0 , - 1 ) :
        satisfies = True
        for x in range ( N ) :
            for y in range ( M ) :
                if ( x + i - 1 <= N - 1 and y + i - 1 <= M - 1 ) :
                    if ( sumQuery ( aux , x , y , x + i - 1 , y + i - 1 ) > K ) :
                        satisfies = False
        if ( satisfies == True ) :
            return ( i )
    return 0
if __name__ == " _ _ main _ _ " :
    K = 30
    mat = [ [ 1 , 2 , 3 , 4 , 6 ] , [ 5 , 3 , 8 , 1 , 2 ] , [ 4 , 6 , 7 , 5 , 5 ] , [ 2 , 4 , 8 , 9 , 4 ] ]
    print ( maximumSquareSize ( mat , K ) )

Index/key variables: i, j, rbi, rbj
Iterator variables: i, j, x, y
Boolean variables: satisfies
Python program:
def createHash ( hash1 , maxElement ) :
    prev , curr = 0 , 1
    hash1 . add ( prev )
    hash1 . add ( curr )
    while ( curr < maxElement ) :
        temp = curr + prev
        hash1 . add ( temp )
        prev = curr
        curr = temp
def findFibonacciPair ( n ) :
    hash1 = set ( )
    createHash ( hash1 , n )
    for i in range ( n ) :
        if ( i in hash1 and ( n - i ) in hash1 ) :
            print ( i , " , ▁ " , ( n - i ) )
            return
    print ( " - 1" )
if __name__ == " _ _ main _ _ " :
    N = 90
    findFibonacciPair ( N )

Accumulator variables: hash1
Iterator variables: i
Python program:
from collections import defaultdict
import math
def add_factors ( n , mp ) :
    for i in range ( 1 , int ( math . sqrt ( n ) ) + 1 , ) :
        if ( n % i == 0 ) :
            if ( n // i == i ) :
                mp [ i ] += 1
            else :
                mp [ i ] += 1
                mp [ n // i ] += 1
def count_divisors ( a , n ) :
    mp = defaultdict ( int )
    for i in range ( n ) :
        print ( mp [ a [ i ] ] , end = " ▁ " )
        add_factors ( a [ i ] , mp )
if __name__ == " _ _ main _ _ " :
    arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ]
    n = len ( arr )
    count_divisors ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def removeDuplicates ( arr , n ) :
    st = 0 ;
    for i in range ( n ) :
        if ( i < n - 2 and arr [ i ] == arr [ i + 1 ] and arr [ i ] == arr [ i + 2 ] ) :
            continue ;
        else :
            arr [ st ] = arr [ i ] ;
            st += 1 ;
    print ( " { " , end = " " )
    for i in range ( st ) :
        print ( arr [ i ] , end = " " ) ;
        if ( i != st - 1 ) :
            print ( " , ▁ " , end = " " ) ;
    print ( " } " , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    removeDuplicates ( arr , n ) ;

Index/key variables: i, st
Iterator variables: i
Python program:
def permutation ( arr , n ) :
    s = set ( )
    maxEle = 0 ;
    for i in range ( n ) :
        s . add ( arr [ i ] ) ;
        maxEle = max ( maxEle , arr [ i ] ) ;
    if ( maxEle != n ) :
        return False
    if ( len ( s ) == n ) :
        return True ;
    return False ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 5 , 3 , 2 ]
    n = len ( arr )
    if ( permutation ( arr , n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
from collections import defaultdict , deque
def desopo ( graph ) :
    v = len ( graph )
    adj = defaultdict ( list )
    for i in range ( v ) :
        for j in range ( i + 1 , v ) :
            if graph [ i ] [ j ] != 0 :
                adj [ i ] . append ( [ graph [ i ] [ j ] , j ] )
                adj [ j ] . append ( [ graph [ i ] [ j ] , i ] )
    q = deque ( [ ] )
    distance = [ float ( ' inf ' ) ] * v
    is_in_queue = [ False ] * v
    source = 0
    distance = 0
    q . append ( source )
    is_in_queue = True
    while q :
        u = q . popleft ( )
        is_in_queue [ u ] = False
        for e in adj [ u ] :
            if distance [ e [ 1 ] ] > distance [ u ] + e [ 0 ] :
                distance [ e [ 1 ] ] = distance [ u ] + e [ 0 ]
                if is_in_queue [ e [ 1 ] ] == False :
                    if distance [ e [ 1 ] ] == float ( ' inf ' ) :
                        q . append ( e [ 1 ] )
                    else :
                        q . appendleft ( e [ 1 ] )
                    is_in_queue [ e [ 1 ] ] = True
    return distance
if __name__ == " _ _ main _ _ " :
    graph = [ [ 0 , 4 , 0 , 0 , 8 ] , [ 0 , 0 , 8 , 0 , 11 ] , [ 0 , 8 , 0 , 2 , 0 ] , [ 0 , 0 , 2 , 0 , 1 ] , [ 8 , 11 , 0 , 1 , 0 ] ]
    print ( desopo ( graph ) )

Index/key variables: i, j, u
Accumulator variables: q
Iterator variables: e, i, j
Boolean variables: is_in_queue
Python program:
def CountSubSet ( arr , n , X ) :
    N = 2 ** n ;
    count = 0 ;
    for i in range ( N ) :
        for j in range ( n ) :
            if ( i & ( 1 << j ) ) :
                if ( arr [ j ] == X ) :
                    count += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 5 , 6 , 7 ] ;
    X = 5 ;
    n = len ( arr ) ;
    print ( CountSubSet ( arr , n , X ) ) ;

Index/key variables: j
Accumulator variables: count
Iterator variables: i, j
Python program:
def calculatePower ( b , e ) :
    ans = 1 ;
    while ( e > 0 ) :
        if ( e % 2 == 1 ) :
            ans = ans * b ;
        e = e // 2 ;
        b = b * b ;
    return ans ;
def CountSubSet ( arr , n , X ) :
    count = 0 ; checkX = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] == X ) :
            checkX = 1 ;
            break ;
    if ( checkX == 1 ) :
        count = calculatePower ( 2 , n - 1 ) ;
    else :
        count = 0 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 5 , 6 , 7 ] ;
    X = 5 ;
    n = len ( arr ) ;
    print ( CountSubSet ( arr , n , X ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def woodCollected ( height , n , m ) :
    sum = 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( height [ i ] - m <= 0 ) :
            break
        sum += ( height [ i ] - m )
    return sum
def collectKWood ( height , n , k ) :
    height = sorted ( height )
    low = 0
    high = height [ n - 1 ]
    while ( low <= high ) :
        mid = low + ( ( high - low ) // 2 )
        collected = woodCollected ( height , n , mid )
        if ( collected == k ) :
            return mid
        if ( collected > k ) :
            low = mid + 1
        else :
            high = mid - 1
    return - 1
height = [ 1 , 2 , 1 , 2 ]
n = len ( height )
k = 2
print ( collectKWood ( height , n , k ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
MAX = 10
def isDigit ( ch ) :
    ch = ord ( ch )
    if ( ch >= ord ( '0' ) and ch <= ord ( '9' ) ) :
        return True
    return False
def allDigits ( st , le ) :
    present = [ False for i in range ( MAX ) ]
    for i in range ( le ) :
        if ( isDigit ( st [ i ] ) ) :
            digit = ord ( st [ i ] ) - ord ( '0' )
            present [ digit ] = True
    for i in range ( MAX ) :
        if ( present [ i ] == False ) :
            return False
    return True
st = " Geeks12345for69708"
le = len ( st )
if ( allDigits ( st , le ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: digit, i
Iterator variables: i
Python program:
def isPlusPossible ( arr , n ) :
    mp = dict ( )
    for i in range ( n ) :
        mp [ arr [ i ] ] = mp . get ( arr [ i ] , 0 ) + 1
    foundModOne = False
    for x in mp :
        element = x
        frequency = mp [ x ]
        if ( frequency % 4 == 0 ) :
            continue
        if ( frequency % 4 == 1 ) :
            if ( foundModOne == True ) :
                return False
            foundModOne = True
        else :
            return False
    return True
arr = [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 2 ]
n = len ( arr )
if ( isPlusPossible ( arr , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, x
Iterator variables: i, x
Boolean variables: foundModOne