dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def kthSmallest ( arr , k , n ) :
    low = min ( arr ) ;
    high = max ( arr ) ;
    while ( low <= high ) :
        mid = low + ( high - low ) // 2 ;
        countless = 0 ; countequal = 0 ;
        for i in range ( n ) :
            if ( arr [ i ] < mid ) :
                countless += 1 ;
            elif ( arr [ i ] == mid ) :
                countequal += 1 ;
        if ( countless < k and ( countless + countequal ) >= k ) :
            return mid ;
        elif ( countless >= k ) :
            high = mid - 1 ;
        elif ( countless < k and countless + countequal < k ) :
            low = mid + 1 ;
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 10 , 4 , 3 , 20 , 15 ] ;
    n = len ( arr ) ;
    k = 3 ;
    print ( kthSmallest ( arr , k , n ) ) ;

Index/key variables: i
Accumulator variables: countequal, countless
Iterator variables: i
Python program:
MAX = 1000
tree = [ 0 ] * MAX ;
lazy = [ 0 ] * MAX ;
def updateRangeUtil ( si , ss , se , us , ue , diff ) :
    if ( lazy [ si ] != 0 ) :
        tree [ si ] += lazy [ si ] ;
        if ( ss != se ) :
            lazy [ si * 2 + 1 ] += lazy [ si ] ;
            lazy [ si * 2 + 2 ] += lazy [ si ] ;
        lazy [ si ] = 0 ;
    if ( ss > se or ss > ue or se < us ) :
        return ;
    if ( ss >= us and se <= ue ) :
        tree [ si ] += diff ;
        if ( ss != se ) :
            lazy [ si * 2 + 1 ] += diff ;
            lazy [ si * 2 + 2 ] += diff ;
        return ;
    mid = ( ss + se ) // 2 ;
    updateRangeUtil ( si * 2 + 1 , ss , mid , us , ue , diff ) ;
    updateRangeUtil ( si * 2 + 2 , mid + 1 , se , us , ue , diff ) ;
    tree [ si ] = max ( tree [ si * 2 + 1 ] , tree [ si * 2 + 2 ] ) ;
def updateRange ( n , us , ue , diff ) :
    updateRangeUtil ( 0 , 0 , n - 1 , us , ue , diff ) ;
def getSumUtil ( ss , se , qs , qe , si ) :
    if ( lazy [ si ] != 0 ) :
        tree [ si ] += lazy [ si ] ;
        if ( ss != se ) :
            lazy [ si * 2 + 1 ] += lazy [ si ] ;
            lazy [ si * 2 + 2 ] += lazy [ si ] ;
        lazy [ si ] = 0 ;
    if ( ss > se or ss > qe or se < qs ) :
        return 0 ;
    if ( ss >= qs and se <= qe ) :
        return tree [ si ] ;
    mid = ( ss + se ) // 2 ;
    return max ( getSumUtil ( ss , mid , qs , qe , 2 * si + 1 ) , getSumUtil ( mid + 1 , se , qs , qe , 2 * si + 2 ) ) ;
def getSum ( n , qs , qe ) :
    if ( qs < 0 or qe > n - 1 or qs > qe ) :
        print ( " Invalid ▁ Input " , end = " " ) ;
        return - 1 ;
    return getSumUtil ( 0 , n - 1 , qs , qe , 0 ) ;
def constructSTUtil ( arr , ss , se , si ) :
    if ( ss > se ) :
        return ;
    if ( ss == se ) :
        tree [ si ] = arr [ ss ] ;
        return ;
    mid = ( ss + se ) // 2 ;
    constructSTUtil ( arr , ss , mid , si * 2 + 1 ) ;
    constructSTUtil ( arr , mid + 1 , se , si * 2 + 2 ) ;
    tree [ si ] = max ( tree [ si * 2 + 1 ] , tree [ si * 2 + 2 ] ) ;
