dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def possibleStrings ( n , r , b , g ) :
    fact = [ 0 for i in range ( n + 1 ) ]
    fact [ 0 ] = 1
    for i in range ( 1 , n + 1 , 1 ) :
        fact [ i ] = fact [ i - 1 ] * i
    left = n - ( r + g + b )
    sum = 0
    for i in range ( 0 , left + 1 , 1 ) :
        for j in range ( 0 , left - i + 1 , 1 ) :
            k = left - ( i + j )
            sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )
    return sum
if __name__ == ' _ _ main _ _ ' :
    n = 4
    r = 2
    b = 0
    g = 1
    print ( int ( possibleStrings ( n , r , b , g ) ) )

Index/key variables: i, n
Iterator variables: i, j
Python program:
CHARS = 26
def remAnagram ( str1 , str2 ) :
    count1 = [ 0 ] * CHARS
    count2 = [ 0 ] * CHARS
    i = 0
    while i < len ( str1 ) :
        count1 [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1
        i += 1
    i = 0
    while i < len ( str2 ) :
        count2 [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] += 1
        i += 1
    result = 0
    for i in range ( 26 ) :
        result += abs ( count1 [ i ] - count2 [ i ] )
    return result
if __name__ == " _ _ main _ _ " :
    str1 = " bcadeh "
    str2 = " hea "
    print ( remAnagram ( str1 , str2 ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
CHARS = 26
def isValidString ( str ) :
    freq = [ 0 ] * CHARS
    for i in range ( len ( str ) ) :
        freq [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1
    freq1 = 0
    count_freq1 = 0
    for i in range ( CHARS ) :
        if ( freq [ i ] != 0 ) :
            freq1 = freq [ i ]
            count_freq1 = 1
            break
    freq2 = 0
    count_freq2 = 0
    for j in range ( i + 1 , CHARS ) :
        if ( freq [ j ] != 0 ) :
            if ( freq [ j ] == freq1 ) :
                count_freq1 += 1
            else :
                count_freq2 = 1
                freq2 = freq [ j ]
                break
    for k in range ( j + 1 , CHARS ) :
        if ( freq [ k ] != 0 ) :
            if ( freq [ k ] == freq1 ) :
                count_freq1 += 1
            if ( freq [ k ] == freq2 ) :
                count_freq2 += 1
            else :
                return False
        if ( count_freq1 > 1 and count_freq2 > 1 ) :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    str = " abcbc "
    if ( isValidString ( str ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i, j, k
Accumulator variables: count_freq1, count_freq2
Iterator variables: i, j, k
Python program:
def checkForVariation ( strr ) :
    if ( len ( strr ) == 0 ) :
        return True
    mapp = { }
    for i in range ( len ( strr ) ) :
        if strr [ i ] in mapp :
            mapp [ strr [ i ] ] += 1
        else :
            mapp [ strr [ i ] ] = 1
    first = True
    second = True
    val1 = 0
    val2 = 0
    countOfVal1 = 0
    countOfVal2 = 0
    for itr in mapp :
        i = itr
        if ( first ) :
            val1 = i
            first = False
            countOfVal1 += 1
            continue
        if ( i == val1 ) :
            countOfVal1 += 1
            continue
        if ( second ) :
            val2 = i
            countOfVal2 += 1
            second = False
            continue
        if ( i == val2 ) :
            countOfVal2 += 1
            continue
    if ( countOfVal1 > 1 and countOfVal2 > 1 ) :
        return False
    else :
        return True
print ( checkForVariation ( " abcbc " ) )

Index/key variables: i
Accumulator variables: countOfVal1, countOfVal2
Iterator variables: i, itr
Boolean variables: first, second
Python program:
def encodeString ( Str ) :
    map = { }
    res = " "
    i = 0
    for ch in Str :
        if ch not in map :
            map [ ch ] = i
            i += 1
        res += str ( map [ ch ] )
    return res
def findMatchedWords ( dict , pattern ) :
    Len = len ( pattern )
    hash = encodeString ( pattern )
    for word in dict :
        if ( len ( word ) == Len and encodeString ( word ) == hash ) :
            print ( word , end = " ▁ " )
dict = [ " abb " , " abc " , " xyz " , " xyy " ]
pattern = " foo "
findMatchedWords ( dict , pattern )

Index/key variables: ch
Accumulator variables: i, res
Iterator variables: ch, word
Python program:
def check ( pattern , word ) :
    if ( len ( pattern ) != len ( word ) ) :
        return False
    ch = [ 0 for i in range ( 128 ) ]
    Len = len ( word )
    for i in range ( Len ) :
        if ( ch [ ord ( pattern [ i ] ) ] == 0 ) :
            ch [ ord ( pattern [ i ] ) ] = word [ i ]
        elif ( ch [ ord ( pattern [ i ] ) ] != word [ i ] ) :
            return False
    return True
def findMatchedWords ( Dict , pattern ) :
    Len = len ( pattern )
    for word in range ( len ( Dict ) - 1 , - 1 , - 1 ) :
        if ( check ( pattern , Dict [ word ] ) ) :
            print ( Dict [ word ] , end = " ▁ " )
Dict = [ " abb " , " abc " , " xyz " , " xyy " ]
pattern = " foo "
findMatchedWords ( Dict , pattern )

Index/key variables: i, word
Iterator variables: i, word
Python program:
def printPath ( res , nThNode , kThNode ) :
    if kThNode > nThNode :
        return
    res . append ( kThNode )
    for i in range ( 0 , len ( res ) ) :
        print ( res [ i ] , end = " ▁ " )
    print ( )
    printPath ( res [ : ] , nThNode , kThNode * 2 )
    printPath ( res [ : ] , nThNode , kThNode * 2 + 1 )
def printPathToCoverAllNodeUtil ( nThNode ) :
    res = [ ]
    printPath ( res , nThNode , 1 )
if __name__ == " _ _ main _ _ " :
    nThNode = 7
    printPathToCoverAllNodeUtil ( nThNode )

Index/key variables: i
Iterator variables: i
Python program:
import math
def getMid ( s : int , e : int ) -> int :
    return s + ( e - s ) // 2
def isArmstrong ( x : int ) -> bool :
    n = len ( str ( x ) )
    sum1 = 0
    temp = x
    while ( temp > 0 ) :
        digit = temp % 10
        sum1 += pow ( digit , n )
        temp //= 10
    if ( sum1 == x ) :
        return True
    return False
def MaxUtil ( st , ss , se , l , r , node ) :
    if ( l <= ss and r >= se ) :
        return st [ node ]
    if ( se < l or ss > r ) :
        return - 1
    mid = getMid ( ss , se )
    return max ( MaxUtil ( st , ss , mid , l , r , 2 * node + 1 ) , MaxUtil ( st , mid + 1 , se , l , r , 2 * node + 2 ) )
def updateValue ( arr , st , ss , se , index , value , node ) :
    if ( index < ss or index > se ) :
        print ( " Invalid ▁ Input " )
        return
    if ( ss == se ) :
        arr [ index ] = value
        if ( isArmstrong ( value ) ) :
            st [ node ] = value
        else :
            st [ node ] = - 1
    else :
        mid = getMid ( ss , se )
        if ( index >= ss and index <= mid ) :
            updateValue ( arr , st , ss , mid , index , value , 2 * node + 1 )
        else :
            updateValue ( arr , st , mid + 1 , se , index , value , 2 * node + 2 )
        st [ node ] = max ( st [ 2 * node + 1 ] , st [ 2 * node + 2 ] )
    return
def getMax ( st , n , l , r ) :
    if ( l < 0 or r > n - 1 or l > r ) :
        print ( " Invalid ▁ Input " )
        return - 1
    return MaxUtil ( st , 0 , n - 1 , l , r , 0 )
def constructSTUtil ( arr , ss , se , st , si ) :
    if ( ss == se ) :
        if ( isArmstrong ( arr [ ss ] ) ) :
            st [ si ] = arr [ ss ]
        else :
            st [ si ] = - 1
        return st [ si ]
    mid = getMid ( ss , se )
    st [ si ] = max ( constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) , constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) )
    return st [ si ]
def constructST ( arr , n ) :
    x = int ( math . ceil ( math . log2 ( n ) ) )
    max_size = 2 * int ( math . pow ( 2 , x ) ) - 1
    st = [ 0 for _ in range ( max_size ) ]
    constructSTUtil ( arr , 0 , n - 1 , st , 0 )
    return st
if __name__ == " _ _ main _ _ " :
    arr = [ 192 , 113 , 535 , 7 , 19 , 111 ]
    n = len ( arr )
    st = constructST ( arr , n )
    print ( " Maximum ▁ armstrong ▁ number ▁ in ▁ given ▁ range ▁ = ▁ { } " . format ( getMax ( st , n , 1 , 3 ) ) )
    updateValue ( arr , st , 0 , n - 1 , 1 , 153 , 0 )
    print ( " Updated ▁ Maximum ▁ armstrong ▁ number ▁ in ▁ given ▁ range ▁ = ▁ { } " . format ( getMax ( st , n , 1 , 3 ) ) )

Index/key variables: index, node, si, ss
Accumulator variables: sum1, temp
Python program:
size = 1000001
def seiveOfEratosthenes ( prime ) :
    prime [ 0 ] = 1
    prime [ 1 ] = 0
    i = 2
    while ( i * i < 1000001 ) :
        if ( prime [ i ] == 0 ) :
            j = i * i
            while ( j < 1000001 ) :
                prime [ j ] = 1
                j = j + i
        i += 1
def probabiltyEuler ( prime , L , R , M ) :
    arr = [ 0 ] * size
    eulerTotient = [ 0 ] * size
    count = 0
    for i in range ( L , R + 1 ) :
        eulerTotient [ i - L ] = i
        arr [ i - L ] = i
    for i in range ( 2 , 1000001 ) :
        if ( prime [ i ] == 0 ) :
            for j in range ( ( L // i ) * i , R + 1 , i ) :
                if ( j - L >= 0 ) :
                    eulerTotient [ j - L ] = ( eulerTotient [ j - L ] // i * ( i - 1 ) )
                    while ( arr [ j - L ] % i == 0 ) :
                        arr [ j - L ] = arr [ j - L ] // i
    for i in range ( L , R + 1 ) :
        if ( arr [ i - L ] > 1 ) :
            eulerTotient [ i - L ] = ( ( eulerTotient [ i - L ] // arr [ i - L ] ) * ( arr [ i - L ] - 1 ) )
    for i in range ( L , R + 1 ) :
        if ( ( eulerTotient [ i - L ] % M ) == 0 ) :
            count += 1
    return ( float ) ( 1.0 * count / ( R + 1 - L ) )
prime = [ 0 ] * size
seiveOfEratosthenes ( prime )
L , R , M = 1 , 7 , 3
print ( probabiltyEuler ( prime , L , R , M ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
import math
def findWinner ( n , k ) :
    cnt = 0 ;
    if ( n == 1 ) :
        print ( " No " ) ;
    elif ( ( n & 1 ) or n == 2 ) :
        print ( " Yes " ) ;
    else :
        tmp = n ;
        val = 1 ;
        while ( tmp > k and tmp % 2 == 0 ) :
            tmp //= 2 ;
            val *= 2 ;
        for i in range ( 3 , int ( math . sqrt ( tmp ) ) + 1 ) :
            while ( tmp % i == 0 ) :
                cnt += 1 ;
                tmp //= i ;
        if ( tmp > 1 ) :
            cnt += 1 ;
        if ( val == n ) :
            print ( " No " ) ;
        elif ( n / tmp == 2 and cnt == 1 ) :
            print ( " No " ) ;
        else :
            print ( " Yes " ) ;
if __name__ == " _ _ main _ _ " :
    n = 1 ; k = 1 ;
    findWinner ( n , k ) ;

Accumulator variables: cnt, tmp, val
Iterator variables: i
Python program:
import math
def pen_hex ( n ) :
    pn = 1
    for i in range ( 1 , N ) :
        pn = ( int ) ( i * ( 3 * i - 1 ) / 2 )
        if ( pn > n ) :
            break
        seqNum = ( 1 + math . sqrt ( 8 * pn + 1 ) ) / 4
        if ( seqNum == ( int ) ( seqNum ) ) :
            print ( pn , end = " , ▁ " )
N = 1000000
pen_hex ( N )

Iterator variables: i
Python program:
def isPal ( a , n , m ) :
    for i in range ( 0 , n // 2 ) :
        for j in range ( 0 , m - 1 ) :
            if ( a [ i ] [ j ] != a [ n - 1 - i ] [ m - 1 - j ] ) :
                return False ;
    return True ;
if __name__ == ' _ _ main _ _ ' :
    n = 3 ;
    m = 3 ;
    a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 4 ] , [ 3 , 2 , 1 ] ] ;
    if ( isPal ( a , n , m ) ) :
        print ( " YES " ) ;
    else :
        print ( " NO " ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def getSum ( n ) :
    sum1 = 0 ;
    while ( n != 0 ) :
        sum1 = sum1 + n % 10 ;
        n = n // 10 ;
    return sum1 ;
def smallestNumber ( N ) :
    i = 1 ;
    while ( 1 ) :
        if ( getSum ( i ) == N ) :
            print ( i ) ;
            break ;
        i += 1 ;
N = 10 ;
smallestNumber ( N ) ;

Accumulator variables: i
Python program:
def calc_ans ( l , r ) :
    power2 = [ ] ; power3 = [ ] ;
    mul2 = 1 ;
    while ( mul2 <= r ) :
        power2 . append ( mul2 ) ;
        mul2 *= 2 ;
    mul3 = 1 ;
    while ( mul3 <= r ) :
        power3 . append ( mul3 ) ;
        mul3 *= 3 ;
    power23 = [ ] ;
    for x in range ( len ( power2 ) ) :
        for y in range ( len ( power3 ) ) :
            mul = power2 [ x ] * power3 [ y ] ;
            if ( mul == 1 ) :
                continue ;
            if ( mul <= r ) :
                power23 . append ( mul ) ;
    ans = 0 ;
    for x in power23 :
        if ( x >= l and x <= r ) :
            ans += 1 ;
    print ( ans ) ;
if __name__ == " _ _ main _ _ " :
    l = 1 ; r = 10 ;
    calc_ans ( l , r ) ;

Index/key variables: x, y
Accumulator variables: ans, mul2, mul3, power2, power23, power3
Iterator variables: x, y
Python program:
def nCr ( n , r ) :
    if ( r > n ) :
        return 0
    return fact ( n ) // ( fact ( r ) * fact ( n - r ) )
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
def countSubsequences ( arr , n , k ) :
    countOdd = 0
    for i in range ( n ) :
        if ( arr [ i ] & 1 ) :
            countOdd += 1 ;
    ans = nCr ( n , k ) - nCr ( countOdd , k ) ;
    return ans
arr = [ 2 , 4 ]
K = 1
N = len ( arr )
print ( countSubsequences ( arr , N , K ) )

Index/key variables: i
Accumulator variables: countOdd
Iterator variables: i
Python program:
def modifiedBinaryPattern ( n ) :
    for i in range ( 1 , n + 1 , 1 ) :
        for j in range ( 1 , i + 1 , 1 ) :
            if ( j == 1 or j == i ) :
                print ( 1 , end = " " )
            else :
                print ( 0 , end = " " )
        print ( ' ' , end = " " )
if __name__ == ' _ _ main _ _ ' :
    n = 7
    modifiedBinaryPattern ( n )

Iterator variables: i, j
Python program:
from math import pow
def highestPower ( n , k ) :
    i = 0
    a = pow ( n , i )
    while ( a <= k ) :
        i += 1
        a = pow ( n , i )
    return i - 1
b = [ 0 for i in range ( 50 ) ]
def PowerArray ( n , k ) :
    while ( k ) :
        t = highestPower ( n , k )
        if ( b [ t ] ) :
            print ( - 1 )
            return 0
        else :
            b [ t ] = 1
        k -= pow ( n , t )
    for i in range ( 50 ) :
        if ( b [ i ] ) :
            print ( i , end = ' , ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    K = 40
    PowerArray ( N , K )

Index/key variables: i, t
Accumulator variables: k
Iterator variables: i
Python program:
N = 100005
def SieveOfEratosthenes ( composite ) :
    for p in range ( 2 , N ) :
        if p * p > N :
            break
        if ( composite [ p ] == False ) :
            for i in range ( 2 * p , N , p ) :
                composite [ i ] = True
def sumOfElements ( arr , n ) :
    composite = [ False ] * N
    SieveOfEratosthenes ( composite )
    m = dict ( ) ;
    for i in range ( n ) :
        m [ arr [ i ] ] = m . get ( arr [ i ] , 0 ) + 1
    sum = 0
    for it in m :
        if ( composite [ m [ it ] ] ) :
            sum += ( it )
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 1 , 1 , 3 , 3 , 2 , 4 ]
    n = len ( arr )
    print ( sumOfElements ( arr , n ) )

Index/key variables: i, it, p
Accumulator variables: sum
Iterator variables: i, it, p
Python program:
def remove ( arr , n ) :
    m = dict . fromkeys ( arr , 0 ) ;
    for i in range ( n ) :
        m [ arr [ i ] ] += 1 ;
    for i in range ( n ) :
        if ( ( m [ arr [ i ] ] & 1 ) ) :
            continue ;
        print ( arr [ i ] , end = " , ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 3 , 3 , 2 , 2 , 4 , 7 , 7 ] ;
    n = len ( arr ) ;
    remove ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def getmax ( arr , n , x ) :
    s = 0
    for i in range ( n ) :
        s = s + arr [ i ]
    print ( min ( s , x ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ]
    x = 5
    arr_size = len ( arr )
    getmax ( arr , arr_size , x )

Index/key variables: i
Iterator variables: i
Python program:
def shortestLength ( n , x , y ) :
    answer = 0
    i = 0
    while n > 0 :
        if ( x [ i ] + y [ i ] > answer ) :
            answer = x [ i ] + y [ i ]
        i += 1
        n -= 1
    print ( " Length ▁ - > ▁ " + str ( answer ) )
    print ( " Path ▁ - > ▁ " + " ( ▁ 1 , ▁ " + str ( answer ) + " ▁ ) " + " and ▁ ( ▁ " + str ( answer ) + " , ▁ 1 ▁ ) " )
if __name__ == " _ _ main _ _ " :
    n = 4
    x = [ 1 , 4 , 2 , 1 ]
    y = [ 4 , 1 , 1 , 2 ]
    shortestLength ( n , x , y )

Index/key variables: i
Accumulator variables: n
Python program:
import math
class Point :
    def __init__ ( self , a = 0 , b = 0 ) :
        self . x = a
        self . y = b
def printCorners ( p , q , l ) :
    a , b , c , d = Point ( ) , Point ( ) , Point ( ) , Point ( )
    if ( p . x == q . x ) :
        a . x = p . x - ( l / 2.0 )
        a . y = p . y
        d . x = p . x + ( l / 2.0 )
        d . y = p . y
        b . x = q . x - ( l / 2.0 )
        b . y = q . y
        c . x = q . x + ( l / 2.0 )
        c . y = q . y
    elif ( p . y == q . y ) :
        a . y = p . y - ( l / 2.0 )
        a . x = p . x
        d . y = p . y + ( l / 2.0 )
        d . x = p . x
        b . y = q . y - ( l / 2.0 )
        b . x = q . x
        c . y = q . y + ( l / 2.0 )
        c . x = q . x
    else :
        m = ( p . x - q . x ) / ( q . y - p . y )
        dx = ( l / math . sqrt ( 1 + ( m * m ) ) ) * 0.5
        dy = m * dx
        a . x = p . x - dx
        a . y = p . y - dy
        d . x = p . x + dx
        d . y = p . y + dy
        b . x = q . x - dx
        b . y = q . y - dy
        c . x = q . x + dx
        c . y = q . y + dy
    print ( int ( a . x ) , " , ▁ " , int ( a . y ) , sep = " " )
    print ( int ( b . x ) , " , ▁ " , int ( b . y ) , sep = " " )
    print ( int ( c . x ) , " , ▁ " , int ( c . y ) , sep = " " )
    print ( int ( d . x ) , " , ▁ " , int ( d . y ) , sep = " " )
    print ( )
p1 = Point ( 1 , 0 )
q1 = Point ( 1 , 2 )
printCorners ( p1 , q1 , 2 )
p = Point ( 1 , 1 )
q = Point ( - 1 , - 1 )
printCorners ( p , q , 2 * math . sqrt ( 2 ) )

Class/struct names: Point
Python program:
def minimumCost ( arr , N , X , Y ) :
    even_count = 0
    odd_count = 0
    for i in range ( 0 , N ) :
        if ( ( arr [ i ] & 1 ) and ( i % 2 == 0 ) ) :
            odd_count += 1
        if ( ( arr [ i ] % 2 ) == 0 and ( i & 1 ) ) :
            even_count += 1
    cost1 = X * min ( odd_count , even_count )
    cost2 = Y * ( max ( odd_count , even_count ) - min ( odd_count , even_count ) )
    cost3 = ( odd_count + even_count ) * Y
    return min ( cost1 + cost2 , cost3 )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 3 , 7 , 2 , 1 ]
    X = 10
    Y = 2
    N = len ( arr )
    print ( minimumCost ( arr , N , X , Y ) )

Index/key variables: i
Accumulator variables: even_count, odd_count
Iterator variables: i
Python program:
def findMinMax ( a ) :
    min_val = 1000000000
    for i in range ( 1 , len ( a ) ) :
        min_val = min ( min_val , a [ i ] * a [ i - 1 ] )
    return min_val
if __name__ == ( " _ _ main _ _ " ) :
    arr = [ 6 , 4 , 5 , 6 , 2 , 4 , 1 ]
    print ( findMinMax ( arr ) )

Index/key variables: i
Iterator variables: i
Python program:
sum = 0
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def kDistanceDownSum ( root , k ) :
    global sum
    if ( root == None or k < 0 ) :
        return
    if ( k == 0 ) :
        sum += root . data
        return
    kDistanceDownSum ( root . left , k - 1 )
    kDistanceDownSum ( root . right , k - 1 )
def kDistanceSum ( root , target , k ) :
    global sum
    if ( root == None ) :
        return - 1
    if ( root . data == target ) :
        kDistanceDownSum ( root . left , k - 1 )
        return 0
    dl = - 1
    if ( target < root . data ) :
        dl = kDistanceSum ( root . left , target , k )
    if ( dl != - 1 ) :
        if ( dl + 1 == k ) :
            sum += root . data
        return - 1
    dr = - 1
    if ( target > root . data ) :
        dr = kDistanceSum ( root . right , target , k )
    if ( dr != - 1 ) :
        if ( dr + 1 == k ) :
            sum += root . data
        else :
            kDistanceDownSum ( root . left , k - dr - 2 )
        return 1 + dr
    return - 1
def insertNode ( data , root ) :
    if ( root == None ) :
        node = Node ( data )
        return node
    elif ( data > root . data ) :
        root . right = insertNode ( data , root . right )
    elif ( data <= root . data ) :
        root . left = insertNode ( data , root . left )
    return root
def findSum ( root , target , K ) :
    kDistanceSum ( root , target , K )
    print ( sum )
if __name__ == ' _ _ main _ _ ' :
    root = None
    N = 11
    tree = [ 3 , 1 , 7 , 0 , 2 , 5 , 10 , 4 , 6 , 9 , 8 ]
    for i in range ( N ) :
        root = insertNode ( tree [ i ] , root )
    target = 7
    K = 2
    findSum ( root , target , K )

Index/key variables: i
Iterator variables: i
Class/struct names: Node
Python program:
def itemType ( n ) :
    count = 0
    day = 1
    while ( True ) :
        for type in range ( day , 0 , - 1 ) :
            count += type
            if ( count >= n ) :
                return type
N = 10
print ( itemType ( N ) )

Accumulator variables: count
Iterator variables: type
Python program:
from math import log2
def FindSum ( arr , N ) :
    res = 0
    for i in range ( N ) :
        power = int ( log2 ( arr [ i ] ) )
        LesserValue = pow ( 2 , power )
        LargerValue = pow ( 2 , power + 1 )
        if ( ( arr [ i ] - LesserValue ) == ( LargerValue - arr [ i ] ) ) :
            res += arr [ i ]
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 24 , 17 , 3 , 8 ]
    N = len ( arr )
    print ( FindSum ( arr , N ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def findLast ( mat ) :
    m = len ( mat )
    n = len ( mat [ 0 ] )
    rows = set ( )
    cols = set ( )
    for i in range ( m ) :
        for j in range ( n ) :
            if mat [ i ] [ j ] :
                rows . add ( i )
                cols . add ( j )
    avRows = m - len ( list ( rows ) )
    avCols = n - len ( list ( cols ) )
    choices = min ( avRows , avCols )
    if choices & 1 :
        print ( ' P1' )
    else :
        print ( ' P2' )
mat = [ [ 1 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 1 ] ]
findLast ( mat )

Index/key variables: i, j
Accumulator variables: cols, rows
Iterator variables: i, j
Python program:
from math import log2 , pow
MOD = 1000000007
def sumOfBinaryNumbers ( n ) :
    ans = 0
    one = 1
    while ( 1 ) :
        if ( n <= 1 ) :
            ans = ( ans + n ) % MOD
            break
        x = int ( log2 ( n ) )
        cur = 0
        add = ( one << ( x - 1 ) )
        for i in range ( 1 , x + 1 , 1 ) :
            cur = ( cur + add ) % MOD
            add = ( add * 10 % MOD )
        ans = ( ans + cur ) % MOD
        rem = n - ( one << x ) + 1
        p = pow ( 10 , x )
        p = ( p * ( rem % MOD ) ) % MOD
        ans = ( ans + p ) % MOD
        n = rem - 1
    print ( int ( ans ) )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    sumOfBinaryNumbers ( N )

Iterator variables: i
Python program:
import sys
def checkPermutation ( ans , a , n ) :
    Max = - sys . maxsize - 1
    for i in range ( n ) :
        Max = max ( Max , ans [ i ] )
        if ( Max != a [ i ] ) :
            return False
    return True
def findPermutation ( a , n ) :
    ans = [ 0 ] * n
    um = { }
    for i in range ( n ) :
        if ( a [ i ] not in um ) :
            ans [ i ] = a [ i ]
            um [ a [ i ] ] = i
    v = [ ]
    j = 0
    for i in range ( 1 , n + 1 ) :
        if ( i not in um ) :
            v . append ( i )
    for i in range ( n ) :
        if ( ans [ i ] == 0 ) :
            ans [ i ] = v [ j ]
            j += 1
    if ( checkPermutation ( ans , a , n ) ) :
        for i in range ( n ) :
            print ( ans [ i ] , end = " ▁ " )
    else :
        print ( " - 1" )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 4 , 5 , 5 ]
    N = len ( arr )
    findPermutation ( arr , N )

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