dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def Find ( parent , a ) :
    if parent [ a ] == a :
        parent [ a ] = a
        return parent [ a ]
    else :
        parent [ a ] = Find ( parent , parent [ a ] )
        return parent [ a ]
def Union ( parent , rank , a , b ) :
    a = Find ( parent , a )
    b = Find ( parent , b )
    if ( rank [ a ] == rank [ b ] ) :
        rank [ a ] += 1
    if ( rank [ a ] > rank [ b ] ) :
        parent [ b ] = a
    else :
        parent [ a ] = b
def numOfDistinctStrings ( arr , N ) :
    parent = [ 0 for _ in range ( 27 ) ]
    rank = [ 0 for _ in range ( 27 ) ]
    for j in range ( 0 , 27 ) :
        parent [ j ] = j
    total = [ False for _ in range ( 26 ) ]
    current = [ False for _ in range ( 26 ) ]
    for i in range ( 0 , N ) :
        for j in range ( 0 , 26 ) :
            current [ j ] = False
        for ch in arr [ i ] :
            current [ ord ( ch ) - ord ( ' a ' ) ] = True
        for j in range ( 0 , 26 ) :
            if ( current [ j ] ) :
                total [ j ] = True
                Union ( parent , rank , ord ( arr [ i ] [ 0 ] ) - ord ( ' a ' ) , j )
    distCount = 0
    for i in range ( 0 , 26 ) :
        if ( total [ i ] and Find ( parent , i ) == i ) :
            distCount += 1
    print ( distCount )
if __name__ == " _ _ main _ _ " :
    arr = [ " a " , " ab " , " b " , " d " ]
    N = len ( arr )
    numOfDistinctStrings ( arr , N )

Index/key variables: a, b, i, j
Accumulator variables: distCount
Iterator variables: ch, i, j
Python program:
def minSwaps ( s ) :
    ones = 0
    zeros = 0
    N = len ( s )
    for i in range ( N ) :
        if s [ i ] == '1' :
            ones += 1
        else :
            zeros += 1
    if ( ( N % 2 == 0 and ones != zeros ) or ( N % 2 == 1 and abs ( ones - zeros ) != 1 ) ) :
        return - 1
    ans_1 = 0
    j = 0
    for i in range ( N ) :
        if ( s [ i ] == '1' ) :
            ans_1 += abs ( j - i )
            j += 2
    ans_0 = 0
    k = 0
    for i in range ( N ) :
        if ( s [ i ] == '0' ) :
            ans_0 += abs ( k - i )
            k += 2
    if ( N % 2 == 0 ) :
        return min ( ans_1 , ans_0 )
    else :
        if ( ones > zeros ) :
            return ans_1
        else :
            return ans_0
if __name__ == ' _ _ main _ _ ' :
    S = "110100"
    print ( minSwaps ( S ) )

Index/key variables: i
Accumulator variables: ans_0, ans_1, j, k, ones, zeros
Iterator variables: i
Python program:
def TotalPossibleJumps ( N ) :
    if ( ( N - 1 ) == 0 ) :
        newvec = [ ]
        newvec . append ( " " )
        return newvec
    else :
        if ( N < 0 ) :
            newvec = [ ]
            return newvec
    jump1 = TotalPossibleJumps ( N - 1 )
    jump2 = TotalPossibleJumps ( N - 2 )
    totaljumps = [ ]
    for s in jump1 :
        totaljumps . append ( "1" + s )
    for s in jump2 :
        totaljumps . append ( "2" + s )
    return totaljumps
if __name__ == " _ _ main _ _ " :
    N = 3
    Ans = TotalPossibleJumps ( N )
    for it in Ans :
        print ( it )

