dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def check ( H , A , mid , N , M , L ) :
    sum = 0
    for i in range ( N ) :
        speed = mid * A [ i ] + H [ i ]
        if ( speed >= L ) :
            sum += speed
    return sum
def buzzTime ( N , M , L , H , A ) :
    low = 0
    high = 1e10
    ans = 0
    while ( high >= low ) :
        mid = low + ( high - low ) // 2
        if ( check ( H , A , mid , N , M , L ) >= M ) :
            ans = mid
            high = mid - 1
        else :
            low = mid + 1
    return int ( ans )
if __name__ == ' _ _ main _ _ ' :
    M = 400
    L = 120
    H = [ 20 , 50 , 20 ]
    A = [ 20 , 70 , 90 ]
    N = len ( A )
    print ( buzzTime ( N , M , L , H , A ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findCount ( number ) :
    sum = 0
    for i in range ( len ( number ) ) :
        sum += int ( number [ i ] ) - 48
    count = 0
    for i in range ( len ( number ) ) :
        remaining_sum = sum - ( int ( number [ i ] ) - 48 )
        for j in range ( 10 ) :
            if ( ( remaining_sum + j ) % 3 == 0 and j != int ( number [ i ] ) - 48 ) :
                count += 1
    print ( count )
number = "235"
findCount ( number )

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i, j
Python program:
def is_possible ( teams , T , k ) :
    sum = 0
    for i in range ( len ( teams ) ) :
        sum += min ( T , teams [ i ] )
    return ( sum >= ( T * k ) )
def countOfTeams ( teams_list , N , K ) :
    lb = 0
    ub = 1000000000
    while ( lb <= ub ) :
        mid = lb + ( ub - lb ) // 2
        if ( is_possible ( teams_list , mid , K ) ) :
            if ( is_possible ( teams_list , mid + 1 , K ) == False ) :
                return mid
            else :
                lb = mid + 1
        else :
            ub = mid - 1
    return 0
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 ]
    K = 2
    N = len ( arr )
    print ( countOfTeams ( arr , N , K ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def minimumOperations ( arr , N ) :
    mx = 0
    pos = 0
    for i in range ( N ) :
        if ( arr [ i ] >= mx ) :
            mx = arr [ i ]
            pos = i
    print ( ( mx - 1 ) * N + pos + 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 0 , 2 ]
    N = len ( arr )
    minimumOperations ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
n = 0
m = 0
k = 0
l = 0
r = 0
i = 0
from math import pow
def check ( v , a ) :
    tec = 0
    ans = 0
    b = [ 0 for i in range ( n + k + 1 ) ]
    for i in range ( n ) :
        tec -= b [ i ]
        if ( a [ i ] + tec < v ) :
            mov = v - a [ i ] - tec
            ans = ans + mov
            tec += mov
            b [ i + k ] = mov
    return ( ans <= m )
def FindLargest ( a ) :
    l = 1
    r = pow ( 10 , 10 )
    while ( r - l > 0 ) :
        tm = ( l + r + 1 ) // 2
        if ( check ( tm , a ) ) :
            l = tm
        else :
            r = tm - 1
    return l
if __name__ == ' _ _ main _ _ ' :
    a = [ 2 , 2 , 2 , 2 , 1 , 1 ]
    m = 2
    k = 3
    n = len ( a )
    print ( int ( FindLargest ( a ) ) )

Index/key variables: i
Accumulator variables: tec
Iterator variables: i
Python program:
def printFreq ( arr , N ) :
    freq = 1
    for i in range ( 1 , N , 1 ) :
        if ( arr [ i ] == arr [ i - 1 ] ) :
            freq += 1
        else :
            print ( " Frequency ▁ of " , arr [ i - 1 ] , " is : " , freq )
            freq = 1
    print ( " Frequency ▁ of " , arr [ N - 1 ] , " is : " , freq )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ]
    N = len ( arr )
    printFreq ( arr , N )

Index/key variables: i
Accumulator variables: freq
Iterator variables: i
Python program:
from bisect import bisect_left , bisect_right
def countPairSum ( arr , L , R , N ) :
    arr . sort ( )
    right = N - 1
    count = 0
    while ( right > 0 ) :
        it1 = bisect_left ( arr , L - arr [ right ] )
        start = it1
        it2 = bisect_right ( arr , R - arr [ right ] )
        it2 -= 1
        end = it2
        end = min ( end , right - 1 )
        if ( end - start >= 0 ) :
            count += ( end - start + 1 )
        right -= 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 1 , 2 , 4 , 3 ]
    L = 5
    R = 8
    N = len ( arr )
    print ( countPairSum ( arr , L , R , N ) )

Index/key variables: right
Accumulator variables: count, it2
Python program:
def isMaximumMedian ( arr , N , K , mid ) :
    Pre = [ [ 0 for x in range ( N + 5 ) ] for y in range ( N + 5 ) ]
    for i in range ( N ) :
        for j in range ( N ) :
            Pre [ i + 1 ] [ j + 1 ] = ( Pre [ i + 1 ] [ j ] + Pre [ i ] [ j + 1 ] - Pre [ i ] [ j ] )
            if ( arr [ i ] [ j ] <= mid ) :
                Pre [ i + 1 ] [ j + 1 ] += 1
    required = ( K * K + 1 ) // 2
    flag = 0
    for i in range ( K , N + 1 ) :
        for j in range ( K , N + 1 ) :
            X = ( Pre [ i ] [ j ] - Pre [ i - K ] [ j ] - Pre [ i ] [ j - K ] + Pre [ i - K ] [ j - K ] )
            if ( X < required ) :
                flag = 1
    return flag
def maximumMedian ( arr , N , K ) :
    low = 0
    high = 1000000009
    while ( low < high ) :
        mid = low + ( high - low ) // 2
        if ( isMaximumMedian ( arr , N , K , mid ) ) :
            low = mid + 1
        else :
            high = mid
    return low
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 5 , 12 ] , [ 6 , 7 , 11 ] , [ 8 , 9 , 10 ] ]
    N = len ( arr )
    K = 2
    print ( maximumMedian ( arr , N , K ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findMinDays ( arr , R , N , X , K ) :
    low = 0
    high = X
    minDays = 0
    while ( low <= high ) :
        mid = ( low + high ) // 2
        sum = 0
        for i in range ( N ) :
            temp = arr [ i ] + R [ i ] * mid
            if ( temp >= K ) :
                sum += temp
        if ( sum >= X ) :
            minDays = mid
            high = mid - 1
        else :
            low = mid + 1
    print ( minDays )
if __name__ == ' _ _ main _ _ ' :
    X = 100
    K = 45
    arr = [ 2 , 5 , 2 , 6 ]
    R = [ 10 , 13 , 15 , 12 ]
    N = len ( arr )
    findMinDays ( arr , R , N , X , K )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def getPairsCount ( a , n ) :
    count = 0
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            if ( ( a [ i ] * a [ j ] ) == abs ( i - j ) ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 4 ]
    N = len ( arr )
    print ( getPairsCount ( arr , N ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def lexicographicallySmallestString ( S , N ) :
    LastZe = - 1
    ans = " "
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( S [ i ] == '0' ) :
            LastZe = i
            break
    for i in range ( N ) :
        if ( i <= LastZe and S [ i ] == '0' ) :
            ans += S [ i ]
        elif ( i > LastZe ) :
            ans += S [ i ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = "11001101"
    N = len ( S )
    print ( lexicographicallySmallestString ( S , N ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
from bisect import bisect_left , bisect_right
tin = [ 0 ] * 100
tout = [ 0 ] * 100
depth = [ 0 ] * 100
t = 0
def Add_edge ( parent , child , adj ) :
    adj [ parent ] . append ( child )
    adj [ child ] . append ( parent )
    return adj
def dfs ( node , parent , d ) :
    global tin , tout , depth , adj , levels , t
    tin [ node ] = t
    t += 1
    levels [ d ] . append ( tin [ node ] )
    depth [ node ] = d
    for x in adj [ node ] :
        if ( x != parent ) :
            dfs ( x , node , d + 1 )
    tout [ node ] = t
    t += 1
def numberOfNodes ( node , dist ) :
    global levels , tin , tout
    dist += depth [ node ]
    start = bisect_left ( levels [ dist ] , tin [ node ] )
    ed = bisect_left ( levels [ dist ] , tout [ node ] )
    print ( ed - start )
def numberOfNodesUtil ( Q , M , N ) :
    global t , adj
    adj = Add_edge ( 1 , 2 , adj )
    adj = Add_edge ( 1 , 3 , adj )
    adj = Add_edge ( 2 , 4 , adj )
    adj = Add_edge ( 2 , 5 , adj )
    adj = Add_edge ( 2 , 6 , adj )
    t = 1
    dfs ( 1 , 1 , 0 )
    for i in range ( M ) :
        numberOfNodes ( Q [ i ] [ 0 ] , Q [ i ] [ 1 ] )
if __name__ == ' _ _ main _ _ ' :
    N = 6
    Q = [ [ 2 , 1 ] , [ 1 , 1 ] ]
    M = len ( Q )
    adj = [ [ ] for i in range ( N + 5 ) ]
    levels = [ [ ] for i in range ( N + 5 ) ]
    numberOfNodesUtil ( Q , M , N )

Index/key variables: child, d, dist, i, node, parent
Iterator variables: i, x
Python program:
def minSwaps ( N , M , A , B ) :
    count01 = 0
    count10 = 0
    for i in range ( 0 , N ) :
        for j in range ( 0 , M ) :
            if ( A [ i ] [ j ] != B [ i ] [ j ] ) :
                if ( A [ i ] [ j ] == 1 ) :
                    count10 += 1
                else :
                    count01 += 1
    if ( count01 == count10 ) :
        return count01
    else :
        return - 1
A = [ [ 1 , 1 , 0 ] , [ 0 , 0 , 1 ] , [ 0 , 1 , 0 ] ]
B = [ [ 0 , 0 , 1 ] , [ 0 , 1 , 0 ] , [ 1 , 1 , 0 ] ]
N = len ( A )
M = len ( B [ 0 ] )
print ( minSwaps ( N , M , A , B ) )

Index/key variables: i, j
Accumulator variables: count01, count10
Iterator variables: i, j
Python program:
def Count ( N , K ) :
    if ( K == 0 ) :
        return 0
    sum = 0
    res = 0
    for i in range ( 1 , N + 1 , 1 ) :
        sum += i
        if ( sum <= K ) :
            res += 1
        else :
            break
    return res
if __name__ == ' _ _ main _ _ ' :
    N = 6
    K = 14
    print ( Count ( N , K ) )

Accumulator variables: res, sum
Iterator variables: i
Python program:
def removeLastOccurrence ( S , W , N , M ) :
    S = [ i for i in S ]
    W = [ i for i in W ]
    if ( M > N ) :
        return S
    for i in range ( N - M , - 1 , - 1 ) :
        flag = 0
        for j in range ( M ) :
            if ( S [ j + i ] != W [ j ] ) :
                flag = 1
                break
        if ( flag == 0 ) :
            for j in range ( i , N - M ) :
                S [ j ] = S [ j + M ]
            S = S [ : N - M ]
            break
    return " " . join ( S )
if __name__ == ' _ _ main _ _ ' :
    S = " This ▁ is ▁ GeeksForGeeks "
    W = " Geeks "
    N = len ( S )
    M = len ( W )
    print ( removeLastOccurrence ( S , W , N , M ) )

Index/key variables: j
Iterator variables: i, j
Python program:
def maximumIndices ( arr , N ) :
    temp = [ 0 ] * N
    maxIndices = ( N - 1 ) // 2
    arr . sort ( )
    for i in range ( maxIndices ) :
        temp [ 2 * i + 1 ] = arr [ i ]
    j = 0
    i = maxIndices
    while ( i < N ) :
        if ( temp [ j ] == 0 ) :
            temp [ j ] = arr [ i ]
            i += 1
        j += 1
    for i in range ( N ) :
        print ( temp [ i ] , end = " ▁ " )
arr = [ 1 , 2 , 3 , 4 ]
N = len ( arr )
maximumIndices ( arr , N )

Index/key variables: i, j
Iterator variables: i
Python program:
from collections import deque
def areSimilar ( S1 , S2 ) :
    S1 = [ i for i in S1 ]
    S2 = [ i for i in S2 ]
    N = len ( S1 )
    M = len ( S2 )
    if ( N == M ) :
        if ( S1 == S2 ) :
            return True
        return False
    X , Y = deque ( ) , deque ( )
    S1 . append ( ' ▁ ' )
    S2 . append ( ' ▁ ' )
    temp = " "
    for i in range ( N + 1 ) :
        if ( S1 [ i ] == ' ▁ ' ) :
            X . append ( temp )
            temp = " "
        else :
            temp += S1 [ i ]
    for i in range ( M + 1 ) :
        if ( S2 [ i ] == ' ▁ ' ) :
            Y . append ( temp )
            temp = " "
        else :
            temp += S2 [ i ]
    while ( len ( X ) > 0 and len ( Y ) > 0 and X [ 0 ] == Y [ 0 ] ) :
        X . popleft ( )
        Y . popleft ( )
    while ( len ( X ) > 0 and len ( Y ) > 0 and X [ - 1 ] == Y [ - 1 ] ) :
        X . pop ( )
        Y . pop ( )
    if ( len ( X ) == 0 or len ( Y ) == 0 ) :
        return True
    return False
if __name__ == ' _ _ main _ _ ' :
    S1 = " Start ▁ practicing ▁ on ▁ GeeksforGeeks "
    S2 = " Start ▁ GeeksforGeeks "
    if ( areSimilar ( S1 , S2 ) ) :
        print ( " True " )
    else :
        print ( " False " )

Index/key variables: i
Accumulator variables: X, Y, temp
Iterator variables: i
Python program:
def repeatingElement ( arr , N ) :
    M = 0
    sum = 0
    for i in range ( N ) :
        sum += arr [ i ]
        M = max ( M , arr [ i ] )
    sum1 = M * ( M + 1 ) // 2
    ans = ( sum - sum1 ) // ( N - M )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 6 , 4 , 3 , 1 , 5 , 2 ]
    N = len ( arr )
    print ( repeatingElement ( arr , N ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def calculateMax ( N , M , K ) :
    ans = - 1
    low = 0
    high = M
    while ( low <= high ) :
        mid = ( low + high ) / 2
        val = 0
        L = K - 1
        R = N - K
        val += mid
        if ( mid >= L ) :
            val += ( L ) * ( 2 * mid - L - 1 ) / 2
        else :
            val += mid * ( mid - 1 ) / 2 + ( L - mid )
        if ( mid >= R ) :
            val += ( R ) * ( 2 * mid - R - 1 ) / 2
        else :
            val += mid * ( mid - 1 ) / 2 + ( R - mid )
        if ( val <= M ) :
            ans = max ( ans , mid )
            low = mid + 1
        else :
            high = mid - 1
    return int ( ans )
N = 7
M = 100
K = 6
print ( calculateMax ( N , M , K ) ) ;

Accumulator variables: val
Python program:
ans = 0
edges = [ [ ] for i in range ( 100000 ) ]
def Add_edge ( u , v ) :
    global edges
    edges [ u ] . append ( v )
    edges [ v ] . append ( u )
def minTimeToColor ( node , parent , arrival_time ) :
    global ans
    current_time = 0
    for x in edges [ node ] :
        if ( x != parent ) :
            current_time += 1
            if ( current_time == arrival_time ) :
                current_time += 1
            ans = max ( ans , current_time )
            minTimeToColor ( x , node , current_time )
if __name__ == ' _ _ main _ _ ' :
    A = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 4 ] ]
    for i in A :
        Add_edge ( i [ 0 ] , i [ 1 ] )
    minTimeToColor ( 1 , - 1 , 0 )
    print ( ans )

Index/key variables: node, u, v
Accumulator variables: current_time
Iterator variables: i, x
Python program:
def largestNum ( arr ) :
    res = 0
    arr = sorted ( arr )
    l = 0
    r = len ( arr ) - 1
    while ( l < r ) :
        sum = arr [ l ] + arr [ r ]
        if ( sum == 0 ) :
            res = max ( res , max ( arr [ l ] , arr [ r ] ) )
            return res
        elif ( sum < 0 ) :
            l += 1
        else :
            r -= 1
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , - 2 , 5 , - 3 ]
    print ( largestNum ( arr ) )

Index/key variables: l, r
Python program:
def findLarger ( arr , n ) :
    mid = ( n + 1 ) // 2
    mx = max ( arr )
    count = [ 0 ] * ( mx + 1 )
    for i in range ( n ) :
        count [ arr [ i ] ] += 1
    for i in range ( mx , - 1 , - 1 ) :
        while ( count [ i ] > 0 ) :
            count [ i ] -= 1
            mid -= 1
            print ( i , end = " ▁ " )
            if ( mid == 0 ) :
                break
        if ( mid == 0 ) :
            break
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 4 , 2 , 8 , 9 ]
    N = len ( arr )
    findLarger ( arr , N )

Index/key variables: i
Accumulator variables: mid
Iterator variables: i
Python program:
def probability ( arr1 , arr2 ) :
    N = len ( arr1 )
    M = len ( arr2 )
    res = 0
    for i in range ( N ) :
        y = 0
        for j in range ( M ) :
            if ( arr2 [ j ] > arr1 [ i ] ) :
                y += 1
        res += y
    res = res / ( N * M )
    return res
if __name__ == " _ _ main _ _ " :
    arr1 = [ 5 , 2 , 6 , 1 ]
    arr2 = [ 1 , 6 , 10 , 1 ]
    print ( probability ( arr1 , arr2 ) )

Index/key variables: i, j
Accumulator variables: res, y
Iterator variables: i, j
Python program:
def probability ( arr1 , arr2 ) :
    n = len ( arr1 )
    m = len ( arr2 )
    res = 0
    arr2 . sort ( )
    for i in range ( n ) :
        y = countGreater ( arr2 , arr1 [ i ] )
        res += y
    res /= ( n * m )
    return res
def countGreater ( arr , k ) :
    n = len ( arr )
    l = 0
    r = n - 1
    leftGreater = n
    while l <= r :
        m = ( l + r ) // 2
        if ( arr [ m ] > k ) :
            leftGreater = m
            r = m - 1
        else :
            l = m + 1
    return n - leftGreater
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 5 , 2 , 6 , 1 ]
    arr2 = [ 1 , 6 , 10 , 1 ]
    print ( probability ( arr1 , arr2 ) )

Index/key variables: i, m
Accumulator variables: res
Iterator variables: i
Python program:
def minCost ( arr , A , B ) :
    n = len ( arr )
    m = len ( arr [ 0 ] )
    ans = 0
    for i in range ( n ) :
        j = 0
        while j < m :
            if ( arr [ i ] [ j ] == ' * ' ) :
                j += 1
                continue
            if ( j == m - 1 ) :
                ans += A
            else :
                if ( arr [ i ] [ j + 1 ] == ' . ' ) :
                    ans += min ( 2 * A , B )
                    j += 1
                else :
                    ans += A
            j += 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ ' . ' , ' . ' , ' * ' ] , [ ' . ' , ' * ' , ' * ' ] ]
    A , B = 2 , 10
    minCost ( arr , A , B )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i
Python program:
from bisect import bisect_left
def countInversions ( arr , n ) :
    v = [ ]
    for i in range ( 1 , n + 1 , 1 ) :
        v . append ( i )
    ans = 0
    for i in range ( n ) :
        itr = bisect_left ( v , arr [ i ] )
        ans += itr
        v = v [ : itr ] + v [ itr + 1 : ]
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 1 , 5 , 4 ]
    n = len ( arr )
    countInversions ( arr , n )

Index/key variables: i
Accumulator variables: ans, v
Iterator variables: i
Python program:
def binarysearch ( array , right , element ) :
    left = 1
    while ( left <= right ) :
        mid = ( left + right // 2 )
        if ( array [ mid ] == element ) :
            return mid
        if ( mid - 1 > 0 and array [ mid ] > element and array [ mid - 1 ] < element ) :
            return mid
        elif ( array [ mid ] < element ) :
            left = mid + 1
        else :
            right = mid - 1
    return 1
def countDistinct ( arr , L , R ) :
    count = 0
    pref = [ 0 ] * ( len ( arr ) + 1 )
    for i in range ( 1 , len ( arr ) + 1 ) :
        count += arr [ i - 1 ]
        pref [ i ] = count
    left = binarysearch ( pref , len ( arr ) + 1 , L )
    right = binarysearch ( pref , len ( arr ) + 1 , R )
    print ( right - left + 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 6 , 7 , 1 , 8 ]
    L = 3
    R = 7
    countDistinct ( arr , L , R )

Index/key variables: i, mid
Accumulator variables: count
Iterator variables: i
Python program:
def isValid ( weight , n , D , mx ) :
    st = 1
    sum = 0
    for i in range ( n ) :
        sum += weight [ i ]
        if ( sum > mx ) :
            st += 1
            sum = weight [ i ]
        if ( st > D ) :
            return False
    return True
def shipWithinDays ( weight , D , n ) :
    sum = 0
    for i in range ( n ) :
        sum += weight [ i ]
    s = weight [ 0 ]
    for i in range ( 1 , n ) :
        s = max ( s , weight [ i ] )
    e = sum
    res = - 1
    while ( s <= e ) :
        mid = s + ( e - s ) // 2
        if ( isValid ( weight , n , D , mid ) ) :
            res = mid
            e = mid - 1
        else :
            s = mid + 1
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    weight = [ 9 , 8 , 10 ]
    D = 3
    N = len ( weight )
    shipWithinDays ( weight , D , N )

Index/key variables: i
Accumulator variables: st, sum
Iterator variables: i
Python program:
def findSum ( arr , N , pt ) :
    sum = 0
    for i in range ( N ) :
        sum += abs ( arr [ i ] - pt )
    return sum
def findPoint ( arr , N , K ) :
    left = 0
    if ( N % 2 ) :
        left = arr [ N // 2 ]
    else :
        left = arr [ N // 2 - 1 ] + 1
    right = arr [ N - 1 ]
    while ( left <= right ) :
        mid = ( left + right ) // 2
        temp = findSum ( arr , N , mid )
        if ( temp == K ) :
            print ( mid )
            return
        elif ( K < temp ) :
            right = mid - 1
        else :
            left = mid + 1
    left = arr [ 0 ]
    right = arr [ N // 2 ] - 1
    while ( left <= right ) :
        mid = ( left + right ) // 2
        temp = findSum ( arr , N , mid )
        if ( temp == K ) :
            print ( mid )
            return
        elif ( K > temp ) :
            right = mid - 1
        else :
            left = mid + 1
    print ( " - 1" )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 6 , 7 , 11 ]
    K = 18
    N = len ( arr )
    findPoint ( arr , N , K )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findArray ( arr , n ) :
    v = [ ]
    for i in range ( n ) :
        ans = - 1
        old_c = 0
        for j in range ( i + 1 , n ) :
            if ( arr [ j ] > arr [ i ] ) :
                curr_c = arr [ j : n + 1 ] . count ( arr [ j ] )
                if ( curr_c == old_c ) :
                    if ( arr [ j ] < ans ) :
                        ans = arr [ j ]
                if ( curr_c > old_c ) :
                    ans = arr [ j ]
                    old_c = curr_c
        v . append ( ans )
    for i in range ( len ( v ) ) :
        print ( v [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 5 , 2 , 25 , 10 , 5 , 10 , 3 , 10 , 5 ]
    size = len ( arr )
    findArray ( arr , size )

Index/key variables: i, j
Accumulator variables: v
Iterator variables: i, j
Python program:
def prodEquilibrium ( arr , N ) :
    product = 1
    for i in range ( N ) :
        product *= arr [ i ]
    left = 1
    right = product
    for i in range ( N ) :
        left = left * arr [ i ]
        right = right // arr [ i ]
        if ( left == right ) :
            print ( i + 1 )
            return
    print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 3 , 2 , 1 ]
    N = len ( arr )
    prodEquilibrium ( arr , N )

Index/key variables: i
Accumulator variables: product
Iterator variables: i
Python program:
def countTriplets ( D , arr ) :
    freq = { }
    ans = 0
    for i in range ( len ( arr ) ) :
        if ( ( ( arr [ i ] - D ) in freq ) and ( arr [ i ] - 2 * D ) in freq ) :
            ans += ( freq [ arr [ i ] - D ] * freq [ arr [ i ] - 2 * D ] )
        freq [ arr [ i ] ] = freq . get ( arr [ i ] , 0 ) + 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 5 , 7 , 8 , 10 ]
    D = 1
    print ( countTriplets ( D , arr ) )

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