dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def nCr ( n , r ) :
    return ( fact ( n ) / ( fact ( r ) * fact ( n - r ) ) )
def fact ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
if __name__ == " _ _ main _ _ " :
    n = 5
    print ( int ( nCr ( n , 4 ) ) )

Iterator variables: i
Python program:
import math
pi = math . acos ( - 1.0 )
def nGon ( N ) :
    proAngleVar = 0
    if ( N % 4 == 0 ) :
        proAngleVar = ( pi * ( 180.0 / N ) / 180 )
    else :
        proAngleVar = ( pi * ( 180.0 / ( 2 * N ) ) / 180 )
    negX = 1.0e+99
    posX = - 1.0e+99
    negY = 1.0e+99
    posY = - 1.0e+99
    for j in range ( N ) :
        px = math . cos ( 2 * pi * j / N + proAngleVar )
        py = math . sin ( 2 * pi * j / N + proAngleVar )
        negX = min ( negX , px )
        posX = max ( posX , px )
        negY = min ( negY , py )
        posY = max ( posY , py )
    opt2 = max ( posX - negX , posY - negY )
    return ( opt2 / math . sin ( pi / N ) / 2 )
if __name__ == " _ _ main _ _ " :
    N = 10
    print ( ' % .5f ' % nGon ( N ) )

Iterator variables: j
Python program:
def numTrip ( points ) :
    res = 0
    for i in range ( len ( points ) ) :
        map = { }
        for j in range ( len ( points ) ) :
            if ( j == i ) :
                continue
            dy = points [ i ] [ 1 ] - points [ j ] [ 1 ]
            dx = points [ i ] [ 0 ] - points [ j ] [ 0 ]
            key = dy * dy
            key += dx * dx
            map [ key ] = map . get ( key , 0 ) + 1
        for p in map :
            res += map [ p ] * ( map [ p ] - 1 )
    return res
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 0 , 0 ] , [ 1 , 0 ] , [ 2 , 0 ] ]
    print ( numTrip ( mat ) )

Index/key variables: i, j, key, p
Accumulator variables: res
Iterator variables: i, j, p
Python program:
def NotParallel ( p , n ) :
    x_axis = { } ; y_axis = { } ;
    for i in range ( n ) :
        if p [ i ] [ 0 ] not in x_axis :
            x_axis [ p [ i ] [ 0 ] ] = 0 ;
        x_axis [ p [ i ] [ 0 ] ] += 1 ;
        if p [ i ] [ 1 ] not in y_axis :
            y_axis [ p [ i ] [ 1 ] ] = 0 ;
        y_axis [ p [ i ] [ 1 ] ] += 1 ;
    total = ( n * ( n - 1 ) ) // 2 ;
    for i in x_axis :
        c = x_axis [ i ] ;
        total -= ( c * ( c - 1 ) ) // 2 ;
    for i in y_axis :
        c = y_axis [ i ] ;
        total -= ( c * ( c - 1 ) ) // 2 ;
    return total ;
if __name__ == " _ _ main _ _ " :
    p = [ [ 1 , 2 ] , [ 1 , 5 ] , [ 1 , 15 ] , [ 2 , 10 ] ] ;
    n = len ( p ) ;
    print ( NotParallel ( p , n ) ) ;

Index/key variables: i
Accumulator variables: total
Iterator variables: i
Python program:
def times ( steps , n ) :
    current_level = 0
    previous_level = 0
    count = 0
    for i in range ( n ) :
        previous_level = current_level
        current_level = current_level + steps [ i ]
        if ( ( previous_level < 0 and current_level >= 0 ) or ( previous_level > 0 and current_level <= 0 ) ) :
            count += 1
    return count
