dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from collections import defaultdict
from math import gcd
def countTriangles ( P , N ) :
    mp = defaultdict ( lambda : 0 )
    ans = 0
    for i in range ( 0 , N ) :
        mp . clear ( )
        for j in range ( i + 1 , N ) :
            X = P [ i ] [ 0 ] - P [ j ] [ 0 ]
            Y = P [ i ] [ 1 ] - P [ j ] [ 1 ]
            g = gcd ( X , Y )
            X //= g
            Y //= g
            mp [ ( X , Y ) ] += 1
        num = N - ( i + 1 )
        ans += ( num * ( num - 1 ) ) // 2
        for j in mp :
            ans -= ( mp [ j ] * ( mp [ j ] - 1 ) ) // 2
    return ans
if __name__ == " _ _ main _ _ " :
    P = [ [ 0 , 0 ] , [ 2 , 0 ] , [ 1 , 1 ] , [ 2 , 2 ] ]
    N = len ( P )
    print ( countTriangles ( P , N ) )

Index/key variables: i, j
Accumulator variables: X, Y, ans
Iterator variables: i, j
Python program:
def findLargestSquare ( points , n ) :
    m = dict ( )
    for i in range ( n ) :
        m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] = m . get ( ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) , 0 ) + 1
    side = - 1
    x = - 1
    y = - 1
    for i in range ( n ) :
        m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] -= 1
        for j in range ( n ) :
            m [ ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] -= 1
            if ( i != j and ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) == ( points [ i ] [ 1 ] - points [ j ] [ 1 ] ) ) :
                if ( m [ ( points [ i ] [ 0 ] , points [ j ] [ 1 ] ) ] > 0 and m [ ( points [ j ] [ 0 ] , points [ i ] [ 1 ] ) ] > 0 ) :
                    if ( side < abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) or ( side == abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) and ( ( points [ i ] [ 0 ] * points [ i ] [ 0 ] + points [ i ] [ 1 ] * points [ i ] [ 1 ] ) < ( x * x + y * y ) ) ) ) :
                        x = points [ i ] [ 0 ]
                        y = points [ i ] [ 1 ]
                        side = abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] )
            m [ ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] += 1
        m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] += 1
    if ( side != - 1 ) :
        print ( " Side ▁ of ▁ the ▁ square ▁ is ▁ : ▁ " , side , " , points of the square are " , x , " ,   " , y , " ▁ " , ( x + side ) , " , ▁ " , y , " ▁ " , ( x ) , " , ▁ " , ( y + side ) , " ▁ " , ( x + side ) , " , ▁ " , ( y + side ) )
    else :
        print ( " No ▁ such ▁ square " )