def constructST ( arr , n ) :
    constructSTUtil ( arr , 0 , n - 1 , 0 ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    n = len ( arr ) ;
    constructST ( arr , n ) ;
    updateRange ( n , 0 , 3 , 4 ) ;
    print ( getSum ( n , 1 , 4 ) ) ;

Index/key variables: si, ss
Python program:
MOD = 1000000007 ;
def rangeSum ( l , r ) :
    a = 1 ; b = 9 ; res = 0 ;
    for i in range ( 1 , 11 ) :
        L = max ( l , a ) ;
        R = min ( r , b ) ;
        if ( L <= R ) :
            sum = ( L + R ) * ( R - L + 1 ) // 2 ;
            res += ( i * i ) * ( sum % MOD ) ;
            res %= MOD ;
        a *= 10 ;
        b = b * 10 + 9 ;
    return res ;
if __name__ == " _ _ main _ _ " :
    l = 98 ; r = 102 ;
    print ( rangeSum ( l , r ) ) ;

Accumulator variables: a, res
Iterator variables: i
Python program:
import random
permutation = [ ]
def printPermutation ( ) :
    for i in permutation :
        print ( i , end = " ▁ " )
def give_random_number ( l , r ) :
    x = random . randint ( l , r )
    return x
def generate_random_permutation ( l , r ) :
    if ( l > r ) :
        return
    n = give_random_number ( l , r )
    permutation . append ( n )
    generate_random_permutation ( l , n - 1 )
    generate_random_permutation ( n + 1 , r )
l = 5
r = 15
generate_random_permutation ( l , r )
printPermutation ( )

Iterator variables: i
Python program:
INF = 99999
size = 10
def getSetBitsFromOneToN ( N ) :
    two , ans = 2 , 0
    n = N
    while ( n > 0 ) :
        ans += ( N // two ) * ( two >> 1 )
        if ( ( N & ( two - 1 ) ) > ( two >> 1 ) - 1 ) :
            ans += ( N & ( two - 1 ) ) - ( two >> 1 ) + 1
        two <<= 1
        n >>= 1
    return ans
def findMinimum ( x ) :
    low = 0
    high = 100000
    ans = high
    while ( low <= high ) :
        mid = ( low + high ) >> 1
        if ( getSetBitsFromOneToN ( mid ) >= x ) :
            ans = min ( ans , mid )
            high = mid - 1
        else :
            low = mid + 1
    return ans
x = 20
print ( findMinimum ( x ) )

Accumulator variables: ans, n, two
Python program:
from bisect import bisect_left as lower_bound
MOD = 1e9
MAX = 100
SZ = 40
BIT = [ 0 ] * ( MAX + 1 )
fact = [ 0 ] * ( SZ + 1 )
class queries :
    def __init__ ( self , tpe , l , r ) :
        self . type = tpe
        self . l = l
        self . r = r
def update ( x , val , n ) :
    global BIT
    while x <= n :
        BIT [ x ] += val
        x += x & - x
def summ ( x ) :
    global BIT
    s = 0
    while x > 0 :
        s += BIT [ x ]
        x -= x & - x
    return s
def answerQueries ( arr : list , que : list , n : int , q : int ) :
    global fact
    fact [ 0 ] = 1
    for i in range ( 1 , 41 ) :
        fact [ i ] = int ( ( fact [ i - 1 ] * i ) % MOD )
    s = set ( )
    for i in range ( 1 , n ) :
        if arr [ i ] < 40 :
            s . add ( i )
            update ( i , fact [ arr [ i ] ] , n )
        else :
            update ( i , 0 , n )
    for i in range ( q ) :
        if que [ i ] . type == 1 :
            while True :
                s = list ( s )
                s . sort ( )
                it = lower_bound ( s , que [ i ] . l )
                if it == len ( s ) or s [ it ] > que [ i ] . r :
                    break
                que [ i ] . l = s [ it ]
                val = arr [ s [ it ] ] + 1
                update ( s [ it ] , fact [ val ] - fact [ arr [ s [ it ] ] ] , n )
                arr [ s [ it ] ] += 1
                if arr [ s [ it ] ] >= 40 :
                    s . remove ( it )
                que [ i ] . l += 1
        elif que [ i ] . type == 2 :
            s = set ( s )
            idx = que [ i ] . l
            val = que [ i ] . r
            update ( idx , fact [ val ] - fact [ arr [ idx ] ] , n )
            arr [ idx ] = val
            if val < 40 :
                s . add ( idx )
            else :
                s . remove ( idx )
        else :
            print ( ( summ ( que [ i ] . r ) - summ ( que [ i ] . l - 1 ) ) )
if __name__ == " _ _ main _ _ " :
    q = 6
    arr = [ 0 , 1 , 2 , 1 , 4 , 5 ]
    n = len ( arr )
    que = [ queries ( 3 , 1 , 5 ) , queries ( 1 , 1 , 3 ) , queries ( 2 , 2 , 4 ) , queries ( 3 , 2 , 4 ) , queries ( 1 , 2 , 5 ) , queries ( 3 , 1 , 5 ) ]
    answerQueries ( arr , que , n , q )

Index/key variables: i, idx, it, val, x
Accumulator variables: s
Iterator variables: i
Class/struct names: queries
Python program:
def trailingZeroes ( n ) :
    cnt = 0
    while n > 0 :
        n = int ( n / 5 )
        cnt += n
    return cnt
def binarySearch ( n ) :
    low = 0
    while low < high :
        mid = int ( ( low + high ) / 2 )
        count = trailingZeroes ( mid )
        if count < n :
            low = mid + 1
        else :
            high = mid
    result = list ( )
    while trailingZeroes ( low ) == n :
        result . append ( low )
        low += 1
    for i in range ( len ( result ) ) :
        print ( result [ i ] , end = " ▁ " )
n = 2
binarySearch ( n )

Index/key variables: i
Accumulator variables: cnt, low, result
Iterator variables: i
Python program:
def kth ( arr1 , arr2 , m , n , k ) :
    sorted1 = [ 0 ] * ( m + n )
    i = 0
    j = 0
    d = 0
    while ( i < m and j < n ) :
        if ( arr1 [ i ] < arr2 [ j ] ) :
            sorted1 [ d ] = arr1 [ i ]
            i += 1
        else :
            sorted1 [ d ] = arr2 [ j ]
            j += 1
        d += 1
    while ( i < m ) :
        sorted1 [ d ] = arr1 [ i ]
        d += 1
        i += 1
    while ( j < n ) :
        sorted1 [ d ] = arr2 [ j ]
        d += 1
        j += 1
    return sorted1 [ k - 1 ]
arr1 = [ 2 , 3 , 6 , 7 , 9 ]
arr2 = [ 1 , 4 , 8 , 10 ]
k = 5
print ( kth ( arr1 , arr2 , 5 , 4 , k ) )

Index/key variables: d, i, j
Python program:
def kth ( arr1 , arr2 , n , m , k ) :
    if n == 1 or m == 1 :
        if m == 1 :
            arr2 , arr1 = arr1 , arr2
            m = n
        if k == 1 :
            return min ( arr1 [ 0 ] , arr2 [ 0 ] )
        elif k == m + 1 :
            return max ( arr1 [ 0 ] , arr2 [ 0 ] )
        else :
            if arr2 [ k - 1 ] < arr1 [ 0 ] :
                return arr2 [ k - 1 ]
            else :
                return max ( arr1 [ 0 ] , arr2 [ k - 2 ] )
    mid1 = ( n - 1 ) // 2
    mid2 = ( m - 1 ) // 2
    if mid1 + mid2 + 1 < k :
        if arr1 [ mid1 ] < arr2 [ mid2 ] :
            return kth ( arr1 [ mid1 + 1 : ] , arr2 , n - mid1 - 1 , m , k - mid1 - 1 )
        else :
            return kth ( arr1 , arr2 [ mid2 + 1 : ] , n , m - mid2 - 1 , k - mid2 - 1 )
    else :
        if arr1 [ mid1 ] < arr2 [ mid2 ] :
            return kth ( arr1 , arr2 [ : mid2 + 1 ] , n , mid2 + 1 , k )
        else :
            return kth ( arr1 [ : mid1 + 1 ] , arr2 , mid1 + 1 , m , k )
if __name__ == " _ _ main _ _ " :
    arr1 = [ 2 , 3 , 6 , 7 , 9 ]
    arr2 = [ 1 , 4 , 8 , 10 ]
    k = 5
    print ( kth ( arr1 , arr2 , 5 , 4 , k ) )

Index/key variables: mid1, mid2
Python program:
def kth ( arr1 , arr2 , m , n , k , st1 = 0 , st2 = 0 ) :
    if ( st1 == m ) :
        return arr2 [ st2 + k - 1 ]
    if ( st2 == n ) :
        return arr1 [ st1 + k - 1 ]
    if ( k == 0 or k > ( m - st1 ) + ( n - st2 ) ) :
        return - 1
    if ( k == 1 ) :
        if ( arr1 [ st1 ] < arr2 [ st2 ] ) :
            return arr1 [ st1 ]
        else :
            return arr2 [ st2 ]
    curr = int ( k / 2 )
    if ( curr - 1 >= m - st1 ) :
        if ( arr1 [ m - 1 ] < arr2 [ st2 + curr - 1 ] ) :
            return arr2 [ st2 + ( k - ( m - st1 ) - 1 ) ]
        else :
            return kth ( arr1 , arr2 , m , n , k - curr , st1 , st2 + curr )
    if ( curr - 1 >= n - st2 ) :
        if ( arr2 [ n - 1 ] < arr1 [ st1 + curr - 1 ] ) :
            return arr1 [ st1 + ( k - ( n - st2 ) - 1 ) ]
        else :
            return kth ( arr1 , arr2 , m , n , k - curr , st1 + curr , st2 )
    else :
        if ( arr1 [ curr + st1 - 1 ] < arr2 [ curr + st2 - 1 ] ) :
            return kth ( arr1 , arr2 , m , n , k - curr , st1 + curr , st2 )
        else :
            return kth ( arr1 , arr2 , m , n , k - curr , st1 , st2 + curr )
arr1 = [ 2 , 3 , 6 , 7 , 9 ]
arr2 = [ 1 , 4 , 8 , 10 ]
k = 5
print ( kth ( arr1 , arr2 , 5 , 4 , k ) )

Index/key variables: st1, st2
Python program:
def binarySearch ( arr , left , right ) :
    if ( left <= right ) :
        mid = ( left + right ) // 2 ;
        if ( arr [ mid - 1 ] < arr [ mid ] and arr [ mid ] > arr [ mid + 1 ] ) :
            return mid ;
        if ( arr [ mid ] < arr [ mid + 1 ] ) :
            return binarySearch ( arr , mid + 1 , right ) ;
        else :
            return binarySearch ( arr , left , mid - 1 ) ;
    return - 1 ;
arr = [ 6 , 7 , 8 , 11 , 9 , 5 , 2 , 1 ] ;
n = len ( arr ) ;
index = binarySearch ( arr , 1 , n - 2 ) ;
if ( index != - 1 ) :
    print ( arr [ index ] ) ;

Index/key variables: index, mid
Python program:
def findFrequencyUtil ( arr , low , high , freq ) :
    if ( arr [ low ] == arr [ high ] ) :
        freq [ arr [ low ] ] += high - low + 1
    else :
        mid = int ( ( low + high ) / 2 )
        findFrequencyUtil ( arr , low , mid , freq )
        findFrequencyUtil ( arr , mid + 1 , high , freq )
def findFrequency ( arr , n ) :
    freq = [ 0 for i in range ( n - 1 + 1 ) ]
    findFrequencyUtil ( arr , 0 , n - 1 , freq )
    for i in range ( 0 , arr [ n - 1 ] + 1 , 1 ) :
        if ( freq [ i ] != 0 ) :
            print ( " Element " , i , " occurs " , freq [ i ] , " times " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ]
    n = len ( arr )
    findFrequency ( arr , n )

Index/key variables: high, i, low
Iterator variables: i
Python program:
def floorSqrt ( x ) :
    if ( x == 0 or x == 1 ) :
        return x
    i = 1 ; result = 1
    while ( result <= x ) :
        i += 1
        result = i * i
    return i - 1
x = 11
print ( floorSqrt ( x ) )

Accumulator variables: i
Python program:
def maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N ) :
    max_rectangles = 0
    X = [ ]
    Y = [ ]
    for i in range ( 0 , N ) :
        X . append ( x1 [ i ] )
        X . append ( x2 [ i ] - 1 )
        Y . append ( y1 [ i ] )
        Y . append ( y2 [ i ] - 1 )
    for i in range ( 0 , len ( X ) ) :
        for j in range ( 0 , len ( Y ) ) :
            cnt = 0
            for k in range ( 0 , N ) :
                if ( X [ i ] >= x1 [ k ] and X [ i ] + 1 <= x2 [ k ] and Y [ j ] >= y1 [ k ] and Y [ j ] + 1 <= y2 [ k ] ) :
                    cnt += 1
            max_rectangles = max ( max_rectangles , cnt )
    print ( max_rectangles )
if __name__ == " _ _ main _ _ " :
    x1 = [ 0 , 50 ]
    y1 = [ 0 , 50 ]
    x2 = [ 100 , 60 ]
    y2 = [ 100 , 60 ]
    N = len ( x1 )
    maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N )