steps = [ 1 , - 1 , 0 , 0 , 1 , 1 , - 3 , 2 ]
n = len ( steps )
print ( times ( steps , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def FindPoints ( n ) :
    v = [ ] ;
    v . append ( [ 0 , 0 ] ) ;
    v . append ( [ 0 , n ] ) ;
    v . append ( [ n , 0 ] ) ;
    v . append ( [ n , n ] ) ;
    if ( n % 2 == 0 ) :
        v . append ( [ n // 2 , n // 2 ] ) ;
    return v ;
if __name__ == " _ _ main _ _ " :
    N = 8 ;
    v = FindPoints ( N ) ;
    for element in v :
        print ( " ( " , element [ 0 ] , " , " , element [ 1 ] , " ) " , end = " ▁ " ) ;

Iterator variables: element
Python program:
dx = [ - 1 , 0 , 1 , 0 ]
dy = [ 0 , 1 , 0 , - 1 ]
def ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) :
    a = ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) )
    b = ( ( x1 - x3 ) * ( x1 - x3 ) ) + ( ( y1 - y3 ) * ( y1 - y3 ) )
    c = ( ( x2 - x3 ) * ( x2 - x3 ) ) + ( ( y2 - y3 ) * ( y2 - y3 ) )
    if ( ( a == ( b + c ) and a != 0 and b != 0 and c != 0 ) or ( b == ( a + c ) and a != 0 and b != 0 and c != 0 ) or ( c == ( a + b ) and a != 0 and b != 0 and c != 0 ) ) :
        return 1
def isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) :
    x , y = 0 , 0
    possible = 0
    if ( ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) ) :
        print ( " ALREADY ▁ RIGHT ▁ ANGLED " )
        return
    else :
        for i in range ( 4 ) :
            x = dx [ i ] + x1
            y = dy [ i ] + y1
            if ( ifRight ( x , y , x2 , y2 , x3 , y3 ) ) :
                print ( " POSSIBLE " )
                return
            x = dx [ i ] + x2
            y = dy [ i ] + y2
            if ( ifRight ( x1 , y1 , x , y , x3 , y3 ) ) :
                print ( " POSSIBLE " )
                return
            x = dx [ i ] + x3
            y = dy [ i ] + y3
            if ( ifRight ( x1 , y1 , x2 , y2 , x , y ) ) :
                print ( " POSSIBLE " )
                return
    if ( possible == 0 ) :
        print ( " NOT ▁ POSSIBLE " )
x1 = - 49
y1 = 0
x2 = 0
y2 = 50
x3 = 0
y3 = - 50
isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 )

Index/key variables: i
Iterator variables: i
Python program:
def isPerfect ( N ) :
    sumOfDivisors = 1 ;
    for i in range ( 2 , int ( N / 2 ) + 1 ) :
        if ( N % i == 0 ) :
            sumOfDivisors += i ;
    if ( sumOfDivisors == N ) :
        return True ;
    else :
        return False ;
def sumOfDigits ( N ) :
    sum = 0 ;
    while ( N != 0 ) :
        sum += ( N % 10 ) ;
        N = N // 10 ;
    return sum ;
def countPerfectNumbers ( arr , N ) :
    for i in range ( N ) :
        if ( isPerfect ( arr [ i ] ) ) :
            sum = sumOfDigits ( arr [ i ] ) ;
            if ( isPerfect ( sum ) ) :
                print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 8 , 12 , 28 , 6 ] ;
    N = len ( arr ) ;
    countPerfectNumbers ( arr , N ) ;

Index/key variables: i
Accumulator variables: sum, sumOfDivisors
Iterator variables: i
Python program:
class TreeNode :
    def __init__ ( self , val = 0 , left = None , right = None ) :
        self . val = val
        self . left = left
        self . right = right
def findSum ( root ) :
    que = [ root ]
    ans = 0
    while ( len ( que ) ) :
        leaf = 0
        nonleaf = 0
        length = len ( que )
        while length :
            temp = que . pop ( 0 )
            if not temp . left and not temp . right :
                leaf += temp . val
            else :
                nonleaf += temp . val
            if temp . left :
                que . append ( temp . left )
            if temp . right :
                que . append ( temp . right )
            length -= 1
        ans += leaf & nonleaf
    return ans
root = TreeNode ( 5 )
root . left = TreeNode ( 3 )
root . right = TreeNode ( 9 )
root . left . left = TreeNode ( 6 )
root . left . right = TreeNode ( 4 )
root . left . left . right = TreeNode ( 7 )
print ( findSum ( root ) )

Accumulator variables: ans, leaf, length, nonleaf, que
Class/struct names: TreeNode
Python program:
def MinTime ( a , b , n , m ) :
    ans = float ( ' inf ' )
    prefix_a = [ 0 ] * 10
    prefix_b = [ 0 ] * 10
    for i in range ( n ) :
        prefix_a [ a [ i ] ] += 1
    for i in range ( m ) :
        prefix_b [ b [ i ] ] += 1
    for i in range ( 1 , 10 ) :
        prefix_a [ i ] += prefix_a [ i - 1 ]
    for i in range ( 1 , 10 ) :
        prefix_b [ i ] += prefix_b [ i - 1 ]
    for i in range ( 1 , 10 ) :
        ans = min ( ans , prefix_a [ i ] + m - prefix_b [ i ] )
        ans = min ( ans , n - prefix_a [ i ] + prefix_b [ i ] )
    print ( ans )