Accumulator variables: totaljumps
Iterator variables: it, s
Python program:
def findString ( arr , N ) :
    ans = " "
    for i in range ( N ) :
        ans += '1' if arr [ i ] [ i ] == '0' else '0'
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ "111" , "011" , "001" ]
    N = len ( arr )
    print ( findString ( arr , N ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def commonSubstring ( s ) :
    n = len ( s )
    i = 0
    j = n - 1
    ans = " "
    while ( j >= 0 ) :
        if ( s [ i ] == s [ j ] ) :
            ans += s [ i ]
            i = i + 1
            j = j - 1
        else :
            break
    if ( len ( ans ) == 0 ) :
        print ( " False " )
    else :
        print ( " True " )
        print ( ans )
if __name__ == " _ _ main _ _ " :
    S = " abca "
    commonSubstring ( S )

Index/key variables: i, j
Accumulator variables: ans
Python program:
def findMinimumSubsequence ( S ) :
    flag = False
    dummy = ' '
    for j in range ( len ( S ) ) :
        if ( S [ j ] != '2' and S [ j ] != '3' and S [ j ] != '5' and S [ j ] != '7' ) :
            print ( 1 )
            flag = True
            break
    if ( flag == False ) :
        for j in range ( len ( S ) ) :
            for j1 in range ( j + 1 , len ( S ) , 1 ) :
                dummy = S [ j ] + S [ j1 ]
                if ( dummy != "23" and dummy != "37" and dummy != "53" and dummy != "73" ) :
                    print ( 2 )
                if ( flag == True ) :
                    break
                else :
                    flag = True
            if ( flag == True ) :
                break
    if ( flag == False ) :
        if ( len ( S ) >= 3 ) :
            print ( 3 )
        else :
            print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    S = "237"
    findMinimumSubsequence ( S )

Index/key variables: j, j1
Iterator variables: j, j1
Boolean variables: flag
Python program:
import sys
from collections import defaultdict
def operations ( s ) :
    ans = 0
    vowels = 0
    consonants = 0
    max_vowels = - sys . maxsize - 1
    max_consonants = - sys . maxsize - 1
    freq_consonants = defaultdict ( int )
    freq_vowels = defaultdict ( int )
    for i in range ( len ( s ) ) :
        if ( s [ i ] == ' a ' or s [ i ] == ' e ' or s [ i ] == ' i ' or s [ i ] == ' o ' or s [ i ] == ' u ' ) :
            vowels += 1
            freq_vowels [ s [ i ] ] += 1
        else :
            consonants += 1
            freq_consonants [ s [ i ] ] += 1
    for it in freq_consonants :
        max_consonants = max ( max_consonants , freq_consonants [ it ] )
    for it in freq_vowels :
        max_vowels = max ( max_vowels , freq_vowels [ it ] )
    ans = min ( ( 2 * ( vowels - max_vowels ) + consonants ) , ( 2 * ( consonants - max_vowels ) + consonants ) )
    return ans
if __name__ == " _ _ main _ _ " :
    S = " geeksforgeeks "
    print ( operations ( S ) )

Index/key variables: i, it
Accumulator variables: consonants, vowels
Iterator variables: i, it
Python program:
import numpy as np
dp = np . zeros ( ( 505 , 505 ) ) ;
choose = np . zeros ( ( 502 , 502 ) ) ;
def calc ( l , r , s ) :
    if ( abs ( r - l ) % 2 == 0 ) :
        return 0 ;
    if ( l > r ) :
        dp [ l ] [ r ] = 1 ;
        return dp [ l ] [ r ]
    if ( dp [ l ] [ r ] != - 1 ) :
        return dp [ l ] [ r ] ;
    if ( ( r - l ) == 1 ) :
        if ( s [ l ] == s [ r ] ) :
            dp [ l ] [ r ] = 1 ;
        else :
            dp [ l ] [ r ] = 0 ;
        return dp [ l ] [ r ] ;
    ans = 0 ;
    for k in range ( l + 1 , r + 1 , 2 ) :
        temp = 1 ;
        if ( s [ l ] == s [ k ] ) :
            temp = calc ( l + 1 , k - 1 , s ) * calc ( k + 1 , r , s ) * choose [ ( r - l + 1 ) // 2 ] [ ( r - k ) // 2 ] ;
            ans += temp ;
    dp [ l ] [ r ] = ans ;
    return dp [ l ] [ r ]
def waysToClearString ( S ) :
    for i in range ( 505 ) :
        for j in range ( 505 ) :
            dp [ i ] [ j ] = - 1
    n = len ( S ) ;
    choose [ 0 ] [ 0 ] = 1 ;
    for i in range ( 1 , ( n // 2 ) + 1 ) :
        choose [ i ] [ 0 ] = 1 ;
        for j in range ( 1 , i + 1 ) :
            choose [ i ] [ j ] = choose [ i - 1 ] [ j ] + choose [ i - 1 ] [ j - 1 ] ;
    return calc ( 0 , n - 1 , S ) ;
if __name__ == " _ _ main _ _ " :
    S = " aabccb " ;
    print ( waysToClearString ( S ) ) ;

Index/key variables: i, j, k, l, r
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
def findSubsequence ( str ) :
    n = len ( str )
    res = [ '0' for i in range ( n ) ]
    for pos in range ( 10 ) :
        lst1 = '0'
        flag = 1
        lst2 = chr ( pos + 48 )
        for i in range ( n ) :
            if ( lst2 <= str [ i ] ) :
                res [ i ] = '2'
                lst2 = str [ i ]
            elif ( lst1 <= str [ i ] ) :
                res [ i ] = '1'
                lst1 = str [ i ]
            else :
                flag = 0
        if ( lst1 > chr ( pos + 48 ) ) :
            flag = 0
        if ( flag ) :
            S1 = " "
            S2 = " "
            for i in range ( n ) :
                if ( res [ i ] == '1' ) :
                    S1 += str [ i ]
                else :
                    S2 += str [ i ]
            print ( S1 , S2 )
            return
    print ( " - 1" )
if __name__ == ' _ _ main _ _ ' :
    S = "040425524644"
    findSubsequence ( S )
    S = "123456789"
    findSubsequence ( S )

Index/key variables: i
Accumulator variables: S1, S2
Iterator variables: i, pos
Python program:
s = ' '
K = 0
def getString ( curlen , N , prod ) :
    global s , K
    if ( curlen == N ) :
        K -= 1
        if ( K == 0 ) :
            ans = s
        return
    ch = '2'
    while ( ch <= '9' ) :
        s = chr ( ord ( s ) + ord ( ch ) )
        ok = 1
        t = 1
        i = curlen
        ch = chr ( ord ( ch ) + 1 )
        while ( i >= 0 and len ( s ) ) :
            t *= ord ( s [ i ] ) - 48
            if ( prod [ t ] != 0 ) :
                ok = 0
            prod [ t ] += 1
            i -= 1
        if ( ok != 0 ) :
            getString ( curlen + 1 , N , prod )
        t = 1
        i = curlen
        while ( i >= 0 and len ( s ) > i ) :
            i -= 1
            t *= ord ( s [ i ] ) - 48
            prod [ t ] -= 1
        if ( len ( s ) > 0 ) :
            s = s [ 0 : len ( s ) - 1 ]
def kthValidString ( N ) :
    if ( N > 10 ) :
        return " - 1"
    if ( N == 1 ) :
        if ( K > 10 ) :
            return " - 1"
        s = " "
        K -= 1
        s += ( K + '0' )
        return s
    ans = " - 1"
    s = " "
    prod = [ 0 ] * 10005
    getString ( 0 , N , prod )
    return ans
N = 3
K = 4
print ( kthValidString ( N ) )

Index/key variables: i, t
Python program:
def lengthNPalindrome ( N , K ) :
    half = N // 2 ;
    if ( N & 1 ) :
        half += 1 ;
    ans = 1 ;
    for i in range ( 1 , half + 1 ) :
        ans *= K ;
        K -= 1 ;
    return ans ;
def palindromicStrings ( N , K ) :
    if ( N == 1 ) :
        return K ;
    if ( N == 2 ) :
        return 2 * K ;
    ans = 0 ;
    ans += ( 2 * K ) ;
    for i in range ( 3 , N + 1 ) :
        ans += lengthNPalindrome ( i , K ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    N = 4 ; K = 3 ;
    print ( palindromicStrings ( N , K ) ) ;

Accumulator variables: K, ans
Iterator variables: i
Python program:
import numpy as np
def LCS ( S , N , T , M , dp ) :
    if ( N == 0 or M == 0 ) :
        return 0 ;
    if ( dp [ N ] [ M ] != 0 ) :
        return dp [ N ] [ M ] ;
    if ( S [ N - 1 ] == T [ M - 1 ] ) :
        dp [ N ] [ M ] = 1 + LCS ( S , N - 1 , T , M - 1 , dp ) ;
        return dp [ N ] [ M ]
    dp [ N ] [ M ] = max ( LCS ( S , N - 1 , T , M , dp ) , LCS ( S , N , T , M - 1 , dp ) ) ;
    return dp [ N ] [ M ]
def minimumCharacter ( S ) :
    T = " abcdefghijklmnopqrstuvwxyz " ;
    N = len ( S ) ; M = len ( T ) ;
    dp = np . zeros ( ( N + 1 , M + 1 ) ) ;
    return ( 26 - LCS ( S , N , T , M , dp ) ) ;
if __name__ == " _ _ main _ _ " :
    S = " abcdadc " ;
    print ( minimumCharacter ( S ) ) ;

Index/key variables: M, N
Python program:
MOD = 1000000007
def exp_mod ( a , b ) :
    ret = 1
    while ( b ) :
        if ( b & 1 ) :
            ret = ret * a % MOD
        b >>= 1
        a = a * a % MOD
    return ret
def countOfWays ( s , k ) :
    N = len ( s )
    ans = 0
    for i in range ( N ) :
        if ( s [ i ] == '5' or s [ i ] == '0' ) :
            ans = ( ans + exp_mod ( 2 , i ) ) % MOD
    q = exp_mod ( 2 , N )
    qk = exp_mod ( q , k )
    inv = exp_mod ( q - 1 , MOD - 2 )
    ans = ans * ( qk - 1 ) % MOD
    ans = ans * inv % MOD
    return ans
S = "1256"
K = 1
print ( countOfWays ( S , K ) )

Index/key variables: i
Accumulator variables: b
Iterator variables: i
Python program:
def KthCharacter ( s , t , k ) :
    f = 1
    ss = 2
    tmp = " "
    lenn = len ( tmp )
    while ( lenn < k ) :
        tf = f
        ts = ss
        while ( tf != 0 ) :
            tf -= 1
            tmp += s
        while ( ts != 0 ) :
            ts -= 1
            tmp += t
        f += 2
        ss += 2
        lenn = len ( tmp )
    output = tmp [ k - 1 ]
    return output
S1 = " a "
S2 = " bc "
k = 4
ans = KthCharacter ( S1 , S2 , k )
print ( ans )

Accumulator variables: f, ss, tf, tmp, ts
Python program:
def KthCharacter ( s , t , k ) :
    n = len ( s )
    m = len ( t )
    first = 1
    second = 2
    output = ' ? '
    while ( k > 0 ) :
        if ( k > first * n ) :
            x = first * n
            k = k - x
            first = first + 2
            if ( k > second * m ) :
                y = second * m
                k = k - y
                second = second + 2
            else :
                ind = k % m
                ind -= 1
                if ( ind < 0 ) :
                    ind = m - 1
                output = t [ ind ]
                break
        else :
            ind = k % n
            ind -= 1
            if ( ind < 0 ) :
                ind = n - 1
            output = s [ ind ]
            break
    return output
S1 = " a "
S2 = " bc "
k = 4
ans = KthCharacter ( S1 , S2 , k )
print ( ans )

Index/key variables: ind
Python program:
def countCamelCase ( S ) :
    count = 0
    for i in range ( len ( S ) ) :
        if ( ord ( S [ i ] ) >= 65 and ord ( S [ i ] ) <= 91 ) :
            count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    S = " ckjkUUYII "
    countCamelCase ( S )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findRepetition ( a ) :
    if a <= ' z ' and a >= ' a ' :
        return ord ( a ) - 97
    elif a <= ' Z ' and a >= ' A ' :
        return ord ( a ) - 65
    else :
        return 0
def decodeString ( str_ ) :
    output = " "
    i = 0
    while ( i < len ( str_ ) ) :
        output += str_ [ i ]
        i += findRepetition ( str_ [ i ] ) + 1
    print ( " Decrypted ▁ code ▁ is ▁ { " + output + " } " )
str_ = " abbbb ▁ acccdddd "
decodeString ( str_ )

Index/key variables: i
Accumulator variables: output
Python program:
def printString ( S , N ) :
    plaintext = [ None ] * 5
    freq = [ 0 ] * 26
    freqSorted = [ None ] * 26
    used = [ 0 ] * 26
    for i in range ( N ) :
        if S [ i ] != ' ▁ ' :
            freq [ ord ( S [ i ] ) - 65 ] += 1
    for i in range ( 26 ) :
        freqSorted [ i ] = freq [ i ]
    T = " ETAOINSHRDLCUMWFGYPBVKJXQZ "
    freqSorted . sort ( reverse = True )
    for i in range ( 5 ) :
        ch = - 1
        for j in range ( 26 ) :
            if freqSorted [ i ] == freq [ j ] and used [ j ] == 0 :
                used [ j ] = 1
                ch = j
                break
        if ch == - 1 :
            break
        x = ord ( T [ i ] ) - 65
        x = x - ch
        curr = " "
        for k in range ( N ) :
            if S [ k ] == ' ▁ ' :
                curr += " ▁ "
                continue
            y = ord ( S [ k ] ) - 65
            y += x
            if y < 0 :
                y += 26
            if y > 25 :
                y -= 26
            curr += chr ( y + 65 )
        plaintext [ i ] = curr
    for i in range ( 5 ) :
        print ( plaintext [ i ] )
S = " B ▁ TJNQMF ▁ NFTTBHF "
N = len ( S )
printString ( S , N )

Index/key variables: i, j, k
Accumulator variables: curr, y
Iterator variables: i, j, k
Python program:
def merge ( v , left , mid , right , inversions ) :
    temp = [ 0 for i in range ( right - left + 1 ) ]
    i = left
    j = mid + 1
    k = 0
    cnt = 0
    while ( i <= mid and j <= right ) :
        if ( v [ i ] <= v [ j ] ) :
            temp [ k ] = v [ i ]
            k += 1
            i += 1
        else :
            inversions += ( mid - i + 1 )
            temp [ k ] = v [ j ]
            k += 1
            j += 1
    while ( i <= mid ) :
        temp [ k ] = v [ i ]
        k += 1
        i += 1
    while ( j <= right ) :
        temp [ k ] = v [ j ]
        k += 1
        j += 1
    k = 0
    for a in range ( left , right + 1 , 1 ) :
        v [ a ] = temp [ k ]
        k += 1
def mergeSort ( v , left , right , inversions ) :
    if ( left < right ) :
        mid = ( left + right ) // 2
        mergeSort ( v , left , mid , inversions )
        mergeSort ( v , mid + 1 , right , inversions )
        merge ( v , left , mid , right , inversions )
def CountInversions ( v ) :
    n = len ( v )
    inversions = 0
    mergeSort ( v , 0 , n - 1 , inversions )
    return inversions
def getSubsCount ( input ) :
    n = len ( input )
    nums = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        nums [ i ] = ord ( input [ i ] ) - 48
        if ( nums [ i ] == 0 ) :
            nums [ i ] = - 1
    pref = [ 0 for i in range ( n ) ]
    sum = 0
    for i in range ( n ) :
        sum += nums [ i ]
        pref [ i ] = sum
    cnt = 0
    for i in range ( n ) :
        if ( pref [ i ] > 0 ) :
            cnt += 1
    pref = pref [ : - 1 ]
    inversions = CountInversions ( pref )
    ans = cnt + inversions + 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    input = "101"
    ans = getSubsCount ( input )
    print ( ans )

Index/key variables: a, i, j, k
Accumulator variables: cnt, inversions, sum
Iterator variables: a, i
Python program:
def canMadeEmpty ( s , n ) :
    st = [ ]
    for i in range ( n ) :
        if s [ i ] == ' c ' :
            if len ( st ) >= 2 :
                b = st [ - 1 ]
                st . pop ( )
                a = st [ - 1 ]
                st . pop ( )
                if a != ' a ' or b != ' b ' :
                    return " No "
            else :
                return " No "
        else :
            st . append ( s [ i ] )
    if len ( st ) == 0 :
        return " Yes "
    else :
        return " No "
s = " aabcbc "
n = len ( s )
print ( canMadeEmpty ( s , n ) )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
def isSumEqual ( A , B , C ) :
    L = len ( A )
    M = len ( B )
    N = len ( A )
    A = A [ : : - 1 ]
    B = B [ : : - 1 ]
    C = C [ : : - 1 ]
    rem = 0
    for i in range ( max ( L , max ( M , N ) ) ) :
        curr = rem
        if ( i < L ) :
            curr += ord ( A [ i ] ) - ord ( ' a ' )
        if ( i < M ) :
            curr += ord ( B [ i ] ) - ord ( ' a ' )
        rem = curr // 10
        curr %= 10
        if ( i < N and curr != ord ( C [ i ] ) - ord ( ' a ' ) ) :
            return " No "
    if ( rem ) :
        return " No "
    else :
        return " Yes "
if __name__ == ' _ _ main _ _ ' :
    A = " acb "
    B = " cba "
    C = " cdb "
    print ( isSumEqual ( A , B , C ) )

Index/key variables: i
Accumulator variables: curr
Iterator variables: i
Python program:
def MinimumLengthSubstring ( S , N ) :
    ans = N
    S = "0" + S + "0"
    S = [ i for i in S ]
    for c in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        prev = 0
        max_len = 0
        S [ 0 ] = chr ( c )
        S [ N + 1 ] = chr ( c )
        for i in range ( 1 , N + 2 ) :
            if ( S [ i ] == chr ( c ) ) :
                len = i - prev
                max_len = max ( max_len , len )
                prev = i
        ans = min ( ans , max_len )
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = " abcde "
    N = len ( S )
    print ( MinimumLengthSubstring ( S , N ) )

Index/key variables: i
Iterator variables: c, i
Python program:
def minimumHammingDistance ( S , K ) :
    n = len ( S )
    pref = [ 0 ] * n
    pref [ 0 ] = ord ( S [ 0 ] ) - ord ( '0' )
    for i in range ( 1 , n ) :
        pref [ i ] = pref [ i - 1 ] + ( ord ( S [ i ] ) - ord ( '0' ) )
    cnt = pref [ n - 1 ]
    ans = cnt
    for i in range ( n - K ) :
        value = pref [ i + K - 1 ] - ( pref [ i - 1 ] if ( i - 1 ) >= 0 else 0 )
        ans = min ( ans , cnt - value + ( K - value ) )
    return ans
if __name__ == ' _ _ main _ _ ' :
    s = "101"
    K = 2
    print ( minimumHammingDistance ( s , K ) )

Index/key variables: i
Iterator variables: i
Python program:
from math import sqrt
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    elif ( n == 2 ) :
        return True
    elif ( n % 2 == 0 ) :
        return False
    for i in range ( 3 , int ( sqrt ( n ) ) + 1 , 2 ) :
        if ( n % i == 0 ) :
            return False
    return True
def checkPermutation ( s1 , s2 ) :
    freq = [ 0 for i in range ( 26 ) ]
    for ch in s1 :
        if ord ( ch ) - 97 in freq :
            freq [ ord ( ch ) - 97 ] -= 1
        else :
            freq [ ord ( ch ) - 97 ] = 1
    for ch in s2 :
        if ord ( ch ) - 97 in freq :
            freq [ ord ( ch ) - 97 ] += 1
        else :
            freq [ ord ( ch ) - 97 ] = 1
    isAllChangesPrime = True
    for i in range ( 26 ) :
        if ( freq [ i ] == 0 ) :
            continue
        elif ( isPrime ( abs ( freq [ i ] ) ) == False ) :
            isAllChangesPrime = False
            break
    if ( isAllChangesPrime == False ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    S1 = " gekforgk "
    S2 = " geeksforgeeks "
    checkPermutation ( S1 , S2 )

Index/key variables: i
Iterator variables: ch, i
Boolean variables: isAllChangesPrime
Python program:
def countWays ( S , N ) :
    ans = 0
    for mask in range ( ( 1 << N ) ) :
        X , Y = " " , " "
        for i in range ( N ) :
            if ( mask >> i & 1 ) :
                X += S [ i ]
            else :
                Y += S [ i ]
        Y = Y [ : : - 1 ]
        if ( X == Y ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = " mippiisssisssiipsspiim "
    N = len ( S )
    print ( countWays ( S , N ) )

Index/key variables: i
Accumulator variables: X, Y, ans
Iterator variables: i, mask
Python program:
def isEqualSubstring ( string , x ) :
    n = len ( string )
    i = 0
    while i < n and i < x :
        if ( string [ i ] != string [ n - i - 1 ] ) :
            print ( " false " )
            return
        i += 1
    print ( " true " )
    return
if __name__ == ' _ _ main _ _ ' :
    string = " GeeksforGeeks "
    x = 3
    isEqualSubstring ( string , x )

Index/key variables: i
Python program:
def solve ( S , N , Queries , Q ) :
    S = list ( S )
    for i in range ( Q ) :
        T = Queries [ i ] [ 0 ]
        A = Queries [ i ] [ 1 ]
        B = Queries [ i ] [ 2 ]
        A -= 1
        B -= 1
        if ( T == 1 ) :
            temp = S [ A ]
            S [ A ] = S [ B ]
            S [ B ] = temp
        else :
            for j in range ( N ) :
                temp = S [ j ]
                S [ j ] = S [ j + N ]
                S [ j + N ] = temp
    S = ' ' . join ( S )
    print ( S )
if __name__ == ' _ _ main _ _ ' :
    S = " ABCD "
    N = len ( S ) // 2
    Queries = [ [ 2 , 0 , 0 ] , [ 1 , 1 , 3 ] , [ 2 , 0 , 0 ] ]
    Q = len ( Queries )
    solve ( S , N , Queries , Q )

Index/key variables: A, B, i, j
Iterator variables: i, j
Python program:
def minimumOperations ( S , N ) :
    ans = 0
    cntOne = 0
    i = N - 1
    while ( i >= 0 ) :
        if ( S [ i ] == '0' ) :
            ans += cntOne
            cntOne *= 2
        else :
            cntOne += 1
        i -= 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    S = "001"
    N = len ( S )
    minimumOperations ( S , N )

Index/key variables: i
Accumulator variables: ans, cntOne
Python program:
def differentBitwiseOR ( s1 , s2 ) :
    n = len ( s1 )
    t00 = 0
    t10 = 0
    t01 = 0
    t11 = 0
    for i in range ( n ) :
        if ( s1 [ i ] == '0' and s2 [ i ] == '0' ) :
            t00 += 1
        if ( s1 [ i ] == '1' and s2 [ i ] == '0' ) :
            t10 += 1
        if ( s1 [ i ] == '1' and s2 [ i ] == '1' ) :
            t11 += 1
        if ( s1 [ i ] == '0' and s2 [ i ] == '1' ) :
            t01 += 1
    ans = t00 * t10 + t01 * t10 + t00 * t11
    print ( ans )
S1 = "01001"
S2 = "11011"
differentBitwiseOR ( S1 , S2 )

Index/key variables: i
Accumulator variables: t00, t01, t10, t11
Iterator variables: i