dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
dp = [ [ 0 for i in range ( 605 ) ] for j in range ( 105 ) ]
def find ( N , a , b ) :
    probability = 0.0
    for i in range ( 1 , 7 ) :
        dp [ 1 ] [ i ] = 1.0 / 6
    for i in range ( 2 , N + 1 ) :
        for j in range ( i , ( 6 * i ) + 1 ) :
            for k in range ( 1 , 7 ) :
                dp [ i ] [ j ] = dp [ i ] [ j ] + dp [ i - 1 ] [ j - k ] / 6
    for Sum in range ( a , b + 1 ) :
        probability = probability + dp [ N ] [ Sum ]
    return probability
N , a , b = 4 , 13 , 17
probability = find ( N , a , b )
print ( ' % .6f ' % probability )

Index/key variables: N, Sum, i, j
Iterator variables: Sum, i, j, k
Python program:
from collections import deque as queue
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def getSumAlternate ( root ) :
    if ( root == None ) :
        return 0
    sum = root . data
    if ( root . left != None ) :
        sum += getSum ( root . left . left )
        sum += getSum ( root . left . right )
    if ( root . right != None ) :
        sum += getSum ( root . right . left )
        sum += getSum ( root . right . right )
    return sum
def getSum ( root ) :
    if ( root == None ) :
        return 0
    return max ( getSumAlternate ( root ) , ( getSumAlternate ( root . left ) + getSumAlternate ( root . right ) ) )
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . right . left = Node ( 4 )
    root . right . left . right = Node ( 5 )
    root . right . left . right . left = Node ( 6 )
    print ( getSum ( root ) )

Class/struct names: Node
Python program:
def isSubsetSum ( arr , n , sum ) :
    subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]
    for i in range ( n + 1 ) :
        for j in range ( sum + 1 ) :
            if ( j == 0 ) :
                subset [ i % 2 ] [ j ] = True
            elif ( i == 0 ) :
                subset [ i % 2 ] [ j ] = False
            elif ( arr [ i - 1 ] <= j ) :
                subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]
            else :
                subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]
    return subset [ n % 2 ] [ sum ]
arr = [ 6 , 2 , 5 ]
sum = 7
n = len ( arr )
if ( isSubsetSum ( arr , n , sum ) == True ) :
    print ( " There ▁ exists ▁ a ▁ subset ▁ with ▁ given ▁ sum " )
else :
    print ( " No ▁ subset ▁ exists ▁ with ▁ given ▁ sum " )

Index/key variables: j, sum
Iterator variables: i, j
Python program:
import sys
def findMaxSum ( arr , n ) :
    res = - sys . maxsize - 1
    for i in range ( n ) :
        prefix_sum = arr [ i ]
        for j in range ( i ) :
            prefix_sum += arr [ j ]
        suffix_sum = arr [ i ]
        j = n - 1
        while ( j > i ) :
            suffix_sum += arr [ j ]
            j -= 1
        if ( prefix_sum == suffix_sum ) :
            res = max ( res , prefix_sum )
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 2 , 5 , 3 , 1 , 2 , 6 , - 4 , 2 ]
    n = len ( arr )
    print ( findMaxSum ( arr , n ) )

