dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def addAP ( A , Q , operations ) :
    for L , R , a , d in operations :
        curr = a
        for i in range ( L - 1 , R ) :
            A [ i ] += curr
            curr += d
    for i in A :
        print ( i , end = ' ▁ ' )
A = [ 5 , 4 , 2 , 8 ]
Q = 2
Query = [ ( 1 , 2 , 1 , 3 ) , ( 1 , 4 , 4 , 1 ) ]
addAP ( A , Q , Query )

Index/key variables: i
Accumulator variables: curr
Iterator variables: L, R, a, d, i
Python program:
def maximizeNumber ( N , K ) :
    s = str ( N )
    L = len ( s )
    result = " "
    i = 0
    while ( ( i < L ) and ( K <= ( ord ( s [ i ] ) - ord ( '0' ) ) ) ) :
        result += ( s [ i ] )
        i += 1
    result += ( chr ( K + ord ( '0' ) ) )
    while ( i < L ) :
        result += ( s [ i ] )
        i += 1
    print ( result )
if __name__ == " _ _ main _ _ " :
    N = 6673
    K = 6
    maximizeNumber ( N , K )

Index/key variables: i
Accumulator variables: result
Python program:
def minimumDistance ( arr , N ) :
    ind = 0 ;
    prev = arr [ ind ] ;
    s = len ( arr ) ;
    for i in range ( N ) :
        distance = 10 ** 9 ;
        if ( i < arr [ 0 ] ) :
            distance = arr [ 0 ] - i ;
        elif ( i >= prev and ind + 1 < s and i <= arr [ ind + 1 ] ) :
            distance = min ( i - prev , arr [ ind + 1 ] - i ) ;
            if ( i == arr [ ind + 1 ] ) :
                distance = 0 ;
                prev = arr [ ind + 1 ] ;
                ind += 1 ;
        else :
            distance = i - prev ;
        print ( distance , end = " ▁ " ) ;
N = 5 ;
arr = [ 0 , 4 ] ;
minimumDistance ( arr , N ) ;

Index/key variables: ind
Iterator variables: i
Python program:
def countOfPairs ( arr , N , X ) :
    count = 0
    for i in range ( N - 1 ) :
        for j in range ( i + 1 , N ) :
            if ( ( ( arr [ i ] ^ arr [ j ] ) & X ) == 0 ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 5 , 4 , 6 , 7 ]
    X = 6
    N = len ( arr )
    print ( countOfPairs ( arr , N , X ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def countOfPairs ( arr , N , X ) :
    count = 0
    M = dict ( )
    for i in range ( 0 , N ) :
        k = arr [ i ] & X
        if k in M :
            M [ k ] += 1
        else :
            M [ k ] = 1
    for m in M . keys ( ) :
        p = M [ m ]
        count += p * ( p - 1 ) // 2
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 5 , 4 , 6 , 7 ]
    X = 6
    N = len ( arr )
    print ( countOfPairs ( arr , N , X ) )

Index/key variables: i, k, m
Accumulator variables: count
Iterator variables: i, m
Python program:
def cntMatrices ( arr , N , M , K ) :
    cnt = 0
    pre = [ [ 0 for i in range ( M + 1 ) ] for i in range ( N + 1 ) ]
    for i in range ( 1 , N + 1 ) :
        for j in range ( 1 , M + 1 ) :
            pre [ i ] [ j ] = ( arr [ i - 1 ] [ j - 1 ] + pre [ i - 1 ] [ j ] + pre [ i ] [ j - 1 ] - pre [ i - 1 ] [ j - 1 ] )
    for i in range ( 1 , N + 1 ) :
        for j in range ( 1 , M + 1 ) :
            l , r = i , j
            while l > 0 and r > 0 :
                sum1 = ( K * ( i - l + 1 ) * ( i - r + 1 ) )
                sum2 = ( pre [ i ] [ j ] - pre [ l - 1 ] [ r ] - pre [ l ] [ r - 1 ] + pre [ l - 1 ] [ r - 1 ] )
                if ( sum1 <= sum2 ) :
                    cnt += 1
                l -= 1
                r -= 1
    return cnt
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 2 , 2 , 3 ] , [ 3 , 4 , 5 ] , [ 4 , 5 , 5 ] ]
    K = 4
    N = len ( arr )
    M = len ( arr [ 0 ] )
    print ( cntMatrices ( arr , N , M , K ) )

