dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
MAX_NODES = 100005
parent = [ 0 for i in range ( MAX_NODES ) ] ;
size_set = [ 0 for i in range ( MAX_NODES ) ] ;
def make_set ( v ) :
    parent [ v ] = v ;
    size_set [ v ] = 1 ;
def find_set ( v ) :
    if ( v == parent [ v ] ) :
        return v ;
    parent [ v ] = find_set ( parent [ v ] ) ;
    return parent [ v ]
def union_set ( a , b ) :
    a = find_set ( a ) ;
    b = find_set ( b ) ;
    if ( a != b ) :
        if ( size_set [ a ] < size_set [ b ] ) :
            swap ( a , b ) ;
        parent [ b ] = a ;
        size_set [ a ] += size_set [ b ] ;
def check ( a , b ) :
    a = find_set ( a ) ;
    b = find_set ( b ) ;
    if a == b :
        return ( " Yes " )
    else :
        return ( " No " )
if __name__ == " _ _ main _ _ " :
    n = 5
    m = 3 ;
    make_set ( 1 ) ;
    make_set ( 2 ) ;
    make_set ( 3 ) ;
    make_set ( 4 ) ;
    make_set ( 5 ) ;
    union_set ( 1 , 3 ) ;
    union_set ( 3 , 4 ) ;
    union_set ( 3 , 5 ) ;
    q = 3 ;
    print ( check ( 1 , 5 ) )
    print ( check ( 3 , 2 ) )
    print ( check ( 5 , 2 ) )

Index/key variables: a, b, v
Python program:
def count ( N , A , B ) :
    if ( N == 1 ) :
        return 9 // B + 1
    max_sum = 9 * N
    odd_count = N // 2 + N % 2
    even_count = N - odd_count
    dp = [ [ 0 for x in range ( max_sum + 1 ) ] for y in range ( even_count ) ]
    for i in range ( 10 ) :
        dp [ 0 ] [ i % A ] += 1
    for i in range ( 1 , even_count ) :
        for j in range ( 10 ) :
            for k in range ( max_sum + 1 ) :
                if ( dp [ i - 1 ] [ k ] > 0 ) :
                    dp [ i ] [ ( j + k ) % A ] += dp [ i - 1 ] [ k ]
    dp1 = [ [ 0 for x in range ( max_sum ) ] for y in range ( odd_count ) ]
    for i in range ( 1 , 10 ) :
        dp1 [ 0 ] [ i % B ] += 1
    for i in range ( 1 , odd_count ) :
        for j in range ( 10 ) :
            for k in range ( max_sum + 1 ) :
                if ( dp1 [ i - 1 ] [ k ] > 0 ) :
                    dp1 [ i ] [ ( j + k ) % B ] += dp1 [ i - 1 ] [ k ]
    return dp [ even_count - 1 ] [ 0 ] * dp1 [ odd_count - 1 ] [ 0 ]
if __name__ == " _ _ main _ _ " :
    N = 2
    A = 2
    B = 5
    print ( count ( N , A , B ) )

Index/key variables: i, k
Iterator variables: i, j, k
Python program:
import math
def maxDiff ( arr , n ) :
    SubsetSum_1 = 0
    SubsetSum_2 = 0
    for i in range ( 0 , n ) :
        isSingleOccurance = True
        for j in range ( i + 1 , n ) :
            if ( arr [ i ] == arr [ j ] ) :
                isSingleOccurance = False
                arr [ i ] = arr [ j ] = 0
                break
        if ( isSingleOccurance == True ) :
            if ( arr [ i ] > 0 ) :
                SubsetSum_1 += arr [ i ]
            else :
                SubsetSum_2 += arr [ i ]
    return abs ( SubsetSum_1 - SubsetSum_2 )
arr = [ 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 ]
n = len ( arr )
print ( " Maximum ▁ Difference ▁ = ▁ { } " . format ( maxDiff ( arr , n ) ) )

Index/key variables: i, j
Accumulator variables: SubsetSum_1, SubsetSum_2
Iterator variables: i, j
Boolean variables: isSingleOccurance
Python program:
from math import log2
def equalXORandOR ( n ) :
    m = 0
    MSB = int ( log2 ( n ) )
    for i in range ( MSB + 1 ) :
        if ( not ( n & ( 1 << i ) ) ) :
            m += ( 1 << i )
    return m
n = 14
print ( equalXORandOR ( n ) )

