dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
MAX = 100001
phi = [ 0 ] * MAX
result = [ 0 ] * MAX
def computeTotient ( ) :
    phi [ 1 ] = 1
    for i in range ( 2 , MAX ) :
        if not phi [ i ] :
            phi [ i ] = i - 1
            for j in range ( i << 1 , MAX , i ) :
                if not phi [ j ] :
                    phi [ j ] = j
                phi [ j ] = ( ( phi [ j ] // i ) * ( i - 1 ) )
def sumOfGcdPairs ( ) :
    computeTotient ( )
    for i in range ( MAX ) :
        for j in range ( 2 , MAX ) :
            if i * j >= MAX :
                break
            result [ i * j ] += i * phi [ j ]
    for i in range ( 2 , MAX ) :
        result [ i ] += result [ i - 1 ]
sumOfGcdPairs ( )
N = 4
print ( " Summation ▁ of " , N , " = " , result [ N ] )
N = 12
print ( " Summation ▁ of " , N , " = " , result [ N ] )
N = 5000
print ( " Summation ▁ of " , N , " = " , result [ N ] )

Index/key variables: N, i, j
Iterator variables: i, j
Python program:
N = 3
def solve ( v ) :
    res = [ ]
    all3 = v [ 0 ] + v [ 1 ] + v [ 2 ]
    res . append ( all3 - v [ 1 ] * 2 )
    res . append ( all3 - v [ 2 ] * 2 )
    res . append ( all3 - v [ 0 ] * 2 )
    return res
def findVertex ( xmid , ymid ) :
    V1 = solve ( xmid )
    V2 = solve ( ymid )
    for i in range ( 0 , 3 ) :
        print ( V1 [ i ] , end = " ▁ " )
        print ( V2 [ i ] )
if __name__ == ' _ _ main _ _ ' :
    xmid = [ 5 , 4 , 5 ]
    ymid = [ 3 , 4 , 5 ]
    findVertex ( xmid , ymid )

Index/key variables: i
Iterator variables: i
Python program:
def nthElement ( a , b , n ) :
    seq = [ ] ;
    for i in range ( 1 , n + 1 ) :
        seq . append ( a * i ) ;
    seq . sort ( ) ;
    i = 1 ;
    k = n ;
    while ( i <= n and k > 0 ) :
        try :
            z = seq . index ( b * i ) ;
        except ValueError :
            seq . append ( b * i ) ;
            seq . sort ( ) ;
            k -= 1 ;
        i += 1 ;
    return seq [ n - 1 ] ;
a = 3 ;
b = 5 ;
n = 5 ;
print ( nthElement ( a , b , n ) ) ;

Accumulator variables: k, seq
Iterator variables: i
Python program:
def gcd ( a , b ) :
    return gcd ( b , a % b ) if b > 0 else a
def countGCD ( L , R , g ) :
    L = ( L + g - 1 ) // g
    R = R // g
    ans = 0
    for i in range ( L , R + 1 ) :
        for j in range ( L , R + 1 ) :
            if ( gcd ( i , j ) == 1 ) :
                ans = ans + 1
    return ans
L = 1
R = 11
g = 5
print ( countGCD ( L , R , g ) )

Iterator variables: i, j
Python program:
dig = [ 1 , 1 , 2 , 6 , 4 , 2 , 2 , 4 , 2 , 8 ]
def lastNon0Digit ( n ) :
    if ( n < 10 ) :
        return dig [ n ]
    if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :
        return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10
    else :
        return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10
    return 0
n = 14
print ( lastNon0Digit ( n ) )

Index/key variables: n
Python program:
def gcd ( a , b ) :
    if ( ( a % b ) == 0 ) :
        return b
    return gcd ( b , a % b )
def firstFactorialDivisibleNumber ( x ) :
    new_x = x
    for i in range ( 1 , x ) :
        new_x /= gcd ( i , new_x )
        if ( new_x == 1 ) :
            break
    return i
def main ( ) :
    x = 16
    print ( firstFactorialDivisibleNumber ( x ) )
if __name__ == ' _ _ main _ _ ' :
    main ( )

Accumulator variables: new_x
Iterator variables: i
Python program:
arr = [ True ] * ( 1001 )
def simpleSieve ( ) :
    k = 0
    for p in range ( 2 , 1001 ) :
        if ( p * p > 1001 ) :
            break
        if ( arr [ p ] ) :
            for k in range ( p , 1001 , k + p ) :
                arr [ k ] = False
def find_sphene ( N ) :
    arr1 = [ 0 ] * ( 8 )
    count = 0
    j = 0
    for i in range ( 1 , N + 1 ) :
        if ( N % i == 0 and count < 8 ) :
            count += 1
            arr1 [ j ] = i
            j += 1
    if ( count == 8 and ( arr [ arr1 [ 1 ] ] and arr [ arr1 [ 2 ] ] and arr [ arr1 [ 3 ] ] ) ) :
        return 1 ;
    return 0 ;
if __name__ == ' _ _ main _ _ ' :
    n = 60
    simpleSieve ( )
    ans = find_sphene ( n )
    if ( ans == 1 ) :
        print ( " Yes " )
    else :
        print ( " NO " )

Index/key variables: j, k, p
Accumulator variables: count
Iterator variables: i, k, p
Python program:
from math import sqrt
def gcd ( a , b ) :
    if a == 0 :
        return b
    return gcd ( b % a , a )
def commDiv ( a , b ) :
    n = gcd ( a , b )
    result = 0
    for i in range ( 1 , int ( sqrt ( n ) ) + 1 ) :
        if n % i == 0 :
            if n / i == i :
                result += 1
            else :
                result += 2
    return result
if __name__ == " _ _ main _ _ " :
    a = 12
    b = 24 ;
    print ( commDiv ( a , b ) )

Accumulator variables: result
Iterator variables: i
Python program:
def spellsCount ( num ) :
    n = len ( num ) ;
    result = 1 ;
    i = 0 ;
    while ( i < n ) :
        count = 1 ;
        while ( i < n - 1 and num [ i + 1 ] == num [ i ] ) :
            count += 1 ;
            i += 1 ;
        result = result * int ( pow ( 2 , count - 1 ) ) ;
        i += 1 ;
    return result ;
num = "11112" ;
print ( spellsCount ( num ) ) ;

Index/key variables: i
Accumulator variables: count
Python program:
def numSquareSum ( n ) :
    squareSum = 0 ;
    while ( n ) :
        squareSum += ( n % 10 ) * ( n % 10 ) ;
        n = int ( n / 10 ) ;
    return squareSum ;
def isHappynumber ( n ) :
    slow = n ;
    fast = n ;
    while ( True ) :
        slow = numSquareSum ( slow ) ;
        fast = numSquareSum ( numSquareSum ( fast ) ) ;
        if ( slow != fast ) :
            continue ;
        else :
            break ;
    return ( slow == 1 ) ;
n = 13 ;
if ( isHappynumber ( n ) ) :
    print ( n , " is ▁ a ▁ Happy ▁ number " ) ;
else :
    print ( n , " is ▁ not ▁ a ▁ Happy ▁ number " ) ;

Accumulator variables: squareSum
Python program:
allPrimes = [ ] ;
def sieve ( n ) :
    prime = [ True ] * ( n + 1 ) ;
    p = 2 ;
    while ( p * p <= n ) :
        if ( prime [ p ] == True ) :
            i = p * 2 ;
            while ( i <= n ) :
                prime [ i ] = False ;
                i += p ;
        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 = result * ( exp + 1 ) ;
    return result ;
print ( factorialDivisors ( 6 ) ) ;

Index/key variables: i, p
Accumulator variables: allPrimes
Iterator variables: i, p
Python program:
one = [ " " , " one ▁ " , " two ▁ " , " three ▁ " , " four ▁ " , " five ▁ " , " six ▁ " , " seven ▁ " , " eight ▁ " , " nine ▁ " , " ten ▁ " , " eleven ▁ " , " twelve ▁ " , " thirteen ▁ " , " fourteen ▁ " , " fifteen ▁ " , " sixteen ▁ " , " seventeen ▁ " , " eighteen ▁ " , " nineteen ▁ " ] ;
ten = [ " " , " " , " twenty ▁ " , " thirty ▁ " , " forty ▁ " , " fifty ▁ " , " sixty ▁ " , " seventy ▁ " , " eighty ▁ " , " ninety ▁ " ] ;
def numToWords ( n , s ) :
    str = " " ;
    if ( n > 19 ) :
        str += ten [ n // 10 ] + one [ n % 10 ] ;
    else :
        str += one [ n ] ;
    if ( n ) :
        str += s ;
    return str ;
def convertToWords ( n ) :
    out = " " ;
    out += numToWords ( ( n // 10000000 ) , " crore ▁ " ) ;
    out += numToWords ( ( ( n // 100000 ) % 100 ) , " lakh ▁ " ) ;
    out += numToWords ( ( ( n // 1000 ) % 100 ) , " thousand ▁ " ) ;
    out += numToWords ( ( ( n // 100 ) % 10 ) , " hundred ▁ " ) ;
    if ( n > 100 and n % 100 ) :
        out += " and ▁ " ;
    out += numToWords ( ( n % 100 ) , " " ) ;
    return out ;
n = 438237764 ;
print ( convertToWords ( n ) ) ;

Index/key variables: n
Python program:
def countEvenSum ( arr , n ) :
    res = 0
    s = 0
    for i in reversed ( range ( n ) ) :
        if arr [ i ] % 2 == 1 :
            s = n - i - 1 - s
        else :
            s = s + 1
        res = res + s
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 2 , 3 , 4 , 1 ]
    n = len ( arr )
    print ( " The ▁ Number ▁ of ▁ Subarrays ▁ with ▁ even " " ▁ sum ▁ is " , countEvenSum ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def power ( x , y , p ) :
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p ;
        x = ( x * x ) % p ;
    return res
def modInverse ( a , p ) :
    return power ( a , p - 2 , p )
def modFact ( n , p ) :
    if ( p <= n ) :
        return 0
    res = ( p - 1 )
    for i in range ( n + 1 , p ) :
        res = ( res * modInverse ( i , p ) ) % p
    return res
n = 25
p = 29
print ( modFact ( n , p ) )

Iterator variables: i
Python program:
def countWays ( n ) :
    for i in range ( 1 , n ) :
        for j in range ( i , n ) :
            for k in range ( j , n ) :
                for l in range ( k , n ) :
                    if ( i + j + k + l == n ) :
                        counter += 1
    return counter
if __name__ == " _ _ main _ _ " :
    n = 8
    print ( countWays ( n ) )

Accumulator variables: counter
Iterator variables: i, j, k, l
Python program:
def pairAndSum ( arr , n ) :
    for i in range ( 0 , n ) :
        for j in range ( ( i + 1 ) , n ) :
            ans = ans + arr [ i ] & arr [ j ]
    return ans
arr = [ 5 , 10 , 15 ]
n = len ( arr )
print ( pairAndSum ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def pairAndSum ( arr , n ) :
    for i in range ( 0 , 32 ) :
        k = 0
        for j in range ( 0 , n ) :
            if ( ( arr [ j ] & ( 1 << i ) ) ) :
                k = k + 1
        ans = ans + ( 1 << i ) * ( k * ( k - 1 ) // 2 )
    return ans
arr = [ 5 , 10 , 15 ]
n = len ( arr )
print ( pairAndSum ( arr , n ) )

Index/key variables: j
Iterator variables: i, j
Python program:
def isPrime ( n ) :
    if n <= 1 :
        return False
    for i in range ( 2 , n ) :
        if n % i == 0 :
            return False ;
    return True
print ( " true " ) if isPrime ( 11 ) else print ( " false " )
print ( " true " ) if isPrime ( 14 ) else print ( " false " )

Iterator variables: i
Python program:
import math
def Euler_totient_function ( n ) :
    result = 1
    for i in range ( 2 , n + 1 ) :
        c = 0
        if n % i == 0 :
            while ( n % i == 0 ) :
                c += 1
                n //= i
        if ( c > 0 ) :
            power = math . pow ( i , c - 1 )
            m = math . pow ( i , c - 1 ) * ( i - 1 )
            result *= m
    if ( n > 1 ) :
        result *= ( n - 1 )
    return int ( result )
for i in range ( 1 , 13 ) :
    print ( " Euler _ totient _ function ( " , i , " ) : ▁ " , end = " " )
    print ( Euler_totient_function ( i ) )

Accumulator variables: c, n, result
Iterator variables: i
Python program:
import math
def isPower ( n ) :
    p = 0
    if ( n <= 1 ) :
        return 1
    for i in range ( 2 , ( int ) ( math . sqrt ( n ) ) + 1 ) :
        p = math . log2 ( n ) / math . log2 ( i )
        if ( ( math . ceil ( p ) == math . floor ( p ) ) and p > 1 ) :
            return 1
    return 0
for i in range ( 2 , 100 ) :
    if isPower ( i ) :
        print ( i , end = " ▁ " )

Iterator variables: i
Python program:
def sumBetweenTwoKth ( arr , n , k1 , k2 ) :
    arr . sort ( )
    result = 0
    for i in range ( k1 , k2 - 1 ) :
        result += arr [ i ]
    return result
arr = [ 20 , 8 , 22 , 4 , 12 , 10 , 14 ]
k1 = 3 ; k2 = 6
n = len ( arr )
print ( sumBetweenTwoKth ( arr , n , k1 , k2 ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def nthMagicNo ( n ) :
    pow = 1
    answer = 0
    while ( n ) :
        pow = pow * 5
        if ( n & 1 ) :
            answer += pow
    return answer
n = 5
print ( " nth ▁ magic ▁ number ▁ is " , nthMagicNo ( n ) )

Accumulator variables: answer
Python program:
def XorSum ( A , B , N , M ) :
    ans1 = 0
    ans2 = 0
    for i in range ( N ) :
        ans1 = ans1 ^ A [ i ]
    for i in range ( M ) :
        ans2 = ans2 ^ B [ i ]
    return ( ans1 & ans2 )
if __name__ == ' _ _ main _ _ ' :
    A = [ 3 , 5 ]
    B = [ 2 , 3 ]
    N = len ( A )
    M = len ( B )
    print ( XorSum ( A , B , N , M ) )

Index/key variables: i
Iterator variables: i
Python program:
class TreeNode :
    def __init__ ( self , val = 0 , left = None , right = None ) :
        self . val = val
        self . left = left
        self . right = right
def uniqueLevels ( root ) :
    uniqueLevels = 0
    que = [ root ]
    while len ( que ) :
        length = len ( que )
        prefix_XOR = 0 ;
        prefix_OR = 0
        flag = True
        while length :
            temp = que . pop ( 0 )
            prefix_OR |= temp . val
            prefix_XOR ^= temp . val
            if prefix_XOR != prefix_OR :
                flag = False
            if temp . left :
                que . append ( temp . left )
            if temp . right :
                que . append ( temp . right )
            length -= 1
        if flag :
            uniqueLevels += 1
    print ( uniqueLevels )
if __name__ == ' _ _ main _ _ ' :
    root = TreeNode ( 5 )
    root . left = TreeNode ( 6 )
    root . right = TreeNode ( 9 )
    root . left . left = TreeNode ( 1 )
    root . left . right = TreeNode ( 4 )
    root . right . right = TreeNode ( 7 )
    uniqueLevels ( root )

Accumulator variables: length, prefix_OR, prefix_XOR, que, uniqueLevels
Boolean variables: flag
Class/struct names: TreeNode
Python program:
n = 7
def minheapify ( a , index ) :
    small = index
    l = 2 * index + 1
    r = 2 * index + 2
    if ( l < n and a [ l ] < a [ small ] ) :
        small = l
    if ( r < n and a [ r ] < a [ small ] ) :
        small = r
    if ( small != index ) :
        ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )
        minheapify ( a , small )
i = 0
k1 = 3
k2 = 6
a = [ 20 , 8 , 22 , 4 , 12 , 10 , 14 ]
ans = 0
for i in range ( ( n // 2 ) - 1 , - 1 , - 1 ) :
    minheapify ( a , i )
k1 -= 1
k2 -= 1
for i in range ( 0 , k1 + 1 ) :
    a [ 0 ] = a [ n - 1 ]
    n -= 1
    minheapify ( a , 0 )
for i in range ( k1 + 1 , k2 ) :
    ans += a [ 0 ]
    a [ 0 ] = a [ n - 1 ]
    n -= 1
    minheapify ( a , 0 )
print ( ans )

Index/key variables: index, l, r, small
Accumulator variables: ans, n
Iterator variables: i
Python program:
def ConstructList ( Q ) :
    xor = 0
    ans = [ ]
    for i in range ( len ( Q ) - 1 , - 1 , - 1 ) :
        if ( Q [ i ] [ 0 ] == 0 ) :
            ans . append ( Q [ i ] [ 1 ] ^ xor )
        else :
            xor ^= Q [ i ] [ 1 ]
    ans . append ( xor )
    ans . sort ( )
    return ans
Q = [ [ 0 , 6 ] , [ 0 , 3 ] , [ 0 , 2 ] , [ 1 , 4 ] , [ 1 , 5 ] ]
print ( ConstructList ( Q ) )

Index/key variables: i
Accumulator variables: ans, xor
Iterator variables: i
Python program:
def build_num ( bit ) :
    ans = 0 ;
    for i in range ( 32 ) :
        if ( bit [ i ] > 0 ) :
            ans += ( 1 << i ) ;
    return ans ;
def maximumOR ( arr , n , k ) :
    bit = [ 0 ] * 32 ;
    for i in range ( k ) :
        for j in range ( 32 ) :
            if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) :
                bit [ j ] += 1 ;
    max_or = build_num ( bit ) ;
    for i in range ( k , n ) :
        for j in range ( 32 ) :
            if ( ( arr [ i - k ] & ( 1 << j ) ) > 0 ) :
                bit [ j ] -= 1 ;
        for j in range ( 32 ) :
            if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) :
                bit [ j ] += 1 ;
        max_or = max ( build_num ( bit ) , max_or ) ;
    return max_or ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , 3 , 6 , 11 , 13 ] ;
    k = 3 ;
    n = len ( arr ) ;
    print ( maximumOR ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def Solve ( root , xr , max_xor ) :
    xr = xr ^ root . data
    if ( root . left == None and root . right == None ) :
        max_xor [ 0 ] = max ( max_xor [ 0 ] , xr )
    if root . left != None :
        Solve ( root . left , xr , max_xor )
    if root . right != None :
        Solve ( root . right , xr , max_xor )
    return
def findMaxXor ( root ) :
    xr , max_xor = 0 , [ 0 ]
    Solve ( root , xr , max_xor )
    return max_xor [ 0 ]
root = Node ( 2 )
root . left = Node ( 1 )
root . right = Node ( 4 )
root . left . left = Node ( 10 )
root . left . right = Node ( 8 )
root . right . left = Node ( 5 )
root . right . right = Node ( 10 )
print ( findMaxXor ( root ) )

Class/struct names: Node
Python program:
def constructXORArray ( A , n , K ) :
    B = [ 0 ] * n ;
    for i in range ( n ) :
        B [ i ] = A [ i ] ^ K ;
    for i in range ( n ) :
        print ( B [ i ] , end = " ▁ " ) ;
    print ( ) ;
if __name__ == ' _ _ main _ _ ' :
    A = [ 2 , 4 , 1 , 3 , 5 ] ;
    K = 5 ;
    n = len ( A ) ;
    constructXORArray ( A , n , K ) ;
    B = [ 4 , 75 , 45 , 42 ] ;
    K = 2 ;
    n = len ( B ) ;
    constructXORArray ( B , n , K ) ;

Index/key variables: i
Iterator variables: i
Python program:
def find_and ( arr ) :
    ans = arr [ 0 ]
    for i in range ( 1 , len ( arr ) ) :
        ans = ans & arr [ i ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 5 , 9 , 11 ]
    print ( find_and ( arr ) )

Index/key variables: i
Iterator variables: i
Python program:
from math import ceil , log
maxsize = 100005
xor_tree = [ 0 ] * maxsize
def construct_Xor_Tree_Util ( current , start , end , x ) :
    if ( start == end ) :
        xor_tree [ x ] = current [ start ]
        return
    left = x * 2 + 1
    right = x * 2 + 2
    mid = start + ( end - start ) // 2
    construct_Xor_Tree_Util ( current , start , mid , left )
    construct_Xor_Tree_Util ( current , mid + 1 , end , right )
    xor_tree [ x ] = ( xor_tree [ left ] ^ xor_tree [ right ] )
def construct_Xor_Tree ( arr , n ) :
    construct_Xor_Tree_Util ( arr , 0 , n - 1 , 0 )
if __name__ == ' _ _ main _ _ ' :
    leaf_nodes = [ 40 , 32 , 12 , 1 , 4 , 3 , 2 , 7 ]
    n = len ( leaf_nodes )
    construct_Xor_Tree ( leaf_nodes , n )
    x = ( ceil ( log ( n , 2 ) ) )
    max_size = 2 * pow ( 2 , x ) - 1
    print ( " Nodes ▁ of ▁ the ▁ XOR ▁ Tree : " )
    for i in range ( max_size ) :
        print ( xor_tree [ i ] , end = " ▁ " )
    root = 0
    print ( " Root :   " , xor_tree [ root ] )

Index/key variables: i, left, right, root, start, x
Iterator variables: i
Python program:
def check ( arr , n , m , d ) :
    i = 0
    while ( i < n and m > 0 ) :
        m -= 1
        i += d
    if m == 0 :
        return True
    return False
def maximumDistance ( arr , n , m ) :
    low = 1
    high = n - 1
    ans = 0
    while ( low <= high ) :
        mid = ( low + high ) // 2
        flag = check ( arr , n , m , mid )
        if ( flag ) :
            ans = mid
            low = mid + 1
        else :
            high = mid - 1
    return ans
n = 5
m = 3
arr = [ 0 ] * n
print ( maximumDistance ( arr , n , m ) )

Accumulator variables: i, m
Python program:
def maximumXor ( arr : list , n : int ) -> int :
    sForward , sBackward = [ ] , [ ]
    ans = - 1
    for i in range ( n ) :
        while len ( sForward ) > 0 and arr [ i ] < arr [ sForward [ - 1 ] ] :
            ans = max ( ans , arr [ i ] ^ arr [ sForward [ - 1 ] ] )
            sForward . pop ( )
        sForward . append ( i )
        while len ( sBackward ) > 0 and arr [ n - i - 1 ] < arr [ sBackward [ - 1 ] ] :
            ans = max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward [ - 1 ] ] )
            sBackward . pop ( )
        sBackward . append ( n - i - 1 )
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 8 , 1 , 2 ]
    n = len ( arr )
    print ( maximumXor ( arr , n ) )

Index/key variables: i
Accumulator variables: sBackward, sForward
Iterator variables: i
Python program:
def minTrees ( n ) :
    count = 0 ;
    while ( n ) :
        n &= ( n - 1 ) ;
        count += 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    n = 7 ;
    print ( minTrees ( n ) ) ;

Accumulator variables: count, n
Python program:
def isDefeat ( s1 , s2 , n ) :
    for i in range ( n ) :
        if ( ( s1 [ i ] == '0' and s2 [ i ] == '1' ) or ( s1 [ i ] == '1' and s2 [ i ] == '0' ) ) :
            continue
        elif ( ( s1 [ i ] == '0' and s2 [ i ] == ' Z ' ) or ( s1 [ i ] == ' Z ' and s2 [ i ] == '0' ) ) :
            continue
        else :
            return True
    return False
s1 = "01001101ZZ "
s2 = "10Z1001000"
n = 10
if ( isDefeat ( s1 , s2 , n ) ) :
    print ( " Defeat " )
else :
    print ( " Victory " )

Index/key variables: i
Iterator variables: i
Python program:
N = 3
M = 3
def check ( a , b ) :
    for i in range ( 1 , N , 1 ) :
        for j in range ( 1 , M , 1 ) :
            if ( a [ i ] [ j ] != b [ i ] [ j ] ) :
                a [ i ] [ j ] ^= 1
                a [ 0 ] [ 0 ] ^= 1
                a [ 0 ] [ j ] ^= 1
                a [ i ] [ 0 ] ^= 1
    for i in range ( N ) :
        for j in range ( M ) :
            if ( a [ i ] [ j ] != b [ i ] [ j ] ) :
                return False
    return True
if __name__ == ' _ _ main _ _ ' :
    a = [ [ 0 , 1 , 0 ] , [ 0 , 1 , 0 ] , [ 1 , 0 , 0 ] ]
    b = [ [ 1 , 0 , 0 ] , [ 1 , 0 , 0 ] , [ 1 , 0 , 0 ] ]
    if ( check ( a , b ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def FindIndexKthBit ( n , k ) :
    cnt , ind = 0 , 0
    while n > 0 :
        if n & 1 :
            cnt += 1
        if cnt == k :
            return ind
        ind += 1
        n = n >> 1
    return - 1
if __name__ == " _ _ main _ _ " :
    n , k = 15 , 3
    ans = FindIndexKthBit ( n , k )
    if ans != - 1 :
        print ( ans )
    else :
        print ( " No ▁ k - th ▁ set ▁ bit " )

Accumulator variables: cnt, ind
Python program:
def hasEqualBlockFrequency ( N ) :
    S = bin ( N ) . replace ( "0b " , " " )
    p = set ( )
    c = 1
    for i in range ( len ( S ) - 1 ) :
        if ( S [ i ] == S [ i + 1 ] ) :
            c += 1
        else :
            p . add ( c )
            c = 1
        p . add ( c )
    if ( len ( p ) == 1 ) :
        print ( " Yes " )
    else :
        print ( " No " )
N = 5
hasEqualBlockFrequency ( N )

Index/key variables: i
Accumulator variables: c, p
Iterator variables: i
Python program:
def printMaxAfterRemoval ( s ) :
    flag = False
    n = len ( s )
    for i in range ( 0 , n ) :
        if s [ i ] == '0' and flag == False :
            flag = True
            continue
        else :
            print ( s [ i ] , end = " " )
if __name__ == " _ _ main _ _ " :
    s = "1001"
    printMaxAfterRemoval ( s )

Index/key variables: i
Iterator variables: i
Boolean variables: flag
Python program:
def countOddPair ( A , N ) :
    count = 0
    for i in range ( 0 , N ) :
        if ( A [ i ] % 2 != 1 ) :
            count += 1
    evenPairCount = count * ( count - 1 ) / 2
    totPairs = N * ( N - 1 ) / 2
    return ( int ) ( totPairs - evenPairCount )
A = [ 5 , 6 , 2 , 8 ]
N = len ( A )
print ( countOddPair ( A , N ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def ReplaceElements ( arr , n ) :
    if n <= 1 :
        return
    prev = arr [ 0 ]
    arr [ 0 ] = arr [ 0 ] ^ arr [ 1 ]
    for i in range ( 1 , n - 1 ) :
        curr = arr [ i ]
        arr [ i ] = prev ^ arr [ i + 1 ]
        prev = curr
    arr [ n - 1 ] = prev ^ arr [ n - 1 ]
arr = [ 2 , 3 , 4 , 5 , 6 ]
n = len ( arr )
ReplaceElements ( arr , n )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i