Index/key variables: i, j, l, r
Accumulator variables: cnt
Iterator variables: i, j
Python program:
import math
def ConcatenateArr ( arr , N ) :
    ans = arr [ 0 ]
    for i in range ( 1 , N ) :
        l = math . floor ( math . log10 ( arr [ i ] ) + 1 )
        ans = ans * math . pow ( 10 , l )
        ans += arr [ i ]
    return int ( ans )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 23 , 456 ]
    N = len ( arr )
    print ( ConcatenateArr ( arr , N ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def findPairs ( p , q , r ) :
    v = [ ]
    for i in range ( p , q + 1 ) :
        if ( i % r == 0 ) :
            v . append ( i )
    ans = [ ]
    for i in range ( len ( v ) ) :
        for j in range ( i + 1 , len ( v ) ) :
            if ( v [ i ] * v [ j ] >= p * q // 4 and v [ i ] * v [ j ] <= p * q ) :
                ans . append ( [ v [ i ] , v [ j ] ] )
    if ( len ( ans ) == 0 ) :
        print ( - 1 )
    else :
        for i in range ( len ( ans ) ) :
            print ( ans [ i ] [ 0 ] , ans [ i ] [ 1 ] )
if __name__ == ' _ _ main _ _ ' :
    p = 14
    q = 30
    r = 5
    findPairs ( p , q , r )

Index/key variables: i, j
Accumulator variables: ans, v
Iterator variables: i, j
Python program:
def printRectPattern ( c1 , c2 , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            print ( max ( abs ( c1 - i ) , abs ( c2 - j ) ) , end = " ▁ " )
        print ( " " )
c1 = 2
c2 = 2
n = 5
printRectPattern ( c1 , c2 , n )

Iterator variables: i, j
Python program:
def countNumbers ( l , r ) :
    count = 0
    for i in range ( l , r + 1 ) :
        if ( ( i & 1 ) == 0 ) :
            count += 1
    return count
l = 10
r = 20
print ( countNumbers ( l , r ) )

Accumulator variables: count
Iterator variables: i
Python program:
import math
def isPerfectSquare ( x ) :
    s = int ( math . sqrt ( x ) )
    if s * s == x :
        return True
    else :
        return False
def isFibonacci ( n ) :
    return ( isPerfectSquare ( 5 * n * n + 4 ) or isPerfectSquare ( 5 * n * n - 4 ) )
def contiguousFibonacciNumber ( arr , n ) :
    current_length = 0
    max_length = 0
    for i in range ( 0 , n ) :
        if isFibonacci ( arr [ i ] ) :
            current_length += 1
        else :
            current_length = 0
        max_length = max ( max_length , current_length )
    return max_length
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 8 , 21 , 5 , 3 , 28 , 4 ]
    n = len ( arr )
    print ( contiguousFibonacciNumber ( arr , n ) )

Index/key variables: i
Accumulator variables: current_length
Iterator variables: i
Python program:
direction = [ [ - 1 , 0 ] , [ 0 , 1 ] , [ 0 , - 1 ] , [ 1 , 0 ] ]
def dfs ( i , j , N , M ) :
    global matrix
    if ( i == N - 1 and j == M - 1 ) :
        return True
    matrix [ i ] [ j ] = 1
    for k in range ( 4 ) :
        newX = i + direction [ k ] [ 0 ]
        newY = j + direction [ k ] [ 1 ]
        if ( newX >= 0 and newX < N and newY >= 0 and newY < M and matrix [ newX ] [ newY ] == 0 ) :
            if ( dfs ( newX , newY , N , M ) ) :
                return True
    return False
def solve ( ) :
    global matrix
    N = len ( matrix )
    M = len ( matrix [ 0 ] )
    if ( not dfs ( 0 , 0 , N , M ) ) :
        return 0
    if ( not dfs ( 0 , 0 , N , M ) ) :
        return 1
    return 2
if __name__ == ' _ _ main _ _ ' :
    matrix = [ [ 0 , 1 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ]
    print ( solve ( ) )

Index/key variables: i, j, k, newX, newY
Iterator variables: k
Python program:
def Kadane ( arr , n ) :
    largestSum = 0
    currMax = 0
    currSum = 0
    for i in range ( n ) :
        currSum += arr [ i ]
        currMax = max ( currMax , arr [ i ] )
        largestSum = max ( largestSum , currMax * currSum )
        if ( currSum < 0 ) :
            currMax = 0
            currSum = 0
    return largestSum
def maximumWeight ( arr , n ) :
    largestSum = Kadane ( arr , n )
    for i in range ( n ) :
        arr [ i ] = - arr [ i ]
    largestSum = max ( largestSum , Kadane ( arr , n ) )
    return largestSum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , - 3 , 8 , - 2 , 5 ]
    N = len ( arr )
    print ( maximumWeight ( arr , N ) )

Index/key variables: i
Accumulator variables: currSum
Iterator variables: i
Python program:
def arrayPartition ( a , n ) :
    ans = [ 0 ] * n
    cnt = 0
    ind , flag = 0 , 0
    mp = { }
    for i in a :
        mp [ i ] = mp . get ( i , 0 ) + 1
    for i in range ( n ) :
        if ( ( a [ i ] in mp ) and mp [ a [ i ] ] == 1 ) :
            cnt += 1
        if ( mp [ a [ i ] ] > 2 and flag == 0 ) :
            flag = 1
            ind = i
    p = ( cnt + 1 ) // 2
    ans1 = 0
    for i in range ( n ) :
        ans [ i ] = 1
    for i in range ( n ) :
        if ( ( a [ i ] in mp ) and mp [ a [ i ] ] == 1 and ans1 < p ) :
            ans [ i ] = 1
            ans1 += 1
        elif ( ( a [ i ] in mp ) and mp [ a [ i ] ] == 1 ) :
            ans [ i ] = 2
    if ( cnt % 2 == 1 and flag == 0 ) :
        print ( - 1 )
        return
    if ( cnt % 2 == 0 ) :
        print ( * ans )
    else :
        for i in range ( n ) :
            if ( ind == i ) :
                print ( 2 , end = " ▁ " )
            else :
                print ( ans [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 3 , 4 , 4 ]
    N = len ( arr )
    arrayPartition ( arr , N )

Index/key variables: i
Accumulator variables: ans1, cnt
Iterator variables: i
Python program:
def evenOdd ( arr , N ) :
    for i in range ( N ) :
        even_digits = 0 ;
        odd_digits = 0 ;
        temp = arr [ i ] ;
        while ( temp ) :
            if ( ( temp % 10 ) & 1 ) :
                odd_digits += 1 ;
            else :
                even_digits += 1 ;
            temp = temp // 10
        if ( even_digits > odd_digits ) :
            res = 0 ;
            while ( arr [ i ] ) :
                res += arr [ i ] % 10 ;
                arr [ i ] = arr [ i ] // 10 ;
            print ( res , end = " ▁ " ) ;
        elif ( odd_digits > even_digits ) :
            res = 1 ;
            while ( arr [ i ] ) :
                res *= arr [ i ] % 10 ;
                arr [ i ] = arr [ i ] // 10
            print ( res , end = " ▁ " ) ;
        else :
            print ( arr [ i ] , end = " ▁ " ) ;
arr = [ 113 , 141 , 214 , 3186 ] ;
N = len ( arr ) ;
evenOdd ( arr , N ) ;

Index/key variables: i
Accumulator variables: even_digits, odd_digits, res
Iterator variables: i
Python program:
def primeFactorization ( N ) :
    sieve = [ 0 for i in range ( N // 2 + 1 ) ]
    for i in range ( 2 , N // 2 + 1 , 1 ) :
        if ( sieve [ i ] == 0 ) :
            for j in range ( i * i , N // 2 + 1 , i ) :
                sieve [ j ] = 1
    prime = [ ]
    for i in range ( 3 , N // 2 + 1 , 1 ) :
        if ( sieve [ i ] == 0 ) :
            prime . append ( i )
    x = len ( prime )
    print ( "2 - > " , x )
    for i in prime :
        print ( i , " - > 1" )
if __name__ == ' _ _ main _ _ ' :
    N = 18
    primeFactorization ( N )

Index/key variables: i, j
Accumulator variables: prime
Iterator variables: i, j
Python program:
def sumOfFirstM ( A , N , M ) :
    sum = 0
    for i in range ( M ) :
        sum = sum + A [ i % N ]
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 ]
    M = 5
    N = len ( arr )
    print ( sumOfFirstM ( arr , N , M ) )

Iterator variables: i
Python program:
def canReach0toM ( a , n , m ) :
    rightMost = [ 0 for i in range ( m + 1 ) ]
    dp = [ 0 for i in range ( m + 1 ) ]
    for i in range ( m + 1 ) :
        rightMost [ i ] = 0
    for i in range ( n ) :
        a1 = a [ i ] [ 0 ]
        b1 = a [ i ] [ 1 ]
        rightMost [ a1 ] = max ( rightMost [ a1 ] , b1 )
    i = m
    while ( i >= 0 ) :
        dp [ i ] = i
        j = min ( m , rightMost [ i ] )
        while ( j > i ) :
            dp [ i ] = max ( dp [ i ] , dp [ j ] )
            j -= 1
        i -= 1
    if ( dp [ 0 ] >= m ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 0 , 2 ] , [ 2 , 2 ] , [ 2 , 5 ] , [ 4 , 5 ] ]
    M = 5
    N = len ( arr )
    canReach0toM ( arr , N , M )

Index/key variables: a1, i, j
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if b == 0 :
        return a
    return gcd ( b , a % b )
def countPairs ( arr , N ) :
    for i in range ( 0 , N ) :
        count = 0
        for x in range ( 1 , arr [ i ] + 1 ) :
            for y in range ( x , arr [ i ] + 1 ) :
                if gcd ( x , y ) > 1 :
                    count += 1
        print ( count , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 10 , 20 ]
    N = len ( arr )
    countPairs ( arr , N )

Index/key variables: i
Accumulator variables: count
Iterator variables: i, x, y
Python program:
def maximumTurns ( arr , N ) :
    Count = 0
    for i in range ( 0 , N ) :
        while ( arr [ i ] % 2 == 0 ) :
            Count += 1
            arr [ i ] = arr [ i ] // 2
    return Count
arr = [ 5 , 2 , 4 ]
M = 3
K = 2
N = len ( arr )
print ( maximumTurns ( arr , N ) )

Index/key variables: i
Accumulator variables: Count
Iterator variables: i
Python program:
def GCD ( a , b ) :
    if ( b == 0 ) :
        return a
    return GCD ( b , a % b )
def maxGCDInRange ( L , R ) :
    ans = 1
    for Z in range ( R , 1 , - 1 ) :
        if ( ( ( R // Z ) - ( L - 1 ) // Z ) > 1 ) :
            ans = Z
            break
    return ans
L = 102
R = 139
print ( maxGCDInRange ( L , R ) )

Iterator variables: Z
Python program:
def noOfWays ( N , K ) :
    S = str ( N )
    ans = 1
    for i in range ( 1 , len ( S ) ) :
        count = 1
        while ( i < len ( S ) and ord ( S [ i ] ) + ord ( S [ i - 1 ] ) - 2 * ord ( '0' ) == K ) :
            count += 1
            i += 1
        if ( count % 2 ) :
            ans *= ( count + 1 ) // 2
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 1454781
    K = 9
    print ( noOfWays ( N , K ) )

Index/key variables: i
Accumulator variables: ans, count
Iterator variables: i
Python program:
def countSetBits ( n ) :
    count = 0
    while ( n ) :
        n = n & ( n - 1 )
        count += 1
    return count
def minOperations ( A , B ) :
    cnt1 = 0
    cnt2 = 0
    cnt1 += countSetBits ( A )
    cnt2 += countSetBits ( B )
    if ( ( cnt1 + cnt2 ) % 2 != 0 ) :
        return - 1
    oneZero = 0
    zeroOne = 0
    ans = 0
    for i in range ( max ( cnt1 , cnt2 ) ) :
        bitpos = 1 << i
        if ( ( not ( bitpos & A ) ) and ( bitpos & B ) ) :
            zeroOne += 1
        if ( ( bitpos & A ) and ( not ( bitpos & B ) ) ) :
            oneZero += 1
    ans = ( zeroOne // 2 ) + ( oneZero // 2 )
    if ( zeroOne % 2 != 0 ) :
        ans += 2
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = 27
    B = 5
    print ( minOperations ( A , B ) )

Accumulator variables: count, oneZero, zeroOne
Iterator variables: i
Python program:
import sys
def maximumSum ( A , N , K ) :
    curr_sum = 0
    max_sum = - sys . maxsize - 1
    for i in range ( N - K + 1 ) :
        dupl_arr = A [ i : i + K ]
        dupl_arr . sort ( )
        flag = True
        for j in range ( 1 , K , 1 ) :
            if ( dupl_arr [ j ] - dupl_arr [ j - 1 ] != 1 ) :
                flag = False
                break
        if ( flag ) :
            temp = 0
            curr_sum = temp
            curr_sum = sum ( dupl_arr )
            max_sum = max ( max_sum , curr_sum )
            curr_sum = 0
    return max_sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 12 , 9 , 8 , 10 , 15 , 1 , 3 , 2 ]
    K = 3
    N = len ( arr )
    print ( maximumSum ( arr , N , K ) )

Index/key variables: j
Iterator variables: i, j
Boolean variables: flag
Python program:
from math import sqrt
MAX = 10000
primes = [ ]
def sieveSundaram ( ) :
    marked = [ 0 for i in range ( MAX // 2 + 100 ) ]
    j = 0
    for i in range ( 1 , int ( ( sqrt ( MAX ) - 1 ) / 2 ) + 1 , 1 ) :
        for j in range ( ( i * ( i + 1 ) ) << 1 , MAX // 2 + 1 , j + 2 * i + 1 ) :
            marked [ j ] = True
    primes . append ( 2 )
    for i in range ( 1 , MAX // 2 + 1 , 1 ) :
        if ( marked [ i ] == False ) :
            primes . append ( 2 * i + 1 )
def isSmith ( n ) :
    original_no = n
    pDigitSum = 0
    i = 0
    while ( primes [ i ] <= n // 2 ) :
        while ( n % primes [ i ] == 0 ) :
            p = primes [ i ]
            n = n // p
            while ( p > 0 ) :
                pDigitSum += ( p % 10 )
                p = p // 10
        i += 1
    if ( n != 1 and n != original_no ) :
        while ( n > 0 ) :
            pDigitSum = pDigitSum + n % 10
            n = n // 10
    sumDigits = 0
    while ( original_no > 0 ) :
        sumDigits = sumDigits + original_no % 10
        original_no = original_no // 10
    return ( pDigitSum == sumDigits )
def isSmithBrotherPair ( X , Y ) :
    return ( isSmith ( X ) and isSmith ( Y ) and abs ( X - Y ) == 1 )
def countSmithBrotherPairs ( A , N ) :
    count = 0
    for i in range ( N ) :
        for j in range ( i + 1 , N , 1 ) :
            if ( isSmithBrotherPair ( A [ i ] , A [ j ] ) ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    sieveSundaram ( )
    A = [ 728 , 729 , 28 , 2964 , 2965 ]
    N = len ( A )
    print ( countSmithBrotherPairs ( A , N ) )

Index/key variables: i, j
Accumulator variables: count, pDigitSum, primes
Iterator variables: i, j
Python program:
def countPairs ( arr , N ) :
    count = 0
    totalSum = 0
    for i in range ( N ) :
        totalSum += arr [ i ]
    for i in range ( N ) :
        for j in range ( i + 1 , N , 1 ) :
            if ( totalSum % ( arr [ i ] + arr [ j ] ) == 0 ) :
                count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    N = len ( arr )
    countPairs ( arr , N )

Index/key variables: i, j
Accumulator variables: count, totalSum
Iterator variables: i, j
Python program:
def change ( pas , total ) :
    currentPassRatio = pas / total
    newPassRatio = ( pas + 1 ) / ( total + 1 )
    increase = newPassRatio - currentPassRatio
    return increase
def maximumAverage ( v , M , N ) :
    sum = 0
    increase , average = 0 , 0
    pq = [ ]
    for i in range ( N ) :
        increase = change ( v [ i ] [ 0 ] , v [ i ] [ 1 ] )
        pq . append ( [ increase , i ] )
        average = v [ i ] [ 0 ] * 1.0 / v [ i ] [ 1 ]
        sum += average
    pq = sorted ( pq )
    while ( M > 0 ) :
        sum += pq [ - 1 ] [ 0 ]
        i = pq [ - 1 ] [ 1 ]
        del pq [ - 1 ]
        v [ i ] [ 0 ] += 1
        v [ i ] [ 1 ] += 1
        pq . append ( [ change ( v [ i ] [ 0 ] , v [ i ] [ 1 ] ) , i ] )
        M -= 1
        pq = sorted ( pq )
    ans = sum / N
    return ans
if __name__ == ' _ _ main _ _ ' :
    V = [ [ 1 , 2 ] , [ 3 , 5 ] , [ 2 , 2 ] ]
    M = 2
    N = len ( V )
    print ( round ( maximumAverage ( V , M , N ) , 6 ) )

Index/key variables: i
Accumulator variables: M, pq, sum
Iterator variables: i
Python program:
from math import sqrt , gcd
def printUnitaryDivisors ( n ) :
    for i in range ( 1 , int ( sqrt ( n ) ) + 1 , 1 ) :
        if ( n % i == 0 ) :
            if ( n // i == i and gcd ( i , n // i ) == 1 ) :
                print ( i )
            else :
                if ( gcd ( i , n // i ) == 1 ) :
                    print ( i , n // i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 12
    printUnitaryDivisors ( N )

Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    else :
        return gcd ( b , a % b )
def largestK ( A , N ) :
    l , r , flag = 0 , N - 1 , 0
    while ( l < r ) :
        if ( A [ l ] != A [ r ] ) :
            flag = 1
            break
        l += 1
        r -= 1
    if ( flag == 0 ) :
        return - 1
    K = abs ( A [ 0 ] - A [ N - 1 ] )
    for i in range ( 1 , N // 2 ) :
        K = gcd ( K , abs ( A [ i ] - A [ N - i - 1 ] ) )
    return K
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 2 , 1 ]
    N = len ( A )
    print ( largestK ( A , N ) )

Index/key variables: i, l, r
Iterator variables: i
Python program:
def PermuteAndFind ( power , idx , SumSoFar , target ) :
    if ( idx == len ( power ) ) :
        if ( SumSoFar == target ) :
            return True
        return False
    select = PermuteAndFind ( power , idx + 1 , SumSoFar , target )
    notselect = PermuteAndFind ( power , idx + 1 , SumSoFar + power [ idx ] , target )
    return ( select or notselect )
def DistinctPowersOf3 ( N ) :
    power = [ 0 for x in range ( 16 ) ]
    power [ 0 ] = 1
    for i in range ( 1 , 16 ) :
        power [ i ] = 3 * power [ i - 1 ]
    found = PermuteAndFind ( power , 0 , 0 , N )
    if ( found == True ) :
        print ( " Yes " )
    else :
        print ( " No " )
N = 91
DistinctPowersOf3 ( N )

Index/key variables: i, idx
Iterator variables: i
Python program:
def DistinctPowersOf3 ( N ) :
    while ( N > 0 ) :
        if ( N % 3 == 2 ) :
            cout << " No "
            return
        N //= 3
    print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    N = 91
    DistinctPowersOf3 ( N )

Accumulator variables: N
Python program:
def game_with_number ( arr , n ) :
    for i in range ( n - 1 ) :
        arr [ i ] = arr [ i ] ^ arr [ i + 1 ]
    return arr
def printt ( arr , n ) :
    print ( * arr )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 11 , 1 , 2 , 3 ]
    n = len ( arr )
    new_arr = game_with_number ( arr , n ) ;
    printt ( new_arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def currSubArrayScore ( a , b , l , r ) :
    straightScore = 0
    reverseScore = 0
    for i in range ( l , r + 1 ) :
        straightScore += a [ i ] * b [ i ]
        reverseScore += a [ r - ( i - l ) ] * b [ i ]
    return max ( straightScore , reverseScore )
def maxScoreSubArray ( a , b , n ) :
    res = 0
    start = 0
    end = 0
    for i in range ( n ) :
        for j in range ( i , n ) :
            currScore = currSubArrayScore ( a , b , i , j )
            if ( currScore > res ) :
                res = currScore
                start = i
                end = j
    print ( res )
A = [ 13 , 4 , 5 ]
B = [ 10 , 22 , 2 ]
N = len ( A )
maxScoreSubArray ( A , B , N )

Index/key variables: i
Accumulator variables: reverseScore, straightScore
Iterator variables: i, j
Python program:
def maxScoreSubArray ( a , b , n ) :
    res = 0
    for mid in range ( n ) :
        straightScore = a [ mid ] * b [ mid ]
        reverseScore = a [ mid ] * a [ mid ]
        prev = mid - 1
        next = mid + 1
        res = max ( res , max ( straightScore , reverseScore ) )
        while ( prev >= 0 and next < n ) :
            straightScore += ( a [ prev ] * b [ prev ] + a [ next ] * b [ next ] )
            reverseScore += ( a [ prev ] * b [ next ] + a [ next ] * b [ prev ] )
            res = max ( res , max ( straightScore , reverseScore ) )
            prev -= 1
            next += 1
        straightScore = 0
        reverseScore = 0
        prev = mid - 1
        next = mid
        while ( prev >= 0 and next < n ) :
            straightScore += ( a [ prev ] * b [ prev ] + a [ next ] * b [ next ] )
            reverseScore += ( a [ prev ] * b [ next ] + a [ next ] * b [ prev ] )
            res = max ( res , max ( straightScore , reverseScore ) )
            prev -= 1
            next += 1
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    A = [ 13 , 4 , 5 ]
    B = [ 10 , 22 , 2 ]
    N = len ( A )
    maxScoreSubArray ( A , B , N )

Index/key variables: mid, next, prev
Accumulator variables: reverseScore, straightScore
Iterator variables: mid
Python program:
def minimumSizeSubarray ( arr , N ) :
    i , j = 0 , N - 1
    while ( i < N and arr [ i ] == 0 ) :
        i += 1
    if ( i == N ) :
        return 1
    while ( j >= 0 and arr [ j ] == 0 ) :
        j -= 1
    return ( j - i + 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 2 , 0 , 0 , 12 , 0 , 0 , 0 ]
    N = len ( arr )
    print ( minimumSizeSubarray ( arr , N ) )

Index/key variables: i, j
Python program:
def maximumSum ( arr , N ) :
    ans = 0
    for bit in range ( 32 ) :
        sum = 0
        for i in range ( N ) :
            if ( arr [ i ] & ( 1 << bit ) ) :
                sum += arr [ i ]
        ans = max ( ans , sum )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 4 , 1 , 7 , 11 ]
    N = len ( arr )
    print ( maximumSum ( arr , N ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: bit, i