dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countTriplets ( arr , N ) :
    zero_i = [ ]
    one_i = [ ]
    mp = { }
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            zero_i . append ( i + 1 )
        elif ( arr [ i ] == 1 ) :
            one_i . append ( i + 1 )
        else :
            mp [ i + 1 ] = 1
    total = len ( zero_i ) * len ( one_i ) * len ( mp )
    for i in range ( len ( zero_i ) ) :
        for j in range ( len ( one_i ) ) :
            p = zero_i [ i ]
            q = one_i [ j ]
            r = 2 * p - q
            if ( r in mp ) :
                total -= 1
            r = 2 * q - p
            if ( r in mp ) :
                total -= 1
            r = ( p + q ) // 2
            if ( ( r in mp ) and abs ( r - p ) == abs ( r - q ) ) :
                total -= 1
    print ( total )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , 1 , 2 , 1 ]
    N = len ( arr )
    countTriplets ( arr , N )

Index/key variables: i, j
Accumulator variables: one_i, total, zero_i
Iterator variables: i, j
Python program:
def PrimeFactors ( N ) :
    st = [ ]
    i = 2
    while ( N != 1 ) :
        if ( N % i == 0 ) :
            st . append ( i )
            while ( N % i == 0 ) :
                N = N // i
        i += 1
    while ( len ( st ) != 0 ) :
        print ( st [ - 1 ] )
        st . pop ( )
if __name__ == " _ _ main _ _ " :
    N = 8
    PrimeFactors ( N )

Accumulator variables: i, st
Python program:
def CountSubarray ( arr , n , k ) :
    temp = k
    count = 0
    for i in range ( n ) :
        if ( arr [ i ] == temp ) :
            if ( temp == 1 ) :
                count += 1
                temp = k
            else :
                temp -= 1
        else :
            temp = k
            if ( arr [ i ] == k ) :
                i -= 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 7 , 9 , 3 , 2 , 1 , 8 , 3 , 2 , 1 ]
    N = len ( arr )
    K = 3
    print ( CountSubarray ( arr , N , K ) )

