dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def minimumDeviation ( A , N ) :
    s = set ( [ ] )
    for i in range ( N ) :
        if ( A [ i ] % 2 == 0 ) :
            s . add ( A [ i ] )
        else :
            s . add ( 2 * A [ i ] )
    s = list ( s )
    diff = s [ - 1 ] - s [ 0 ]
    while ( len ( s ) and s [ - 1 ] % 2 == 0 ) :
        maxEl = s [ - 1 ]
        s . remove ( maxEl )
        s . append ( maxEl // 2 )
        diff = min ( diff , s [ - 1 ] - s [ 0 ] )
    print ( diff )
if __name__ == " _ _ main _ _ " :
    A = [ 4 , 1 , 5 , 20 , 3 ]
    N = len ( A )
    minimumDeviation ( A , N )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def findMaxNum ( num ) :
    binaryNumber = bin ( num ) [ 2 : ]
    maxBinaryNumber = " "
    count0 , count1 = 0 , 0
    N = len ( binaryNumber )
    for i in range ( N ) :
        if ( binaryNumber [ i ] == '1' ) :
            count1 += 1
        else :
            count0 += 1
    for i in range ( count1 ) :
        maxBinaryNumber += '1'
    for i in range ( count0 ) :
        maxBinaryNumber += '0'
    return int ( maxBinaryNumber , 2 )
if __name__ == ' _ _ main _ _ ' :
    N = 11
    print ( findMaxNum ( N ) )

Index/key variables: i
Accumulator variables: count0, count1, maxBinaryNumber
Iterator variables: i
Python program:
def minOperations ( N ) :
    even = 0 ;
    odd = 0 ;
    for it in N :
        if ( int ( ord ( it ) - ord ( '0' ) ) % 2 == 0 ) :
            even += 1 ;
        else :
            odd += 1 ;
    if ( odd == 0 or odd == 1 ) :
        print ( " Not ▁ Possible " + " " ) ;
    else :
        ans = 0 ;
        for it in N :
            if ( int ( ord ( it ) - ord ( '0' ) ) % 2 == 0 ) :
                ans += 1 ;
            else :
                ans = 0 ;
        if ( odd % 2 != 0 ) :
            ans += 1 ;
        print ( ans , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    N = "12345" ;
    minOperations ( N ) ;

Accumulator variables: ans, even, odd
Iterator variables: it
Python program:
def FindwinnerOfGame ( S ) :
    cntZero = 0
    cntConOne = 0
    nimSum = 0
    N = len ( S )
    for i in range ( N ) :
        if ( S [ i ] == '1' ) :
            cntConOne += 1
        else :
            nimSum ^= cntConOne
            cntConOne = 0
            cntZero += 1
    nimSum ^= cntConOne
    if ( cntZero % 2 == 0 ) :
        print ( " Tie " )
    elif ( nimSum ) :
        print ( " player ▁ 1" )
    else :
        print ( " player ▁ 2" )
if __name__ == ' _ _ main _ _ ' :
    S = "0110011"
    FindwinnerOfGame ( S )

Index/key variables: i
Accumulator variables: cntConOne, cntZero, nimSum
Iterator variables: i
Python program:
def generatepermutation ( N ) :
    answer = [ ]
    answer . append ( N )
    for i in range ( 1 , N ) :
        answer . append ( i )
    print ( * answer )
N = 4
generatepermutation ( N )

Accumulator variables: answer
Iterator variables: i
Python program:
def maxSum ( arr , N ) :
    ans = 0 ;
    for i in range ( N - 1 , - 1 , - 1 ) :
        t = i ;
        if ( t + arr [ i ] < N ) :
            arr [ i ] += arr [ t + arr [ i ] ] ;
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 7 , 1 , 8 ] ;
    N = len ( arr ) ;
    maxSum ( arr , N ) ;

Index/key variables: i
Iterator variables: i
Python program:
from bisect import bisect_left
def PrintPathNodes ( N ) :
    arr = [ ]
    arr . append ( 1 )
    k = 1
    flag = True
    while ( k < N ) :
        if ( flag == True ) :
            k *= 2
            flag = False
        else :
            k *= 4
            flag = True
        if ( k > N ) :
            break
        arr . append ( k )
    lenn = len ( arr )
    prefix = [ 0 ] * ( lenn )
    prefix [ 0 ] = 1
    for i in range ( 1 , lenn ) :
        prefix [ i ] = arr [ i ] + prefix [ i - 1 ]
    it = bisect_left ( prefix , N )
    ind = it
    temp = N
    path = [ ]
    path . append ( N )
    while ( ind > 1 ) :
        val = temp - prefix [ ind - 1 ]
        if ( ind % 2 != 0 ) :
            temp = prefix [ ind - 2 ] + ( val + 1 ) // 2
        else :
            temp = prefix [ ind - 2 ] + ( val + 3 ) // 4
        ind -= 1
        path . append ( temp )
    if ( N != 1 ) :
        path . append ( 1 )
    for i in range ( len ( path ) - 1 , - 1 , - 1 ) :
        print ( path [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 14
    PrintPathNodes ( N )

Index/key variables: i
Accumulator variables: arr, ind, k, path
Iterator variables: i
Boolean variables: flag
Python program:
def minOpsToTurnArrToZero ( arr , N ) :
    st = dict ( )
    for i in range ( N ) :
        if ( i in st . keys ( ) or arr [ i ] == 0 ) :
            continue
        else :
            st [ arr [ i ] ] = 1
    print ( len ( st ) )
arr = [ 3 , 7 , 3 ]
N = len ( arr )
minOpsToTurnArrToZero ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
from collections import defaultdict
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def splitArray ( arr , N ) :
    mp = defaultdict ( int )
    for i in range ( N ) :
        mp [ arr [ i ] ] += 1
    G = 0
    for i in mp :
        G = gcd ( G , mp [ i ] )
    if ( G > 1 ) :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 4 , 3 , 2 , 1 ]
    n = len ( arr )
    splitArray ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
import math
def CheckAllEqual ( arr , N ) :
    for i in range ( 1 , N ) :
        if ( arr [ 0 ] != arr [ i ] ) :
            return False
    return True
def minCntOperations ( arr , N ) :
    Max = max ( arr )
    isPower2 = not ( Max and ( Max & ( Max - 1 ) ) )
    if ( isPower2 and CheckAllEqual ( arr , N ) ) :
        return log2 ( Max )
    else :
        return math . ceil ( math . log2 ( Max ) ) + 1
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 ]
    N = len ( arr )
    print ( minCntOperations ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def minXOR ( Arr , N ) :
    for i in range ( N ) :
        if ( Arr [ i ] == 2 ) :
            print ( Arr [ i ] ^ 3 , end = " ▁ " )
        else :
            print ( Arr [ i ] ^ 2 , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    Arr = [ 5 , 4 , 7 , 6 ]
    N = len ( Arr )
    minXOR ( Arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def findArray ( n ) :
    Arr = [ 0 ] * ( n + 1 )
    Arr [ 1 ] = 1
    for i in range ( 2 , n + 1 ) :
        if ( i % 2 == 0 ) :
            Arr [ i ] = Arr [ i // 2 ]
        else :
            Arr [ i ] = ( Arr [ ( i - 1 ) // 2 ] + Arr [ ( i - 1 ) // 2 + 1 ] )
    return Arr
def maxElement ( n ) :
    if ( n == 0 ) :
        return 0
    if ( n == 1 ) :
        return 1
    Arr = findArray ( n )
    return max ( Arr )
if __name__ == " _ _ main _ _ " :
    N = 7
    print ( maxElement ( N ) )

Index/key variables: i
Iterator variables: i
Python program:
def constGraphWithCon ( N , K ) :
    Max = ( ( N - 1 ) * ( N - 2 ) ) // 2
    if ( K > Max ) :
        print ( - 1 )
        return
    ans = [ ]
    for i in range ( 1 , N ) :
        for j in range ( i + 1 , N + 1 ) :
            ans . append ( [ i , j ] )
    for i in range ( 0 , ( N - 1 ) + Max - K ) :
        print ( ans [ i ] [ 0 ] , ans [ i ] [ 1 ] , sep = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 3
    constGraphWithCon ( N , K )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i, j
Python program:
def min_elements ( arr , N , K ) :
    mp = { }
    for i in range ( N ) :
        if arr [ i ] in mp :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    Freq = [ ]
    for it in mp :
        i = it
        Freq . append ( mp [ i ] )
    Freq . sort ( )
    Freq . reverse ( )
    Len = len ( Freq )
    if ( Len <= K ) :
        return 0
    cntMin = 0
    for i in range ( K , Len ) :
        cntMin += Freq [ i ]
    return cntMin
arr = [ 5 , 1 , 3 , 2 , 4 , 1 , 1 , 2 , 3 , 4 ]
N = len ( arr )
K = 3 ;
print ( min_elements ( arr , N , K ) )

Index/key variables: i
Accumulator variables: Freq, cntMin
Iterator variables: i, it
Python program:
def sumzero ( arr , N , K ) :
    sum = 0 ;
    for i in range ( N ) :
        sum += arr [ i ] ;
    if ( sum == 0 ) :
        print ( " Yes " ) ;
    elif ( sum > 0 ) :
        if ( sum % K == 0 ) :
            print ( " Yes " ) ;
        else :
            print ( " No " ) ;
    else :
        print ( " No " ) ;
if __name__ == " _ _ main _ _ " :
    arr1 = [ 1 , - 6 , 2 , 2 ] ;
    K = 1 ;
    N = len ( arr1 ) ;
    sumzero ( arr1 , N , K ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def cntOnesArrWithGivenOp ( arr , N ) :
    cntOnes = 0
    for i in range ( 1 , N + 1 ) :
        for j in range ( i - 1 , N , i ) :
            arr [ j ] = 1 if arr [ j ] == 0 else 0
    for i in range ( N ) :
        if ( arr [ i ] == 1 ) :
            cntOnes += 1
    return cntOnes
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 0 , 0 , 0 , 0 ]
    N = len ( arr )
    print ( cntOnesArrWithGivenOp ( arr , N ) )

Index/key variables: i, j
Accumulator variables: cntOnes
Iterator variables: i, j
Python program:
def cntKnightsAttackPawn ( knights , pawn , M ) :
    cntKnights = 0 ;
    for i in range ( M ) :
        X = abs ( knights [ i ] [ 0 ] - pawn [ 0 ] ) ;
        Y = abs ( knights [ i ] [ 1 ] - pawn [ 1 ] ) ;
        if ( ( X == 1 and Y == 2 ) or ( X == 2 and Y == 1 ) ) :
            cntKnights += 1 ;
    return cntKnights ;
if __name__ == ' _ _ main _ _ ' :
    knights = [ [ 0 , 4 ] , [ 4 , 5 ] , [ 1 , 4 ] , [ 3 , 1 ] ] ;
    pawn = [ 2 , 3 ] ;
    M = len ( knights ) ;
    print ( cntKnightsAttackPawn ( knights , pawn , M ) ) ;

Index/key variables: i
Accumulator variables: cntKnights
Iterator variables: i
Python program:
def findWinnerGameRemoveGCD ( arr , n ) :
    mp = dict . fromkeys ( arr , 0 ) ;
    for i in range ( n ) :
        for j in range ( 2 , int ( arr [ i ] * ( 1 / 2 ) ) + 1 ) :
            if ( arr [ i ] % j == 0 ) :
                mp [ j ] += 1 ;
                while ( arr [ i ] % j == 0 ) :
                    arr [ i ] = arr [ i ] // j ;
        if ( arr [ i ] > 1 ) :
            mp [ arr [ i ] ] += 1 ;
    maxCnt = 0 ;
    for i in mp :
        maxCnt = max ( maxCnt , mp [ i ] ) ;
    if ( n % 2 == 0 ) :
        if ( maxCnt >= n - 1 ) :
            print ( " Player ▁ 1" , end = " " ) ;
        else :
            print ( " Player ▁ 2" , end = " " ) ;
    else :
        if ( maxCnt == n ) :
            print ( " Player ▁ 1" , end = " " ) ;
        else :
            print ( " Player ▁ 2" , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 8 ] ;
    N = len ( arr ) ;
    findWinnerGameRemoveGCD ( arr , N ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def minimumSwaps ( arr1 , arr2 , n ) :
    sumArr1 = 0 ; sumArr2 = 0 ;
    for i in range ( n ) :
        sumArr1 += arr1 [ i ] ;
        sumArr2 += arr2 [ i ] ;
    if ( sumArr1 % 2 == 0 and sumArr2 % 2 == 0 ) :
        print ( 0 ) ;
        return ;
    if ( sumArr1 % 2 != 0 and sumArr2 % 2 != 0 ) :
        flag = - 1 ;
        for i in range ( n ) :
            if ( ( arr1 [ i ] + arr2 [ i ] ) % 2 == 1 ) :
                flag = 1 ;
                break ;
        print ( flag ) ;
        return ;
    print ( - 1 ) ;
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 11 , 14 , 20 , 2 ] ;
    arr2 = [ 5 , 9 , 6 , 3 ] ;
    N = len ( arr1 ) ;
    minimumSwaps ( arr1 , arr2 , N ) ;

Index/key variables: i
Accumulator variables: sumArr1, sumArr2
Iterator variables: i
Python program:
def corpFlightBookings ( Bookings , N ) :
    res = [ 0 ] * N
    for i in range ( len ( Bookings ) ) :
        l = Bookings [ i ] [ 0 ]
        r = Bookings [ i ] [ 1 ]
        K = Bookings [ i ] [ 2 ]
        res [ l - 1 ] = res [ l - 1 ] + K
        if ( r <= len ( res ) - 1 ) :
            res [ r ] = ( - K ) + res [ r ]
    for i in range ( 1 , len ( res ) ) :
        res [ i ] = res [ i ] + res [ i - 1 ]
    for i in range ( len ( res ) ) :
        print ( res [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    bookings = [ [ 1 , 3 , 100 ] , [ 2 , 6 , 100 ] , [ 3 , 4 , 100 ] ]
    N = 6
    corpFlightBookings ( bookings , N )

Index/key variables: i, r
Iterator variables: i
Python program:
def findSmallestNumber ( n ) :
    for i in range ( n , n + 2521 ) :
        possible = 1
        temp = i
        while ( temp ) :
            if ( temp % 10 != 0 ) :
                digit = temp % 10
                if ( i % digit != 0 ) :
                    possible = 0
                    break
            temp //= 10
        if ( possible == 1 ) :
            print ( i , end = " " )
            return
if __name__ == " _ _ main _ _ " :
    N = 31
    findSmallestNumber ( N )

Accumulator variables: temp
Iterator variables: i
Python program:
def path_to_root ( node ) :
    while ( node >= 1 ) :
        print ( node , end = " ▁ " )
        node //= 2
if __name__ == ' _ _ main _ _ ' :
    N = 7
    path_to_root ( N )

Accumulator variables: node
Python program:
def findSmallestNumberPossible ( N , K ) :
    if ( N > 45 * K ) :
        print ( " - 1" , endl = " " ) ;
        return ;
    res = " " ;
    count = 0 ;
    i = 9 ;
    while i >= 1 :
        if ( count == K ) :
            i -= 1 ;
            count = 0 ;
        if ( N > i ) :
            N -= i ;
            res += chr ( 48 + i ) ;
        else :
            res += chr ( N + 48 ) ;
            N = 0 ;
            break ;
        count += 1 ;
    res = res [ : : - 1 ]
    print ( res , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    N = 25 ; K = 3 ;
    findSmallestNumberPossible ( N , K ) ;

Accumulator variables: N, count, i, res
Python program:
def minValue ( arr , n ) :
    minimum = min ( arr )
    sum = 0
    for i in range ( n ) :
        sum = sum + ( arr [ i ] - minimum )
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 ]
    N = len ( arr )
    print ( minValue ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def result ( n ) :
    if ( n > 45 ) :
        print ( - 1 , end = " " )
        return
    res = " "
    digit = 9
    while ( n > digit ) :
        res = str ( digit ) + res
        n -= digit
        digit -= 1
    if ( n > 0 ) :
        res = str ( n ) + res
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    N = 19
    result ( N )

Accumulator variables: digit, n
Python program:
def findArray ( N , K ) :
    if ( N == 1 ) :
        print ( K , end = " ▁ " )
        return
    if ( N == 2 ) :
        print ( "0" , end = " ▁ " )
        print ( K , end = " ▁ " )
        return
    P = N - 2
    Q = N - 1
    VAL = 0
    for i in range ( 1 , N - 2 ) :
        print ( i , end = " ▁ " )
        VAL ^= i
    if ( VAL == K ) :
        print ( P , end = " ▁ " )
        print ( Q , end = " ▁ " )
        print ( P ^ Q , end = " ▁ " )
    else :
        print ( "0" , end = " ▁ " )
        print ( P , end = " ▁ " )
        print ( P ^ K ^ VAL , end = " ▁ " )
N = 4
X = 6
findArray ( N , X )

Accumulator variables: VAL
Iterator variables: i
Python program:
def findNumber ( N ) :
    count = 0
    while ( ( N & 1 ) == 1 ) :
        N = N >> 1
        count += 1
    return N << count
if __name__ == " _ _ main _ _ " :
    N = 39
    print ( findNumber ( N ) )

Accumulator variables: count
Python program:
def subString ( s , n ) :
    v = [ ]
    for i in range ( n ) :
        for len in range ( 1 , n - i + 1 ) :
            find = s [ i : i + len ]
            v . append ( find )
    return v
def IsPresent ( str , target ) :
    if ( target in str ) :
        return 1
    return - 1
def countSubstrings ( S , T ) :
    v = subString ( S , len ( S ) )
    ans = 0
    for it in v :
        if ( IsPresent ( it , T ) != - 1 ) :
            ans += 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    S = " dabc "
    T = " ab "
    countSubstrings ( S , T )

Accumulator variables: ans, v
Iterator variables: i, it, len
Python program:
def minOperation ( X , Y , n ) :
    C = 0 ;
    count = 0 ;
    for i in range ( 1 , n , 2 ) :
        if ( X [ i ] != Y [ i ] ) :
            count += 1 ;
        else :
            if ( count != 0 ) :
                C += 1 ;
            count = 0 ;
    if ( count != 0 ) :
        C += 1 ;
    count = 0 ;
    for i in range ( 0 , n , 2 ) :
        if ( X [ i ] != Y [ i ] ) :
            count += 1 ;
        else :
            if ( count != 0 ) :
                C += 1 ;
            count = 0 ;
    if ( count != 0 ) :
        C += 1 ;
    print ( C ) ;
if __name__ == ' _ _ main _ _ ' :
    X = [ 1 , 0 , 0 , 0 , 0 , 1 ] ;
    Y = [ 1 , 1 , 0 , 1 , 1 , 1 ] ;
    N = len ( X ) ;
    minOperation ( X , Y , N ) ;

Index/key variables: i
Accumulator variables: C, count
Iterator variables: i
Python program:
def minimumcntOperationReq ( arr , N ) :
    cntOp = 0
    for i in range ( N - 1 ) :
        if ( arr [ i ] == arr [ i + 1 ] ) :
            cntOp += 1
    return ( cntOp + 1 ) // 2
arr = [ 1 , 1 , 1 , 0 , 1 , 0 , 0 , 0 ]
N = len ( arr )
print ( minimumcntOperationReq ( arr , N ) )

Index/key variables: i
Accumulator variables: cntOp
Iterator variables: i
Python program:
def isSequenceValid ( B , N ) :
    for i in range ( N ) :
        if ( ( i + 1 ) % B [ i ] != 0 ) :
            print ( " No " )
            return
    print ( " Yes " )
N = 4
arr = [ 1 , 2 , 3 , 2 ]
isSequenceValid ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def ConstArrayAdjacentCoprime ( N ) :
    for i in range ( 1 , N + 1 ) :
        print ( i , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    N = 6
    ConstArrayAdjacentCoprime ( N )

Iterator variables: i
Python program:
def minimumCost ( a , b ) :
    fre1 = [ 0 ] * ( 256 )
    fre2 = [ 0 ] * ( 256 )
    for c in a :
        fre1 [ ord ( c ) ] += 1
    for c in b :
        fre2 [ ord ( c ) ] += 1
    mincost = 0
    for i in range ( 256 ) :
        mincost += abs ( fre1 [ i ] - fre2 [ i ] )
    print ( mincost )
if __name__ == ' _ _ main _ _ ' :
    A = "1AB + - "
    B = " cc "
    minimumCost ( A , B )

Index/key variables: i
Accumulator variables: mincost
Iterator variables: c, i
Python program:
def minCost ( arr ) :
    odd = 0
    even = 0
    for i in range ( len ( arr ) ) :
        if ( arr [ i ] % 2 == 0 ) :
            even += 1
        else :
            odd += 1
    print ( min ( even , odd ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 ]
    minCost ( arr )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
def findMaxSumByAlternatingSign ( arr , N ) :
    cntNeg = 0
    MaxAltSum = 0
    SmValue = 0
    sum = 0
    for i in range ( N ) :
        if ( arr [ i ] < 0 ) :
            cntNeg += 1
        sum += abs ( arr [ i ] )
        SmValue = min ( SmValue , abs ( arr [ i ] ) )
    MaxAltSum = sum
    if ( cntNeg & 1 ) :
        MaxAltSum -= 2 * SmValue
    return MaxAltSum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , - 2 , - 4 , 5 ]
    N = len ( arr )
    print ( findMaxSumByAlternatingSign ( arr , N ) )

Index/key variables: i
Accumulator variables: cntNeg, sum
Iterator variables: i
Python program:
def constructNewArraySumZero ( arr , N ) :
    newArr = [ 0 ] * N
    for i in range ( N ) :
        if ( i % 2 == 0 ) :
            newArr [ i ] = arr [ i + 1 ]
        else :
            newArr [ i ] = - arr [ i - 1 ]
    for i in range ( N ) :
        print ( newArr [ i ] , end = " ▁ " )
arr = [ 1 , 2 , 3 , - 5 , - 6 , 8 ]
N = len ( arr )
constructNewArraySumZero ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
from collections import deque
def bitonicSequence ( num , lower , upper ) :
    if ( num > ( upper - lower ) * 2 + 1 ) :
        print ( - 1 )
        return
    ans = deque ( )
    for i in range ( min ( upper - lower + 1 , num - 1 ) ) :
        ans . append ( upper - i )
    for i in range ( num - len ( ans ) ) :
        ans . appendleft ( upper - i - 1 )
    print ( list ( ans ) )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    L = 3
    R = 10
    bitonicSequence ( N , L , R )

Accumulator variables: ans
Iterator variables: i
Python program:
def countSubstrings ( s , t ) :
    answ = 0
    for i in range ( len ( s ) ) :
        for j in range ( len ( t ) ) :
            if t [ j ] != s [ i ] :
                answ += 1
                k = 1
                z = - 1
                q = 1
                while ( j + z >= 0 <= i + z and s [ i + z ] == t [ j + z ] ) :
                    z -= 1
                    answ += 1
                    q += 1
                while ( len ( s ) > i + k and j + k < len ( t ) and s [ i + k ] == t [ j + k ] ) :
                    k += 1
                    answ += q
                    z = - 1
    return answ
S = " aba "
T = " baba "
print ( countSubstrings ( S , T ) )

Index/key variables: i, j
Accumulator variables: answ, k, q, z
Iterator variables: i, j
Python program:
def minimumCntOfFlipsRequired ( str ) :
    n = len ( str ) ;
    zeros = 0 ;
    for i in range ( n ) :
        if ( str [ i ] == '0' ) :
            zeros += 1 ;
    if ( zeros == 0 or zeros == n ) :
        return 0 ;
    minFlips = 10000001 ;
    currOnes = 0 ;
    flips = 0 ;
    for i in range ( n ) :
        if ( str [ i ] == '1' ) :
            currOnes += 1 ;
        flips = currOnes + ( zeros - ( i + 1 - currOnes ) ) ;
        minFlips = min ( minFlips , flips ) ;
    return minFlips ;
if __name__ == ' _ _ main _ _ ' :
    str = "100101" ;
    print ( minimumCntOfFlipsRequired ( str ) ) ;

Index/key variables: i
Accumulator variables: currOnes, zeros
Iterator variables: i
Python program:
def findLongestNonDecreasing ( A , N ) :
    res = 0 ;
    start = 0 ;
    end = N - 1 ;
    prev = - 1 ;
    while ( start <= end ) :
        if ( A [ start ] <= A [ end ] ) :
            if ( prev == - 1 ) :
                prev = A [ start ] ;
                res += 1
                start += 1
            else :
                if ( A [ start ] >= prev ) :
                    res += 1
                    prev = A [ start ] ;
                    start += 1
                elif ( A [ end ] >= prev ) :
                    res += 1
                    prev = A [ end ] ;
                    end -= 1
                else :
                    break ;
        else :
            if ( prev == - 1 ) :
                prev = A [ end ] ;
                res += 1
                end -= 1
            else :
                if ( A [ end ] >= prev ) :
                    res += 1
                    prev = A [ end ] ;
                    end -= 1
                elif ( A [ start ] >= prev ) :
                    res += 1
                    prev = A [ start ] ;
                    start += 1
                else :
                    break ;
    return res
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 1 , 3 , 5 , 4 , 3 , 6 , 2 , 1 ]
    N = len ( A )
    print ( findLongestNonDecreasing ( A , N ) ) ;

Index/key variables: end, start
Accumulator variables: res
Python program:
def findPairs ( N ) :
    for i in range ( 0 , N + 1 ) :
        print ( " ( " , i , " , " , N - i , " ) , ▁ " , end = " " )
if __name__ == " _ _ main _ _ " :
    N = 5
    findPairs ( N )

Iterator variables: i
Python program:
def GCD ( a , b ) :
    if ( b == 0 ) :
        return a
    return GCD ( b , a % b )
def findPartition ( nums , N ) :
    prefix = [ 0 ] * N
    suffix = [ 0 ] * N
    prefix [ 0 ] = nums [ 0 ]
    for i in range ( 1 , N ) :
        prefix [ i ] = ( prefix [ i - 1 ] * nums [ i ] )
    suffix [ N - 1 ] = nums [ N - 1 ]
    for i in range ( N - 2 , - 1 , - 1 ) :
        suffix [ i ] = ( suffix [ i + 1 ] * nums [ i ] )
    for k in range ( N - 1 ) :
        if ( GCD ( prefix [ k ] , suffix [ k + 1 ] ) == 1 ) :
            return k
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 , 5 ]
    N = len ( arr )
    print ( findPartition ( arr , N ) )

Index/key variables: i, k
Iterator variables: i, k