Index/key variables: i, j, k
Accumulator variables: X, Y, cnt
Iterator variables: i, j, k
Python program:
class Node :
    def __init__ ( self , val ) :
        self . data = val
        self . next = None
        self . prev = None
        self . top = None
        self . bottom = None
class LinkedList :
    def __init__ ( self ) :
        self . head = None
    def Quad ( self , grid , n , m ) :
        self . head = Node ( grid [ 0 ] [ 0 ] )
        temp = self . head
        i = 0
        j = 1
        while temp . top != self . head :
            if j < m and i == 0 :
                temp . next = Node ( grid [ i ] [ j ] )
                temp = temp . next
                j += 1
            elif j == m and i < n - 1 :
                i = i + 1
                temp . bottom = Node ( grid [ i ] [ j - 1 ] )
                temp = temp . bottom
            elif i == n - 1 and j <= m and j >= 1 :
                if j == m : j = j - 1
                j = j - 1
                temp . prev = Node ( grid [ i ] [ j ] )
                temp = temp . prev
            elif i <= n - 1 and j == 0 :
                i = i - 1
                temp . top = Node ( grid [ i ] [ j ] )
                temp = temp . top
                if i == 1 :
                    temp . top = self . head
    def printList ( self , root ) :
        temp = root
        print ( temp . data , end = " ▁ " )
        while temp . top != root :
            if temp . next :
                print ( temp . next . data , end = " ▁ " )
                temp = temp . next
            if temp . prev :
                print ( temp . prev . data , end = " ▁ " )
                temp = temp . prev
            if temp . bottom :
                print ( temp . bottom . data , end = " ▁ " )
                temp = temp . bottom
            if temp . top :
                print ( temp . top . data , end = " ▁ " )
                temp = temp . top
