dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
INF = 1e9
def findMinHike ( arr , n ) :
    arr . insert ( 0 , INF )
    arr . append ( INF )
    hike = [ 0 ] * ( n + 2 )
    for i in range ( 1 , n + 1 ) :
        if ( arr [ i - 1 ] >= arr [ i ] and arr [ i ] <= arr [ i + 1 ] ) :
            hike [ i ] = 1
    for i in range ( 1 , n + 1 ) :
        if ( arr [ i - 1 ] < arr [ i ] and arr [ i ] <= arr [ i + 1 ] ) :
            hike [ i ] = hike [ i - 1 ] + 1
    for i in range ( 1 , n + 1 ) :
        if ( arr [ i - 1 ] >= arr [ i ] and arr [ i ] > arr [ i + 1 ] ) :
            hike [ i ] = hike [ i + 1 ] + 1
    for i in range ( 1 , n + 1 ) :
        if ( arr [ i - 1 ] < arr [ i ] and arr [ i ] > arr [ i + 1 ] ) :
            hike [ i ] = max ( hike [ i - 1 ] , hike [ i + 1 ] ) + 1
    for i in range ( 1 , n + 1 ) :
        print ( hike [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 3 , 4 , 2 , 1 , 6 ]
    findMinHike ( arr , len ( arr ) )

Index/key variables: i
Iterator variables: i
Python program:
def minimumCost ( arr , cost , N ) :
    dp = [ [ 0 for i in range ( 3 ) ] for i in range ( N ) ]
    dp [ 0 ] [ 0 ] = 0
    dp [ 0 ] [ 1 ] = cost [ 0 ]
    dp [ 0 ] [ 2 ] = cost [ 0 ] * 2
    for i in range ( 1 , N ) :
        for j in range ( 3 ) :
            minimum = 1e6
            if ( j + arr [ i ] != arr [ i - 1 ] ) :
                minimum = min ( minimum , dp [ i - 1 ] [ 0 ] )
            if ( j + arr [ i ] != arr [ i - 1 ] + 1 ) :
                minimum = min ( minimum , dp [ i - 1 ] [ 1 ] )
            if ( j + arr [ i ] != arr [ i - 1 ] + 2 ) :
                minimum = min ( minimum , dp [ i - 1 ] [ 2 ] )
            dp [ i ] [ j ] = j * cost [ i ] + minimum
    ans = 1e6
    for i in range ( 3 ) :
        ans = min ( ans , dp [ N - 1 ] [ i ] )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 2 , 3 , 4 ]
    cost = [ 3 , 2 , 5 , 4 , 2 , 1 ]
    N = len ( arr )
    minimumCost ( arr , cost , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maximumSumSubarray ( arr , n ) :
    mp = { }
    for i in range ( n ) :
        if ( arr [ i ] >= 0 and arr [ i ] not in mp ) :
            mp [ arr [ i ] ] = 1
    first = 0
    last = 0
    ans = 0
    INF = 1e6
    for i in mp :
        mx = i
        curr = 0
        for j in range ( n ) :
            if ( curr == 0 ) :
                curr_start = j
            if arr [ j ] > mx :
                val = - INF
            else :
                val = arr [ j ] ;
            curr += val
            if ( curr < 0 ) :
                curr = 0
            if ( curr > ans ) :
                ans = curr
                first = curr_start
                last = j
    print ( first + 1 , last + 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , - 2 , 10 , - 1 , 4 ]
    size = len ( arr )
    maximumSumSubarray ( arr , size )

Index/key variables: i, j
Accumulator variables: curr
Iterator variables: i, j
Python program:
def make_xor_half ( arr ) :
    sum = 0 ; xr = 0 ;
    for a in arr :
        sum += a ;
        xr ^= a ;
    if ( 2 * xr == sum ) :
        return - 1 ;
    if ( xr == 0 ) :
        arr . append ( sum ) ;
        return 1 ;
    arr . append ( xr ) ;
    arr . append ( sum + xr ) ;
    return 2 ;
if __name__ == " _ _ main _ _ " :
    N = 7 ;
    nums = [ 3 , 4 , 7 , 1 , 2 , 5 , 6 ] ;
    count = make_xor_half ( nums ) ;
    if ( count == - 1 ) :
        print ( " - 1" ) ;
    elif ( count == 1 ) :
        print ( nums [ N ] ) ;
    else :
        print ( nums [ N ] , nums [ N + 1 ] ) ;

Index/key variables: N
Accumulator variables: sum, xr
Iterator variables: a
Python program:
def count_triangles ( a , b , c , d ) :
    ans = 0
    for x in range ( a , b + 1 ) :
        num_greater_than_d = ( max ( d , c + x ) - max ( d , b + x - 1 ) )
        ans = ( ans + num_greater_than_d * ( d - c + 1 ) )
        r = min ( max ( c , c + x ) , d ) - c ;
        l = min ( max ( c , b + x - 1 ) , d ) - c ;
        x1 = int ( ( r * ( r + 1 ) ) / 2 )
        x2 = int ( ( l * ( l + 1 ) ) / 2 )
        ans = ans + ( x1 - x2 )
    return ans
a = 2
b = 3
c = 4
d = 5
print ( count_triangles ( a , b , c , d ) , end =   ' ' )

Iterator variables: x
Python program:
def minFlip ( s , n , k , a , p ) :
    allowed = [ 0 ] * 26
    for i in range ( p ) :
        allowed [ ord ( a [ i ] ) - ord ( ' a ' ) ] = True
    freq = [ [ 0 for x in range ( 26 ) ] for y in range ( k ) ]
    for i in range ( k ) :
        for j in range ( 26 ) :
            freq [ i ] [ j ] = 0
    for i in range ( n ) :
        freq [ i % k ] [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    ans = 0
    totalpositions = n // k
    for i in range ( k ) :
        maxfrequency = 0
        for j in range ( 26 ) :
            if ( freq [ i ] [ j ] > maxfrequency and allowed [ j ] == True ) :
                maxfrequency = freq [ i ] [ j ]
        ans += ( totalpositions - maxfrequency )
        if ( i % k < n % k ) :
            ans += 1
    print ( ans )
if __name__ == " _ _ main _ _ " :
    S = " nihsiakyt "
    n = len ( S )
    K = 3
    A = [ ' n ' , ' i ' , ' p ' , ' s ' , ' q ' ]
    p = len ( A )
    minFlip ( S , n , K , A , p )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def colorRequired ( arr , n ) :
    all_same = True
    one_adjacent_same = False
    for i in range ( n - 1 ) :
        if ( arr [ i ] != arr [ i + 1 ] ) :
            all_same = False
        if ( arr [ i ] == arr [ i + 1 ] ) :
            one_adjacent_same = True
    if ( all_same == True ) :
        print ( 1 )
        return
    if ( n % 2 == 0 or one_adjacent_same == True ) :
        print ( 2 )
        return
    print ( 3 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 1 , 2 ]
    n = len ( arr )
    colorRequired ( arr , n )

Index/key variables: i
Iterator variables: i
Boolean variables: all_same, one_adjacent_same
Python program:
def maxRemainingSum ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    i = 0
    j = n - 1
    result = 0
    while ( i < j ) :
        if ( arr [ i ] < arr [ j ] ) :
            sum -= arr [ i ]
            i += 1
        else :
            sum -= arr [ j ]
            j -= 1
        result += sum ;
    return result
arr = [ 3 , 1 , 7 , 2 , 1 ]
N = len ( arr )
print ( maxRemainingSum ( arr , N ) )

Index/key variables: i, j
Accumulator variables: result, sum
Iterator variables: i
Python program:
def printKParts ( N , K ) :
    if ( N % K == 0 ) :
        for i in range ( 1 , K ) :
            print ( "1 , ▁ " ) ;
        print ( N - ( K - 1 ) , end = " " ) ;
    else :
        if ( K == 2 ) :
            print ( " Not ▁ Possible " , end = " " ) ;
            return ;
    for i in range ( 1 , K - 1 ) :
        print ( 1 , end = " , ▁ " ) ;
    print ( 2 , " , ▁ " , ( N - K ) , end = " " ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 18 ;
    K = 5 ;
    printKParts ( N , K ) ;

Iterator variables: i
Python program:
def assignIntervals ( interval , n ) :
    for i in range ( n ) :
        interval [ i ] . append ( i )
    interval . sort ( key = lambda x : x [ 0 ] )
    firstEndTime = - 1
    secondEndTime = - 1
    fin = ' '
    flag = False
    for i in range ( n ) :
        if interval [ i ] [ 0 ] >= firstEndTime :
            firstEndTime = interval [ i ] [ 1 ]
            interval [ i ] . append ( ' S ' )
        elif interval [ i ] [ 0 ] >= secondEndTime :
            secondEndTime = interval [ i ] [ 1 ]
            interval [ i ] . append ( ' F ' )
        else :
            flag = True
            break
    if flag :
        print ( - 1 )
    else :
        form = [ ' ' ] * n
        for i in range ( n ) :
            indi = interval [ i ] [ 2 ]
            form [ indi ] = interval [ i ] [ 3 ]
        print ( form , " , ▁ " )
if __name__ == " _ _ main _ _ " :
    intervals = [ [ 360 , 480 ] , [ 420 , 540 ] , [ 600 , 660 ] ]
    assignIntervals ( intervals , len ( intervals ) )

Index/key variables: i, indi
Iterator variables: i
Boolean variables: flag
Python program:
from queue import LifoQueue
def minOperations ( s , len ) :
    operationCnt = 0 ;
    st = LifoQueue ( ) ;
    cntClosing = 0 ;
    for i in range ( 0 , len ) :
        if ( s [ i ] == ' { ' ) :
            if ( cntClosing > 0 ) :
                operationCnt += 1 ;
                st . pop ( ) ;
            st . put ( s [ i ] ) ;
            cntClosing = 0 ;
        elif ( st . empty ( ) ) :
            st . put ( ' { ' ) ;
            operationCnt += 1 ;
            cntClosing = 1 ;
        else :
            cntClosing = ( cntClosing + 1 ) % 2 ;
            if ( cntClosing == 0 ) :
                st . pop ( ) ;
    operationCnt += st . qsize ( ) * 2 - cntClosing + 1 ;
    return operationCnt ;
if __name__ == ' _ _ main _ _ ' :
    str = " { " ;
    print ( minOperations ( str , 1 ) ) ;

Index/key variables: i
Accumulator variables: operationCnt
Iterator variables: i
Python program:
def longestSubsequence ( s ) :
    n = len ( s ) ;
    answer = 0 ;
    prev = ' - ' ;
    for i in range ( 0 , n ) :
        if ( prev != s [ i ] ) :
            prev = s [ i ] ;
            answer += 1 ;
    return answer ;
str = " ababa " ;
print ( longestSubsequence ( str ) ) ;

Index/key variables: i
Accumulator variables: answer
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if b == 0 :
        return a
    return gcd ( b , a % b )
def maxGcdSubarray ( arr , n ) :
    if n == 1 :
        return 0
    k = 1
    for i in range ( 1 , n ) :
        k = max ( k , gcd ( arr [ i ] , arr [ i - 1 ] ) )
    cnt = 0
    maxLength = 0
    for i in range ( n ) :
        if arr [ i ] % k == 0 :
            cnt += 1
        else :
            maxLength = max ( maxLength , cnt )
            cnt = 0
    maxLength = max ( maxLength , cnt )
    return maxLength
arr = [ 18 , 3 , 6 , 9 ]
n = len ( arr )
print ( maxGcdSubarray ( arr , n ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def MinDiff ( n ) :
    val = 2 ** n
    sep = n // 2
    grp1 = 0
    grp2 = 0
    grp1 = grp1 + val
    for i in range ( 1 , sep ) :
        grp1 = grp1 + 2 ** i
    for i in range ( sep , n ) :
        grp2 = grp2 + 2 ** i
    print ( abs ( grp1 - grp2 ) )
if __name__ == ' _ _ main _ _ ' :
    n = 4
    MinDiff ( n )

Iterator variables: i
Python program:
def countDist ( arr1 , n , arr2 , m , k ) :
    count = 0
    smallest = arr2 [ 0 ]
    largest = arr2 [ 0 ]
    for i in range ( m ) :
        smallest = max ( smallest , arr2 [ i ] )
        largest = min ( largest , arr1 [ i ] )
    for i in range ( n ) :
        if ( abs ( arr1 [ i ] - smallest ) > k or abs ( arr1 [ i ] - largest ) > k ) :
            count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 3 , 1 , 4 ]
    n = len ( arr1 )
    arr2 = [ 5 , 1 , 2 ]
    m = len ( arr2 )
    k = 2
    countDist ( arr1 , n , arr2 , m , k )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def maxNormalSubstring ( P , Q , K , N ) :
    if ( K == 0 ) :
        return 0
    count = 0
    left = 0
    right = 0
    ans = 0
    while ( right < N ) :
        while ( right < N and count <= K ) :
            if ( P [ right ] in Q ) :
                if ( count + 1 > K ) :
                    break
                else :
                    count += 1
            right += 1
            if ( count <= K ) :
                ans = max ( ans , right - left )
        while ( left < right ) :
            left += 1
            if ( P [ left - 1 ] in Q ) :
                count -= 1
            if ( count < K ) :
                break
    return ans
P = " giraffe "
Q = { chr }
Q . add ( ' a ' )
Q . add ( ' f ' )
Q . add ( ' g ' )
Q . add ( ' r ' )
K = 2
N = len ( P )
print ( maxNormalSubstring ( P , Q , K , N ) )

Index/key variables: right
Accumulator variables: count, left
Python program:
def countOfSubstrings ( s ) :
    n = len ( s )
    prefix_sum = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        if ( s [ i ] == '1' ) :
            prefix_sum [ i ] = 1
    for i in range ( 1 , n , 1 ) :
        prefix_sum [ i ] += prefix_sum [ i - 1 ]
    answer = 0
    for i in range ( n ) :
        for j in range ( i , n , 1 ) :
            if ( i - 1 >= 0 ) :
                countOfOnes = prefix_sum [ j ] - prefix_sum [ i - 1 ]
            else :
                countOfOnes = prefix_sum [ j ]
            length = j - i + 1
            if ( countOfOnes > 0 and length % countOfOnes == 0 ) :
                answer += 1
    return answer
if __name__ == ' _ _ main _ _ ' :
    S = "1111100000"
    print ( countOfSubstrings ( S ) )

Index/key variables: i, j
Accumulator variables: answer
Iterator variables: i, j
Python program:
def count_element ( N , K , arr ) :
    mp = dict ( )
    for i in range ( N ) :
        mp [ arr [ i ] ] = mp . get ( arr [ i ] , 0 ) + 1
    answer = 0
    for i in mp :
        if i + K in mp :
            answer += mp [ i ]
    return answer
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 2 , 8 , 7 , 6 , 5 , 9 ]
    N = len ( arr )
    K = 2
    print ( count_element ( N , K , arr ) )

Index/key variables: i
Accumulator variables: answer
Iterator variables: i
Python program:
def digit_xor ( x ) :
    xorr = 0
    while ( x != 0 ) :
        xorr ^= x % 10
        x = x // 10
    return xorr
def find_count ( n ) :
    mpp = { }
    for i in range ( 1 , n + 1 ) :
        if digit_xor ( i ) in mpp :
            mpp [ digit_xor ( i ) ] += 1
        else :
            mpp [ digit_xor ( i ) ] = 1
    maxm = 0
    for x in mpp :
        if ( mpp [ x ] > maxm ) :
            maxm = mpp [ x ]
    return maxm
N = 13
print ( find_count ( N ) )

Index/key variables: x
Accumulator variables: xorr
Iterator variables: i, x
Python program:
def digit_prod ( x ) :
    prod = 1
    while ( x ) :
        prod = prod * ( x % 10 )
        x = x // 10
    return prod
def find_count ( n ) :
    mpp = { }
    for i in range ( 1 , n + 1 ) :
        x = digit_prod ( i )
        if x in mpp :
            mpp [ x ] += 1
        else :
            mpp [ x ] = 1
    ans = 1
    maxm = 0
    for value in mpp . values ( ) :
        if ( value > maxm ) :
            maxm = value
            ans = 1
        elif ( value == maxm ) :
            ans = ans + 1
    return ans
N = 13
print ( find_count ( N ) )

Index/key variables: x
Iterator variables: i, value
Python program:
from math import sqrt
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return True
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return False
    for i in range ( 5 , int ( sqrt ( n ) ) + 1 , 6 ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
    return True
def findSubarraySum ( arr , n , K ) :
    prevSum = { i : 0 for i in range ( 100 ) }
    res = 0
    currsum = 0
    for i in range ( n ) :
        currsum += arr [ i ]
        if ( currsum == K ) :
            res += 1
        if ( currsum - K ) in prevSum :
            res += ( prevSum [ currsum - K ] )
        prevSum [ currsum ] += 1
    return res
def countSubarray ( arr , n , K ) :
    for i in range ( n ) :
        if ( isPrime ( arr [ i ] ) ) :
            arr [ i ] = 1
        else :
            arr [ i ] = 0
    print ( findSubarraySum ( arr , n , K ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ]
    K = 2
    N = len ( arr )
    countSubarray ( arr , N , K )

Index/key variables: currsum, i
Accumulator variables: res
Iterator variables: i
Python program:
def find_maxm ( arr , n ) :
    mpp = { }
    for i in range ( 0 , n ) :
        if arr [ i ] in mpp :
            mpp [ arr [ i ] ] = mpp [ arr [ i ] ] + 1
        else :
            mpp [ arr [ i ] ] = 1
    ans = 0
    for key in mpp :
        value = key
        freq = mpp [ key ]
        if value == freq :
            ans = ans + 1
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 2 , 2 , 3 , 4 , 3 ]
    n = len ( arr )
    print ( find_maxm ( arr , n ) )

Index/key variables: i, key
Iterator variables: i, key
Python program:
def pow ( x , y ) :
    if ( y == 1 ) :
        return x
    if ( y == 0 ) :
        return 1
    temp = pow ( x , y // 2 )
    temp *= temp
    if ( y & 1 ) :
        temp *= x
    return temp
def noOfPermutations ( a , n ) :
    if ( n == 1 ) :
        return 1
    a . sort ( )
    if ( a [ n - 1 ] == a [ n - 2 ] ) :
        return 0
    x = 0
    for i in range ( n - 2 ) :
        if ( a [ i ] == a [ i + 1 ] ) :
            if ( a [ i ] == a [ i + 2 ] ) :
                return 0
            x += 1
            i += 1
    return pow ( 2 , n - 2 * x - 1 )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 2 , 3 , 4 ]
    n = len ( a )
    num = noOfPermutations ( a , n )
    print ( num )

Index/key variables: i
Accumulator variables: x
Iterator variables: i
Python program:
def GetMinSubarrayLength ( a , n ) :
    ans = max ( a [ 0 ] , a [ n - 1 ] )
    lo = 0
    hi = n - 1
    while ( lo < n and a [ lo ] % ans == 0 ) :
        lo += 1
    while ( hi > lo and a [ hi ] % ans == 0 ) :
        hi -= 1
    return ( hi - lo + 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 8 , 2 , 1 , 4 ]
    N = len ( arr )
    length = GetMinSubarrayLength ( arr , N )
    print ( length )

Index/key variables: hi, lo
Python program:
def countPairs ( arr , N ) :
    M = dict . fromkeys ( arr , 0 ) ;
    for i in range ( N ) :
        M [ arr [ i ] ] += 1 ;
    maxFreq = 0 ;
    for it in M . values ( ) :
        maxFreq = max ( maxFreq , it ) ;
    print ( N - maxFreq ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 8 , 5 , 9 , 8 , 8 , 7 , 7 , 5 , 7 , 7 ] ;
    N = len ( arr ) ;
    countPairs ( arr , N ) ;

Index/key variables: i
Iterator variables: i, it
Python program:
def minimumValue ( arr , n , k ) :
    arr . sort ( ) ;
    answer = 0 ;
    for i in range ( k ) :
        answer += arr [ i ] * arr [ i ] ;
    return answer * ( 2 * k - 2 ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 21 , 5 , 3 , 8 ] ;
    k = 3 ;
    n = len ( arr ) ;
    print ( minimumValue ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: answer
Iterator variables: i
Python program:
import sys ;
min_val = sys . maxsize ;
min_steps = 0 ;
def sumOfDigits ( n ) :
    s = str ( n ) ;
    sum = 0 ;
    for i in range ( len ( s ) ) :
        sum += ( ord ( s [ i ] ) - ord ( '0' ) ) ;
    return sum ;
def Transform ( n , d , steps ) :
    global min_val ; global min_steps ;
    if ( n < min_val ) :
        min_val = n ;
        min_steps = steps ;
    elif ( n == min_val ) :
        min_steps = min ( min_steps , steps ) ;
    if ( steps < 15 ) :
        Transform ( sumOfDigits ( n ) , d , steps + 1 ) ;
        Transform ( n + d , d , steps + 1 ) ;
if __name__ == " _ _ main _ _ " :
    N = 9 ; D = 3 ;
    Transform ( N , D , 0 ) ;
    print ( min_val , min_steps ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def noOfMoves ( arr , n ) :
    cnt = 0
    maxCnt = 0
    for i in range ( n ) :
        if ( arr [ i ] == 1 ) :
            cnt += 1
        else :
            if ( cnt != 0 ) :
                maxCnt = max ( maxCnt , cnt )
                cnt = 0
    print ( maxCnt )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 ]
    N = len ( arr )
    noOfMoves ( arr , N )
    arr1 = [ 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 ]
    N = len ( arr1 )
    noOfMoves ( arr1 , N )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def knowPair ( a , b , n , s , m ) :
    i = 0
    rem = 0
    count_b = 0
    flag = 0
    while ( i <= a ) :
        rem = s - ( n * i )
        count_b = rem // m
        if ( rem % m == 0 and count_b <= b ) :
            flag = 1
        i += 1
    if ( flag == 1 ) :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == ' _ _ main _ _ ' :
    A = 1
    B = 2
    n = 3
    S = 4
    m = 2
    knowPair ( A , B , n , S , m )

Accumulator variables: i
Python program:
def sumDivisibles ( A , B , M ) :
    sum = 0
    for i in range ( A , B + 1 ) :
        if ( i % M == 0 ) :
            sum += i
    return sum
if __name__ == " _ _ main _ _ " :
    A = 6
    B = 15
    M = 3
    print ( sumDivisibles ( A , B , M ) )

Accumulator variables: sum
Iterator variables: i
Python program:
def distinctSubstring ( P , N ) :
    S = dict ( )
    for i in range ( N ) :
        freq = [ False ] * 26
        s = " "
        for j in range ( i , N ) :
            pos = ord ( P [ j ] ) - ord ( ' a ' )
            if ( freq [ pos ] == True ) :
                break
            freq [ pos ] = True
            s += P [ j ]
            S [ s ] = 1
    return len ( S )
S = " abba "
N = len ( S )
print ( distinctSubstring ( S , N ) )

Index/key variables: j, pos, s
Iterator variables: i, j
Python program:
def calcSum ( arr , n , k ) :
    for i in range ( n - k + 1 ) :
        sum = 0
        for j in range ( i , k + i ) :
            sum += arr [ j ]
        print ( sum , end = " ▁ " )
arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
n = len ( arr )
k = 3
calcSum ( arr , n , k )

Index/key variables: j
Accumulator variables: sum
Iterator variables: i, j
Python program:
def calcSum ( arr , n , k ) :
    sum = 0
    for i in range ( k ) :
        sum += arr [ i ]
    print ( sum , end = " ▁ " )
    for i in range ( k , n ) :
        sum = ( sum - arr [ i - k ] ) + arr [ i ]
        print ( sum , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    n = len ( arr )
    k = 3
    calcSum ( arr , n , k )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import bisect
def getPairs ( A , B , n ) :
    D = [ 0 ] * ( n )
    for i in range ( n ) :
        D [ i ] = A [ i ] - B [ i ]
    D . sort ( )
    total = 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( D [ i ] > 0 ) :
            total += n - i - 1
        else :
            k = bisect . bisect_right ( D , - D [ i ] , 0 , len ( D ) )
            total += n - k
    return total
if __name__ == " _ _ main _ _ " :
    n = 5
    A = [ ]
    B = [ ]
    A . append ( 4 ) ;
    A . append ( 8 ) ;
    A . append ( 2 ) ;
    A . append ( 6 ) ;
    A . append ( 2 ) ;
    B . append ( 4 ) ;
    B . append ( 5 ) ;
    B . append ( 4 ) ;
    B . append ( 1 ) ;
    B . append ( 3 ) ;
    print ( getPairs ( A , B , n ) )

Index/key variables: i
Accumulator variables: total
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( a == 0 ) :
        return b ;
    return gcd ( b % a , a ) ;
def lcm ( a , b ) :
    return ( a * b ) / gcd ( a , b ) ;
def countPairs ( arr , n ) :
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( lcm ( arr [ i ] , arr [ j ] ) == gcd ( arr [ i ] , arr [ j ] ) ) :
                ans += 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 1 ] ;
    n = len ( arr ) ;
    print ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
from collections import defaultdict
def countPairs ( a , n ) :
    frequency = defaultdict ( int )
    for i in range ( n ) :
        frequency [ a [ i ] ] += 1
    count = 0
    for x in frequency . keys ( ) :
        f = frequency [ x ]
        count += f * ( f - 1 ) // 2
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 1 ]
    n = len ( arr )
    print ( countPairs ( arr , n ) )

Index/key variables: i, x
Accumulator variables: count
Iterator variables: i, x
Python program:
def maxValue ( arr , n , moves ) :
    for i in range ( n - 2 , - 1 , - 1 ) :
        if ( arr [ i ] > 0 ) :
            distance = n - 1 - i
            if ( moves < distance ) :
                break
            can_take = moves // distance
            take = min ( arr [ i ] , can_take )
            arr [ n - 1 ] += take
            moves -= take * distance
    return arr [ n - 1 ]
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 0 , 1 ]
    M = 5
    N = len ( arr )
    print ( maxValue ( arr , N , M ) )

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