dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def xor_operations ( N , arr , M , K ) :
    if M < 0 or M >= N :
        return - 1
    if K < 0 or K >= N - M :
        return - 1
    for _ in range ( M ) :
        temp = [ ]
        for i in range ( len ( arr ) - 1 ) :
            value = arr [ i ] ^ arr [ i + 1 ]
            temp . append ( value )
        arr = temp [ : ]
    ans = arr [ K ]
    return ans
N = 5
arr = [ 1 , 4 , 5 , 6 , 7 ]
M = 1
K = 2
print ( xor_operations ( N , arr , M , K ) )

Index/key variables: K, i
Accumulator variables: temp
Iterator variables: i
Python program:
def canBreakN ( n ) :
    for i in range ( 2 , n ) :
        m = i * ( i + 1 ) // 2
        if ( m > n ) :
            break
        k = n - m
        if ( k % i ) :
            continue
        print ( i )
        return
    print ( " - 1" )
N = 12
canBreakN ( N )

Iterator variables: i
Python program:
import math
def findCoprimePair ( N ) :
    for x in range ( 2 , int ( math . sqrt ( N ) ) + 1 ) :
        if ( N % x == 0 ) :
            while ( N % x == 0 ) :
                N //= x
            if ( N > 1 ) :
                print ( x , N )
                return ;
    print ( " - 1" )
N = 45
findCoprimePair ( N )
N = 25
findCoprimePair ( N )

