dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
CHARS = "0123456789ABCDEF " ;
DIGITS = 16 ;
def isDivisible ( s , m ) :
    mp = dict . fromkeys ( CHARS , 0 ) ;
    for i in range ( DIGITS ) :
        mp [ CHARS [ i ] ] = i ;
    r = 0 ;
    for i in range ( len ( s ) ) :
        r = ( r * 16 + mp [ s [ i ] ] ) % m ;
    if ( not r ) :
        return True ;
    return False ;
if __name__ == " _ _ main _ _ " :
    s = "10" ;
    m = 3 ;
    if ( isDivisible ( s , m ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Iterator variables: i
Python program:
def cntSplits ( s ) :
    if ( s [ len ( s ) - 1 ] == '1' ) :
        return - 1 ;
    ans = 0 ;
    for i in range ( len ( s ) ) :
        ans += ( s [ i ] == '0' ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    s = "10010" ;
    print ( cntSplits ( s ) ) ;

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
CHARS = " qwertyuiopasdfghjklzxcvbnm " ;
MAX = 26 ;
def getString ( string , n ) :
    string = list ( string ) ;
    uMap = { } ;
    for i in range ( MAX ) :
        uMap [ CHARS [ i ] ] = CHARS [ ( i + 1 ) % MAX ] ;
    for i in range ( n ) :
        string [ i ] = uMap [ string [ i ] ] ;
    return " " . join ( string ) ;
if __name__ == " _ _ main _ _ " :
    string = " geeks " ;
    n = len ( string ) ;
    print ( getString ( string , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def Count ( s , pos ) :
    c = s [ pos - 1 ]
    counter = 0
    for i in range ( pos - 1 ) :
        if s [ i ] == c :
            counter = counter + 1
    return counter
if __name__ == " _ _ main _ _ " :
    s = " abacsddaa "
    n = len ( s )
    query = [ 9 , 3 , 2 ]
    Q = len ( query )
    for i in range ( Q ) :
        pos = query [ i ]
        print ( Count ( s , pos ) )

Index/key variables: i
Iterator variables: i
Python program:
def Count ( temp ) :
    query = [ 9 , 3 , 2 ]
    Q = len ( query )
    for i in range ( Q ) :
        pos = query [ i ]
        print ( temp [ pos - 1 ] )
def processing ( s ) :
    temp = [ 0 ] * len ( s )
    d = dict ( )
    for i in range ( len ( s ) ) :
        if s [ i ] not in d :
            d [ s [ i ] ] = i
        else :
            temp [ i ] = temp [ d [ s [ i ] ] ] + 1
            d [ s [ i ] ] = i
    return temp
if __name__ == " _ _ main _ _ " :
    s = " abacsddaa "
    n = len ( s )
    temp = processing ( s )
    Count ( temp )

Index/key variables: i
Iterator variables: i
Python program:
sticks = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ;
def countSticks ( string , n ) :
    cnt = 0 ;
    for i in range ( n ) :
        cnt += ( sticks [ ord ( string [ i ] ) - ord ( '0' ) ] ) ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    string = "56" ;
    n = len ( string ) ;
    print ( countSticks ( string , n ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def getMod ( _str , n , k ) :
    pwrTwo = [ 0 ] * n
    pwrTwo [ 0 ] = 1 % k
    for i in range ( 1 , n ) :
        pwrTwo [ i ] = pwrTwo [ i - 1 ] * ( 2 % k )
        pwrTwo [ i ] %= k
    res = 0
    i = 0
    j = n - 1
    while ( i < n ) :
        if ( _str [ j ] == '1' ) :
            res += ( pwrTwo [ i ] )
            res %= k
        i += 1
        j -= 1
    return res
_str = "1101"
n = len ( _str )
k = 45
print ( getMod ( _str , n , k ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i
Python program:
MOD = 1000000007
def countStrings ( N ) :
    dp = [ [ 0 ] * 3 for i in range ( N + 1 ) ]
    dp [ 1 ] [ 0 ] = 1 ;
    dp [ 1 ] [ 1 ] = 1 ;
    dp [ 1 ] [ 2 ] = 0 ;
    for i in range ( 2 , N + 1 ) :
        dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] + dp [ i - 1 ] [ 2 ] ) % MOD
        dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] % MOD
        dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] % MOD
    ans = ( dp [ N ] [ 0 ] + dp [ N ] [ 1 ] + dp [ N ] [ 2 ] ) % MOD
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 3
    print ( countStrings ( N ) )

Index/key variables: N, i
Iterator variables: i
Python program:
def maxNumber ( string , n ) :
    freq = [ 0 , 0 ]
    for i in range ( n ) :
        if ( string [ i ] == ' z ' ) :
            freq [ 0 ] += 1 ;
        elif ( string [ i ] == ' n ' ) :
            freq [ 1 ] += 1 ;
    num = " " ;
    for i in range ( freq [ 1 ] ) :
        num += '1' ;
    for i in range ( freq [ 0 ] ) :
        num += '0' ;
    return num ;
if __name__ == " _ _ main _ _ " :
    string = " roenenzooe " ;
    n = len ( string ) ;
    print ( maxNumber ( string , n ) ) ;

Index/key variables: i
Accumulator variables: num
Iterator variables: i
Python program:
def result ( s , n ) :
    st = set ( ) ;
    for i in range ( len ( s ) ) :
        ans = " " ;
        for j in range ( i , len ( s ) ) :
            ans += s [ j ] ;
            if ( len ( ans ) == n ) :
                st . add ( ans ) ;
                break ;
    for it in st :
        print ( it , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    s = " abca " ;
    n = 3 ;
    result ( s , n ) ;

Index/key variables: j
Accumulator variables: ans, st
Iterator variables: i, it, j
Python program:
def decToBinary ( n ) :
    binaryNum = [ 0 for i in range ( 32 ) ]
    i = 0
    while ( n > 0 ) :
        binaryNum [ i ] = n % 2
        n = n // 2
        i += 1
    binary = " "
    for j in range ( i - 1 , - 1 , - 1 ) :
        binary += str ( binaryNum [ j ] )
    return binary
def countFreq ( pat , txt ) :
    M = len ( pat )
    N = len ( txt )
    res = 0
    for i in range ( N - M + 1 ) :
        j = 0
        while ( j < M ) :
            if ( txt [ i + j ] != pat [ j ] ) :
                break
            j += 1
        if ( j == M ) :
            res += 1
            j = 0
    return res
def findOccurrence ( arr , n , pattern ) :
    for i in range ( n ) :
        binary = decToBinary ( arr [ i ] )
        print ( countFreq ( pattern , binary ) , end = " ▁ " )
arr = [ 5 , 106 , 7 , 8 ]
pattern = "10"
n = len ( arr )
findOccurrence ( arr , n , pattern )

Index/key variables: i, j
Accumulator variables: binary, res
Iterator variables: i, j
Python program:
def find_winner ( string , n ) :
    string1 = " " ; string2 = " " ;
    for i in range ( n ) :
        if ( i % 2 == 0 ) :
            string1 += string [ i ] ;
        else :
            string2 += string [ i ] ;
    string1 = " " . join ( sorted ( string1 ) )
    string2 = " " . join ( sorted ( string2 ) )
    if ( string1 < string2 ) :
        print ( " A " , end = " " ) ;
    elif ( string2 < string1 ) :
        print ( " B " , end = " " ) ;
    else :
        print ( " Tie " , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    n = len ( string ) ;
    find_winner ( string , n ) ;

Index/key variables: i
Accumulator variables: string1, string2
Iterator variables: i
Python program:
def Find_Index ( str1 , str2 ) :
    n = len ( str1 )
    m = len ( str2 )
    l = 0
    r = 0
    if ( n != m + 1 ) :
        return - 1
    for i in range ( m ) :
        if str1 [ i ] == str2 [ i ] :
            l += 1
        else :
            break
    i = n - 1
    j = m - 1
    while i >= 0 and j >= 0 and str1 [ i ] == str2 [ j ] :
        r += 1
        i -= 1
        j -= 1
    if l + r < m :
        return - 1
    else :
        i = max ( n - r , 1 )
        j = min ( l + 1 , n )
        return ( j - i + 1 )
if __name__ == " _ _ main _ _ " :
    str1 = " aaa "
    str2 = " aa "
    print ( Find_Index ( str1 , str2 ) )

Index/key variables: i, j
Accumulator variables: l, r
Iterator variables: i
Python program:
def expandString ( strin ) :
    temp = " "
    j = 0
    i = 0
    while ( i < len ( strin ) ) :
        if ( strin [ i ] >= "0" ) :
            num = ord ( strin [ i ] ) - ord ( "0" )
            if ( strin [ i + 1 ] == ' ( ' ) :
                j = i + 1
                while ( strin [ j ] != ' ) ' ) :
                    if ( ( strin [ j ] >= ' a ' and strin [ j ] <= ' z ' ) or ( strin [ j ] >= ' A ' and strin [ j ] <= ' Z ' ) ) :
                        temp += strin [ j ]
                    j += 1
                for k in range ( 1 , num + 1 ) :
                    print ( temp , end = " " )
                num = 0
                temp = " "
                if ( j < len ( strin ) ) :
                    i = j
        i += 1
strin = "3 ( ab ) 4 ( cd ) "
expandString ( strin )

Index/key variables: i, j
Accumulator variables: temp
Iterator variables: k
Python program:
import operator
def findPrefix ( str1 , str2 ) :
    pos = False ;
    while ( len ( str1 ) != 0 ) :
        if operator . contains ( str2 , str1 ) != True :
            str1 = str1 [ 0 : len ( str1 ) - 1 ] ;
        else :
            pos = operator . contains ( str2 , str1 ) ;
            break ;
    if ( pos == False ) :
        return " - 1" ;
    return str1 ;
if __name__ == ' _ _ main _ _ ' :
    str1 = " geeksfor " ;
    str2 = " forgeeks " ;
    print ( findPrefix ( str1 , str2 ) ) ;

Boolean variables: pos
Python program:
def roundToNearest ( str , n ) :
    if ( str == " " ) :
        return
    if ( ord ( str [ n - 1 ] ) - ord ( '0' ) <= 5 ) :
        str = list ( str )
        str [ n - 1 ] = '0'
        str = ' ' . join ( str )
        print ( str [ 0 : n ] )
    else :
        carry = 0
        str = list ( str )
        str [ n - 1 ] = '0'
        str = ' ' . join ( str )
        i = n - 2
        carry = 1
        while ( i >= 0 and carry == 1 ) :
            currentDigit = ord ( str [ i ] ) - ord ( '0' )
            currentDigit += carry
            if ( currentDigit > 9 ) :
                carry = 1
                currentDigit = 0
            else :
                carry = 0
            str [ i ] = chr ( currentDigit + '0' )
            i -= 1
        if ( carry == 1 ) :
            print ( carry )
        print ( str [ 0 : n ] )
if __name__ == ' _ _ main _ _ ' :
    str = "99999999999999993"
    n = len ( str )
    roundToNearest ( str , n )

Index/key variables: i
Accumulator variables: currentDigit
Python program:
def isDigit ( ch ) :
    if ch >= '0' and ch <= '9' :
        return True
    return False
def nextNonDigit ( string , i ) :
    while i < len ( string ) and isDigit ( string [ i ] ) :
        i += 1
    if i >= len ( string ) :
        return - 1
    return i
def appendRepeated ( sb , string , times ) :
    for i in range ( times ) :
        sb . append ( string )
def findString ( string , n ) :
    sb = list ( )
    startStr = nextNonDigit ( string , 0 )
    while startStr != - 1 :
        endStr = startStr
        while ( endStr + 1 < n and not isDigit ( string [ endStr + 1 ] ) ) :
            endStr += 1
        startNum = endStr + 1
        if startNum == - 1 :
            break
        endNum = startNum
        while ( endNum + 1 < n and isDigit ( string [ endNum + 1 ] ) ) :
            endNum += 1
        num = int ( string [ startNum : endNum + 1 ] )
        appendRepeated ( sb , string [ startStr : endStr + 1 ] , num )
        startStr = nextNonDigit ( string , endStr + 1 )
    sb = ' ' . join ( sb )
    return sb
if __name__ == " _ _ main _ _ " :
    string = " g1ee1ks1for1g1e2ks1"
    n = len ( string )
    print ( findString ( string , n ) )

Index/key variables: i
Accumulator variables: endNum, endStr, sb
Iterator variables: i
Python program:
MAX = 256
def smallestStr ( str , n ) :
    i , j = 0 , 0
    chk = [ 0 for i in range ( MAX ) ]
    for i in range ( MAX ) :
        chk [ i ] = - 1
    for i in range ( n ) :
        if ( chk [ ord ( str [ i ] ) ] == - 1 ) :
            chk [ ord ( str [ i ] ) ] = i
    for i in range ( n ) :
        flag = False
        for j in range ( ord ( str [ i ] ) ) :
            if ( chk [ j ] > chk [ ord ( str [ i ] ) ] ) :
                flag = True
                break
        if ( flag ) :
            break
    if ( i < n ) :
        ch1 = ( str [ i ] )
        ch2 = chr ( j )
        for i in range ( n ) :
            if ( str [ i ] == ch1 ) :
                str [ i ] = ch2
            elif ( str [ i ] == ch2 ) :
                str [ i ] = ch1
    return " " . join ( str )
st = " ccad "
str = [ i for i in st ]
n = len ( str )
print ( smallestStr ( str , n ) )

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: flag
Python program:
def longest_substring ( s , k ) :
    n = len ( s )
    if ( k > 1 ) :
        s += s
        n *= 2
    ans = 0
    i = 0
    while ( i < n ) :
        x = 0
        while ( i < n and s [ i ] == '0' ) :
            x , i = x + 1 , i + 1
        ans = max ( ans , x )
        i += 1
    if ( k == 1 or ans != n ) :
        return ans
    else :
        return ( ans // 2 ) * k
s = "010001000"
k = 4
print ( longest_substring ( s , k ) )

Index/key variables: i
Python program:
def Occurrence ( s , position ) :
    count = 0
    for i in range ( position - 1 ) :
        if ( s [ i ] == s [ position - 1 ] ) :
            count += 1
    return count
s = " ababababab " ;
p = 9
print ( Occurrence ( s , p ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def countOccurrence ( s , position ) :
    alpha = [ 0 ] * 26
    b = [ 0 ] * len ( s )
    for i in range ( 0 , len ( s ) ) :
        b [ i ] = alpha [ ord ( s [ i ] ) - 97 ]
        alpha [ ord ( s [ i ] ) - 97 ] = alpha [ ord ( s [ i ] ) - 97 ] + 1
    return b [ position - 1 ]
s = " ababababab "
p = 9
print ( countOccurrence ( s , p ) )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 26
def canBeMapped ( s1 , l1 , s2 , l2 ) :
    if ( l1 != l2 ) :
        return False
    freq1 = [ 0 for i in range ( MAX ) ]
    freq2 = [ 0 for i in range ( MAX ) ]
    for i in range ( l1 ) :
        freq1 [ ord ( s1 [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( l2 ) :
        freq2 [ ord ( s2 [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( MAX ) :
        if ( freq1 [ i ] == 0 ) :
            continue
        found = False
        for j in range ( MAX ) :
            if ( freq1 [ i ] == freq2 [ j ] ) :
                freq2 [ j ] = - 1
                found = True
                break
        if ( found == False ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    s1 = " axx "
    s2 = " cbc "
    l1 = len ( s1 )
    l2 = len ( s2 )
    if ( canBeMapped ( s1 , l1 , s2 , l2 ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: found
Python program:
stringSet = dict ( )
def find_permutation ( str1 , str2 , len1 , len2 , i , j , res ) :
    if ( len ( res ) == len1 + len2 ) :
        stringSet [ res ] = 1
        return
    if ( i < len1 ) :
        find_permutation ( str1 , str2 , len1 , len2 , i + 1 , j , res + str1 [ i ] )
    if ( j < len2 ) :
        find_permutation ( str1 , str2 , len1 , len2 , i , j + 1 , res + str2 [ j ] )
def print_set ( ) :
    for i in stringSet :
        print ( i )
str1 = " aa "
str2 = " ab "
len1 = len ( str1 )
len2 = len ( str2 )
find_permutation ( str1 , str2 , len1 , len2 , 0 , 0 , " " )
print_set ( )

Index/key variables: i, j, res
Iterator variables: i
Python program:
def GetAllValidIpAddress ( result , givenString , index , count , ipAddress ) :
    if ( len ( givenString ) == index and count == 4 ) :
        ipAddress . pop ( ) ;
        result . append ( ipAddress ) ;
        return ;
    if ( len ( givenString ) < index + 1 ) :
        return ;
    ipAddress = ( ipAddress + givenString [ index : index + 1 ] + [ ' . ' ] ) ;
    GetAllValidIpAddress ( result , givenString , index + 1 , count + 1 , ipAddress ) ;
    ipAddress = ipAddress [ : - 2 ] ;
    if ( len ( givenString ) < index + 2 or givenString [ index ] == '0' ) :
        return ;
    ipAddress = ipAddress + givenString [ index : index + 2 ] + [ ' . ' ] ;
    GetAllValidIpAddress ( result , givenString , index + 2 , count + 1 , ipAddress ) ;
    ipAddress = ipAddress [ : - 3 ] ;
    if ( len ( givenString ) < index + 3 or int ( " " . join ( givenString [ index : index + 3 ] ) ) > 255 ) :
        return ;
    ipAddress += givenString [ index : index + 3 ] + [ ' . ' ] ;
    GetAllValidIpAddress ( result , givenString , index + 3 , count + 1 , ipAddress ) ;
    ipAddress = ipAddress [ : - 4 ] ;
if __name__ == " _ _ main _ _ " :
    givenString = list ( "25525511135" ) ;
    result = [ ] ;
    GetAllValidIpAddress ( result , givenString , 0 , 0 , [ ] ) ;
    for i in range ( len ( result ) ) :
        print ( " " . join ( result [ i ] ) ) ;

Index/key variables: i, index
Iterator variables: i
Python program:
def countSubStr ( s , n ) :
    count = 0 ;
    i = 0
    while i < ( n - 2 ) :
        if ( s [ i ] == '0' and s [ i + 1 ] == '1' and s [ i + 2 ] == '0' ) :
            count += 1 ;
            i += 3 ;
        elif ( s [ i ] == '1' and s [ i + 1 ] == '0' and s [ i + 2 ] == '1' ) :
            count += 1 ;
            i += 3 ;
        else :
            i += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    s = "10101010101" ;
    n = len ( s ) ;
    print ( countSubStr ( s , n ) ) ;

Index/key variables: i
Accumulator variables: count
Python program:
def countTotalDistinct ( string ) :
    cnt = 0 ;
    items = set ( ) ;
    for i in range ( len ( string ) ) :
        temp = " " ;
        ans = set ( ) ;
        for j in range ( i , len ( string ) ) :
            temp = temp + string [ j ] ;
            ans . add ( string [ j ] ) ;
            if temp not in items :
                items . add ( temp ) ;
                cnt += len ( ans ) ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    string = " ABCA " ;
    print ( countTotalDistinct ( string ) ) ;

Index/key variables: j
Accumulator variables: ans, cnt, items
Iterator variables: i, j
Python program:
def division_of_string ( string , k ) :
    n = len ( string ) ;
    has = { } ;
    cnt = 0 ; i = 0 ;
    while ( i < n ) :
        if string [ i ] not in has :
            cnt += 1 ;
            has [ string [ i ] ] = True ;
        if ( cnt == k ) :
            ans = i ;
            break ;
        i += 1 ;
    i += 1 ;
    has . clear ( ) ;
    cnt = 0 ;
    while ( i < n ) :
        if ( string [ i ] not in has ) :
            cnt += 1 ;
            has [ string [ i ] ] = True ;
        if ( cnt == k ) :
            break ;
        i += 1 ;
    if ( cnt < k ) :
        print ( " Not ▁ possible " , end = " " ) ;
    else :
        i = 0 ;
        while ( i <= ans ) :
            print ( string [ i ] , end = " " ) ;
            i += 1 ;
        print ( ) ;
        while ( i < n ) :
            print ( string [ i ] , end = " " ) ;
            i += 1 ;
        print ( )
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    k = 4 ;
    division_of_string ( string , k ) ;

Index/key variables: i
Accumulator variables: cnt
Python program:
def isVowel ( c ) :
    return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) ;
def countSubstringsUtil ( s ) :
    count = 0 ;
    mp = dict . fromkeys ( s , 0 ) ;
    n = len ( s ) ;
    start = 0 ;
    for i in range ( n ) :
        mp [ s [ i ] ] += 1 ;
        while ( mp [ ' a ' ] > 0 and mp [ ' e ' ] > 0 and mp [ ' i ' ] > 0 and mp [ ' o ' ] > 0 and mp [ ' u ' ] > 0 ) :
            count += n - i ;
            mp [ s [ start ] ] -= 1 ;
            start += 1 ;
    return count ;
def countSubstrings ( s ) :
    count = 0 ;
    temp = " " ;
    for i in range ( len ( s ) ) :
        if ( isVowel ( s [ i ] ) ) :
            temp += s [ i ] ;
        else :
            if ( len ( temp ) > 0 ) :
                count += countSubstringsUtil ( temp ) ;
            temp = " " ;
    if ( len ( temp ) > 0 ) :
        count += countSubstringsUtil ( temp ) ;
    return count ;
if __name__ == " _ _ main _ _ " :
    s = " aeouisddaaeeiouua " ;
    print ( countSubstrings ( s ) ) ;

Index/key variables: i, start
Accumulator variables: count, temp
Iterator variables: i
Python program:
def removeDuplicates ( S ) :
    ans = " " ;
    for it in S :
        if ( ans == " " or ans [ - 1 ] != it ) :
            ans += it ;
        elif ( ans [ - 1 ] == it ) :
            ans = ans [ : - 1 ] ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    string = " keexxllx " ;
    print ( removeDuplicates ( string ) ) ;

Accumulator variables: ans
Iterator variables: it
Python program:
def reverseWords ( Str ) :
    start = 0
    for i in range ( len ( Str ) ) :
        if ( Str [ i ] == ' ▁ ' or i == len ( Str ) - 1 ) :
            end = i - 1
            if ( i == len ( Str ) - 1 ) :
                end = i
            while ( start < end ) :
                Str [ start ] , Str [ end ] = Str [ end ] , Str [ start ]
                start += 1
                end -= 1
            start = i + 1
    return " " . join ( Str )
Str = " Geeks ▁ for ▁ Geeks "
Str = [ i for i in Str ]
print ( reverseWords ( Str ) )

Index/key variables: end, i, start
Iterator variables: i
Python program:
def reverse ( k ) :
    s = [ ]
    token = k . split ( )
    for word in token :
        s . append ( word ) ;
    while ( len ( s ) ) :
        print ( s . pop ( ) , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    k = " geeks ▁ for ▁ geeks " ;
    reverse ( k ) ;

Accumulator variables: s
Iterator variables: word
Python program:
def countSubString ( s , c , k ) :
    leftCount = 0
    rightCount = 0
    left = 0
    right = 0
    freq = 0
    result = 0
    Len = len ( s )
    while ( s [ left ] != c and left < Len ) :
        left += 1
        leftCount += 1
    right = left + 1
    while ( freq != ( k - 1 ) and ( right - 1 ) < Len ) :
        if ( s [ right ] == c ) :
            freq += 1
        right += 1
    while ( left < Len and ( right - 1 ) < Len ) :
        while ( s [ left ] != c and left < Len ) :
            left += 1
            leftCount += 1
        while ( right < Len 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
s = "3123231"
c = '3'
k = 2
print ( countSubString ( s , c , k ) )

Index/key variables: left, right
Accumulator variables: freq, leftCount, rightCount
Python program:
MOD = 1000000007
def solve ( test ) :
    size = len ( test )
    total = 0
    for i in range ( 9 ) :
        x = i
        y = i + 1
        newtest = " "
        for j in range ( size ) :
            if ( ord ( test [ j ] ) == x + 48 or ord ( test [ j ] ) == y + 48 ) :
                newtest += test [ j ]
        if ( len ( newtest ) > 0 ) :
            size1 = len ( newtest )
            prefix = [ 0 for i in range ( size1 ) ]
            for j in range ( size1 ) :
                if ( ord ( newtest [ j ] ) == y + 48 ) :
                    prefix [ j ] += 1
            for j in range ( 1 , size1 ) :
                prefix [ j ] += prefix [ j - 1 ]
            count = 0
            firstcount = 0
            ss = 0
            prev = 0
            for j in range ( size1 ) :
                if ( ord ( newtest [ j ] ) == x + 48 ) :
                    count += 1
                    firstcount += 1
                else :
                    ss += count * count
                    pairsum = ( firstcount * firstcount - ss ) // 2
                    temp = pairsum
                    pairsum -= prev
                    prev = temp
                    secondway = prefix [ size1 - 1 ]
                    if ( j != 0 ) :
                        secondway -= prefix [ j - 1 ]
                    answer = count * ( count - 1 ) * secondway * ( secondway - 1 )
                    answer //= 4
                    answer += ( pairsum * secondway * ( secondway - 1 ) ) // 2
                    total += answer
                    count = 0
    return total
test = "13134422"
print ( solve ( test ) )

Index/key variables: j
Accumulator variables: answer, count, firstcount, newtest, pairsum, secondway, ss, total
Iterator variables: i, j