Accumulator variables: m
Iterator variables: i
Python program:
def maxDiff ( arr , n ) :
    result = 0
    arr . sort ( )
    for i in range ( n - 1 ) :
        if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :
            result += abs ( arr [ i ] )
        else :
            pass
    if ( arr [ n - 2 ] != arr [ n - 1 ] ) :
        result += abs ( arr [ n - 1 ] )
    return result
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 ]
    n = len ( arr )
    print ( " Maximum ▁ Difference ▁ = ▁ " , maxDiff ( arr , n ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def findNewString ( s ) :
    ans = 0
    freq = [ 0 ] * 26
    n = len ( s )
    for i in range ( n ) :
        ans += freq [ ord ( s [ i ] ) - ord ( ' a ' ) ]
        freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    return ans
s = " aaabaaa "
print ( findNewString ( s ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def maxDiff ( arr , n ) :
    hashPositive = dict ( )
    hashNegative = dict ( )
    SubsetSum_1 , SubsetSum_2 = 0 , 0
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            hashPositive [ arr [ i ] ] = hashPositive . get ( arr [ i ] , 0 ) + 1
    for i in range ( n ) :
        if ( arr [ i ] > 0 and arr [ i ] in hashPositive . keys ( ) and hashPositive [ arr [ i ] ] == 1 ) :
            SubsetSum_1 += arr [ i ]
    for i in range ( n ) :
        if ( arr [ i ] < 0 ) :
            hashNegative [ abs ( arr [ i ] ) ] = hashNegative . get ( abs ( arr [ i ] ) , 0 ) + 1
    for i in range ( n ) :
        if ( arr [ i ] < 0 and abs ( arr [ i ] ) in hashNegative . keys ( ) and hashNegative [ abs ( arr [ i ] ) ] == 1 ) :
            SubsetSum_2 += arr [ i ]
    return abs ( SubsetSum_1 - SubsetSum_2 )
arr = [ 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 ]
n = len ( arr )
print ( " Maximum ▁ Difference ▁ = " , maxDiff ( arr , n ) )

Index/key variables: i
Accumulator variables: SubsetSum_1, SubsetSum_2
Iterator variables: i
Python program:
def proofreadSpell ( str ) :
    result = [ ]
    for c in str :
        result . append ( c )
        n = len ( result )
        if ( n >= 3 ) :
            if ( result [ n - 1 ] == result [ n - 2 ] and result [ n - 1 ] == result [ n - 3 ] ) :
                result . pop ( )
        n = len ( result )
        if ( n >= 4 ) :
            if ( result [ n - 1 ] == result [ n - 2 ] and result [ n - 3 ] == result [ n - 4 ] ) :
                result . pop ( )
    resultStr = " "
    for c in result :
        resultStr += c
    return resultStr
str = " hello "
print ( proofreadSpell ( str ) )

Accumulator variables: result, resultStr
Iterator variables: c
Python program:
def minRange ( arr , n , k ) :
    l = 0
    r = n
    for i in range ( n ) :
        s = [ ]
        for j in range ( i , n ) :
            s . append ( arr [ j ] )
            if ( len ( s ) == k ) :
                if ( ( j - i ) < ( r - l ) ) :
                    r = j
                    l = i
                break
        if ( j == n ) :
            break
    if ( l == 0 and r == n ) :
        print ( " Invalid ▁ k " )
    else :
        print ( l , r )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    n = len ( arr )
    k = 3
    minRange ( arr , n , k )

Index/key variables: j
Accumulator variables: s
Iterator variables: i, j
Python program:
from collections import defaultdict
def minRange ( arr , n , k ) :
    l , r = 0 , n
    i = 0
    j = - 1
    hm = defaultdict ( lambda : 0 )
    while i < n :
        while j < n :
            j += 1
            if len ( hm ) < k and j < n :
                hm [ arr [ j ] ] += 1
            if len ( hm ) == k and ( ( r - l ) >= ( j - i ) ) :
                l , r = i , j
                break
        if len ( hm ) < k :
            break
        while len ( hm ) == k :
            if hm [ arr [ i ] ] == 1 :
                del ( hm [ arr [ i ] ] )
            else :
                hm [ arr [ i ] ] -= 1
            i += 1
            if len ( hm ) == k and ( r - l ) >= ( j - i ) :
                l , r = i , j
        if hm [ arr [ i ] ] == 1 :
            del ( hm [ arr [ i ] ] )
        else :
            hm [ arr [ i ] ] -= 1
        i += 1
    if l == 0 and r == n :
        print ( " Invalid ▁ k " )
    else :
        print ( l , r )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 ]
    n = len ( arr )
    k = 3
    minRange ( arr , n , k )

Index/key variables: i, j
Python program:
def sum ( a , n ) :
    cnt = dict ( )
    ans = 0
    pre_sum = 0
    for i in range ( n ) :
        ans += ( i * a [ i ] ) - pre_sum
        pre_sum += a [ i ]
        if ( a [ i ] - 1 ) in cnt :
            ans -= cnt [ a [ i ] - 1 ]
        if ( a [ i ] + 1 ) in cnt :
            ans += cnt [ a [ i ] + 1 ]
        if a [ i ] not in cnt :
            cnt [ a [ i ] ] = 0
        cnt [ a [ i ] ] += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 2 , 3 , 1 , 3 ]
    n = len ( a )
    print ( sum ( a , n ) )

Index/key variables: i
Accumulator variables: ans, pre_sum
Iterator variables: i
Python program:
import sys
def minDistance ( a , n ) :
    maximum = - 1
    minimum = sys . maxsize
    min_index = - 1
    max_index = - 1
    min_dist = n + 1
    for i in range ( n ) :
        if ( a [ i ] > maximum ) :
            maximum = a [ i ]
        if ( a [ i ] < minimum ) :
            minimum = a [ i ]
    for i in range ( n ) :
        if ( a [ i ] == minimum ) :
            min_index = i
        if ( a [ i ] == maximum ) :
            max_index = i
        if ( min_index != - 1 and max_index != - 1 ) :
            min_dist = ( min ( min_dist , abs ( min_index - max_index ) ) )
    return min_dist
if __name__ == " _ _ main _ _ " :
    a = [ 3 , 2 , 1 , 2 , 1 , 4 , 5 , 8 , 6 , 7 , 8 , 2 ]
    n = len ( a )
    print ( minDistance ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def printDiagonal ( K , N , M ) :
    startrow , startcol = 0 , 0
    if K - 1 < N :
        startrow = K - 1
        startcol = 0
    else :
        startrow = N - 1
        startcol = K - N
    while startrow >= 0 and startcol < N :
        print ( M [ startrow ] [ startcol ] , end = " ▁ " )
        startrow -= 1
        startcol += 1
if __name__ == ' _ _ main _ _ ' :
    N , K = 3 , 4
    M = [ [ 4 , 7 , 8 ] , [ 9 , 2 , 3 ] , [ 0 , 4 , 1 ] ]
    printDiagonal ( K , N , M )

Index/key variables: startcol, startrow
Python program:
def longestSubstring ( str , X , Y ) :
    N = len ( str )
    start = 0
    end = N - 1
    xPos = 0
    yPos = 0
    while ( True ) :
        if ( str [ start ] == X ) :
            xPos = start
            break
        start += 1
    while ( True ) :
        if ( str [ end ] == Y ) :
            yPos = end
            break
        end -= 1
    length = ( yPos - xPos ) + 1
    print ( length )
if __name__ == " _ _ main _ _ " :
    str = " HASFJGHOGAKZZFEGA "
    X = ' A '
    Y = ' Z '
    longestSubstring ( str , X , Y )

Index/key variables: end, start
Python program:
def ReplaceElements ( arr , n ) :
    if ( n < 2 ) :
        print ( " Invalid ▁ Input " )
        return
    firstSmallest = 10 ** 18
    secondSmallest = 10 ** 18
    for i in range ( n ) :
        if ( arr [ i ] < firstSmallest ) :
            secondSmallest = firstSmallest
            firstSmallest = arr [ i ]
        elif ( arr [ i ] < secondSmallest and arr [ i ] != firstSmallest ) :
            secondSmallest = arr [ i ]
    for i in range ( n ) :
        if ( arr [ i ] != firstSmallest ) :
            arr [ i ] = firstSmallest
        else :
            arr [ i ] = secondSmallest
    for i in arr :
        print ( i , end = " , ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 1 , 3 ]
    n = len ( arr )
    ReplaceElements ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def countSubarrWithEqualZeroAndOne ( arr , n ) :
    um = dict ( )
    curr_sum = 0
    for i in range ( n ) :
        curr_sum += ( - 1 if ( arr [ i ] == 0 ) else arr [ i ] )
        if um . get ( curr_sum ) :
            um [ curr_sum ] += 1
        else :
            um [ curr_sum ] = 1
    count = 0
    for itr in um :
        if um [ itr ] > 1 :
            count += ( ( um [ itr ] * int ( um [ itr ] - 1 ) ) / 2 )
    if um . get ( 0 ) :
        count += um [ 0 ]
    return int ( count )
arr = [ 1 , 0 , 0 , 1 , 0 , 1 , 1 ]
n = len ( arr )
print ( " Count ▁ = " , countSubarrWithEqualZeroAndOne ( arr , n ) )

Index/key variables: curr_sum, i, itr
Accumulator variables: count
Iterator variables: i, itr
Python program:
def lenOfLongSubarr ( arr , n ) :
    um = { i : 0 for i in range ( 10 ) }
    sum = 0
    maxLen = 0
    for i in range ( n ) :
        if arr [ i ] == 0 :
            sum += - 1
        else :
            sum += 1
        if ( sum == 1 ) :
            maxLen = i + 1
        elif ( sum not in um ) :
            um [ sum ] = i
        if ( ( sum - 1 ) in um ) :
            if ( maxLen < ( i - um [ sum - 1 ] ) ) :
                maxLen = i - um [ sum - 1 ]
    return maxLen
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 1 , 1 , 0 , 0 , 1 ]
    n = len ( arr )
    print ( " Length ▁ = " , lenOfLongSubarr ( arr , n ) )

Index/key variables: i, sum
Iterator variables: i
Python program:
def printAllAPTriplets ( arr , n ) :
    s = [ ] ;
    for i in range ( 0 , n - 1 ) :
        for j in range ( i + 1 , n ) :
            diff = arr [ j ] - arr [ i ] ;
            if ( ( arr [ i ] - diff ) in arr ) :
                print ( " { } ▁ { } ▁ { } " . format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end =   " " ) ;
    s . append ( arr [ i ] ) ;
arr = [ 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 ] ;
n = len ( arr ) ;
printAllAPTriplets ( arr , n ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printAllAPTriplets ( arr , n ) :
    for i in range ( 1 , n - 1 ) :
        j = i - 1
        k = i + 1
        while ( j >= 0 and k < n ) :
            if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) :
                print ( arr [ j ] , " " , arr [ i ] , " " , arr [ k ] )
                k += 1
                j -= 1
            elif ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) :
                k += 1
            else :
                j -= 1
arr = [ 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 ]
n = len ( arr )
printAllAPTriplets ( arr , n )

Index/key variables: i, j, k
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , val ) :
        self . val = val
        self . left = None
        self . right = None
def existPathUtil ( root , arr , n , index ) :
    if not root or index == n :
        return False
    if not root . left and not root . right :
        if root . val == arr [ index ] and index == n - 1 :
            return True
        return False
    return ( ( index < n ) and ( root . val == arr [ index ] ) and ( existPathUtil ( root . left , arr , n , index + 1 ) or existPathUtil ( root . right , arr , n , index + 1 ) ) )
def existPath ( root , arr , n , index ) :
    if not root :
        return ( n == 0 )
    return existPathUtil ( root , arr , n , 0 )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 8 , 6 , 7 ]
    n = len ( arr )
    root = Node ( 5 )
    root . left = Node ( 3 )
    root . right = Node ( 8 )
    root . left . left = Node ( 2 )
    root . left . right = Node ( 4 )
    root . left . left . left = Node ( 1 )
    root . right . left = Node ( 6 )
    root . right . left . right = Node ( 7 )
    if existPath ( root , arr , n , 0 ) :
        print ( " Path ▁ Exists " )
    else :
        print ( " Path ▁ does ▁ not ▁ Exist " )

