dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findNumbers ( n ) :
    i = 1
    while ( i <= n ) :
        print ( ( 3 * i * ( i - 1 ) + 1 ) , end = " ▁ " )
        i += 1
n = 4
findNumbers ( n )

Accumulator variables: i
Python program:
from math import sqrt , ceil
def decToOctal ( n ) :
    octalNum = [ 0 ] * 100 ;
    i = 0 ;
    while ( n != 0 ) :
        octalNum [ i ] = n % 8 ;
        n = n // 8 ;
        i += 1 ;
    for j in range ( i - 1 , - 1 , - 1 ) :
        print ( octalNum [ j ] , end = " " ) ;
    print ( ) ;
def nDigitPerfectSquares ( n ) :
    decimal = pow ( ceil ( sqrt ( pow ( 8 , n ) ) ) - 1 , 2 ) ;
    decToOctal ( decimal ) ;
if __name__ == " _ _ main _ _ " :
    n = 2 ;
    nDigitPerfectSquares ( n ) ;

Index/key variables: i, j
Iterator variables: j
Python program:
def reverseStr ( str , l , h ) :
    n = h - l
    for i in range ( n // 2 ) :
        str [ i + l ] , str [ n - i - 1 + l ] = str [ n - i - 1 + l ] , str [ i + l ]
def reverseString ( s , A , n ) :
    reverseStr ( s , 0 , A [ 0 ] )
    for i in range ( 1 , n ) :
        reverseStr ( s , A [ i - 1 ] , A [ i ] )
    reverseStr ( s , A [ n - 1 ] , len ( s ) )
s = " abcdefgh "
s = [ i for i in s ]
A = [ 2 , 4 , 6 ]
n = len ( A )
reverseString ( s , A , n )
print ( " " . join ( s ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxSubStr ( str , n ) :
    count0 = 0
    count1 = 0
    cnt = 0
    for i in range ( n ) :
        if str [ i ] == '0' :
            count0 += 1
        else :
            count1 += 1
        if count0 == count1 :
            cnt += 1
    if cnt == 0 :
        return - 1
    return cnt
str = "0100110101"
n = len ( str )
print ( maxSubStr ( str , n ) )

Index/key variables: i
Accumulator variables: cnt, count0, count1
Iterator variables: i
Python program:
def getString ( x ) :
    return x
def solve ( s1 , s2 ) :
    a = getString ( s1 [ 0 ] )
    b = getString ( s2 [ 0 ] )
    for i in range ( 1 , len ( s1 ) ) :
        if s1 [ i ] != s1 [ i - 1 ] :
            a += getString ( s1 [ i ] )
    for i in range ( 1 , len ( s2 ) ) :
        if s2 [ i ] != s2 [ i - 1 ] :
            b += getString ( s2 [ i ] )
    if a == b :
        return True
    return False
s1 = " Geeks "
s2 = " Geks "
if solve ( s1 , s2 ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Accumulator variables: a, b
Iterator variables: i
Python program:
x = 26
mod = 3001
def CntSubstr ( s , l ) :
    hash = 0 ;
    for i in range ( l ) :
        hash = ( hash * x + ( ord ( s [ i ] ) - 97 ) ) % mod ;
    pow_l = 1 ;
    for i in range ( l - 1 ) :
        pow_l = ( pow_l * x ) % mod ;
    result = set ( ) ;
    result . add ( hash ) ;
    for i in range ( l , len ( s ) ) :
        hash = ( ( hash - pow_l * ( ord ( s [ i - l ] ) - 97 ) + 2 * mod ) * x + ( ord ( s [ i ] ) - 97 ) ) % mod ;
        result . add ( hash ) ;
    print ( len ( result ) ) ;
if __name__ == " _ _ main _ _ " :
    s = " abcba " ;
    l = 2 ;
    CntSubstr ( s , l ) ;

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def endsWith ( str1 , pat ) :
    patLen = len ( pat )
    str1Len = len ( str1 )
    if ( patLen > str1Len ) :
        return False
    patLen -= 1
    str1Len -= 1
    while ( patLen >= 0 ) :
        if ( pat [ patLen ] != str1 [ str1Len ] ) :
            return False
        patLen -= 1
        str1Len -= 1
    return True
def countOfstr1ings ( pat , n , sArr ) :
    count = 0
    for i in range ( n ) :
        if ( endsWith ( sArr [ i ] , pat ) == True ) :
            count += 1
    return count
pat = " ks "
n = 4
sArr = [ " geeks " , " geeksforgeeks " , " games " , " unit " ]
print ( countOfstr1ings ( pat , n , sArr ) )

Index/key variables: i, patLen, str1Len
Accumulator variables: count
Iterator variables: i
Python program:
def getEndingIndex ( str1 , n , i ) :
    i += 1
    while ( i < n ) :
        curr = str1 [ i ]
        prev = str1 [ i - 1 ]
        if ( ( curr == ' a ' and prev == ' z ' ) or ( ord ( curr ) - ord ( prev ) == 1 ) ) :
            i += 1
        else :
            break
    return i - 1
def largestSubstr1 ( str1 , n ) :
    Len = 0
    i = 0
    while ( i < n ) :
        end = getEndingIndex ( str1 , n , i )
        Len = max ( end - i + 1 , Len )
        i = end + 1
    return Len
str1 = " abcabcdefabc "
n = len ( str1 )
print ( largestSubstr1 ( str1 , n ) )

Index/key variables: i
Python program:
def getSum ( n , d ) :
    if ( n < d ) :
        return 0
    while ( n % 10 != d ) :
        n -= 1
    k = n // 10
    return ( ( k + 1 ) * d + ( k * 10 + 10 * k * k ) // 2 )
if __name__ == " _ _ main _ _ " :
    n = 30
    d = 3
    print ( getSum ( n , d ) )

Accumulator variables: n
Python program:
from collections import defaultdict
def getFrequencyMap ( arr , n ) :
    hashMap = defaultdict ( lambda : 0 )
    for i in range ( n ) :
        hashMap [ arr [ i ] ] += 1
    return hashMap
def hasDigit ( hashMap , digit ) :
    if hashMap [ digit ] > 0 :
        hashMap [ digit ] -= 1
        return True
    return False
def getMaxtime_value ( arr , n ) :
    hashMap = getFrequencyMap ( arr , n )
    flag = False
    time_value = " "
    for i in range ( 2 , - 1 , - 1 ) :
        if hasDigit ( hashMap , i ) == True :
            flag = True
            time_value += str ( i )
            break
    if not flag :
        return " - 1"
    flag = False
    if ( time_value [ 0 ] == '2' ) :
        for i in range ( 3 , - 1 , - 1 ) :
            if hasDigit ( hashMap , i ) == True :
                flag = True
                time_value += str ( i )
                break
    else :
        for i in range ( 9 , - 1 , - 1 ) :
            if hasDigit ( hashMap , i ) == True :
                flag = True
                time_value += str ( i )
                break
    if not flag :
        return " - 1"
    time_value += " : "
    flag = False
    for i in range ( 5 , - 1 , - 1 ) :
        if hasDigit ( hashMap , i ) == True :
            flag = True
            time_value += str ( i )
            break
    if not flag :
        return " - 1"
    flag = False
    for i in range ( 9 , - 1 , - 1 ) :
        if hasDigit ( hashMap , i ) == True :
            flag = True
            time_value += str ( i )
            break
    if not flag :
        return " - 1"
    return time_value
if __name__ == " _ _ main _ _ " :
    arr = [ 0 , 0 , 0 , 9 ]
    n = len ( arr )
    print ( getMaxtime_value ( arr , n ) )

Index/key variables: digit, i
Accumulator variables: time_value
Iterator variables: i
Boolean variables: flag
Python program:
from collections import defaultdict
def smallestFreq ( S1 , S2 ) :
    banned = defaultdict ( lambda : 0 )
    i = 0
    while i < len ( S2 ) :
        s = " "
        while i < len ( S2 ) and S2 [ i ] != ' ▁ ' :
            s += S2 [ i ]
            i += 1
        i += 1
        banned [ s ] += 1
    result = defaultdict ( lambda : 0 )
    ans = " "
    freq = 0
    i = 0
    while i < len ( S1 ) :
        s = " "
        while i < len ( S1 ) and S1 [ i ] != ' ▁ ' :
            s += S1 [ i ]
            i += 1
        i += 1
        if banned [ s ] == 0 :
            result [ s ] += 1
            if ( result [ s ] > freq or ( result [ s ] == freq and s < ans ) ) :
                ans = s
                freq = result [ s ]
    return ans
if __name__ == " _ _ main _ _ " :
    S1 = " geeks ▁ for ▁ geeks ▁ is ▁ best ▁ place ▁ to ▁ learn "
    S2 = " bad ▁ place "
    print ( smallestFreq ( S1 , S2 ) )

Index/key variables: i, s
Python program:
def replace ( A , B ) :
    n , m = len ( A ) , len ( B )
    count , i = 0 , 0
    while i < n :
        j = 0
        while j < m :
            if i + j >= n or A [ i + j ] != B [ j ] :
                break
            j += 1
        if j == m :
            count += 1
            i += m - 1
        i += 1
    return count
if __name__ == " _ _ main _ _ " :
    str1 = " aaaaaaaa "
    str2 = " aaa "
    print ( replace ( str1 , str2 ) )

Index/key variables: j
Accumulator variables: count, i
Python program:
n = 6 ;
m = 8 ;
visited = [ [ 0 for j in range ( m ) ] for i in range ( n ) ]
result = [ [ 0 for j in range ( m ) ] for i in range ( n ) ]
COUNT = 0
def is_valid ( x , y , key , input ) :
    if ( x < n and y < m and x >= 0 and y >= 0 ) :
        if ( visited [ x ] [ y ] == 0 and input [ x ] [ y ] == key ) :
            return True ;
        else :
            return False ;
    else :
        return False ;
def BFS ( x , y , i , j , input ) :
    global COUNT
    if ( x != y ) :
        return ;
    visited [ i ] [ j ] = 1 ;
    COUNT += 1
    x_move = [ 0 , 0 , 1 , - 1 ]
    y_move = [ 1 , - 1 , 0 , 0 ]
    for u in range ( 4 ) :
        if ( is_valid ( i + y_move [ u ] , j + x_move [ u ] , x , input ) ) :
            BFS ( x , y , i + y_move [ u ] , j + x_move [ u ] , input ) ;
def reset_visited ( ) :
    for i in range ( n ) :
        for j in range ( m ) :
            visited [ i ] [ j ] = 0
def reset_result ( key , input ) :
    for i in range ( n ) :
        for j in range ( m ) :
            if ( visited [ i ] [ j ] != 0 and input [ i ] [ j ] == key ) :
                result [ i ] [ j ] = visited [ i ] [ j ] ;
            else :
                result [ i ] [ j ] = 0 ;
def print_result ( res ) :
    print ( " The ▁ largest ▁ connected ▁ " + " component ▁ of ▁ the ▁ grid ▁ is ▁ : " + str ( res ) ) ;
    for i in range ( n ) :
        for j in range ( m ) :
            if ( result [ i ] [ j ] != 0 ) :
                print ( result [ i ] [ j ] , end = ' ▁ ' )
            else :
                print ( ' . ▁ ' , end = ' ' )
        print ( )
def computeLargestConnectedGrid ( input ) :
    global COUNT
    current_max = - 10000000000
    for i in range ( n ) :
        for j in range ( m ) :
            reset_visited ( ) ;
            COUNT = 0 ;
            if ( j + 1 < m ) :
                BFS ( input [ i ] [ j ] , input [ i ] [ j + 1 ] , i , j , input ) ;
            if ( COUNT >= current_max ) :
                current_max = COUNT ;
                reset_result ( input [ i ] [ j ] , input ) ;
            reset_visited ( ) ;
            COUNT = 0 ;
            if ( i + 1 < n ) :
                BFS ( input [ i ] [ j ] , input [ i + 1 ] [ j ] , i , j , input ) ;
            if ( COUNT >= current_max ) :
                current_max = COUNT ;
                reset_result ( input [ i ] [ j ] , input ) ;
    print_result ( current_max ) ;
if __name__ == ' _ _ main _ _ ' :
    input = [ [ 1 , 4 , 4 , 4 , 4 , 3 , 3 , 1 ] , [ 2 , 1 , 1 , 4 , 3 , 3 , 1 , 1 ] , [ 3 , 2 , 1 , 1 , 2 , 3 , 2 , 1 ] , [ 3 , 3 , 2 , 1 , 2 , 2 , 2 , 2 ] , [ 3 , 1 , 3 , 1 , 1 , 4 , 4 , 4 ] , [ 1 , 1 , 3 , 1 , 1 , 4 , 4 , 4 ] ] ;
    computeLargestConnectedGrid ( input ) ;

Index/key variables: i, j, u, x, y
Iterator variables: i, j, u
Python program:
def isSubstring ( s1 , s2 ) :
    M = len ( s1 )
    N = len ( s2 )
    for i in range ( N - M + 1 ) :
        for j in range ( M ) :
            if ( s2 [ i + j ] != s1 [ j ] ) :
                break
        if j + 1 == M :
            return i
    return - 1
if __name__ == " _ _ main _ _ " :
    s1 = " for "
    s2 = " geeksforgeeks "
    res = isSubstring ( s1 , s2 )
    if res == - 1 :
        print ( " Not ▁ present " )
    else :
        print ( " Present ▁ at ▁ index ▁ " + str ( res ) )

Index/key variables: j
Iterator variables: i, j
Python program:
def split ( Str ) :
    Len = len ( Str )
    if ( Len == 1 ) :
        print ( " Not ▁ Possible " )
        return
    s1 , s2 = " " , " "
    for i in range ( ( Len // 2 ) + 1 ) :
        flag = 0
        s1 = Str [ 0 : i + 1 ]
        num1 = int ( s1 )
        num2 = num1 + 1
        s2 = str ( num2 )
        k = i + 1
        while ( flag == 0 ) :
            l = len ( s2 )
            if ( k + l > Len ) :
                flag = 1
                break
            if ( ( Str [ k : k + l ] == s2 ) ) :
                flag = 0
                num2 += 1
                k = k + l
                if ( k == Len ) :
                    break
                s2 = str ( num2 )
                l = len ( s2 )
                if ( k + 1 > len ) :
                    flag = 1
                    break
            else :
                flag = 1
        if ( flag == 0 ) :
            print ( " Possible " , s1 )
            break
        elif ( flag == 1 and i > ( Len // 2 ) - 1 ) :
            print ( " Not ▁ Possible " )
            break
Str = "99100"
split ( Str )

Accumulator variables: num2
Iterator variables: i
Python program:
def internalSearch ( ii , needle , row , col , hay , row_max , col_max ) :
    found = 0
    if ( row >= 0 and row <= row_max and col >= 0 and col <= col_max and needle [ ii ] == hay [ row ] [ col ] ) :
        match = needle [ ii ]
        ii += 1
        hay [ row ] [ col ] = 0
        if ( ii == len ( needle ) ) :
            found = 1
        else :
            found += internalSearch ( ii , needle , row , col + 1 , hay , row_max , col_max )
            found += internalSearch ( ii , needle , row , col - 1 , hay , row_max , col_max )
            found += internalSearch ( ii , needle , row + 1 , col , hay , row_max , col_max )
            found += internalSearch ( ii , needle , row - 1 , col , hay , row_max , col_max )
        hay [ row ] [ col ] = match
    return found
def searchString ( needle , row , col , strr , row_count , col_count ) :
    found = 0
    for r in range ( row_count ) :
        for c in range ( col_count ) :
            found += internalSearch ( 0 , needle , r , c , strr , row_count - 1 , col_count - 1 )
    return found
needle = " MAGIC "
inputt = [ " BBABBM " , " CBMBBA " , " IBABBG " , " GOZBBI " , " ABBBBC " , " MCIGAM " ]
strr = [ 0 ] * len ( inputt )
for i in range ( len ( inputt ) ) :
    strr [ i ] = list ( inputt [ i ] )
print ( " count : ▁ " , searchString ( needle , 0 , 0 , strr , len ( strr ) , len ( strr [ 0 ] ) ) )

Index/key variables: col, i, ii, row
Accumulator variables: found
Iterator variables: c, i, r
Python program:
def KMP ( m , n , str2 , str1 ) :
    pos = 0
    Len = 0
    p = [ 0 for i in range ( m + 1 ) ]
    k = 0
    for i in range ( 2 , n + 1 ) :
        while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :
            k = p [ k ]
        if ( str1 [ k ] == str1 [ i - 1 ] ) :
            k += 1
        p [ i ] = k
    j = 0
    for i in range ( m ) :
        while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :
            j = p [ j ]
        if ( j < n and str1 [ j ] == str2 [ i ] ) :
            j += 1
        if ( j > Len ) :
            Len = j
            pos = i - j + 1
    print ( " Shift ▁ = ▁ " , pos )
    print ( " Prefix ▁ = ▁ " , str1 [ : Len ] )
str1 = " geeksforgeeks "
str2 = " forgeeksgeeks "
n = len ( str1 )
str2 = str2 + str2
KMP ( 2 * n , n , str2 , str1 )

Index/key variables: i, j, k
Iterator variables: i
Python program:
def patternCount ( str ) :
    last = str [ 0 ]
    i = 1 ; counter = 0
    while ( i < len ( str ) ) :
        if ( str [ i ] == '0' and last == '1' ) :
            while ( str [ i ] == '0' ) :
                i += 1
                if ( str [ i ] == '1' ) :
                    counter += 1
        last = str [ i ]
        i += 1
    return counter
str = "1001ab010abc01001"
ans = patternCount ( str )
print ( ans )

Index/key variables: i
Accumulator variables: counter
Python program:
def preprocess_strong_suffix ( shift , bpos , pat , m ) :
    i = m
    j = m + 1
    bpos [ i ] = j
    while i > 0 :
        while j <= m and pat [ i - 1 ] != pat [ j - 1 ] :
            if shift [ j ] == 0 :
                shift [ j ] = j - i
            j = bpos [ j ]
        i -= 1
        j -= 1
        bpos [ i ] = j
def preprocess_case2 ( shift , bpos , pat , m ) :
    j = bpos [ 0 ]
    for i in range ( m + 1 ) :
        if shift [ i ] == 0 :
            shift [ i ] = j
        if i == j :
            j = bpos [ j ]
def search ( text , pat ) :
    s = 0
    m = len ( pat )
    n = len ( text )
    bpos = [ 0 ] * ( m + 1 )
    shift = [ 0 ] * ( m + 1 )
    preprocess_strong_suffix ( shift , bpos , pat , m )
    preprocess_case2 ( shift , bpos , pat , m )
    while s <= n - m :
        j = m - 1
        while j >= 0 and pat [ j ] == text [ s + j ] :
            j -= 1
        if j < 0 :
            print ( " pattern ▁ occurs ▁ at ▁ shift ▁ = ▁ % d " % s )
            s += shift [ 0 ]
        else :
            s += shift [ j + 1 ]
if __name__ == " _ _ main _ _ " :
    text = " ABAAAABAACD "
    pat = " ABA "
    search ( text , pat )

Index/key variables: i, j
Accumulator variables: s
Iterator variables: i
Python program:
def maxPrefix ( s , t ) :
    count = 0
    for i in range ( 0 , len ( t ) ) :
        if ( count == len ( s ) ) :
            break
        if ( t [ i ] == s [ count ] ) :
            count = count + 1
    return count
S = " digger "
T = " biggerdiagram "
print ( maxPrefix ( S , T ) )

Index/key variables: count, i
Iterator variables: i
Python program:
def translate ( st ) :
    for i in range ( 1 , len ( st ) ) :
        if ( st [ i - 1 ] == ' A ' and st [ i ] == ' B ' ) :
            st [ i - 1 ] = ' C '
            for j in range ( i , len ( st ) - 1 ) :
                st [ j ] = st [ j + 1 ]
            st [ len ( st ) - 1 ] = ' ▁ '
    return
st = list ( " helloABworldABGfG " )
translate ( st )
print ( " The ▁ modified ▁ string ▁ is ▁ : " )
print ( ' ' . join ( st ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
ROW = 3
COL = 5
def isvalid ( row , col , prevRow , prevCol ) :
    return ( row >= 0 ) and ( row < ROW ) and ( col >= 0 ) and ( col < COL ) and not ( row == prevRow and col == prevCol )
rowNum = [ - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 ]
colNum = [ - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 ]
def DFS ( mat , row , col , prevRow , prevCol , word , path , index , n ) :
    if ( index > n or mat [ row ] [ col ] != word [ index ] ) :
        return
    path += word [ index ] + " ( " + str ( row ) + " , ▁ " + str ( col ) + " ) ▁ "
    if ( index == n ) :
        print ( path )
        return
    for k in range ( 8 ) :
        if ( isvalid ( row + rowNum [ k ] , col + colNum [ k ] , prevRow , prevCol ) ) :
            DFS ( mat , row + rowNum [ k ] , col + colNum [ k ] , row , col , word , path , index + 1 , n )
def findWords ( mat , word , n ) :
    for i in range ( ROW ) :
        for j in range ( COL ) :
            if ( mat [ i ] [ j ] == word [ 0 ] ) :
                DFS ( mat , i , j , - 1 , - 1 , word , " " , 0 , n )
mat = [ [ ' B ' , ' N ' , ' E ' , ' Y ' , ' S ' ] , [ ' H ' , ' E ' , ' D ' , ' E ' , ' S ' ] , [ ' S ' , ' G ' , ' N ' , ' D ' , ' E ' ] ]
word = list ( " DES " )
findWords ( mat , word , len ( word ) - 1 )

Index/key variables: col, i, index, j, k, row
Iterator variables: i, j, k
Python program:
import random , math
maxSize = 10 ;
def randomHexInt ( N ) :
    hexChar = [ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' ] ;
    for i in range ( N ) :
        Len = math . floor ( random . random ( ) * ( maxSize - 1 ) + 1 )
        for j in range ( Len ) :
            print ( hexChar [ math . floor ( random . random ( ) * 16 ) ] , end = " " ) ;
        print ( ) ;
if __name__ == " _ _ main _ _ " :
    N = 3 ;
    randomHexInt ( N ) ;

Iterator variables: i, j
Python program:
def checkEqualArrays ( arr , brr , N ) :
    siz = len ( arr [ 0 ] ) ;
    for i in range ( N ) :
        temp1 = list ( arr [ i ] ) ;
        temp1 . sort ( ) ;
        arr [ i ] = " " . join ( temp1 )
        temp2 = list ( brr [ i ] ) ;
        temp2 . sort ( ) ;
        brr [ i ] = " " . join ( temp2 ) ;
    arr . sort ( )
    brr . sort ( )
    for i in range ( N ) :
        if ( arr [ i ] != brr [ i ] ) :
            return False ;
    return True ;
if __name__ == " _ _ main _ _ " :
    N = 2 ;
    arr = [ " bcd " , " aac " ] ;
    brr = [ " aca " , " dbc " ] ;
    ans = checkEqualArrays ( arr , brr , N ) ;
    if ( ans ) :
        print ( " true " ) ;
    else :
        print ( " false " ) ;

Index/key variables: i
Iterator variables: i
Python program:
maxi = 0 ;
ans1 = " " ;
def calculate ( ans ) :
    global maxi , ans1 ;
    dp = [ 0 ] * 26 ;
    for i in range ( len ( ans ) ) :
        dp [ ord ( ans [ i ] ) - ord ( ' A ' ) ] += 1 ;
    for i in range ( 26 ) :
        if ( dp [ i ] % 2 == 1 ) :
            return ;
    if ( maxi < len ( ans ) ) :
        maxi = len ( ans ) ;
        ans1 = ans ;
def longestString ( arr , index , string ) :
    if ( index == len ( arr ) ) :
        return ;
    longestString ( arr , index + 1 , string ) ;
    string += arr [ index ] ;
    calculate ( string ) ;
    longestString ( arr , index + 1 , string ) ;
if __name__ == " _ _ main _ _ " :
    A = [ " ABAB " , " ABF " , " CDA " , " AD " , " CCC " ] ;
    longestString ( A , 0 , " " ) ;
    print ( ans1 , len ( ans1 ) ) ;

Index/key variables: i, index
Iterator variables: i
Python program:
def generateNumber ( number ) :
    temp = 0 ; adding_number = 0 ;
    result = " " ;
    l = len ( number ) ;
    for i in range ( l - 1 , - 1 , - 1 ) :
        digit = ord ( number [ i ] ) - ord ( '0' ) ;
        if ( temp % 2 == 0 ) :
            adding_number += 1 ;
            digit += adding_number ;
            if ( digit >= 10 ) :
                digit %= 9 ;
                if ( digit == 0 ) :
                    digit = 9 ;
        result = str ( digit ) + result ;
        temp += 1 ;
    return result ;
if __name__ == " _ _ main _ _ " :
    S = "1345" ;
    print ( generateNumber ( S ) ) ;

Index/key variables: i
Accumulator variables: adding_number, digit, temp
Iterator variables: i
Python program:
def findTheSum ( str ) :
    alpha = " "
    for i in range ( 0 , len ( str ) ) :
        if ( ( str [ i ] >= ' A ' and str [ i ] <= ' Z ' ) or ( str [ i ] >= ' a ' and str [ i ] <= ' z ' ) ) :
            alpha += str [ i ]
    score = 0
    n = 0
    for i in range ( 0 , len ( alpha ) ) :
        if ( alpha [ i ] >= ' A ' and alpha [ i ] <= ' Z ' ) :
            score += ord ( alpha [ i ] ) - ord ( ' A ' ) + 1
        else :
            score += ord ( alpha [ i ] ) - ord ( ' a ' ) + 1
    while ( score > 0 or n > 9 ) :
        if ( score == 0 ) :
            score = n
            n = 0
        n += score % 10
        score = score // 10
    return n
if __name__ == " _ _ main _ _ " :
    S = " GeeksforGeeks "
    print ( findTheSum ( S ) )

Index/key variables: i
Accumulator variables: alpha, n, score
Iterator variables: i
Python program:
def findK ( s , c ) :
    n = len ( s )
    diff = 0
    max = 0
    prev = 0
    for i in range ( 0 , n ) :
        if ( s [ i ] == c ) :
            diff = i - prev
            prev = i
            if ( diff > max ) :
                max = diff
    if ( max == 0 ) :
        return - 1
    return max
if __name__ == " _ _ main _ _ " :
    S = " abdegb "
    ch = ' b '
    print ( findK ( S , ch ) )

Index/key variables: i
Iterator variables: i
Python program:
def countSubsequence ( S , N , K ) :
    C = 0
    C1 = 0
    C0 = 0
    for i in range ( 0 , N ) :
        if ( S [ i ] == '1' ) :
            C1 += 1
        elif ( S [ i ] == '0' ) :
            C0 += 1
    B1 = 0
    for i in range ( 0 , N ) :
        if ( S [ i ] == '1' ) :
            B1 += 1
        elif ( S [ i ] == '0' ) :
            C = C + ( C1 - B1 )
    ans = C * K
    ans += ( C1 * C0 * ( ( ( K ) * ( K - 1 ) ) // 2 ) )
    return ans
if __name__ == " _ _ main _ _ " :
    S = "230013110087"
    K = 2
    N = len ( S )
    print ( countSubsequence ( S , N , K ) )

Index/key variables: i
Accumulator variables: B1, C0, C1
Iterator variables: i