dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from math import sqrt
def find_index ( arr , N ) :
    max_value = - 10 ** 9
    for i in range ( N ) :
        max_value = max ( max_value , arr [ i ] )
    store = { }
    for i in range ( 1 , max_value + 1 ) :
        store [ i ] = store . get ( i , 0 ) + 1
    if ( 1 in store ) :
        del store [ 1 ]
    for i in range ( 2 , int ( sqrt ( max_value ) ) + 1 ) :
        multiple = 2
        while ( ( i * multiple ) <= max_value ) :
            if ( i * multiple in store ) :
                del store [ i * multiple ]
            multiple += 1
    prime_sum_from_left = 0
    first_array = [ 0 ] * N
    for i in range ( N ) :
        first_array [ i ] = prime_sum_from_left
        if arr [ i ] in store :
            prime_sum_from_left += arr [ i ]
    prime_sum_from_right = 0
    second_array = [ 0 ] * N
    for i in range ( N - 1 , - 1 , - 1 ) :
        second_array [ i ] = prime_sum_from_right
        if ( arr [ i ] in store ) :
            prime_sum_from_right += arr [ i ]
    for i in range ( N ) :
        if ( first_array [ i ] == second_array [ i ] ) :
            return i
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 4 , 7 , 6 , 13 , 1 , 5 ]
    N = len ( arr )
    print ( find_index ( arr , N ) )

Index/key variables: i
Accumulator variables: multiple, prime_sum_from_left, prime_sum_from_right
Iterator variables: i
Python program:
def convert ( arr , n ) :
    brr = [ i for i in arr ]
    brr = sorted ( brr )
    for i in range ( n ) :
        l , r , mid = 0 , n - 1 , 0
        while ( l <= r ) :
            mid = ( l + r ) // 2
            if ( brr [ mid ] == arr [ i ] ) :
                print ( mid , end = " ▁ " )
                break
            elif ( brr [ mid ] < arr [ i ] ) :
                l = mid + 1
            else :
                r = mid - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 20 , 15 , 12 , 11 , 50 ]
    N = len ( arr )
    convert ( arr , N )

Index/key variables: i, mid
Iterator variables: i
Python program:
from collections import defaultdict
import sys
import math
def findIndex ( arr , N ) :
    maxValue = - sys . maxsize - 1
    for i in range ( N ) :
        maxValue = max ( maxValue , arr [ i ] )
    St = defaultdict ( int )
    for i in range ( 1 , maxValue + 1 ) :
        St [ i ] += 1
    if ( 1 in St ) :
        St . pop ( 1 )
    for i in range ( 2 , int ( math . sqrt ( maxValue ) ) + 1 ) :
        j = 2
        while ( ( i * j ) <= maxValue ) :
            if ( i * j ) in St :
                St . pop ( i * j )
            j += 1
    LeftCount = 0
    Prefix = [ 0 ] * N
    for i in range ( N ) :
        Prefix [ i ] = LeftCount
        if ( arr [ i ] in St ) :
            LeftCount += 1
    RightCount = 0
    Suffix = [ 0 ] * N
    for i in range ( N - 1 , - 1 , - 1 ) :
        Suffix [ i ] = RightCount
        if arr [ i ] in St :
            RightCount += 1
    for i in range ( N ) :
        if ( Prefix [ i ] == Suffix [ i ] ) :
            return i
    return - 1
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 4 , 7 , 5 , 10 , 1 , 8 ]
    N = len ( arr )
    print ( findIndex ( arr , N ) )

Index/key variables: i
Accumulator variables: LeftCount, RightCount, j
Iterator variables: i
Python program:
def getCountPairs ( arr , N , S ) :
    count = 0
    for i in range ( len ( arr ) ) :
        for j in range ( i + 1 , len ( arr ) ) :
            if ( ( arr [ i ] + arr [ j ] ) == S ) :
                count += 1
    return count
def countPairs ( arr , N ) :
    count = 0
    S = set ( [ ] )
    for i in range ( N ) :
        S . add ( arr [ i ] )
    for ele in S :
        sum = 2 * ele
        count += getCountPairs ( arr , N , sum )
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 2 , 5 , 1 , 3 , 5 ]
    N = len ( arr )
    print ( countPairs ( arr , N ) )