Index/key variables: i, j
Accumulator variables: prefix_sum, suffix_sum
Iterator variables: i, j
Python program:
def findMaxSum ( arr , n ) :
    preSum = [ 0 for i in range ( n ) ]
    suffSum = [ 0 for i in range ( n ) ]
    ans = - 10000000
    preSum [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        preSum [ i ] = preSum [ i - 1 ] + arr [ i ]
    suffSum [ n - 1 ] = arr [ n - 1 ]
    if ( preSum [ n - 1 ] == suffSum [ n - 1 ] ) :
        ans = max ( ans , preSum [ n - 1 ] )
    for i in range ( n - 2 , - 1 , - 1 ) :
        suffSum [ i ] = suffSum [ i + 1 ] + arr [ i ]
        if ( suffSum [ i ] == preSum [ i ] ) :
            ans = max ( ans , preSum [ i ] )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 2 , 5 , 3 , 1 , 2 , 6 , - 4 , 2 ]
    n = len ( arr )
    print ( findMaxSum ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def findMaxSum ( arr , n ) :
    ss = sum ( arr )
    prefix_sum = 0
    res = - sys . maxsize
    for i in range ( n ) :
        prefix_sum += arr [ i ]
        if prefix_sum == ss :
            res = max ( res , prefix_sum ) ;
        ss -= arr [ i ] ;
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ - 2 , 5 , 3 , 1 , 2 , 6 , - 4 , 2 ]
    n = len ( arr )
    print ( findMaxSum ( arr , n ) )