n = 6
points = [ [ 1 , 1 ] , [ 4 , 4 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 1 , 4 ] , [ 4 , 1 ] ]
findLargestSquare ( points , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
MAX = 50
def solveQuery ( n , q , qi , qj ) :
    arr = [ None ] * MAX
    for i in range ( n + 1 ) :
        arr [ i ] = 0
    for k in range ( q ) :
        flag = 0
        if ( qj [ k ] < qi [ k ] ) :
            qj [ k ] , qi [ k ] = qi [ k ] , qj [ k ]
        if ( arr [ qi [ k ] ] != 0 or arr [ qj [ k ] ] != 0 ) :
            flag = 1
        elif ( qi [ k ] == qj [ k ] ) :
            flag = 1
        else :
            for i in range ( 1 , qi [ k ] ) :
                if ( arr [ i ] != 0 and arr [ i ] < qj [ k ] and qi [ k ] < arr [ i ] ) :
                    flag = 1
                    break
            if ( flag == 0 ) :
                for i in range ( qi [ k ] + 1 , qj [ k ] ) :
                    if ( arr [ i ] != 0 and arr [ i ] > qj [ k ] ) :
                        flag = 1
                        break
        if ( flag == 0 ) :
            print ( " YES " )
            arr [ qi [ k ] ] = qj [ k ]
            arr [ qj [ k ] ] = qi [ k ]
        else :
            print ( " NO " )
if __name__ == " _ _ main _ _ " :
    n = 10
    q = 7
    qi = [ 1 , 2 , 2 , 2 , 9 , 10 , 8 ]
    qj = [ 5 , 7 , 3 , 4 , 9 , 9 , 6 ]
    solveQuery ( n , q , qi , qj )

Index/key variables: i, k
Iterator variables: i, k
Python program:
def pentagon_pyramidal ( n ) :
    sum = 0
    for i in range ( 1 , n + 1 ) :
        p = ( 3 * i * i - i ) / 2
        sum = sum + p
    return sum
n = 4
print ( int ( pentagon_pyramidal ( n ) ) )

Iterator variables: i
Python program:
def factorial ( a , b ) :
    res = 1
    for i in range ( 1 , a + b + 1 ) :
        res = res * i
    for i in range ( 1 , a + 1 ) :
        res = res // i
    for i in range ( 1 , b + 1 ) :
        res = res // i
    return res
def Ksmallest ( x , y , k ) :
    if x == 0 and y == 0 :
        return
    elif x == 0 :
        y -= 1
        print ( " V " , end = " " )
        Ksmallest ( x , y , k )
    elif y == 0 :
        x -= 1
        print ( " H " , end = " " )
        Ksmallest ( x , y , k )
    else :
        if factorial ( x - 1 , y ) > k :
            print ( " H " , end = " " )
            Ksmallest ( x - 1 , y , k )
        else :
            print ( " V " , end = " " )
            Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) )
if __name__ == " _ _ main _ _ " :
    x , y , k = 2 , 2 , 2
    Ksmallest ( x , y , k )

Iterator variables: i
Python program:
import math
def isBetween ( a , b , c ) :
    return min ( a , b ) <= c and c <= max ( a , b )
def canJoin ( x , y , i , j , k ) :
    return ( x [ k ] == x [ i ] or x [ k ] == x [ j ] ) and isBetween ( y [ i ] , y [ j ] , y [ k ] ) or ( y [ k ] == y [ i ] or y [ k ] == y [ j ] ) and isBetween ( x [ i ] , x [ j ] , x [ k ] )
def countLineSegments ( x , y ) :
    if ( ( x [ 0 ] == x [ 1 ] and x [ 1 ] == x [ 2 ] ) or ( y [ 0 ] == y [ 1 ] and y [ 1 ] == y [ 2 ] ) ) :
        return 1
    elif ( canJoin ( x , y , 0 , 1 , 2 ) or canJoin ( x , y , 0 , 2 , 1 ) or canJoin ( x , y , 1 , 2 , 0 ) ) :
        return 2
    else :
        return 3
x = [ - 1 , - 1 , 4 ]
y = [ - 1 , 3 , 3 ]
print ( countLineSegments ( x , y ) )

Index/key variables: i, j, k
Python program:
class point :
    def __init__ ( self ) :
        self . x = 0
        self . y = 0
RIGHT = 1
LEFT = - 1
ZERO = 0
def directionOfPoint ( A , B , P ) :
    global RIGHT , LEFT , ZERO
    B . x -= A . x
    B . y -= A . y
    P . x -= A . x
    P . y -= A . y
    cross_product = B . x * P . y - B . y * P . x
    if ( cross_product > 0 ) :
        return RIGHT
    if ( cross_product < 0 ) :
        return LEFT
    return ZERO
if __name__ == " _ _ main _ _ " :
    A = point ( )
    B = point ( )
    P = point ( )
    A . x = - 30
    B . x = 29
    P . x = 15
    direction = directionOfPoint ( A , B , P )
    if ( direction == 1 ) :
        print ( " Right ▁ Direction " )
    elif ( direction == - 1 ) :
        print ( " Left ▁ Direction " )
    else :
        print ( " Point ▁ is ▁ on ▁ the ▁ Line " )

Class/struct names: point
Python program:
def minRadius ( k , x , y , n ) :
    dis = [ 0 ] * n
    for i in range ( 0 , n ) :
        dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]
    dis . sort ( )
    return dis [ k - 1 ]
