dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
ma = { }
def primeFactorize ( a ) :
    sqt = int ( math . sqrt ( a ) )
    for i in range ( 2 , sqt , 2 ) :
        cnt = 0
        while ( a % i == 0 ) :
            cnt += 1
            a /= i
        ma [ i ] = cnt
    if ( a > 1 ) :
        ma [ a ] = 1
def commDiv ( a , b ) :
    primeFactorize ( a )
    res = 1
    for key , value in ma . items ( ) :
        cnt = 0
        while ( b % key == 0 ) :
            b /= key
            cnt += 1
        res *= ( min ( cnt , value ) + 1 )
    return res
a = 12
b = 24
print ( commDiv ( a , b ) )

Index/key variables: a, i
Accumulator variables: b, cnt, res
Iterator variables: i, key, value
Python program:
def findCountOfSolutions ( n , p ) :
    ans = 0 ;
    for x in range ( 1 , p ) :
        if ( ( x * x ) % p == 1 ) :
            last = x + p * ( n / p ) ;
            if ( last > n ) :
                last -= p ;
            ans += ( ( last - x ) / p + 1 ) ;
    return int ( ans ) ;
n = 10 ;
p = 5 ;
print ( findCountOfSolutions ( n , p ) ) ;

Accumulator variables: ans, last
Iterator variables: x
Python program:
def kaprekarRec ( n , prev ) :
    if ( n == 0 ) :
        return 0 ;
    prev = n ;
    digits = [ 0 ] * 4 ;
    for i in range ( 4 ) :
        digits [ i ] = n % 10 ;
        n = int ( n / 10 ) ;
    digits . sort ( ) ;
    asc = 0 ;
    for i in range ( 4 ) :
        asc = asc * 10 + digits [ i ] ;
    digits . sort ( ) ;
    desc = 0 ;
    for i in range ( 3 , - 1 , - 1 ) :
        desc = desc * 10 + digits [ i ] ;
    diff = abs ( asc - desc ) ;
    if ( diff == prev ) :
        return diff ;
    return kaprekarRec ( diff , prev ) ;
def kaprekar ( n ) :
    rev = 0 ;
    return kaprekarRec ( n , rev ) ;
