dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import sys
def maxLength ( arr ) :
    lenn = - sys . maxsize - 1
    N = len ( arr )
    for i in range ( N ) :
        l = len ( arr [ i ] )
        if ( lenn < l ) :
            lenn = l
    return lenn
def maxStrings ( arr , lenn ) :
    N = len ( arr )
    ans = [ ]
    for i in range ( N ) :
        if ( lenn == len ( arr [ i ] ) ) :
            ans . append ( arr [ i ] )
    for i in range ( len ( ans ) ) :
        print ( ans [ i ] , end = " ▁ " )
def printStrings ( arr ) :
    max = maxLength ( arr )
    maxStrings ( arr , max )
if __name__ == ' _ _ main _ _ ' :
    arr = [ " aba " , " aa " , " ad " , " vcd " , " aba " ]
    printStrings ( arr )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def min_flips ( strr , k ) :
    if ( len ( strr ) == 0 ) :
        return 0
    ans = 0
    cnt_zeros = 0
    for ch in strr :
        if ( ch == '0' ) :
            cnt_zeros += 1
        else :
            cnt_zeros = 0
        if ( cnt_zeros == k ) :
            ans += 1
            cnt_zeros = 0
    return ans
if __name__ == ' _ _ main _ _ ' :
    strr = "11100000011"
    k = 3
    print ( min_flips ( strr , k ) )

Accumulator variables: ans, cnt_zeros
Iterator variables: ch
Python program:
def maxSubArray ( arr , n , K ) :
    solution = [ ]
    multi = 1
    start = 0
    if ( n <= 1 or K < 0 ) :
        return solution
    for i in range ( n ) :
        multi = multi * arr [ i ]
        while ( multi > K ) :
            multi = multi // arr [ start ]
            start += 1
        li = [ ]
        j = i
        while ( j >= start ) :
            li . insert ( 0 , arr [ j ] )
            solution . append ( list ( li ) )
            j -= 1
    return solution
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 7 , 1 , 4 ]
    n = len ( arr )
    K = 7
    v = maxSubArray ( arr , n , K )
    print ( v )

Index/key variables: i, j, start
Accumulator variables: solution
Iterator variables: i
Python program:
def solve ( D , N , X , Y ) :
    T = [ ]
    for i in range ( N ) :
        x = D [ i ] [ 0 ]
        y = D [ i ] [ 1 ]
        speed = D [ i ] [ 2 ]
        time = ( ( x * x - X * X ) + ( y * y - Y * Y ) ) / ( speed * speed )
        T . append ( time )
    T . sort ( )
    i = 0
    total = 0
    while i < len ( T ) - 1 :
        count = 1
        while i < len ( T ) - 1 and T [ i ] == T [ i + 1 ] :
            count += 1
            i += 1
        total += ( count * ( count - 1 ) ) / 2
        i += 1
    return total
N = 5
D = [ [ 5 , 12 , 1 ] , [ 16 , 63 , 5 ] , [ - 10 , 24 , 2 ] , [ 7 , 24 , 2 ] , [ - 24 , 7 , 2 ] ]
X = 0
Y = 0
print ( solve ( D , N , X , Y ) )

Index/key variables: i
Accumulator variables: T, count, total
Iterator variables: i
Python program:
def getMaxLength ( arr , N ) :
    res = 2
    dist = 2
    curradj = ( arr [ 1 ] - arr [ 0 ] )
    prevadj = ( arr [ 1 ] - arr [ 0 ] )
    for i in range ( 2 , N ) :
        curradj = arr [ i ] - arr [ i - 1 ]
        if ( curradj == prevadj ) :
            dist += 1
        else :
            prevadj = curradj
            res = max ( res , dist )
            dist = 2
    res = max ( res , dist )
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 7 , 4 , 6 , 8 , 10 , 11 ]
    N = len ( arr )
    print ( getMaxLength ( arr , N ) )