k = 3
x = [ 1 , - 1 , 1 ]
y = [ 1 , - 1 , - 1 ]
n = len ( x )
print ( minRadius ( k , x , y , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def findTriangle ( a , n ) :
    b = [ ]
    for i in range ( n ) :
        b . append ( a [ i ] * a [ i ] )
    a . sort ( )
    b . sort ( )
    x , y , z = 0 , 0 , 0
    for i in range ( n ) :
        p = i + 1
        q = i + 1
        for j in range ( i + 1 , n ) :
            while ( p < n - 1 and b [ i ] + b [ j ] >= b [ p + 1 ] ) :
                p += 1
            q = max ( q , p )
            while ( q < n - 1 and a [ i ] + a [ j ] > a [ q + 1 ] ) :
                q += 1
            if ( b [ i ] + b [ j ] == b [ p ] ) :
                x += max ( p - j - 1 , 0 )
                y += 1
                z += q - p
            else :
                x += max ( p - j , 0 )
                z += q - p
    print ( " Acute ▁ Triangle : " , x )
    print ( " Right ▁ Triangle : " , y )
    print ( " Obtuse ▁ Triangle : " , z )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 9 , 10 , 12 , 15 ]
    n = len ( arr )
    findTriangle ( arr , n )

Index/key variables: i, j, p
Accumulator variables: b, q, x, y, z
Iterator variables: i, j
Python program:
def polygonArea ( X , Y , n ) :
    area = 0.0
    j = n - 1
    for i in range ( 0 , n ) :
        area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )
    return int ( abs ( area / 2.0 ) )
X = [ 0 , 2 , 4 ]
Y = [ 1 , 3 , 7 ]
n = len ( X )
print ( polygonArea ( X , Y , n ) )

Index/key variables: i, j
Accumulator variables: area
Iterator variables: i
Python program:
def findDifferenceArray ( arr , N ) :
    S1 = set ( ) ;
    S2 = set ( ) ;
    for i in range ( N ) :
        for j in range ( i ) :
            S1 . add ( arr [ j ] ) ;
        for j in range ( i + 1 , N ) :
            S2 . add ( arr [ j ] ) ;
        print ( abs ( len ( S1 ) - len ( S2 ) ) , end = ' ▁ ' ) ;
        S1 . clear ( ) ;
        S2 . clear ( ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 7 , 3 , 2 , 3 ] ;
    N = len ( arr ) ;
    findDifferenceArray ( arr , N ) ;

Index/key variables: j
Accumulator variables: S1, S2
Iterator variables: i, j
Python program:
import sys
def maximumSubarraySum ( arr ) :
    N = len ( arr ) ;
    memo = { } ;
    res = - ( sys . maxsize - 1 ) ;
    currsum = 0 ;
    currval = 0 ;
    for i in range ( N ) :
        currval = arr [ i ] ;
        currsum = currsum + currval ;
        if currval in memo :
            if ( currval > 0 ) :
                res = max ( res , currsum - memo [ currval ] + currval ) ;
            else :
                res = max ( res , currsum - memo [ currval ] + 2 * currval ) ;
        else :
            memo [ currval ] = currsum ;
        if ( currval < 0 ) :
            currsum = currsum - currval ;
    return res ;
if __name__ == " _ _ main _ _ " :
    arr = [ - 1 , - 3 , 4 , 0 , - 1 , - 2 ] ;
    print ( maximumSubarraySum ( arr ) ) ;

Index/key variables: currval, i
Iterator variables: i
Python program:
def factorial ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res *= i
    return res
def countPermutations ( ar , n ) :
    mp = dict ( )
    ans = 1
    cnt = n
    for i in range ( n ) :
        if ( ar [ i ] in mp ) :
            mp [ ar [ i ] ] += 1
        else :
            mp [ ar [ i ] ] = 1
    for i in range ( n ) :
        if ( i not in mp ) :
            break
        ans = ( ans * mp [ i ] )
        cnt -= 1
    ans = ans * factorial ( cnt )
    return ans
