dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def minSum ( A , N ) :
    mp = { }
    sum = 0
    for i in range ( N ) :
        sum += A [ i ]
        if A [ i ] in mp :
            mp [ A [ i ] ] += 1
        else :
            mp [ A [ i ] ] = 1
    minSum = float ( ' inf ' )
    for it in mp :
        minSum = min ( minSum , sum - ( it * mp [ it ] ) )
    return minSum
arr = [ 4 , 5 , 6 , 6 ]
N = len ( arr )
print ( minSum ( arr , N ) )

Index/key variables: i, it
Accumulator variables: sum
Iterator variables: i, it
Python program:
def maxAdjacent ( arr , N ) :
    res = [ ]
    for i in range ( 1 , N - 1 ) :
        prev = arr [ 0 ]
        maxi = - 1 * float ( ' inf ' )
        for j in range ( 1 , N ) :
            if ( i == j ) :
                continue
            maxi = max ( maxi , abs ( arr [ j ] - prev ) )
            prev = arr [ j ]
        res . append ( maxi )
    for x in res :
        print ( x , end = ' ▁ ' )
    print ( )
arr = [ 1 , 3 , 4 , 7 , 8 ]
N = len ( arr )
maxAdjacent ( arr , N )

Index/key variables: j
Accumulator variables: res
Iterator variables: i, j, x
Python program:
def prime ( n ) :
    if ( n == 1 ) :
        return False
    for i in range ( 2 , n + 1 ) :
        if i * i > n :
            break
        if ( n % i == 0 ) :
            return False
    return True