Index/key variables: i
Accumulator variables: prefix_sum, ss
Iterator variables: i
Python program:
def findMajority ( arr , n ) :
    maxCount = 0
    index = - 1
    for i in range ( n ) :
        count = 0
        for j in range ( n ) :
            if ( arr [ i ] == arr [ j ] ) :
                count += 1
        if ( count > maxCount ) :
            maxCount = count
            index = i
    if ( maxCount > n // 2 ) :
        print ( arr [ index ] )
    else :
        print ( " No ▁ Majority ▁ Element " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 2 , 1 , 3 , 5 , 1 ]
    n = len ( arr )
    findMajority ( arr , n )

Index/key variables: i, index, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def findCandidate ( A ) :
    maj_index = 0
    count = 1
    for i in range ( len ( A ) ) :
        if A [ maj_index ] == A [ i ] :
            count += 1
        else :
            count -= 1
        if count == 0 :
            maj_index = i
            count = 1
    return A [ maj_index ]
def isMajority ( A , cand ) :
    count = 0
    for i in range ( len ( A ) ) :
        if A [ i ] == cand :
            count += 1
    if count > len ( A ) / 2 :
        return True
    else :
        return False
def printMajority ( A ) :
    cand = findCandidate ( A )
    if isMajority ( A , cand ) == True :
        print ( cand )
    else :
        print ( " No ▁ Majority ▁ Element " )
A = [ 1 , 3 , 3 , 1 , 2 ]
printMajority ( A )

Index/key variables: i, maj_index
Accumulator variables: count
Iterator variables: i
Python program:
def findMajority ( arr , size ) :
    m = { }
    for i in range ( size ) :
        if arr [ i ] in m :
            m [ arr [ i ] ] += 1
        else :
            m [ arr [ i ] ] = 1
    count = 0
    for key in m :
        if m [ key ] > size / 2 :
            count = 1
            print ( " Majority ▁ found ▁ : - " , key )
            break
    if ( count == 0 ) :
        print ( " No ▁ Majority ▁ element " )
arr = [ 2 , 2 , 2 , 2 , 5 , 5 , 2 , 3 , 3 ]
n = len ( arr )
findMajority ( arr , n )

Index/key variables: i, key
Iterator variables: i, key
Python program:
def majorityElement ( arr , n ) :
    arr . sort ( )
    count , max_ele , temp , f = 1 , - 1 , arr [ 0 ] , 0
    for i in range ( 1 , n ) :
        if ( temp == arr [ i ] ) :
            count += 1
        else :
            count = 1
            temp = arr [ i ]
        if ( max_ele < count ) :
            max_ele = count
            ele = arr [ i ]
            if ( max_ele > ( n // 2 ) ) :
                f = 1
                break
    if f == 1 :
        return ele
    else :
        return - 1
arr = [ 1 , 1 , 2 , 1 , 3 , 5 , 1 ]
n = len ( arr )
print ( majorityElement ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
tab = [ [ - 1 for i in range ( 2000 ) ] for j in range ( 2000 ) ]
def subsetSum ( a , n , sum ) :
    if ( sum == 0 ) :
        return 1
    if ( n <= 0 ) :
        return 0
    if ( tab [ n - 1 ] [ sum ] != - 1 ) :
        return tab [ n - 1 ] [ sum ]
    if ( a [ n - 1 ] > sum ) :
        tab [ n - 1 ] [ sum ] = subsetSum ( a , n - 1 , sum )
        return tab [ n - 1 ] [ sum ]
    else :
        tab [ n - 1 ] [ sum ] = subsetSum ( a , n - 1 , sum )
        return tab [ n - 1 ] [ sum ] or subsetSum ( a , n - 1 , sum - a [ n - 1 ] )
n = 5
a = [ 1 , 5 , 3 , 7 , 4 ]
sum = 12
if ( subsetSum ( a , n , sum ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: sum
Python program:
from math import log
def binpow ( a , b ) :
    res = 1
    while ( b > 0 ) :
        if ( b % 2 == 1 ) :
            res = res * a
        a = a * a
        b //= 2
    return res
def find ( x ) :
    if ( x == 0 ) :
        return 0
    p = log ( x ) / log ( 2 )
    return binpow ( 2 , p + 1 ) - 1
def getBinary ( n ) :
    ans = " "
    while ( n > 0 ) :
        dig = n % 2
        ans += str ( dig )
        n //= 2
    return ans
def totalCountDifference ( n ) :
    ans = getBinary ( n )
    req = 0
    for i in range ( len ( ans ) ) :
        if ( ans [ i ] == '1' ) :
            req += find ( binpow ( 2 , i ) )
    return req
N = 5
print ( totalCountDifference ( N ) )

Index/key variables: i
Accumulator variables: ans, b, n, req
Iterator variables: i
Python program:
def Maximum_Length ( a ) :
    counts = [ 0 ] * 11
    for index , v in enumerate ( a ) :
        counts [ v ] += 1
        k = sorted ( [ i for i in counts if i ] )
        if len ( k ) == 1 or ( k [ 0 ] == k [ - 2 ] and k [ - 1 ] - k [ - 2 ] == 1 ) or ( k [ 0 ] == 1 and k [ 1 ] == k [ - 1 ] ) :
            ans = index
    return ans + 1
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 1 , 1 , 2 , 2 , 2 ]
    n = len ( a )
    print ( Maximum_Length ( a ) )

Index/key variables: v
Iterator variables: index, v
Python program:
def gcd ( a , b ) :
    if a == 0 :
        return b
    return gcd ( b % a , a )
def print_gcd_online ( n , m , query , arr ) :
    max_gcd = 0
    for i in range ( 0 , n ) :
        max_gcd = gcd ( max_gcd , arr [ i ] )
    for i in range ( 0 , m ) :
        query [ i ] [ 0 ] -= 1
        arr [ query [ i ] [ 0 ] ] //= query [ i ] [ 1 ]
        max_gcd = gcd ( arr [ query [ i ] [ 0 ] ] , max_gcd )
        print ( max_gcd )
if __name__ == " _ _ main _ _ " :
    n , m = 3 , 3
    query = [ [ 1 , 3 ] , [ 3 , 12 ] , [ 2 , 4 ] ]
    arr = [ 36 , 24 , 72 ]
    print_gcd_online ( n , m , query , arr )

Index/key variables: i
Iterator variables: i
Python program:
from math import *
N = 100005
prime = [ True ] * N
def SieveOfEratosthenes ( ) :
    prime [ 1 ] = False
    for p in range ( 2 , int ( sqrt ( N ) ) ) :
        if prime [ p ] == True :
            for i in range ( 2 * p , N , p ) :
                prime [ i ] = False
def almostPrimes ( n ) :
    ans = 0
    for i in range ( 6 , n + 1 ) :
        c = 0
        for j in range ( 2 , int ( sqrt ( i ) ) + 1 ) :
            if i % j == 0 :
                if j * j == i :
                    if prime [ j ] :
                        c += 1
                else :
                    if prime [ j ] :
                        c += 1
                    if prime [ i // j ] :
                        c += 1
        if c == 2 :
            ans += 1
    return ans
if __name__ == " _ _ main _ _ " :
    SieveOfEratosthenes ( )
    n = 21
    print ( almostPrimes ( n ) )

Index/key variables: i, j, p
Accumulator variables: ans, c
Iterator variables: i, j, p
Python program:
def sumOfDigitsSingle ( x ) :
    ans = 0
    while x :
        ans += x % 10
        x //= 10
    return ans
def closest ( x ) :
    ans = 0
    while ( ans * 10 + 9 <= x ) :
        ans = ans * 10 + 9
    return ans
def sumOfDigitsTwoParts ( N ) :
    A = closest ( N )
    return sumOfDigitsSingle ( A ) + sumOfDigitsSingle ( N - A )
if __name__ == " _ _ main _ _ " :
    N = 35
    print ( sumOfDigitsTwoParts ( N ) )

Accumulator variables: ans, x
Python program:
def isPrime ( p ) :
    checkNumber = 2 ** p - 1
    nextval = 4 % checkNumber
    for i in range ( 1 , p - 1 ) :
        nextval = ( nextval * nextval - 2 ) % checkNumber
    if ( nextval == 0 ) : return True
    else : return False
p = 7
checkNumber = 2 ** p - 1
if isPrime ( p ) :
    print ( checkNumber , ' is ▁ Prime . ' )
else :
    print ( checkNumber , ' is ▁ not ▁ Prime ' )

Iterator variables: i
Python program:
def sieve ( n , prime ) :
    p = 2
    while ( p * p <= n ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * 2 , n , p ) :
                prime [ i ] = False
        p += 1
def printSophieGermanNumber ( n ) :
    prime = [ True ] * ( 2 * n + 1 )
    sieve ( 2 * n + 1 , prime )
    for i in range ( 2 , n + 1 ) :
        if ( prime [ i ] and prime [ 2 * i + 1 ] ) :
            print ( i , end = " ▁ " )
n = 25
printSophieGermanNumber ( n )

Index/key variables: i, p
Iterator variables: i
Python program:
def fibonacci ( n ) :
    a = 0
    b = 1
    if ( n <= 1 ) :
        return n
    for i in range ( 2 , n + 1 ) :
        c = a + b
        a = b
        b = c
    return c
def isMultipleOf10 ( n ) :
    f = fibonacci ( 30 )
    return ( f % 10 == 0 )
if __name__ == " _ _ main _ _ " :
    n = 30
    if ( isMultipleOf10 ( n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Iterator variables: i
Python program:
def nextPowerOf2 ( n ) :
    p = 1
    if ( n and not ( n & ( n - 1 ) ) ) :
        return n
    while ( p < n ) :
        p <<= 1
    return p
def memoryUsed ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    nearest = nextPowerOf2 ( sum )
    return nearest
arr = [ 1 , 2 , 3 , 2 ]
n = len ( arr )
print ( memoryUsed ( arr , n ) )

Index/key variables: i
Accumulator variables: p, sum
Iterator variables: i
Python program:
def nextPowerOf2 ( n ) :
    count = 0
    if ( n and not ( n & ( n - 1 ) ) ) :
        return n
    while ( n != 0 ) :
        n >>= 1
        count += 1
    return 1 << count
n = 0
print ( nextPowerOf2 ( n ) )

Accumulator variables: count, n
Python program:
def variationStalinsort ( arr ) :
    j = 0
    while True :
        moved = 0
        for i in range ( len ( arr ) - 1 - j ) :
            if arr [ i ] > arr [ i + 1 ] :
                arr . insert ( moved , arr . pop ( i + 1 ) )
                moved += 1
        j += 1
        if moved == 0 :
            break
    return arr
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 1 , 4 , 3 , 6 , 5 , 8 , 7 , 10 , 9 ]
    print ( variationStalinsort ( arr ) )

Index/key variables: i
Accumulator variables: j, moved
Iterator variables: i
Python program:
def printArray ( arr , N ) :
    for i in range ( N ) :
        print ( arr [ i ] , end = ' ▁ ' )
def sortArray ( arr , N ) :
    i = 0
    while i < N :
        if arr [ i ] == i + 1 :
            i += 1
        else :
            temp1 = arr [ i ]
            temp2 = arr [ arr [ i ] - 1 ]
            arr [ i ] = temp2
            arr [ temp1 - 1 ] = temp1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 5 , 3 , 4 ]
    N = len ( arr )
    sortArray ( arr , N )
    printArray ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def maximum ( value , weight , weight1 , flag , K , index , val_len ) :
    if ( index >= val_len ) :
        return 0
    if ( flag == K ) :
        skip = maximum ( value , weight , weight1 , flag , K , index + 1 , val_len )
        full = 0
        if ( weight [ index ] <= weight1 ) :
            full = value [ index ] + maximum ( value , weight , weight1 - weight [ index ] , flag , K , index + 1 , val_len )
        return max ( full , skip )
    else :
        skip = maximum ( value , weight , weight1 , flag , K , index + 1 , val_len )
        full = 0
        half = 0
        if ( weight [ index ] <= weight1 ) :
            full = value [ index ] + maximum ( value , weight , weight1 - weight [ index ] , flag , K , index + 1 , val_len )
        if ( weight [ index ] / 2 <= weight1 ) :
            half = value [ index ] + maximum ( value , weight , weight1 - weight [ index ] / 2 , flag , K , index + 1 , val_len )
        return max ( full , max ( skip , half ) )
value = [ 17 , 20 , 10 , 15 ]
weight = [ 4 , 2 , 7 , 5 ]
K = 1
W = 4
val_len = len ( value )
print ( maximum ( value , weight , W , 0 , K , 0 , val_len ) )

Index/key variables: index
Python program:
N = 1005
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def newNode ( data ) :
    node = Node ( data )
    return node
dp = [ [ [ - 1 for i in range ( 5 ) ] for j in range ( 5 ) ] for k in range ( N ) ] ;
def minDominatingSet ( root , covered , compulsory ) :
    if ( not root ) :
        return 0 ;
    if ( not root . left and not root . right and not covered ) :
        compulsory = True ;
    if ( dp [ root . data ] [ covered ] [ compulsory ] != - 1 ) :
        return dp [ root . data ] [ covered ] [ compulsory ] ;
    if ( compulsory ) :
        dp [ root . data ] [ covered ] [ compulsory ] = 1 + minDominatingSet ( root . left , 1 , 0 ) + minDominatingSet ( root . right , 1 , 0 ) ;
        return dp [ root . data ] [ covered ] [ compulsory ]
    if ( covered ) :
        dp [ root . data ] [ covered ] [ compulsory ] = min ( 1 + minDominatingSet ( root . left , 1 , 0 ) + minDominatingSet ( root . right , 1 , 0 ) , minDominatingSet ( root . left , 0 , 0 ) + minDominatingSet ( root . right , 0 , 0 ) ) ;
        return dp [ root . data ] [ covered ] [ compulsory ]
    ans = 1 + minDominatingSet ( root . left , 1 , 0 ) + minDominatingSet ( root . right , 1 , 0 ) ;
    if ( root . left ) :
        ans = min ( ans , minDominatingSet ( root . left , 0 , 1 ) + minDominatingSet ( root . right , 0 , 0 ) ) ;
    if ( root . right ) :
        ans = min ( ans , minDominatingSet ( root . left , 0 , 0 ) + minDominatingSet ( root . right , 0 , 1 ) ) ;
    dp [ root . data ] [ covered ] [ compulsory ] = ans ;
    return ans
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 ) ;
    root . left = newNode ( 2 ) ;
    root . left . left = newNode ( 3 ) ;
    root . left . right = newNode ( 4 ) ;
    root . left . left . left = newNode ( 5 ) ;
    root . left . left . left . left = newNode ( 6 ) ;
    root . left . left . left . right = newNode ( 7 ) ;
    root . left . left . left . right . right = newNode ( 10 ) ;
    root . left . left . left . left . left = newNode ( 8 ) ;
    root . left . left . left . left . right = newNode ( 9 ) ;
    print ( minDominatingSet ( root , 0 , 0 ) )

Index/key variables: compulsory, covered
Boolean variables: compulsory
Class/struct names: Node
Python program:
import numpy as np
maxSum = 100
arrSize = 51
dp = np . zeros ( ( arrSize , maxSum ) ) ;
visit = np . zeros ( ( arrSize , maxSum ) ) ;
def SubsetCnt ( i , s , arr , n ) :
    if ( i == n ) :
        if ( s == 0 ) :
            return 1 ;
        else :
            return 0 ;
    if ( visit [ i ] [ s + arrSize ] ) :
        return dp [ i ] [ s + arrSize ] ;
    visit [ i ] [ s + arrSize ] = 1 ;
    dp [ i ] [ s + arrSize ] = ( SubsetCnt ( i + 1 , s + arr [ i ] , arr , n ) + SubsetCnt ( i + 1 , s , arr , n ) ) ;
    return dp [ i ] [ s + arrSize ] ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 2 , 2 , - 4 , - 4 ] ;
    n = len ( arr ) ;
    print ( SubsetCnt ( 0 , 0 , arr , n ) ) ;

Index/key variables: i
Python program:
def printTetra ( n ) :
    if ( n < 0 ) :
        return ;
    first = 0 ;
    second = 1 ;
    third = 1 ;
    fourth = 2 ;
    curr = 0 ;
    if ( n == 0 ) :
        print ( first ) ;
    elif ( n == 1 or n == 2 ) :
        print ( second ) ;
    elif ( n == 3 ) :
        print ( fourth ) ;
    else :
        for i in range ( 4 , n + 1 ) :
            curr = first + second + third + fourth ;
            first = second ;
            second = third ;
            third = fourth ;
            fourth = curr ;
    print ( curr ) ;
n = 10 ;
printTetra ( n ) ;

Iterator variables: i
Python program:
def countWays ( n ) :
    res = [ 0 ] * ( n + 2 )
    res [ 0 ] = 1
    res [ 1 ] = 1
    res [ 2 ] = 2
    for i in range ( 3 , n + 1 ) :
        res [ i ] = res [ i - 1 ] + res [ i - 2 ] + res [ i - 3 ]
    return res [ n ]
n = 4
print ( countWays ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def countWays ( n ) :
    a = 1
    b = 2
    c = 4
    if ( n == 0 or n == 1 or n == 2 ) :
        return n
    if ( n == 3 ) :
        return c
    for i in range ( 4 , n + 1 ) :
        d = c + b + a
        a = b
        b = c
        c = d
    return d
n = 4
print ( countWays ( n ) )

Iterator variables: i
Python program:
def isPossible ( elements , target ) :
    dp = [ False ] * ( target + 1 )
    dp [ 0 ] = True
    for ele in elements :
        for j in range ( target , ele - 1 , - 1 ) :
            if dp [ j - ele ] :
                dp [ j ] = True
    return dp [ target ]
arr = [ 6 , 2 , 5 ]
target = 7
if isPossible ( arr , target ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: j, target
Iterator variables: ele, j
Python program:
import math
def FindKthChar ( Str , K , X ) :
    ans = ' ▁ '
    Sum = 0
    for i in range ( len ( Str ) ) :
        digit = ord ( Str [ i ] ) - 48
        Range = int ( math . pow ( digit , X ) )
        Sum += Range
        if ( K <= Sum ) :
            ans = Str [ i ]
            break
    return ans
Str = "123"
K = 9
X = 3
ans = FindKthChar ( Str , K , X )
print ( ans )

Index/key variables: i
Accumulator variables: Sum
Iterator variables: i
Python program:
def countSetBits ( n ) :
    count = 0
    while ( n ) :
        count += n & 1
        n >>= 1
    return count
def totalPairs ( s1 , s2 ) :
    count = 0 ;
    arr1 = [ 0 ] * 7 ; arr2 = [ 0 ] * 7 ;
    for i in range ( len ( s1 ) ) :
        set_bits = countSetBits ( ord ( s1 [ i ] ) )
        arr1 [ set_bits ] += 1 ;
    for i in range ( len ( s2 ) ) :
        set_bits = countSetBits ( ord ( s2 [ i ] ) ) ;
        arr2 [ set_bits ] += 1 ;
    for i in range ( 1 , 7 ) :
        count += ( arr1 [ i ] * arr2 [ i ] ) ;
    return count ;
if __name__ == " _ _ main _ _ " :
    s1 = " geeks " ;
    s2 = " forgeeks " ;
    print ( totalPairs ( s1 , s2 ) ) ;

Index/key variables: i, set_bits
Accumulator variables: count, n
Iterator variables: i
Python program:
def itemType ( n ) :
    count = 0
    day = 1
    while ( count + day * ( day + 1 ) // 2 < n ) :
        count += day * ( day + 1 ) // 2 ;
        day += 1
    type = day
    while ( type > 0 ) :
        count += type
        if ( count >= n ) :
            return type
        type -= 1
if __name__ == ' _ _ main _ _ ' :
    N = 10
    print ( itemType ( N ) )

Accumulator variables: count, day, type
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data ;
        self . next = next ;
def isSortedDesc ( head ) :
    if ( head == None ) :
        return True ;
    while ( head . next != None ) :
        t = head ;
        if ( t . data <= t . next . data ) :
            return False ;
        head = head . next
    return True ;
def newNode ( data ) :
    temp = Node ( 0 ) ;
    temp . next = None ;
    temp . data = data ;
    return temp ;
if __name__ == ' _ _ main _ _ ' :
    head = newNode ( 7 ) ;
    head . next = newNode ( 5 ) ;
    head . next . next = newNode ( 4 ) ;
    head . next . next . next = newNode ( 3 ) ;
    if ( isSortedDesc ( head ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Class/struct names: Node
Python program:
def checkInfinite ( s ) :
    flag = 1
    N = len ( s )
    for i in range ( N - 1 ) :
        if ( s [ i ] == chr ( ord ( s [ i + 1 ] ) + 1 ) ) :
            continue
        elif ( s [ i ] == ' a ' and s [ i + 1 ] == ' z ' ) :
            continue
        else :
            flag = 0
            break
    if ( flag == 0 ) :
        print ( " NO " )
    else :
        print ( " YES " )
if __name__ == ' _ _ main _ _ ' :
    s = " ecbaz "
    checkInfinite ( s )

Index/key variables: i
Iterator variables: i
Python program:
def minChangeInLane ( barrier , n ) :
    dp = [ 1 , 0 , 1 ]
    for j in range ( n ) :
        val = barrier [ j ]
        if ( val > 0 ) :
            dp [ val - 1 ] = 1000000
        for i in range ( 3 ) :
            if ( val != i + 1 ) :
                dp [ i ] = min ( dp [ i ] , min ( dp [ ( i + 1 ) % 3 ] , dp [ ( i + 2 ) % 3 ] ) + 1 )
    return min ( dp [ 0 ] , min ( dp [ 1 ] , dp [ 2 ] ) )
barrier = [ 0 , 1 , 2 , 3 , 0 ]
N = len ( barrier )
print ( minChangeInLane ( barrier , N ) )

Index/key variables: i, j
Iterator variables: i, j