dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
MAX = 26
def countPairs ( string , k ) :
    n = len ( string ) ;
    freq = [ 0 ] * MAX ;
    for i in range ( n ) :
        freq [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1 ;
    cnt = 0 ;
    if ( k == 0 ) :
        for i in range ( MAX ) :
            if ( freq [ i ] > 1 ) :
                cnt += ( ( freq [ i ] * ( freq [ i ] - 1 ) ) // 2 ) ;
    else :
        for i in range ( MAX ) :
            if ( freq [ i ] > 0 and i + k < MAX and freq [ i + k ] > 0 ) :
                cnt += ( freq [ i ] * freq [ i + k ] ) ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    string = " abcdab " ;
    k = 0 ;
    print ( countPairs ( string , k ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def isPalin ( i , j , k , l , p , q , s ) :
    start = i ; end = q ;
    while ( start < end ) :
        if ( s [ start ] != s [ end ] ) :
            return False ;
        start += 1 ;
        if ( start == j + 1 ) :
            start = k ;
        end -= 1 ;
        if ( end == p - 1 ) :
            end = l ;
    return True ;
def countSubStr ( s ) :
    count = 0 ;
    n = len ( s ) ;
    for i in range ( n - 2 ) :
        for j in range ( i , n - 2 ) :
            for k in range ( j + 1 , n - 1 ) :
                for l in range ( k , n - 1 ) :
                    for p in range ( l + 1 , n ) :
                        for q in range ( p , n ) :
                            if ( isPalin ( i , j , k , l , p , q , s ) ) :
                                count += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    s = " abca " ;
    print ( countSubStr ( s ) ) ;

Index/key variables: end, start
Accumulator variables: count
Iterator variables: i, j, k, l, p, q
Python program:
from math import sqrt
def isPrime ( n ) :
    if ( n == 0 or n == 1 ) :
        return False ;
    for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            return False ;
    return True ;
def sumAscii ( string , n ) :
    sum = 0 ;
    for i in range ( n ) :
        if ( isPrime ( i + 1 ) ) :
            sum += ord ( string [ i ] ) ;
    return sum ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    n = len ( string ) ;
    print ( sumAscii ( string , n ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
graph = [ [ ] for i in range ( 100 ) ]
weight = [ 0 ] * 100
def Pangram ( x ) :
    mp = { }
    n = len ( x )
    for i in range ( n ) :
        if x [ i ] not in mp :
            mp [ x [ i ] ] = 0
        mp [ x [ i ] ] += 1
    if ( len ( mp ) == 26 ) :
        return True
    else :
        return False
def countTotalPangram ( n ) :
    cnt = 0
    for i in range ( 1 , n + 1 ) :
        if ( Pangram ( weight [ i ] ) ) :
            cnt += 1
    return cnt
def dfs ( node , parent ) :
    for to in graph [ node ] :
        if ( to == parent ) :
            continue
        dfs ( to , node )
        weight [ node ] += weight [ to ]
n = 6
weight [ 1 ] = " abcde "
weight [ 2 ] = " fghijkl "
weight [ 3 ] = " abcdefg "
weight [ 4 ] = " mnopqr "
weight [ 5 ] = " stuvwxy "
weight [ 6 ] = " zabcdef "
graph [ 1 ] . append ( 2 )
graph [ 2 ] . append ( 3 )
graph [ 2 ] . append ( 4 )
graph [ 1 ] . append ( 5 )
graph [ 5 ] . append ( 6 )
dfs ( 1 , 1 )
print ( countTotalPangram ( n ) )

Index/key variables: i, node, to
Accumulator variables: cnt
Iterator variables: i, to
Python program:
cnt = 0
graph = [ [ ] for i in range ( 100 ) ]
weight = [ 0 ] * 100
def uniqueChars ( x ) :
    mp = { }
    n = len ( x )
    for i in range ( n ) :
        if x [ i ] not in mp :
            mp [ x [ i ] ] = 0
        mp [ x [ i ] ] += 1
    if ( len ( mp ) == len ( x ) ) :
        return True
    else :
        return False
def dfs ( node , parent ) :
    global cnt , x
    if ( uniqueChars ( weight [ node ] ) ) :
        cnt += 1
    for to in graph [ node ] :
        if ( to == parent ) :
            continue
        dfs ( to , node )
x = 5
weight [ 1 ] = " abc "
weight [ 2 ] = " aba "
weight [ 3 ] = " bcb "
weight [ 4 ] = " moh "
weight [ 5 ] = " aa "
graph [ 1 ] . append ( 2 )
graph [ 2 ] . append ( 3 )
graph [ 2 ] . append ( 4 )
graph [ 1 ] . append ( 5 )
dfs ( 1 , 1 )
print ( cnt )

Index/key variables: i, node
Iterator variables: i, to
Python program:
MAX = 256 ;
def lastNonRepeating ( string , n ) :
    freq = [ 0 ] * MAX ;
    for i in range ( n ) :
        freq [ ord ( string [ i ] ) ] += 1 ;
    for i in range ( n - 1 , - 1 , - 1 ) :
        ch = string [ i ] ;
        if ( freq [ ord ( ch ) ] == 1 ) :
            return ( " " + ch ) ;
    return " - 1" ;
if __name__ == " _ _ main _ _ " :
    string = " GeeksForGeeks " ;
    n = len ( string ) ;
    print ( lastNonRepeating ( string , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def findCount ( s , n , a , b ) :
    res = 0
    for i in range ( b ) :
        if ( i == a ) :
            res += ( s [ n - i - 1 ] != '1' )
        else :
            res += ( s [ n - i - 1 ] != '0' )
    return res
if __name__ == ' _ _ main _ _ ' :
    str = "1001011001"
    N = len ( str )
    A = 3
    B = 6
    print ( findCount ( str , N , A , B ) )

Accumulator variables: res
Iterator variables: i
Python program:
NUM = 31
def positions ( str ) :
    for i in str :
        print ( ( ord ( i ) & NUM ) , end = " ▁ " )
str = " Geeks "
positions ( str )

Iterator variables: i
Python program:
def permute ( str , l , r ) :
    if ( l == r ) :
        if " AB " not in ' ' . join ( str ) :
            print ( ' ' . join ( str ) , end = " ▁ " )
        return
    for i in range ( l , r + 1 ) :
        str [ l ] , str [ i ] = str [ i ] , str [ l ]
        permute ( str , l + 1 , r )
        str [ l ] , str [ i ] = str [ i ] , str [ l ]
str = " ABC "
permute ( list ( str ) , 0 , len ( str ) - 1 )

Index/key variables: i, l
Iterator variables: i
Python program:
def lenoflongestnonpalindrome ( s ) :
    max1 , length = 1 , 0
    for i in range ( 0 , len ( s ) - 1 ) :
        if s [ i ] == s [ i + 1 ] :
            length = 0
        elif s [ i + 1 ] == s [ i - 1 ] and i > 0 :
            length = 1
            length += 1
    if max1 == 1 :
        return 0
    else :
        return max1
if __name__ == " _ _ main _ _ " :
    s = " synapse "
    print ( lenoflongestnonpalindrome ( s ) )

Index/key variables: i
Accumulator variables: length
Iterator variables: i
Python program:
def calcScore ( str ) :
    score = 0
    len1 = len ( str )
    i = 0
    while ( i < len1 ) :
        chunkSize = 1
        currentChar = str [ i ]
        i += 1
        while ( i < len1 and str [ i ] == currentChar ) :
            chunkSize += 1
            i += 1
        if ( currentChar == '1' ) :
            score += pow ( chunkSize , 2 )
        else :
            score -= pow ( chunkSize , 2 )
    return score
if __name__ == ' _ _ main _ _ ' :
    str = "11011"
    print ( calcScore ( str ) )

Index/key variables: i
Accumulator variables: chunkSize, score
Python program:
def countSubString ( s , c , k ) :
    leftCount = 0
    rightCount = 0
    left = 0
    right = 0
    freq = 0
    result = 0
    len1 = len ( s )
    while ( s [ left ] != c and left < len1 ) :
        left += 1
        leftCount += 1
    right = left + 1
    while ( freq != ( k - 1 ) and ( right - 1 ) < len1 ) :
        if ( s [ right ] == c ) :
            freq += 1
        right += 1
    while ( left < len1 and ( right - 1 ) < len1 ) :
        while ( s [ left ] != c and left < len1 ) :
            left += 1
            leftCount += 1
        while ( right < len1 and s [ right ] != c ) :
            if ( s [ right ] == c ) :
                freq += 1
            right += 1
            rightCount += 1
        result = ( result + ( leftCount + 1 ) * ( rightCount + 1 ) )
        freq = k - 1
        leftCount = 0
        rightCount = 0
        left += 1
        right += 1
    return result
if __name__ == ' _ _ main _ _ ' :
    s = " abada "
    c = ' a '
    k = 2
    print ( countSubString ( s , c , k ) )

Index/key variables: left, right
Accumulator variables: freq, leftCount, rightCount
Python program:
N = 4
def performQueries ( l , r , prefix ) :
    l -= 1
    r -= 1
    flag = False
    count = 0
    for i in range ( 26 ) :
        cnt = prefix [ r ] [ i ]
        if ( l > 0 ) :
            cnt -= prefix [ l - 1 ] [ i ]
        if ( cnt % 2 == 1 ) :
            flag = True
            count += cnt - 1
        else :
            count += cnt
    if ( flag ) :
        count += 1
    return count
def preCalculate ( s , prefix ) :
    n = len ( s )
    for i in range ( n ) :
        prefix [ i ] [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 1 , n ) :
        for j in range ( 26 ) :
            prefix [ i ] [ j ] += prefix [ i - 1 ] [ j ]
s = " amim "
prefix = [ [ 0 for i in range ( 26 ) ] for i in range ( N ) ]
preCalculate ( s , prefix )
queries = [ [ 1 , 4 ] , [ 3 , 4 ] ]
q = len ( queries )
for i in range ( q ) :
    print ( performQueries ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , prefix ) )

Index/key variables: i, j, r
Accumulator variables: cnt, count
Iterator variables: i, j
Boolean variables: flag
Python program:
from bisect import bisect_right as upper_bound
from collections import defaultdict
def numOccurences ( arr : list , n : int , string : str , L : int , R : int ) -> int :
    M = defaultdict ( lambda : list )
    for i in range ( n ) :
        temp = arr [ i ]
        if temp not in M :
            A = [ ]
            A . append ( i + 1 )
            M [ temp ] = A
        else :
            M [ temp ] . append ( i + 1 )
    if string not in M :
        return 0
    A = M [ string ]
    y = upper_bound ( A , R )
    x = upper_bound ( A , L - 1 )
    return ( y - x )
if __name__ == " _ _ main _ _ " :
    arr = [ " abc " , " abcabc " , " abc " ]
    n = len ( arr )
    L = 1
    R = 3
    string = " abc "
    print ( numOccurences ( arr , n , string , L , R ) )

Index/key variables: i, string, temp
Accumulator variables: A
Iterator variables: i
Python program:
def isValid ( str1 , n ) :
    if ( ( ( ord ( str1 [ 0 ] ) >= ord ( ' a ' ) and ord ( str1 [ 0 ] ) <= ord ( ' z ' ) ) or ( ord ( str1 [ 0 ] ) >= ord ( ' A ' ) and ord ( str1 [ 0 ] ) <= ord ( ' Z ' ) ) or ord ( str1 [ 0 ] ) == ord ( ' _ ' ) ) == False ) :
        return False
    for i in range ( 1 , len ( str1 ) ) :
        if ( ( ( ord ( str1 [ i ] ) >= ord ( ' a ' ) and ord ( str1 [ i ] ) <= ord ( ' z ' ) ) or ( ord ( str1 [ i ] ) >= ord ( ' A ' ) and ord ( str1 [ i ] ) <= ord ( ' Z ' ) ) or ( ord ( str1 [ i ] ) >= ord ( '0' ) and ord ( str1 [ i ] ) <= ord ( '9' ) ) or ord ( str1 [ i ] ) == ord ( ' _ ' ) ) == False ) :
            return False
    return True
str1 = " _ geeks123"
n = len ( str1 )
if ( isValid ( str1 , n ) ) :
    print ( " Valid " )
else :
    print ( " Invalid " )

Index/key variables: i
Iterator variables: i
Python program:
def check ( s , l ) :
    pos = [ ]
    for i in range ( l ) :
        if ( s [ i ] == '1' ) :
            pos . append ( i )
    t = len ( pos )
    for i in range ( 1 , t ) :
        if ( ( pos [ i ] - pos [ i - 1 ] ) != ( pos [ 1 ] - pos [ 0 ] ) ) :
            return False
    return True
s = "100010001000"
l = len ( s )
if ( check ( s , l ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Accumulator variables: pos
Iterator variables: i
Python program:
def FirstAndLast ( string ) :
    ch = list ( string ) ;
    i = 0 ;
    while i < len ( ch ) :
        k = i ;
        while ( i < len ( ch ) and ch [ i ] != ' ▁ ' ) :
            i += 1 ;
        if ( ord ( ch [ k ] ) >= 97 and ord ( ch [ k ] ) <= 122 ) :
            ch [ k ] = chr ( ord ( ch [ k ] ) - 32 ) ;
        else :
            ch [ k ] = ch [ k ]
        if ( ord ( ch [ i - 1 ] ) >= 90 and ord ( ch [ i - 1 ] ) <= 122 ) :
            ch [ i - 1 ] = chr ( ord ( ch [ i - 1 ] ) - 32 ) ;
        else :
            ch [ i - 1 ] = ch [ i - 1 ]
        i += 1
    return " " . join ( ch ) ;
if __name__ == " _ _ main _ _ " :
    string = " Geeks ▁ for ▁ Geeks " ;
    print ( string ) ;
    print ( FirstAndLast ( string ) ) ;

Index/key variables: i, k
Python program:
def findM ( s , x ) :
    cnt = 0
    for i in range ( len ( s ) ) :
        if ( ord ( s [ i ] ) - ord ( '0' ) != x ) :
            cnt += 1
    return cnt
if __name__ == ' _ _ main _ _ ' :
    s = "3662123"
    x = 6
    print ( findM ( s , x ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def compute_lps ( s ) :
    n = len ( s )
    lps = [ 0 for i in range ( n ) ]
    Len = 0
    lps [ 0 ] = 0
    i = 1
    while ( i < n ) :
        if ( s [ i ] == s [ Len ] ) :
            Len += 1
            lps [ i ] = Len
            i += 1
        else :
            if ( Len != 0 ) :
                Len = lps [ Len - 1 ]
            else :
                lps [ i ] = 0
                i += 1
    return lps
def Longestsubstring ( s ) :
    lps = compute_lps ( s )
    n = len ( s )
    if ( lps [ n - 1 ] == 0 ) :
        print ( - 1 )
        exit ( )
    for i in range ( 0 , n - 1 ) :
        if ( lps [ i ] == lps [ n - 1 ] ) :
            print ( s [ 0 : lps [ i ] ] )
            exit ( )
    if ( lps [ lps [ n - 1 ] - 1 ] == 0 ) :
        print ( - 1 )
    else :
        print ( s [ 0 : lps [ lps [ n - 1 ] - 1 ] ] )
s = " fixprefixsuffix "
Longestsubstring ( s )

Index/key variables: Len, i
Iterator variables: i
Python program:
def pair_count ( d ) :
    return sum ( ( i * ( i - 1 ) ) // 2 for i in d . values ( ) )
def Difference ( array , m ) :
    changed , same = { } , { }
    for s in array :
        same [ s ] = same . get ( s , 0 ) + 1
        for i in range ( m ) :
            changed [ t ] = changed . get ( t , 0 ) + 1
    return pair_count ( changed ) - pair_count ( same ) * m
if __name__ == " _ _ main _ _ " :
    n , m = 3 , 3
    array = [ " abc " , " abd " , " bbd " ]
    print ( Difference ( array , m ) )

Index/key variables: s, t
Iterator variables: i, s
Python program:
def calculateWays ( s , n , l , r ) :
    freq = [ 0 for i in range ( 26 ) ]
    for i in range ( n ) :
        if ( i < l or i > r ) :
            freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    ways = 1
    for i in range ( l , r + 1 , 1 ) :
        if ( freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] ) :
            ways = ways * freq [ ord ( s [ i ] ) - ord ( ' a ' ) ]
            freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] -= 1
        else :
            ways = 0
            break
    return ways
if __name__ == ' _ _ main _ _ ' :
    s = " cabcaab "
    n = len ( s )
    l = 1
    r = 3
    print ( calculateWays ( s , n , l , r ) )

Index/key variables: i
Iterator variables: i
Python program:
def findKthChar ( s , k ) :
    len1 = len ( s )
    i = 0
    total_len = 0
    while ( i < len1 ) :
        if ( s [ i ] . isalpha ( ) ) :
            total_len += 1
            if ( total_len == k ) :
                return s [ i ]
            i += 1
        else :
            n = 0
            while ( i < len1 and s [ i ] . isalpha ( ) == False ) :
                n = n * 10 + ( ord ( s [ i ] ) - ord ( '0' ) )
                i += 1
            next_total_len = total_len * n
            if ( k <= next_total_len ) :
                pos = k % total_len
                if ( pos == 0 ) :
                    pos = total_len
                return findKthChar ( s , pos )
            else :
                total_len = next_total_len
    return - 1
if __name__ == ' _ _ main _ _ ' :
    s = " ab2c3"
    k = 5
    print ( findKthChar ( s , k ) )

Index/key variables: i
Accumulator variables: total_len
Python program:
from math import floor
def check_char ( st , ch ) :
    l = len ( st )
    for i in range ( l ) :
        if ( st [ i ] == ch ) :
            return True
    return False
def find_avg ( st ) :
    sm = 0
    l = len ( st )
    for i in range ( l ) :
        ch = st [ i ]
        sm = sm + ord ( ch )
    avg = int ( floor ( sm / l ) )
    return ( chr ( avg ) )
if __name__ == ' _ _ main _ _ ' :
    st = " ag23sdfa "
    ch = find_avg ( st )
    print ( ch )
    if ( check_char ( st , ch ) == True ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def asciiToSentence ( string , length ) :
    num = 0 ;
    for i in range ( length ) :
        num = num * 10 + ( ord ( string [ i ] ) - ord ( '0' ) ) ;
        if ( num >= 32 and num <= 122 ) :
            ch = chr ( num ) ;
            print ( ch , end = " " ) ;
            num = 0 ;
if __name__ == " _ _ main _ _ " :
    string = "7110110110711510211111471101101107115" ;
    length = len ( string ) ;
    asciiToSentence ( string , length ) ;

Index/key variables: i
Iterator variables: i
Python program:
def countDistinctCode ( string ) :
    codes = set ( )
    for i in range ( 0 , len ( string ) - 1 ) :
        codes . add ( string [ i : i + 2 ] )
    return len ( codes )
if __name__ == " _ _ main _ _ " :
    string = " UPUP "
    print ( countDistinctCode ( string ) )

Accumulator variables: codes
Iterator variables: i
Python program:
arr = [ 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 1 , 2 , 3 , 4 ] ;
def countKeyPressed ( string , length ) :
    count = 0 ;
    for i in range ( length ) :
        count += arr [ ord ( string [ i ] ) - ord ( ' a ' ) ] ;
    return count ;
if __name__ == " _ _ main _ _ " :
    string = " abcdef " ;
    length = len ( string ) ;
    print ( countKeyPressed ( string , length ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def isReverseEqual ( s1 , s2 ) :
    if len ( s1 ) != len ( s2 ) :
        return False
    l = len ( s1 )
    for i in range ( l ) :
        if s1 [ i ] != s2 [ l - i - 1 ] :
            return False
    return True
def getWord ( str , n ) :
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            if ( isReverseEqual ( str [ i ] , str [ j ] ) ) :
                return str [ i ]
    return " - 1"
if __name__ == " _ _ main _ _ " :
    str = [ " geeks " , " for " , " skeeg " ]
    print ( getWord ( str , 3 ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isPrefix ( string , length , i , k ) :
    if i + k > length :
        return False
    for j in range ( 0 , k ) :
        if string [ i ] != string [ j ] :
            return False
        i += 1
    return True
def isKPeriodic ( string , length , k ) :
    for i in range ( k , length , k ) :
        if isPrefix ( string , length , i , k ) == False :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    string = " geeksgeeks "
    length = len ( string )
    k = 5
    if isKPeriodic ( string , length , k ) == True :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findMaxLenEven ( str ) :
    n = len ( str )
    i = 0
    currlen = 0
    maxlen = 0
    st = - 1
    while ( i < n ) :
        if ( str [ i ] == ' ▁ ' ) :
            if ( currlen % 2 == 0 ) :
                if ( maxlen < currlen ) :
                    maxlen = currlen
                    st = i - currlen
            currlen = 0
        else :
            currlen += 1
        i += 1
    if ( currlen % 2 == 0 ) :
        if ( maxlen < currlen ) :
            maxlen = currlen
            st = i - currlen
    if ( st == - 1 ) :
        print ( " trie " )
        return " - 1"
    return str [ st : st + maxlen ]
if __name__ == " _ _ main _ _ " :
    str = " this ▁ is ▁ a ▁ test ▁ string "
    print ( findMaxLenEven ( str ) )

Index/key variables: i
Accumulator variables: currlen
Python program:
def findMinLenStr ( str , k ) :
    n = len ( str )
    st = 0
    end = 0
    cnt = [ 0 ] * 26
    distEle = 0
    currlen = 0
    minlen = n
    startInd = - 1
    while ( end < n ) :
        cnt [ ord ( str [ end ] ) - ord ( ' a ' ) ] += 1
        if ( cnt [ ord ( str [ end ] ) - ord ( ' a ' ) ] == 1 ) :
            distEle += 1
        if ( distEle > k ) :
            while ( st < end and distEle > k ) :
                if ( cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] == 1 ) :
                    distEle -= 1
                cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] -= 1
                st += 1
        if ( distEle == k ) :
            while ( st < end and cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] > 1 ) :
                cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] -= 1
                st += 1
            currlen = end - st + 1
            if ( currlen < minlen ) :
                minlen = currlen
                startInd = st
        end += 1
    return str [ startInd : startInd + minlen ]
if __name__ == " _ _ main _ _ " :
    str = " efecfefd "
    k = 4
    print ( findMinLenStr ( str , k ) )

Index/key variables: end, st
Accumulator variables: distEle
Python program:
def minReplacement ( s , length ) :
    ans = 0
    for i in range ( 0 , length ) :
        if i % 2 == 0 and s [ i ] == '1' :
            ans += 1
        if i % 2 == 1 and s [ i ] == '0' :
            ans += 1
    return min ( ans , length - ans )
if __name__ == " _ _ main _ _ " :
    s = "1100"
    length = len ( s )
    print ( minReplacement ( s , length ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def substrDeletion ( string , length ) :
    count0 = 0 ;
    count1 = 0 ;
    for i in range ( length ) :
        if ( string [ i ] == '0' ) :
            count0 += 1 ;
        else :
            count1 += 1 ;
    return min ( count0 , count1 ) ;
if __name__ == " _ _ main _ _ " :
    string = "010" ;
    length = len ( string ) ;
    print ( substrDeletion ( string , length ) ) ;

Index/key variables: i
Accumulator variables: count0, count1
Iterator variables: i
Python program:
def groupCharacters ( s , l ) :
    temp = " "
    for i in range ( l ) :
        if ( s [ i ] != ' ▁ ' ) :
            temp = temp + s [ i ]
    l = len ( temp )
    ans = " "
    i = 0
    while ( i < l ) :
        if ( ord ( temp [ i ] ) >= ord ( ' A ' ) and ord ( temp [ i ] ) <= ord ( ' Z ' ) ) :
            while ( i < l and ord ( temp [ i ] ) >= ord ( ' A ' ) and ord ( temp [ i ] ) <= ord ( ' Z ' ) ) :
                ans = ans + temp [ i ]
                i += 1
            ans = ans + " ▁ "
        elif ( ord ( temp [ i ] ) >= ord ( '0' ) and ord ( temp [ i ] ) <= ord ( '9' ) ) :
            while ( i < l and ord ( temp [ i ] ) >= ord ( '0' ) and ord ( temp [ i ] ) <= ord ( '9' ) ) :
                ans = ans + temp [ i ]
                i += 1
            ans = ans + " ▁ "
        else :
            while ( i < l and ord ( temp [ i ] ) >= ord ( ' * ' ) and ord ( temp [ i ] ) <= ord ( ' / ' ) ) :
                ans = ans + temp [ i ]
                i += 1
            ans = ans + " ▁ "
    return ans
if __name__ == " _ _ main _ _ " :
    s = "34FTG234 + ▁ + - ▁ * "
    l = len ( s )
    print ( groupCharacters ( s , l ) )

Index/key variables: i
Iterator variables: i
Python program:
def Preprocess ( A , B ) :
    n = len ( A )
    ans = 0
    for i in range ( n // 2 ) :
        mp = dict ( )
        mp [ A [ i ] ] = 1
        if A [ i ] == A [ n - i - 1 ] :
            mp [ A [ n - i - 1 ] ] += 1
        if B [ i ] in mp . keys ( ) :
            mp [ B [ i ] ] += 1
        else :
            mp [ B [ i ] ] = 1
        if B [ n - i - 1 ] in mp . keys ( ) :
            mp [ B [ n - 1 - i ] ] += 1
        else :
            mp [ B [ n - 1 - i ] ] = 1
        sz = len ( mp )
        if ( sz == 4 ) :
            ans += 2
        elif ( sz == 3 ) :
            ans += 1 + ( A [ i ] == A [ n - i - 1 ] )
        elif ( sz == 2 ) :
            ans += mp [ A [ i ] ] != 2
    if ( n % 2 == 1 and A [ n // 2 ] != B [ n // 2 ] ) :
        ans += 1
    return ans
A = " abacaba "
B = " bacabaa "
print ( Preprocess ( A , B ) )

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