Index/key variables: i, j
Accumulator variables: S, count
Iterator variables: ele, i, j
Python program:
from collections import defaultdict
import math
def isPowerOfTwo ( n ) :
    if ( n == 0 ) :
        return False
    return ( math . ceil ( math . log2 ( n ) ) == math . floor ( math . log2 ( n ) ) )
def printArray ( res ) :
    res . sort ( )
    for i in range ( len ( res ) ) :
        print ( res [ i ] , end = " ▁ " )
def sortedStrings ( S , N ) :
    freq = defaultdict ( int )
    res = [ ]
    for i in range ( N ) :
        st = " "
        for j in range ( len ( S [ i ] ) ) :
            freq [ S [ i ] [ j ] ] += 1
        for i in freq :
            if ( isPowerOfTwo ( freq [ i ] ) ) :
                for j in range ( freq [ i ] ) :
                    st += i
        freq . clear ( )
        if ( len ( st ) == 0 ) :
            continue
        st = list ( st )
        st . sort ( reverse = True )
        st = ' ' . join ( st )
        res . append ( st )
    printArray ( res )
if __name__ == " _ _ main _ _ " :
    arr = [ " aaacbb " , " geeks " , " aaa " ]
    N = len ( arr )
    sortedStrings ( arr , N )

Index/key variables: i, j
Accumulator variables: res, st
Iterator variables: i, j
Python program:
def replaceCharacters ( s , p ) :
    n , k = len ( s ) , len ( p )
    arr = [ 0 ] * 26
    brr = [ 0 ] * 26
    for i in range ( n ) :
        arr [ ord ( s [ i ] ) - ord ( ' a ' ) ] = s [ i ]
        brr [ ord ( s [ i ] ) - ord ( ' a ' ) ] = s [ i ]
    for j in range ( k ) :
        a , b = p [ j ] [ 0 ] , p [ j ] [ 1 ]
        for i in range ( 26 ) :
            if ( arr [ i ] == a ) :
                brr [ i ] = b
    for i in range ( n ) :
        print ( brr [ ord ( s [ i ] ) - ord ( ' a ' ) ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    S = " aabbgg "
    P = [ [ ' a ' , ' b ' ] , [ ' b ' , ' g ' ] , [ ' g ' , ' a ' ] ]
    replaceCharacters ( S , P )

Index/key variables: i, j
Iterator variables: i, j
Python program:
MAX = 100001
def SieveOfEratosthenes ( prime ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    p = 2
    while p * p < MAX :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , MAX , p ) :
                prime [ i ] = False
        p += 1
def smallestSemiPrime ( n ) :
    prime = [ True ] * MAX
    SieveOfEratosthenes ( prime )
    num1 = n + 1
    while ( prime [ num1 ] != True ) :
        num1 += 1
    num2 = num1 + n
    while ( prime [ num2 ] != True ) :
        num2 += 1
    print ( num1 * num2 )
if __name__ == " _ _ main _ _ " :
    N = 2
    smallestSemiPrime ( N )

Index/key variables: i, num1, num2, p
Iterator variables: i
Python program:
def productOfTwoPerfectCubes ( N ) :
    cubes = { }
    i = 1
    while i * i * i <= N :
        cubes [ i * i * i ] = i
        i += 1
    for itr in cubes :
        firstNumber = itr
        if ( N % itr == 0 ) :
            secondNumber = N // itr
            if ( secondNumber in cubes ) :
                print ( " Yes " )
                return
    print ( " No " )
if __name__ == " _ _ main _ _ " :
    N = 216
    productOfTwoPerfectCubes ( N )

Accumulator variables: i
Iterator variables: itr
Python program:
from math import sqrt
def printNumberOfPairs ( N ) :
    st = set ( )
    for i in range ( 2 , int ( sqrt ( N ) ) + 1 , 1 ) :
        x = i
        while ( x <= N ) :
            x *= i
            if ( x <= N ) :
                st . add ( x )
    print ( len ( st ) )
if __name__ == ' _ _ main _ _ ' :
    N = 10000
    printNumberOfPairs ( N )

Accumulator variables: st, x
Iterator variables: i
Python program:
def countSetBits ( n ) :
    count = 0
    while ( n > 0 ) :
        count += n & 1
        n >>= 1
    return count
def maximumProduct ( words ) :
    bits = [ 0 for i in range ( len ( words ) ) ]
    for i in range ( len ( words ) ) :
        for j in range ( len ( words [ i ] ) ) :
            bits [ i ] = bits [ i ] | 1 << ( ord ( words [ i ] [ j ] ) - 97 )
    result = 0
    for i in range ( len ( bits ) ) :
        for j in range ( i + 1 , len ( bits ) ) :
            if ( ( bits [ i ] & bits [ j ] ) == 0 ) :
                L = countSetBits ( bits [ i ] )
                R = countSetBits ( bits [ j ] )
                result = max ( L * R , result )
    print ( result )
if __name__ == ' _ _ main _ _ ' :
    arr = [ " abcw " , " baz " , " foo " , " bar " , " xtfn " , " abcdef " ]
    maximumProduct ( arr )

Index/key variables: i, j
Accumulator variables: count, n
Iterator variables: i, j
Python program:
def palindrome ( string ) :
    if ( string == string [ : : - 1 ] ) :
        return True
    else :
        return False
def printReverse ( sentence ) :
    newlist = [ ]
    lis = list ( sentence . split ( ) )
    for i in lis :
        if ( palindrome ( i ) ) :
            newlist . append ( i )
    newlist . reverse ( )
    j = 0
    for i in range ( len ( lis ) ) :
        if ( palindrome ( lis [ i ] ) ) :
            lis [ i ] = newlist [ j ]
            j = j + 1
    for i in lis :
        print ( i , end = " ▁ " )
sentence = " mom ▁ and ▁ dad ▁ went ▁ to ▁ eye ▁ hospital "
printReverse ( sentence )

Index/key variables: i, j
Accumulator variables: newlist
Iterator variables: i
Python program:
def minCount ( A , B , N ) :
    i = 0
    for j in range ( N ) :
        if ( A [ i ] == B [ j ] ) :
            i += 1
    return N - i
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 4 , 5 ]
    B = [ 1 , 5 , 2 , 3 , 4 ]
    N = len ( A )
    print ( minCount ( A , B , N ) )

Index/key variables: i, j
Iterator variables: j
Python program:
def possible ( A , N , mid , K ) :
    count = 0
    for i in range ( N ) :
        count += ( A [ i ] - 1 ) // mid
    return count <= K
def minimumMaximum ( A , N , K ) :
    lo = 1
    hi = max ( A )
    while ( lo < hi ) :
        mid = ( lo + hi ) // 2
        if ( possible ( A , N , mid , K ) ) :
            hi = mid
        else :
            lo = mid + 1
    return hi
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 8 , 2 ]
    K = 4
    N = len ( arr )
    print ( minimumMaximum ( arr , N , K ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def maximumNumber ( arr , N , K ) :
    minimum = min ( arr )
    ans = minimum + K
    for i in range ( N ) :
        if ( abs ( arr [ i ] - ans ) > K ) :
            ans = - 1
            break
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 5 ]
    K = 2
    N = len ( arr )
    maximumNumber ( arr , N , K )

Index/key variables: i
Iterator variables: i
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 sumOfPrimeSquare ( n ) :
    i = 0
    squares = [ ]
    while ( i * i < n ) :
        squares . append ( i * i )
        i += 1
    flag = False
    for i in range ( len ( squares ) ) :
        difference = n - squares [ i ]
        if ( isPrime ( difference ) ) :
            flag = True
            break
    if ( flag ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    N = 27
    sumOfPrimeSquare ( N )

Index/key variables: i
Accumulator variables: squares
Iterator variables: i
Boolean variables: flag
Python program:
import math
def SieveOfEratosthenes ( prime , n ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , int ( n ** ( 1 / 2 ) ) ) :
        if ( prime [ p ] == True ) :
            for i in range ( p ** 2 , n + 1 , p ) :
                prime [ i ] = False
def sumOfPrimeSquare ( n ) :
    flag = False
    prime = [ True ] * ( n + 1 )
    SieveOfEratosthenes ( prime , n )
    for i in range ( n + 1 ) :
        if ( not prime [ i ] ) :
            continue
        dif = n - i
        if ( math . ceil ( dif ** ( 1 / 2 ) ) == math . floor ( dif ** ( 1 / 2 ) ) ) :
            flag = True
            break
    if ( flag ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == " _ _ main _ _ " :
    N = 27
    sumOfPrimeSquare ( N )

Index/key variables: i, p
Iterator variables: i, p
Boolean variables: flag
Python program:
def check ( arr , M , K , ind ) :
    for i in range ( M ) :
        for j in range ( 1 , K , 1 ) :
            if ( arr [ ind + i ] != arr [ ind + i + j * M ] ) :
                return False
    return True
def SubarrayRepeatsKorMore ( arr , N , M , K ) :
    for ind in range ( N - M * K + 1 ) :
        if ( check ( arr , M , K , ind ) ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 2 , 1 , 1 , 1 , 3 ]
    M = 2
    K = 2
    N = len ( arr )
    if ( SubarrayRepeatsKorMore ( arr , N , M , K ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Iterator variables: i, ind, j
Python program:
def checkExists ( arr , N , M , K ) :
    count = 0
    for i in range ( N - M ) :
        if ( arr [ i ] == arr [ i + M ] ) :
            count += 1
        else :
            count = 0
        if ( count == M * ( K - 1 ) ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 2 , 1 , 1 , 1 , 3 ]
    N = len ( arr )
    M = 2
    K = 2
    if ( checkExists ( arr , N , M , K ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def CommonDigits ( N , M ) :
    count = 0
    freq1 = [ 0 ] * 10
    freq2 = [ 0 ] * 10
    while ( N > 0 ) :
        freq1 [ N % 10 ] += 1
        N = N // 10
    while ( M > 0 ) :
        freq2 [ M % 10 ] += 1
        M = M // 10
    for i in range ( 10 ) :
        if ( freq1 [ i ] > 0 and freq2 [ i ] > 0 ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    N = 748294
    M = 34298156
    print ( CommonDigits ( N , M ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def minimumNumber ( K , X ) :
    if ( K > X ) :
        print ( " - 1" )
        return
    ans = 0
    sum = 0
    for i in range ( K , X + 1 ) :
        sum += i
        if ( sum >= X ) :
            ans = i
            break
    print ( ans )
K = 5
X = 13
minimumNumber ( K , X )

Accumulator variables: sum
Iterator variables: i
Python program:
def CountPairs ( arr , n ) :
    count = 0
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            if ( ( i * j ) == ( arr [ i ] * arr [ j ] ) ) :
                count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 0 , 3 , 2 , 6 ]
    N = len ( arr )
    print ( CountPairs ( arr , N ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
from bisect import bisect_left
def maxRemainder ( A , N , K ) :
    even = { }
    odd = { }
    for i in range ( N ) :
        num = A [ i ]
        if ( num % 2 == 0 ) :
            even [ num % K ] = 1
        else :
            odd [ num % K ] = 1
    max_rem = 0
    for x in even :
        y = K - 1 - x
        od = list ( odd . keys ( ) )
        it = bisect_left ( od , y )
        if ( it != 0 ) :
            max_rem = max ( max_rem , x + od [ it ] )
    print ( max_rem )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 4 , 11 , 6 , 7 ]
    N = len ( arr )
    K = 7
    maxRemainder ( arr , N , K )

Index/key variables: i, it
Iterator variables: i, x
Python program:
visited = [ False for i in range ( 4 ) ]
def dfs ( src , Adj , level , distance ) :
    global visited
    visited [ src ] = True
    distance = max ( distance , level )
    for child in Adj [ src ] :
        if ( child != src and visited [ child ] == False ) :
            dfs ( child , Adj , level + 1 , distance )
    visited [ src ] = False
def maximumLength ( mat , V ) :
    distance = 0
    N = len ( mat )
    Adj = [ [ ] for i in range ( N ) ]
    for i in range ( N ) :
        for j in range ( N ) :
            if ( mat [ i ] [ j ] == 1 ) :
                Adj [ i ] . append ( j )
    dfs ( V , Adj , 0 , distance )
    return distance + 2
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 0 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] ]
    V = 2
    print ( maximumLength ( mat , V ) )

Index/key variables: child, i, j, src
Iterator variables: child, i, j
Python program:
def findLength ( s , i , j ) :
    required = i
    length = 0
    for curr in s :
        if ( curr == required ) :
            length += 1
            if ( required == i ) :
                required = j
            else :
                required = i
    return length
def minimumDeletions ( S ) :
    len1 = 0
    n = len ( S )
    for i in range ( 0 , 26 , 1 ) :
        for j in range ( i + 1 , 26 , 1 ) :
            newLen = findLength ( S , chr ( i + 97 ) , chr ( j + 97 ) )
            len1 = max ( len1 , newLen )
    return n - len1
if __name__ == ' _ _ main _ _ ' :
    S = " adebbeeaebd "
    print ( minimumDeletions ( S ) )

Accumulator variables: length
Iterator variables: curr, i, j
Python program:
import math
def inv ( a , m ) :
    m0 = m
    x0 = 0
    x1 = 1
    if ( m == 1 ) :
        return 0
    while ( a > 1 ) :
        q = a // m
        t = m
        m = a % m
        a = t
        t = x0
        x0 = x1 - q * x0
        x1 = t
    if ( x1 < 0 ) :
        x1 += m0
    return x1
def findMinX ( A , B , N ) :
    prod = 1
    for i in range ( N ) :
        prod *= A [ i ]
    result = 0
    for i in range ( N ) :
        pp = prod // A [ i ]
        result += B [ i ] * inv ( pp , A [ i ] ) * pp
    return result % prod
def product ( a , n ) :
    ans = 1
    for i in range ( n ) :
        ans *= a [ i ]
    return ans
def findSmallestInteger ( A , B , P , n ) :
    Y = findMinX ( A , B , n )
    M = product ( A , n )
    K = math . ceil ( ( P - Y ) / M )
    X = Y + K * M
    print ( X )
if __name__ == " _ _ main _ _ " :
    A = [ 3 , 4 , 5 ]
    B = [ 2 , 3 , 1 ]
    n = len ( A )
    P = 72
    findSmallestInteger ( A , B , P , n )

Index/key variables: i
Accumulator variables: ans, prod, result
Iterator variables: i
Python program:
def minJumps ( arr , jump , N ) :
    jumps = 0
    temp = [ 0 for i in range ( 1000 ) ]
    vect = [ ]
    for i in range ( N ) :
        vect . append ( [ arr [ i ] , i + 1 ] )
    for i in range ( N ) :
        temp [ arr [ i ] ] = jump [ i ]
    vect . sort ( reverse = False )
    for i in range ( N ) :
        while ( vect [ i ] [ 1 ] <= vect [ i - 1 ] [ 1 ] ) :
            vect [ i ] = [ vect [ i ] [ 0 ] , vect [ i ] [ 1 ] + temp [ vect [ i ] [ 0 ] ] ]
            jumps += 1
    print ( jumps )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 1 ]
    jump = [ 1 , 1 , 1 ]
    N = len ( arr )
    minJumps ( arr , jump , N )

Index/key variables: i
Accumulator variables: jumps, vect
Iterator variables: i
Python program:
def numberOfGates ( s ) :
    N = len ( s )
    ans = 0
    for i in range ( len ( s ) ) :
        if ( s [ i ] == ' . ' or s [ i ] == ' + ' or s [ i ] == '1' ) :
            ans += 1
    print ( ans , end = " " )
if __name__ == " _ _ main _ _ " :
    S = " ( 1 - A ) . B + C "
    numberOfGates ( S )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def findPairs ( arr , N ) :
    for i in range ( N ) :
        arr [ i ] = abs ( arr [ i ] )
    arr . sort ( )
    left = 0
    ans = 0
    for right in range ( N ) :
        while ( 2 * arr [ left ] < arr [ right ] ) :
            left += 1
        ans += ( right - left )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 5 , 7 ]
    N = len ( arr )
    findPairs ( arr , N )

Index/key variables: i, left, right
Accumulator variables: ans
Iterator variables: i, right
Python program:
import sys
def GetDiff ( A , N ) :
    SuffMaxArr = [ 0 for i in range ( N ) ]
    SuffMaxArr [ N - 1 ] = A [ N - 1 ]
    i = N - 2
    while ( i >= 0 ) :
        SuffMaxArr [ i ] = max ( SuffMaxArr [ i + 1 ] , A [ i + 1 ] )
        i -= 1
    MaximumSum = - sys . maxsize - 1
    for i in range ( N - 1 ) :
        if ( A [ i ] < SuffMaxArr [ i ] ) :
            MaximumSum = max ( MaximumSum , A [ i ] + SuffMaxArr [ i ] )
    MinimumSum = sys . maxsize
    SuffMinArr = [ 0 for i in range ( N ) ]
    SuffMinArr [ N - 1 ] = sys . maxsize
    i = N - 2
    while ( i >= 0 ) :
        SuffMinArr [ i ] = min ( SuffMinArr [ i + 1 ] , A [ i + 1 ] )
        i -= 1
    for i in range ( N - 1 ) :
        if ( A [ i ] < SuffMinArr [ i ] ) :
            MinimumSum = min ( MinimumSum , A [ i ] + SuffMinArr [ i ] )
    return abs ( MaximumSum - MinimumSum )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 1 , 3 , 7 , 5 , 6 ]
    N = len ( arr )
    print ( GetDiff ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def minimumSwaps ( arr , N ) :
    even , odd = 0 , 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 != i % 2 ) :
            if ( i % 2 == 0 ) :
                even += 1
            else :
                odd += 1
    if ( even != odd ) :
        print ( - 1 )
    else :
        print ( even )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 7 , 6 ]
    N = len ( arr )
    minimumSwaps ( arr , N )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
from collections import Counter
def smallestSubstring ( a ) :
    a1 = [ ]
    for i in range ( len ( a ) ) :
        for j in range ( i + 1 , len ( a ) ) :
            if i != j :
                a1 . append ( a [ i : j + 1 ] )
    a2 = Counter ( a1 )
    freshlist = [ ]
    for i in a2 :
        if a2 [ i ] == 1 :
            freshlist . append ( i )
    dictionary = dict ( )
    for i in range ( len ( freshlist ) ) :
        dictionary [ freshlist [ i ] ] = len ( freshlist [ i ] )
    newlist = [ ]
    for i in dictionary :
        newlist . append ( dictionary [ i ] )
    return ( min ( newlist ) )
S = " ababaabba "
print ( smallestSubstring ( S ) )

Index/key variables: i
Accumulator variables: a1, freshlist, newlist
Iterator variables: i, j
Python program:
def mininsert ( arr , K , N ) :
    ans = 0
    for i in range ( N - 1 ) :
        a = min ( arr [ i ] , arr [ i + 1 ] )
        b = max ( arr [ i ] , arr [ i + 1 ] )
        while ( K * a < b ) :
            a *= K
            ans += 1
    return ans
arr = [ 2 , 10 , 25 , 21 ]
K = 2
N = len ( arr )
print ( mininsert ( arr , K , N ) )

Index/key variables: i
Accumulator variables: a, ans
Iterator variables: i
Python program:
def sumOfDigits ( s ) :
    curr = 0
    ret = 0
    for ch in s :
        if ( ord ( ch ) >= 48 and ord ( ch ) <= 57 ) :
            curr = curr * 10 + ord ( ch ) - ord ( '0' )
        else :
            ret += curr
            curr = 0
    ret += curr
    return ret
S = "11aa32bbb5"
print ( sumOfDigits ( S ) )

Accumulator variables: ret
Iterator variables: ch
Python program:
def print_triplet ( arr , n ) :
    for i in range ( 1 , n - 1 ) :
        if ( arr [ i - 1 ] < arr [ i ] and arr [ i ] > arr [ i + 1 ] ) :
            print ( i - 1 , i , i + 1 )
            return
    print ( - 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 3 , 5 , 2 , 1 , 6 ]
    N = len ( arr )
    print_triplet ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
from collections import defaultdict
def findConcatenatedNumbers ( a , b ) :
    ans = True
    n1 = len ( a )
    n2 = len ( b )
    cnt = defaultdict ( int )
    for i in range ( n1 ) :
        cnt [ a [ i ] ] = 1
    for i in range ( n2 ) :
        left = b [ i ]
        right = 0
        mul = 1
        while ( left > 9 ) :
            right += ( left % 10 ) * mul
            left //= 10
            mul *= 10
            if ( cnt [ left ] == 1 and cnt [ right ] == 1 ) :
                ans = False
                print ( b [ i ] , end = " ▁ " )
    if ( ans ) :
        print ( " - 1" )
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 34 , 4 , 5 ]
    b = [ 26 , 24 , 345 , 4 , 22 ]
    findConcatenatedNumbers ( a , b )

Index/key variables: i, left, right
Accumulator variables: mul
Iterator variables: i
Boolean variables: ans