A = [ 0 , 0 , 1 , 3 , 3 ]
B = [ 2 , 0 , 3 ]
N = len ( A )
M = len ( B )
MinTime ( A , B , N , M )

Index/key variables: i
Iterator variables: i
Python program:
def fizzBuzz ( N ) :
    count3 = 0
    count5 = 0
    for i in range ( 1 , N + 1 ) :
        count3 += 1
        count5 += 1
        flag = False
        if ( count3 == 3 ) :
            print ( " Fizz " , end = " " )
            count3 = 0
            flag = True
        if ( count5 == 5 ) :
            print ( " Buzz " , end = " " )
            count5 = 0
            flag = True
        if ( not flag ) :
            print ( i , end = " " )
        print ( end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 15
    fizzBuzz ( N )

Accumulator variables: count3, count5
Iterator variables: i
Boolean variables: flag
Python program:
prime = [ True ] * 1000005
def SieveOfEratosthenes ( N ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , N + 1 ) :
        if p * p > N :
            break
        if ( prime [ p ] == True ) :
            for i in range ( p * p , N + 1 , p ) :
                prime [ i ] = False
def checkElementsOnDiagonal ( M , N ) :
    flag = 1
    SieveOfEratosthenes ( 1000000 )
    for i in range ( N ) :
        flag &= ( prime [ M [ i ] [ i ] ] and prime [ M [ i ] [ N - 1 - i ] ] )
    if ( flag ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    M = [ [ 1 , 2 , 3 , 13 ] , [ 5 , 3 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 7 ] ]
    N = len ( M )
    checkElementsOnDiagonal ( M , N )

Index/key variables: i, p
Accumulator variables: flag
Iterator variables: i, p
Python program:
def circularPermutation ( n , start ) :
    res = [ 0 ]
    ret = [ ]
    index , add = - 1 , 1
    for k in range ( n ) :
        add = 1 << k
        for i in range ( len ( res ) - 1 , - 1 , - 1 ) :
            if ( res [ i ] + add == start ) :
                index = len ( res )
            res . append ( res [ i ] + add )
        add = 1 << k
    if ( start == 0 ) :
        return res
    while ( len ( ret ) < len ( res ) ) :
        ret . append ( res [ index ] )
        index = ( index + 1 ) % len ( res )
    return ret
if __name__ == ' _ _ main _ _ ' :
    N , S = 2 , 3
    print ( circularPermutation ( N , S ) )

Index/key variables: i, index
Accumulator variables: res, ret
Iterator variables: i, k
Python program:
def countPairs ( a , n ) :
    count = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( a [ j ] != 0 and a [ i ] % a [ j ] == 0 ) :
                if ( ( a [ i ] + a [ j ] ) == ( a [ i ] // a [ j ] ) ) :
                    count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 4 , - 3 , 0 , 2 , 1 ]
    N = len ( arr )
    print ( countPairs ( arr , N ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def countPairs ( a , n ) :
    count = 0
    mp = { }
    for i in range ( n ) :
        y = a [ i ]
        if ( y != 0 and y != 1 ) :
            x = ( ( ( y * 1.0 ) // ( 1 - y ) ) * y )
            count += mp . get ( x , 0 )
        mp [ y ] = mp . get ( y , 0 ) + 1
    return count
arr = [ - 4 , - 3 , 0 , 2 , 1 ]
N = len ( arr )
print ( countPairs ( arr , N ) )

Index/key variables: i, y
Accumulator variables: count
Iterator variables: i
Python program:
def contains ( num , K , base ) :
    isThere = 0
    while ( num ) :
        remainder = num % base
        if ( remainder == K ) :
            isThere = 1
        num //= base
    return isThere
def count ( n , k , v ) :
    pref = [ 0 ] * 1000005
    for i in range ( 1 , 10 ** 6 + 5 ) :
        present = contains ( i , k , 10 ) or contains ( i , k , 8 )
        pref [ i ] += pref [ i - 1 ] + present
    for i in range ( n ) :
        print ( v [ i ] [ 1 ] - v [ i ] [ 0 ] + 1 - ( pref [ v [ i ] [ 1 ] ] - pref [ v [ i ] [ 0 ] - 1 ] ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    K = 7
    Q = [ [ 2 , 5 ] , [ 1 , 15 ] ]
    N = len ( Q )
    count ( N , K , Q )

Index/key variables: i
Accumulator variables: num
Iterator variables: i
Python program:
def canMakeEqual ( arr1 , arr2 , N ) :
    count = 0
    arr1_one = 0
    arr1_zero = 0
    arr2_one = 0
    arr2_zero = 0
    for i in range ( N ) :
        if ( arr1 [ i ] == 1 ) :
            arr1_one += 1
        elif ( arr1 [ i ] == 0 ) :
            arr1_zero += 1
        if ( arr2 [ i ] == 1 ) :
            arr2_one += 1
        elif ( arr2 [ i ] == 0 ) :
            arr2_zero += 1
    if ( arr1_one != arr2_one or arr1_zero != arr2_zero ) :
        print ( " No " )
        return
    for i in range ( N ) :
        count = count + ( arr1 [ i ] - arr2 [ i ] )
        if ( count < 0 ) :
            print ( " No " )
            return
    print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 0 , 1 , 1 , 0 ]
    arr2 = [ 0 , 0 , 1 , 1 ]
    N = len ( arr1 )
    canMakeEqual ( arr1 , arr2 , N )

Index/key variables: i
Accumulator variables: arr1_one, arr1_zero, arr2_one, arr2_zero
Iterator variables: i
Python program:
def checksubarrayExist1_N ( arr , N ) :
    pos = { }
    for i in range ( N ) :
        pos [ arr [ i ] ] = i
    st = { }
    for i in range ( 1 , N + 1 ) :
        st [ pos [ i ] ] = 1
        Min = sorted ( list ( st . keys ( ) ) ) [ 0 ]
        Max = sorted ( list ( st . keys ( ) ) ) [ - 1 ]
        if ( Max - Min + 1 == i ) :
            print ( " True " , end = " ▁ " )
        else :
            print ( " False " , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 4 , 3 , 2 ]
    N = len ( arr )
    checksubarrayExist1_N ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def checkSamePosition ( arr , n ) :
    mp = { }
    for i in range ( n ) :
        temp = ( ( i + arr [ i ] ) % n + n ) % n
        if temp in mp :
            print ( " Yes " )
            return
        if ( temp in mp ) :
            mp [ temp ] += 1
        else :
            mp [ temp ] = mp . get ( temp , 0 ) + 1
    print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 4 , 3 ]
    N = len ( arr )
    checkSamePosition ( arr , N )

Index/key variables: i, temp
Iterator variables: i
Python program:
import sys
def maxProduct ( arr , N ) :
    max_product = - sys . maxsize ;
    prefix_sum = 0 ;
    sum = 0 ;
    for i in range ( N ) :
        sum += arr [ i ] ;
    for i in range ( N - 1 ) :
        prefix_sum += arr [ i ] ;
        X = prefix_sum ;
        Y = sum - prefix_sum ;
        max_product = max ( max_product , X * Y ) ;
    print ( max_product ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 5 , 6 , 7 ] ;
    N = len ( arr ) ;
    maxProduct ( arr , N ) ;

Index/key variables: i
Accumulator variables: prefix_sum, sum
Iterator variables: i
Python program:
def findMask ( K ) :
    mask = 1 ;
    while ( ( K & mask ) == 0 ) :
        mask = mask << 1 ;
    return mask ;
def sameRightSetBitPos ( arr , N , K ) :
    mask = findMask ( K ) ;
    pos = ( K & mask ) ;
    for i in range ( N ) :
        if ( ( arr [ i ] & mask ) == pos ) :
            print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 4 , 6 , 7 , 9 , 12 , 15 ] ;
    N = len ( arr ) ;
    K = 7 ;
    sameRightSetBitPos ( arr , N , K ) ;

Index/key variables: i
Iterator variables: i
Python program:
import math
def checkPronic ( x ) :
    for i in range ( int ( math . sqrt ( x ) ) + 1 ) :
        if ( x == i * ( i + 1 ) ) :
            return True
    return False
def countPronic ( A , B ) :
    count = 0
    for i in range ( A , B + 1 ) :
        if ( checkPronic ( i ) != 0 ) :
            count += 1
    print ( count )
A = 3
B = 20
countPronic ( A , B )

Accumulator variables: count
Iterator variables: i
Python program:
def oddDivisors ( arr , N ) :
    for i in range ( N ) :
        powerOfTwo = 2 ;
        count = 0 ;
        while ( powerOfTwo <= arr [ i ] ) :
            count += 1 ;
            powerOfTwo = 2 * powerOfTwo ;
        print ( count , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 15 , 16 , 20 , 35 ] ;
    N = len ( arr ) ;
    oddDivisors ( arr , N ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def checkPossible ( arr , n ) :
    for i in range ( 1 , n ) :
        if ( arr [ i ] < arr [ i - 1 ] ) :
            print ( " No " ) ;
            return ;
        else :
            arr [ i ] -= arr [ i - 1 ] ;
            arr [ i - 1 ] = 0 ;
    if ( arr [ n - 1 ] == 0 ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 3 , 4 , 2 ] ;
    N = len ( arr ) ;
    checkPossible ( arr , N ) ;

Index/key variables: i
Iterator variables: i
Python program:
import math
def highestPowerOfTwo ( num ) :
    s = str ( num )
    for i in range ( len ( s ) ) :
        if ( s [ i ] == '0' ) :
            print ( "0" )
            continue
        lg = int ( math . log2 ( ord ( s [ i ] ) - 48 ) )
        p = pow ( 2 , lg )
        print ( chr ( p + 48 ) , end = " " )
num = 4317
highestPowerOfTwo ( num )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def maxSumAfterKReverse ( arr , K , N ) :
    sum = - sys . maxsize - 1
    if ( K & 1 ) :
        arr . reverse ( )
    currsum = 0
    for i in range ( N ) :
        currsum += arr [ i ]
        sum = max ( sum , currsum )
    print ( sum )
arr = [ 1 , 5 , 8 , 9 , 11 , 2 ]
K = 1
N = len ( arr )
maxSumAfterKReverse ( arr , K , N )

Index/key variables: i
Accumulator variables: currsum
Iterator variables: i
Python program:
import sys
def minimumMoves ( a , n ) :
    min_element = sys . maxsize
    max_element = - sys . maxsize - 1
    min_ind = - 1
    max_ind = - 1
    for i in range ( n ) :
        if ( a [ i ] <= min_element ) :
            min_element = a [ i ]
            min_ind = i
        if ( a [ i ] > max_element ) :
            max_element = a [ i ]
            max_ind = i
    if ( max_ind == min_ind ) :
        return 0
    elif ( max_ind > min_ind ) :
        return max_ind + ( n - min_ind - 2 )
    else :
        return max_ind + n - min_ind - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 35 , 46 , 17 , 23 ]
    N = len ( arr )
    print ( minimumMoves ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def findIndex ( arr , n , K ) :
    sum = 0
    res = - 1
    mini = 1e9
    for i in range ( n ) :
        sum += arr [ i ]
    for i in range ( n ) :
        temp = sum - arr [ i ]
        if ( temp % K == 0 ) :
            if ( res == - 1 or mini > arr [ i ] ) :
                res = i + 1
                mini = arr [ i ]
    return res ;
arr = [ 14 , 7 , 8 , 2 , 4 ]
K = 7
N = len ( arr )
print ( findIndex ( arr , N , K ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
from collections import defaultdict
def divisionalArrays ( arr , N ) :
    sum = N
    mp = defaultdict ( int )
    for i in range ( N ) :
        mp [ arr [ i ] ] += 1
    for x in mp :
        if ( mp [ x ] > 1 ) :
            sum += mp [ x ] - 1
    print ( sum )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 3 ]
    N = len ( arr )
    divisionalArrays ( arr , N )

Index/key variables: i, x
Accumulator variables: sum
Iterator variables: i, x
Python program:
def totalInversions ( arr , K , N ) :
    inv = 0
    X = 0
    for i in range ( N ) :
        for j in range ( N ) :
            if ( arr [ i ] > arr [ j ] and i < j ) :
                inv += 1
            if ( arr [ i ] > arr [ j ] ) :
                X += 1
    totalInv = X * K * ( K - 1 ) // 2 + inv * K
    print ( totalInv )
arr = [ 2 , 1 , 3 ]
K = 3
N = len ( arr )
totalInversions ( arr , K , N )

Index/key variables: i, j
Accumulator variables: X, inv
Iterator variables: i, j
Python program:
def Fact ( N ) :
    result = 1
    for i in range ( 1 , N + 1 ) :
        result = ( result * i )
    return result
def numberOfWays ( M , arr , N ) :
    B = [ 0 ] * ( M )
    counter = [ 0 ] * ( M + 1 )
    for i in range ( 0 , N ) :
        if ( arr [ i ] != 0 ) :
            if ( B [ i % M ] == 0 ) :
                B [ i % M ] = arr [ i ]
                counter [ arr [ i ] ] += 1
                if ( counter [ arr [ i ] ] > 1 ) :
                    print ( 0 )
                    return
            elif ( B [ i % M ] != arr [ i ] ) :
                print ( 0 )
                return
    cnt = 0
    for i in range ( 0 , M ) :
        if ( B [ i ] == 0 ) :
            cnt += 1
    print ( Fact ( cnt ) )
if __name__ == ' _ _ main _ _ ' :
    M = 4
    arr = [ 1 , 0 , 3 , 0 , 0 ]
    N = len ( arr )
    numberOfWays ( M , arr , N )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def MaximumSum ( arr , n ) :
    ans = 0 ;
    for i in range ( n ) :
        x , y , sum = 0 , i , 0
        for j in range ( i , n ) :
            sum , x , y = sum + arr [ x ] [ y ] , x + 1 , y + 1
        if ( sum > ans ) :
            ans = sum
    for i in range ( 1 , n ) :
        x , y , sum = i , 0 , 0
        for j in range ( i , n ) :
            sum , x , y = sum + arr [ x ] [ y ] , x + 1 , y + 1
        if ( sum > ans ) :
            ans = sum
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 2 , 3 ] , [ 3 , 5 , 10 ] , [ 1 , 3 , 5 ] ]
    n = len ( arr )
    print ( MaximumSum ( arr , n ) )

Index/key variables: x, y
Iterator variables: i, j
Python program:
def numberOfIntegers ( arr , N ) :
    cur_max = 0
    count = 0
    if ( N == 1 ) :
        count = 1
    else :
        for i in range ( N - 1 ) :
            if ( arr [ i ] > cur_max ) :
                cur_max = arr [ i ]
                if ( arr [ i ] > arr [ i + 1 ] ) :
                    count += 1
        if ( arr [ N - 1 ] > cur_max ) :
            count += 1
    print ( count )
arr = [ 1 , 2 , 0 , 7 , 2 , 0 , 2 , 0 ]
N = len ( arr )
numberOfIntegers ( arr , N )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def possibleTriplets ( arr , N ) :
    freq = 0
    for i in range ( N ) :
        if ( arr [ i ] > 0 ) :
            freq += 1
    return ( freq * ( freq - 1 ) * ( freq - 2 ) ) // 6
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , - 9 , - 3 , 6 ]
    N = len ( arr )
    print ( possibleTriplets ( arr , N ) )

Index/key variables: i
Accumulator variables: freq
Iterator variables: i
Python program:
def maxPossibleDiff ( arr , N ) :
    arr . append ( - 1 )
    arr = arr [ : : - 1 ]
    arr . append ( - 1 )
    arr = arr [ : : - 1 ]
    maxDiff = 0
    for i in range ( 1 , N + 1 ) :
        if ( arr [ i ] > arr [ i - 1 ] and arr [ i ] > arr [ i + 1 ] ) :
            maxDiff += arr [ i ]
        if ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) :
            maxDiff -= arr [ i ]
    print ( maxDiff )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 1 , 4 , 5 , 2 , 1 , 7 , 8 , 9 ]
    N = len ( arr )
    maxPossibleDiff ( arr , N )

Index/key variables: i
Accumulator variables: maxDiff
Iterator variables: i
Python program:
def printArray ( arr , N ) :
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " )
def reverseCircularArray ( arr , N , K ) :
    start , end = K , K - 1
    count = N // 2
    while ( count ) :
        temp = arr [ start % N ]
        arr [ start % N ] = arr [ end % N ]
        arr [ end % N ] = temp
        start += 1
        end -= 1
        if ( end == - 1 ) :
            end = N - 1
        count -= 1
    printArray ( arr , N )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 5 , 2 , 4 , 1 ]
    K = 2
    N = len ( arr )
    reverseCircularArray ( arr , N , K )

Index/key variables: i
Accumulator variables: count, end, start
Iterator variables: i