dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import sys
def largestSumpair ( arr , n ) :
    pair = [ ]
    max_sum = - sys . maxsize - 1
    for i in range ( 1 , n ) :
        if max_sum < ( arr [ i ] + arr [ i - 1 ] ) :
            max_sum = arr [ i ] + arr [ i - 1 ]
            if pair == [ ] :
                pair . append ( arr [ i - 1 ] )
                pair . append ( arr [ i ] )
            else :
                pair [ 0 ] = arr [ i - 1 ]
                pair [ 1 ] = arr [ i ]
    return pair
arr = [ 11 , - 5 , 9 , - 3 , 2 ]
N = len ( arr )
pair = largestSumpair ( arr , N )
print ( pair [ 0 ] , end = " ▁ " )
print ( pair [ 1 ] , end = " ▁ " )

Index/key variables: i
Accumulator variables: pair
Iterator variables: i
Python program:
def isSuperdNum ( n ) :
    for d in range ( 2 , 10 ) :
        substring = str ( d ) * d ;
        if substring in str ( d * pow ( n , d ) ) :
            return True
    return False
n = 261
if isSuperdNum ( n ) == True :
    print ( " Yes " )
else :
    print ( " No " )

Iterator variables: d
Python program:
import math
MAX = 1000000
primes = [ ]
def sieveSundaram ( ) :
    marked = [ 0 ] * int ( MAX / 2 + 1 )
    for i in range ( 1 , int ( ( math . sqrt ( MAX ) - 1 ) // 2 ) + 1 ) :
        for j in range ( ( i * ( i + 1 ) ) << 1 , MAX // 2 + 1 , 2 * i + 1 ) :
            marked [ j ] = True
    primes . append ( 2 )
    for i in range ( 1 , MAX // 2 + 1 ) :
        if ( marked [ i ] == False ) :
            primes . append ( 2 * i + 1 )
def calculateKummer ( n ) :
    result = 1
    for i in range ( n ) :
        result = result * primes [ i ]
    return ( - 1 + result )
N = 5
sieveSundaram ( )
for i in range ( 1 , N + 1 ) :
    print ( calculateKummer ( i ) , end = " , ▁ " )

Index/key variables: i, j
Accumulator variables: primes
Iterator variables: i, j
Python program:
def check ( n ) :
    digits = set ( )
    temp = n
    Sum = 0
    count = 0
    while ( temp > 0 ) :
        Sum += temp % 10
        digits . add ( temp % 10 )
        count += 1
        temp = temp // 10
    if ( ( Sum % count == 0 ) and ( ( int ) ( Sum / count ) in digits ) ) :
        print ( " Yes " )
    else :
        print ( " No " )
n = 42644
check ( n )

Accumulator variables: Sum, count, digits
Python program:
def countSmaller ( str ) :
    n = len ( str ) ;
    for i in range ( n ) :
        cnt = 0 ;
        for j in range ( i + 1 , n ) :
            if ( str [ j ] < str [ i ] ) :
                cnt += 1 ;
        print ( cnt , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    str = " edcba " ;
    countSmaller ( str ) ;

Index/key variables: i, j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
import sys
def smallestSumpair ( arr , n ) :
    pair = [ ]
    min_sum = sys . maxsize
    for i in range ( 1 , n ) :
        if min_sum > ( arr [ i ] + arr [ i - 1 ] ) :
            min_sum = arr [ i ] + arr [ i - 1 ]
            if pair == [ ] :
                pair . append ( arr [ i - 1 ] )
                pair . append ( arr [ i ] )
            else :
                pair [ 0 ] = arr [ i - 1 ]
                pair [ 1 ] = arr [ i ]
    return pair
arr = [ 4 , 9 , - 3 , 2 , 0 ]
n = len ( arr )
pair = smallestSumpair ( arr , n )
print ( pair [ 0 ] , pair [ 1 ] )

Index/key variables: i
Accumulator variables: pair
Iterator variables: i
Python program:
def sumOfProductOfDigits ( n1 , n2 ) :
    sum1 = 0 ;
    while ( n1 > 0 and n2 > 0 ) :
        sum1 += ( ( n1 % 10 ) * ( n2 % 10 ) ) ;
        n1 = n1 // 10 ;
        n2 = n2 // 10 ;
    return sum1 ;
n1 = 25 ;
n2 = 1548 ;
print ( sumOfProductOfDigits ( n1 , n2 ) ) ;

Accumulator variables: sum1
Python program:
import math
n = 500000 - 2
v = [ ]
def sieveoferanthones ( ) :
    prime = [ 1 ] * ( n + 1 )
    for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) :
        if ( prime [ i ] != 0 ) :
            for j in range ( i * i , n + 1 , i ) :
                prime [ j ] = False
    for i in range ( 2 , n ) :
        if ( prime [ i ] != 0 ) :
            v . append ( i )
def numberOfWays ( n ) :
    count = 0
    j = 1
    while ( 2 * ( pow ( j , 2 ) ) < n ) :
        i = 1
        while ( v [ i ] + 2 <= n ) :
            if ( n == v [ i ] + ( 2 * ( math . pow ( j , 2 ) ) ) ) :
                count += 1
            i += 1
        j += 1
    print ( count )
sieveoferanthones ( )
n = 9
numberOfWays ( n )

Index/key variables: i, j
Accumulator variables: count, v
Iterator variables: i, j
Python program:
def bcdToHexaDecimal ( s ) :
    len1 = len ( s )
    check = 0
    num = 0
    sum = 0
    mul = 1
    ans = [ ]
    i = len1 - 1
    while ( i >= 0 ) :
        sum += ( ord ( s [ i ] ) - ord ( '0' ) ) * mul
        mul *= 2
        check += 1
        if ( check == 4 or i == 0 ) :
            if ( sum <= 9 ) :
                ans . append ( chr ( sum + ord ( '0' ) ) )
            else :
                ans . append ( chr ( sum + 55 ) ) ;
            check = 0
            sum = 0
            mul = 1
        i -= 1
    len1 = len ( ans )
    i = len1 - 1
    while ( i >= 0 ) :
        print ( ans [ i ] , end = " " )
        i -= 1
if __name__ == ' _ _ main _ _ ' :
    s = "100000101111"
    bcdToHexaDecimal ( s )

Index/key variables: i
Accumulator variables: ans, check, mul, sum
Python program:
graph = [ [ ] for i in range ( 100 ) ]
weight = [ 0 ] * 100
ans = 0
def isPerfect ( n ) :
    sum = 1 ;
    i = 2 ;
    while ( i * i < n ) :
        if ( n % i == 0 ) :
            if ( i * i != n ) :
                sum = sum + i + n / i ;
            else :
                sum = sum + i ;
        i += 1 ;
    if ( sum == n and n != 1 ) :
        return True ;
    return False ;
def dfs ( Node , parent ) :
    global ans ;
    if ( isPerfect ( weight [ Node ] ) ) :
        ans += 1 ;
    for to in graph [ Node ] :
        if ( to == parent ) :
            continue ;
        dfs ( to , Node ) ;
weight [ 1 ] = 5 ;
weight [ 2 ] = 10 ;
weight [ 3 ] = 11 ;
weight [ 4 ] = 8 ;
weight [ 5 ] = 6 ;
graph [ 1 ] . append ( 2 ) ;
graph [ 2 ] . append ( 3 ) ;
graph [ 2 ] . append ( 4 ) ;
graph [ 1 ] . append ( 5 ) ;
dfs ( 1 , 1 ) ;
print ( ans ) ;

Index/key variables: Node
Accumulator variables: i
Iterator variables: to
Python program:
def GetMinCost ( N ) :
    pq = [ ]
    for i in range ( 1 , N + 1 , 1 ) :
        pq . append ( i )
    pq . sort ( reverse = False )
    cost = 0
    while ( len ( pq ) > 1 ) :
        mini = pq [ 0 ]
        pq . remove ( pq [ 0 ] )
        secondmini = pq [ 0 ]
        pq . remove ( pq [ 0 ] )
        current = mini * secondmini
        cost += current
        pq . append ( current )
        pq . sort ( reverse = False )
    return cost
if __name__ == ' _ _ main _ _ ' :
    N = 5
    print ( GetMinCost ( N ) )

Accumulator variables: cost, pq
Iterator variables: i
Python program:
import math ;
def numPrimeArrangements ( n ) :
    prime = [ True for i in range ( n + 1 ) ]
    prime [ 0 ] = False
    prime [ 1 ] = False
    for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) :
        if prime [ i ] :
            factor = 2
            while factor * i <= n :
                prime [ factor * i ] = False
                factor += 1
    primeIndices = 0
    for i in range ( 1 , n + 1 ) :
        if prime [ i ] :
            primeIndices += 1
    mod = 1000000007
    res = 1
    for i in range ( 1 , primeIndices + 1 ) :
        res = ( res * i ) % mod
    for i in range ( 1 , n - primeIndices + 1 ) :
        res = ( res * i ) % mod
    return res
if __name__ == ' _ _ main _ _ ' :
    N = 5
    print ( numPrimeArrangements ( N ) )

Index/key variables: i
Accumulator variables: factor, primeIndices
Iterator variables: i
Python program:
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
def count_heads ( n , r ) :
    output = fact ( n ) / ( fact ( r ) * fact ( n - r ) )
    output = output / ( pow ( 2 , n ) )
    return output
n = 4
r = 3
print ( count_heads ( n , r ) )

Iterator variables: i
Python program:
from math import gcd
def dfs ( u , adj , vis ) :
    vis [ u ] = 1
    componentSize = 1
    for x in adj [ u ] :
        if ( vis [ x ] == 0 ) :
            componentSize += dfs ( x , adj , vis )
    return componentSize
def maximumComponentSize ( a , n ) :
    adj = [ [ ] for i in range ( n ) ]
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( gcd ( a [ i ] , a [ j ] ) > 1 ) :
                adj [ i ] . append ( j )
            adj [ j ] . append ( i )
    answer = 0
    vis = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        if ( vis [ i ] == False ) :
            answer = max ( answer , dfs ( i , adj , vis ) )
    return answer
if __name__ == ' _ _ main _ _ ' :
    n = 8
    A = [ 2 , 3 , 6 , 7 , 4 , 12 , 21 , 39 ]
    print ( maximumComponentSize ( A , n ) )

Index/key variables: i, j, u, x
Accumulator variables: componentSize
Iterator variables: i, j, x
Python program:
spf = [ 0 for i in range ( 100005 ) ]
def sieve ( ) :
    for i in range ( 2 , 100005 ) :
        if ( spf [ i ] == 0 ) :
            spf [ i ] = i ;
            for j in range ( 2 * i , 100005 , i ) :
                if ( spf [ j ] == 0 ) :
                    spf [ j ] = i ;
def factorize ( n , s ) :
    while ( n > 1 ) :
        z = spf [ n ] ;
        s . add ( z ) ;
        while ( n % z == 0 ) :
            n //= z ;
id = [ 0 for i in range ( 100005 ) ]
par = [ 0 for i in range ( 100005 ) ]
sizeContainer = [ 0 for i in range ( 100005 ) ]
def root ( i ) :
    if ( par [ i ] == i ) :
        return i ;
    else :
        return root ( par [ i ] ) ;
        return par [ i ]
def merge ( a , b ) :
    p = root ( a ) ;
    q = root ( b ) ;
    if ( p == q ) :
        return ;
    if ( sizeContainer [ p ] > sizeContainer [ q ] ) :
        p = p + q ;
        q = p - q ;
        p = p - q ;
    par [ p ] = q ;
    sizeContainer [ q ] += sizeContainer [ p ] ;
def maximumComponentsizeContainer ( a , n ) :
    for i in range ( 100005 ) :
        par [ i ] = i ;
        sizeContainer [ i ] = 1 ;
    sieve ( ) ;
    for i in range ( n ) :
        s = set ( )
        factorize ( a [ i ] , s ) ;
        for it in s :
            if ( id [ it ] == 0 ) :
                id [ it ] = i + 1 ;
            else :
                merge ( i + 1 , id [ it ] ) ;
    answer = 0 ;
    for i in range ( n ) :
        answer = max ( answer , sizeContainer [ i ] ) ;
    return answer ;
if __name__ == ' _ _ main _ _ ' :
    n = 8 ;
    A = [ 2 , 3 , 6 , 7 , 4 , 12 , 21 , 39 ]
    print ( maximumComponentsizeContainer ( A , n ) ) ;

Index/key variables: i, it, j, n, p, q
Accumulator variables: s
Iterator variables: i, it, j
Python program:
from collections import deque
N = 1000000
prime = [ ]
def SieveOfEratosthenes ( ) -> None :
    check = [ True for _ in range ( N + 1 ) ]
    p = 2
    while p * p <= N :
        if ( check [ p ] ) :
            prime . append ( p )
            for i in range ( p * p , N + 1 , p ) :
                check [ i ] = False
        p += 1
class Node :
    def __init__ ( self , key : int ) -> None :
        self . key = key
        self . left = None
        self . right = None
def IsChilrenPrimeFactor ( parent : Node , a : Node ) -> bool :
    if ( prime [ a . key ] and ( parent . key % a . key == 0 ) ) :
        return True
    else :
        return False
def GetCount ( node : Node ) -> int :
    if ( not node ) :
        return 0
    q = deque ( )
    count = 0
    q . append ( node )
    while q :
        temp = q . popleft ( )
        if ( temp . left == None and temp . right != None ) :
            if ( IsChilrenPrimeFactor ( temp , temp . right ) ) :
                count += 1
        else :
            if ( temp . right == None and temp . left != None ) :
                if ( IsChilrenPrimeFactor ( temp , temp . left ) ) :
                    count += 1
            else :
                if ( temp . left != None and temp . right != None ) :
                    if ( IsChilrenPrimeFactor ( temp , temp . right ) and IsChilrenPrimeFactor ( temp , temp . left ) ) :
                        count += 1
        if ( temp . left != None ) :
            q . append ( temp . left )
        if ( temp . right != None ) :
            q . append ( temp . right )
    return count
if __name__ == " _ _ main _ _ " :
    root = Node ( 10 )
    root . left = Node ( 2 )
    root . right = Node ( 5 )
    root . right . left = Node ( 18 )
    root . right . right = Node ( 12 )
    root . right . left . left = Node ( 2 )
    root . right . left . right = Node ( 3 )
    root . right . right . left = Node ( 3 )
    root . right . right . right = Node ( 14 )
    root . right . right . right . left = Node ( 7 )
    SieveOfEratosthenes ( )
    print ( GetCount ( root ) )

Index/key variables: i, p
Accumulator variables: count, prime, q
Iterator variables: i
Class/struct names: Node
Python program:
def check ( Arr , n , M , K ) :
    flag = 0
    for i in range ( n ) :
        if ( Arr [ i ] == 0 ) :
            flag = 1
    if ( K % 2 != 0 and flag == 0 ) :
        return " No "
    else :
        return " Yes " ;
if __name__ == ' _ _ main _ _ ' :
    Arr = [ 1 , 1 , 2 , 4 , 7 , 8 ]
    M = 5 ;
    K = 6 ;
    n = len ( Arr ) ;
    print ( check ( Arr , n , M , K ) )

Index/key variables: i
Iterator variables: i
Python program:
from math import sqrt , gcd
import numpy as np
def factor ( n ) :
    base = [ 2 , 3 , 5 , 7 ]
    start = int ( sqrt ( n ) )
    pairs = [ ]
    for i in range ( start , n ) :
        for j in range ( len ( base ) ) :
            lhs = i ** 2 % n
            rhs = base [ j ] ** 2 % n
            if ( lhs == rhs ) :
                pairs . append ( [ i , base [ j ] ] )
    new = [ ]
    for i in range ( len ( pairs ) ) :
        factor = gcd ( pairs [ i ] [ 0 ] - pairs [ i ] [ 1 ] , n )
        if ( factor != 1 ) :
            new . append ( factor )
    x = np . array ( new )
    return ( np . unique ( x ) )
if __name__ == " _ _ main _ _ " :
    print ( factor ( 23449 ) )

Index/key variables: i, j
Accumulator variables: new, pairs
Iterator variables: i, j
Python program:
pref = [ 0 ] * 100001
def checkArmstrong ( x ) :
    n = len ( str ( x ) )
    sum1 = 0
    temp = x
    while temp > 0 :
        digit = temp % 10
        sum1 += digit ** n
        temp //= 10
    if sum1 == x :
        return x
    return 0
def preCompute ( ) :
    for i in range ( 1 , 100001 ) :
        pref [ i ] = pref [ i - 1 ] + checkArmstrong ( i )
def printSum ( L , R ) :
    print ( pref [ R ] - pref [ L - 1 ] )
def printSumarmstrong ( arr , Q ) :
    preCompute ( )
    for i in range ( Q ) :
        printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] )
Q = 2
arr = [ [ 1 , 13 ] , [ 121 , 211 ] ]
printSumarmstrong ( arr , Q )

Index/key variables: R, i
Accumulator variables: sum1, temp
Iterator variables: i
Python program:
prime = [ 0 ] * 100001
k = [ 0 ] * 100001
def Sieve ( ) :
    for i in range ( 1 , 100001 ) :
        k [ i ] = i
    for i in range ( 2 , 100001 ) :
        if ( prime [ i ] == 0 ) :
            for j in range ( i , 100001 , i ) :
                prime [ j ] = 1
                while ( k [ j ] % ( i * i ) == 0 ) :
                    k [ j ] /= ( i * i )
def countPairs ( arr , n ) :
    freq = dict ( )
    for i in range ( n ) :
        if k [ arr [ i ] ] in freq . keys ( ) :
            freq [ k [ arr [ i ] ] ] += 1
        else :
            freq [ k [ arr [ i ] ] ] = 1
    Sum = 0
    for i in freq :
        Sum += ( freq [ i ] * ( freq [ i ] - 1 ) ) / 2
    return Sum
arr = [ 1 , 2 , 4 , 8 , 5 , 6 ]
n = len ( arr )
Sieve ( )
print ( int ( countPairs ( arr , n ) ) )

Index/key variables: i, j
Accumulator variables: Sum
Iterator variables: i, j
Python program:
pref = [ 0 ] * 100010 ;
def isPerfectCube ( x ) :
    cr = round ( x ** ( 1 / 3 ) ) ;
    rslt = x if ( cr * cr * cr == x ) else 0 ;
    return rslt ;
def compute ( ) :
    for i in range ( 1 , 100001 ) :
        pref [ i ] = pref [ i - 1 ] + isPerfectCube ( i ) ;
def printSum ( L , R ) :
    sum = pref [ R ] - pref [ L - 1 ] ;
    print ( sum , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    compute ( ) ;
    Q = 4 ;
    arr = [ [ 1 , 10 ] , [ 1 , 100 ] , [ 2 , 25 ] , [ 4 , 50 ] ] ;
    for i in range ( Q ) :
        printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ;

Index/key variables: R, i
Iterator variables: i
Python program:
def binomialCoeff ( n , k ) :
    C = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ] ;
    i , j = 0 , 0 ;
    for i in range ( n + 1 ) :
        for j in range ( min ( i , k ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1 ;
            else :
                C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;
    return C [ n ] [ k ] ;
def count ( n , k ) :
    sum = 0 ;
    for j in range ( 1 , k + 1 ) :
        sum = sum + binomialCoeff ( n , j ) ;
    return sum ;
if __name__ == ' _ _ main _ _ ' :
    n = 3 ;
    k = 2 ;
    print ( count ( n , k ) , end = " " ) ;
    n1 = 5 ;
    k1 = 2 ;
    print ( count ( n1 , k1 ) ) ;

Index/key variables: i, j, k, n
Iterator variables: i, j
Python program:
def findNumber ( s , d ) :
    num = " "
    val = s // d
    rem = s % d
    for i in range ( 1 , d - rem + 1 ) :
        num = num + str ( val )
    if ( rem ) :
        val += 1
        for i in range ( d - rem + 1 , d + 1 ) :
            num = num + str ( val )
    return num
if __name__ == " _ _ main _ _ " :
    s = 25
    d = 4
    print ( findNumber ( s , d ) )

Iterator variables: i
Python program:
def fastmod ( base , exp , mod ) :
    if ( exp == 0 ) :
        return 1 ;
    elif ( exp % 2 == 0 ) :
        ans = fastmod ( base , exp / 2 , mod ) ;
        return ( ans % mod * ans % mod ) % mod ;
    else :
        return ( fastmod ( base , exp - 1 , mod ) % mod * base % mod ) % mod ;
def findPowerSum ( n , ar ) :
    mod = int ( 1e9 ) + 7 ;
    sum = 0 ;
    for i in range ( n ) :
        base = bin ( ar [ i ] ) . count ( '1' ) ;
        exp = ar [ i ] ;
        sum += fastmod ( base , exp , mod ) ;
        sum %= mod ;
    return sum ;
if __name__ == " _ _ main _ _ " :
    n = 3 ;
    ar = [ 1 , 2 , 3 ] ;
    print ( findPowerSum ( n , ar ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def sub_arrays ( a , n , k ) :
    sum = [ 0 for i in range ( n + 2 ) ]
    for i in range ( n ) :
        a [ i ] -= 1
        a [ i ] %= k
        sum [ i + 1 ] += sum [ i ] + a [ i ]
        sum [ i + 1 ] %= k
    ans = 0
    l = 0
    r = 0
    mp = dict ( )
    for i in range ( n + 1 ) :
        if sum [ i ] in mp :
            ans += mp [ sum [ i ] ]
        mp [ sum [ i ] ] = mp . get ( sum [ i ] , 0 ) + 1
        r += 1
        if ( r - l >= k ) :
            mp [ sum [ l ] ] -= 1
            l += 1
    return ans
a = [ 1 , 4 , 2 , 3 , 5 ]
n = len ( a )
k = 4
print ( sub_arrays ( a , n , k ) )

Index/key variables: i, l
Accumulator variables: ans, r
Iterator variables: i
Python program:
from math import sqrt , pow
def sieve ( prime , n ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , n + 1 , p ) :
                prime [ i ] = False
def sumPrime ( d ) :
    maxVal = int ( pow ( 2 , d ) ) - 1 ;
    prime = [ True for i in range ( maxVal + 1 ) ]
    sieve ( prime , maxVal )
    sum = 0
    for i in range ( 2 , maxVal + 1 , 1 ) :
        if ( prime [ i ] ) :
            sum += i
    return sum
if __name__ == ' _ _ main _ _ ' :
    d = 8
    print ( sumPrime ( d ) )

Index/key variables: i, p
Accumulator variables: sum
Iterator variables: i, p
Python program:
from math import gcd as __gcd
def isPossible ( arr , n , p ) :
    gcd = 0 ;
    for i in range ( n ) :
        gcd = __gcd ( gcd , arr [ i ] ) ;
    if ( p % gcd == 0 ) :
        return True ;
    return False ;
if __name__ == " _ _ main _ _ " :
    arr = [ 6 , 9 ] ;
    n = len ( arr ) ;
    p = 3 ;
    if ( isPossible ( arr , n , p ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Iterator variables: i
Python program:
from math import ceil , floor
def printArr ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
def generateArr ( arr , n ) :
    flip = True
    for i in range ( n ) :
        if ( arr [ i ] & 1 ) :
            flip ^= True
            if ( flip ) :
                print ( int ( ceil ( ( arr [ i ] ) / 2 ) ) , end = " ▁ " )
            else :
                print ( int ( floor ( ( arr [ i ] ) / 2 ) ) , end = " ▁ " )
        else :
            print ( int ( arr [ i ] / 2 ) , end = " ▁ " )
arr = [ 3 , - 5 , - 7 , 9 , 2 , - 2 ]
n = len ( arr )
generateArr ( arr , n )

Index/key variables: i
Accumulator variables: flip
Iterator variables: i
Boolean variables: flip
Python program:
def binomialCoeff ( n , k ) :
    C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( k + 1 ) ]
    for i in range ( 0 , n + 1 ) :
        for j in range ( 0 , min ( i , k ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]
    return C [ n ] [ k ]
def cntSubSeq ( arr , n , k ) :
    arr . sort ( )
    num = arr [ k - 1 ] ;
    Y = 0 ;
    for i in range ( k - 1 , - 1 , 1 ) :
        if ( arr [ i ] == num ) :
            Y += 1
    cntX = Y ;
    for i in range ( k , n ) :
        if ( arr [ i ] == num ) :
            cntX += 1
    return binomialCoeff ( cntX , Y )
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
k = 2
print ( cntSubSeq ( arr , n , k ) )

Index/key variables: i, j, k, n
Accumulator variables: Y, cntX
Iterator variables: i, j
Python program:
def convertToBinary ( num , a , n ) :
    pointer = n - 1
    while ( num > 0 ) :
        a [ pointer ] = num % 2
        num = num // 2
        pointer -= 1
def checkforsum ( a , n ) :
    sum1 = 0
    sum2 = 0
    mid = n // 2
    for i in range ( mid ) :
        sum1 = sum1 + a [ i ]
    for j in range ( mid , n ) :
        sum2 = sum2 + a [ j ]
    if ( sum1 == sum2 ) :
        for i in range ( n ) :
            print ( a [ i ] , end = " " )
        print ( )
def print_seq ( m ) :
    n = ( 2 * m )
    a = [ 0 for i in range ( n ) ]
    for i in range ( pow ( 2 , n ) ) :
        convertToBinary ( i , a , n )
        checkforsum ( a , n )
m = 2
print_seq ( m )

Index/key variables: i, j, pointer
Iterator variables: i, j
Python program:
from math import gcd , sqrt
def coprime ( a , b ) :
    if ( gcd ( a , b ) == 1 ) :
        return True ;
    else :
        return False ;
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False ;
    if ( n == 2 or n == 3 ) :
        return True ;
    for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            return False ;
    return True ;
def findNumbers ( a , b , n ) :
    possible = True ;
    if ( not coprime ( a , b ) ) :
        possible = False ;
    c1 = 1 ;
    c2 = 1 ;
    num1 = 0 ;
    num2 = 0 ;
    st = set ( ) ;
    if ( possible ) :
        while ( len ( st ) != n ) :
            num1 = a + ( c1 * b ) ;
            if ( isPrime ( num1 ) ) :
                st . add ( num1 ) ;
            c1 += 1 ;
            num2 = b + ( c2 * a ) ;
            if ( isPrime ( num2 ) ) :
                st . add ( num2 ) ;
            c2 += 1 ;
        for i in st :
            print ( i , end = " ▁ " ) ;
    else :
        print ( " - 1" ) ;
if __name__ == " _ _ main _ _ " :
    a = 3 ;
    b = 5 ;
    n = 4 ;
    findNumbers ( a , b , n ) ;

Accumulator variables: c1, c2, st
Iterator variables: i
Boolean variables: possible
Python program:
def findIntegers ( n , a , x , t1 , t2 ) :
    flag = True
    for i in range ( n ) :
        temp = pow ( a [ i ] , 2 ) + x
        if ( temp % 10 != t1 and temp % 10 != t2 ) :
            print ( temp , end = " ▁ " )
            flag = False
    if flag :
        print ( - 1 )
N , X , T1 , T2 = 4 , 10 , 5 , 6
a = [ 3 , 1 , 4 , 7 ]
findIntegers ( N , a , X , T1 , T2 ) ;
print ( )
N , X , T1 , T2 = 4 , 2 , 5 , 6
b = [ 2 , 18 , 22 , 8 ]
findIntegers ( N , b , X , T1 , T2 )

Index/key variables: i
Iterator variables: i
Boolean variables: flag