dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
mod = 1000000007 ;
def countSubsets ( a , n ) :
    answer = 0 ;
    for i in range ( 1 << n ) :
        bitwiseAND = - 1 ;
        bitwiseOR = 0 ;
        bitwiseXOR = 0 ;
        for j in range ( n ) :
            if ( i & ( 1 << j ) ) :
                if ( bitwiseAND == - 1 ) :
                    bitwiseAND = a [ j ] ;
                else :
                    bitwiseAND &= a [ j ] ;
                bitwiseOR |= a [ j ] ;
                bitwiseXOR ^= a [ j ] ;
        if ( bitwiseAND == bitwiseOR and bitwiseOR == bitwiseXOR ) :
            answer = ( answer + 1 ) % mod ;
    return answer ;
if __name__ == " _ _ main _ _ " :
    N = 6 ;
    A = [ 1 , 3 , 2 , 1 , 2 , 1 ] ;
    print ( countSubsets ( A , N ) ) ;

Index/key variables: j
Accumulator variables: bitwiseAND, bitwiseOR, bitwiseXOR
Iterator variables: i, j
Python program:
def count ( arr , N , K ) :
    count = 0
    ans = 0
    for i in range ( N ) :
        if ( arr [ i ] == K ) :
            count = count + 1
        else :
            ans += ( count * ( count + 1 ) ) // 2
            count = 0
    ans = ans + ( count * ( count + 1 ) ) // 2
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 0 , 1 , 1 , 0 , 0 ]
    N = len ( arr )
    K = 0
    print ( count ( arr , N , K ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def countOfGreaterElements ( arr , n ) :
    mp = { i : 0 for i in range ( 1000 ) }
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1
    x = 0
    p = [ ]
    q = [ ]
    m = [ ]
    for key , value in mp . items ( ) :
        m . append ( [ key , value ] )
    m = m [ : : - 1 ]
    for p in m :
        temp = p [ 1 ]
        mp [ p [ 0 ] ] = x
        x += temp
    for i in range ( n ) :
        print ( mp [ arr [ i ] ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 7 , 9 , 5 , 2 , 1 , 3 , 4 , 8 , 6 ]
    n = len ( arr )
    countOfGreaterElements ( arr , n )

Index/key variables: i
Accumulator variables: m, x
Iterator variables: i, key, p, value
Python program:
import sys
class Node ( ) :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def push ( head_ref , new_data ) :
    new_node = Node ( new_data )
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def largestElement ( head_ref ) :
    max = - sys . maxsize
    head = head_ref
    while ( head != None ) :
        if ( max < head . data ) :
            max = head . data
        head = head . next
    return max
def createHash ( hash , maxElement ) :
    prev = 0
    curr = 1
    hash . add ( prev )
    hash . add ( curr )
    while ( curr <= maxElement ) :
        temp = curr + prev
        hash . add ( temp )
        prev = curr
        curr = temp
    return hash
def sumAndProduct ( head_ref ) :
    maxEle = largestElement ( head_ref )
    hash = set ( )
    hash = createHash ( hash , maxEle )
    prod = 1
    sum = 0
    ptr = head_ref
    while ( ptr != None ) :
        if ptr . data in hash :
            prod *= ptr . data
            sum += ptr . data
        ptr = ptr . next
    print ( " Sum ▁ = " , sum )
    print ( " Product ▁ = " , prod )
if __name__ == " _ _ main _ _ " :
    head = None ;
    head = push ( head , 13 )
    head = push ( head , 6 )
    head = push ( head , 8 )
    head = push ( head , 16 )
    head = push ( head , 15 )
    sumAndProduct ( head )

Accumulator variables: hash, prod, sum
Class/struct names: Node
Python program:
def val ( c ) :
    if ( ord ( c ) >= ord ( '0' ) and ord ( c ) <= ord ( '9' ) ) :
        return ord ( c ) - ord ( '0' )
    else :
        return ord ( c ) - ord ( ' A ' ) + 10
def toDeci ( str , base ) :
    Len = len ( str )
    power = 1
    num = 0
    for i in range ( Len - 1 , - 1 , - 1 ) :
        if ( val ( str [ i ] ) >= base ) :
            print ( " Invalid ▁ Number " )
            return - 1
        num += val ( str [ i ] ) * power
        power = power * base
    return num
def isEven ( num , N ) :
    deci = toDeci ( num , N )
    return ( deci % 2 == 0 )
if __name__ == ' _ _ main _ _ ' :
    num = "11A "
    N = 16
    if ( isEven ( num , N ) ) :
        print ( " Even " )
    else :
        print ( " Odd " )

Index/key variables: i
Accumulator variables: num
Iterator variables: i
Python program:
fact = [ 0 ] * 21
def preCompute ( ) :
    fact [ 0 ] = 1
    for i in range ( 1 , 18 ) :
        fact [ i ] = ( fact [ i - 1 ] * i )
def nextFactorial ( N ) :
    for i in range ( 21 ) :
        if N < fact [ i ] :
            print ( fact [ i ] )
            break
preCompute ( )
N = 120
nextFactorial ( N )

Index/key variables: i
Iterator variables: i
Python program:
def findDistinctOddsumm ( n , k ) :
    if ( ( k * k ) <= n and ( n + k ) % 2 == 0 ) :
        val = 1
        summ = 0
        for i in range ( 1 , k ) :
            print ( val , end = " ▁ " )
            summ += val
            val += 2
        print ( n - summ )
    else :
        print ( " NO " )
n = 100
k = 4
findDistinctOddsumm ( n , k )

Accumulator variables: summ, val
Iterator variables: i
Python program:
def checkArray ( a , b , n ) :
    operations = 0 ;
    i = 0 ;
    while ( i < n ) :
        if ( a [ i ] - b [ i ] == 0 ) :
            i += 1 ;
            continue ;
        diff = a [ i ] - b [ i ] ;
        i += 1 ;
        while ( i < n and a [ i ] - b [ i ] == diff ) :
            i += 1 ;
        operations += 1 ;
    print ( operations ) ;
if __name__ == " _ _ main _ _ " :
    a = [ 3 , 7 , 1 , 4 , 1 , 2 ] ;
    b = [ 3 , 7 , 3 , 6 , 3 , 2 ] ;
    size = len ( a ) ;
    checkArray ( a , b , size ) ;

Index/key variables: i
Accumulator variables: operations
Python program:
import math
def insertPF ( primeFact , fact ) :
    if ( fact in primeFact ) :
        primeFact [ fact ] += 1
    else :
        primeFact [ fact ] = 1
    return primeFact
def primeFactors ( n ) :
    primeFact = { }
    while ( n % 2 == 0 ) :
        primeFact = insertPF ( primeFact , 2 )
        n = n // 2
    for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) :
        while ( n % i == 0 ) :
            primeFact = insertPF ( primeFact , i )
            n = n // i
    if ( n > 2 ) :
        primeFact = insertPF ( primeFact , n )
    return primeFact
def perfectCube ( n ) :
    primeFact = { }
    primeFact = primeFactors ( n )
    for x in primeFact :
        if ( primeFact [ x ] % 3 != 0 ) :
            return " No "
    return " Yes "
N = 216
print ( perfectCube ( N ) )

Index/key variables: fact, x
Iterator variables: i, x
Python program:
import math
def ways ( n ) :
    if n < 3 :
        return 0
    c2 = 0
    c1 = n - 3
    l = c1 + 1
    s = 0
    exp_c2 = c1 / 2
    while exp_c2 >= c2 :
        f1 = math . factorial ( l )
        f2 = math . factorial ( c1 )
        f3 = math . factorial ( c2 )
        s += f1 // ( f2 * f3 )
        c2 += 1
        c1 -= 2
        l -= 1
    return s
if __name__ == " _ _ main _ _ " :
    N = 7
    print ( ways ( N ) )

Accumulator variables: c1, c2, l, s
Python program:
m = { } ;
def precompute ( ) :
    fact = 1 ;
    for i in range ( 1 , 19 ) :
        fact = fact * i ;
        m [ fact ] = i ;
if __name__ == " _ _ main _ _ " :
    precompute ( ) ;
    K = 120 ;
    print ( m [ K ] ) ;
    K = 6 ;
    print ( m [ K ] ) ;

Index/key variables: K, fact
Iterator variables: i
Python program:
N = 100005
mod = ( 10 ** 9 + 7 )
factorial = [ 0 ] * N
modinverse = [ 0 ] * N
def factorialfun ( ) :
    factorial [ 0 ] = 1
    for i in range ( 1 , N ) :
        factorial [ i ] = ( factorial [ i - 1 ] * i ) % mod
def modinversefun ( ) :
    modinverse [ N - 1 ] = pow ( factorial [ N - 1 ] , mod - 2 , mod ) % mod
    for i in range ( N - 2 , - 1 , - 1 ) :
        modinverse [ i ] = ( modinverse [ i + 1 ] * ( i + 1 ) ) % mod
def binomial ( n , r ) :
    if ( r > n ) :
        return 0
    a = ( factorial [ n ] * modinverse [ n - r ] ) % mod
    a = ( a * modinverse [ r ] ) % mod
    return a
def max_min ( a , n , k ) :
    a = sorted ( a )
    factorialfun ( )
    modinversefun ( )
    ans = 0
    k -= 1
    for i in range ( n ) :
        x = n - i - 1
        if ( x >= k ) :
            ans -= ( binomial ( x , k ) * a [ i ] ) % mod
        y = i
        if ( y >= k ) :
            ans += ( binomial ( y , k ) * a [ i ] ) % mod
        ans = ( ans + mod ) % mod
    return ans
a = [ 1 , 1 , 3 , 4 ]
k = 2
n = len ( a )
print ( max_min ( a , n , k ) )

Index/key variables: i, n, r
Accumulator variables: ans
Iterator variables: i
Python program:
def countNumber ( N , S ) :
    countElements = 0 ;
    currSum = 0 ;
    while ( currSum <= S ) :
        currSum += N ;
        N = N - 1 ;
        countElements = countElements + 1 ;
    return countElements ;
N = 5 ;
S = 11 ;
count = countNumber ( N , S ) ;
print ( count ) ;

Accumulator variables: currSum
Python program:
import sys
INT_MAX = sys . maxsize ;
def countDistinct ( n ) :
    arr = [ 0 ] * 10 ;
    count = 0 ;
    while ( n != 0 ) :
        r = int ( n % 10 ) ;
        arr [ r ] = 1 ;
        n //= 10 ;
    for i in range ( 10 ) :
        if ( arr [ i ] != 0 ) :
            count += 1 ;
    return count ;
def countDigit ( n ) :
    c = 0 ;
    while ( n != 0 ) :
        r = n % 10 ;
        c += 1 ;
        n //= 10 ;
    return c ;
def nextNumberDistinctDigit ( n ) :
    while ( n < INT_MAX ) :
        distinct_digits = countDistinct ( n + 1 ) ;
        total_digits = countDigit ( n + 1 ) ;
        if ( distinct_digits == total_digits ) :
            return n + 1 ;
        else :
            n += 1 ;
    return - 1 ;
if __name__ == ' _ _ main _ _ ' :
    n = 2019 ;
    print ( nextNumberDistinctDigit ( n ) ) ;

Index/key variables: i, r
Accumulator variables: c, count, n
Iterator variables: i
Python program:
mod = 10 ** 9 + 7
N = 1000005
lpf = [ 0 for i in range ( N ) ]
def least_prime_factor ( ) :
    for i in range ( 1 , N ) :
        lpf [ i ] = i
    for i in range ( 2 , N ) :
        if ( lpf [ i ] == i ) :
            for j in range ( i * 2 , N , i ) :
                if ( lpf [ j ] == j ) :
                    lpf [ j ] = i
def sum_of_elements ( a , n ) :
    least_prime_factor ( )
    prime_factor = dict ( )
    for i in range ( n ) :
        temp = a [ i ]
        single_number = dict ( )
        while ( temp > 1 ) :
            x = lpf [ temp ]
            single_number [ x ] = single_number . get ( x , 0 ) + 1
            temp //= x
        if ( i == 0 ) :
            prime_factor = single_number
        else :
            for x in single_number :
                if x in prime_factor :
                    prime_factor [ x ] = max ( prime_factor [ x ] , single_number [ x ] )
                else :
                    prime_factor [ x ] = single_number [ x ]
    ans , lcm = 0 , 1
    for x in prime_factor :
        lcm = ( lcm * pow ( x , prime_factor [ x ] , mod ) ) % mod
    for i in range ( n ) :
        ans = ( ans + ( lcm * pow ( a [ i ] , mod - 2 , mod ) ) % mod ) % mod
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = [ 2 , 3 , 4 ]
    n = len ( a )
    print ( sum_of_elements ( a , n ) )

Index/key variables: i, j, temp, x
Iterator variables: i, j, x
Python program:
def findNumberOfEvenCells ( n , q , size ) :
    row = [ 0 ] * n ;
    col = [ 0 ] * n
    for i in range ( size ) :
        x = q [ i ] [ 0 ] ;
        y = q [ i ] [ 1 ] ;
        row [ x - 1 ] += 1 ;
        col [ y - 1 ] += 1 ;
    r1 = 0 ;
    r2 = 0 ;
    c1 = 0 ;
    c2 = 0 ;
    for i in range ( n ) :
        if ( row [ i ] % 2 == 0 ) :
            r1 += 1 ;
        if ( row [ i ] % 2 == 1 ) :
            r2 += 1 ;
        if ( col [ i ] % 2 == 0 ) :
            c1 += 1 ;
        if ( col [ i ] % 2 == 1 ) :
            c2 += 1 ;
    count = r1 * c1 + r2 * c2 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    n = 2 ;
    q = [ [ 1 , 1 ] , [ 1 , 2 ] , [ 2 , 1 ] ] ;
    size = len ( q ) ;
    print ( findNumberOfEvenCells ( n , q , size ) ) ;

Index/key variables: i
Accumulator variables: c1, c2, r1, r2
Iterator variables: i
Python program:
from math import ceil , sqrt
def FermatFactors ( n ) :
    if ( n <= 0 ) :
        return [ n ]
    if ( n & 1 ) == 0 :
        return [ n / 2 , 2 ]
    a = ceil ( sqrt ( n ) )
    if ( a * a == n ) :
        return [ a , a ]
    while ( True ) :
        b1 = a * a - n
        b = int ( sqrt ( b1 ) )
        if ( b * b == b1 ) :
            break
        else :
            a += 1
    return [ a - b , a + b ]
print ( FermatFactors ( 6557 ) )

Accumulator variables: a
Python program:
def findNums ( arr , n ) :
    S = 0 ; X = 0 ;
    for i in range ( n ) :
        S += arr [ i ] ;
        X ^= arr [ i ] ;
    print ( X , X + S ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 7 ] ;
    n = len ( arr ) ;
    findNums ( arr , n ) ;

Index/key variables: i
Accumulator variables: S, X
Iterator variables: i
Python program:
from math import gcd as __gcd
def findLargest ( arr , n ) :
    gcd = 0
    for i in range ( n ) :
        gcd = __gcd ( arr [ i ] , gcd )
    return gcd
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 9 ]
    n = len ( arr )
    print ( findLargest ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def digitSum ( n ) :
    sum = 0 ;
    while ( n > 0 ) :
        sum += ( n % 10 ) ;
        n //= 10 ;
    return sum ;
def isPalindrome ( n ) :
    divisor = 1 ;
    while ( n // divisor >= 10 ) :
        divisor *= 10 ;
    while ( n != 0 ) :
        leading = n // divisor ;
        trailing = n % 10 ;
        if ( leading != trailing ) :
            return False ;
        n = ( n % divisor ) // 10 ;
        divisor = divisor // 100 ;
    return True ;
def isDigitSumPalindrome ( n ) :
    sum = digitSum ( n ) ;
    if ( isPalindrome ( sum ) ) :
        return True ;
    return False ;
if __name__ == " _ _ main _ _ " :
    n = 56 ;
    if ( isDigitSumPalindrome ( n ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Accumulator variables: divisor, n, sum
Python program:
N = 100005
mod = ( int ) ( 1e9 + 7 )
factorial = [ 0 ] * N ;
modinverse = [ 0 ] * N ;
def power ( a , m1 ) :
    if ( m1 == 0 ) :
        return 1 ;
    elif ( m1 == 1 ) :
        return a ;
    elif ( m1 == 2 ) :
        return ( a * a ) % mod ;
    elif ( m1 & 1 ) :
        return ( a * power ( power ( a , m1 // 2 ) , 2 ) ) % mod ;
    else :
        return power ( power ( a , m1 // 2 ) , 2 ) % mod ;
def factorialfun ( ) :
    factorial [ 0 ] = 1 ;
    for i in range ( 1 , N ) :
        factorial [ i ] = ( factorial [ i - 1 ] * i ) % mod ;
def modinversefun ( ) :
    modinverse [ N - 1 ] = power ( factorial [ N - 1 ] , mod - 2 ) % mod ;
    for i in range ( N - 2 , - 1 , - 1 ) :
        modinverse [ i ] = ( modinverse [ i + 1 ] * ( i + 1 ) ) % mod ;
def binomial ( n , r ) :
    if ( r > n ) :
        return 0 ;
    a = ( factorial [ n ] * modinverse [ n - r ] ) % mod ;
    a = ( a * modinverse [ r ] ) % mod ;
    return a ;
def arrange ( n , m , k ) :
    factorialfun ( ) ;
    modinversefun ( ) ;
    ans = 0 ;
    for i in range ( 1 , n ) :
        ans += ( i * ( n - i ) * m * m ) % mod ;
    for i in range ( 1 , m ) :
        ans += ( i * ( m - i ) * n * n ) % mod ;
    ans = ( ans * binomial ( n * m - 2 , k - 2 ) ) % mod ;
    return int ( ans ) ;
if __name__ == " _ _ main _ _ " :
    n = 2 ; m = 2 ; k = 2 ;
    print ( arrange ( n , m , k ) ) ;

Index/key variables: i, n, r
Accumulator variables: ans
Iterator variables: i
Python program:
def findNthDigit ( p , q , N ) :
    while ( N > 0 ) :
        N -= 1 ;
        p *= 10 ;
        res = p // q ;
        p %= q ;
    return res ;
if __name__ == " _ _ main _ _ " :
    p = 1 ; q = 2 ; N = 1 ;
    print ( findNthDigit ( p , q , N ) ) ;

Accumulator variables: N, p
Python program:
def sumArr ( arr , n ) :
    sum = 0 ;
    for i in range ( n ) :
        sum += arr [ i ] ;
    return sum ;
def sumModArr ( arr , n ) :
    subSum = arr [ n - 1 ] ;
    for i in range ( n - 2 , - 1 , - 1 ) :
        curr = arr [ i ] ;
        arr [ i ] -= subSum ;
        subSum += curr ;
    return sumArr ( arr , n ) ;
arr = [ 40 , 25 , 12 , 10 ] ;
n = len ( arr ) ;
print ( sumModArr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: subSum, sum
Iterator variables: i
Python program:
NumUnsignBits = 64 ;
def findNum ( x ) :
    for i in range ( NumUnsignBits - 1 ) :
        if ( ( ( x >> i ) & 1 ) != ( ( x >> ( i + 1 ) ) & 1 ) ) :
            x ^= ( 1 << i ) | ( 1 << ( i + 1 ) ) ;
            return x ;
if __name__ == " _ _ main _ _ " :
    n = 92 ;
    print ( findNum ( n ) ) ;

Accumulator variables: x
Iterator variables: i
Python program:
def reverse ( num ) :
    rev = 0 ;
    while ( num > 0 ) :
        rev = rev * 10 + num % 10 ;
        num = num // 10 ;
    return rev ;
def isPalindrome ( num ) :
    if ( num == reverse ( num ) ) :
        return True ;
    return False ;
def printPalindromes ( d ) :
    if ( d <= 0 ) :
        return ;
    smallest = pow ( 10 , d - 1 ) ;
    largest = pow ( 10 , d ) - 1 ;
    for i in range ( smallest , largest + 1 ) :
        if ( isPalindrome ( i ) ) :
            print ( i , end = " ▁ " ) ;
d = 2 ;
printPalindromes ( d ) ;

Iterator variables: i
Python program:
import sys
from math import sqrt
def min_moves ( n ) :
    ans = sys . maxsize ;
    for i in range ( 1 , int ( sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            ans = min ( ans , i + n // i - 2 ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    n = 10 ;
    print ( min_moves ( n ) ) ;

Iterator variables: i
Python program:
MOD = 2019 ;
def min_modulo ( l , r ) :
    if ( r - l >= MOD ) :
        return 0 ;
    else :
        ans = MOD - 1 ;
        for i in range ( l , r + 1 ) :
            for j in range ( i + 1 , r + 1 ) :
                ans = min ( ans , ( i * j ) % MOD ) ;
        return ans ;
if __name__ == " _ _ main _ _ " :
    l = 2020 ; r = 2040 ;
    print ( min_modulo ( l , r ) ) ;

Iterator variables: i, j
Python program:
def countPairs ( arr , n ) :
    map = dict ( )
    for i in range ( n ) :
        map [ arr [ i ] - i ] = map . get ( arr [ i ] - i , 0 ) + 1
    res = 0
    for x in map :
        cnt = map [ x ]
        res += ( ( cnt * ( cnt - 1 ) ) // 2 )
    return res
arr = [ 1 , 5 , 6 , 7 , 9 ]
n = len ( arr )
print ( countPairs ( arr , n ) )

Index/key variables: i, x
Accumulator variables: res
Iterator variables: i, x
Python program:
def minInt ( str1 ) :
    for i in range ( len ( str1 ) ) :
        if ( str1 [ i ] >= 5 ) :
            str1 [ i ] = ( 9 - str1 [ i ] )
    if ( str1 [ 0 ] == 0 ) :
        str1 [ 0 ] = 9
    temp = " "
    for i in str1 :
        temp += str ( i )
    return temp
str1 = "589"
str1 = [ int ( i ) for i in str1 ]
print ( minInt ( str1 ) )

Index/key variables: i
Accumulator variables: temp
Iterator variables: i
Python program:
def minOperations ( n ) :
    count = 0
    d = 0
    if ( n == 1 ) :
        return 0
    while ( n > 9 ) :
        d = max ( n % 10 , d )
        n //= 10
        count += 10
    d = max ( d , n - 1 )
    count += abs ( d )
    return count - 1
if __name__ == ' _ _ main _ _ ' :
    n = 240
    print ( minOperations ( n ) )

Accumulator variables: count, n
Python program:
def findMaximumNum ( st , n , k ) :
    for i in range ( n ) :
        if ( k < 1 ) :
            break
        if ( st [ i ] != '9' ) :
            st = st [ 0 : i ] + '9' + st [ i + 1 : ]
            k -= 1
    return st
st = "569431"
n = len ( st )
k = 3
print ( findMaximumNum ( st , n , k ) )

Index/key variables: i
Accumulator variables: k
Iterator variables: i
Python program:
def prime ( n ) :
    for i in range ( 2 , n + 1 ) :
        if i * i > n + 1 :
            break
        if ( n % i == 0 ) :
            return False
    return True
def thirdNumber ( a , b ) :
    summ = 0
    temp = 0
    summ = a + b
    temp = 1
    if ( summ & 1 ) :
        temp = 2
    while ( prime ( summ + temp ) == False ) :
        temp += 2
    print ( temp )
a = 3
b = 5
thirdNumber ( a , b )

Accumulator variables: temp
Iterator variables: i
Python program:
def nCr ( n , r ) :
    ans = 1 ;
    for i in range ( 1 , r + 1 ) :
        ans *= ( n - r + i ) ;
        ans //= i ;
    return ans ;
def total_ways ( N , X ) :
    return ( nCr ( N - 1 , X - 1 ) + nCr ( N - 1 , X ) ) ;
if __name__ == " _ _ main _ _ " :
    N = 5 ; X = 3 ;
    print ( total_ways ( N , X ) ) ;

Accumulator variables: ans
Iterator variables: i
Python program:
def printNumber ( holes ) :
    if ( holes == 0 ) :
        print ( "1" )
    elif ( holes == 1 ) :
        print ( "0" , end = " " )
    else :
        rem = 0
        quo = 0
        rem = holes % 2
        quo = holes // 2
        if ( rem == 1 ) :
            print ( "4" , end = " " )
        for i in range ( quo ) :
            print ( "8" , end = " " )
holes = 3
printNumber ( holes )

Iterator variables: i
Python program:
def minCost ( arr , n ) :
    count_even = 0
    count_odd = 0
    for i in range ( n ) :
        if ( arr [ i ] % 2 == 0 ) :
            count_even += 1
        else :
            count_odd += 1
    return min ( count_even , count_odd )
arr = [ 2 , 4 , 3 , 1 , 5 ]
n = len ( arr )
print ( minCost ( arr , n ) )

Index/key variables: i
Accumulator variables: count_even, count_odd
Iterator variables: i
Python program:
def negProdSubArr ( arr , n ) :
    positive = 1
    negative = 0
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            arr [ i ] = 1
        else :
            arr [ i ] = - 1
        if ( i > 0 ) :
            arr [ i ] *= arr [ i - 1 ]
        if ( arr [ i ] == 1 ) :
            positive += 1
        else :
            negative += 1
    return ( positive * negative )
def posProdSubArr ( arr , n ) :
    total = ( n * ( n + 1 ) ) / 2 ;
    cntNeg = negProdSubArr ( arr , n ) ;
    return ( total - cntNeg ) ;
arr = [ 5 , - 4 , - 3 , 2 , - 5 ]
n = len ( arr )
print ( posProdSubArr ( arr , n ) )

Index/key variables: i
Accumulator variables: negative, positive
Iterator variables: i
Python program:
MAX = 10000
prime = [ True for i in range ( MAX + 1 ) ]
def SieveOfEratosthenes ( ) :
    prime [ 1 ] = False
    for p in range ( 2 , MAX + 1 ) :
        if ( prime [ p ] == True ) :
            for i in range ( 2 * p , MAX + 1 , p ) :
                prime [ i ] = False
def xorFirstNPrime ( n ) :
    count = 0
    num = 1
    xorVal = 0
    while ( count < n ) :
        if ( prime [ num ] ) :
            xorVal ^= num
            count += 1
        num += 1
    return xorVal
SieveOfEratosthenes ( )
n = 4
print ( xorFirstNPrime ( n ) )

Index/key variables: i, num, p
Accumulator variables: count, xorVal
Iterator variables: i, p
Python program:
import sys
def maxSubArraySum ( a , n , k , i ) :
    max_so_far = - sys . maxsize ;
    max_ending_here = 0 ;
    while ( i < n ) :
        max_ending_here = max_ending_here + a [ i ] ;
        if ( max_so_far < max_ending_here ) :
            max_so_far = max_ending_here ;
        if ( max_ending_here < 0 ) :
            max_ending_here = 0 ;
        i += k ;
    return max_so_far ;
def find ( arr , n , k ) :
    maxSum = 0 ;
    for i in range ( 0 , min ( n , k ) + 1 ) :
        sum = 0 ;
        maxSum = max ( maxSum , maxSubArraySum ( arr , n , k , i ) ) ;
    return maxSum ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , - 3 , - 1 , - 1 , 2 ] ;
    n = len ( arr ) ;
    k = 2 ;
    print ( find ( arr , n , k ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
from math import sqrt
MAX = 1000000
prime = [ True ] * ( MAX + 1 ) ;
def SieveOfEratosthenes ( ) :
    prime [ 1 ] = False ;
    for p in range ( 2 , int ( sqrt ( MAX ) ) + 1 ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * 2 , MAX + 1 , p ) :
                prime [ i ] = False ;
def solve ( n ) :
    count = 0 ;
    i = 3 ;
    while count < n :
        if ( prime [ i ] ) :
            print ( i , end = " ▁ " ) ;
            count += 1 ;
        i += 1
if __name__ == " _ _ main _ _ " :
    SieveOfEratosthenes ( ) ;
    n = 6 ;
    solve ( n ) ;

Index/key variables: i, p
Accumulator variables: count
Iterator variables: i, p
Python program:
def solve ( n ) :
    n_2 = n // 2 ;
    den = "1" ;
    while ( n_2 ) :
        den += '0' ;
        n_2 -= 1
    print ( str ( 1 ) + " / " + str ( den ) )
if __name__ == " _ _ main _ _ " :
    N = 5 ;
    solve ( N ) ;

Accumulator variables: den, n_2