dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def getPositionCount ( a , n ) :
    count = 1 ;
    min = a [ 0 ] ;
    for i in range ( 1 , n ) :
        if ( a [ i ] <= min ) :
            min = a [ i ] ;
            count += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    a = [ 5 , 4 , 6 , 1 , 3 , 1 ] ;
    n = len ( a ) ;
    print ( getPositionCount ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def maxSum ( arr , n , k ) :
    if ( n < k ) :
        return - 1 ;
    res = 0 ;
    for i in range ( k ) :
        res += arr [ i ] ;
    curr_sum = res ;
    for i in range ( k , n ) :
        curr_sum += arr [ i ] - arr [ i - k ] ;
        res = max ( res , curr_sum ) ;
    return res ;
def solve ( arr , n , k ) :
    max_len = 0 ; l = 0 ; r = n ;
    while ( l <= r ) :
        m = ( l + r ) // 2 ;
        if ( maxSum ( arr , n , m ) > k ) :
            r = m - 1 ;
        else :
            l = m + 1 ;
            max_len = m ;
    return max_len ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    k = 10 ;
    print ( solve ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: curr_sum, res
Iterator variables: i
Python program:
MAX = 100001
ROW = 10
COL = 3
indices = [ 0 ] * MAX
test = [ [ 2 , 3 , 6 ] , [ 2 , 4 , 4 ] , [ 2 , 6 , 3 ] , [ 3 , 2 , 6 ] , [ 3 , 3 , 3 ] , [ 3 , 6 , 2 ] , [ 4 , 2 , 4 ] , [ 4 , 4 , 2 ] , [ 6 , 2 , 3 ] , [ 6 , 3 , 2 ] ]
def find_triplet ( array , n ) :
    answer = 0
    for i in range ( MAX ) :
        indices [ i ] = [ ]
    for i in range ( n ) :
        indices [ array [ i ] ] . append ( i )
    for i in range ( n ) :
        y = array [ i ]
        for j in range ( ROW ) :
            s = test [ j ] [ 1 ] * y
            if s % test [ j ] [ 0 ] != 0 :
                continue
            if s % test [ j ] [ 2 ] != 0 :
                continue
            x = s // test [ j ] [ 0 ]
            z = s // test [ j ] [ 2 ]
            if x > MAX or z > MAX :
                continue
            l = 0
            r = len ( indices [ x ] ) - 1
            first = - 1
            while l <= r :
                m = ( l + r ) // 2
                if indices [ x ] [ m ] < i :
                    first = m
                    l = m + 1
                else :
                    r = m - 1
            l = 0
            r = len ( indices [ z ] ) - 1
            third = - 1
            while l <= r :
                m = ( l + r ) // 2
                if indices [ z ] [ m ] > i :
                    third = m
                    r = m - 1
                else :
                    l = m + 1
            if first != - 1 and third != - 1 :
                answer += ( first + 1 ) * ( len ( indices [ z ] ) - third )
    return answer
if __name__ == " _ _ main _ _ " :
    array = [ 2 , 4 , 5 , 6 , 7 ]
    n = len ( array )
    print ( find_triplet ( array , n ) )

Index/key variables: i, j, m, x, z
Accumulator variables: answer
Iterator variables: i, j
Python program:
def distinct ( arr ) :
    count = 0
    if len ( arr ) == 1 :
        return 1
    for i in range ( 0 , len ( arr ) - 1 ) :
        if ( i == 0 ) :
            if ( arr [ i ] != arr [ i + 1 ] ) :
                count += 1
        elif ( i > 0 & i < len ( arr ) - 1 ) :
            if ( arr [ i ] != arr [ i + 1 ] or arr [ i ] != arr [ i - 1 ] ) :
                count += 1
    if ( arr [ len ( arr ) - 1 ] != arr [ len ( arr ) - 2 ] ) :
        count += 1
    return count
arr = [ 0 , 0 , 0 , 0 , 0 , 1 , 0 ]
print ( distinct ( arr ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def isSorted ( arr , N ) :
    for i in range ( 1 , N ) :
        if ( arr [ i ] [ 0 ] > arr [ i - 1 ] [ 0 ] ) :
            return False
    return True
def isPossibleToSort ( arr , N ) :
    group = arr [ 0 ] [ 1 ]
    for i in range ( 1 , N ) :
        if ( arr [ i ] [ 1 ] != group ) :
            return " Yes "
    if ( isSorted ( arr , N ) ) :
        return " Yes "
    else :
        return " No "
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 340000 , 2 ] , [ 45000 , 1 ] , [ 30000 , 2 ] , [ 50000 , 4 ] ]
    N = len ( arr )
    print ( isPossibleToSort ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
sum = 0
total_sum = 0
mod = 1000000007
def getAlphaScore ( node ) :
    global sum
    global total_sum
    if node . left != None :
        getAlphaScore ( node . left )
    sum = ( sum + node . data ) % mod
    total_sum = ( total_sum + sum ) % mod
    if node . right != None :
        getAlphaScore ( node . right )
    return total_sum
def constructBST ( arr , start , end , root ) :
    if start > end :
        return None
    mid = ( start + end ) // 2
    if root == None :
        root = Node ( arr [ mid ] )
    root . left = constructBST ( arr , start , mid - 1 , root . left )
    root . right = constructBST ( arr , mid + 1 , end , root . right )
    return root
arr = [ 10 , 11 , 12 ]
length = len ( arr )
arr . sort ( )
root = None
root = constructBST ( arr , 0 , length - 1 , root )
print ( getAlphaScore ( root ) )

Index/key variables: mid
Class/struct names: Node
Python program:
def sortByFreq ( arr , n ) :
    maxE = - 1 ;
    for i in range ( n ) :
        maxE = max ( maxE , arr [ i ] )
    freq = [ 0 ] * ( maxE + 1 ) ;
    for i in range ( n ) :
        freq [ arr [ i ] ] += 1 ;
    cnt = 0 ;
    for i in range ( maxE + 1 ) :
        if ( freq [ i ] > 0 ) :
            value = 100000 - i ;
            arr [ cnt ] = 100000 * freq [ i ] + value ;
            cnt += 1 ;
    return cnt ;
def printSortedArray ( arr , cnt ) :
    for i in range ( cnt ) :
        frequency = arr [ i ] / 100000 ;
        value = 100000 - ( arr [ i ] % 100000 ) ;
        for j in range ( int ( frequency ) ) :
            print ( value , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 4 , 5 , 6 , 4 , 2 , 2 , 8 , 5 ]
    n = len ( arr )
    cnt = sortByFreq ( arr , n ) ;
    arr . sort ( reverse = True )
    printSortedArray ( arr , cnt ) ;

Index/key variables: cnt, i
Iterator variables: i, j
Python program:
def checkRectangles ( arr , n ) :
    ans = True
    arr . sort ( )
    area = arr [ 0 ] * arr [ 4 * n - 1 ]
    for i in range ( 0 , 2 * n , 2 ) :
        if ( arr [ i ] != arr [ i + 1 ] or arr [ 4 * n - i - 1 ] != arr [ 4 * n - i - 2 ] or arr [ i ] * arr [ 4 * n - i - 1 ] != area ) :
            ans = False
            break
    if ( ans ) :
        return True
    return False
arr = [ 1 , 8 , 2 , 1 , 2 , 4 , 4 , 8 ]
n = 2
if ( checkRectangles ( arr , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Boolean variables: ans
Python program:
def cntElements ( arr , n ) :
    copy_arr = [ 0 ] * n
    for i in range ( n ) :
        copy_arr [ i ] = arr [ i ]
    count = 0
    arr . sort ( )
    for i in range ( n ) :
        if ( arr [ i ] != copy_arr [ i ] ) :
            count += 1
    return count
arr = [ 1 , 2 , 6 , 2 , 4 , 5 ]
n = len ( arr )
print ( cntElements ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findPairs ( arr , n , k , d ) :
    if ( n < 2 * k ) :
        print ( " - 1" )
        return
    pairs = [ ]
    arr = sorted ( arr )
    for i in range ( k ) :
        if ( arr [ n - k + i ] - arr [ i ] >= d ) :
            pairs . append ( [ arr [ i ] , arr [ n - k + i ] ] )
    if ( len ( pairs ) < k ) :
        print ( " - 1" )
        return
    for v in pairs :
        print ( " ( " , v [ 0 ] , " , ▁ " , v [ 1 ] , " ) " )
arr = [ 4 , 6 , 10 , 23 , 14 , 7 , 2 , 20 , 9 ]
n = len ( arr )
k = 4
d = 3
findPairs ( arr , n , k , d )

Index/key variables: i
Accumulator variables: pairs
Iterator variables: i, v
Python program:
def pairs_count ( arr , n , sum ) :
    ans = 0
    arr = sorted ( arr )
    i , j = 0 , n - 1
    while ( i < j ) :
        if ( arr [ i ] + arr [ j ] < sum ) :
            i += 1
        elif ( arr [ i ] + arr [ j ] > sum ) :
            j -= 1
        else :
            x = arr [ i ]
            xx = i
            while ( i < j and arr [ i ] == x ) :
                i += 1
            y = arr [ j ]
            yy = j
            while ( j >= i and arr [ j ] == y ) :
                j -= 1
            if ( x == y ) :
                temp = i - xx + yy - j - 1
                ans += ( temp * ( temp + 1 ) ) // 2
            else :
                ans += ( i - xx ) * ( yy - j )
    return ans
arr = [ 1 , 5 , 7 , 5 , - 1 ]
n = len ( arr )
sum = 6
print ( pairs_count ( arr , n , sum ) )

Index/key variables: i, j
Accumulator variables: ans
Python program:
import sys
def check ( str ) :
    min = sys . maxsize
    max = - sys . maxsize - 1
    sum = 0
    for i in range ( len ( str ) ) :
        ascii = str [ i ]
        if ( ord ( ascii ) < 96 or ord ( ascii ) > 122 ) :
            return False
        sum += ord ( ascii )
        if ( min > ord ( ascii ) ) :
            min = ord ( ascii )
        if ( max < ord ( ascii ) ) :
            max = ord ( ascii )
    min -= 1
    eSum = ( ( ( max * ( max + 1 ) ) // 2 ) - ( ( min * ( min + 1 ) ) // 2 ) )
    return sum == eSum
if __name__ == ' _ _ main _ _ ' :
    str = " dcef "
    if ( check ( str ) ) :
        print ( " Yes " )
    else :
        print ( " No " )
    str1 = " xyza "
    if ( check ( str1 ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findKth ( arr , n , k ) :
    missing = dict ( )
    count = 0
    for i in range ( n ) :
        missing [ arr [ i ] ] = 1
    maxm = max ( arr )
    minm = min ( arr )
    for i in range ( minm + 1 , maxm ) :
        if ( i not in missing . keys ( ) ) :
            count += 1
        if ( count == k ) :
            return i
    return - 1
arr = [ 2 , 10 , 9 , 4 ]
n = len ( arr )
k = 5
print ( findKth ( arr , n , k ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
import math
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def sortList ( head ) :
    startVal = 1
    while ( head != None ) :
        head . data = startVal
        startVal = startVal + 1
        head = head . next
def push ( head_ref , new_data ) :
    new_node = Node ( new_data )
    new_node . data = new_data
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def prList ( node ) :
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        node = node . next
if __name__ == ' _ _ main _ _ ' :
    head = None
    head = push ( head , 2 )
    head = push ( head , 1 )
    head = push ( head , 6 )
    head = push ( head , 4 )
    head = push ( head , 5 )
    head = push ( head , 3 )
    sortList ( head )
    prList ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def isSortedDesc ( head ) :
    if ( head == None or head . next == None ) :
        return True
    return ( head . data > head . next . data and isSortedDesc ( head . next ) )
def newNode ( data ) :
    temp = Node ( data )
    return temp
if __name__ == " _ _ main _ _ " :
    head = newNode ( 7 )
    head . next = newNode ( 5 )
    head . next . next = newNode ( 4 )
    head . next . next . next = newNode ( 3 )
    if isSortedDesc ( head ) :
        print ( " Yes " )
    else :
        print ( " No " )

Class/struct names: Node
Python program:
def minSum ( arr , n ) :
    evenArr = [ ]
    oddArr = [ ]
    arr . sort ( )
    for i in range ( n ) :
        if ( i < n // 2 ) :
            oddArr . append ( arr [ i ] )
        else :
            evenArr . append ( arr [ i ] )
    evenArr . sort ( reverse = True )
    i = 0
    sum = 0
    for j in range ( len ( evenArr ) ) :
        arr [ i ] = evenArr [ j ]
        i += 1
        arr [ i ] = oddArr [ j ]
        i += 1
        sum += evenArr [ j ] * oddArr [ j ]
    return sum
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ]
    n = len ( arr )
    print ( " Minimum ▁ required ▁ sum ▁ = " , minSum ( arr , n ) )
    print ( " Sorted ▁ array ▁ in ▁ required ▁ format ▁ : ▁ " , end = " " )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Accumulator variables: evenArr, oddArr, sum
Iterator variables: i, j
Python program:
def minTime ( word ) :
    ans = 0
    curr = 0
    for i in range ( len ( word ) ) :
        k = ord ( word [ i ] ) - 97
        a = abs ( curr - k )
        b = 26 - abs ( curr - k )
        ans += min ( a , b )
        ans += 1
        curr = ord ( word [ i ] ) - 97
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    str = " zjpc "
    minTime ( str )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def reduceToOne ( N ) :
    cnt = 0
    while ( N != 1 ) :
        if ( N == 2 or ( N % 2 == 1 ) ) :
            N = N - 1
            cnt += 1
        elif ( N % 2 == 0 ) :
            N = N / ( N / 2 )
            cnt += 1
    return cnt
if __name__ == ' _ _ main _ _ ' :
    N = 35
    print ( reduceToOne ( N ) )

Accumulator variables: cnt
Python program:
def maxDiamonds ( A , N , K ) :
    pq = [ ]
    for i in range ( N ) :
        pq . append ( A [ i ] )
    pq . sort ( )
    ans = 0
    while ( len ( pq ) > 0 and K > 0 ) :
        pq . sort ( )
        top = pq [ len ( pq ) - 1 ]
        pq = pq [ 0 : len ( pq ) - 1 ]
        ans += top
        top = top // 2 ;
        pq . append ( top )
        K -= 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    A = [ 2 , 1 , 7 , 4 , 2 ]
    K = 3
    N = len ( A )
    maxDiamonds ( A , N , K )

Index/key variables: i
Accumulator variables: K, ans, pq
Iterator variables: i
Python program:
def MinimumCost ( A , B , N ) :
    totalCost = 0
    for i in range ( N ) :
        mod_A = B [ i ] % A [ i ]
        totalCost_A = min ( mod_A , A [ i ] - mod_A )
        mod_B = A [ i ] % B [ i ]
        totalCost_B = min ( mod_B , B [ i ] - mod_B )
        totalCost += min ( totalCost_A , totalCost_B )
    return totalCost
A = [ 3 , 6 , 3 ]
B = [ 4 , 8 , 13 ]
N = len ( A )
print ( MinimumCost ( A , B , N ) )

Index/key variables: i
Accumulator variables: totalCost
Iterator variables: i
Python program:
def printLargestDivisible ( arr , N ) :
    count0 = 0 ; count7 = 0 ;
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            count0 += 1 ;
        else :
            count7 += 1 ;
    if ( count7 % 50 == 0 ) :
        while ( count7 ) :
            count7 -= 1 ;
            print ( 7 , end = " " ) ;
        while ( count0 ) :
            count0 -= 1 ;
            print ( count0 , end = " " ) ;
    elif ( count7 < 5 ) :
        if ( count0 == 0 ) :
            print ( " No " , end = " " ) ;
        else :
            print ( "0" , end = " " ) ;
    else :
        count7 = count7 - count7 % 5 ;
        while ( count7 ) :
            count7 -= 1 ;
            print ( 7 , end = " " ) ;
        while ( count0 ) :
            count0 -= 1 ;
            print ( 0 , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 0 , 7 , 0 , 7 , 7 , 7 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 ] ;
    N = len ( arr ) ;
    printLargestDivisible ( arr , N ) ;

Index/key variables: i
Accumulator variables: count0, count7
Iterator variables: i
Python program:
def findMaxValByRearrArr ( arr , N ) :
    arr . sort ( )
    res = 0
    while ( True ) :
        Sum = 0
        for i in range ( N ) :
            Sum += __gcd ( i + 1 , arr [ i ] )
        res = max ( res , Sum )
        if ( not next_permutation ( arr ) ) :
            break
    return res
def __gcd ( a , b ) :
    if b == 0 :
        return a
    else :
        return __gcd ( b , a % b )
def next_permutation ( p ) :
    for a in range ( len ( p ) - 2 , - 1 , - 1 ) :
        if ( p [ a ] < p [ a + 1 ] ) :
            b = len ( p ) - 1
            while True :
                if ( p [ b ] > p [ a ] ) :
                    t = p [ a ]
                    p [ a ] = p [ b ]
                    p [ b ] = t
                    a += 1
                    b = len ( p ) - 1
                    while a < b :
                        t = p [ a ]
                        p [ a ] = p [ b ]
                        p [ b ] = t
                        a += 1
                        b -= 1
                    return True
                b -= 1
    return False
arr = [ 3 , 2 , 1 ]
N = len ( arr )
print ( findMaxValByRearrArr ( arr , N ) )

Index/key variables: a, b, i
Accumulator variables: Sum
Iterator variables: a, i
Python program:
def min_elements ( arr , N ) :
    mp = { } ;
    for i in range ( N ) :
        if arr [ i ] in mp :
            mp [ arr [ i ] ] += 1 ;
        else :
            mp [ arr [ i ] ] = 1 ;
    cntMinRem = 0 ;
    for it in mp :
        i = it ;
        if ( mp [ i ] < i ) :
            cntMinRem += mp [ i ] ;
        elif ( mp [ i ] > i ) :
            cntMinRem += ( mp [ i ] - i ) ;
    return cntMinRem ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 1 , 4 , 2 ] ;
    N = len ( arr ) ;
    print ( min_elements ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: cntMinRem
Iterator variables: i, it
Python program:
def CheckAllarrayEqual ( arr , N ) :
    if ( N == 1 ) :
        return True
    totalSum = arr [ 0 ]
    secMax = - 10 ** 19
    Max = arr [ 0 ]
    for i in range ( 1 , N ) :
        if ( arr [ i ] >= Max ) :
            secMax = Max
            Max = arr [ i ]
        elif ( arr [ i ] > secMax ) :
            secMax = arr [ i ]
        totalSum += arr [ i ]
    if ( ( secMax * ( N - 1 ) ) > totalSum ) :
        return False
    if ( totalSum % ( N - 1 ) ) :
        return False
    return True
if __name__ == ' _ _ main _ _ ' :
    arr = [ 6 , 2 , 2 , 2 ]
    N = len ( arr )
    if ( CheckAllarrayEqual ( arr , N ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i
Accumulator variables: totalSum
Iterator variables: i
Python program:
def Remove_one_element ( arr , n ) :
    post_odd = 0
    post_even = 0
    curr_odd = 0
    curr_even = 0
    res = 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( i % 2 ) :
            post_odd ^= arr [ i ]
        else :
            post_even ^= arr [ i ]
    for i in range ( n ) :
        if ( i % 2 ) :
            post_odd ^= arr [ i ]
        else :
            post_even ^= arr [ i ]
        X = curr_odd ^ post_even
        Y = curr_even ^ post_odd
        if ( X == Y ) :
            res += 1
        if ( i % 2 ) :
            curr_odd ^= arr [ i ]
        else :
            curr_even ^= arr [ i ]
    print ( res )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 0 , 1 , 0 , 1 ]
    N = len ( arr )
    Remove_one_element ( arr , N )

Index/key variables: i
Accumulator variables: curr_even, curr_odd, post_even, post_odd, res
Iterator variables: i
Python program:
def cntIndexesToMakeBalance ( arr , n ) :
    if ( n == 1 ) :
        return 1
    if ( n == 2 ) :
        return 0
    sumEven = 0
    sumOdd = 0
    for i in range ( n ) :
        if ( i % 2 == 0 ) :
            sumEven += arr [ i ]
        else :
            sumOdd += arr [ i ]
    currOdd = 0
    currEven = arr [ 0 ]
    res = 0
    newEvenSum = 0
    newOddSum = 0
    for i in range ( 1 , n - 1 ) :
        if ( i % 2 ) :
            currOdd += arr [ i ]
            newEvenSum = ( currEven + sumOdd - currOdd )
            newOddSum = ( currOdd + sumEven - currEven - arr [ i ] )
        else :
            currEven += arr [ i ]
            newOddSum = ( currOdd + sumEven - currEven )
            newEvenSum = ( currEven + sumOdd - currOdd - arr [ i ] )
        if ( newEvenSum == newOddSum ) :
            res += 1
    if ( sumOdd == sumEven - arr [ 0 ] ) :
        res += 1
    if ( n % 2 == 1 ) :
        if ( sumOdd == sumEven - arr [ n - 1 ] ) :
            res += 1
    else :
        if ( sumEven == sumOdd - arr [ n - 1 ] ) :
            res += 1
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 1 ]
    n = len ( arr )
    print ( cntIndexesToMakeBalance ( arr , n ) )

Index/key variables: i
Accumulator variables: currEven, currOdd, res, sumEven, sumOdd
Iterator variables: i
Python program:
def checkCount ( A , Q , q ) :
    for i in range ( q ) :
        L = Q [ i ] [ 0 ]
        R = Q [ i ] [ 1 ]
        L -= 1
        R -= 1
        if ( ( A [ L ] < A [ L + 1 ] ) != ( A [ R - 1 ] < A [ R ] ) ) :
            print ( " Yes " )
        else :
            print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 13 , 12 , 14 ]
    Q = [ [ 1 , 4 ] , [ 2 , 4 ] ]
    q = len ( Q )
    checkCount ( arr , Q , q )

Index/key variables: L, R, i
Iterator variables: i
Python program:
def pairProductMean ( arr , N ) :
    pairArray = [ ] ;
    for i in range ( N ) :
        for j in range ( i + 1 , N ) :
            pairProduct = arr [ i ] * arr [ j ] ;
            pairArray . append ( pairProduct ) ;
    length = len ( pairArray ) ;
    sum = 0 ;
    for i in range ( length ) :
        sum += pairArray [ i ] ;
    mean = 0 ;
    if ( length != 0 ) :
        mean = sum / length ;
    else :
        mean = 0 ;
    return mean ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 8 ] ;
    N = len ( arr ) ;
    print ( " { 0 : . 2f } " . format ( pairProductMean ( arr , N ) ) )

Index/key variables: i, j
Accumulator variables: pairArray, sum
Iterator variables: i, j
Python program:
def find_next ( n , k ) :
    M = n + 1 ;
    while ( True ) :
        if ( ( M & ( 1 << k ) ) > 0 ) :
            break ;
        M += 1 ;
    return M ;
if __name__ == ' _ _ main _ _ ' :
    N = 15 ; K = 2 ;
    print ( find_next ( N , K ) ) ;

Accumulator variables: M
Python program:
def find_next ( n , k ) :
    ans = 0
    if ( ( n & ( 1 << k ) ) == 0 ) :
        cur = 0
        for i in range ( k ) :
            if ( n & ( 1 << i ) ) :
                cur += 1 << i
        ans = n - cur + ( 1 << k )
    else :
        first_unset_bit , cur = - 1 , 0
        for i in range ( 64 ) :
            if ( ( n & ( 1 << i ) ) == 0 ) :
                first_unset_bit = i
                break
            else :
                cur += ( 1 << i )
        ans = n - cur + ( 1 << first_unset_bit )
        if ( ( ans & ( 1 << k ) ) == 0 ) :
            ans += ( 1 << k )
    return ans
N , K = 15 , 2
print ( find_next ( N , K ) )

Accumulator variables: cur
Iterator variables: i
Python program:
def largestString ( num , k ) :
    ans = [ ]
    for i in range ( len ( num ) ) :
        while ( len ( ans ) and ans [ - 1 ] < num [ i ] and k > 0 ) :
            ans . pop ( )
            k -= 1
        ans . append ( num [ i ] )
    while ( len ( ans ) and k ) :
        k -= 1
        ans . pop ( )
    return ans
str = " zyxedcba "
k = 1
print ( * largestString ( str , k ) , sep = " " )

Index/key variables: i
Accumulator variables: ans, k
Iterator variables: i
Python program:
def maxLengthSubArray ( A , N ) :
    forward = [ 0 ] * N
    backward = [ 0 ] * N
    for i in range ( N ) :
        if i == 0 or A [ i ] != A [ i - 1 ] :
            forward [ i ] = 1
        else :
            forward [ i ] = forward [ i - 1 ] + 1
    for i in range ( N - 1 , - 1 , - 1 ) :
        if i == N - 1 or A [ i ] != A [ i + 1 ] :
            backward [ i ] = 1
        else :
            backward [ i ] = backward [ i + 1 ] + 1
    ans = 0
    for i in range ( N - 1 ) :
        if ( A [ i ] != A [ i + 1 ] ) :
            ans = max ( ans , min ( forward [ i ] , backward [ i + 1 ] ) * 2 ) ;
    print ( ans )
arr = [ 1 , 2 , 3 , 4 , 4 , 4 , 6 , 6 , 6 , 9 ]
N = len ( arr )
maxLengthSubArray ( arr , N )

Index/key variables: i
Iterator variables: i