Index/key variables: index
Class/struct names: Node
Python program:
def findTriplets ( a , n , sum ) :
    a . sort ( )
    flag = False
    for i in range ( n - 2 ) :
        if ( i == 0 or a [ i ] > a [ i - 1 ] ) :
            start = i + 1
            end = n - 1
            target = sum - a [ i ]
            while ( start < end ) :
                if ( start > i + 1 and a [ start ] == a [ start - 1 ] ) :
                    start += 1
                    continue
                if ( end < n - 1 and a [ end ] == a [ end + 1 ] ) :
                    end -= 1
                    continue
                if ( target == a [ start ] + a [ end ] ) :
                    print ( " [ " , a [ i ] , " , " , a [ start ] , " , " , a [ end ] , " ] " , end = " ▁ " )
                    flag = True
                    start += 1
                    end -= 1
                elif ( target > ( a [ start ] + a [ end ] ) ) :
                    start += 1
                else :
                    end -= 1
    if ( flag == False ) :
        print ( " No ▁ Such ▁ Triplets ▁ Exist " )
if __name__ == " _ _ main _ _ " :
    a = [ 12 , 3 , 6 , 1 , 6 , 9 ]
    n = len ( a )
    sum = 24
    findTriplets ( a , n , sum )

Index/key variables: end, i, start
Iterator variables: i
Boolean variables: flag
Python program:
m , n = 6 , 4 ;
def linearCheck ( ar , arr ) :
    for i in range ( m ) :
        matched = True ;
        for j in range ( n ) :
            if ( ar [ i ] [ j ] != arr [ j ] ) :
                matched = False ;
                break ;
        if ( matched ) :
            return i + 1 ;
    return - 1 ;