Accumulator variables: N
Iterator variables: x
Python program:
import math
MAX = 10000
primes = [ ]
def sieveSundaram ( ) :
    marked = [ False ] * ( ( MAX // 2 ) + 1 )
    for i in range ( 1 , ( ( int ( math . sqrt ( MAX ) ) - 1 ) // 2 ) + 1 ) :
        j = ( i * ( i + 1 ) ) << 1
        while j <= ( MAX // 2 ) :
            marked [ j ] = True
            j = j + 2 * i + 1
    primes . append ( 2 )
    for i in range ( 1 , ( MAX // 2 ) + 1 ) :
        if marked [ i ] == False :
            primes . append ( 2 * i + 1 )
def isWasteful ( n ) :
    if ( n == 1 ) :
        return False
    original_no = n
    sumDigits = 0
    while ( original_no > 0 ) :
        sumDigits += 1
        original_no = original_no // 10
    pDigit , count_exp , p = 0 , 0 , 0
    i = 0
    while ( primes [ i ] <= ( n // 2 ) ) :
        while ( n % primes [ i ] == 0 ) :
            p = primes [ i ]
            n = n // p
            count_exp += 1
        while ( p > 0 ) :
            pDigit += 1
            p = p // 10
        while ( count_exp > 1 ) :
            pDigit += 1
            count_exp = count_exp // 10
        i += 1
    if ( n != 1 ) :
        while ( n > 0 ) :
            pDigit += 1
            n = n // 10
    return bool ( pDigit > sumDigits )
def Solve ( N ) :
    for i in range ( 1 , N ) :
        if ( isWasteful ( i ) ) :
            print ( i , end = " ▁ " )
sieveSundaram ( )
N = 10
Solve ( N )

Index/key variables: i, j
Accumulator variables: count_exp, pDigit, primes, sumDigits
Iterator variables: i
Python program:
def printhexa ( n ) :
    if ( n < 0 ) :
        return
    first = 0
    second = 0
    third = 0
    fourth = 0
    fifth = 0
    sixth = 1
    curr = 0
    if ( n < 6 ) :
        print ( first )
    elif ( n == 6 ) :
        print ( sixth )
    else :
        for i in range ( 6 , n ) :
            curr = first + second + third + fourth + fifth + sixth
            first = second
            second = third
            third = fourth
            fourth = fifth
            fifth = sixth
            sixth = curr
    print ( curr )
n = 11
printhexa ( n )

Iterator variables: i
Python program:
def isComposite ( n ) :
    if ( n <= 3 ) :
        return False
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return True
    i = 5
    while ( i * i <= n ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return True
        i = i + 6
    return False
def Compositorial_list ( n ) :
    l = 0
    for i in range ( 4 , 10 ** 6 ) :
        if l < n :
            if isComposite ( i ) :
                compo . append ( i )
                l += 1
def calculateCompositorial ( n ) :
    result = 1
    for i in range ( n ) :
        result = result * compo [ i ]
    return result
if __name__ == " _ _ main _ _ " :
    n = 5
    compo = [ ]
    Compositorial_list ( n )
    print ( calculateCompositorial ( n ) )

Index/key variables: i
Accumulator variables: compo, l
Iterator variables: i
Python program:
b = [ 0 for i in range ( 50 ) ]
def PowerArray ( n , k ) :
    count = 0
    while ( k ) :
        if ( k % n == 0 ) :
            k //= n
            count += 1
        elif ( k % n == 1 ) :
            k -= 1
            b [ count ] += 1
            if ( b [ count ] > 1 ) :
                print ( - 1 )
                return 0
        else :
            print ( - 1 )
            return 0
    for i in range ( 50 ) :
        if ( b [ i ] ) :
            print ( i , end = " , " )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    K = 40
    PowerArray ( N , K )

Index/key variables: count, i
Accumulator variables: k
Iterator variables: i
Python program:
from math import pow
def findSum ( N , k ) :
    sum = 0
    for i in range ( 1 , N + 1 , 1 ) :
        sum += pow ( i , k )
    return sum
if __name__ == ' _ _ main _ _ ' :
    N = 8
    k = 4
    print ( int ( findSum ( N , k ) ) )

Accumulator variables: sum
Iterator variables: i
Python program:
def countIndices ( arr , n ) :
    cnt = 0 ;
    max = 0 ;
    for i in range ( n ) :
        if ( max < arr [ i ] ) :
            max = arr [ i ] ;
            cnt += 1 ;
    return cnt ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ] ;
    n = len ( arr ) ;
    print ( countIndices ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
bin = [ "000" , "001" , "010" , "011" , "100" , "101" , "110" , "111" ] ;
def maxFreq ( s ) :
    binary = " " ;
    for i in range ( len ( s ) ) :
        binary += bin [ ord ( s [ i ] ) - ord ( '0' ) ] ;
    binary = binary [ 0 : len ( binary ) - 1 ] ;
    count = 1 ; prev = - 1 ; j = 0 ;
    for i in range ( len ( binary ) - 1 , - 1 , - 1 ) :
        if ( binary [ i ] == '1' ) :
            count = max ( count , j - prev ) ;
            prev = j ;
        j += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    octal = "13" ;
    print ( maxFreq ( octal ) ) ;

Index/key variables: i
Accumulator variables: binary, j
Iterator variables: i
Python program:
from math import sqrt , pow
sz = 100005
isPrime = [ True for i in range ( sz + 1 ) ]
def sieve ( ) :
    isPrime [ 0 ] = isPrime [ 1 ] = False
    for i in range ( 2 , int ( sqrt ( sz ) ) + 1 , 1 ) :
        if ( isPrime [ i ] ) :
            for j in range ( i * i , sz , i ) :
                isPrime [ j ] = False
def findPrimesD ( d ) :
    left = int ( pow ( 10 , d - 1 ) )
    right = int ( pow ( 10 , d ) - 1 )
    for i in range ( left , right + 1 , 1 ) :
        if ( isPrime [ i ] ) :
            print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    sieve ( )
    d = 1
    findPrimesD ( d )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def Cells ( n , x ) :
    if ( n <= 0 or x <= 0 or x > n * n ) :
        return 0 ;
    i = 1
    count = 0
    while ( i * i < x ) :
        if ( x % i == 0 and x <= n * i ) :
            count += 2 ;
        i += 1
    if ( i * i == x ) :
        return count + 1
    else :
        return count
n = 6
x = 12
print ( Cells ( n , x ) )

Accumulator variables: count, i
Python program:
def maxOfMin ( a , n , S ) :
    mi = 10 ** 9
    s1 = 0
    for i in range ( n ) :
        s1 += a [ i ]
        mi = min ( a [ i ] , mi )
    if ( s1 < S ) :
        return - 1
    if ( s1 == S ) :
        return 0
    low = 0
    high = mi
    ans = 0
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( s1 - ( mid * n ) >= S ) :
            ans = mid
            low = mid + 1
        else :
            high = mid - 1
    return ans
a = [ 10 , 10 , 10 , 10 , 10 ]
S = 10
n = len ( a )
print ( maxOfMin ( a , n , S ) )

Index/key variables: i
Accumulator variables: s1
Iterator variables: i
Python program:
def isSumDivides ( N ) :
    temp = N
    sum = 0
    while ( temp ) :
        sum += temp % 10
        temp = int ( temp / 10 )
    if ( N % sum == 0 ) :
        return 1
    else :
        return 0
if __name__ == ' _ _ main _ _ ' :
    N = 12
    if ( isSumDivides ( N ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Accumulator variables: sum
Python program:
def nextGreater ( N ) :
    power_of_2 = 1 ;
    shift_count = 0 ;
    while ( True ) :
        if ( ( ( N >> shift_count ) & 1 ) % 2 == 0 ) :
            break ;
        shift_count += 1 ;
        power_of_2 = power_of_2 * 2 ;
    return ( N + power_of_2 ) ;
N = 11 ;
print ( " The ▁ next ▁ number ▁ is ▁ = " , nextGreater ( N ) ) ;

Accumulator variables: shift_count
Python program:
def countWays ( n ) :
    if ( n == 0 ) :
        return 1
    if ( n <= 2 ) :
        return n
    f0 = 1
    f1 = 1
    f2 = 2
    ans = 0
    for i in range ( 3 , n + 1 ) :
        ans = f0 + f1 + f2
        f0 = f1
        f1 = f2
        f2 = ans
    return ans
n = 4
print ( countWays ( n ) )

Iterator variables: i
Python program:
import numpy as np
n = 6 ; m = 6 ;
def maxSum ( arr ) :
    dp = np . zeros ( ( n + 1 , 3 ) ) ;
    for i in range ( n ) :
        m1 = 0 ; m2 = 0 ; m3 = 0 ;
        for j in range ( m ) :
            if ( ( j // ( m // 3 ) ) == 0 ) :
                m1 = max ( m1 , arr [ i ] [ j ] ) ;
            elif ( ( j // ( m // 3 ) ) == 1 ) :
                m2 = max ( m2 , arr [ i ] [ j ] ) ;
            elif ( ( j // ( m // 3 ) ) == 2 ) :
                m3 = max ( m3 , arr [ i ] [ j ] ) ;
        dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 1 ] , dp [ i ] [ 2 ] ) + m1 ;
        dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 2 ] ) + m2 ;
        dp [ i + 1 ] [ 2 ] = max ( dp [ i ] [ 1 ] , dp [ i ] [ 0 ] ) + m3 ;
    print ( max ( max ( dp [ n ] [ 0 ] , dp [ n ] [ 1 ] ) , dp [ n ] [ 2 ] ) ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] ] ;
    maxSum ( arr ) ;

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def solve ( s ) :
    n = len ( s )
    dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
    for Len in range ( n - 1 , - 1 , - 1 ) :
        for i in range ( n ) :
            if i + Len >= n :
                break
            j = i + Len
            if ( i == 0 and j == n - 1 ) :
                if ( s [ i ] == s [ j ] ) :
                    dp [ i ] [ j ] = 2
                elif ( s [ i ] != s [ j ] ) :
                    dp [ i ] [ j ] = 1
            else :
                if ( s [ i ] == s [ j ] ) :
                    if ( i - 1 >= 0 ) :
                        dp [ i ] [ j ] += dp [ i - 1 ] [ j ]
                    if ( j + 1 <= n - 1 ) :
                        dp [ i ] [ j ] += dp [ i ] [ j + 1 ]
                    if ( i - 1 < 0 or j + 1 >= n ) :
                        dp [ i ] [ j ] += 1
                elif ( s [ i ] != s [ j ] ) :
                    if ( i - 1 >= 0 ) :
                        dp [ i ] [ j ] += dp [ i - 1 ] [ j ]
                    if ( j + 1 <= n - 1 ) :
                        dp [ i ] [ j ] += dp [ i ] [ j + 1 ]
                    if ( i - 1 >= 0 and j + 1 <= n - 1 ) :
                        dp [ i ] [ j ] -= dp [ i - 1 ] [ j + 1 ]
    ways = [ ]
    for i in range ( n ) :
        if ( i == 0 or i == n - 1 ) :
            ways . append ( 1 )
        else :
            total = dp [ i - 1 ] [ i + 1 ]
            ways . append ( total )
    for i in ways :
        print ( i , end = " ▁ " )
s = " xyxyx "
solve ( s )

Index/key variables: i, j
Accumulator variables: ways
Iterator variables: Len, i
Python program:
def getChicks ( n ) :
    size = max ( n , 7 ) ;
    dp = [ 0 ] * size ;
    dp [ 0 ] = 0 ;
    dp [ 1 ] = 1 ;
    for i in range ( 2 , 7 ) :
        dp [ i ] = dp [ i - 1 ] * 3 ;
    dp [ 6 ] = 726 ;
    for i in range ( 8 , n + 1 ) :
        dp [ i ] = ( dp [ i - 1 ] - ( 2 * dp [ i - 6 ] // 3 ) ) * 3 ;
    return dp [ n ] ;
n = 3 ;
print ( getChicks ( n ) ) ;

Index/key variables: i, n
Iterator variables: i
Python program:
import numpy as np
n = 3
dp = np . zeros ( ( n , n ) )
v = np . zeros ( ( n , n ) ) ;
def minSteps ( i , j , arr ) :
    if ( i == n - 1 and j == n - 1 ) :
        return 0 ;
    if ( i > n - 1 or j > n - 1 ) :
        return 9999999 ;
    if ( v [ i ] [ j ] ) :
        return dp [ i ] [ j ] ;
    v [ i ] [ j ] = 1 ;
    dp [ i ] [ j ] = 9999999 ;
    for k in range ( max ( 0 , arr [ i ] [ j ] + j - n + 1 ) , min ( n - i - 1 , arr [ i ] [ j ] ) + 1 ) :
        dp [ i ] [ j ] = min ( dp [ i ] [ j ] , minSteps ( i + k , j + arr [ i ] [ j ] - k , arr ) ) ;
    dp [ i ] [ j ] += 1 ;
    return dp [ i ] [ j ] ;
if __name__ == " _ _ main _ _ " :
    arr = [ [ 4 , 1 , 2 ] , [ 1 , 1 , 1 ] , [ 2 , 1 , 1 ] ] ;
    ans = minSteps ( 0 , 0 , arr ) ;
    if ( ans >= 9999999 ) :
        print ( - 1 ) ;
    else :
        print ( ans ) ;

Index/key variables: i, j
Iterator variables: k
Python program:
import numpy as np ;
n = 3
dp = np . zeros ( ( n , n ) ) ;
v = np . zeros ( ( n , n ) ) ;
def minSteps ( i , j , arr ) :
    if ( i == n - 1 and j == n - 1 ) :
        return 0 ;
    if ( i > n - 1 or j > n - 1 ) :
        return 9999999 ;
    if ( v [ i ] [ j ] ) :
        return dp [ i ] [ j ] ;
    v [ i ] [ j ] = 1 ;
    dp [ i ] [ j ] = 1 + min ( minSteps ( i + arr [ i ] [ j ] , j , arr ) , minSteps ( i , j + arr [ i ] [ j ] , arr ) ) ;
    return dp [ i ] [ j ] ;
arr = [ [ 2 , 1 , 2 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ;
ans = minSteps ( 0 , 0 , arr ) ;
if ( ans >= 9999999 ) :
    print ( - 1 ) ;
else :
    print ( ans ) ;

Index/key variables: i, j
Python program:
MAX = 1001
dp = [ [ - 1 for i in range ( MAX ) ] for i in range ( MAX ) ]
def MaxProfit ( treasure , color , n , k , col , A , B ) :
    if ( k == n ) :
        dp [ k ] [ col ] = 0
        return dp [ k ] [ col ]
    if ( dp [ k ] [ col ] != - 1 ) :
        return dp [ k ] [ col ]
    summ = 0
    if ( col == color [ k ] ) :
        summ += max ( A * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )
    else :
        summ += max ( B * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )
    dp [ k ] [ col ] = summ
    return dp [ k ] [ col ]
A = - 5
B = 7
treasure = [ 4 , 8 , 2 , 9 ]
color = [ 2 , 2 , 6 , 2 ]
n = len ( color )
print ( MaxProfit ( treasure , color , n , 0 , 0 , A , B ) )

Index/key variables: col, k
Python program:
def printTetra ( n ) :
    dp = [ 0 ] * ( n + 5 ) ;
    dp [ 0 ] = 0 ;
    dp [ 1 ] = 1 ;
    dp [ 2 ] = 1 ;
    dp [ 3 ] = 2 ;
    for i in range ( 4 , n + 1 ) :
        dp [ i ] = ( dp [ i - 1 ] + dp [ i - 2 ] + dp [ i - 3 ] + dp [ i - 4 ] ) ;
    print ( dp [ n ] ) ;
n = 10 ;
printTetra ( n ) ;

Index/key variables: i, n
Iterator variables: i
Python program:
def maxSum1 ( arr , n ) :
    dp = [ 0 ] * n
    maxi = 0
    for i in range ( n - 1 ) :
        dp [ i ] = arr [ i ]
        if ( maxi < arr [ i ] ) :
            maxi = arr [ i ]
    for i in range ( 2 , n - 1 ) :
        for j in range ( i - 1 ) :
            if ( dp [ i ] < dp [ j ] + arr [ i ] ) :
                dp [ i ] = dp [ j ] + arr [ i ]
                if ( maxi < dp [ i ] ) :
                    maxi = dp [ i ]
    return maxi
def maxSum2 ( arr , n ) :
    dp = [ 0 ] * n
    maxi = 0
    for i in range ( 1 , n ) :
        dp [ i ] = arr [ i ]
        if ( maxi < arr [ i ] ) :
            maxi = arr [ i ]
    for i in range ( 3 , n ) :
        for j in range ( 1 , i - 1 ) :
            if ( dp [ i ] < arr [ i ] + dp [ j ] ) :
                dp [ i ] = arr [ i ] + dp [ j ]
                if ( maxi < dp [ i ] ) :
                    maxi = dp [ i ]
    return maxi
def findMaxSum ( arr , n ) :
    return max ( maxSum1 ( arr , n ) , maxSum2 ( arr , n ) )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 1 ]
    n = len ( arr )
    print ( findMaxSum ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def permutationCoeff ( n , k ) :
    P = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( min ( i , k ) + 1 ) :
            if ( j == 0 ) :
                P [ i ] [ j ] = 1
            else :
                P [ i ] [ j ] = P [ i - 1 ] [ j ] + ( j * P [ i - 1 ] [ j - 1 ] )
            if ( j < k ) :
                P [ i ] [ j + 1 ] = 0
    return P [ n ] [ k ]
n = 10
k = 2
print ( " Value ▁ fo ▁ P ( " , n , " , ▁ " , k , " ) ▁ is ▁ " , permutationCoeff ( n , k ) , sep = " " )

Index/key variables: i, j, k, n
Iterator variables: i, j
Python program:
def permutationCoeff ( n , k ) :
    fact = [ 0 for i in range ( n + 1 ) ]
    fact [ 0 ] = 1
    for i in range ( 1 , n + 1 ) :
        fact [ i ] = i * fact [ i - 1 ]
    return int ( fact [ n ] / fact [ n - k ] )
n = 10
k = 2
print ( " Value ▁ of ▁ P ( " , n , " , ▁ " , k , " ) ▁ is ▁ " , permutationCoeff ( n , k ) , sep = " " )

Index/key variables: i, n
Iterator variables: i
Python program:
def compute_z ( s , z ) :
    l = 0
    r = 0
    n = len ( s )
    for i in range ( 1 , n , 1 ) :
        if ( i > r ) :
            l = i
            r = i
            while ( r < n and s [ r - l ] == s [ r ] ) :
                r += 1
            z [ i ] = r - l
            r -= 1
        else :
            k = i - l
            if ( z [ k ] < r - i + 1 ) :
                z [ i ] = z [ k ]
            else :
                l = i
                while ( r < n and s [ r - l ] == s [ r ] ) :
                    r += 1
                z [ i ] = r - l
                r -= 1
def countPermutation ( a , b ) :
    b = b + b
    b = b [ 0 : len ( b ) - 1 ]
    ans = 0
    s = a + " $ " + b
    n = len ( s )
    z = [ 0 for i in range ( n ) ]
    compute_z ( s , z )
    for i in range ( 1 , n , 1 ) :
        if ( z [ i ] == len ( a ) ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = "101"
    b = "101"
    print ( countPermutation ( a , b ) )

Index/key variables: i, k, r
Accumulator variables: ans
Iterator variables: i
Python program:
def smallestSubsequence ( S , K ) :
    N = len ( S )
    answer = [ ]
    for i in range ( N ) :
        if ( len ( answer ) == 0 ) :
            answer . append ( S [ i ] )
        else :
            while ( len ( answer ) > 0 and ( S [ i ] < answer [ len ( answer ) - 1 ] ) and ( len ( answer ) - 1 + N - i >= K ) ) :
                answer = answer [ : - 1 ]
            if ( len ( answer ) == 0 or len ( answer ) < K ) :
                answer . append ( S [ i ] )
    ret = [ ]
    while ( len ( answer ) > 0 ) :
        ret . append ( answer [ len ( answer ) - 1 ] )
        answer = answer [ : - 1 ]
    ret = ret [ : : - 1 ]
    ret = ' ' . join ( ret )
    print ( ret )
if __name__ == ' _ _ main _ _ ' :
    S = " aabdaabc "
    K = 3
    smallestSubsequence ( S , K )

Index/key variables: i
Accumulator variables: answer, ret
Iterator variables: i
Python program:
from math import sqrt , floor , ceil
def is_rtol ( s ) :
    tmp = floor ( sqrt ( len ( s ) ) ) - 1
    first = s [ tmp ]
    for pos in range ( tmp , len ( s ) - 1 , tmp ) :
        if ( s [ pos ] != first ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    str = " abcxabxcaxbcxabc "
    if ( is_rtol ( str ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: pos, tmp
Iterator variables: pos
Python program:
def check ( str , K ) :
    if ( len ( str ) % K == 0 ) :
        sum = 0
        for i in range ( K ) :
            sum += ord ( str [ i ] ) ;
        for j in range ( K , len ( str ) , K ) :
            s_comp = 0 ;
            for p in range ( j , j + K ) :
                s_comp += ord ( str [ p ] ) ;
            if ( s_comp != sum ) :
                return False ;
        return True ;
    return False ;
K = 3 ;
str = " abdcbbdba " ;
if ( check ( str , K ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i, p
Accumulator variables: s_comp, sum
Iterator variables: i, j, p
Python program:
def maxSum ( str ) :
    maximumSum = 0
    totalOnes = 0
    for i in str :
        if i == '1' :
            totalOnes += 1
    zero = 0
    ones = 0
    i = 0
    while i < len ( str ) :
        if ( str [ i ] == '0' ) :
            zero += 1
        else :
            ones += 1
        maximumSum = max ( maximumSum , zero + ( totalOnes - ones ) )
        i += 1
    return maximumSum
if __name__ == ' _ _ main _ _ ' :
    str = "011101"
    print ( maxSum ( str ) )

Index/key variables: i
Accumulator variables: ones, totalOnes, zero
Iterator variables: i
Python program:
def maxLenSubStr ( s ) :
    if ( len ( s ) < 3 ) :
        return len ( s )
    temp = 2
    ans = 2
    for i in range ( 2 , len ( s ) ) :
        if ( s [ i ] != s [ i - 1 ] or s [ i ] != s [ i - 2 ] ) :
            temp += 1
        else :
            ans = max ( temp , ans )
            temp = 2
    ans = max ( temp , ans )
    return ans
s = " baaabbabbb "
print ( maxLenSubStr ( s ) )

Index/key variables: i
Accumulator variables: temp
Iterator variables: i
Python program:
def no_of_ways ( s ) :
    n = len ( s )
    count_left = 0
    count_right = 0
    for i in range ( 0 , n , 1 ) :
        if ( s [ i ] == s [ 0 ] ) :
            count_left += 1
        else :
            break
    i = n - 1
    while ( i >= 0 ) :
        if ( s [ i ] == s [ n - 1 ] ) :
            count_right += 1
        else :
            break
        i -= 1
    if ( s [ 0 ] == s [ n - 1 ] ) :
        return ( ( count_left + 1 ) * ( count_right + 1 ) )
    else :
        return ( count_left + count_right + 1 )
if __name__ == ' _ _ main _ _ ' :
    s = " geeksforgeeks "
    print ( no_of_ways ( s ) )

Index/key variables: i
Accumulator variables: count_left, count_right
Iterator variables: i
Python program:
def preCompute ( n , s , pref ) :
    for i in range ( 1 , n ) :
        pref [ i ] = pref [ i - 1 ]
        if s [ i - 1 ] == s [ i ] :
            pref [ i ] += 1
def query ( pref , l , r ) :
    return pref [ r ] - pref [ l ]
if __name__ == " _ _ main _ _ " :
    s = " ggggggg "
    n = len ( s )
    pref = [ 0 ] * n
    preCompute ( n , s , pref )
    l = 1
    r = 2
    print ( query ( pref , l , r ) )
    l = 1
    r = 5
    print ( query ( pref , l , r ) )

Index/key variables: i, l, r
Iterator variables: i
Python program:
def findDirection ( s ) :
    count = 0
    d = " "
    for i in range ( len ( s ) ) :
        if ( s [ i ] == ' L ' ) :
            count -= 1
        else :
            if ( s [ i ] == ' R ' ) :
                count += 1
    if ( count > 0 ) :
        if ( count % 4 == 0 ) :
            d = " N "
        elif ( count % 4 == 10 ) :
            d = " E "
        elif ( count % 4 == 2 ) :
            d = " S "
        elif ( count % 4 == 3 ) :
            d = " W "
    if ( count < 0 ) :
        count *= - 1
        if ( count % 4 == 0 ) :
            d = " N "
        elif ( count % 4 == 1 ) :
            d = " W "
        elif ( count % 4 == 2 ) :
            d = " S "
        elif ( count % 4 == 3 ) :
            d = " E "
    return d
if __name__ == ' _ _ main _ _ ' :
    s = " LLRLRRL "
    print ( findDirection ( s ) )
    s = " LL "
    print ( findDirection ( s ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def isCheck ( str ) :
    length = len ( str )
    lowerStr , upperStr = " " , " "
    for i in range ( length ) :
        if ( ord ( str [ i ] ) >= 65 and ord ( str [ i ] ) <= 91 ) :
            upperStr = upperStr + str [ i ]
        else :
            lowerStr = lowerStr + str [ i ]
    transformStr = lowerStr . upper ( )
    return transformStr == upperStr
if __name__ == " _ _ main _ _ " :
    str = " geeGkEEsKS "
    if isCheck ( str ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i