def minDivisior ( n ) :
    if ( prime ( n ) ) :
        print ( 1 , n - 1 )
    else :
        for i in range ( 2 , n + 1 ) :
            if i * i > n :
                break
            if ( n % i == 0 ) :
                print ( n // i , n // i * ( i - 1 ) )
                break
N = 4
minDivisior ( N )

Iterator variables: i
Python program:
import sys
Landau = - sys . maxsize - 1
def gcd ( a , b ) :
    if ( a == 0 ) :
        return b
    return gcd ( b % a , a )
def lcm ( a , b ) :
    return ( a * b ) // gcd ( a , b )
def findLCM ( arr ) :
    global Landau
    nth_lcm = arr [ 0 ]
    for i in range ( 1 , len ( arr ) ) :
        nth_lcm = lcm ( nth_lcm , arr [ i ] )
    Landau = max ( Landau , nth_lcm )
def findWays ( arr , i , n ) :
    if ( n == 0 ) :
        findLCM ( arr )
    for j in range ( i , n + 1 ) :
        arr . append ( j )
        findWays ( arr , j , n - j )
        arr . pop ( )
def Landau_function ( n ) :
    arr = [ ]
    findWays ( arr , 1 , n )
    print ( Landau )
N = 4
Landau_function ( N )

Index/key variables: i
Accumulator variables: arr
Iterator variables: i, j
Python program:
def isPrime ( n ) :
    if ( n == 1 ) :
        return True
    if ( n <= 3 ) :
        return True
    if ( ( n % 2 == 0 ) or ( n % 3 == 0 ) ) :
        return False
    i = 5
    while ( i * i <= n ) :
        if ( ( n % i == 0 ) or ( n % ( i + 2 ) == 0 ) ) :
            return False ;
            i += 6
    return true ;
def checkExpression ( n ) :
    if ( isPrime ( n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    checkExpression ( N )

Accumulator variables: i
Python program:
def checkArray ( n , k , arr ) :
    cnt = 0
    for i in range ( n ) :
        if ( arr [ i ] & 1 ) :
            cnt += 1
    if ( cnt >= k and cnt % 2 == k % 2 ) :
        return True
    else :
        return False
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 4 , 7 , 5 , 3 , 1 ]
    n = len ( arr )
    k = 4
    if ( checkArray ( n , k , arr ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
from math import *
def func ( arr , n ) :
    ans = 0
    maxx = 0
    freq = [ 0 ] * 100005
    temp = 0
    for i in range ( n ) :
        temp = arr [ i ]
        freq [ temp ] += 1
        maxx = max ( maxx , temp )
    for i in range ( 1 , maxx + 1 ) :
        freq [ i ] += freq [ i - 1 ]
    for i in range ( 1 , maxx + 1 ) :
        if ( freq [ i ] ) :
            value = 0
            cur = ceil ( 0.5 * i ) - 1.0
            j = 1.5
            while ( 1 ) :
                val = min ( maxx , ( ceil ( i * j ) - 1.0 ) )
                times = ( freq [ i ] - freq [ i - 1 ] )
                con = j - 0.5
                ans += times * con * ( freq [ int ( val ) ] - freq [ int ( cur ) ] )
                cur = val
                if ( val == maxx ) :
                    break
                j += 1
    return int ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 ]
    n = len ( arr )
    print ( func ( arr , n ) )

Index/key variables: i, temp
Accumulator variables: ans, j
Iterator variables: i
Python program:
def insert_element ( a , n ) :
    Xor = 0
    Sum = 0
    for i in range ( n ) :
        Xor ^= a [ i ]
        Sum += a [ i ]
    if ( Sum == 2 * Xor ) :
        print ( 0 )
        return
    if ( Xor == 0 ) :
        print ( 1 )
        print ( Sum )
        return
    num1 = Sum + Xor
    num2 = Xor
    print ( 2 )
    print ( num1 , num2 )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 3 ]
    n = len ( a )
    insert_element ( a , n )

Index/key variables: i
Accumulator variables: Sum, Xor
Iterator variables: i
Python program:
def countValues ( n ) :
    answer = 0
    for i in range ( 2 , n + 1 , 1 ) :
        k = n
        while ( k >= i ) :
            if ( k % i == 0 ) :
                k //= i
            else :
                k -= i
        if ( k == 1 ) :
            answer += 1
    return answer
if __name__ == ' _ _ main _ _ ' :
    N = 6
    print ( countValues ( N ) )

Accumulator variables: answer, k
Iterator variables: i
Python program:
def printKNumbers ( N , K ) :
    for i in range ( K - 1 ) :
        print ( 1 , end = ' ▁ ' )
    print ( N - K + 1 )
if __name__ == ' _ _ main _ _ ' :
    ( N , K ) = ( 10 , 3 )
    printKNumbers ( N , K )

Iterator variables: i
Python program:
def NthSmallest ( K ) :
    Q = [ ]
    for i in range ( 1 , 10 ) :
        Q . append ( i )
    for i in range ( 1 , K + 1 ) :
        x = Q [ 0 ]
        Q . remove ( Q [ 0 ] )
        if ( x % 10 != 0 ) :
            Q . append ( x * 10 + x % 10 - 1 )
        Q . append ( x * 10 + x % 10 )
        if ( x % 10 != 9 ) :
            Q . append ( x * 10 + x % 10 + 1 )
    return x
if __name__ == ' _ _ main _ _ ' :
    N = 16
    print ( NthSmallest ( N ) )

Accumulator variables: Q
Iterator variables: i
Python program:
import math
def decBinary ( arr , n ) :
    k = int ( math . log2 ( n ) )
    while ( n > 0 ) :
        arr [ k ] = n % 2
        k = k - 1
        n = n // 2
def binaryDec ( arr , n ) :
    ans = 0
    for i in range ( 0 , n ) :
        ans = ans + ( arr [ i ] << ( n - i - 1 ) )
    return ans
def getNum ( n , k ) :
    l = int ( math . log2 ( n ) ) + 1
    a = [ 0 for i in range ( 0 , l ) ]
    decBinary ( a , n )
    if ( k > l ) :
        return n
    if ( a [ k - 1 ] == 0 ) :
        a [ k - 1 ] = 1
    else :
        a [ k - 1 ] = 0
    return binaryDec ( a , l )
n = 56
k = 2
print ( getNum ( n , k ) )

Index/key variables: i, k
Iterator variables: i
Python program:
MAX = 1000000
MOD = 10 ** 9 + 7
result = [ 0 for i in range ( MAX + 1 ) ]
fact = [ 0 for i in range ( MAX + 1 ) ]
def preCompute ( ) :
    fact [ 0 ] = 1
    result [ 0 ] = 1
    for i in range ( 1 , MAX + 1 ) :
        fact [ i ] = ( ( fact [ i - 1 ] % MOD ) * i ) % MOD
        result [ i ] = ( ( result [ i - 1 ] % MOD ) * ( fact [ i ] % MOD ) ) % MOD
def performQueries ( q , n ) :
    preCompute ( )
    for i in range ( n ) :
        print ( result [ q [ i ] ] )
q = [ 4 , 5 ]
n = len ( q )
performQueries ( q , n )

Index/key variables: i
Iterator variables: i
Python program:
MAXN = 1000001
spf = [ i for i in range ( MAXN ) ]
hash1 = [ 0 for i in range ( MAXN ) ]
def sieve ( ) :
    for i in range ( 4 , MAXN , 2 ) :
        spf [ i ] = 2
    for i in range ( 3 , MAXN ) :
        if i * i >= MAXN :
            break
        if ( spf [ i ] == i ) :
            for j in range ( i * i , MAXN , i ) :
                if ( spf [ j ] == j ) :
                    spf [ j ] = i
def getFactorization ( x ) :
    while ( x != 1 ) :
        temp = spf [ x ]
        if ( x % temp == 0 ) :
            hash1 [ spf [ x ] ] += 1
            x = x // spf [ x ]
        while ( x % temp == 0 ) :
            x = x // temp
def check ( x ) :
    while ( x != 1 ) :
        temp = spf [ x ]
        if ( x % temp == 0 and hash1 [ temp ] > 1 ) :
            return False
        while ( x % temp == 0 ) :
            x = x // temp
    return True
def hasValidNum ( arr , n ) :
    sieve ( )
    for i in range ( n ) :
        getFactorization ( arr [ i ] )
    for i in range ( n ) :
        if ( check ( arr [ i ] ) ) :
            return True
    return False
arr = [ 2 , 8 , 4 , 10 , 6 , 7 ]
n = len ( arr )
if ( hasValidNum ( arr , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j, temp, x
Iterator variables: i, j
Python program:
l = [ [ 0 for i in range ( 1001 ) ] for j in range ( 1001 ) ]
def initialize ( ) :
    l [ 0 ] [ 0 ] = 1
    for i in range ( 1 , 1001 ) :
        l [ i ] [ 0 ] = 1
        for j in range ( 1 , i + 1 ) :
            l [ i ] [ j ] = ( l [ i - 1 ] [ j - 1 ] + l [ i - 1 ] [ j ] )
def nCr ( n , r ) :
    return l [ n ] [ r ]
initialize ( )
n = 8
r = 3
print ( nCr ( n , r ) )

Index/key variables: i, j, n, r
Iterator variables: i, j
Python program:
def check ( s ) :
    freq = [ 0 ] * 10
    while ( s != 0 ) :
        r = s % 10
        s = s // 10
        freq [ r ] += 1
    xor = 0
    for i in range ( 10 ) :
        xor = xor ^ freq [ i ]
    if ( xor == 0 ) :
        return True
    else :
        return False
s = 122233
if ( check ( s ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, r
Iterator variables: i
Python program:
def printLines ( n , k ) :
    for i in range ( n ) :
        print ( k * ( 6 * i + 1 ) , k * ( 6 * i + 2 ) , k * ( 6 * i + 3 ) , k * ( 6 * i + 5 ) )
if __name__ == " _ _ main _ _ " :
    n , k = 2 , 2
    printLines ( n , k )

Iterator variables: i
Python program:
mod = 1000000007
def count_special ( n ) :
    fib = [ 0 for i in range ( n + 1 ) ]
    fib [ 0 ] = 1
    fib [ 1 ] = 2
    for i in range ( 2 , n + 1 , 1 ) :
        fib [ i ] = ( fib [ i - 1 ] % mod + fib [ i - 2 ] % mod ) % mod
    return fib [ n ]
if __name__ == ' _ _ main _ _ ' :
    n = 3
    print ( count_special ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
mod = 1e9 + 7 ;
def ways ( i , arr , n ) :
    if ( i == n - 1 ) :
        return 1 ;
    sum = 0 ;
    for j in range ( 1 , arr [ i ] + 1 ) :
        if ( i + j < n ) :
            sum += ( ways ( i + j , arr , n ) ) % mod ;
            sum %= mod ;
    return int ( sum % mod ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 3 , 1 , 4 , 3 ] ;
    n = len ( arr ) ;
    print ( ways ( 0 , arr , n ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: j
Python program:
mod = 10 ** 9 + 7
def ways ( arr , n ) :
    dp = [ 0 ] * ( n + 1 )
    dp [ n - 1 ] = 1
    for i in range ( n - 2 , - 1 , - 1 ) :
        dp [ i ] = 0
        j = 1
        while ( ( j + i ) < n and j <= arr [ i ] ) :
            dp [ i ] += dp [ i + j ]
            dp [ i ] %= mod
            j += 1
    return dp [ 0 ] % mod
arr = [ 5 , 3 , 1 , 4 , 3 ]
n = len ( arr )
print ( ways ( arr , n ) % mod )

Index/key variables: i
Accumulator variables: j
Iterator variables: i
Python program:
def countSum ( arr , n ) :
    result = 0
    count_odd = 0
    count_even = 0
    for i in range ( 1 , n + 1 ) :
        if ( arr [ i - 1 ] % 2 == 0 ) :
            count_even = count_even + count_even + 1
            count_odd = count_odd + count_odd
        else :
            temp = count_even
            count_even = count_even + count_odd
            count_odd = count_odd + temp + 1
    return ( count_even , count_odd )
arr = [ 1 , 2 , 2 , 3 ] ;
n = len ( arr )
count_even , count_odd = countSum ( arr , n ) ;
print ( " EvenSum ▁ = ▁ " , count_even , " ▁ OddSum ▁ = ▁ " , count_odd )

Iterator variables: i
Python program:
MAX = 10
def numToVec ( N ) :
    digit = [ ]
    while ( N != 0 ) :
        digit . append ( N % 10 )
        N = N // 10
    if ( len ( digit ) == 0 ) :
        digit . append ( 0 )
    digit = digit [ : : - 1 ]
    return digit
def solve ( A , B , C ) :
    d , d2 = 0 , 0
    digit = numToVec ( C )
    d = len ( A )
    if ( B > len ( digit ) or d == 0 ) :
        return 0
    elif ( B < len ( digit ) ) :
        if ( A [ 0 ] == 0 and B != 1 ) :
            return ( d - 1 ) * pow ( d , B - 1 )
        else :
            return pow ( d , B )
    else :
        dp = [ 0 for i in range ( B + 1 ) ]
        lower = [ 0 for i in range ( MAX + 1 ) ]
        for i in range ( d ) :
            lower [ A [ i ] + 1 ] = 1
        for i in range ( 1 , MAX + 1 ) :
            lower [ i ] = lower [ i - 1 ] + lower [ i ]
        flag = True
        dp [ 0 ] = 0
        for i in range ( 1 , B + 1 ) :
            d2 = lower [ digit [ i - 1 ] ]
            dp [ i ] = dp [ i - 1 ] * d
            if ( i == 1 and A [ 0 ] == 0 and B != 1 ) :
                d2 = d2 - 1
            if ( flag ) :
                dp [ i ] += d2
            flag = ( flag & ( lower [ digit [ i - 1 ] + 1 ] == lower [ digit [ i - 1 ] ] + 1 ) )
        return dp [ B ]
A = [ 0 , 1 , 2 , 5 ]
N = 2
k = 21
print ( solve ( A , N , k ) )

Index/key variables: B, i
Accumulator variables: digit
Iterator variables: i
Boolean variables: flag
Python program:
def partitions ( n ) :
    p = [ 0 ] * ( n + 1 )
    p [ 0 ] = 1
    for i in range ( 1 , n + 1 ) :
        k = 1
        while ( ( k * ( 3 * k - 1 ) ) / 2 <= i ) :
            p [ i ] += ( ( 1 if k % 2 else - 1 ) * p [ i - ( k * ( 3 * k - 1 ) ) // 2 ] )
            if ( k > 0 ) :
                k *= - 1
            else :
                k = 1 - k
    return p [ n ]
if __name__ == " _ _ main _ _ " :
    N = 20
    print ( partitions ( N ) )

Index/key variables: i, n
Accumulator variables: k
Iterator variables: i
Python program:
MAX = 20
def LIP ( dp , mat , n , m , x , y ) :
    if ( dp [ x ] [ y ] < 0 ) :
        result = 0
        if ( x == n - 1 and y == m - 1 ) :
            dp [ x ] [ y ] = 1
            return dp [ x ] [ y ]
        if ( x == n - 1 or y == m - 1 ) :
            result = 1
        if ( x + 1 < n and mat [ x ] [ y ] < mat [ x + 1 ] [ y ] ) :
            result = 1 + LIP ( dp , mat , n , m , x + 1 , y )
        if ( y + 1 < m and mat [ x ] [ y ] < mat [ x ] [ y + 1 ] ) :
            result = max ( result , 1 + LIP ( dp , mat , n , m , x , y + 1 ) )
        dp [ x ] [ y ] = result
    return dp [ x ] [ y ]
def wrapper ( mat , n , m ) :
    dp = [ [ - 1 for i in range ( MAX ) ] for i in range ( MAX ) ]
    return LIP ( dp , mat , n , m , 0 , 0 )
mat = [ [ 1 , 2 , 3 , 4 ] , [ 2 , 2 , 3 , 4 ] , [ 3 , 2 , 3 , 4 ] , [ 4 , 5 , 6 , 7 ] ]
n = 4
m = 4
print ( wrapper ( mat , n , m ) )

Index/key variables: x, y
Python program:
MAX = 100
def getMaxGold ( gold , m , n ) :
    goldTable = [ [ 0 for i in range ( n ) ] for j in range ( m ) ]
    for col in range ( n - 1 , - 1 , - 1 ) :
        for row in range ( m ) :
            if ( col == n - 1 ) :
                right = 0
            else :
                right = goldTable [ row ] [ col + 1 ]
            if ( row == 0 or col == n - 1 ) :
                right_up = 0
            else :
                right_up = goldTable [ row - 1 ] [ col + 1 ]
            if ( row == m - 1 or col == n - 1 ) :
                right_down = 0
            else :
                right_down = goldTable [ row + 1 ] [ col + 1 ]
            goldTable [ row ] [ col ] = gold [ row ] [ col ] + max ( right , right_up , right_down )
    res = goldTable [ 0 ] [ 0 ]
    for i in range ( 1 , m ) :
        res = max ( res , goldTable [ i ] [ 0 ] )
    return res
gold = [ [ 1 , 3 , 1 , 5 ] , [ 2 , 2 , 4 , 1 ] , [ 5 , 0 , 2 , 3 ] , [ 0 , 6 , 1 , 2 ] ]
m = 4
n = 4
print ( getMaxGold ( gold , m , n ) )

Index/key variables: col, i, row
Iterator variables: col, i, row
Python program:
M = 100
def minAdjustmentCost ( A , n , target ) :
    dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]
    for j in range ( M + 1 ) :
        dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )
    for i in range ( 1 , n ) :
        for j in range ( M + 1 ) :
            dp [ i ] [ j ] = 100000000
            for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :
                dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )
    res = 10000000
    for j in range ( M + 1 ) :
        res = min ( res , dp [ n - 1 ] [ j ] )
    return res
arr = [ 55 , 77 , 52 , 61 , 39 , 6 , 25 , 60 , 49 , 47 ]
n = len ( arr )
target = 10
print ( " Minimum ▁ adjustment ▁ cost ▁ is " , minAdjustmentCost ( arr , n , target ) , sep = ' ▁ ' )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def printArrays ( n ) :
    A , B = [ ] , [ ] ;
    for i in range ( 1 , 2 * n + 1 ) :
        if ( i % 2 == 0 ) :
            A . append ( i ) ;
        else :
            B . append ( i ) ;
    print ( " { ▁ " , end = " " ) ;
    for i in range ( n ) :
        print ( A [ i ] , end = " " ) ;
        if ( i != n - 1 ) :
            print ( " , ▁ " , end = " " ) ;
    print ( " } " ) ;
    print ( " { ▁ " , end = " " ) ;
    for i in range ( n ) :
        print ( B [ i ] , end = " " ) ;
        if ( i != n - 1 ) :
            print ( " , " , end = " ▁ " ) ;
    print ( " ▁ } " , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    N = 5 ;
    printArrays ( N ) ;

Index/key variables: i
Accumulator variables: A, B
Iterator variables: i
Python program:
def flipBitsOfAandB ( A , B ) :
    for i in range ( 0 , 32 ) :
        if ( ( A & ( 1 << i ) ) and ( B & ( 1 << i ) ) ) :
            A = A ^ ( 1 << i )
            B = B ^ ( 1 << i )
    print ( A , B )
if __name__ == " _ _ main _ _ " :
    A = 7
    B = 4
    flipBitsOfAandB ( A , B )

Iterator variables: i
Python program:
def countSubstrings ( str ) :
    freq = [ 0 ] * 3
    count = 0
    i = 0
    for j in range ( 0 , len ( str ) ) :
        freq [ ord ( str [ j ] ) - ord ( '0' ) ] += 1
        while ( freq [ 0 ] > 0 and freq [ 1 ] > 0 and freq [ 2 ] > 0 ) :
            i += 1
            freq [ ord ( str [ i ] ) - ord ( '0' ) ] -= 1
        count += i
    return count
str = "00021"
count = countSubstrings ( str )
print ( count )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: j
Python program:
def minFlips ( st ) :
    count = 0
    if ( len ( st ) <= 2 ) :
        return 0
    for i in range ( len ( st ) - 2 ) :
        if ( st [ i ] == st [ i + 1 ] and st [ i + 2 ] == st [ i + 1 ] ) :
            i = i + 3
            count += 1
        else :
            i += 1
    return count
if __name__ == " _ _ main _ _ " :
    S = "0011101"
    print ( minFlips ( S ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def convertToHex ( num ) :
    temp = " "
    while ( num != 0 ) :
        rem = num % 16
        c = 0
        if ( rem < 10 ) :
            c = rem + 48
        else :
            c = rem + 87
        temp += chr ( c )
        num = num // 16
    return temp
def encryptString ( S , N ) :
    ans = " "
    for i in range ( N ) :
        ch = S [ i ]
        count = 0
        while ( i < N and S [ i ] == ch ) :
            count += 1
            i += 1
        i -= 1
        hex = convertToHex ( count )
        ans += ch
        ans += hex
    ans = ans [ : : - 1 ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = " abc "
    N = len ( S )
    print ( encryptString ( S , N ) )

Index/key variables: i
Accumulator variables: ans, count, temp
Iterator variables: i
Python program:
def binomialCoeff ( n , k ) :
    res = 1
    if ( k > n - k ) :
        k = n - k
    for i in range ( k ) :
        res *= ( n - i )
        res //= ( i + 1 )
    return res
def countOfString ( N ) :
    Stotal = pow ( 2 , N )
    Sequal = 0
    if ( N % 2 == 0 ) :
        Sequal = binomialCoeff ( N , N // 2 )
    S1 = ( Stotal - Sequal ) // 2
    return S1
N = 3
print ( countOfString ( N ) )

Accumulator variables: res
Iterator variables: i
Python program:
def isValid ( a1 , a2 , strr , flag ) :
    v1 , v2 = 0 , 0
    if ( flag == 0 ) :
        v1 = strr [ 4 ]
        v2 = strr [ 3 ]
    else :
        v1 = strr [ 1 ]
        v2 = strr [ 0 ]
    if ( v1 != a1 and v1 != ' ? ' ) :
        return False
    if ( v2 != a2 and v2 != ' ? ' ) :
        return False
    return True
def inRange ( hh , mm , L , R ) :
    a = abs ( hh - mm )
    if ( a < L or a > R ) :
        return False
    return True
def displayTime ( hh , mm ) :
    if ( hh > 10 ) :
        print ( hh , end = " : " )
    elif ( hh < 10 ) :
        print ( "0" , hh , end = " : " )
    if ( mm > 10 ) :
        print ( mm )
    elif ( mm < 10 ) :
        print ( "0" , mm )
def maximumTimeWithDifferenceInRange ( strr , L , R ) :
    i , j = 0 , 0
    h1 , h2 , m1 , m2 = 0 , 0 , 0 , 0
    for i in range ( 23 , - 1 , - 1 ) :
        h1 = i % 10
        h2 = i // 10
        if ( not isValid ( chr ( h1 ) , chr ( h2 ) , strr , 1 ) ) :
            continue
        for j in range ( 59 , - 1 , - 1 ) :
            m1 = j % 10
            m2 = j // 10
            if ( not isValid ( chr ( m1 ) , chr ( m2 ) , strr , 0 ) ) :
                continue
            if ( inRange ( i , j , L , R ) ) :
                displayTime ( i , j )
                return
    if ( inRange ( i , j , L , R ) ) :
        displayTime ( i , j )
    else :
        print ( - 1 )
timeValue = " ? ? : ? ? "
L = 20
R = 39
maximumTimeWithDifferenceInRange ( timeValue , L , R )

Iterator variables: i, j
Python program:
def check ( s , n ) :
    st = [ ]
    for i in range ( n ) :
        if ( len ( st ) != 0 and st [ len ( st ) - 1 ] == s [ i ] ) :
            st . pop ( ) ;
        else :
            st . append ( s [ i ] ) ;
    if ( len ( st ) == 0 ) :
        return True ;
    else :
        return False ;
str = " aanncddc " ;
n = len ( str )
if ( check ( str , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
from collections import defaultdict
def findNumOfValidWords ( w , p ) :
    m = defaultdict ( int )
    res = [ ]
    for s in w :
        val = 0
        for c in s :
            val = val | ( 1 << ( ord ( c ) - ord ( ' a ' ) ) )
        m [ val ] += 1
    for s in p :
        val = 0
        for c in s :
            val = val | ( 1 << ( ord ( c ) - ord ( ' a ' ) ) )
        temp = val
        first = ord ( s [ 0 ] ) - ord ( ' a ' )
        count = 0
        while ( temp != 0 ) :
            if ( ( ( temp >> first ) & 1 ) == 1 ) :
                if ( temp in m ) :
                    count += m [ temp ]
            temp = ( temp - 1 ) & val
        res . append ( count )
    for it in res :
        print ( it )
if __name__ == " _ _ main _ _ " :
    arr1 = [ " aaaa " , " asas " , " able " , " ability " , " actt " , " actor " , " access " ]
    arr2 = [ " aboveyz " , " abrodyz " , " absolute " , " absoryz " , " actresz " , " gaswxyz " ]
    findNumOfValidWords ( arr1 , arr2 )

Index/key variables: temp, val
Accumulator variables: count, res
Iterator variables: c, it, s
Python program:
def flip ( s ) :
    s = list ( s )
    for i in range ( len ( s ) ) :
        if ( s [ i ] == '0' ) :
            while ( s [ i ] == '0' ) :
                s [ i ] = '1'
                i += 1
            s = ' ' . join ( map ( str , s ) )
            return s
s = "100010001"
print ( flip ( s ) )

Index/key variables: i
Iterator variables: i
Python program:
def getOrgString ( s ) :
    print ( s [ 0 ] , end = " " )
    i = 1
    while ( i < len ( s ) ) :
        if ( ord ( s [ i ] ) >= ord ( ' A ' ) and ord ( s [ i ] ) <= ord ( ' Z ' ) ) :
            print ( " ▁ " , s [ i ] . lower ( ) , end = " " )
        else :
            print ( s [ i ] , end = " " )
        i += 1
s = " ILoveGeeksForGeeks "
getOrgString ( s )

Index/key variables: i
Python program:
def countFreq ( arr , n , limit ) :
    count = [ 0 for i in range ( limit + 1 ) ]
    for i in range ( n ) :
        count [ arr [ i ] ] += 1
    for i in range ( limit + 1 ) :
        if ( count [ i ] > 0 ) :
            print ( i , count [ i ] )
arr = [ 5 , 5 , 6 , 6 , 5 , 6 , 1 , 2 , 3 , 10 , 10 ]
n = len ( arr )
limit = 10
countFreq ( arr , n , limit )

Index/key variables: i
Iterator variables: i