grid = [ [ 13 , 42 , 93 , 88 ] , [ 26 , 38 , 66 , 42 ] , [ 75 , 63 , 78 , 12 ] ]
n = len ( grid )
m = len ( grid [ 0 ] )
l = LinkedList ( )
l . Quad ( grid , n , m )
l . printList ( l . head )

Index/key variables: i, j
Class/struct names: LinkedList, Node
Python program:
import math
def isPossibleToReach ( A , N , X , Y ) :
    distance = math . sqrt ( X * X + Y * Y )
    mx = 0
    for i in range ( N ) :
        mx += A [ i ]
    if ( mx < distance ) :
        print ( " NO " )
        return 0
    if ( ( mx - distance ) < 0.000001 ) :
        print ( " YES " )
        return 0
    for i in range ( N ) :
        if ( distance + mx < ( 2 ) * ( A [ i ] ) ) :
            print ( " No " )
            return 0
    print ( " Yes " )
    return 0
A = [ 2 , 5 ]
X = 5
Y = 4
N = len ( A )
isPossibleToReach ( A , N , X , Y )

Index/key variables: i
Accumulator variables: mx
Iterator variables: i
Python program:
def canReach ( X , Y ) :
    steps = 0
    while ( X != 0 or Y != 0 ) :
        pos1 = X % 3
        pos2 = Y % 3
        if ( pos1 == 2 or pos2 == 2 ) :
            return False
        if ( pos1 == 1 and pos2 == 1 ) :
            return False
        if ( pos1 == 0 and pos2 == 0 ) :
            return False
        X /= 3
        Y /= 3
        steps += 1
    return True