arr = [ 1 , 0 , 1 ]
N = len ( arr )
print ( countPermutations ( arr , N ) )

Index/key variables: i
Accumulator variables: cnt, res
Iterator variables: i
Python program:
def minimumAdditionOperation ( N ) :
    count = 0
    while ( N ) :
        if ( N & 1 == 1 ) :
            count += 1
        N = N >> 1
    return count
if __name__ == " _ _ main _ _ " :
    N = 6
    print ( minimumAdditionOperation ( N ) )

Accumulator variables: count
Python program:
maxn = 100000
prime = [ 0 for _ in range ( maxn ) ]
def semiPrimes ( N ) :
    for p in range ( 2 , maxn ) :
        if ( prime [ p ] == 0 ) :
            for i in range ( 2 * p , maxn , p ) :
                prime [ i ] += 1
    sPrimes = [ ]
    for p in range ( 2 , N + 1 ) :
        if ( prime [ p ] == 2 ) :
            sPrimes . append ( p )
    return sPrimes
def countPairs ( semiPrimes ) :
    cnt = 0
    for i in range ( 0 , len ( semiPrimes ) ) :
        for j in range ( i + 1 , len ( semiPrimes ) ) :
            if ( prime [ semiPrimes [ i ] + semiPrimes [ j ] ] == 0 ) :
                cnt += 1
    return cnt
if __name__ == " _ _ main _ _ " :
    N = 100
    print ( countPairs ( semiPrimes ( N ) ) )

