dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
fact = [ 0 ] * 14
size = 1
def preCompute ( N ) :
    global size
    fact [ 0 ] = 1
    i = 1
    while fact [ i - 1 ] <= N :
        fact [ i ] = fact [ i - 1 ] * i
        size += 1
        i += 1
def findMin ( N ) :
    preCompute ( N )
    originalN = N
    ans = [ ]
    for i in range ( size - 1 , - 1 , - 1 ) :
        while ( N >= fact [ i ] ) :
            N -= fact [ i ]
            ans . append ( fact [ i ] )
    print ( len ( ans ) )
    for i in ans :
        print ( i , end = " ▁ " )
n = 27
findMin ( n )

Index/key variables: i
Accumulator variables: N, ans, size
Iterator variables: i
Python program:
from bisect import bisect as upper_bound
def minSubsequnces ( A , B ) :
    v = [ [ ] for i in range ( 26 ) ]
    minIndex = - 1
    cnt = 1
    j = 0
    flag = 0
    for i in range ( len ( A ) ) :
        p = ord ( A [ i ] ) - 97
        v [ p ] . append ( i )
    while ( j < len ( B ) ) :
        p = ord ( B [ j ] ) - 97
        k = upper_bound ( v [ p ] , minIndex )
        if ( len ( v [ p ] ) == 0 ) :
            flag = 1
            break
        if ( k != len ( v [ p ] ) ) :
            minIndex = v [ p ] [ k ]
            j = j + 1
        else :
            cnt = cnt + 1
            minIndex = - 1
    if ( flag == 1 ) :
        return - 1
    return cnt
A1 = " abbace "
B1 = " acebbaae "
print ( minSubsequnces ( A1 , B1 ) )

Index/key variables: i, j, k, p
Iterator variables: i
Python program:
MAX = 26 ;
def maxLength ( str , len ) :
    res = 0 ;
    lastPos = [ 0 ] * MAX ;
    for i in range ( MAX ) :
        lastPos [ i ] = - 1 ;
    for i in range ( len ) :
        C = ord ( str [ i ] ) - ord ( ' a ' ) ;
        if ( lastPos [ C ] != - 1 ) :
            res = max ( len - ( i - lastPos [ C ] - 1 ) - 1 , res ) ;
        lastPos [ C ] = i ;
    return res ;
if __name__ == ' _ _ main _ _ ' :
    str = " geeksforgeeks " ;
    len = len ( str ) ;
    print ( maxLength ( str , len ) ) ;

Index/key variables: C, i
Iterator variables: i
Python program:
def maxProfit ( a , b , n ) :
    maxP = - 1
    for i in range ( 0 , n + 1 ) :
        sumA = sum ( a [ : i ] )
        sumB = sum ( b [ i : ] )
        maxP = max ( maxP , sumA + sumB )
    return maxP
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 3 , 2 ]
    b = [ 10 , 30 , 40 ]
    print ( maxProfit ( a , b , 4 ) )