print ( kaprekar ( 1000 ) ) ;
print ( kaprekar ( 1112 ) ) ;
print ( kaprekar ( 9812 ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def power ( x , a ) :
    res = 1
    while ( a ) :
        if ( a & 1 ) :
            res = res * x
        x = x * x
        a >>= 1
    return res
def breakInteger ( N ) :
    if ( N == 2 ) :
        return 1
    if ( N == 3 ) :
        return 2
    maxProduct = 0
    if ( N % 3 == 0 ) :
        maxProduct = power ( 3 , int ( N / 3 ) )
        return maxProduct
    elif ( N % 3 == 1 ) :
        maxProduct = 2 * 2 * power ( 3 , int ( N / 3 ) - 1 )
        return maxProduct
    elif ( N % 3 == 2 ) :
        maxProduct = 2 * power ( 3 , int ( N / 3 ) )
        return maxProduct
maxProduct = breakInteger ( 10 )
print ( maxProduct )

Accumulator variables: a
Python program:
import math
def digSum ( n ) :
    sum = 0
    while ( n > 0 or sum > 9 ) :
        if ( n == 0 ) :
            n = sum
            sum = 0
        sum += n % 10
        n /= 10
    return sum
n = 1234
print ( digSum ( n ) )

Accumulator variables: n, sum
Python program:
sum = [ 0 for i in range ( 1000005 ) ]
def toInt ( x ) :
    return int ( x )
def prepareSum ( s ) :
    sum [ 0 ] = 0
    for i in range ( 0 , len ( s ) ) :
        sum [ i + 1 ] = sum [ i ] + toInt ( s [ i ] )
def query ( l , r ) :
    if ( ( sum [ r + 1 ] - sum [ l ] ) % 3 == 0 ) :
        print ( " Divisible ▁ by ▁ 3" )
    else :
        print ( " Not ▁ divisible ▁ by ▁ 3" )
if __name__ == ' _ _ main _ _ ' :
    n = "12468236544"
    prepareSum ( n )
    query ( 0 , 1 )
    query ( 1 , 2 )
    query ( 3 , 6 )
    query ( 0 , 10 )

Index/key variables: i, l
Iterator variables: i
Python program:
def oneDigit ( num ) :
    return ( num >= 0 and num < 10 ) ;
def isPalUtil ( num , dupNum ) :
    if ( oneDigit ( num ) ) :
        return ( num == ( dupNum ) % 10 ) ;
    if ( not isPalUtil ( int ( num / 10 ) , dupNum ) ) :
        return False ;
    dupNum = int ( dupNum / 10 ) ;
    return ( num % 10 == ( dupNum ) % 10 ) ;
def isPal ( num ) :
    if ( num < 0 ) :
        num = - num ;
    return isPalUtil ( num , dupNum ) ;
def printPalPrimesLessThanN ( n ) :
    prime = [ True ] * ( n + 1 ) ;
    p = 2 ;
    while ( p * p <= n ) :
        if ( prime [ p ] ) :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = False ;
        p += 1 ;
    for p in range ( 2 , n + 1 ) :
        if ( prime [ p ] and isPal ( p ) ) :
            print ( p , end = " ▁ " ) ;
n = 100 ;
print ( " Palindromic ▁ primes ▁ smaller " , " than ▁ or ▁ equal ▁ to " , n , " are ▁ : " ) ;
printPalPrimesLessThanN ( n ) ;

Index/key variables: i, p
Iterator variables: i, p
Python program:
import math
def countPrimeFactors ( n ) :
    count = 0 ;
    while ( n % 2 == 0 ) :
        n = n / 2 ;
        count += 1 ;
    i = 3 ;
    while ( i <= math . sqrt ( n ) ) :
        while ( n % i == 0 ) :
            n = n / i ;
            count += 1 ;
        i = i + 2 ;
    if ( n > 2 ) :
        count += 1 ;
    return ( count ) ;
def printKAlmostPrimes ( k , n ) :
    i = 1 ;
    num = 2
    while ( i <= n ) :
        if ( countPrimeFactors ( num ) == k ) :
            print ( num , end = " " ) ;
            print ( " ▁ " , end = " " ) ;
            i += 1 ;
        num += 1 ;
    return ;
n = 10 ;
k = 2 ;
print ( " First ▁ n ▁ k - almost ▁ prime ▁ numbers : " ) ;
printKAlmostPrimes ( k , n ) ;

Accumulator variables: count, i, num
Python program:
import math
def findDigits ( n ) :
    if ( n < 0 ) :
        return 0 ;
    if ( n <= 1 ) :
        return 1 ;
    digits = 0 ;
    for i in range ( 2 , n + 1 ) :
        digits += math . log10 ( i ) ;
    return math . floor ( digits ) + 1 ;
print ( findDigits ( 1 ) ) ;
print ( findDigits ( 5 ) ) ;
print ( findDigits ( 10 ) ) ;
print ( findDigits ( 120 ) ) ;

Accumulator variables: digits
Iterator variables: i
Python program:
def countEvenSum ( arr , n ) :
    result = 0
    for i in range ( 0 , n , 1 ) :
        sum = 0
        for j in range ( i , n , 1 ) :
            sum = sum + arr [ j ]
            if ( sum % 2 == 0 ) :
                result = result + 1
    return ( result )
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: j
Iterator variables: i, j
Python program:
def countEvenSum ( arr , n ) :
    temp = [ 1 , 0 ]
    result = 0
    sum = 0
    for i in range ( n ) :
        sum = ( ( sum + arr [ i ] ) % 2 + 2 ) % 2
        temp [ sum ] += 1
    result = result + ( temp [ 0 ] * ( temp [ 0 ] - 1 ) // 2 )
    result = result + ( temp [ 1 ] * ( temp [ 1 ] - 1 ) // 2 )
    return ( result )
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, sum
Iterator variables: i
Python program:
def calculateSum ( n ) :
    if ( n <= 0 ) :
        return 0
    fibo = [ 0 ] * ( n + 1 )
    fibo [ 1 ] = 1
    sm = fibo [ 0 ] + fibo [ 1 ]
    for i in range ( 2 , n + 1 ) :
        fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]
        sm = sm + fibo [ i ]
    return sm
n = 4
print ( " Sum ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ " , calculateSum ( n ) )

Index/key variables: i
Iterator variables: i
Python program:
def findCombinationsUtil ( arr , index , num , reducedNum ) :
    if ( reducedNum < 0 ) :
        return
    if ( reducedNum == 0 ) :
        for i in range ( index ) :
            print ( arr [ i ] , end = " ▁ " )
        print ( " " )
        return
    prev = 1 if ( index == 0 ) else arr [ index - 1 ]
    for k in range ( prev , num + 1 ) :
        arr [ index ] = k
        findCombinationsUtil ( arr , index + 1 , num , reducedNum - k )
def findCombinations ( n ) :
    arr = [ 0 ] * n
    findCombinationsUtil ( arr , 0 , n , n )
n = 5 ;
findCombinations ( n ) ;

Index/key variables: i, index
Iterator variables: i, k
Python program:
def pow1 ( base , exponent , modulus ) :
    result = 1 ;
    base = base % modulus ;
    while ( exponent > 0 ) :
        if ( exponent % 2 == 1 ) :
            result = ( result * base ) % modulus ;
        exponent = int ( exponent ) >> 1 ;
        base = ( base * base ) % modulus ;
    return result ;
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a ;
    else :
        return gcd ( b , a % b ) ;
def order ( p , b ) :
    if ( gcd ( p , b ) != 1 ) :
        print ( " p and b are not co - prime . " ) ;
        return - 1 ;
    k = 3 ;
    while ( True ) :
        if ( pow1 ( b , k , p ) == 1 ) :
            return k ;
        k += 1 ;
def convertx2e ( x ) :
    z = 0 ;
    while ( x % 2 == 0 ) :
        x = x / 2 ;
        z += 1 ;
    return [ x , z ] ;
def STonelli ( n , p ) :
    if ( gcd ( n , p ) != 1 ) :
        print ( " a and p are not coprime " ) ;
        return - 1 ;
    if ( pow1 ( n , ( p - 1 ) / 2 , p ) == ( p - 1 ) ) :
        print ( " no sqrt possible " ) ;
        return - 1 ;
    ar = convertx2e ( p - 1 ) ;
    s = ar [ 0 ] ;
    e = ar [ 1 ] ;
    q = 2 ;
    while ( True ) :
        if ( pow1 ( q , ( p - 1 ) / 2 , p ) == ( p - 1 ) ) :
            break ;
        q += 1 ;
    x = pow1 ( n , ( s + 1 ) / 2 , p ) ;
    b = pow1 ( n , s , p ) ;
    g = pow1 ( q , s , p ) ;
    r = e ;
    while ( True ) :
        m = 0 ;
        while ( m < r ) :
            if ( order ( p , b ) == - 1 ) :
                return - 1 ;
            if ( order ( p , b ) == pow ( 2 , m ) ) :
                break ;
            m += 1 ;
        if ( m == 0 ) :
            return x ;
        x = ( x * pow1 ( g , pow ( 2 , r - m - 1 ) , p ) ) % p ;
        g = pow1 ( g , pow ( 2 , r - m ) , p ) ;
        b = ( b * g ) % p ;
        if ( b == 1 ) :
            return x ;
        r = m ;
n = 2 ;
p = 113 ;
x = STonelli ( n , p ) ;
if ( x == - 1 ) :
    print ( " Modular square root is not exist " ) ;
else :
    print ( " Modular ▁ square ▁ root ▁ of " , n , " and " , p , " is " , x ) ;

Accumulator variables: k, m, q, z
Python program:
def isPerfectSquare ( n ) :
    i = 1
    the_sum = 0
    while the_sum < n :
        the_sum += i
        if the_sum == n :
            return True
        i += 2
    return False
if __name__ == " _ _ main _ _ " :
    print ( ' Yes ' ) if isPerfectSquare ( 35 ) else print ( ' NO ' )
    print ( ' Yes ' ) if isPerfectSquare ( 49 ) else print ( ' NO ' )

Accumulator variables: i, the_sum
Python program:
def countDyckPaths ( n ) :
    res = 1
    for i in range ( 0 , n ) :
        res *= ( 2 * n - i )
        res /= ( i + 1 )
    return res / ( n + 1 )
n = 4
print ( " Number ▁ of ▁ Dyck ▁ Paths ▁ is ▁ " , str ( int ( countDyckPaths ( n ) ) ) )

Accumulator variables: res
Iterator variables: i
Python program:
def isTriangular ( num ) :
    if ( num < 0 ) :
        return False
    sum , n = 0 , 1
    while ( sum <= num ) :
        sum = sum + n
        if ( sum == num ) :
            return True
        n += 1
    return False
n = 55
if ( isTriangular ( n ) ) :
    print ( " The ▁ number ▁ is ▁ a ▁ triangular ▁ number " )
else :
    print ( " The ▁ number ▁ is ▁ NOT ▁ a ▁ triangular ▁ number " )

Accumulator variables: n
Python program:
def xor_c ( a , b ) :
    return '0' if ( a == b ) else '1' ;
def flip ( c ) :
    return '1' if ( c == '0' ) else '0' ;
def binarytoGray ( binary ) :
    gray = " " ;
    gray += binary [ 0 ] ;
    for i in range ( 1 , len ( binary ) ) :
        gray += xor_c ( binary [ i - 1 ] , binary [ i ] ) ;
    return gray ;
def graytoBinary ( gray ) :
    binary = " " ;
    binary += gray [ 0 ] ;
    for i in range ( 1 , len ( gray ) ) :
        if ( gray [ i ] == '0' ) :
            binary += binary [ i - 1 ] ;
        else :
            binary += flip ( binary [ i - 1 ] ) ;
    return binary ;
binary = "01001" ;
print ( " Gray ▁ code ▁ of " , binary , " is " , binarytoGray ( binary ) ) ;
gray = "01101" ;
print ( " Binary ▁ code ▁ of " , gray , " is " , graytoBinary ( gray ) ) ;

Index/key variables: i
Accumulator variables: binary, gray
Iterator variables: i
Python program:
def seriesSum ( calculated , current , N ) :
    i = calculated ;
    cur = 1 ;
    if ( current == N + 1 ) :
        return 0 ;
    while ( i < calculated + current ) :
        cur *= i ;
        i += 1 ;
    return cur + seriesSum ( i , current + 1 , N ) ;
N = 5 ;
print ( seriesSum ( 1 , 1 , N ) ) ;

Accumulator variables: cur, i
Python program:
def modFact ( n , p ) :
    if n >= p :
        return 0
    result = 1
    for i in range ( 1 , n + 1 ) :
        result = ( result * i ) % p
    return result
n = 25 ; p = 29
print ( modFact ( n , p ) )

Iterator variables: i
Python program:
def inv ( a , m ) :
    m0 = m
    x0 = 0
    x1 = 1
    if ( m == 1 ) :
        return 0
    while ( a > 1 ) :
        q = a // m
        t = m
        m = a % m
        a = t
        t = x0
        x0 = x1 - q * x0
        x1 = t
    if ( x1 < 0 ) :
        x1 = x1 + m0
    return x1
def findMinX ( num , rem , k ) :
    prod = 1
    for i in range ( 0 , k ) :
        prod = prod * num [ i ]
    result = 0
    for i in range ( 0 , k ) :
        pp = prod // num [ i ]
        result = result + rem [ i ] * inv ( pp , num [ i ] ) * pp
    return result % prod
num = [ 3 , 4 , 5 ]
rem = [ 2 , 3 , 1 ]
k = len ( num )
print ( " x ▁ is ▁ " , findMinX ( num , rem , k ) )

Index/key variables: i
Iterator variables: i
Python program:
def findMinX ( num , rem , k ) :
    while ( True ) :
        j = 0 ;
        while ( j < k ) :
            if ( x % num [ j ] != rem [ j ] ) :
                break ;
            j += 1 ;
        if ( j == k ) :
            return x ;
        x += 1 ;
num = [ 3 , 4 , 5 ] ;
rem = [ 2 , 3 , 1 ] ;
k = len ( num ) ;
print ( " x ▁ is " , findMinX ( num , rem , k ) ) ;

Index/key variables: j
Accumulator variables: x
Python program:
def simpleSieve ( limit ) :
    mark = [ True for i in range ( limit ) ]
    for p in range ( p * p , limit - 1 , 1 ) :
        if ( mark [ p ] == True ) :
            for i in range ( p * p , limit - 1 , p ) :
                mark [ i ] = False
    for p in range ( 2 , limit - 1 , 1 ) :
        if ( mark [ p ] == True ) :
            print ( p , end = " ▁ " )

Index/key variables: i, p
Iterator variables: i, p
Python program:
import math
def printTwins ( low , high ) :
    prime = [ True ] * ( high + 1 ) ;
    twin = False ;
    prime [ 0 ] = prime [ 1 ] = False ;
    for p in range ( 2 , int ( math . floor ( math . sqrt ( high ) ) + 2 ) ) :
        if ( prime [ p ] ) :
            for i in range ( p * 2 , high + 1 , p ) :
                prime [ i ] = False ;
    for i in range ( low , high + 1 ) :
        if ( prime [ i ] and prime [ i + 2 ] ) :
            print ( " Smallest ▁ twins ▁ in ▁ given ▁ range : ▁ ( " , i , " , " , ( i + 2 ) , " ) " ) ;
            twin = True ;
            break ;
    if ( twin == False ) :
        print ( " No ▁ such ▁ pair ▁ exists " ) ;
printTwins ( 10 , 100 ) ;

Index/key variables: i, p
Iterator variables: i, p
Boolean variables: twin
Python program:
def isFancy ( num ) :
    fp = { }
    fp [ '0' ] = '0'
    fp [ '1' ] = '1'
    fp [ '6' ] = '9'
    fp [ '8' ] = '8'
    fp [ '9' ] = '6'
    n = len ( num )
    l = 0
    r = n - 1
    while ( l <= r ) :
        if ( num [ l ] not in fp or fp [ num [ l ] ] != num [ r ] ) :
            return False
        l += 1
        r -= 1
    return True
if __name__ == " _ _ main _ _ " :
    st = "9088806"
    if isFancy ( st ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: l, r
Python program:
def nextSparse ( x ) :
    bin = [ ]
    while ( x != 0 ) :
        bin . append ( x & 1 )
        x >>= 1
    bin . append ( 0 )
    last_final = 0
    for i in range ( 1 , n - 1 ) :
        if ( ( bin [ i ] == 1 and bin [ i - 1 ] == 1 and bin [ i + 1 ] != 1 ) ) :
            bin [ i + 1 ] = 1
            for j in range ( i , last_final - 1 , - 1 ) :
                bin [ j ] = 0
            last_final = i + 1
    ans = 0
    for i in range ( n ) :
        ans += bin [ i ] * ( 1 << i )
    return ans
if __name__ == ' _ _ main _ _ ' :
    x = 38
    print ( " Next ▁ Sparse ▁ Number ▁ is " , nextSparse ( x ) )

Index/key variables: i, j
Accumulator variables: ans, bin, x
Iterator variables: i, j
Python program:
def countSubsets ( arr , n , gcd , m ) :
    freq = dict ( )
    subsets = dict ( )
    arrMax = 0
    for i in range ( n ) :
        arrMax = max ( arrMax , arr [ i ] )
        if arr [ i ] not in freq :
            freq [ arr [ i ] ] = 1
        else :
            freq [ arr [ i ] ] += 1
    for i in range ( arrMax , 0 , - 1 ) :
        sub = 0
        add = 0
        if i in freq :
            add = freq [ i ]
        j = 2
        while j * i <= arrMax :
            if j * i in freq :
                add += freq [ j * i ]
            sub += subsets [ j * i ]
            j += 1
        subsets [ i ] = ( 1 << add ) - 1 - sub
    for i in range ( m ) :
        print ( " Number ▁ of ▁ subsets ▁ with ▁ gcd ▁ % d ▁ is ▁ % d " % ( gcd [ i ] , subsets [ gcd [ i ] ] ) )
if __name__ == " _ _ main _ _ " :
    gcd = [ 2 , 3 ]
    arr = [ 9 , 6 , 2 ]
    n = len ( arr )
    m = len ( gcd )
    countSubsets ( arr , n , gcd , m )

Index/key variables: i
Accumulator variables: add, j, sub
Iterator variables: i
Python program:
def sumBitDifferences ( arr , n ) :
    for i in range ( 0 , 32 ) :
        count = 0
        for j in range ( 0 , n ) :
            if ( ( arr [ j ] & ( 1 << i ) ) ) :
                count += 1
        ans += ( count * ( n - count ) * 2 ) ;
    return ans
arr = [ 1 , 3 , 5 ]
n = len ( arr )
print ( sumBitDifferences ( arr , n ) )

Index/key variables: j
Accumulator variables: ans, count
Iterator variables: i, j
Python program:
def printArr ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( " " )
def generateUtil ( x , arr , curr_sum , curr_idx ) :
    if ( curr_sum == x ) :
        printArr ( arr , curr_idx )
        return
    num = 1
    while ( num <= x - curr_sum and ( curr_idx == 0 or num <= arr [ curr_idx - 1 ] ) ) :
        arr [ curr_idx ] = num
        generateUtil ( x , arr , curr_sum + num , curr_idx + 1 )
        num += 1
def generate ( x ) :
    arr = [ 0 ] * x
    generateUtil ( x , arr , 0 , 0 )
x = 5
generate ( x )

Index/key variables: curr_idx, i
Accumulator variables: num
Iterator variables: i
Python program:
def isPerfect ( n ) :
    sum = 1
    i = 2
    while i * i <= n :
        if n % i == 0 :
            sum = sum + i + n / i
        i += 1
    return ( True if sum == n and n != 1 else False )
print ( " Below ▁ are ▁ all ▁ perfect ▁ numbers ▁ till ▁ 10000" )
n = 2
for n in range ( 10000 ) :
    if isPerfect ( n ) :
        print ( n , " ▁ is ▁ a ▁ perfect ▁ number " )

Accumulator variables: i
Iterator variables: n
Python program:
def gcd ( a , b ) :
    if ( a == 0 ) :
        return b
    return gcd ( b % a , a )
def phi ( n ) :
    result = 1
    for i in range ( 2 , n ) :
        if ( gcd ( i , n ) == 1 ) :
            result += 1
    return result
for n in range ( 1 , 11 ) :
    print ( " phi ( " , n , " ) ▁ = ▁ " , phi ( n ) , sep = " " )

Accumulator variables: result
Iterator variables: i, n
Python program:
def phi ( n ) :
    p = 2
    while p * p <= n :
        if n % p == 0 :
            while n % p == 0 :
                n = n // p
            result = result * ( 1.0 - ( 1.0 / float ( p ) ) )
        p = p + 1
    if n > 1 :
        result = result * ( 1.0 - ( 1.0 / float ( n ) ) )
    return int ( result )
for n in range ( 1 , 11 ) :
    print ( " phi ( " , n , " ) ▁ = ▁ " , phi ( n ) )

Iterator variables: n
Python program:
def getRemainder ( num , divisor ) :
    while ( num >= divisor ) :
        num -= divisor ;
    return num ;
if __name__ == ' _ _ main _ _ ' :
    num = 100 ; divisor = 7 ;
    print ( getRemainder ( num , divisor ) ) ;

Accumulator variables: num
Python program:
def factorial ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res *= i
    return res
def sum ( n ) :
    s = 0.0
    for i in range ( 1 , n + 1 ) :
        s += 1.0 / factorial ( i )
    print ( s )
n = 5
sum ( n )

Accumulator variables: res, s
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 int ( res ) ;
def catalan ( n ) :
    c = binomialCoeff ( 2 * n , n ) ;
    return int ( c / ( n + 1 ) ) ;
def findWays ( n ) :
    if ( n & 1 ) :
        return 0 ;
    return catalan ( int ( n / 2 ) ) ;
n = 6 ;
print ( " Total ▁ possible ▁ expressions ▁ of ▁ length " , n , " is " , findWays ( 6 ) ) ;

Accumulator variables: res
Iterator variables: i
Python program:
def isOperand ( c ) :
    return ( c >= '0' and c <= '9' ) ;
def value ( c ) :
    return ord ( c ) - ord ( '0' ) ;
def evaluate ( exp ) :
    len1 = len ( exp ) ;
    if ( len1 == 0 ) :
        return - 1 ;
    res = value ( exp [ 0 ] ) ;
    for i in range ( 1 , len1 , 2 ) :
        opr = exp [ i ] ;
        opd = exp [ i + 1 ] ;
        if ( isOperand ( opd ) == False ) :
            return - 1 ;
        if ( opr == ' + ' ) :
            res += value ( opd ) ;
        elif ( opr == ' - ' ) :
            res -= int ( value ( opd ) ) ;
        elif ( opr == ' * ' ) :
            res *= int ( value ( opd ) ) ;
        elif ( opr == ' / ' ) :
            res /= int ( value ( opd ) ) ;
        else :
            return - 1 ;
    return res ;
expr1 = "1 + 2*5 + 3" ;
res = evaluate ( expr1 ) ;
print ( expr1 , " is ▁ Invalid " ) if ( res == - 1 ) else print ( " Value ▁ of " , expr1 , " is " , res ) ;
expr2 = "1 + 2*3" ;
res = evaluate ( expr2 ) ;
print ( expr2 , " is ▁ Invalid " ) if ( res == - 1 ) else print ( " Value ▁ of " , expr2 , " is " , res ) ;
expr3 = "4-2 + 6*3" ;
res = evaluate ( expr3 ) ;
print ( expr3 , " is ▁ Invalid " ) if ( res == - 1 ) else print ( " Value ▁ of " , expr3 , " is " , res ) ;
expr4 = "1 + + 2" ;
res = evaluate ( expr4 ) ;
print ( expr4 , " is ▁ Invalid " ) if ( res == - 1 ) else print ( " Value ▁ of " , expr4 , " is " , res ) ;

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def printFibonacciNumbers ( n ) :
    f1 = 0
    f2 = 1
    if ( n < 1 ) :
        return
    print ( f1 , end = " ▁ " )
    for x in range ( 1 , n ) :
        print ( f2 , end = " ▁ " )
        next = f1 + f2
        f1 = f2
        f2 = next
printFibonacciNumbers ( 7 )

Iterator variables: x
Python program:
import math
M = 1000000000 + 7
directions = [ [ 0 , 1 ] , [ - 1 , 0 ] , [ 0 , - 1 ] , [ 1 , 0 ] , [ 1 , 1 ] , [ - 1 , - 1 ] , [ - 1 , 1 ] , [ 1 , - 1 ] ]
def isInside ( i , j , N , M ) :
    if ( i >= 0 and i < N and j >= 0 and j < M ) :
        return True
    return False
def DFS ( mat , N , M , i , j , visited ) :
    if ( visited [ i ] [ j ] == True ) :
        return
    visited [ i ] [ j ] = True
    for it in directions :
        I = i + it [ 0 ]
        J = j + it [ 1 ]
        if ( isInside ( I , J , N , M ) ) :
            if ( mat [ I ] [ J ] == 0 ) :
                DFS ( mat , N , M , I , J , visited )
def check ( N , M , mat ) :
    black = 0
    for i in range ( 0 , N ) :
        for j in range ( 0 , M ) :
            if ( mat [ i ] [ j ] == 0 ) :
                black += 1
    if ( black < 2 * ( max ( N , M ) ) ) :
        print ( " NO " )
        return
    visited = [ ]
    for i in range ( 0 , N ) :
        temp = [ ]
        for j in range ( 0 , M ) :
            temp . append ( False )
        visited . append ( temp )
    black_spots = 0
    for i in range ( 0 , N ) :
        for j in range ( 0 , M ) :
            if ( visited [ i ] [ j ] == False and mat [ i ] [ j ] == 0 ) :
                black_spots += 1
                DFS ( mat , N , M , i , j , visited )
    T = math . gcd ( N , M )
    if black_spots >= T :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == " _ _ main _ _ " :
    N = 3
    M = 3
    mat = [ [ 0 , 0 , 1 ] , [ 1 , 1 , 1 ] , [ 0 , 0 , 1 ] ]
    check ( M , N , mat )

Index/key variables: I, J, i, j
Accumulator variables: black, black_spots, temp, visited
Iterator variables: i, it, j
Python program:
def countSubsequences ( arr ) :
    odd = 0 ;
    even = 0 ;
    for x in arr :
        if ( x & 1 ) :
            odd += 1 ;
        else :
            even += 1 ;
    return ( ( 1 << odd ) - 1 ) * ( 1 << even ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 1 ] ;
    print ( countSubsequences ( arr ) ) ;

Accumulator variables: even, odd
Iterator variables: x