Index/key variables: i
Accumulator variables: dist
Iterator variables: i
Python program:
def minSteps ( str , N ) :
    cost = 0
    f = [ 0 ] * 26
    for i in range ( N ) :
        curr_ele = ord ( str [ i ] ) - ord ( ' a ' )
        smaller = 0
        for j in range ( curr_ele + 1 ) :
            if ( f [ j ] ) :
                smaller += f [ j ]
        if ( smaller == 0 ) :
            cost += ( i + 1 )
        else :
            cost += ( i - smaller + 1 )
        f [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1
    return cost
str = " abcab "
N = len ( str )
print ( minSteps ( str , N ) )

Index/key variables: i, j
Accumulator variables: cost, smaller
Iterator variables: i, j
Python program:
def findSubarrays ( a ) :
    n = len ( a )
    freq = [ 0 ] * ( n + 1 )
    count = 0
    for i in range ( n ) :
        if ( a [ i ] == 0 ) :
            if ( count == 0 ) :
                continue
            else :
                value = count
                for j in range ( 1 , count + 1 ) :
                    freq [ j ] += value
                    value -= 1
                count = 0
        else :
            count += 1
    if ( count > 0 ) :
        value = count
        for j in range ( 1 , count + 1 ) :
            freq [ j ] += value
            value -= 1
    return freq
def countRectangles ( a , b , K ) :
    n = len ( a )
    m = len ( b )
    subA = [ ]
    subA = findSubarrays ( a )
    subB = [ ]
    subB = findSubarrays ( b )
    total = 0
    for i in range ( 1 , len ( subA ) ) :
        if ( K % i == 0 and ( K // i ) <= m ) :
            total = total + subA [ i ] * subB [ K // i ]
    print ( total )
a = [ 0 , 0 , 1 , 1 ]
b = [ 1 , 0 , 1 ]
K = 2
countRectangles ( a , b , K )

Index/key variables: i, j
Accumulator variables: count, value
Iterator variables: i, j
Python program:
def printRes ( res ) :
    n = len ( res )
    for i in range ( n ) :
        print ( res [ i ] , end = " ▁ " )
def printLBS ( arr , N ) :
    lis = [ 0 ] * N
    lds = [ 0 ] * N
    for i in range ( N ) :
        lis [ i ] = lds [ i ] = 1
    for i in range ( N ) :
        for j in range ( i ) :
            if arr [ j ] < arr [ i ] :
                if lis [ i ] < lis [ j ] + 1 :
                    lis [ i ] = lis [ j ] + 1
    for i in range ( N - 1 , - 1 , - 1 ) :
        for j in range ( N - 1 , i , - 1 ) :
            if arr [ j ] < arr [ i ] :
                if lds [ i ] < lds [ j ] + 1 :
                    lds [ i ] = lds [ j ] + 1
    MaxVal = arr [ 0 ]
    inx = 0
    for i in range ( N ) :
        if MaxVal < lis [ i ] + lds [ i ] - 1 :
            MaxVal = lis [ i ] + lds [ i ] - 1
            inx = i
    ct1 = lis [ inx ]
    res = [ ]
    i = inx
    while i >= 0 and ct1 > 0 :
        if lis [ i ] == ct1 :
            res . append ( arr [ i ] )
            ct1 -= 1
        i -= 1
    res . reverse ( )
    ct2 = lds [ inx ] - 1
    i = inx
    while i < N and ct2 > 0 :
        if lds [ i ] == ct2 :
            res . append ( arr [ i ] )
            ct2 -= 1
        i += 1
    printRes ( res )
arr = [ 80 , 60 , 30 , 40 , 20 , 10 ]
N = len ( arr )
printLBS ( arr , N )

Index/key variables: i, inx, j
Accumulator variables: ct1, ct2, res
Iterator variables: i, j
Python program:
def possible ( T , arr , n , d ) :
    partition = 1 ;
    total = 0 ;
    for i in range ( n ) :
        total = total + arr [ i ] ;
        if ( total > T ) :
            partition = partition + 1 ;
            total = arr [ i ] ;
            if ( partition > d ) :
                return False ;
    return True ;
def calcT ( n , d , arr ) :
    mx = - 1 ; sum = 0 ;
    for i in range ( n ) :
        mx = max ( mx , arr [ i ] ) ;
        sum = sum + arr [ i ] ;
    lb = mx ;
    ub = sum ;
    while ( lb < ub ) :
        T_mid = lb + ( ub - lb ) // 2 ;
        if ( possible ( T_mid , arr , n , d ) == True ) :
            ub = T_mid ;
        else :
            lb = T_mid + 1 ;
    print ( lb ) ;
if __name__ == ' _ _ main _ _ ' :
    d = 2 ;
    arr = [ 1 , 1 , 1 , 1 , 1 ] ;
    n = len ( arr ) ;
    calcT ( n , d , arr ) ;

Index/key variables: i
Iterator variables: i
Python program:
def minReqSubstring ( s , n ) :
    ongoing = ' N '
    count , l = 0 , len ( s )
    for i in range ( 1 , l ) :
        if ongoing == ' N ' :
            if s [ i ] < s [ i - 1 ] :
                ongoing = ' D '
            elif s [ i ] == s [ i - 1 ] :
                ongoing = ' N '
            else :
                ongoing = ' I '
        elif ongoing == ' I ' :
            if s [ i ] > s [ i - 1 ] :
                ongoing = ' I '
            elif s [ i ] == s [ i - 1 ] :
                ongoing = ' I '
            else :
                ongoing = ' N '
                count += 1
        else :
            if s [ i ] < s [ i - 1 ] :
                ongoing = ' D '
            elif s [ i ] == s [ i - 1 ] :
                ongoing = ' D '
            else :
                ongoing = ' N '
                count += 1
    return count + 1
S = " aeccdhba "
n = len ( S )
print ( minReqSubstring ( S , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def minimum_required_operations ( arr , n , k ) :
    answer = 0
    mod = 10 ** 9 + 7
    for i in range ( n - 1 ) :
        if arr [ i ] + arr [ i + 1 ] > k :
            if arr [ i ] > k :
                answer += ( arr [ i ] - k )
                arr [ i ] = k
            answer += ( arr [ i ] + arr [ i + 1 ] ) - k
            arr [ i + 1 ] = ( k - arr [ i ] )
            answer %= mod
    return answer
a = [ 9 , 50 , 4 , 14 , 42 , 89 ]
k = 10
print ( minimum_required_operations ( a , len ( a ) , k ) )

Index/key variables: i
Accumulator variables: answer
Iterator variables: i
Python program:
def findSmallestString ( str1 , str2 ) :
    freq1 = [ 0 ] * 26
    freq2 = [ 0 ] * 26
    n1 = len ( str1 )
    n2 = len ( str2 )
    for i in range ( n1 ) :
        freq1 [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( n2 ) :
        freq2 [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 26 ) :
        freq1 [ i ] -= freq2 [ i ]
    res = " "
    minIndex = ord ( str2 [ 0 ] ) - ord ( ' a ' )
    for i in range ( 26 ) :
        for j in range ( freq1 [ i ] ) :
            res += chr ( i + ord ( ' a ' ) )
        if i == minIndex :
            res += str2
    return res
str1 = " geeksforgeeksfor "
str2 = " for "
print ( findSmallestString ( str1 , str2 ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i, j
Python program:
def decryptString ( s , N ) :
    for i in range ( 0 , len ( s ) , 2 * N ) :
        if ( i + N < len ( s ) ) :
            end = s [ i + N ]
        if ( i + N > len ( s ) ) :
            end = s [ - 1 ]
        if ( i == 0 ) :
            s = s [ i + N - 1 : : - 1 ] + s [ i + N : ]
        else :
            s = s [ : i ] + s [ i + N - 1 : i - 1 : - 1 ] + s [ i + N : ]
    print ( s )
if __name__ == " _ _ main _ _ " :
    s = " ihTs ▁ suohld ▁ ebeas ! y "
    N = 3
    decryptString ( s , N )

Iterator variables: i
Python program:
def determineWinner ( str ) :
    A = [ 0 for i in range ( 9 ) ] ;
    sum1 = 0 ; sum2 = 0 ;
    for i in range ( 0 , len ( str ) ) :
        A [ int ( str [ i ] ) ] += 1 ;
    for i in range ( 0 , 9 ) :
        if ( i % 2 != 0 ) :
            sum1 = sum1 + A [ i ] ;
        else :
            sum2 = sum2 + A [ i ] ;
    if ( sum1 == sum2 ) :
        print ( " - 1" ) ;
    elif ( sum1 > sum2 ) :
        print ( " Player ▁ 1" ) ;
    else :
        print ( " Player ▁ 2" ) ;
if __name__ == ' _ _ main _ _ ' :
    str = "78787" ;
    determineWinner ( str ) ;

Index/key variables: i
Iterator variables: i
Python program:
def manipulateStrings ( P , Q ) :
    freq = [ 0 for i in range ( 26 ) ] ;
    for i in range ( len ( P ) ) :
        freq [ ord ( P [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( len ( Q ) ) :
        freq [ ord ( Q [ i ] ) - ord ( ' a ' ) ] -= 1
    sb = " "
    pos = ord ( Q [ 0 ] ) - ord ( ' a ' )
    for i in range ( pos + 1 ) :
        while freq [ i ] > 0 :
            sb += chr ( ord ( ' a ' ) + i )
            freq [ i ] -= 1
    sb += Q
    for i in range ( pos + 1 , 26 ) :
        while freq [ i ] > 0 :
            sb += chr ( ord ( ' a ' ) + i )
            freq [ i ] -= 1
    print ( sb )
if __name__ == " _ _ main _ _ " :
    P = " geeksforgeeksfor " ;
    Q = " for " ;
    manipulateStrings ( P , Q ) ;

Index/key variables: i
Accumulator variables: sb
Iterator variables: i
Python program:
from collections import defaultdict
mod = 1000000007
def countS ( string : list , n : int , m : int ) -> int :
    counts = defaultdict ( lambda : set ( ) )
    for i in range ( n ) :
        s = string [ i ]
        for j in range ( m ) :
            counts [ j ] . add ( s [ j ] )
    result = 1
    for index in counts :
        result = ( result * len ( counts [ index ] ) ) % mod
    return result
if __name__ == " _ _ main _ _ " :
    string = [ "112" , "211" ]
    N = 2
    M = 3
    print ( countS ( string , N , M ) )

Index/key variables: i, index, j
Iterator variables: i, index, j
Python program:
def solve ( n , arr ) :
    ans = 0
    for i in range ( n ) :
        left = max ( i - 1 , 0 )
        right = min ( n - 1 , i + 1 )
        while left >= 0 :
            if arr [ left ] > arr [ i ] :
                left += 1
                break
            left -= 1
        if left < 0 :
            left += 1
        while right < n :
            if arr [ right ] > arr [ i ] :
                right -= 1
                break
            right += 1
        if right >= n :
            right -= 1
        ans = 1 + right - left
        print ( ans , end = " ▁ " )
arr = [ 4 , 2 , 1 ]
n = len ( arr )
solve ( n , arr )

Index/key variables: i, left, right
Iterator variables: i
Python program:
from collections import defaultdict
def countSubstrings ( s , n ) :
    count , sum = 0 , 0
    mp = defaultdict ( lambda : 0 )
    mp [ 0 ] += 1
    for i in range ( n ) :
        sum += ord ( s [ i ] ) - ord ( '0' )
        count += mp [ sum - ( i + 1 ) ]
        mp [ sum - ( i + 1 ) ] += 1
    return count
str = '112112'
n = len ( str )
print ( countSubstrings ( str , n ) )

Index/key variables: i
Accumulator variables: count, sum
Iterator variables: i
Python program:
def findCount ( arr , n ) :
    prefix_sum = [ 0 for x in range ( n ) ]
    prefix_sum [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ]
    suffix_sum = [ 0 for x in range ( n ) ]
    suffix_sum [ n - 1 ] = arr [ n - 1 ]
    for i in range ( n - 2 , - 1 , - 1 ) :
        suffix_sum [ i ] = suffix_sum [ i + 1 ] + arr [ i ]
    s = 1
    e = 1
    curr_subarray_sum = 0
    count = 0
    while ( s < n - 1 and e < n - 1 ) :
        while ( e < n - 1 and curr_subarray_sum < prefix_sum [ s - 1 ] ) :
            curr_subarray_sum += arr [ e ]
            e += 1
        if ( curr_subarray_sum <= suffix_sum [ e ] ) :
            count += 1
        curr_subarray_sum -= arr [ s ]
        s += 1
    return count
arr = [ 2 , 3 , 1 , 7 ]
n = len ( arr )
print ( findCount ( arr , n ) )

Index/key variables: e, i, s
Accumulator variables: count, curr_subarray_sum
Iterator variables: i
Python program:
def minOperation ( s , n ) :
    cnt1 = 0 ;
    for i in range ( n ) :
        if ( ord ( s [ i ] ) == ord ( '1' ) ) :
            cnt1 += 1 ;
    cnt0 = 0 ;
    for i in range ( 0 , cnt1 ) :
        if ( s [ i ] == '0' ) :
            cnt0 += 1 ;
    return cnt0 ;
if __name__ == ' _ _ main _ _ ' :
    n = 8 ;
    s = "01001011" ;
    ans = minOperation ( s , n ) ;
    print ( ans ) ;

Index/key variables: i
Accumulator variables: cnt0, cnt1
Iterator variables: i
Python program:
def minOperation ( s , n ) :
    ans = 0 ;
    i = 0 ; j = n - 1 ;
    while ( i < j ) :
        if ( s [ i ] == '0' and s [ j ] == '1' ) :
            ans += 1 ;
            i += 1 ;
            j -= 1 ;
            continue ;
        if ( s [ i ] == '1' ) :
            i += 1 ;
        if ( s [ j ] == '0' ) :
            j -= 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    n = 8 ;
    s = "10100101" ;
    print ( minOperation ( s , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans
Python program:
def count ( N ) :
    if ( N == 1 ) :
        print ( 10 ) ;
        return ;
    dp = [ [ 0 for i in range ( 10 ) ] for j in range ( N ) ]
    for i in range ( 1 , 10 ) :
        dp [ 0 ] [ i ] = 1 ;
    for i in range ( 1 , N ) :
        temp = 0 ;
        for j in range ( 10 ) :
            temp += dp [ i - 1 ] [ j ] ;
        for j in range ( 10 ) :
            dp [ i ] [ j ] = temp - dp [ i - 1 ] [ j ] ;
    ans = 0 ;
    for i in range ( 10 ) :
        ans += dp [ N - 1 ] [ i ] ;
    print ( ans ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 2 ;
    count ( N ) ;

Index/key variables: i, j
Accumulator variables: ans, temp
Iterator variables: i, j
Python program:
def kmp ( s ) :
    n = len ( s )
    lps = [ None ] * n
    lps [ 0 ] = 0
    i , Len = 1 , 0
    while ( i < n ) :
        if ( s [ i ] == s [ Len ] ) :
            Len += 1
            lps [ i ] = Len
            i += 1
        else :
            if ( Len != 0 ) :
                Len = lps [ Len - 1 ]
            else :
                lps [ i ] = 0
                i += 1
    return lps
def findString ( s , k ) :
    n = len ( s )
    lps = kmp ( s )
    ans = " "
    suff = s [ 0 : n - lps [ n - 1 ] : 1 ]
    for i in range ( k - 1 ) :
        ans += suff
    ans += s
    return ans
k = 3
s = " geeksforgeeks "
print ( findString ( s , k ) )

Index/key variables: Len, i
Accumulator variables: ans
Iterator variables: i
Python program:
def check ( arr , n ) :
    g = 0
    for i in range ( 1 , n ) :
        if ( arr [ i ] - arr [ i - 1 ] > 0 and g == 1 ) :
            return False
        if ( arr [ i ] - arr [ i ] < 0 ) :
            g = 1
    return True
arr = [ 2 , 3 , 4 , 10 , 4 , 3 , 1 ]
n = len ( arr )
if ( check ( arr , n ) == True ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
ctr = 0
def find ( parent , x ) :
    if ( parent [ x ] == x ) :
        return x
    parent [ x ] = find ( parent , parent [ x ] )
    return parent [ x ]
def setUnion ( parent , rank , x , y ) :
    global ctr
    parentx = find ( parent , x )
    parenty = find ( parent , y )
    if ( parenty == parentx ) :
        return
    ctr -= 1
    if ( rank [ parentx ] < rank [ parenty ] ) :
        parent [ parentx ] = parenty
    elif ( rank [ parentx ] > rank [ parenty ] ) :
        parent [ parenty ] = parentx
    else :
        parent [ parentx ] = parenty
        rank [ parenty ] += 1
def solve ( n , m , query ) :
    global ctr
    result = [ 0 ] * len ( query )
    parent = [ 0 ] * ( n * m )
    for i in range ( n * m ) :
        parent [ i ] = i
    rank = [ 1 ] * ( n * m )
    grid = [ 0 ] * ( n * m )
    for i in range ( len ( query ) ) :
        x = query [ i ] [ 0 ]
        y = query [ i ] [ 1 ]
        if ( grid [ m * x + y ] == 1 ) :
            result [ i ] = ctr
            continue
        grid [ m * x + y ] = 1
        ctr += 1
        if ( x > 0 and grid [ m * ( x - 1 ) + y ] == 1 ) :
            setUnion ( parent , rank , m * x + y , m * ( x - 1 ) + y )
        if ( y > 0 and grid [ m * ( x ) + y - 1 ] == 1 ) :
            setUnion ( parent , rank , m * x + y , m * ( x ) + y - 1 )
        if ( x < n - 1 and grid [ m * ( x + 1 ) + y ] == 1 ) :
            setUnion ( parent , rank , m * x + y , m * ( x + 1 ) + y )
        if ( y < m - 1 and grid [ m * ( x ) + y + 1 ] == 1 ) :
            setUnion ( parent , rank , m * x + y , m * ( x ) + y + 1 )
        result [ i ] = ctr
    return result
if __name__ == " _ _ main _ _ " :
    N = 3
    M = 3
    K = 4
    query = [ [ 0 , 0 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] ]
    result = solve ( N , M , query )
    for i in range ( K ) :
        print ( result [ i ] , end = " ▁ " )

Index/key variables: i, parentx, parenty, x
Accumulator variables: ctr
Iterator variables: i
Python program:
import sys
def findMinSum ( A , K ) :
    n = len ( A ) ;
    suffix_min = [ 0 ] * n ;
    suffix_min [ n - 1 ] = A [ n - 1 ] ;
    for i in range ( n - 2 , - 1 , - 1 ) :
        suffix_min [ i ] = min ( suffix_min [ i + 1 ] , A [ i ] ) ;
    min_sum = sys . maxsize ;
    for i in range ( n ) :
        if ( i + K < n ) :
            min_sum = min ( min_sum , A [ i ] + suffix_min [ i + K ] ) ;
    print ( min_sum ) ;
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
    K = 2 ;
    findMinSum ( A , K ) ;

Index/key variables: i
Iterator variables: i
Python program:
def maxEnvelopes ( envelopes ) :
    N = len ( envelopes )
    if ( N == 0 ) :
        return N
    envelopes = sorted ( envelopes )
    dp = [ 0 ] * N
    max_envelope = 1
    dp [ 0 ] = 1
    for i in range ( 1 , N ) :
        dp [ i ] = 1
        for j in range ( i ) :
            if ( envelopes [ i ] [ 0 ] > envelopes [ j ] [ 0 ] and envelopes [ i ] [ 1 ] > envelopes [ j ] [ 1 ] and dp [ i ] < dp [ j ] + 1 ) :
                dp [ i ] = dp [ j ] + 1
        max_envelope = max ( max_envelope , dp [ i ] )
    return max_envelope
if __name__ == ' _ _ main _ _ ' :
    envelopes = [ [ 4 , 3 ] , [ 5 , 3 ] , [ 5 , 6 ] , [ 1 , 2 ] ]
    print ( maxEnvelopes ( envelopes ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def FindMaxDif ( a , m ) :
    n = m // 3
    l = [ 0 ] * ( m + 5 )
    r = [ 0 ] * ( m + 5 )
    s = [ ]
    for i in range ( 1 , m + 1 ) :
        if ( i <= n ) :
            l [ i ] = a [ i - 1 ] + l [ i - 1 ]
            s . append ( a [ i - 1 ] )
        else :
            l [ i ] = l [ i - 1 ]
            s . sort ( )
            d = s [ 0 ]
            if ( a [ i - 1 ] > d ) :
                l [ i ] -= d
                l [ i ] += a [ i - 1 ]
                s . remove ( d )
                s . append ( a [ i - 1 ] )
    s . clear ( )
    for i in range ( m , 0 , - 1 ) :
        if ( i >= m - n + 1 ) :
            r [ i ] = a [ i - 1 ] + r [ i + 1 ]
            s . append ( a [ i - 1 ] )
        else :
            r [ i ] = r [ i + 1 ]
            s . sort ( )
            d = s [ - 1 ]
            if ( a [ i - 1 ] < d ) :
                r [ i ] -= d
                r [ i ] += a [ i - 1 ]
                s . remove ( d )
                s . append ( a [ i - 1 ] )
    ans = - 9e18
    for i in range ( n , m - n + 1 ) :
        ans = max ( ans , l [ i ] - r [ i + 1 ] )
    return ans
vtr = [ 3 , 1 , 4 , 1 , 5 , 9 ]
n = len ( vtr )
print ( FindMaxDif ( vtr , n ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def checkPossible ( A , B , n ) :
    values = set ( [ ] )
    for i in range ( n ) :
        values . add ( B [ i ] )
    for i in range ( n ) :
        for j in range ( n ) :
            if ( ( A [ i ] + A [ j ] ) in values ) :
                values . remove ( A [ i ] + A [ j ] )
                if ( len ( values ) == 0 ) :
                    break
    if ( len ( values ) == 0 ) :
        return " Yes "
    else :
        return " No "
if __name__ == " _ _ main _ _ " :
    N = 5
    A = [ 3 , 5 , 1 , 4 , 2 ]
    B = [ 3 , 4 , 5 , 6 , 7 ]
    print ( checkPossible ( A , B , N ) )

Index/key variables: i, j
Accumulator variables: values
Iterator variables: i, j
Python program:
import math
N = 200000
V = 500
def solve ( n , d , input1 ) :
    a = [ 0 ] * N
    cnt = [ 0 ] * ( V + 1 )
    for i in range ( n ) :
        a [ i ] = input1 [ i ]
    answer = 0
    for i in range ( d ) :
        cnt [ a [ i ] ] += 1
    for i in range ( d , n ) :
        acc = 0
        low_median = - 1
        high_median = - 1
        for v in range ( V + 1 ) :
            acc += cnt [ v ]
            if ( low_median == - 1 and acc >= int ( math . floor ( ( d + 1 ) / 2.0 ) ) ) :
                low_median = v
            if ( high_median == - 1 and acc >= int ( math . ceil ( ( d + 1 ) / 2.0 ) ) ) :
                high_median = v
        double_median = low_median + high_median
        if ( a [ i ] >= double_median ) :
            answer += 1
        cnt [ a [ i - d ] ] -= 1
        cnt [ a [ i ] ] += 1
    print ( answer )
if __name__ == " _ _ main _ _ " :
    input1 = [ 1 , 2 , 2 , 4 , 5 ]
    n = len ( input1 )
    k = 3
    solve ( n , k , input1 )

Index/key variables: i, v
Accumulator variables: acc, answer
Iterator variables: i, v
Python program:
import sys
def findMinSoln ( n , k ) :
    minSoln = sys . maxsize ;
    for i in range ( 1 , k ) :
        if ( n % i == 0 ) :
            minSoln = min ( minSoln , ( n // i ) * k + i ) ;
    return minSoln ;
if __name__ == ' _ _ main _ _ ' :
    n = 4 ;
    k = 6 ;
    print ( findMinSoln ( n , k ) ) ;

Iterator variables: i