X = 10
Y = 30
if ( canReach ( X , Y ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Accumulator variables: X, Y, steps
Python program:
def minimumRectangleArea ( A , N ) :
    ans = 0
    A . sort ( )
    ans = ( A [ N - 1 ] - A [ 0 ] ) * ( A [ 2 * N - 1 ] - A [ N ] )
    for i in range ( 1 , N , 1 ) :
        ans = min ( ans , ( A [ 2 * N - 1 ] - A [ 0 ] ) * ( A [ i + N - 1 ] - A [ i ] ) )
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = [ 2 , 4 , 1 , 5 , 3 , 6 , 7 , 8 ]
    N = len ( A )
    N //= 2
    print ( minimumRectangleArea ( A , N ) )

Index/key variables: N, i
Iterator variables: i
Python program:
def checkIntersection ( arr , N ) :
    vec = [ ]
    for i in range ( N - 1 ) :
        x = arr [ i ]
        y = arr [ i + 1 ]
        minn = min ( x , y )
        maxx = max ( x , y )
        vec . append ( [ minn , maxx ] )
    for i in range ( len ( vec ) ) :
        x = vec [ i ]
        for j in range ( len ( vec ) ) :
            y = vec [ j ]
            cond1 = ( x [ 0 ] < y [ 0 ] and x [ 1 ] < y [ 1 ] and y [ 0 ] < x [ 1 ] )
            cond2 = ( y [ 0 ] < x [ 0 ] and y [ 1 ] < x [ 1 ] and x [ 0 ] < y [ 1 ] )
            if ( cond1 or cond2 ) :
                return True
    return False
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 15 , 5 , 10 ]
    N = len ( arr )
    if ( checkIntersection ( arr , N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j
Accumulator variables: vec
Iterator variables: i, j
Python program:
def find ( a , b , N , K ) :
    for i in range ( N ) :
        count = 0
        for j in range ( N ) :
            if ( i == j ) :
                continue
            dis = abs ( a [ i ] - a [ j ] ) + abs ( b [ i ] - b [ j ] )
            if ( dis <= K ) :
                count = count + 1
            if ( count == N - 1 ) :
                return " Yes "
        return " No "
N = 5
A = [ 1 , 0 , 2 , 1 , 1 ]
B = [ 1 , 1 , 1 , 0 , 2 ]
K = 1
print ( find ( A , B , N , K ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findPairs ( x , y , K ) :
    n = len ( x )
    ans = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( K * abs ( x [ i ] - x [ j ] ) >= abs ( y [ i ] - y [ j ] ) ) :
                ans += 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    X = [ 2 , 1 , 0 ]
    Y = [ 1 , 2 , 0 ]
    K = 1
    findPairs ( X , Y , K )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
MAX = 10 ** 6 + 5
from math import ceil
def query ( arr , Q ) :
    pre = [ 0 ] * ( MAX )
    for i in range ( len ( arr ) ) :
        if ( arr [ i ] [ 0 ] < 0 or arr [ i ] [ 1 ] < 0 ) :
            continue
        sum = ceil ( ( arr [ i ] [ 0 ] + arr [ i ] [ 1 ] ) ) ;
        pre [ sum ] += 1
    for i in range ( 1 , MAX ) :
        pre [ i ] += pre [ i - 1 ]
    for i in range ( len ( Q ) ) :
        print ( pre [ Q [ i ] ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 2.1 , 3.0 ] , [ 3.7 , 1.2 ] , [ 1.5 , 6.5 ] , [ 1.2 , 0.0 ] ]
    Q = [ 2 , 8 , 5 ]
    N = len ( arr )
    M = len ( Q )
    query ( arr , Q )

Index/key variables: i, sum
Iterator variables: i
Python program:
def CrossProduct ( A ) :
    X1 = ( A [ 1 ] [ 0 ] - A [ 0 ] [ 0 ] )
    Y1 = ( A [ 1 ] [ 1 ] - A [ 0 ] [ 1 ] )
    X2 = ( A [ 2 ] [ 0 ] - A [ 0 ] [ 0 ] )
    Y2 = ( A [ 2 ] [ 1 ] - A [ 0 ] [ 1 ] )
    return ( X1 * Y2 - Y1 * X2 )
def isConvex ( points ) :
    N = len ( points )
    prev = 0
    curr = 0
    for i in range ( N ) :
        temp = [ points [ i ] , points [ ( i + 1 ) % N ] , points [ ( i + 2 ) % N ] ]
        curr = CrossProduct ( temp )
        if ( curr != 0 ) :
            if ( curr * prev < 0 ) :
                return False
            else :
                prev = curr
    return True
if __name__ == ' _ _ main _ _ ' :
    points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ]
    if ( isConvex ( points ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def cntRect ( points , N , rectangle ) :
    cntHor = set ( [ ] )
    cntVer = set ( [ ] )
    cntHor . add ( 0 )
    cntVer . add ( 0 )
    cntHor . add ( rectangle [ 3 ] [ 0 ] )
    cntVer . add ( rectangle [ 3 ] [ 1 ] )
    for i in range ( N ) :
        cntHor . add ( points [ i ] [ 0 ] )
        cntVer . add ( points [ i ] [ 1 ] )
    return ( ( len ( cntHor ) - 1 ) * ( len ( cntVer ) - 1 ) )
if __name__ == " _ _ main _ _ " :
    rectangle = [ [ 0 , 0 ] , [ 0 , 5 ] , [ 5 , 0 ] , [ 5 , 5 ] ]
    points = [ [ 1 , 2 ] , [ 3 , 4 ] ]
    N = len ( points )
    print ( cntRect ( points , N , rectangle ) )

Index/key variables: i
Accumulator variables: cntHor, cntVer
Iterator variables: i
Python program:
def numberOfSquares ( X , Y , N , M ) :
    m1 = { }
    m2 = { }
    ans = 0
    for i in range ( 0 , N ) :
        for j in range ( i + 1 , N ) :
            dist = abs ( X [ i ] - X [ j ] )
            if dist in m1 :
                m1 [ dist ] = m1 [ dist ] + 1
            else :
                m1 [ dist ] = 1
    for i in range ( 0 , M ) :
        for j in range ( i + 1 , M ) :
            dist = abs ( Y [ i ] - Y [ j ] )
            if dist in m2 :
                m2 [ dist ] = m2 [ dist ] + 1
            else :
                m2 [ dist ] = 1
    for key in m1 :
        if key in m2 :
            ans = ans + ( m1 [ key ] * m2 [ key ] )
    return ans
if __name__ == " _ _ main _ _ " :
    X = [ 1 , 3 , 7 ]
    Y = [ 2 , 4 , 6 , 1 ]
    N = len ( X )
    M = len ( Y )
    print ( numberOfSquares ( X , Y , N , M ) )

Index/key variables: dist, i, j, key
Iterator variables: i, j, key
Python program:
from math import sqrt
def find ( x , y , p ) :
    mind = 0
    for i in range ( len ( p ) ) :
        a = p [ i ] [ 0 ]
        b = p [ i ] [ 1 ]
        mind += sqrt ( ( x - a ) * ( x - a ) + ( y - b ) * ( y - b ) )
    return mind
def getMinDistSum ( p ) :
    x = 0
    y = 0
    for i in range ( len ( p ) ) :
        x += p [ i ] [ 0 ]
        y += p [ i ] [ 1 ]
    x = x // len ( p )
    y = y // len ( p )
    mind = find ( x , y , p )
    return mind
if __name__ == ' _ _ main _ _ ' :
    vec = [ [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] , [ 2 , 1 ] ]
    d = getMinDistSum ( vec )
    print ( int ( d ) )

Index/key variables: i
Accumulator variables: mind, x, y
Iterator variables: i
Python program:
def checkValidPolygon ( arr , N ) :
    Sum = 0
    for i in range ( N ) :
        Sum += arr [ i ]
    if Sum == 180 * ( N - 2 ) :
        print ( " Yes " )
    else :
        print ( " No " )
N = 3
arr = [ 60 , 60 , 60 ]
checkValidPolygon ( arr , N )

Index/key variables: i
Accumulator variables: Sum
Iterator variables: i
Python program:
MAX = 1001
arr = [ [ False for i in range ( MAX ) ] for j in range ( MAX ) ]
def updateArray ( x1 , y1 , x2 , y2 ) :
    for i in range ( x1 , x2 ) :
        for j in range ( y1 , y2 ) :
            arr [ i ] [ j ] = True
def findAreaCovered ( ) :
    area = 0
    for i in range ( MAX ) :
        for j in range ( MAX ) :
            if arr [ i ] [ j ] :
                area += 1
    return area
if __name__ == " _ _ main _ _ " :
    N = 3
    A = [ [ 1 , 3 , 4 , 5 ] , [ 3 , 1 , 7 , 4 ] , [ 5 , 3 , 8 , 6 ] ] ;
    for i in range ( N ) :
        updateArray ( A [ i ] [ 0 ] , A [ i ] [ 1 ] , A [ i ] [ 2 ] , A [ i ] [ 3 ] ) ;
    area = findAreaCovered ( ) ;
    print ( area )

Index/key variables: i, j
Accumulator variables: area
Iterator variables: i, j