if __name__ == " _ _ main _ _ " :
    mat = [ [ 0 , 0 , 1 , 0 ] , [ 10 , 9 , 22 , 23 ] , [ 40 , 40 , 40 , 40 ] , [ 43 , 44 , 55 , 68 ] , [ 81 , 73 , 100 , 132 ] , [ 100 , 75 , 125 , 133 ] ] ;
    row = [ 10 , 9 , 22 , 23 ] ;
    print ( linearCheck ( mat , row ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: matched
Python program:
def countTriplets ( arr , n , m ) :
    count = 0
    for i in range ( n - 2 ) :
        for j in range ( i + 1 , n - 1 ) :
            for k in range ( j + 1 , n ) :
                if ( arr [ i ] * arr [ j ] * arr [ k ] == m ) :
                    count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 4 , 6 , 2 , 3 , 8 ]
    m = 24
    print ( countTriplets ( arr , len ( arr ) , m ) )

Index/key variables: i, j, k
Accumulator variables: count
Iterator variables: i, j, k
Python program:
def countTriplets ( li , product ) :
    flag = 0
    count = 0
    for i in range ( len ( li ) ) :
        if li [ i ] != 0 and product % li [ i ] == 0 :
            for j in range ( i + 1 , len ( li ) ) :
                if li [ j ] != 0 and product % ( li [ j ] * li [ i ] ) == 0 :
                    if product // ( li [ j ] * li [ i ] ) in li :
                        n = li . index ( product // ( li [ j ] * li [ i ] ) )
                        if n > i and n > j :
                            flag = 1
                            count += 1
    print ( count )
li = [ 1 , 4 , 6 , 2 , 3 , 8 ]
product = 24
countTriplets ( li , product )

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

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def preCalculate ( binary , n , left ) :
    count1 , count0 = 0 , 0
    for i in range ( n ) :
        left [ i ] [ 0 ] = count1
        left [ i ] [ 1 ] = count0
        if ( binary [ i ] ) :
            count1 += 1
        else :
            count0 += 1
binary = [ 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 ]
n = len ( binary )
left = [ [ 0 for i in range ( 2 ) ] for i in range ( n ) ]
preCalculate ( binary , n , left )
queries = [ 0 , 1 , 2 , 4 ]
q = len ( queries )
for i in range ( q ) :
    print ( left [ queries [ i ] ] [ 0 ] , " ones " , left [ queries [ i ] ] [ 1 ] , " zeros " )

Index/key variables: i
Accumulator variables: count0, count1
Iterator variables: i
Python program:
import math as mt
def countPairs ( arr , n ) :
    mp = dict ( )
    for i in range ( n ) :
        if arr [ i ] in mp . keys ( ) :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    ans = 0
    for it in mp :
        count = mp [ it ]
        ans += ( count * ( count - 1 ) ) // 2
    return ans
arr = [ 1 , 1 , 2 ]
n = len ( arr )
print ( countPairs ( arr , n ) )

Index/key variables: i, it
Accumulator variables: ans
Iterator variables: i, it
Python program:
def equiSumUtil ( arr , pos1 , pos2 ) :
    n = len ( arr ) ;
    pre = [ 0 ] * n ;
    sum = 0 ;
    for i in range ( n ) :
        sum += arr [ i ] ;
        pre [ i ] = sum ;
    suf = [ 0 ] * n ;
    sum = 0 ;
    for i in range ( n - 1 , - 1 , - 1 ) :
        sum += arr [ i ] ;
        suf [ i ] = sum ;
    total_sum = sum ;
    i = 0 ;
    j = n - 1 ;
    while ( i < j - 1 ) :
        if ( pre [ i ] == total_sum // 3 ) :
            pos1 = i ;
        if ( suf [ j ] == total_sum // 3 ) :
            pos2 = j ;
        if ( pos1 != - 1 and pos2 != - 1 ) :
            if ( suf [ pos1 + 1 ] - suf [ pos2 ] == total_sum // 3 ) :
                return [ True , pos1 , pos2 ] ;
            else :
                return [ False , pos1 , pos2 ] ;
        if ( pre [ i ] < suf [ j ] ) :
            i += 1 ;
        else :
            j -= 1 ;
    return [ False , pos1 , pos2 ] ;
def equiSum ( arr ) :
    pos1 = - 1 ;
    pos2 = - 1 ;
    ans = equiSumUtil ( arr , pos1 , pos2 ) ;
    pos1 = ans [ 1 ] ;
    pos2 = ans [ 2 ] ;
    if ( ans [ 0 ] ) :
        print ( " First ▁ Segment ▁ : ▁ " , end = " " ) ;
        for i in range ( pos1 + 1 ) :
            print ( arr [ i ] , end = " ▁ " ) ;
        print ( " " ) ;
        print ( " Second ▁ Segment ▁ : ▁ " , end = " " ) ;
        for i in range ( pos1 + 1 , pos2 ) :
            print ( arr [ i ] , end = " ▁ " ) ;
        print ( " " ) ;
        print ( " Third ▁ Segment ▁ : ▁ " , end = " " ) ;
        for i in range ( pos2 , len ( arr ) ) :
            print ( arr [ i ] , end = " ▁ " ) ;
        print ( " " ) ;
    else :
        println ( " Array ▁ cannot ▁ be ▁ divided ▁ into " , " three ▁ equal ▁ sum ▁ segments " ) ;
arr = [ 1 , 3 , 6 , 2 , 7 , 1 , 2 , 8 ] ;
equiSum ( arr ) ;

Index/key variables: i, j, pos2
Accumulator variables: sum
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , item ) :
        self . data = item
        self . left = self . right = None
def getLevel ( root , node , level ) :
    if ( root == None ) :
        return 0
    if ( root == node ) :
        return level
    downlevel = getLevel ( root . left , node , level + 1 )
    if ( downlevel != 0 ) :
        return downlevel
    return getLevel ( root . right , node , level + 1 )
def printGivenLevel ( root , node , level ) :
    if ( root == None or level < 2 ) :
        return
    if ( level == 2 ) :
        if ( root . left == node or root . right == node ) :
            return
        if ( root . left ) :
            print ( root . left . data , end = " ▁ " )
        if ( root . right ) :
            print ( root . right . data , end = " ▁ " )
    elif ( level > 2 ) :
        printGivenLevel ( root . left , node , level - 1 )
        printGivenLevel ( root . right , node , level - 1 )
def printCousins ( root , node ) :
    level = getLevel ( root , node , 1 )
    printGivenLevel ( root , node , level )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . left . right . right = newNode ( 15 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 7 )
    root . right . left . right = newNode ( 8 )
    printCousins ( root , root . left . right )

Class/struct names: newNode
Python program:
def getRightMin ( arr , n ) :
    min = arr [ 0 ]
    rightMin = 0
    i = 1
    while ( i < n ) :
        if ( arr [ i ] == min ) :
            rightMin = i
        i *= 2
    i = rightMin + 1
    while ( i < n and arr [ i ] == min ) :
        rightMin = i
        i += 1
    return rightMin
def getLeftMax ( arr , n ) :
    max = arr [ n - 1 ]
    leftMax = n - 1
    i = n - 2
    while ( i > 0 ) :
        if ( arr [ i ] == max ) :
            leftMax = i
        i = int ( i / 2 )
    i = leftMax - 1
    while ( i >= 0 and arr [ i ] == max ) :
        leftMax = i
        i -= 1
    return leftMax
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 0 , 1 , 2 , 5 , 5 , 6 , 8 , 8 ]
    n = len ( arr )
    print ( " Minimum ▁ left ▁ : " , 0 )
    print ( " Minimum ▁ right ▁ : " , getRightMin ( arr , n ) )
    print ( " Maximum ▁ left ▁ : " , getLeftMax ( arr , n ) )
    print ( " Maximum ▁ right ▁ : " , ( n - 1 ) )

Index/key variables: i