dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countPairs ( arr , n ) :
    countZero = 0 ;
    countTwo = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] == 0 ) :
            countZero += 1 ;
        elif ( arr [ i ] == 2 ) :
            countTwo += 1 ;
    pair0 = ( countZero * ( countZero - 1 ) ) // 2 ;
    pair2 = ( countTwo * ( countTwo - 1 ) ) // 2 ;
    return pair0 + pair2 ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 0 , 3 , 2 , 0 ] ;
    n = len ( arr ) ;
    print ( countPairs ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: countTwo, countZero
Iterator variables: i
Python program:
import math
def cntSubSeq ( arr , n ) :
    pos_count = 0 ;
    neg_count = 0
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            pos_count += 1
        if ( arr [ i ] < 0 ) :
            neg_count += 1
    result = int ( math . pow ( 2 , pos_count ) )
    if ( neg_count > 0 ) :
        result *= int ( math . pow ( 2 , neg_count - 1 ) )
    result -= 1
    return result
arr = [ 2 , - 3 , - 1 , 4 ]
n = len ( arr ) ;
print ( cntSubSeq ( arr , n ) )

Index/key variables: i
Accumulator variables: neg_count, pos_count
Iterator variables: i
Python program:
def findMin ( arr , n ) :
    m = 0
    for i in range ( n ) :
        m = max ( m , arr [ i ] )
    freq = [ 0 ] * ( m + 2 )
    for i in range ( n ) :
        freq [ arr [ i ] ] += 1
    for i in range ( 1 , m + 2 ) :
        j = i
        cnt = 0
        while ( j <= m ) :
            cnt += freq [ j ]
            j += i
        if ( not cnt ) :
            return i
    return m + 1
arr = [ 2 , 12 , 6 ]
n = len ( arr )
print ( findMin ( arr , n ) )

Index/key variables: i, j
Accumulator variables: cnt
Iterator variables: i
Python program:
def findMin ( arr , n ) :
    m = 0
    for i in range ( n ) :
        m = max ( m , arr [ i ] )
    cnt = [ 0 ] * ( m + 2 )
    for i in range ( n ) :
        j = 1
        while j * j <= arr [ i ] :
            if ( arr [ i ] % j == 0 ) :
                if ( j * j == arr [ i ] ) :
                    cnt [ j ] += 1
                else :
                    cnt [ j ] += 1
                    cnt [ arr [ i ] // j ] += 1
            j += 1
    for i in range ( 1 , m + 2 ) :
        if ( cnt [ i ] == 0 ) :
            return i
    return - 1
arr = [ 2 , 12 , 6 ]
n = len ( arr )
print ( findMin ( arr , n ) )

Index/key variables: i, j
Iterator variables: i
Python program:
sz = 10 ** 5
isPrime = [ True for i in range ( sz + 1 ) ]
def sieve ( ) :
    isPrime [ 0 ] = isPrime [ 1 ] = False
    i = 2
    while i * i < sz :
        if ( isPrime [ i ] ) :
            for j in range ( i * i , sz , i ) :
                isPrime [ j ] = False
        i += 1
def prArray ( arr , lenn ) :
    for i in range ( lenn ) :
        print ( arr [ i ] , end = " ▁ " )
def removePrimes ( arr , lenn ) :
    sieve ( )
    i = 0
    while i < lenn :
        if ( isPrime [ arr [ i ] ] ) :
            for j in range ( i , lenn - 1 ) :
                arr [ j ] = arr [ j + 1 ]
            i -= 1
            lenn -= 1
        i += 1
    prArray ( arr , lenn )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 6 , 5 , 3 , 8 , 7 , 10 , 11 , 14 , 15 ]
    lenn = len ( arr )
    removePrimes ( arr , lenn )

Index/key variables: i, j
Accumulator variables: lenn
Iterator variables: i, j
Python program:
from math import sqrt
def subgrids ( N , Z , row , col , r , d ) :
    conrow = [ ] ;
    concol = [ ] ;
    K = int ( sqrt ( Z ) ) ;
    conrow . append ( row [ 0 ] - 0 - 1 )
    conrow . append ( N + 1 - row [ r - 1 ] - 1 )
    for i in range ( 1 , r ) :
        conrow . append ( row [ i ] - row [ i - 1 ] - 1 ) ;
    concol . append ( col [ 0 ] - 0 - 1 )
    concol . append ( N + 1 - col [ d - 1 ] - 1 )
    for i in range ( 1 , d ) :
        concol . append ( col [ i ] - col [ i - 1 ] - 1 ) ;
    row_size = len ( conrow )
    col_size = len ( concol )
    answer = 0
    for i in range ( row_size ) :
        for j in range ( col_size ) :
            total = ( concol [ j ] // K ) * ( conrow [ i ] // K )
            answer += ( total )
    return answer
if __name__ == " _ _ main _ _ " :
    N = 8 ; Z = 4
    row = [ 4 , 6 ]
    col = [ 3 , 8 ]
    r = len ( row )
    d = len ( col )
    print ( subgrids ( N , Z , row , col , r , d ) )

Index/key variables: i, j
Accumulator variables: answer, concol, conrow
Iterator variables: i, j
Python program:
def countDigits ( n ) :
    cnt = 0
    while ( n > 0 ) :
        cnt += 1
        n //= 10
    return cnt
def digitPowSum ( n ) :
    sum = 0
    pw = countDigits ( n )
    while ( n > 0 ) :
        d = n % 10
        sum += pow ( d , pw )
        pw -= 1
        n //= 10
    return sum
def countNum ( n ) :
    count = 0
    for i in range ( n + 1 ) :
        if ( i == digitPowSum ( i ) ) :
            count += 1
    return count
n = 200
print ( countNum ( n ) )

Accumulator variables: cnt, count, n, pw, sum
Iterator variables: i
Python program:
def perfectSquares ( l , r ) :
    for i in range ( l , r + 1 ) :
        if ( i ** ( .5 ) == int ( i ** ( .5 ) ) ) :
            print ( i , end = " ▁ " )
l = 2
r = 24
perfectSquares ( l , r )

Iterator variables: i
Python program:
from math import ceil , sqrt
def perfectSquares ( l , r ) :
    number = ceil ( sqrt ( l ) ) ;
    n2 = number * number ;
    number = ( number * 2 ) + 1 ;
    while ( ( n2 >= l and n2 <= r ) ) :
        print ( n2 , end = " ▁ " ) ;
        n2 = n2 + number ;
        number += 2 ;
if __name__ == " _ _ main _ _ " :
    l = 2 ; r = 24 ;
    perfectSquares ( l , r ) ;

Accumulator variables: number
Python program:
def xorK ( n , k ) :
    res = n
    for i in range ( 1 , k ) :
        res = ( res ^ n )
    return n
n = 123
k = 3
print ( xorK ( n , k ) )

Iterator variables: i
Python program:
from math import ceil , floor , sqrt
def findRemainders ( n ) :
    vc = dict ( )
    for i in range ( 1 , ceil ( sqrt ( n ) ) + 1 ) :
        vc [ n // i ] = 1
    for i in range ( n // ceil ( sqrt ( n ) ) - 1 , - 1 , - 1 ) :
        vc [ i ] = 1
    for it in sorted ( vc ) :
        print ( it , end = " ▁ " )
n = 5
findRemainders ( n )

Index/key variables: i
Iterator variables: i, it
Python program:
MAX = 100005
prime = [ True for i in range ( MAX ) ]
def SieveOfEratosthenes ( ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( MAX ) :
        if ( p * p > MAX ) :
            break
        if ( prime [ p ] ) :
            for i in range ( 2 * p , MAX , p ) :
                prime [ i ] = False
def countPrimes ( n ) :
    SieveOfEratosthenes ( )
    cnt = 0
    for i in range ( 2 , n ) :
        if ( prime [ i ] and prime [ i - 2 ] ) :
            cnt += 1
    return cnt
n = 11
print ( countPrimes ( n ) )

Index/key variables: i, p
Accumulator variables: cnt
Iterator variables: i, p
Python program:
MAX_VALID_YR = 9999
MIN_VALID_YR = 1800
def isLeap ( year ) :
    return ( ( ( year % 4 == 0 ) and ( year % 100 != 0 ) ) or ( year % 400 == 0 ) )
def isValidDate ( d , m , y ) :
    if ( y > MAX_VALID_YR or y < MIN_VALID_YR ) :
        return False
    if ( m < 1 or m > 12 ) :
        return False
    if ( d < 1 or d > 31 ) :
        return False
    if ( m == 2 ) :
        if ( isLeap ( y ) ) :
            return ( d <= 29 )
        else :
            return ( d <= 28 )
    if ( m == 4 or m == 6 or m == 9 or m == 11 ) :
        return ( d <= 30 )
    return True
def printPalindromeDates ( y1 , y2 ) :
    for year in range ( y1 , y2 + 1 , 1 ) :
        str1 = str ( year )
        rev = str1
        rev = rev [ : : - 1 ]
        day = int ( rev [ 0 : 2 ] )
        month = int ( rev [ 2 : 4 ] )
        rev += str1
        if ( isValidDate ( day , month , year ) ) :
            print ( rev )
if __name__ == ' _ _ main _ _ ' :
    y1 = 2001
    y2 = 2005
    printPalindromeDates ( y1 , y2 )

Accumulator variables: rev
Iterator variables: year
Python program:
import sys
MAX = 10
def distinctDigits ( x ) :
    present = [ False for i in range ( MAX ) ]
    while ( x > 0 ) :
        digit = x % 10
        if ( present [ digit ] ) :
            return False
        present [ digit ] = True
        x = x // 10
    return True
def findK ( l , r ) :
    maxExp = - sys . maxsize - 1
    k = - 1
    for i in range ( l , r + 1 , 1 ) :
        if ( distinctDigits ( i ) ) :
            exp = ( l - i ) * ( i - r )
            if ( exp >= maxExp ) :
                k = i ;
                maxExp = exp
    return k
if __name__ == ' _ _ main _ _ ' :
    l = 50
    r = 60
    print ( findK ( l , r ) )

Index/key variables: digit
Iterator variables: i
Python program:
def Hex ( num ) :
    m = dict . fromkeys ( range ( 16 ) , 0 ) ;
    digit = ord ( '0' ) ;
    c = ord ( ' a ' ) ;
    for i in range ( 16 ) :
        if ( i < 10 ) :
            m [ i ] = chr ( digit ) ;
            digit += 1 ;
        else :
            m [ i ] = chr ( c ) ;
            c += 1
    res = " " ;
    if ( not num ) :
        return "0" ;
    if ( num > 0 ) :
        while ( num ) :
            res = m [ num % 16 ] + res ;
            num //= 16 ;
    else :
        n = num + 2 ** 32 ;
        while ( n ) :
            res = m [ n % 16 ] + res ;
            n //= 16 ;
    return res ;
if __name__ == " _ _ main _ _ " :
    x = 134 ; y = - 1 ; z = - 234 ;
    print ( " Hexa ▁ representation ▁ for " ) ;
    print ( x , " is " , Hex ( x ) ) ;
    print ( y , " is " , Hex ( y ) ) ;
    print ( z , " is " , Hex ( z ) ) ;

Index/key variables: i
Accumulator variables: c, digit, n, num
Iterator variables: i
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_balls ( n , k ) :
    factorialfun ( ) ;
    modinversefun ( ) ;
    for i in range ( 1 , k + 1 ) :
        print ( ( binomial ( n - k + 1 , i ) * binomial ( k - 1 , i - 1 ) ) % mod , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    n = 5 ; k = 3 ;
    arrange_balls ( n , k ) ;

Index/key variables: i, n, r
Iterator variables: i
Python program:
def min_changes ( a , n ) :
    ans_a = 0 ;
    ans_b = 0 ;
    for i in range ( n ) :
        if ( i % 2 == 0 ) :
            if ( a [ i ] == 0 ) :
                ans_a += 1 ;
            else :
                ans_b += 1 ;
        else :
            if ( a [ i ] == 0 ) :
                ans_b += 1 ;
            else :
                ans_a += 1 ;
    return min ( ans_a , ans_b ) ;
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 ] ;
    n = len ( a ) ;
    print ( min_changes ( a , n ) ) ;

Index/key variables: i
Accumulator variables: ans_a, ans_b
Iterator variables: i
Python program:
def minNum ( num , k ) :
    len_ = len ( num )
    if len_ == 0 or k == 0 :
        return num
    if len_ == 1 :
        return "0"
    if num [ 0 ] != '1' :
        num = '1' + num [ 1 : ]
        k -= 1
    i = 1
    while k > 0 and i < len_ :
        if num [ i ] != '0' :
            num = num [ : i ] + '0' + num [ i + 1 : ]
            k -= 1
        i += 1
    return num
num = "91945"
k = 3
print ( minNum ( num , k ) )

Index/key variables: i
Accumulator variables: k
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
def removeLeadingZeros ( a ) :
    if ( a != None and a . data == 0 ) :
        return removeLeadingZeros ( a . next ) ;
    else :
        return a ;
def getSize ( a ) :
    sz = 0 ;
    while ( a != None ) :
        a = a . next ;
        sz += 1
    return sz ;
def push ( head_ref , new_data ) :
    new_node = Node ( )
    new_node . data = new_data ;
    new_node . next = ( head_ref ) ;
    ( head_ref ) = new_node ;
    return head_ref
def compare ( a , b ) :
    a = removeLeadingZeros ( a ) ;
    b = removeLeadingZeros ( b ) ;
    lenA = getSize ( a ) ;
    lenB = getSize ( b ) ;
    if ( lenA > lenB ) :
        return 1 ;
    elif ( lenB > lenA ) :
        return - 1 ;
    while ( a != None and b != None ) :
        if ( a . data > b . data ) :
            return 1 ;
        elif ( a . data < b . data ) :
            return - 1 ;
        a = a . next ;
        b = b . next ;
    return 0 ;
if __name__ == ' _ _ main _ _ ' :
    a = None ;
    a = push ( a , 7 ) ;
    a = push ( a , 6 ) ;
    a = push ( a , 5 ) ;
    b = None ;
    b = push ( b , 3 ) ;
    b = push ( b , 3 ) ;
    b = push ( b , 2 ) ;
    print ( compare ( a , b ) )

Accumulator variables: sz
Class/struct names: Node
Python program:
def sumArr ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    return sum
def sumModArr ( arr , n ) :
    for i in range ( n - 1 ) :
        subSum = 0
        for j in range ( i + 1 , n ) :
            subSum += arr [ j ]
        arr [ i ] -= subSum
    return sumArr ( arr , n )
arr = [ 40 , 25 , 12 , 10 ]
n = len ( arr )
print ( sumModArr ( arr , n ) )

Index/key variables: i, j
Accumulator variables: subSum, sum
Iterator variables: i, j
Python program:
from math import gcd
def minHealth ( health , n ) :
    __gcd = 0 ;
    for i in range ( n ) :
        __gcd = gcd ( __gcd , health [ i ] ) ;
    return __gcd ;
if __name__ == " _ _ main _ _ " :
    health = [ 5 , 6 , 1 , 2 , 3 , 4 ] ;
    n = len ( health ) ;
    print ( minHealth ( health , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
from math import sqrt
def printArr ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " ) ;
def constructArr ( pair , n ) :
    size = int ( ( 1 + sqrt ( 1 + 8 * n ) ) // 2 ) ;
    arr = [ 0 ] * ( size ) ;
    arr [ 0 ] = int ( sqrt ( ( pair [ 0 ] * pair [ 1 ] ) / pair [ size - 1 ] ) ) ;
    for i in range ( 1 , size ) :
        arr [ i ] = pair [ i - 1 ] // arr [ 0 ] ;
    printArr ( arr , size ) ;
if __name__ == " _ _ main _ _ " :
    pair = [ 48 , 18 , 24 , 24 , 32 , 12 ] ;
    n = len ( pair ) ;
    constructArr ( pair , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def findPairs ( arr , n ) :
    cntEven = 0 ; cntOdd = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] % 2 == 0 ) :
            cntEven += 1 ;
        else :
            cntOdd += 1 ;
    evenPairs = 0 ;
    evenPairs += ( ( cntEven * ( cntEven - 1 ) ) // 2 ) ;
    evenPairs += ( ( cntOdd * ( cntOdd - 1 ) ) // 2 ) ;
    oddPairs = 0 ;
    oddPairs += ( cntEven * cntOdd ) ;
    print ( " Odd ▁ pairs ▁ = ▁ " , oddPairs ) ;
    print ( " Even ▁ pairs ▁ = ▁ " , evenPairs ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    findPairs ( arr , n ) ;

Index/key variables: i
Accumulator variables: cntEven, cntOdd
Iterator variables: i
Python program:
MOD = 1000000007 ;
def factMod ( n ) :
    fact = 1 ;
    for i in range ( 2 , n + 1 ) :
        fact *= ( i % MOD ) ;
        fact %= MOD ;
    return fact ;
def countWays ( n , m ) :
    return factMod ( m ) ;
if __name__ == " _ _ main _ _ " :
    n = 2 ; m = 2 ;
    print ( countWays ( n , m ) ) ;

Accumulator variables: fact
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 res ;
def Fuss_catalan ( n ) :
    c = binomialCoeff ( 3 * n , n ) ;
    return c // ( 2 * n + 1 ) ;
if __name__ == " _ _ main _ _ " :
    for i in range ( 10 ) :
        print ( Fuss_catalan ( i ) , end = " ▁ " ) ;

Accumulator variables: res
Iterator variables: i
Python program:
from math import gcd , sqrt
def isComposite ( n ) :
    for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            return True ;
    return False ;
def Power ( x , y , p ) :
    res = 1 ;
    x = x % p ;
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p ;
        x = ( x * x ) % p ;
    return res ;
def isEulerPseudoprime ( N , A ) :
    if ( A <= 0 ) :
        return False ;
    if ( N % 2 == 0 or not isComposite ( N ) ) :
        return False ;
    if ( gcd ( A , N ) != 1 ) :
        return false ;
    mod = Power ( A , ( N - 1 ) // 2 , N ) ;
    if ( mod != 1 and mod != N - 1 ) :
        return False ;
    return True ;
if __name__ == " _ _ main _ _ " :
    N = 121 ; A = 3 ;
    if ( isEulerPseudoprime ( N , A ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Iterator variables: i
Python program:
from math import sqrt
sz = int ( 1e5 ) ;
isPrime = [ True ] * ( sz + 1 ) ;
def sieve ( ) :
    isPrime [ 0 ] = isPrime [ 1 ] = False ;
    for i in range ( 2 , int ( sqrt ( sz ) ) + 1 ) :
        if ( isPrime [ i ] ) :
            for j in range ( i * i , sz , i ) :
                isPrime [ j ] = False ;
def minDifference ( L , R ) :
    fst = 0 ;
    for i in range ( L , R + 1 ) :
        if ( isPrime [ i ] ) :
            fst = i ;
            break ;
    snd = 0 ;
    for i in range ( fst + 1 , R + 1 ) :
        if ( isPrime [ i ] ) :
            snd = i ;
            break ;
    if ( snd == 0 ) :
        return - 1 ;
    diff = snd - fst ;
    left = snd + 1 ;
    right = R ;
    for i in range ( left , right + 1 ) :
        if ( isPrime [ i ] ) :
            if ( i - snd <= diff ) :
                fst = snd ;
                snd = i ;
                diff = snd - fst ;
    return diff ;
if __name__ == " _ _ main _ _ " :
    sieve ( ) ;
    L = 21 ; R = 50 ;
    print ( minDifference ( L , R ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findCnt ( arr , n , k ) :
    ret = 0 ;
    i = 0 ;
    while ( i < n ) :
        j = i + 1 ;
        while ( j < n and arr [ j ] >= arr [ j - 1 ] ) :
            j += 1 ;
        x = max ( 0 , j - i - k ) ;
        ret += ( x * ( x + 1 ) ) / 2 ;
        i = j ;
    return ret ;
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 4 , 3 , 2 , 1 ] ;
    n = len ( arr ) ;
    k = 2 ;
    print ( findCnt ( arr , n , k ) ) ;

Index/key variables: j
Accumulator variables: ret
Python program:
def countElements ( p , n ) :
    ans = 0 ;
    for i in range ( 1 , n - 1 ) :
        if ( p [ i - 1 ] > p [ i ] and p [ i ] > p [ i + 1 ] ) :
            ans += 1 ;
        elif ( p [ i - 1 ] < p [ i ] and p [ i ] < p [ i + 1 ] ) :
            ans += 1 ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    p = [ 2 , 5 , 1 , 3 , 4 ] ;
    n = len ( p ) ;
    print ( countElements ( p , n ) ) ;

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def cntSubArrays ( arr , n , k ) :
    res = 0 ;
    i = 0 ;
    while ( i < n ) :
        j = i + 1 ;
        while ( j < n and arr [ j ] >= arr [ j - 1 ] ) :
            j += 1 ;
        res += max ( j - i - k + 1 , 0 ) ;
        i = j ;
    return res ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 2 , 5 ] ;
    n = len ( arr ) ;
    k = 2 ;
    print ( cntSubArrays ( arr , n , k ) ) ;

Index/key variables: j
Accumulator variables: res
Python program:
def cntPairs ( a , n ) :
    odd = 0 ; even = 0 ;
    for i in range ( n ) :
        if ( a [ i ] % 2 == 1 ) :
            odd += 1 ;
        elif ( ( a [ i ] / 2 ) % 2 == 1 ) :
            even += 1 ;
    ans = odd * even + ( odd * ( odd - 1 ) ) // 2 ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    a = [ 4 , 2 , 7 , 11 , 14 , 15 , 18 ] ;
    n = len ( a ) ;
    print ( cntPairs ( a , n ) ) ;

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
def isPossible ( a , n ) :
    cur = a [ 0 ] ;
    cur -= 1 ;
    for i in range ( 1 , n ) :
        nxt = a [ i ] ;
        if ( nxt > cur ) :
            nxt -= 1 ;
        elif ( nxt < cur ) :
            return False ;
        cur = nxt ;
    return True ;
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 1 , 2 , 3 ] ;
    n = len ( a ) ;
    if ( isPossible ( a , n ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Accumulator variables: nxt
Iterator variables: i
Python program:
def max_element ( a , n ) :
    pre = [ 0 ] * n ;
    pre [ 0 ] = a [ 0 ] ;
    for i in range ( 1 , n ) :
        pre [ i ] = max ( pre [ i - 1 ] , a [ i ] ) ;
    suf = [ 0 ] * n ;
    suf [ n - 1 ] = a [ n - 1 ] ;
    for i in range ( n - 2 , - 1 , - 1 ) :
        suf [ i ] = max ( suf [ i + 1 ] , a [ i ] ) ;
    for i in range ( n ) :
        if ( i == 0 ) :
            print ( suf [ i + 1 ] , end = " ▁ " ) ;
        elif ( i == n - 1 ) :
            print ( pre [ i - 1 ] , end = " ▁ " ) ;
        else :
            print ( max ( pre [ i - 1 ] , suf [ i + 1 ] ) , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 5 , 6 , 1 , 3 ] ;
    n = len ( a ) ;
    max_element ( a , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def isPossible ( a , n ) :
    k = 0 ;
    for i in range ( n ) :
        if ( a [ i ] != i + 1 ) :
            k += 1 ;
    if ( k <= 2 ) :
        return True ;
    return False ;
if __name__ == " _ _ main _ _ " :
    a = [ 5 , 2 , 3 , 4 , 1 ] ;
    n = len ( a ) ;
    if ( isPossible ( a , n ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Accumulator variables: k
Iterator variables: i
Python program:
def findMissing ( arr , n , k , avg ) :
    sum = 0 ;
    for i in range ( n ) :
        sum += arr [ i ] ;
    num = ( avg * ( n + k ) ) - sum ;
    den = k ;
    if ( num % den != 0 ) :
        return - 1 ;
    return ( int ) ( num / den ) ;
k = 3 ; avg = 4 ;
arr = [ 2 , 7 , 3 ] ;
n = len ( arr ) ;
print ( findMissing ( arr , n , k , avg ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def binomialCoeff ( n , k ) :
    if ( k == 0 or k == n ) :
        return 1
    return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )
def fact ( n ) :
    if ( n >= 1 ) :
        return n * fact ( n - 1 )
    else :
        return 1
def isVowel ( ch ) :
    if ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) :
        return True
    return False
def countWords ( s , p , q ) :
    countc = 0
    countv = 0
    for i in range ( len ( s ) ) :
        if ( isVowel ( s [ i ] ) ) :
            countv += 1
        else :
            countc += 1
    a = binomialCoeff ( countc , p )
    b = binomialCoeff ( countv , q )
    c = fact ( p + q )
    ans = ( a * b ) * c
    return ans
s = " crackathon "
p = 4
q = 3
print ( countWords ( s , p , q ) )

Index/key variables: i
Accumulator variables: countc, countv
Iterator variables: i
Python program:
def printArr ( arr , n ) :
    for i in arr :
        print ( i , end = " ▁ " )
def generateArr ( A , n ) :
    B = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        cnt = 0
        for j in range ( i ) :
            if ( A [ j ] % A [ i ] == 0 ) :
                cnt += 1
        B [ i ] = cnt
    printArr ( B , n )
A = [ 3 , 5 , 1 ]
n = len ( A )
generateArr ( A , n )

Index/key variables: i, j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
def product ( a , n ) :
    ans = 1
    val = pow ( 2 , n - 1 )
    for i in range ( n ) :
        ans *= pow ( a [ i ] , val )
    return ans
n = 2
a = [ 3 , 7 ]
print ( product ( a , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i