Index/key variables: i
Accumulator variables: count, temp
Iterator variables: i
Python program:
import math
def LCM ( A , B ) :
    return ( A * B // math . gcd ( A , B ) )
def findSmallestNumber ( X ) :
    lcm = 1
    temp = X
    while ( temp ) :
        last = temp % 10
        temp //= 10
        if ( not last ) :
            continue
        lcm = LCM ( lcm , last )
    answer = ( ( X + lcm - 1 ) // lcm ) * lcm
    print ( answer )
if __name__ == " _ _ main _ _ " :
    X = 280
    findSmallestNumber ( X )

Accumulator variables: temp
Python program:
INF = 1000000
pref = [ 0 for i in range ( 500005 ) ]
suf = [ 0 for i in range ( 500005 ) ]
MAX = [ 0 for i in range ( 500005 ) ]
def build ( a , tl , tr , v ) :
    global MAX
    global pref
    global suf
    if ( tl == tr ) :
        MAX [ v ] = a [ tl ]
        pref [ v ] = a [ tl ]
        suf [ v ] = a [ tl ]
    else :
        tm = ( tl + tr ) // 2
        build ( a , tl , tm , v * 2 )
        build ( a , tm + 1 , tr , v * 2 + 1 )
        MAX [ v ] = max ( MAX [ v * 2 ] , max ( MAX [ v * 2 + 1 ] , suf [ v * 2 ] + pref [ v * 2 + 1 ] ) )
        pref [ v ] = max ( pref [ v * 2 ] , pref [ 2 * v ] + ( pref [ 2 * v ] == tm - tl + 1 ) * pref [ v * 2 + 1 ] )
        suf [ v ] = max ( suf [ v * 2 + 1 ] , suf [ 2 * v + 1 ] + suf [ v * 2 ] * ( suf [ 2 * v + 1 ] == tr - tm ) )
def update ( a , pos , tl , tr , v ) :
    global pref
    global suf
    global MAX
    if ( tl > pos or tr < pos ) :
        return
    if ( tl == tr and tl == pos ) :
        MAX [ v ] = a [ pos ]
        pref [ v ] = a [ pos ]
        suf [ v ] = a [ pos ]
    else :
        tm = ( tl + tr ) // 2
        update ( a , pos , tl , tm , v * 2 )
        update ( a , pos , tm + 1 , tr , v * 2 + 1 )
        MAX [ v ] = max ( MAX [ v * 2 ] , max ( MAX [ v * 2 + 1 ] , suf [ v * 2 ] + pref [ v * 2 + 1 ] ) )
        pref [ v ] = max ( pref [ v * 2 ] , pref [ 2 * v ] + ( pref [ 2 * v ] == tm - tl + 1 ) * pref [ v * 2 + 1 ] )
        suf [ v ] = max ( suf [ v * 2 + 1 ] , suf [ 2 * v + 1 ] + ( suf [ 2 * v + 1 ] == tr - tm ) * suf [ v * 2 ] )
def solveQueries ( arr , n , Q , k ) :
    global MAX
    cntQuery = len ( Q )
    build ( arr , 0 , n - 1 , 1 )
    for i in range ( cntQuery ) :
        if ( Q [ i ] [ 0 ] == 1 ) :
            print ( MAX [ 1 ] , end = " ▁ " )
        else :
            arr [ Q [ i ] [ 1 ] - 1 ] ^= 1
            update ( arr , Q [ i ] [ 1 ] - 1 , 0 , n - 1 , 1 )
if __name__ == ' _ _ main _ _ ' :
    N = 10
    arr = [ 1 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 ]
    Q = [ [ 1 ] , [ 2 , 3 ] , [ 1 ] ]
    K = 3
    solveQueries ( arr , N , Q , K )

Index/key variables: i, pos, tl, v
Iterator variables: i
Python program:
def countFreq ( N , K ) :
    count = 0
    while ( N > 0 ) :
        if ( N % 10 == K ) :
            count += 1
        N = N // 10
    return count
def findElementUtil ( arr , N , K ) :
    c = 0
    max = 0
    ele = 0
    for i in range ( N ) :
        c = countFreq ( arr [ i ] , K )
        if ( c > max ) :
            max = c
            ele = arr [ i ]
    if ( max == 0 ) :
        return - 1
    else :
        return ele
def findElement ( arr , N , K ) :
    ele = findElementUtil ( arr , N , K )
    if ( ele == - 1 ) :
        print ( " - 1" , end = " " )
    else :
        print ( ele )
if __name__ == ' _ _ main _ _ ' :
    K = 3
    arr = [ 3 , 77 , 343 , 456 ]
    N = len ( arr )
    findElement ( arr , K , N )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findMinDeletions ( v , n ) :
    minDel = 10 ** 18
    for i in range ( n ) :
        L = v [ i ] [ 0 ]
        R = v [ i ] [ 1 ]
        Count = 0
        for j in range ( n ) :
            if ( v [ j ] [ 1 ] >= L and v [ j ] [ 0 ] <= R ) :
                Count += 1
        minDel = min ( minDel , n - Count )
    return minDel
if __name__ == ' _ _ main _ _ ' :
    v = [ ]
    v . append ( [ 1 , 3 ] )
    v . append ( [ 4 , 12 ] )
    v . append ( [ 5 , 8 ] )
    v . append ( [ 13 , 2 ] )
    N = len ( v )
    print ( findMinDeletions ( v , N ) )

Index/key variables: i, j
Accumulator variables: Count
Iterator variables: i, j
Python program:
def maxEvenIntegers ( arr , N , M ) :
    curr = 0
    for i in range ( 0 , M ) :
        if ( arr [ i ] % 2 == 0 ) :
            curr += 1
    ans = curr
    for i in range ( M , N ) :
        if ( arr [ i - M ] % 2 == 0 ) :
            curr -= 1
        if ( arr [ i ] % 2 == 0 ) :
            curr += 1
            ans = max ( curr , ans )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 5 , 4 , 7 , 6 ]
    M = 3
    N = len ( arr )
    print ( maxEvenIntegers ( arr , N , M ) )

Index/key variables: i
Accumulator variables: curr
Iterator variables: i
Python program:
def countNumbers ( n , d ) :
    total = 0
    for i in range ( 1 , n + 1 ) :
        x = i
        while ( x > 0 ) :
            if ( x % 8 == d ) :
                total += 1
                break
            x = x // 8
    print ( total )
if __name__ == ' _ _ main _ _ ' :
    n , d = 20 , 7
    countNumbers ( n , d )

Accumulator variables: total
Iterator variables: i
Python program:
import sys
def build ( tree , A , start , end , node ) :
    if ( start == end ) :
        tree [ node ] = A [ start ]
        return tree [ node ]
    mid = ( int ) ( ( start + end ) / 2 )
    X = build ( tree , A , start , mid , 2 * node + 1 )
    Y = build ( tree , A , mid + 1 , end , 2 * node + 2 )
    return ( tree [ node ] == min ( X , Y ) )
def query ( tree , start , end , l , r , node ) :
    if ( start > r or end < l ) :
        return sys . maxsize
    if ( start >= l and end <= r ) :
        return tree [ node ]
    mid = ( int ) ( ( start + end ) / 2 )
    X = query ( tree , start , mid , l , r , 2 * node + 1 )
    Y = query ( tree , mid + 1 , end , l , r , 2 * node + 2 )
    return min ( X , Y )
def longestSubArray ( A , N , K ) :
    res = 1
    preSum = [ 0 ] * ( N + 1 )
    preSum [ 0 ] = A [ 0 ]
    for i in range ( N ) :
        preSum [ i + 1 ] = preSum [ i ] + A [ i ]
    tree = [ 0 ] * ( 4 * N + 5 )
    build ( tree , A , 0 , N - 1 , 0 )
    for i in range ( N ) :
        start = i
        end = N - 1
        max_index = i
        while ( start <= end ) :
            mid = ( int ) ( ( start + end ) / 2 )
            min_element = query ( tree , 0 , N - 1 , i , mid , 0 )
            expected_sum = ( mid - i + 1 ) * min_element
            actual_sum = preSum [ mid + 1 ] - preSum [ i ]
            if ( actual_sum - expected_sum <= K ) :
                start = mid + 1
                max_index = max ( max_index , mid )
            else :
                end = mid - 1
        res = max ( res , max_index - i + 2 )
    return res
arr = [ 1 , 7 , 3 , 4 , 5 , 6 ]
k = 6
n = 6
print ( longestSubArray ( arr , n , k ) )

Index/key variables: i, node, start
Iterator variables: i
Python program:
def findCntTriplet ( N ) :
    cntTriplet = 0 ;
    for i in range ( 1 , N ) :
        if ( N % i != 0 ) :
            cntTriplet += N // i ;
        else :
            cntTriplet += ( N // i ) - 1 ;
    return cntTriplet ;
if __name__ == ' _ _ main _ _ ' :
    N = 3 ;
    print ( findCntTriplet ( N ) ) ;

Accumulator variables: cntTriplet
Iterator variables: i
Python program:
from math import floor , sqrt
def countDivisors ( n ) :
    count = 0
    divisor = [ ]
    for i in range ( 2 , floor ( sqrt ( n ) ) ) :
        if ( n % i == 0 ) :
            if ( n // i == i ) :
                divisor . append ( i )
            else :
                divisor . append ( i )
                divisor . append ( n // i )
    divisor . append ( n )
    for x in divisor :
        x -= 1
        if ( ( n // x ) == ( n % x ) ) :
            count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    N = 1000000000000
    countDivisors ( N )

Accumulator variables: count, divisor
Iterator variables: i, x
Python program:
def smallestIndexArrayElementsFlip ( arr , N ) :
    pos = - 1
    for i in range ( N ) :
        arr [ i ] *= - 1
        sum = 0
        for j in range ( N ) :
            sum += arr [ j ]
        if ( sum == 0 ) :
            pos = i
            break
        else :
            arr [ i ] *= - 1
    return pos
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , - 5 , 3 , 4 ]
    N = len ( arr )
    print ( smallestIndexArrayElementsFlip ( arr , N ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
def smallestIndexArrayElementsFlip ( arr , N ) :
    pos = - 1
    ArrSum = 0
    for i in range ( N ) :
        ArrSum += arr [ i ]
    for i in range ( N ) :
        if ( 2 * arr [ i ] == ArrSum ) :
            pos = i
            break
    return pos
arr = [ 1 , 3 , - 5 , 3 , 4 ]
N = len ( arr )
print ( smallestIndexArrayElementsFlip ( arr , N ) )

Index/key variables: i
Accumulator variables: ArrSum
Iterator variables: i
Python program:
def make_string_S_to_T ( S , T ) :
    possible = False
    M = len ( T )
    N = len ( S )
    for i in range ( 0 , M + 1 ) :
        prefix_length = i
        suffix_length = M - i
        prefix = S [ : prefix_length ]
        suffix = S [ N - suffix_length : N ]
        if ( prefix + suffix == T ) :
            possible = True
            break
    if ( possible ) :
        return " YES "
    else :
        return " NO "
S = " ababcdcd "
T = " abcd "
print ( make_string_S_to_T ( S , T ) )

Iterator variables: i
Boolean variables: possible
Python program:
def countPairs ( arr , n ) :
    mp1 = { }
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
        mp1 [ sum ] = mp1 . get ( sum , 0 ) + 1
    sum = 0
    ans = 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        sum += arr [ i ]
        if ( sum in mp1 ) :
            ans += mp1 [ sum ]
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 1 ]
    n = len ( arr )
    countPairs ( arr , n )

Index/key variables: i, sum
Accumulator variables: ans
Iterator variables: i
Python program:
def isMagic ( num ) :
    return ( num % 9 == 1 )
def isComposite ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return False
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return True
    for i in range ( 5 , n + 1 , 6 ) :
        if i * i > n + 1 :
            break
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return True
    return False
def find ( L , R , q ) :
    dp = [ 0 ] * 1000005
    dp [ 0 ] = 0
    dp [ 1 ] = 0
    for i in range ( 1 , 1000005 ) :
        if ( isComposite ( i ) and isMagic ( i ) ) :
            dp [ i ] = dp [ i - 1 ] + 1
        else :
            dp [ i ] = dp [ i - 1 ]
    for i in range ( q ) :
        print ( dp [ R [ i ] ] - dp [ L [ i ] - 1 ] )
if __name__ == ' _ _ main _ _ ' :
    L = [ 10 , 3 ]
    R = [ 100 , 2279 ]
    Q = 2
    find ( L , R , Q )

Index/key variables: i
Iterator variables: i
Python program:
def findSmallestInteger ( arr , N , K ) :
    left = 1
    right = max ( arr )
    while ( left < right ) :
        mid = ( left + right ) // 2
        sum = 0
        for i in range ( N ) :
            sum += ( arr [ i ] + mid - 1 ) // mid
        if ( sum > K ) :
            left = mid + 1
        else :
            right = mid
    return left
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 5 , 9 ]
    N = len ( arr )
    K = 6
    print ( findSmallestInteger ( arr , N , K ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def minimum_deci_binary_number ( s ) :
    m = - 10 ** 19
    for i in range ( len ( s ) ) :
        temp = ord ( s [ i ] ) - ord ( '0' )
        if ( temp > m ) :
            m = temp
    return m
if __name__ == ' _ _ main _ _ ' :
    S = "31"
    print ( minimum_deci_binary_number ( S ) )

Index/key variables: i
Iterator variables: i
Python program:
def minOperations ( arr , n ) :
    flips = 0 ;
    i = 0 ;
    while i < n :
        if ( arr [ i ] % 2 == 1 ) :
            i += 2 ;
            continue ;
        while ( i < n and arr [ i ] % 2 == 0 ) :
            i += 2 ;
        flips += 1 ;
        i += 2 ;
    i = 1
    while i < n :
        if ( arr [ i ] % 2 == 1 ) :
            i += 2 ;
            continue ;
        while ( i < n and arr [ i ] % 2 == 0 ) :
            i += 2 ;
        flips += 1 ;
        i += 2 ;
    print ( flips ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 4 , 3 , 5 , 3 , 2 ] ;
    N = len ( arr ) ;
    minOperations ( arr , N ) ;

Index/key variables: i
Accumulator variables: flips
Python program:
def minimumReverse ( s , n ) :
    k = 0 ;
    l = 0 ;
    sum1 = 0 ;
    sum0 = 0 ;
    for i in range ( 1 , n ) :
        if ( s [ i ] == '1' ) :
            sum1 += 1 ;
        else :
            sum0 += 1 ;
        if ( s [ i ] == s [ i - 1 ] and s [ i ] == '0' ) :
            k += 1 ;
        elif ( s [ i ] == s [ i - 1 ] and s [ i ] == '1' ) :
            l += 1 ;
    if ( s [ 0 ] == '1' ) :
        sum1 += 1 ;
        sum0 += 1 ;
    if ( abs ( sum1 - sum0 ) > 1 ) :
        return - 1 ;
    return max ( k , l ) ;
if __name__ == ' _ _ main _ _ ' :
    S = "10001" ;
    N = len ( S ) ;
    print ( minimumReverse ( S , N ) ) ;

Index/key variables: i
Accumulator variables: k, l, sum0, sum1
Iterator variables: i
Python program:
def cntPairsInTwoArray ( arr , brr , N , M ) :
    cntOddArr = 0
    cntOddBrr = 0
    for i in range ( N ) :
        if ( arr [ i ] & 1 ) :
            cntOddArr += 1
    for i in range ( M ) :
        if ( brr [ i ] & 1 ) :
            cntOddBrr += 1
    return ( N * M ) - ( cntOddArr * cntOddBrr )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 ]
    N = len ( arr )
    brr = [ 1 , 2 ]
    M = len ( brr )
    print ( cntPairsInTwoArray ( arr , brr , N , M ) )

Index/key variables: i
Accumulator variables: cntOddArr, cntOddBrr
Iterator variables: i
Python program:
from bisect import bisect_left
def countMaxPersons ( A , n , B , m , x ) :
    count = 0
    A = sorted ( A )
    B = sorted ( B )
    s = [ ]
    for i in range ( m ) :
        s . append ( B [ i ] )
    for i in range ( n ) :
        val = A [ i ] - x
        it = bisect_left ( s , val )
        if ( it != len ( s ) and it <= A [ i ] + x ) :
            count += 1
            del s [ it ]
    return count
if __name__ == ' _ _ main _ _ ' :
    A = [ 90 , 49 , 20 , 39 , 49 ]
    B = [ 14 , 24 , 82 ]
    X = 15
    N = len ( A )
    M = len ( B )
    print ( countMaxPersons ( A , N , B , M , X ) )

Index/key variables: i, it
Accumulator variables: count, s
Iterator variables: i
Python program:
def max_freq ( arr , N ) :
    Max = max ( arr )
    Min = min ( arr )
    freq = [ 0 ] * ( Max - Min + 1 )
    for i in range ( N ) :
        freq [ arr [ i ] - Min ] += 1
    maxSum = 0
    for i in range ( Max - Min - 1 ) :
        val = freq [ i ] + freq [ i + 1 ] + freq [ i + 2 ]
        maxSum = max ( maxSum , val )
    print ( maxSum )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 1 , 4 , 1 , 5 , 9 , 2 ]
    N = len ( arr )
    max_freq ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def findMaxLength ( N , arr ) :
    dp = [ 1 ] * ( N + 1 )
    for i in range ( 1 , N + 1 ) :
        for j in range ( 2 * i , N + 1 , i ) :
            if ( arr [ i - 1 ] < arr [ j - 1 ] ) :
                dp [ j ] = max ( dp [ j ] , dp [ i ] + 1 )
    return max ( dp )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
    N = len ( arr )
    print ( findMaxLength ( N , arr ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def binary_search ( vec , n , a ) :
    low , high , mid = 0 , 0 , 0
    low = 0
    high = n - 1
    while ( low < high ) :
        mid = low + ( high - low + 1 ) // 2
        if ( vec [ mid ] [ 0 ] > a ) :
            high = mid - 1
        elif vec [ mid ] [ 0 ] <= a :
            low = mid
    return low
def modify_vec ( v , n ) :
    for i in range ( n ) :
        v [ i ] [ 1 ] = min ( v [ i ] [ 1 ] , v [ i - 1 ] [ 1 ] )
    return v
def evaluate_query ( v , n , m1 , m2 ) :
    temp = binary_search ( v , n , m1 )
    if ( ( v [ temp ] [ 0 ] <= m1 ) and ( v [ temp ] [ 1 ] <= m2 ) ) :
        return 1
    return 0
def checkPairs ( v , queries ) :
    n = len ( v )
    v = sorted ( v )
    v = modify_vec ( v , n )
    k = len ( queries )
    for i in range ( k ) :
        m1 = queries [ i ] [ 0 ]
        m2 = queries [ i ] [ 1 ]
        result = evaluate_query ( v , n , m1 , m2 )
        if ( result > 0 ) :
            print ( " Yes " )
        else :
            print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 3 , 5 ] , [ 2 , 7 ] , [ 2 , 3 ] , [ 4 , 9 ] ]
    queries = [ [ 3 , 4 ] , [ 3 , 2 ] , [ 4 , 1 ] , [ 3 , 7 ] ]
    checkPairs ( arr , queries )

Index/key variables: i, mid, temp
Iterator variables: i
Python program:
def Sort ( ans , num ) :
    pos = - 1 ;
    for i in range ( len ( ans ) ) :
        if ( ans [ i ] >= num ) :
            pos = i ;
            break ;
    if ( pos == - 1 ) :
        ans . append ( num ) ;
    else :
        ans . insert ( pos , num ) ;
    return ans ;
def sortStream ( arr , N ) :
    ans = list ( ) ;
    for i in range ( N ) :
        ans = Sort ( ans , arr [ i ] ) ;
        for j in range ( len ( ans ) ) :
            print ( ans [ j ] , end = " ▁ " ) ;
        print ( ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 1 , 7 , 6 , 2 ] ;
    N = len ( arr ) ;
    sortStream ( arr , N ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countSubArraySignChange ( arr , N ) :
    prefixCount = { }
    suffixCount = { }
    total = 0
    for i in range ( N - 1 , - 1 , - 1 ) :
        total += arr [ i ]
        suffixCount [ arr [ i ] ] = suffixCount . get ( arr [ i ] , 0 ) + 1
    prefixSum = 0
    suffixSum = 0
    count = 0
    for i in range ( N - 1 ) :
        prefixSum += arr [ i ]
        prefixCount [ arr [ i ] ] = prefixCount . get ( arr [ i ] , 0 ) + 1
        suffixSum = total - prefixSum
        suffixCount [ arr [ i ] ] -= 1
        diff = prefixSum - suffixSum
        if ( diff % 2 == 0 ) :
            y , z = 0 , 0
            if - diff // 2 in suffixCount :
                y = suffixCount [ - dff // 2 ]
            if diff // 2 in prefixCount :
                z = prefixCount
            x = z + y
            count = count + x
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 2 , - 3 , 3 ]
    N = len ( arr )
    print ( countSubArraySignChange ( arr , N ) )

Index/key variables: i
Accumulator variables: prefixSum, total
Iterator variables: i
Python program:
def countCommonChar ( ind , S ) :
    cnt = 0
    ls = set ( )
    rs = set ( )
    for i in range ( ind ) :
        ls . add ( S [ i ] )
    for i in range ( ind , len ( S ) ) :
        rs . add ( S [ i ] )
    for v in ls :
        if v in rs :
            cnt += 1
    return cnt
def partitionStringWithMaxCom ( S ) :
    ans = 0
    for i in range ( 1 , len ( S ) ) :
        ans = max ( ans , countCommonChar ( i , S ) )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    string = " aabbca "
    partitionStringWithMaxCom ( string )

Index/key variables: i
Accumulator variables: cnt, ls, rs
Iterator variables: i, v
Python program:
def SmallestString ( s , c ) :
    i = 0
    while ( i < len ( s ) ) :
        if s [ i ] > c :
            s = s [ : i ] + c + s [ i : ]
            return s
        i = i + 1
    s = s + c
    return s
S = ' abd '
C = ' c '
print ( SmallestString ( S , C ) )

Index/key variables: i
Python program:
import sys
def LarUnEl ( arr , N ) :
    map = dict . fromkeys ( arr , 0 ) ;
    for i in range ( N ) :
        map [ arr [ i ] ] += 1 ;
    LNRElem = - sys . maxsize ;
    ind = - 1 ;
    for i in range ( N ) :
        if ( map . get ( arr [ i ] ) == 1 and arr [ i ] > LNRElem ) :
            ind = i ;
            LNRElem = arr [ i ] ;
    if ( ind == - 1 ) :
        print ( ind ) ;
        return ;
    print ( arr [ ind ] ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 1 , 8 , 8 , 4 ] ;
    N = len ( arr ) ;
    LarUnEl ( arr , N ) ;

Index/key variables: i, ind
Iterator variables: i
Python program:
def checkSubsequenceUtil ( arr , L , R , N ) :
    for i in range ( L ) :
        if ( arr [ i ] == arr [ L ] ) :
            return True
    for i in range ( R + 1 , N , 1 ) :
        if ( arr [ i ] == arr [ R ] ) :
            return True
    return False
def checkSubsequence ( arr , L , R , N ) :
    if ( checkSubsequenceUtil ( arr , L , R , N ) ) :
        print ( " YES " )
    else :
        print ( " NO " )
arr = [ 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 ]
N = len ( arr )
L = 3
R = 6
checkSubsequence ( arr , L , R , N )

Index/key variables: L, R, i
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def findPair ( A , N ) :
    right_prod = [ 0 ] * N
    flag = 0
    right_prod [ N - 1 ] = A [ N - 1 ]
    for i in range ( N - 2 , 0 , - 1 ) :
        right_prod [ i ] = right_prod [ i + 1 ] * A [ i ]
    total_prod = right_prod [ 0 ]
    product = 1
    for i in range ( 1 , N - 1 ) :
        product = 1
        for j in range ( i , N - 1 ) :
            product *= A [ j ]
            if ( gcd ( product , right_prod [ j + 1 ] ) == 1 or gcd ( product , total_prod / right_prod [ i ] ) == 1 ) :
                flag = 1
                print ( " ( " , ( i - 1 ) , " , ▁ " , ( j + 1 ) , " ) " )
                break
        if ( flag == 1 ) :
            break
    if ( flag == 0 ) :
        print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 1 , 3 , 7 ]
    N = len ( arr )
    findPair ( arr , N )

Index/key variables: i, j
Accumulator variables: product
Iterator variables: i, j
Python program:
def countString ( S ) :
    count = 0
    for i in S :
        if ( i == '0' and count > 0 ) :
            count -= 1
        else :
            count += 1
    print ( ( 1 << count ) - 1 )
if __name__ == " _ _ main _ _ " :
    S = "1001"
    countString ( S )

Accumulator variables: count
Iterator variables: i