Iterator variables: i
Python program:
import sys
INT_MAX = sys . maxsize ;
def countPartitions ( A , N ) :
    count = 0 ;
    for i in range ( N ) :
        min_elem = min ( A ) ;
        if ( min_elem == INT_MAX ) :
            break ;
        count += 1 ;
        for i in range ( N ) :
            if ( A [ i ] % min_elem == 0 ) :
                A [ i ] = INT_MAX ;
    return count ;
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 6 , 5 , 4 , 3 , 2 , 2 , 3 ] ;
    N = len ( arr ) ;
    print ( countPartitions ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def minSwaps ( s1 , s2 ) :
    c0 = 0 ; c1 = 0 ;
    for i in range ( len ( s1 ) ) :
        if ( s1 [ i ] == '0' and s2 [ i ] == '1' ) :
            c0 += 1 ;
        elif ( s1 [ i ] == '1' and s2 [ i ] == '0' ) :
            c1 += 1 ;
    ans = c0 // 2 + c1 // 2 ;
    if ( c0 % 2 == 0 and c1 % 2 == 0 ) :
        return ans ;
    elif ( ( c0 + c1 ) % 2 == 0 ) :
        return ans + 2 ;
    else :
        return - 1 ;
if __name__ == " _ _ main _ _ " :
    s1 = "0011" ; s2 = "1111" ;
    ans = minSwaps ( s1 , s2 ) ;
    print ( ans ) ;

Index/key variables: i
Accumulator variables: c0, c1
Iterator variables: i
Python program:
def minChanges ( arr , n ) :
    mp = dict ( )
    for i in range ( n ) :
        if arr [ i ] in mp . keys ( ) :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    maxElem = 0
    for x in mp :
        maxElem = max ( maxElem , mp [ x ] )
    return n - maxElem
arr = [ 2 , 3 , 3 , 4 ]
n = len ( arr )
print ( minChanges ( arr , n ) )

Index/key variables: i, x
Iterator variables: i, x
Python program:
def k_sum ( a , n , k ) :
    r , sum = 0 , 0 ;
    ans = 0 ;
    for l in range ( n ) :
        while ( sum < k ) :
            if ( r == n ) :
                break ;
            else :
                sum += a [ r ] ;
                r += 1 ;
        if ( sum < k ) :
            break ;
        ans += n - r + 1 ;
        sum -= a [ l ] ;
    return ans ;
a = [ 6 , 1 , 2 , 7 ] ; k = 10 ;
n = len ( a ) ;
print ( k_sum ( a , n , k ) ) ;

Index/key variables: l, r
Accumulator variables: ans, sum
Iterator variables: l
Python program:
def hasCrest ( arr , n , L , R ) :
    present = [ 0 ] * n ;
    for i in range ( 1 , n - 2 + 1 ) :
        if ( ( arr [ i ] <= arr [ i + 1 ] ) and ( arr [ i ] <= arr [ i - 1 ] ) ) :
            present [ i ] = 1 ;
    for i in range ( 1 , n ) :
        present [ i ] += present [ i - 1 ] ;
    if ( present [ L ] == present [ R - 1 ] ) :
        return True ;
    return False ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 1 , 3 , 5 , 12 , 11 , 7 , 9 ] ;
    N = len ( arr ) ;
    L = 2 ;
    R = 6 ;
    if ( hasCrest ( arr , N , L , R ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: L, i
Iterator variables: i
Python program:
import sys
def maxSum ( arr1 , arr2 , n ) :
    initialParity , finalParity = 0 , 0
    sum = 0
    minPositive = sys . maxsize
    maxNegative = - sys . maxsize - 1
    for i in range ( n ) :
        initialParity += arr2 [ i ] ;
        if ( arr1 [ i ] >= 0 ) :
            finalParity += 1
            sum += arr1 [ i ]
            minPositive = min ( minPositive , arr1 [ i ] )
        else :
            maxNegative = max ( maxNegative , arr1 [ i ] )
    if ( initialParity % 2 == finalParity % 2 ) :
        return sum
    else :
        if ( minPositive + maxNegative >= 0 ) :
            return sum + maxNegative
        else :
            return sum - minPositive
arr1 = [ 2 , - 4 , 5 , 3 ]
arr2 = [ 0 , 1 , 0 , 1 ]
n = len ( arr1 )
print ( maxSum ( arr1 , arr2 , n ) )

Index/key variables: i
Accumulator variables: finalParity, initialParity, sum
Iterator variables: i
Python program:
def IsLarger ( X , Y , n ) :
    for i in range ( n ) :
        if ( X [ i ] < Y [ i ] ) :
            return False ;
    return True ;
def solve ( X , Y , n ) :
    ans = 0 ;
    if ( IsLarger ( X , Y , n ) ) :
        ans = 0 ;
    else :
        d = Y [ 0 ] - X [ 0 ] ;
        for i in range ( n ) :
            X [ i ] += d ;
        if ( IsLarger ( X , Y , n ) ) :
            ans = d ;
        else :
            ans = d + 1 ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    X = [ 2 , 3 , 6 , 9 ] ;
    Y = [ 3 , 4 , 8 , 1 ] ;
    n = len ( X ) ;
    print ( solve ( X , Y , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def valueofX ( ar , n ) :
    summ = sum ( ar )
    if ( summ % n == 0 ) :
        return summ // n
    else :
        A = summ // n
        B = summ // n + 1
        ValueA = 0
        ValueB = 0
        for i in range ( n ) :
            ValueA += ( ar [ i ] - A ) * ( ar [ i ] - A )
            ValueB += ( ar [ i ] - B ) * ( ar [ i ] - B )
        if ( ValueA < ValueB ) :
            return A
        else :
            return B
n = 7
arr = [ 6 , 9 , 1 , 6 , 1 , 3 , 7 ]
print ( valueofX ( arr , n ) )

Index/key variables: i
Accumulator variables: ValueA, ValueB
Iterator variables: i
Python program:
def minLength ( n ) :
    ans = n // 26
    if ( n % 26 != 0 ) :
        ans += 1
    return ans
def minString ( n ) :
    ans = n // 26
    res = " "
    while ( ans ) :
        res = res + " z "
        ans -= 1
    if ( n % 26 != 0 ) :
        res = res + chr ( ( n % 26 ) + 96 )
    return res
n = 50 ;
print ( minLength ( n ) )
print ( minString ( n ) )

Accumulator variables: ans
Python program:
MAX = 100001
def minHalls ( lectures , n ) :
    prefix_sum = [ 0 ] * MAX ;
    for i in range ( n ) :
        prefix_sum [ lectures [ i ] [ 0 ] ] += 1 ;
        prefix_sum [ lectures [ i ] [ 1 ] + 1 ] -= 1 ;
    ans = prefix_sum [ 0 ] ;
    for i in range ( 1 , MAX ) :
        prefix_sum [ i ] += prefix_sum [ i - 1 ] ;
        ans = max ( ans , prefix_sum [ i ] ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    lectures = [ [ 0 , 5 ] , [ 1 , 2 ] , [ 1 , 10 ] ] ;
    n = len ( lectures ) ;
    print ( minHalls ( lectures , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def minCapacity ( enter , exit , n ) :
    minCap = 0 ;
    currCap = 0 ;
    for i in range ( n ) :
        currCap = currCap + enter [ i ] - exit [ i ] ;
        minCap = max ( minCap , currCap ) ;
    return minCap ;
if __name__ == ' _ _ main _ _ ' :
    enter = [ 3 , 5 , 2 , 0 ] ;
    exit = [ 0 , 2 , 4 , 4 ] ;
    n = len ( enter ) ;
    print ( minCapacity ( enter , exit , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
from collections import deque
MAX = 543210
ans = [ ]
def isValidNum ( x ) :
    mp = dict ( )
    for i in range ( len ( x ) ) :
        if ( ord ( x [ i ] ) - ord ( '0' ) in mp . keys ( ) ) :
            return False
        elif ( ord ( x [ i ] ) - ord ( '0' ) > 5 ) :
            return False
        else :
            mp [ ord ( x [ i ] ) - ord ( '0' ) ] = 1
    return True
def generate ( ) :
    q = deque ( )
    q . append ( "1" )
    q . append ( "2" )
    q . append ( "3" )
    q . append ( "4" )
    q . append ( "5" )
    flag = True
    ans . append ( "0" )
    while ( len ( q ) > 0 ) :
        x = q . popleft ( )
        if ( isValidNum ( x ) ) :
            ans . append ( x )
        if ( len ( x ) == 6 ) :
            continue
        for i in range ( 6 ) :
            z = str ( i )
            temp = x + z
            q . append ( temp )
def comp ( a , b ) :
    if ( len ( a ) == len ( b ) ) :
        if a < b :
            return True
    else :
        return len ( a ) < len ( b )
def findcount ( l , r ) :
    generate ( )
    count = 0
    for i in range ( len ( ans ) ) :
        a = ans [ i ]
        if ( comp ( l , a ) and comp ( a , r ) ) :
            count += 1
        elif ( a == l or a == r ) :
            count += 1
    return count
l = "1"
r = "1000"
print ( findcount ( l , r ) )

Index/key variables: i
Accumulator variables: ans, count, q
Iterator variables: i
Boolean variables: flag
Python program:
def Findpermutation ( n ) :
    a = [ 0 ] * ( n + 1 ) ;
    a [ 1 ] = n ;
    for i in range ( 2 , n + 1 ) :
        a [ i ] = i - 1 ;
    return a ;
if __name__ == " _ _ main _ _ " :
    n = 8 ;
    v = Findpermutation ( n ) ;
    for i in range ( 1 , n + 1 ) :
        print ( v [ i ] , end = ' ▁ ' ) ;

Index/key variables: i
Iterator variables: i
Python program:
def lexo_small ( n , k ) :
    arr = " " ;
    for i in range ( n ) :
        arr += ' a ' ;
    for i in range ( n - 1 , - 1 , - 1 ) :
        k -= i ;
        if ( k >= 0 ) :
            if ( k >= 26 ) :
                arr = arr [ : i ] + ' z ' + arr [ i + 1 : ] ;
                k -= 26 ;
            else :
                c = ( k + 97 - 1 ) ;
                arr = arr [ : i ] + chr ( c ) + arr [ i + 1 : ] ;
                k -= ord ( arr [ i ] ) - ord ( ' a ' ) + 1 ;
        else :
            break ;
        k += i ;
    return arr ;
if __name__ == ' _ _ main _ _ ' :
    n = 5 ; k = 42 ;
    arr = lexo_small ( n , k ) ;
    print ( arr ) ;

Index/key variables: i
Accumulator variables: arr, k
Iterator variables: i
Python program:
def IsPossible ( s ) :
    n = len ( s ) ;
    count = set ( ) ;
    map = dict . fromkeys ( s , 0 ) ;
    for i in range ( n ) :
        count . add ( s [ i ] ) ;
        map [ s [ i ] ] += 1 ;
    if ( len ( count ) == 1 ) :
        return True ;
    if ( len ( count ) > 2 ) :
        return False ;
    j = 0
    it = list ( count ) [ j ] ;
    x = 0 ; y = 0 ;
    x = map [ it ] ;
    j += 1
    it = list ( count ) [ j ] ;
    y = map [ it ] ;
    if ( abs ( x - y ) <= 1 ) :
        return True ;
    return False ;
if __name__ == " _ _ main _ _ " :
    s = " aaaddad " ;
    if ( IsPossible ( s ) ) :
        print ( " YES " ) ;
    else :
        print ( " NO " ) ;

Index/key variables: i, it, j
Accumulator variables: count
Iterator variables: i
Python program:
def Substring ( s ) :
    ans , temp = 1 , 1
    for i in range ( 1 , len ( s ) ) :
        if ( s [ i ] == s [ i - 1 ] ) :
            temp += 1
        else :
            ans = max ( ans , temp )
            temp = 1
    ans = max ( ans , temp )
    return ans
s = " abcdddddeff "
print ( Substring ( s ) )

Index/key variables: i
Accumulator variables: temp
Iterator variables: i
Python program:
def Balanced_Substring ( s , n ) :
    ans = 0 ;
    arr = [ 0 ] * ( int ( n / 2 ) + 1 ) ;
    d = 0 ;
    for i in range ( n ) :
        if ( s [ i ] == ' ( ' ) :
            d += 1 ;
        else :
            if ( d == 1 ) :
                j = 2
                while ( j <= n // 2 + 1 and arr [ j ] != 0 ) :
                    arr [ j ] = 0
            ans += 1 ;
            ans += arr [ d ] ;
            arr [ d ] += 1 ;
            d -= 1 ;
    return ans ;
s = " ( ) ( ) ( ) " ;
n = len ( s ) ;
print ( Balanced_Substring ( s , n ) ) ;

Index/key variables: d, i, j
Accumulator variables: ans
Iterator variables: i
Python program:
def power ( x , y , mod ) :
    res = 1
    while ( y ) :
        if ( y & 1 ) :
            res = ( res * x ) % mod
        x = ( x * x ) % mod
        y = ( y >> 1 )
    return ( res % mod )
def ncr ( n , r , mod ) :
    res = 1
    for i in range ( 1 , r + 1 ) :
        res = ( res * ( n - i + 1 ) ) % mod
        inv = power ( i , mod - 2 , mod )
        res = ( res * inv ) % mod
    return ( res % mod )
def NoOfChords ( A ) :
    mod = 10 ** 9 + 7
    ans = ncr ( 2 * A , A , mod )
    inv = power ( A + 1 , mod - 2 , mod )
    ans = ( ans * inv ) % mod
    return ( ans % mod )
N = 2
print ( NoOfChords ( N ) )

Iterator variables: i
Python program:
def StrictlyPositiveXor ( A , N ) :
    allxor = 0 ;
    checkallzero = True ;
    for i in range ( N ) :
        allxor ^= A [ i ] ;
        if ( A [ i ] > 0 ) :
            checkallzero = False ;
    if ( allxor != 0 ) :
        return N ;
    if ( checkallzero ) :
        return - 1 ;
    l = N ; r = - 1 ;
    for i in range ( N ) :
        if ( A [ i ] > 0 ) :
            l = i + 1 ;
            break ;
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( A [ i ] > 0 ) :
            r = i + 1 ;
            break ;
    return max ( N - l , r - 1 ) ;
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 0 , 0 , 1 ] ;
    N = len ( A ) ;
    print ( StrictlyPositiveXor ( A , N ) ) ;

Index/key variables: i
Accumulator variables: allxor
Iterator variables: i
Boolean variables: checkallzero
Python program:
MAX_INT = 1000000
def solve ( Array , N ) :
    pos = [ [ ] for i in range ( 5 ) ]
    pref = [ 0 for i in range ( 5 ) ]
    if ( Array [ 0 ] == 0 ) :
        pref [ 0 ] = 1
        pos [ 0 ] . append ( 0 )
    ans = MAX_INT
    for i in range ( N ) :
        if ( Array [ i ] == 0 ) :
            pref [ 0 ] += 1
            pos [ 0 ] . append ( i )
        else :
            if ( pref [ Array [ i ] - 1 ] > 0 ) :
                pref [ Array [ i ] ] += 1
                pos [ Array [ i ] ] . append ( i )
                if ( Array [ i ] == 4 ) :
                    end = i
                    start = i
                    for j in range ( 3 , - 1 , - 1 ) :
                        s = 0
                        e = len ( pos [ j ] ) - 1
                        temp = - 1
                        while ( s <= e ) :
                            m = ( s + e ) // 2
                            if ( pos [ j ] [ m ] <= start ) :
                                temp = pos [ j ] [ m ]
                                s = m + 1
                            else :
                                e = m - 1
                        start = temp
                    ans = min ( ans , end - start + 1 )
    return ans
Array = [ 0 , 1 , 2 , 3 , 4 , 2 , 0 , 3 , 4 ]
N = len ( Array )
print ( solve ( Array , N ) )

Index/key variables: i, j, m
Iterator variables: i, j
Python program:
def findWeights ( X ) :
    sum = 0
    power = 0
    while ( sum < X ) :
        sum = pow ( 3 , power + 1 ) - 1
        sum //= 2
        power += 1
    ans = 1
    for i in range ( 1 , power + 1 ) :
        print ( ans , end = " ▁ " )
        ans = ans * 3
X = 2
findWeights ( X )

Accumulator variables: power, sum
Iterator variables: i
Python program:
import sys ;
def solve ( X , A ) :
    minimum = sys . maxsize ;
    ind = - 1 ;
    for i in range ( len ( A ) ) :
        if ( A [ i ] < minimum ) :
            minimum = A [ i ] ;
            ind = i ;
    maxIndChosen = X // minimum ;
    ans = [ ] ;
    if ( maxIndChosen == 0 ) :
        return ans ;
    for i in range ( maxIndChosen ) :
        ans . append ( ind ) ;
    temp = maxIndChosen ;
    sum = maxIndChosen * A [ ind ] ;
    for i in range ( ind ) :
        if ( sum - X == 0 or temp == 0 ) :
            break ;
        while ( ( sum - A [ ind ] + A [ i ] ) <= X and temp != 0 ) :
            del ( ans [ 0 ] ) ;
            ans . append ( i ) ;
            temp -= 1 ;
            sum += ( A [ i ] - A [ ind ] ) ;
    ans . sort ( ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    A = [ 5 , 6 , 4 , 8 ] ;
    X = 18 ;
    ans = solve ( X , A ) ;
    for i in range ( len ( ans ) ) :
        print ( ans [ i ] , end = " ▁ " ) ;

Index/key variables: i, ind
Accumulator variables: ans, sum, temp
Iterator variables: i
Python program:
def matrix_exist ( row , column , r , c ) :
    row_sum = 0
    column_sum = 0
    row_max = - 1
    column_max = - 1
    row_non_zero = 0
    column_non_zero = 0
    for i in range ( r ) :
        row_sum += row [ i ]
        row_max = max ( row_max , row [ i ] )
        if ( row [ i ] ) :
            row_non_zero = row_non_zero + 1
    for i in range ( c ) :
        column_sum = column_sum + column [ i ]
        column_max = max ( column_max , column [ i ] )
        if ( column [ i ] ) :
            column_non_zero = column_non_zero + 1
    if ( ( row_sum != column_sum ) or ( row_max > column_non_zero ) or ( column_max > row_non_zero ) ) :
        return False
    return True
if __name__ == ' _ _ main _ _ ' :
    row = [ 2 , 2 , 2 , 2 , 2 ]
    column = [ 5 , 5 , 0 , 0 ]
    r = len ( row )
    c = len ( column )
    if matrix_exist ( row , column , r , c ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i
Accumulator variables: row_sum
Iterator variables: i
Python program:
def longestSubarray ( arr , n ) :
    maxMean = 0 ;
    for i in range ( 1 , n ) :
        maxMean = max ( maxMean , ( arr [ i ] + arr [ i - 1 ] ) // 2 ) ;
    ans = 0 ;
    subarrayLength = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] >= maxMean ) :
            subarrayLength += 1 ;
            ans = max ( ans , subarrayLength ) ;
        else :
            subarrayLength = 0 ;
    return ans ;
arr = [ 4 , 3 , 3 , 2 , 1 , 4 ] ;
n = len ( arr ) ;
print ( longestSubarray ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: subarrayLength
Iterator variables: i
Python program:
def maxDistance ( arr , n ) :
    if ( arr [ 0 ] != arr [ n - 1 ] ) :
        return ( n - 1 ) ;
    i = n - 1 ;
    while ( i > 0 ) :
        if ( arr [ i ] != arr [ 0 ] ) :
            break ;
        i -= 1 ;
    distFirst = - 1 if ( i == 0 ) else i ;
    i = 0 ;
    while ( i < n - 1 ) :
        if ( arr [ i ] != arr [ n - 1 ] ) :
            break ;
        i += 1 ;
    distLast = - 1 if ( i == n - 1 ) else ( n - 1 - i ) ;
    maxDist = max ( distFirst , distLast ) ;
    return maxDist ;
arr = [ 4 , 4 , 1 , 2 , 1 , 4 ] ;
n = len ( arr ) ;
print ( maxDistance ( arr , n ) ) ;

Index/key variables: i
Python program:
from collections import defaultdict , deque
def Check_Path ( a , b , G ) :
    visited = defaultdict ( bool )
    queue = deque ( )
    queue . append ( a )
    visited [ a ] = True
    while queue :
        n = queue . popleft ( )
        if n == b :
            return True
        for i in list ( G [ n ] ) :
            if visited [ i ] == False :
                queue . append ( i )
                visited [ i ] = True
    return False
def countPairs ( s1 , s2 , G ) :
    name = defaultdict ( bool )
    count = 0
    for i in range ( x ) :
        a = s1 [ i ]
        b = s2 [ i ]
        if a in G and b not in G and a != b :
            G [ a ] . append ( b )
            G [ b ] . append ( a )
            count += 1
        elif b in G and a not in G and a != b :
            G [ b ] . append ( a )
            G [ a ] . append ( b )
            count += 1
        elif a not in G and b not in G and a != b :
            G [ a ] . append ( b )
            G [ b ] . append ( a )
            count += 1
        else :
            if not Check_Path ( a , b , G ) and a != b :
                G [ a ] . append ( b )
                G [ b ] . append ( a )
                count += 1
    return count
if __name__ == " _ _ main _ _ " :
    s1 = " abb "
    s2 = " dad "
    x = len ( s1 )
    G = defaultdict ( list )
    print ( countPairs ( s1 , s2 , G ) )

Index/key variables: a, b, i, n
Accumulator variables: count, queue
Iterator variables: i
Python program:
def solve ( n , k ) :
    mini = 0
    x1 = 1
    a = [ 0 for i in range ( k ) ]
    for i in range ( 1 , k + 1 ) :
        mini += x1
        a [ i - 1 ] = x1
        x1 += 1
    if ( n < mini ) :
        print ( " - 1" , end = " " )
        return
    rem = n - mini
    cnt = int ( rem / k )
    rem = rem % k
    for i in range ( k ) :
        a [ i ] += cnt
    i = k - 1
    while ( i > 0 and rem > 0 ) :
        xx = a [ i - 1 ] * 2
        left = xx - a [ i ]
        if ( rem >= left ) :
            a [ i ] = xx
            rem -= left
        else :
            a [ i ] += rem
            rem = 0
        i -= 1
    sum = a [ 0 ]
    for i in range ( 1 , k ) :
        if ( a [ i ] > 2 * a [ i - 1 ] ) :
            print ( " - 1" , end = " " )
            return
        sum += a [ i ]
    if ( sum != n ) :
        print ( " - 1" , end = " " )
        return
    for i in range ( k ) :
        print ( a [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    n = 26
    k = 6
    solve ( n , k )

Index/key variables: i
Accumulator variables: mini, rem, sum, x1
Iterator variables: i
Python program:
MAX = 25 ;
def getMinSum ( arr , n ) :
    bits_count = [ 0 ] * MAX
    max_bit = 0 ; sum = 0 ; ans = 0 ;
    for d in range ( n ) :
        e = arr [ d ] ; f = 0 ;
        while ( e > 0 ) :
            rem = e % 2 ;
            e = e // 2 ;
            if ( rem == 1 ) :
                bits_count [ f ] += rem ;
            f += 1
        max_bit = max ( max_bit , f ) ;
    for d in range ( max_bit ) :
        temp = pow ( 2 , d ) ;
        if ( bits_count [ d ] > n // 2 ) :
            ans = ans + temp ;
    for d in range ( n ) :
        arr [ d ] = arr [ d ] ^ ans ;
        sum = sum + arr [ d ] ;
    return sum
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 5 , 7 , 11 , 15 ] ;
    n = len ( arr ) ;
    print ( getMinSum ( arr , n ) )

Index/key variables: d, f
Iterator variables: d
Python program:
def findMinimumX ( a , n ) :
    st = set ( )
    for i in range ( n ) :
        st . add ( a [ i ] )
    if ( len ( st ) == 1 ) :
        return 0
    if ( len ( st ) == 2 ) :
        st = list ( st )
        el1 = st [ 0 ]
        el2 = st [ 1 ]
        if ( ( el2 - el1 ) % 2 == 0 ) :
            return int ( ( el2 - el1 ) / 2 )
        else :
            return ( el2 - el1 )
    if ( len ( st ) == 3 ) :
        st = list ( st )
        el1 = st [ 0 ]
        el2 = st [ 1 ]
        el3 = st [ 2 ]
        if ( ( el2 - el1 ) == ( el3 - el2 ) ) :
            return el2 - el1
        else :
            return - 1
    return - 1
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 4 , 4 , 7 , 4 , 1 ]
    n = len ( a )
    print ( findMinimumX ( a , n ) )

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