Index/key variables: i, j, p
Accumulator variables: cnt, sPrimes
Iterator variables: i, j, p
Python program:
INT_MAX = 2147483647
def minimumOperations ( arr , N ) :
    mini = INT_MAX
    for i in range ( 0 , N ) :
        count = 0
        while ( arr [ i ] % 2 == 0 ) :
            arr [ i ] = arr [ i ] // 2
            count += 1
        if ( mini > count ) :
            mini = count
    return mini
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 6 ]
    N = len ( arr )
    print ( minimumOperations ( arr , N ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def countTriplets ( N ) :
    cnt = 0 ;
    for A in range ( 1 , N + 1 ) :
        for B in range ( 1 , N // A + 1 ) :
            cnt += N // ( A * B ) ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    N = 2 ;
    print ( countTriplets ( N ) ) ;

Accumulator variables: cnt
Iterator variables: A, B
Python program:
import math
maxn = 100001
gpf = [ 0 for _ in range ( maxn ) ]
def modifiedSieve ( ) :
    gpf [ 0 ] = 0
    gpf [ 1 ] = 1
    for i in range ( 2 , maxn ) :
        if ( gpf [ i ] > 0 ) :
            continue
        for j in range ( i , maxn , i ) :
            gpf [ j ] = max ( i , gpf [ j ] )
def greatestValidInt ( N ) :
    modifiedSieve ( )
    for i in range ( N , 0 , - 1 ) :
        if ( gpf [ i ] > math . sqrt ( i ) ) :
            return i
    return - 1
if __name__ == " _ _ main _ _ " :
    N = 25
    print ( greatestValidInt ( N ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def subfactorial ( N ) :
    res = 0
    fact = 1
    count = 0
    for i in range ( 1 , N + 1 ) :
        fact = fact * i
        if ( count % 2 == 0 ) :
            res = res - ( 1 / fact )
        else :
            res = res + ( 1 / fact )
        count += 1
    return fact * ( 1 + res )
if __name__ == " _ _ main _ _ " :
    N = 4
    print ( subfactorial ( N ) )

Accumulator variables: count
Iterator variables: i
Python program:
def minOperations ( A , B , N ) :
    cnt = 0
    i = 0
    while ( i < N ) :
        j = 0
        while ( j < N and i < N ) :
            if ( B [ i ] == A [ j ] ) :
                i += 1
            j += 1
        cnt += 1
    return cnt
if __name__ == ' _ _ main _ _ ' :
    A = [ 2 , 4 , 6 , 1 , 5 , 3 ]
    B = [ 6 , 5 , 4 , 2 , 3 , 1 ]
    N = len ( A )
    print ( minOperations ( A , B , N ) )

Index/key variables: i, j
Accumulator variables: cnt
Python program:
import math
def countPairs ( N ) :
    res = 0
    for q in range ( 1 , int ( math . sqrt ( N ) ) + 1 ) :
        maxP = min ( 2 * N - q , N // q )
        if ( maxP < q ) :
            continue
        cnt = maxP - q + 1
        res += ( cnt // 2 + ( cnt & 1 ) )
    return res
if __name__ == " _ _ main _ _ " :
    N = 3
    print ( countPairs ( N ) )

Accumulator variables: res
Iterator variables: q
Python program:
def maximizeSubset ( N , arr , M , x = 0 ) :
    if ( x == M ) :
        return 0
    ans = 0
    for i in range ( x , M ) :
        if ( N % arr [ i ] == 0 ) :
            ans = max ( ans , maximizeSubset ( N // arr [ i ] , arr , M , x + 1 ) + 1 )
    return ans
N = 64
arr = [ 1 , 2 , 4 , 8 , 16 , 32 ]
M = len ( arr )
print ( maximizeSubset ( N , arr , M ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys
from math import ceil , floor
def setSumtoZero ( arr , N ) :
    A = [ 0 for i in range ( N ) ]
    sum = 0
    m = - sys . maxsize - 1
    for i in range ( N ) :
        sum += ceil ( arr [ i ] )
        A [ i ] = ceil ( arr [ i ] )
    if ( sum > 0 ) :
        m = min ( sum , N )
        i = 0
        while ( i < N and m > 0 ) :
            A [ i ] = floor ( arr [ i ] )
            if ( A [ i ] != floor ( arr [ i ] ) ) :
                m -= 1
            i += 1
    for i in range ( N ) :
        print ( A [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 2 , - 2 , 4.5 ]
    N = len ( arr )
    setSumtoZero ( arr , N )

Index/key variables: i
Accumulator variables: m, sum
Iterator variables: i
Python program:
def Get ( graph , a ) :
    if graph [ graph [ a ] ] != graph [ a ] :
        graph [ a ] = Get ( graph , graph [ a ] )
    else :
        return graph [ a ]
def Union ( graph , a , b ) :
    a = Get ( graph , a )
    b = Get ( graph , b )
    graph [ a ] = b
def Queries ( queries , N , M ) :
    graph = [ 0 for i in range ( N + 2 ) ]
    for i in range ( 1 , N + 2 , 1 ) :
        graph [ i ] = i
    for query in queries :
        if ( query [ 0 ] == 1 ) :
            Union ( graph , query [ 1 ] , query [ 1 ] + 1 )
        else :
            a = Get ( graph , query [ 1 ] )
            if ( a == N + 1 ) :
                print ( - 1 )
            else :
                print ( graph [ a ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    queries = [ [ 2 , 1 ] , [ 1 , 1 ] , [ 2 , 1 ] , [ 2 , 3 ] ]
    Q = len ( queries )
    Queries ( queries , N , Q )

Index/key variables: a, i
Iterator variables: i, query
Python program:
def convertToBase9 ( n ) :
    ans = 0
    a = 1
    while ( n > 0 ) :
        ans += ( a * ( n % 9 ) )
        a *= 10
        n //= 9
    return ans
def getNthnumber ( base9 , K ) :
    ans = 0
    a = 1
    while ( base9 > 0 ) :
        cur = base9 % 10
        if ( cur >= K ) :
            ans += a * ( cur + 1 )
        else :
            ans += a * cur
        base9 //= 10
        a *= 10
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 10
    K = 1
    base9 = convertToBase9 ( N )
    print ( getNthnumber ( base9 , K ) )

Accumulator variables: a, ans, base9, n
Python program:
def binarySearch ( arr , size , key ) :
    low = 0
    high = size - 1
    while ( low <= high ) :
        mid = low + ( high - low ) // 2
        if ( key > arr [ mid ] ) :
            low = mid + 1
        elif ( key < arr [ mid ] ) :
            high = mid - 1
        else :
            return 1
    return 0
def twoPointers ( arr , N , mean ) :
    i = 0
    j = N - 1
    while ( i < j ) :
        temp = ( arr [ i ] + arr [ j ] ) / 2
        if ( temp > mean ) :
            j = j - 1
        elif ( temp < mean ) :
            i = i + 1
        else :
            return 1
    return 0
def checkArray ( arr , N ) :
    sum = 0
    for i in range ( 0 , N ) :
        sum += arr [ i ]
    mean = sum / N
    if ( N & 1 ) :
        return binarySearch ( arr , N , mean )
    else :
        return twoPointers ( arr , N , mean )
if __name__ == " _ _ main _ _ " :
    arr = [ 1.0 , 3.0 , 6.0 , 9.0 , 12.0 , 32.0 ]
    N = len ( arr )
    if ( checkArray ( arr , N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j, mid
Accumulator variables: sum
Iterator variables: i
Python program:
def UniqueGeometricTerms ( N , a1 , r1 , a2 , r2 ) :
    S = set ( )
    p1 = a1
    for i in range ( N ) :
        S . add ( p1 )
        p1 = ( p1 * r1 )
    p2 = a2
    for i in range ( N ) :
        S . add ( p2 )
        p2 = ( p2 * r2 )
    return len ( S )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    a1 = 3
    r1 = 2
    a2 = 2
    r2 = 3
    print ( UniqueGeometricTerms ( N , a1 , r1 , a2 , r2 ) )

Accumulator variables: S
Iterator variables: i
Python program:
def minOperations ( arr , N , K ) :
    vp = [ ]
    for i in range ( N ) :
        vp . append ( [ arr [ i ] , i ] )
    vp . sort ( )
    minCnt = 0
    while ( len ( vp ) != 0 ) :
        val = vp [ - 1 ] [ 0 ]
        ind = vp [ - 1 ] [ 1 ]
        minCnt += 1
        while ( len ( vp ) != 0 and vp [ - 1 ] [ 0 ] == val and ind - vp [ - 1 ] [ 1 ] + 1 <= K ) :
            vp . pop ( )
    return minCnt
if __name__ == " _ _ main _ _ " :
    arr = [ 18 , 11 , 18 , 11 , 18 ]
    K = 3
    N = len ( arr )
    print ( minOperations ( arr , N , K ) )

Index/key variables: i
Accumulator variables: minCnt, vp
Iterator variables: i
Python program:
def nearestLeft ( arr , N , steps ) :
    L = - N
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( arr [ i ] > 0 ) :
            L = - ( N - i )
            break
    for i in range ( N ) :
        if ( arr [ i ] > 0 ) :
            L = i
        steps [ i ] = i - L
def nearestRight ( arr , N , steps ) :
    R = 2 * N
    for i in range ( N ) :
        if ( arr [ i ] > 0 ) :
            R = N + i
            break
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( arr [ i ] > 0 ) :
            R = i
        steps [ i ] = min ( steps [ i ] , R - i )
def findSum ( arr , N , M , K ) :
    steps = [ 0 ] * N
    s = sum ( arr )
    if ( s == 0 ) :
        return 0
    nearestLeft ( arr , N , steps )
    nearestRight ( arr , N , steps )
    for i in range ( N ) :
        s += 2 * K * max ( 0 , M - steps [ i ] )
    return s
if __name__ == " _ _ main _ _ " :
    arr = [ 0 , 1 , 0 , 1 , 0 , 0 ]
    N = len ( arr )
    M = 2
    K = 1
    print ( findSum ( arr , N , M , K ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
maxn = 100
parent = [ 0 ] * maxn
Size = [ 0 ] * maxn
def make_set ( v ) :
    parent [ v ] = v
    Size [ v ] = 1
def find_set ( v ) :
    if ( v == parent [ v ] ) :
        return v
    parent [ v ] = find_set ( parent [ v ] )
    return parent [ v ]
def union_sets ( a , b ) :
    a = find_set ( a )
    b = find_set ( b )
    if ( a != b ) :
        if ( Size [ a ] < Size [ b ] ) :
            a , b = b , a
        parent [ b ] = a
        Size [ a ] += Size [ b ]
def findMinVertex ( N , edges ) :
    for i in range ( 1 , N + 1 ) :
        make_set ( i )
    for i in range ( len ( edges ) ) :
        union_sets ( edges [ i ] [ 0 ] , edges [ i ] [ 1 ] )
    minVal = { }
    for i in range ( 1 , N + 1 ) :
        if ( find_set ( i ) not in minVal ) :
            minVal [ find_set ( i ) ] = i
        else :
            minVal [ find_set ( i ) ] = min ( minVal [ find_set ( i ) ] , i )
    for i in range ( 1 , N + 1 ) :
        print ( minVal [ find_set ( i ) ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    N = 6
    edges = [ [ 1 , 3 ] , [ 2 , 4 ] ]
    findMinVertex ( N , edges )

Index/key variables: a, b, i, v
Iterator variables: i
Python program:
def getProduct ( n ) :
    product = 1
    while ( n != 0 ) :
        product = product * ( n % 10 )
        n = n // 10
    return product
def countPairs ( L , R ) :
    cntPair = 0
    for a in range ( L , R + 1 , 1 ) :
        for b in range ( a + 1 , R + 1 , 1 ) :
            x = getProduct ( a )
            y = getProduct ( b )
            if ( x and y and ( a * y ) == ( b * x ) ) :
                cntPair += 1
    return cntPair
if __name__ == ' _ _ main _ _ ' :
    L = 1
    R = 100
    print ( countPairs ( 1 , 100 ) )

Accumulator variables: cntPair
Iterator variables: a, b
Python program:
import sys
def maxSum ( matrix ) :
    r = len ( matrix )
    c = len ( matrix [ 0 ] )
    sum = 0
    mini = sys . maxsize
    count = 0
    for i in range ( r ) :
        for j in range ( c ) :
            k = matrix [ i ] [ j ]
            mini = min ( mini , abs ( k ) )
            if ( k < 0 ) :
                count += 1
            sum += abs ( k )
    if ( count % 2 == 0 ) :
        return sum
    else :
        return ( sum - 2 * mini )
if __name__ == ' _ _ main _ _ ' :
    matrix = [ [ 2 , - 2 ] , [ - 2 , 2 ] ]
    print ( maxSum ( matrix ) )

Index/key variables: i, j
Accumulator variables: count, sum
Iterator variables: i, j
Python program:
def lastPositiveElement ( arr ) :
    N = len ( arr ) ;
    if ( N == 1 ) :
        return arr [ 0 ] ;
    greatest = - 1 ; secondGreatest = - 1 ;
    for x in arr :
        if ( x >= greatest ) :
            secondGreatest = greatest ;
            greatest = x ;
        elif ( x >= secondGreatest ) :
            secondGreatest = x ;
    return greatest - secondGreatest ;
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 5 , 4 , 7 ] ;
    print ( lastPositiveElement ( arr ) ) ;

Iterator variables: x
Python program:
def updateArray ( arr , K ) :
    sum = 0
    res = [ ]
    for i in range ( 0 , int ( len ( arr ) ) ) :
        if ( arr [ i ] < K ) :
            sum += arr [ i ]
        else :
            if ( sum != 0 ) :
                res . append ( sum )
            sum = 0
            res . append ( arr [ i ] )
    if ( sum != 0 ) :
        res . append ( sum )
    for it in res :
        print ( it , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 200 , 6 , 36 , 612 , 121 , 66 , 63 , 39 , 668 , 108 ]
    K = 100
    updateArray ( arr , K )

Index/key variables: i
Accumulator variables: res, sum
Iterator variables: i, it