dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def getMinJumps ( s ) :
    ones = [ ]
    jumps , median , ind = 0 , 0 , 0
    for i in range ( len ( s ) ) :
        if ( s [ i ] == '1' ) :
            ones . append ( i )
    if ( len ( ones ) == 0 ) :
        return jumps
    median = ones [ len ( ones ) // 2 ]
    ind = median
    for i in range ( ind , - 1 , - 1 ) :
        if ( s [ i ] == '1' ) :
            jumps += ind - i
            ind -= 1
    ind = median
    for i in range ( ind , len ( s ) ) :
        if ( s [ i ] == '1' ) :
            jumps += i - ind
            ind += 1
    return jumps
if __name__ == ' _ _ main _ _ ' :
    s = "00100000010011"
    print ( getMinJumps ( s ) )

Index/key variables: i
Accumulator variables: ind, jumps, ones
Iterator variables: i
Python program:
N = 10 ** 5 + 5
v = [ [ ] for i in range ( N ) ]
val = [ 0 ] * ( N )
answer = [ 0 ] * ( N )
n = 0
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def DFS ( node , parent ) :
    answer [ node ] = val [ node ]
    for child in v [ node ] :
        if ( child == parent ) :
            continue
        DFS ( child , node )
        answer [ node ] = gcd ( answer [ node ] , answer [ child ] )
def preprocess ( ) :
    DFS ( 1 , - 1 )
def findGCD ( queries , q ) :
    preprocess ( )
    for i in range ( q ) :
        GCD = answer [ queries [ i ] ]
        print ( " For ▁ subtree ▁ of ▁ " , queries [ i ] , " , ▁ GCD ▁ = ▁ " , GCD )
if __name__ == ' _ _ main _ _ ' :
    n = 5
    v [ 1 ] . append ( 2 )
    v [ 2 ] . append ( 1 )
    v [ 1 ] . append ( 3 )
    v [ 3 ] . append ( 1 )
    v [ 3 ] . append ( 4 )
    v [ 4 ] . append ( 3 )
    v [ 3 ] . append ( 5 )
    v [ 5 ] . append ( 3 )
    val [ 1 ] = 2
    val [ 2 ] = 3
    val [ 3 ] = 4
    val [ 4 ] = 8
    val [ 5 ] = 16
    queries = [ 2 , 3 , 1 ]
    q = len ( queries )
    findGCD ( queries , q )

Index/key variables: child, i, node
Iterator variables: child, i
Python program:
def splitFraction ( n , d ) :
    ar = [ ]
    for i in range ( 0 , n ) :
        ar . append ( 0 )
    first = d + n - 1
    ar [ 0 ] = first
    for i in range ( 1 , n ) :
        temp = first - 1
        ar [ i ] = first * temp
        first -= 1
    for i in range ( 0 , n ) :
        if ar [ i ] % n == 0 :
            print ( "1 / " , int ( ar [ i ] / n ) , " , " , end = " ▁ " )
        else :
            print ( n , " / " , ar [ i ] , " , " , end = " ▁ " )
N = 4
D = 2
splitFraction ( N , D )

Index/key variables: i
Accumulator variables: ar, first
Iterator variables: i
Python program:
def numPairs ( arr , n ) :
    ans = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if arr [ j ] % arr [ i ] == 0 :
                ans += 1
    return ans
arr = [ 1 , 1 , 2 , 2 , 3 , 3 ]
n = len ( arr )
print ( numPairs ( arr , n ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def check ( arr , n ) :
    flag = True ;
    for i in range ( n ) :
        if ( arr [ i ] < n - i ) :
            flag = False ;
    if ( flag ) :
        return True ;
    else :
        return False ;
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 11 , 11 , 11 , 11 ] ;
    n1 = len ( arr1 ) ;
    if ( check ( arr1 , n1 ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Iterator variables: i
Boolean variables: flag
Python program:
def minOccupiedPosition ( A , n ) :
    minPos = 0
    i = 0
    while i < n :
        if ( A [ i ] > 0 ) :
            minPos += 1
            i += 2
        i += 1
    return minPos
if __name__ == ' _ _ main _ _ ' :
    A = [ 8 , 0 , 7 , 0 , 0 , 6 ]
    n = len ( A )
    print ( minOccupiedPosition ( A , n ) )

Index/key variables: i
Accumulator variables: minPos
Python program:
import math
def findMinimumK ( a , n , S ) :
    sum = 0
    for i in range ( 0 , n ) :
        sum += a [ i ]
    return math . ceil ( ( ( S + 1 ) * 1.0 ) / ( sum * 1.0 ) )
a = [ 10 , 7 , 8 , 10 , 12 , 19 ]
n = len ( a )
s = 200
print ( findMinimumK ( a , n , s ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def largestNum ( n ) :
    num = 0 ;
    for i in range ( 32 ) :
        x = ( 1 << i ) ;
        if ( ( x - 1 ) <= n ) :
            num = ( 1 << i ) - 1 ;
        else :
            break ;
    return num ;
if __name__ == " _ _ main _ _ " :
    N = 345 ;
    print ( largestNum ( N ) ) ;

Iterator variables: i
Python program:
def findString ( N , K ) :
    for i in range ( N ) :
        print ( chr ( ord ( ' A ' ) + i % K ) , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    N = 10 ;
    K = 3 ;
    findString ( N , K ) ;

Iterator variables: i
Python program:
def count ( s ) :
    cnt , ans = 0 , 0
    N = len ( s )
    for i in range ( N ) :
        if ( s [ i ] == ' R ' ) :
            cnt += 1
        if ( s [ i ] == ' L ' ) :
            ans += cnt
    return ans
s = " RRLL "
print ( count ( s ) )

Index/key variables: i
Accumulator variables: ans, cnt
Iterator variables: i
Python program:
def findMinimumSubsequences ( A , B ) :
    numberOfSubsequences = 1
    sizeOfB = len ( B )
    sizeOfA = len ( A )
    inf = 1000000
    next = [ [ inf for i in range ( sizeOfB ) ] for i in range ( 26 ) ]
    for i in range ( sizeOfB ) :
        next [ ord ( B [ i ] ) - ord ( ' a ' ) ] [ i ] = i
    for i in range ( 26 ) :
        for j in range ( sizeOfB - 2 , - 1 , - 1 ) :
            if ( next [ i ] [ j ] == inf ) :
                next [ i ] [ j ] = next [ i ] [ j + 1 ]
    pos = 0
    i = 0
    while ( i < sizeOfA ) :
        if ( pos == 0 and next [ ord ( A [ i ] ) - ord ( ' a ' ) ] [ pos ] == inf ) :
            numberOfSubsequences = - 1
            break
        elif ( pos < sizeOfB and next [ ord ( A [ i ] ) - ord ( ' a ' ) ] [ pos ] < inf ) :
            nextIndex = next [ ord ( A [ i ] ) - ord ( ' a ' ) ] [ pos ] + 1
            pos = nextIndex
            i += 1
        else :
            numberOfSubsequences += 1
            pos = 0
    return numberOfSubsequences
if __name__ == ' _ _ main _ _ ' :
    A = " aacbe "
    B = " aceab "
    print ( findMinimumSubsequences ( A , B ) )

Index/key variables: i, j, pos
Accumulator variables: numberOfSubsequences
Iterator variables: i, j
Python program:
MAX_SIZE = 10 ;
def convolution ( x , h , n , m ) :
    row_vec = [ 0 ] * MAX_SIZE ;
    col_vec = [ 0 ] * MAX_SIZE ;
    out = [ 0 ] * MAX_SIZE ;
    circular_shift_mat = [ [ 0 for i in range ( MAX_SIZE ) ] for j in range ( MAX_SIZE ) ] ;
    if ( n > m ) :
        maxSize = n ;
    else :
        maxSize = m ;
    for i in range ( maxSize ) :
        if ( i >= n ) :
            row_vec [ i ] = 0 ;
        else :
            row_vec [ i ] = x [ i ] ;
    for i in range ( maxSize ) :
        if ( i >= m ) :
            col_vec [ i ] = 0 ;
        else :
            col_vec [ i ] = h [ i ] ;
    k = 0 ;
    d = 0 ;
    for i in range ( maxSize ) :
        curIndex = k - d ;
        for j in range ( maxSize ) :
            circular_shift_mat [ j ] [ i ] = row_vec [ curIndex % maxSize ] ;
            curIndex += 1 ;
        k = maxSize ;
        d += 1 ;
    for i in range ( maxSize ) :
        for j in range ( maxSize ) :
            out [ i ] += circular_shift_mat [ i ] [ j ] * col_vec [ j ] ;
        print ( out [ i ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    x = [ 5 , 7 , 3 , 2 ] ;
    n = len ( x ) ;
    h = [ 1 , 5 ] ;
    m = len ( h ) ;
    convolution ( x , h , n , m ) ;

Index/key variables: i, j
Accumulator variables: curIndex, d
Iterator variables: i, j
Python program:
def max_palindrome ( s , n ) :
    flag = 0 ;
    for i in range ( n ) :
        if ( len ( s [ i ] ) % 2 != 0 ) :
            flag = 1 ;
    if ( flag == 1 ) :
        return n ;
    z = 0 ; o = 0 ;
    for i in range ( n ) :
        for j in range ( len ( s [ i ] ) ) :
            if ( s [ i ] [ j ] == '0' ) :
                z += 1 ;
            else :
                o += 1 ;
    if ( o % 2 == 0 and z % 2 == 0 ) :
        return n ;
    else :
        return n - 1 ;
if __name__ == " _ _ main _ _ " :
    n = 3 ;
    s = [ "1110" , "100110" , "010101" ] ;
    print ( max_palindrome ( s , n ) ) ;

Index/key variables: i, j
Accumulator variables: o, z
Iterator variables: i, j
Python program:
def minCost ( cost , n ) :
    totalCost = 0
    boardingBus = 0
    for i in range ( 1 , n ) :
        if ( cost [ boardingBus ] > cost [ i ] ) :
            totalCost += ( ( i - boardingBus ) * cost [ boardingBus ] )
            boardingBus = i
    totalCost += ( ( n - boardingBus ) * cost [ boardingBus ] )
    return totalCost
cost = [ 4 , 7 , 8 , 3 , 4 ]
n = len ( cost )
print ( minCost ( cost , n ) )

Index/key variables: boardingBus, i
Accumulator variables: totalCost
Iterator variables: i
Python program:
import sys
def minFlipsSub ( mat , i , j ) :
    cnt0 = 0
    cnt1 = 0
    if ( mat [ i ] [ j ] == '1' ) :
        cnt1 += 1
    else :
        cnt0 += 1
    if ( mat [ i ] [ j + 1 ] == '1' ) :
        cnt1 += 1
    else :
        cnt0 += 1
    if ( mat [ i + 1 ] [ j ] == '1' ) :
        cnt1 += 1
    else :
        cnt0 += 1
    if ( mat [ i + 1 ] [ j + 1 ] == '1' ) :
        cnt1 += 1
    else :
        cnt0 += 1
    return min ( cnt0 , cnt1 )
def minFlips ( mat , r , c ) :
    res = sys . maxsize
    for i in range ( r - 1 ) :
        for j in range ( c - 1 ) :
            res = min ( res , minFlipsSub ( mat , i , j ) )
    return res
if __name__ == ' _ _ main _ _ ' :
    mat = [ "0101" , "0101" , "0101" ]
    r = len ( mat )
    c = len ( mat [ 0 ] )
    print ( minFlips ( mat , r , c ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def minCost ( str1 , str2 , n ) :
    cost = 0
    for i in range ( n ) :
        if ( str1 [ i ] != str2 [ i ] ) :
            if ( i < n - 1 and str1 [ i + 1 ] != str2 [ i + 1 ] ) :
                swap ( str1 [ i ] , str1 [ i + 1 ] )
                cost += 1
            else :
                cost += 1
    return cost
if __name__ == ' _ _ main _ _ ' :
    str1 = " abb "
    str2 = " bba "
    n = len ( str1 )
    print ( minCost ( str1 , str2 , n ) )

Index/key variables: i
Accumulator variables: cost
Iterator variables: i
Python program:
def CheckForSequence ( arr , n , k ) :
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( k >= arr [ i ] ) :
            k -= arr [ i ] ;
    if ( k != 0 ) :
        return False ;
    else :
        return True ;
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 3 , 7 , 15 , 31 ] ;
    n = len ( A ) ;
    if ( CheckForSequence ( A , n , 18 ) ) :
        print ( True )
    else :
        print ( False )

Index/key variables: i
Accumulator variables: k
Iterator variables: i
Python program:
import sys
from math import floor , ceil
def generateArray ( n , k ) :
    array = [ 0 ] * k
    remaining = n - int ( k * ( k + 1 ) / 2 )
    if remaining < 0 :
        print ( " NO " )
        sys . exit ( )
    right_most = remaining % k
    high = ceil ( remaining / k )
    low = floor ( remaining / k )
    for i in range ( k - right_most , k ) :
        array [ i ] = high
    for i in range ( k - right_most ) :
        array [ i ] = low
    for i in range ( k ) :
        array [ i ] += i + 1
    if k - 1 != remaining or k == 1 :
        print ( * array )
        sys . exit ( )
    elif k == 2 or k == 3 :
        print ( " - 1" )
        sys . exit ( )
    else :
        array [ 1 ] -= 1
        array [ k - 1 ] += 1
        print ( * array )
        sys . exit ( )
if __name__ == " _ _ main _ _ " :
    n , k = 26 , 6
    generateArray ( n , k )

Index/key variables: i
Iterator variables: i
Python program:
def get_maximum ( s , a ) :
    s = list ( s )
    n = len ( s )
    for i in range ( n ) :
        if ( ord ( s [ i ] ) - ord ( '0' ) < a [ ord ( s [ i ] ) - ord ( '0' ) ] ) :
            j = i
            while ( j < n and ( ord ( s [ j ] ) - ord ( '0' ) <= a [ ord ( s [ j ] ) - ord ( '0' ) ] ) ) :
                s [ j ] = chr ( ord ( '0' ) + a [ ord ( s [ j ] ) - ord ( '0' ) ] )
                j += 1
            return " " . join ( s ) ;
    return s
if __name__ == " _ _ main _ _ " :
    s = "1337"
    a = [ 0 , 1 , 2 , 5 , 4 , 6 , 6 , 3 , 1 , 9 ]
    print ( get_maximum ( s , a ) )

Index/key variables: i, j
Iterator variables: i
Python program:
from math import sqrt
def countSteps ( n ) :
    steps = 0 ;
    while ( n ) :
        largest = int ( sqrt ( n ) ) ;
        n -= ( largest * largest ) ;
        steps += 1 ;
    return steps ;
if __name__ == " _ _ main _ _ " :
    n = 85 ;
    print ( countSteps ( n ) ) ;

Accumulator variables: n, steps
Python program:
def sumArr ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    return sum
def maxSum ( arr , n , k ) :
    arr . sort ( reverse = False )
    i = 0
    while ( i < n and k > 0 and arr [ i ] < 0 ) :
        arr [ i ] *= - 1
        k -= 1
        i += 1
    if ( k % 2 == 1 ) :
        min = 0
        for i in range ( 1 , n ) :
            if ( arr [ min ] > arr [ i ] ) :
                min = i
        arr [ min ] *= - 1
    return sumArr ( arr , n )
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 5 , 4 , 1 , 3 , 2 ]
    n = len ( arr )
    k = 4
    print ( maxSum ( arr , n , k ) )

Index/key variables: i, min
Accumulator variables: k, sum
Iterator variables: i
Python program:
from typing import List
par = [ ]
rnk = [ ]
def find ( x : int ) -> int :
    global par
    if ( par [ x ] != x ) :
        par [ x ] = find ( par [ x ] )
    return par [ x ]
def Union ( u : int , v : int ) -> None :
    global par , rnk
    x = find ( u )
    y = find ( v )
    if ( x == y ) :
        return
    if ( rnk [ x ] > rnk [ y ] ) :
        par [ y ] = x
    elif ( rnk [ x ] < rnk [ y ] ) :
        par [ x ] = y
    else :
        par [ x ] = y
        rnk [ y ] += 1
def findSpanningTree ( deg : List [ int ] , n : int , m : int , g : List [ List [ int ] ] ) -> None :
    global rnk , par
    par = [ i for i in range ( n + 1 ) ]
    rnk = [ 0 ] * ( n + 1 )
    max = 1
    for i in range ( 2 , n + 1 ) :
        if ( deg [ i ] > deg [ max ] ) :
            max = i
    for v in g [ max ] :
        print ( " { } ▁ { } " . format ( max , v ) )
        Union ( max , v )
    for u in range ( 1 , n + 1 ) :
        for v in g [ u ] :
            x = find ( u )
            y = find ( v )
            if ( x == y ) :
                continue
            Union ( x , y )
            print ( " { } ▁ { } " . format ( u , v ) )
if __name__ == " _ _ main _ _ " :
    n = 5
    m = 5
    g = [ [ ] for _ in range ( n + 1 ) ]
    deg = [ 0 ] * ( n + 1 )
    g [ 1 ] . append ( 2 )
    g [ 2 ] . append ( 1 )
    deg [ 1 ] += 1
    deg [ 2 ] += 1
    g [ 1 ] . append ( 5 )
    g [ 5 ] . append ( 1 )
    deg [ 1 ] += 1
    deg [ 5 ] += 1
    g [ 2 ] . append ( 3 )
    g [ 3 ] . append ( 2 )
    deg [ 2 ] += 1
    deg [ 3 ] += 1
    g [ 5 ] . append ( 3 )
    g [ 3 ] . append ( 5 )
    deg [ 3 ] += 1
    deg [ 5 ] += 1
    g [ 3 ] . append ( 4 )
    g [ 4 ] . append ( 3 )
    deg [ 3 ] += 1
    deg [ 4 ] += 1
    findSpanningTree ( deg , n , m , g )

Index/key variables: i, int, max, u, x, y
Iterator variables: i, u, v
Python program:
def printArray ( N , arr ) :
    for i in range ( 0 , N ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
def replacedArray ( N , arr ) :
    pos_sum = 0
    neg_sum = 0
    for i in range ( N - 1 , - 1 , - 1 ) :
        diff = abs ( pos_sum ) - abs ( neg_sum )
        if ( arr [ i ] > 0 ) :
            pos_sum = pos_sum + arr [ i ]
        else :
            neg_sum = neg_sum + arr [ i ]
        arr [ i ] = abs ( diff )
N = 5
arr = [ 1 , - 1 , 2 , 3 , - 2 ]
replacedArray ( N , arr )
printArray ( N , arr )
N = 6
arr1 = [ - 3 , - 4 , - 2 , 5 , 1 , - 2 ]
replacedArray ( N , arr1 )
printArray ( N , arr1 )

Index/key variables: i
Iterator variables: i
Python program:
def findArray ( N , P ) :
    ans = ( P * ( P + 1 ) ) // 2 + ( N - P ) ;
    arr = [ 0 ] * ( N + 1 ) ;
    for i in range ( 1 , P + 1 ) :
        arr [ i ] = i ;
    for i in range ( P + 1 , N + 1 ) :
        arr [ i ] = 1 ;
    print ( " The ▁ Minimum ▁ Possible ▁ Sum ▁ is : ▁ " , ans ) ;
    print ( " The ▁ Array ▁ Elements ▁ are : ▁ " ) ;
    for i in range ( 1 , N + 1 ) :
        print ( arr [ i ] , end = " ▁ " ) ;
N = 5 ;
P = 3 ;
findArray ( N , P ) ;

Index/key variables: i
Iterator variables: i
Python program:
def findIntersection ( intervals , N ) :
    l = intervals [ 0 ] [ 0 ]
    r = intervals [ 0 ] [ 1 ]
    for i in range ( 1 , N ) :
        if ( intervals [ i ] [ 0 ] > r or intervals [ i ] [ 1 ] < l ) :
            print ( - 1 )
        else :
            l = max ( l , intervals [ i ] [ 0 ] )
            r = min ( r , intervals [ i ] [ 1 ] )
    print ( " [ " , l , " , ▁ " , r , " ] " )
intervals = [ [ 1 , 6 ] , [ 2 , 8 ] , [ 3 , 10 ] , [ 5 , 8 ] ]
N = len ( intervals )
findIntersection ( intervals , N )

Index/key variables: i
Iterator variables: i
Python program:
def cmp ( a , b ) :
    return ( a > b ) - ( a < b )
def maxSubarraySize ( arr ) :
    N = len ( arr )
    ans = 1
    anchor = 0
    for i in range ( 1 , N ) :
        c = cmp ( arr [ i - 1 ] , arr [ i ] )
        if c == 0 :
            anchor = i
        elif i == N - 1 or c * cmp ( arr [ i ] , arr [ i + 1 ] ) != - 1 :
            ans = max ( ans , i - anchor + 1 )
            anchor = i
    return ans
arr = [ 9 , 4 , 2 , 10 , 7 , 8 , 8 , 1 , 9 ]
print ( maxSubarraySize ( arr ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxSubStrings ( s , k ) :
    maxSubStr = 0
    n = len ( s )
    for c in range ( 27 ) :
        ch = chr ( ord ( ' a ' ) + c )
        curr = 0
        for i in range ( n - k ) :
            if ( s [ i ] != ch ) :
                continue
            cnt = 0
            while ( i < n and s [ i ] == ch and cnt != k ) :
                i += 1
                cnt += 1
            i -= 1
            if ( cnt == k ) :
                curr += 1
        maxSubStr = max ( maxSubStr , curr )
    return maxSubStr
if __name__ == ' _ _ main _ _ ' :
    s = " aaacaabbaa "
    k = 2
    print ( maxSubStrings ( s , k ) )

Index/key variables: i
Accumulator variables: cnt, curr
Iterator variables: c, i
Python program:
def ValidPairs ( arr ) :
    count = [ 0 ] * 121
    for ele in arr :
        count [ ele ] += 1
    ans = 0
    for eleX , countX in enumerate ( count ) :
        for eleY , countY in enumerate ( count ) :
            if eleX < eleY :
                continue
            if ( abs ( eleX - eleY ) % 2 == 1 ) :
                continue
            ans += countX * countY
            if eleX == eleY :
                ans -= countX
    return ans
arr = [ 16 , 17 , 18 ]
print ( ValidPairs ( arr ) )

Index/key variables: ele
Accumulator variables: ans
Iterator variables: countX, countY, ele, eleX, eleY
Python program:
def check_distribution ( n , k , age , candy ) :
    mxage = max ( age ) + 1
    mxcandy = max ( candy ) + 1
    fr1 = [ 0 ] * mxage
    fr2 = [ 0 ] * mxcandy
    for j in range ( n ) :
        fr1 [ age [ j ] ] += 1
    for j in range ( k ) :
        fr2 [ candy [ j ] ] += 1
    k = 0
    Tf = True
    for j in range ( mxage ) :
        if ( fr1 [ j ] == 0 ) :
            continue
        flag = False
        while ( k < mxcandy ) :
            if ( fr1 [ j ] <= fr2 [ k ] ) :
                flag = True
                break
            k += 1
        k = k + 1
        if ( flag == False ) :
            Tf = False
            break
    if ( Tf ) :
        print ( " YES " )
    else :
        print ( " NO " )
age = [ 5 , 15 , 10 ]
candy = [ 2 , 2 , 2 , 3 , 3 , 4 ]
n = len ( age )
k = len ( candy )
check_distribution ( n , k , age , candy )

Index/key variables: j, k
Iterator variables: j
Boolean variables: Tf, flag
Python program:
def minChanges ( A , n ) :
    cnt = 0
    for i in range ( n - 2 ) :
        if ( ( i - 1 >= 0 ) and A [ i - 1 ] == 1 and A [ i + 1 ] == 1 and A [ i ] == 0 ) :
            A [ i + 1 ] = 0
            cnt = cnt + 1
    return cnt
A = [ 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 0 ]
n = len ( A )
print ( minChanges ( A , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def completeSequence ( s ) :
    n = len ( s )
    open = 0
    close = 0
    for i in range ( n ) :
        if ( s [ i ] == ' ( ' ) :
            open += 1
        else :
            close += 1
        if ( close > open ) :
            print ( " IMPOSSIBLE " )
            return
    print ( s , end = " " )
    for i in range ( open - close ) :
        print ( " ) " , end = " " )
if __name__ == " _ _ main _ _ " :
    s = " ( ( ) ( ( ) ( "
    completeSequence ( s )

Index/key variables: i
Accumulator variables: close, open
Iterator variables: i
Python program:
def smallestPermute ( n ) :
    res = [ " " ] * ( n + 1 )
    if ( n % 2 == 0 ) :
        for i in range ( n ) :
            if ( i % 2 == 0 ) :
                res [ i ] = chr ( 48 + i + 2 )
            else :
                res [ i ] = chr ( 48 + i )
    else :
        for i in range ( n - 2 ) :
            if ( i % 2 == 0 ) :
                res [ i ] = chr ( 48 + i + 2 )
            else :
                res [ i ] = chr ( 48 + i )
        res [ n - 1 ] = chr ( 48 + n - 2 )
        res [ n - 2 ] = chr ( 48 + n )
        res [ n - 3 ] = chr ( 48 + n - 1 )
    res = ' ' . join ( res )
    return res
if __name__ == " _ _ main _ _ " :
    n = 7
    print ( smallestPermute ( n ) )

Index/key variables: i
Iterator variables: i
Python program:
import math
def minInsertions ( H , n , K ) :
    inser = 0 ;
    for i in range ( 1 , n ) :
        diff = abs ( H [ i ] - H [ i - 1 ] ) ;
        if ( diff <= K ) :
            continue ;
        else :
            inser += math . ceil ( diff / K ) - 1 ;
    return inser ;
H = [ 2 , 4 , 8 , 16 ] ;
K = 3 ;
n = len ( H ) ;
print ( minInsertions ( H , n , K ) ) ;

Index/key variables: i
Accumulator variables: inser
Iterator variables: i
Python program:
def count_minimum_operations ( n ) :
    count = 0
    while ( n > 1 ) :
        if ( n % 3 == 0 ) :
            n //= 3
        elif ( n % 3 == 1 ) :
            n -= 1
        else :
            if ( n == 2 ) :
                n -= 1
            else :
                n += 1
        count += 1
    return count
if __name__ == " _ _ main _ _ " :
    n = 4
    ans = count_minimum_operations ( n )
    print ( ans )

Accumulator variables: count, n
Python program:
def maxSum ( arr , n ) :
    s = 0
    l = [ ]
    for i in range ( len ( a ) ) :
        s += abs ( a [ i ] )
        if ( a [ i ] >= 0 ) :
            continue
        if ( i == 0 ) :
            l . append ( i + 1 )
        else :
            l . append ( i + 1 )
            l . append ( i )
    print ( s )
    print ( * l )
n = 4
a = [ 1 , - 2 , - 3 , 4 ]
maxSum ( a , n )

Index/key variables: i
Accumulator variables: l, s
Iterator variables: i
Python program:
def LengthLCP ( x , y ) :
    fr = [ 0 ] * 26
    for i in range ( b ) :
        fr [ ord ( y [ i ] ) - 97 ] += 1
    c = 0
    for i in range ( a ) :
        if ( fr [ ord ( x [ i ] ) - 97 ] > 0 ) :
            c += 1
            fr [ ord ( x [ i ] ) - 97 ] -= 1
        else :
            break
    print ( c )
x , y = " here " , " there "
LengthLCP ( x , y )

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