dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def canVote ( a , n , x ) :
    dp = [ [ 0 ] * ( x + 1 ) for _ in range ( n + 1 ) ]
    a = a [ : ]
    a . append ( 0 )
    sm = 0
    for i in range ( n + 1 ) :
        sm += a [ i ]
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , x + 1 ) :
            if a [ i ] <= j :
                dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , a [ i ] + dp [ i - 1 ] [ j - a [ i ] ] )
            else :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
    return ( sm - dp [ n ] [ x ] ) <= x
if __name__ == " _ _ main _ _ " :
    n = 3
    x = 4
    a = [ 2 , 4 , 2 ]
    print ( " YES " if canVote ( a , n , x ) else " NO " )

Index/key variables: i, j, n, x
Accumulator variables: sm
Iterator variables: i, j
Python program:
def minSum ( ar , n ) :
    if ( n <= 4 ) :
        return min ( ar )
    sum = [ 0 for i in range ( n ) ]
    sum [ 0 ] = ar [ 0 ]
    sum [ 1 ] = ar [ 1 ]
    sum [ 2 ] = ar [ 2 ]
    sum [ 3 ] = ar [ 3 ]
    for i in range ( 4 , n ) :
        sum [ i ] = ar [ i ] + min ( sum [ i - 4 : i ] )
    return min ( sum [ n - 4 : n ] )
ar = [ 2 , 4 , 1 , 5 , 2 , 3 , 6 , 1 , 2 , 4 ]
n = len ( ar )
print ( " Minimum ▁ sum ▁ = ▁ " , minSum ( ar , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxAlternateSum ( arr , n ) :
    if ( n == 1 ) :
        return arr [ 0 ]
    min = arr [ 0 ]
    for i in range ( 1 , n ) :
        if ( min > arr [ i ] ) :
            min = arr [ i ]
    if ( arr [ 0 ] == min ) :
        return arr [ 0 ]
    dec = [ 0 for i in range ( n + 1 ) ]
    inc = [ 0 for i in range ( n + 1 ) ]
    dec [ 0 ] = inc [ 0 ] = arr [ 0 ]
    flag = 0
    for i in range ( 1 , n ) :
        for j in range ( i ) :
            if ( arr [ j ] > arr [ i ] ) :
                dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )
                flag = 1
            elif ( arr [ j ] < arr [ i ] and flag == 1 ) :
                inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )
    result = - 2147483648
    for i in range ( n ) :
        if ( result < inc [ i ] ) :
            result = inc [ i ]
        if ( result < dec [ i ] ) :
            result = dec [ i ]
    return result
arr = [ 8 , 2 , 3 , 5 , 7 , 9 , 10 ]
n = len ( arr )
print ( " Maximum ▁ sum ▁ = ▁ " , maxAlternateSum ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isSafe ( M , row , col , visited ) :
    global ROW , COL
    return ( ( row >= 0 ) and ( row < ROW ) and ( col >= 0 ) and ( col < COL ) and ( M [ row ] [ col ] and not visited [ row ] [ col ] ) )
def DFS ( M , row , col , visited , count ) :
    rowNbr = [ - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 ]
    colNbr = [ - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 ]
    visited [ row ] [ col ] = True
    for k in range ( 8 ) :
        if ( isSafe ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited ) ) :
            count [ 0 ] += 1
            DFS ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited , count )
def largestRegion ( M ) :
    global ROW , COL
    visited = [ [ 0 ] * COL for i in range ( ROW ) ]
    result = - 999999999999
    for i in range ( ROW ) :
        for j in range ( COL ) :
            if ( M [ i ] [ j ] and not visited [ i ] [ j ] ) :
                count = [ 1 ]
                DFS ( M , i , j , visited , count )
                result = max ( result , count [ 0 ] )
    return result
ROW = 4
COL = 5
M = [ [ 0 , 0 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 1 ] ]
print ( largestRegion ( M ) )

Index/key variables: col, i, j, k, row
Iterator variables: i, j, k
Python program:
def lucas ( n ) :
    a = 2
    b = 1
    if ( n == 0 ) :
        return a
    for i in range ( 2 , n + 1 ) :
        c = a + b
        a = b
        b = c
    return b
n = 9
print ( lucas ( n ) )

Iterator variables: i
Python program:
MAX = 1000000
def breakSum ( n ) :
    dp = [ 0 ] * ( n + 1 )
    dp [ 0 ] = 0
    dp [ 1 ] = 1
    for i in range ( 2 , n + 1 ) :
        dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i ) ;
    return dp [ n ]
n = 24
print ( breakSum ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def longestRepeatedSubstring ( str ) :
    n = len ( str )
    LCSRe = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]
    index = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( i + 1 , n + 1 ) :
            if ( str [ i - 1 ] == str [ j - 1 ] and LCSRe [ i - 1 ] [ j - 1 ] < ( j - i ) ) :
                LCSRe [ i ] [ j ] = LCSRe [ i - 1 ] [ j - 1 ] + 1
                if ( LCSRe [ i ] [ j ] > res_length ) :
                    res_length = LCSRe [ i ] [ j ]
                    index = max ( i , index )
            else :
                LCSRe [ i ] [ j ] = 0
    if ( res_length > 0 ) :
        for i in range ( index - res_length + 1 , index + 1 ) :
            res = res + str [ i - 1 ]
    return res
if __name__ == " _ _ main _ _ " :
    str = " geeksforgeeks "
    print ( longestRepeatedSubstring ( str ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import sys
def minCost ( cost , n ) :
    dp = [ 0 for i in range ( n + 1 ) ]
    for i in range ( 1 , n + 1 ) :
        min_cost = sys . maxsize
        for j in range ( i ) :
            if j < len ( cost ) and cost [ j ] != - 1 :
                min_cost = min ( min_cost , cost [ j ] + dp [ i - j - 1 ] )
        dp [ i ] = min_cost
    return dp [ n ]
cost = [ 10 , - 1 , - 1 , - 1 , - 1 ]
W = len ( cost )
print ( minCost ( cost , W ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def printLIS ( arr : list ) :
    for x in arr :
        print ( x , end = " ▁ " )
    print ( )
def constructPrintLIS ( arr : list , n : int ) :
    l = [ [ ] for i in range ( n ) ]
    l [ 0 ] . append ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        for j in range ( i ) :
            if arr [ i ] > arr [ j ] and ( len ( l [ i ] ) < len ( l [ j ] ) + 1 ) :
                l [ i ] = l [ j ] . copy ( )
        l [ i ] . append ( arr [ i ] )
    maxx = l [ 0 ]
    for x in l :
        if len ( x ) > len ( maxx ) :
            maxx = x
    printLIS ( maxx )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 2 , 6 , 4 , 5 , 1 ]
    n = len ( arr )
    constructPrintLIS ( arr , n )

Index/key variables: i, j
Iterator variables: i, j, x
Python program:
def count ( n ) :
    dp = [ 0 for _ in range ( n + 1 ) ]
    for i in range ( 1 , n + 1 ) :
        if i <= 3 :
            dp [ i ] = 1
        elif i == 4 :
            dp [ i ] = 2
        else :
            dp [ i ] = dp [ i - 1 ] + dp [ i - 4 ]
    return dp [ n ]
n = 5
print ( " Count ▁ of ▁ ways ▁ is " ) ,
print ( count ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def nCrModp ( n , r , p ) :
    if ( r > n - r ) :
        r = n - r
    C = [ 0 for i in range ( r + 1 ) ]
    C [ 0 ] = 1
    for i in range ( 1 , n + 1 ) :
        for j in range ( min ( i , r ) , 0 , - 1 ) :
            C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p
    return C [ r ]
n = 10
r = 2
p = 13
print ( ' Value ▁ of ▁ nCr ▁ % ▁ p ▁ is ' , nCrModp ( n , r , p ) )

Index/key variables: j, r
Iterator variables: i, j
Python program:
def printCountDP ( dist ) :
    count = [ 0 ] * ( dist + 1 )
    count [ 0 ] = 1
    if dist >= 1 :
        count [ 1 ] = 1
    if dist >= 2 :
        count [ 2 ] = 2
    for i in range ( 3 , dist + 1 ) :
        count [ i ] = ( count [ i - 1 ] + count [ i - 2 ] + count [ i - 3 ] )
    return count [ dist ] ;
dist = 4 ;
print ( printCountDP ( dist ) )

Index/key variables: dist, i
Iterator variables: i
Python program:
def countSeq ( n ) :
    nCr = 1
    res = 1
    for r in range ( 1 , n + 1 ) :
        nCr = ( nCr * ( n + 1 - r ) ) / r ;
        res += nCr * nCr ;
    return res ;
n = 2
print ( " Count ▁ of ▁ sequences ▁ is " ) ,
print ( int ( countSeq ( n ) ) )

Accumulator variables: res
Iterator variables: r
Python program:
def numberOfPaths ( m , n ) :
    for i in range ( n , ( m + n - 1 ) ) :
        path *= i ;
        path //= ( i - n + 1 ) ;
    return path ;
print ( numberOfPaths ( 3 , 3 ) ) ;

Accumulator variables: path
Iterator variables: i
Python program:
def lenghtOfLongestAP ( set , n ) :
    if ( n <= 2 ) :
        return n
    L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]
    llap = 2
    for i in range ( n ) :
        L [ i ] [ n - 1 ] = 2
    for j in range ( n - 2 , 0 , - 1 ) :
        i = j - 1
        k = j + 1
        while ( i >= 0 and k <= n - 1 ) :
            if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :
                k += 1
            elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :
                L [ i ] [ j ] = 2
                i -= 1
            else :
                L [ i ] [ j ] = L [ j ] [ k ] + 1
                llap = max ( llap , L [ i ] [ j ] )
                i -= 1
                k += 1
                while ( i >= 0 ) :
                    L [ i ] [ j ] = 2
                    i -= 1
    return llap
if __name__ == " _ _ main _ _ " :
    set1 = [ 1 , 7 , 10 , 13 , 14 , 19 ]
    n1 = len ( set1 )
    print ( lenghtOfLongestAP ( set1 , n1 ) )
    set2 = [ 1 , 7 , 10 , 15 , 27 , 29 ]
    n2 = len ( set2 )
    print ( lenghtOfLongestAP ( set2 , n2 ) )
    set3 = [ 2 , 4 , 6 , 8 , 10 ]
    n3 = len ( set3 )
    print ( lenghtOfLongestAP ( set3 , n3 ) )

Index/key variables: i, j, k
Iterator variables: i, j
Python program:
INF = 2147483647
def printSolution ( p , n ) :
    k = 0
    if p [ n ] == 1 :
        k = 1
    else :
        k = printSolution ( p , p [ n ] - 1 ) + 1
    print ( ' Line ▁ number ▁ ' , k , ' : ▁ From ▁ word ▁ no . ▁ ' , p [ n ] , ' to ▁ ' , n )
    return k
def solveWordWrap ( l , n , M ) :
    extras = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]
    lc = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]
    c = [ 0 for i in range ( n + 1 ) ]
    p = [ 0 for i in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        extras [ i ] [ i ] = M - l [ i - 1 ]
        for j in range ( i + 1 , n + 1 ) :
            extras [ i ] [ j ] = ( extras [ i ] [ j - 1 ] - l [ j - 1 ] - 1 )
    for i in range ( n + 1 ) :
        for j in range ( i , n + 1 ) :
            if extras [ i ] [ j ] < 0 :
                lc [ i ] [ j ] = INF ;
            elif j == n and extras [ i ] [ j ] >= 0 :
                lc [ i ] [ j ] = 0
            else :
                lc [ i ] [ j ] = ( extras [ i ] [ j ] * extras [ i ] [ j ] )
    c [ 0 ] = 0
    for j in range ( 1 , n + 1 ) :
        c [ j ] = INF
        for i in range ( 1 , j + 1 ) :
            if ( c [ i - 1 ] != INF and lc [ i ] [ j ] != INF and ( ( c [ i - 1 ] + lc [ i ] [ j ] ) < c [ j ] ) ) :
                c [ j ] = c [ i - 1 ] + lc [ i ] [ j ]
                p [ j ] = i
    printSolution ( p , n )
l = [ 3 , 2 , 2 , 5 ]
n = len ( l )
M = 6
solveWordWrap ( l , n , M )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def isPalindrome ( x ) :
    return x == x [ : : - 1 ]
def minPalPartion ( string , i , j ) :
    if i >= j or isPalindrome ( string [ i : j + 1 ] ) :
        return 0
    ans = float ( ' inf ' )
    for k in range ( i , j ) :
        count = ( 1 + minPalPartion ( string , i , k ) + minPalPartion ( string , k + 1 , j ) )
        ans = min ( ans , count )
    return ans
def main ( ) :
    string = " ababbbabbababa "
    print ( " Min ▁ cuts ▁ needed ▁ for ▁ Palindrome ▁ Partitioning ▁ is ▁ " , minPalPartion ( string , 0 , len ( string ) - 1 ) , )
if __name__ == " _ _ main _ _ " :
    main ( )

Iterator variables: k
Python program:
def minCut ( a ) :
    cut = [ 0 for i in range ( len ( a ) ) ]
    palindrome = [ [ False for i in range ( len ( a ) ) ] for j in range ( len ( a ) ) ]
    for i in range ( len ( a ) ) :
        minCut = i ;
        for j in range ( i + 1 ) :
            if ( a [ i ] == a [ j ] and ( i - j < 2 or palindrome [ j + 1 ] [ i - 1 ] ) ) :
                palindrome [ j ] [ i ] = True ;
                minCut = min ( minCut , 0 if j == 0 else ( cut [ j - 1 ] + 1 ) ) ;
        cut [ i ] = minCut ;
    return cut [ len ( a ) - 1 ] ;
if __name__ == ' _ _ main _ _ ' :
    print ( minCut ( " aab " ) )
    print ( minCut ( " aabababaxx " ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def ispallindrome ( input , start , end ) :
    while ( start < end ) :
        if ( input [ start ] != input [ end ] ) :
            return False ;
        start += 1
        end -= 1
    return True ;
def convert ( a , b ) :
    return str ( a ) + str ( b ) ;
def minpalparti_memo ( input , i , j , memo ) :
    if ( i > j ) :
        return 0 ;
    ij = convert ( i , j ) ;
    if ( ij in memo ) :
        return memo [ ij ] ;
    if ( i == j ) :
        memo [ ij ] = 0 ;
        return 0 ;
    if ( ispallindrome ( input , i , j ) ) :
        memo [ ij ] = 0 ;
        return 0 ;
    minimum = 1000000000
    for k in range ( i , j ) :
        left_min = 1000000000
        right_min = 1000000000
        left = convert ( i , k ) ;
        right = convert ( k + 1 , j ) ;
        if ( left in memo ) :
            left_min = memo [ left ] ;
        if ( right in memo ) :
            right_min = memo [ right ] ;
        if ( left_min == 1000000000 ) :
            left_min = minpalparti_memo ( input , i , k , memo ) ;
        if ( right_min == 1000000000 ) :
            right_min = minpalparti_memo ( input , k + 1 , j , memo ) ;
        minimum = min ( minimum , left_min + 1 + right_min ) ;
    memo [ ij ] = minimum ;
    return memo [ ij ] ;
if __name__ == ' _ _ main _ _ ' :
    input = " ababbbabbababa " ;
    memo = dict ( )
    print ( minpalparti_memo ( input , 0 , len ( input ) - 1 , memo ) )

Index/key variables: end, ij, left, right, start
Iterator variables: k
Python program:
INT_MAX = 32767
def eggDrop ( n , k ) :
    eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]
    for i in range ( 1 , n + 1 ) :
        eggFloor [ i ] [ 1 ] = 1
        eggFloor [ i ] [ 0 ] = 0
    for j in range ( 1 , k + 1 ) :
        eggFloor [ 1 ] [ j ] = j
    for i in range ( 2 , n + 1 ) :
        for j in range ( 2 , k + 1 ) :
            eggFloor [ i ] [ j ] = INT_MAX
            for x in range ( 1 , j + 1 ) :
                res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )
                if res < eggFloor [ i ] [ j ] :
                    eggFloor [ i ] [ j ] = res
    return eggFloor [ n ] [ k ]
n = 2
k = 36
print ( " Minimum ▁ number ▁ of ▁ trials ▁ in ▁ worst ▁ case ▁ with " + str ( n ) + " eggs ▁ and ▁ " + str ( k ) + " ▁ floors ▁ is ▁ " + str ( eggDrop ( n , k ) ) )

Index/key variables: i, j, k, n
Iterator variables: i, j, x
Python program:
def minCost ( cost , row , col ) :
    for i in range ( 1 , row ) :
        cost [ i ] [ 0 ] += cost [ i - 1 ] [ 0 ]
    for j in range ( 1 , col ) :
        cost [ 0 ] [ j ] += cost [ 0 ] [ j - 1 ]
    for i in range ( 1 , row ) :
        for j in range ( 1 , col ) :
            cost [ i ] [ j ] += ( min ( cost [ i - 1 ] [ j - 1 ] , min ( cost [ i - 1 ] [ j ] , cost [ i ] [ j - 1 ] ) ) )
    return cost [ row - 1 ] [ col - 1 ]
if __name__ == ' _ _ main _ _ ' :
    row = 3
    col = 3
    cost = [ [ 1 , 2 , 3 ] , [ 4 , 8 , 2 ] , [ 1 , 5 , 3 ] ]
    print ( minCost ( cost , row , col ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def factorial ( n ) :
    res = 1
    for i in range ( 1 , n + 1 ) :
        res *= i
    return res
def binomialCoeff ( n , k ) :
    res = 1
    if ( k > n - k ) :
        k = n - k
    for i in range ( k ) :
        res *= ( n - i )
        res //= ( i + 1 )
    return res
def catalan ( n ) :
    c = binomialCoeff ( 2 * n , n )
    return c // ( n + 1 )
def countBST ( n ) :
    count = catalan ( n )
    return count
def countBT ( n ) :
    count = catalan ( n )
    return count * factorial ( n )
if __name__ == ' _ _ main _ _ ' :
    n = 5
    count1 = countBST ( n )
    count2 = countBT ( n )
    print ( " Count ▁ of ▁ BST ▁ with " , n , " nodes ▁ is " , count1 )
    print ( " Count ▁ of ▁ binary ▁ trees ▁ with " , n , " nodes ▁ is " , count2 )

Accumulator variables: res
Iterator variables: i
Python program:
def getMissingNumbers ( arr ) :
    for num in arr :
        arr [ abs ( num ) - 1 ] = - ( abs ( arr [ abs ( num ) - 1 ] ) )
    for pos , num in enumerate ( arr ) :
        if num > 0 :
            print ( pos + 1 , end = ' ▁ ' )
arr = [ 5 , 5 , 4 , 4 , 2 ]
getMissingNumbers ( arr )

Iterator variables: num, pos
Python program:
def maxSubsequenceLen ( S , K ) :
    N = len ( S )
    start , end = 0 , 0
    S = sorted ( S )
    ans , sum = - 10 ** 9 , 0
    for end in range ( N ) :
        sum = sum + ( ord ( S [ end ] ) - ord ( ' a ' ) )
        while ( sum + K < ( ord ( S [ end ] ) - ord ( ' a ' ) ) * ( end - start + 1 ) ) :
            sum = sum - ( ord ( S [ start ] ) - ord ( ' a ' ) )
            start += 1
        ans = max ( ans , end - start + 1 )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    S = " acscbcca "
    K = 1
    maxSubsequenceLen ( S , K )

Index/key variables: end, start
Iterator variables: end
Python program:
def checkPro ( n , k ) :
    KthRoot = int ( n ** ( 1 / k ) )
    product = 1
    for i in range ( 1 , k + 1 ) :
        product = product * i
    print ( product )
    if ( product == N ) :
        return ( " Yes " )
    for i in range ( 2 , KthRoot + 1 ) :
        product = product * ( i + k - 1 )
        product = product / ( i - 1 )
        print ( product )
        if ( product == N ) :
            return ( " Yes " )
    return ( " No " )
N = 210
K = 3
print ( checkPro ( N , K ) )

Iterator variables: i
Python program:
def findCount0th ( arr , N , K ) :
    oddsum = 0
    evensum = 0
    for i in range ( 1 , N , 2 ) :
        oddsum += arr [ i ]
    for i in range ( 2 , N , 2 ) :
        evensum += arr [ i ]
    if ( abs ( oddsum - evensum ) == K ) :
        return 1
    else :
        return 0
def findCount1st ( arr , N , K ) :
    evensum = arr [ 0 ]
    oddsum = 0
    for i in range ( 3 , N , 2 ) :
        evensum += arr [ i ]
    for i in range ( 2 , N , 2 ) :
        oddsum += arr [ i ]
    if ( abs ( oddsum - evensum ) == K ) :
        return 1
    else :
        return 0
def countTimes ( arr , K ) :
    N = len ( arr )
    if ( N == 1 ) :
        return 1
    if ( N < 3 ) :
        return 0
    if ( N == 3 ) :
        cnt = 0
        if abs ( arr [ 0 ] - arr [ 1 ] ) == K :
            cnt += 1
        if abs ( arr [ 2 ] - arr [ 1 ] ) == K :
            cnt += 1
        if abs ( arr [ 0 ] - arr [ 2 ] ) == K :
            cnt += 1
        return cnt
    prefix = [ 0 ] * ( N + 2 )
    suffix = [ 0 ] * ( N + 2 )
    prefix [ 0 ] = arr [ 0 ]
    prefix [ 1 ] = arr [ 1 ]
    suffix [ N - 1 ] = arr [ N - 1 ]
    suffix [ N - 2 ] = arr [ N - 2 ]
    for i in range ( 2 , N , 2 ) :
        prefix [ i ] = arr [ i ] + prefix [ i - 2 ]
    for i in range ( 3 , N , 2 ) :
        prefix [ i ] = arr [ i ] + prefix [ i - 2 ]
    for i in range ( N - 3 , - 1 , - 2 ) :
        suffix [ i ] = arr [ i ] + suffix [ i + 2 ]
    for i in range ( N - 4 , - 1 , - 2 ) :
        suffix [ i ] = arr [ i ] + suffix [ i + 2 ]
    count = 0
    for i in range ( 2 , N ) :
        if ( abs ( prefix [ i - 1 ] + suffix [ i + 2 ] - prefix [ i - 2 ] - suffix [ i + 1 ] ) == K ) :
            count += 1
    count += findCount0th ( arr , N , K )
    count += findCount1st ( arr , N , K )
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 5 , 6 ]
    K = 2
    print ( countTimes ( arr , K ) )

Index/key variables: i
Accumulator variables: count, evensum, oddsum
Iterator variables: i
Python program:
def checkReverseBitonic ( s ) :
    i = 0
    j = 0
    for i in range ( len ( s ) ) :
        if ( s [ i ] < s [ i - 1 ] ) :
            continue ;
        if ( s [ i ] >= s [ i - 1 ] ) :
            break ;
    if ( i == len ( s ) - 1 ) :
        return 1 ;
    for j in range ( i + 1 , len ( s ) ) :
        if ( s [ j ] > s [ j - 1 ] ) :
            continue ;
        if ( s [ j ] <= s [ j - 1 ] ) :
            break ;
    i = j ;
    if ( i != len ( s ) ) :
        return 0 ;
    return 1 ;
s = " abcdwef "
if ( checkReverseBitonic ( s ) == 1 ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countKCountdown ( arr , N , K ) :
    flag = - 1 ;
    count = 0 ;
    for i in range ( 0 , N ) :
        if ( arr [ i ] == K ) :
            flag = K ;
        if ( arr [ i ] == flag ) :
            flag -= 1 ;
        else :
            flag = - 1 ;
        if ( flag == 0 ) :
            count += 1 ;
    return count ;
N = 8 ;
K = 3 ;
arr = [ 4 , 3 , 2 , 1 , 5 , 3 , 2 , 1 ] ;
print ( countKCountdown ( arr , N , K ) )

Index/key variables: i
Accumulator variables: count, flag
Iterator variables: i
Python program:
def decToHexa ( n ) :
    hexaDeciNum = [ '0' ] * 100
    i = 0
    while ( n != 0 ) :
        temp = 0
        temp = n % 16
        if ( temp < 10 ) :
            hexaDeciNum [ i ] = chr ( temp + 48 )
            i = i + 1
        else :
            hexaDeciNum [ i ] = chr ( temp + 55 )
            i = i + 1
        n = int ( n / 16 )
    hexCode = " "
    if ( i == 2 ) :
        hexCode = hexCode + hexaDeciNum [ 0 ]
        hexCode = hexCode + hexaDeciNum [ 1 ]
    elif ( i == 1 ) :
        hexCode = "0"
        hexCode = hexCode + hexaDeciNum [ 0 ]
    elif ( i == 0 ) :
        hexCode = "00"
    return hexCode
def convertRGBtoHex ( R , G , B ) :
    if ( ( R >= 0 and R <= 255 ) and ( G >= 0 and G <= 255 ) and ( B >= 0 and B <= 255 ) ) :
        hexCode = hexCode + decToHexa ( R )
        hexCode = hexCode + decToHexa ( G )
        hexCode = hexCode + decToHexa ( B )
        return hexCode
    else :
        return " - 1"
R = 0
G = 0
B = 0
print ( convertRGBtoHex ( R , G , B ) )
R = 255
G = 255
B = 255
print ( convertRGBtoHex ( R , G , B ) )
R = 25
G = 56
B = 123
print ( convertRGBtoHex ( R , G , B ) )
R = 2
G = 3
B = 4
print ( convertRGBtoHex ( R , G , B ) )
R = 255
G = 255
B = 256
print ( convertRGBtoHex ( R , G , B ) )

Index/key variables: i
Python program:
def getStrings ( strr , arr ) :
    for i in range ( len ( arr ) ) :
        if ( check ( arr [ i ] , strr ) ) :
            print ( arr [ i ] , end = " ▁ " )
def check ( s , strr ) :
    chars = s
    for c in chars :
        if c not in strr :
            return False
    for i in range ( len ( chars ) - 1 ) :
        if ( chars [ i ] == chars [ i + 1 ] ) :
            return False
    return True
strr = " ABCD "
arr = [ " AABCDA " , " ABCDZADC " , " ABCDBCA " , " ABCDABDCA " ]
getStrings ( strr , arr )

Index/key variables: i
Iterator variables: c, i
Python program:
def q1 ( s , i ) :
    if ( i == len ( s ) ) :
        print ( " Yes " ) ;
        return ;
    if ( s [ i ] == ' a ' ) :
        q1 ( s , i + 1 ) ;
    else :
        q2 ( s , i + 1 ) ;
def q2 ( s , i ) :
    if ( i == len ( s ) ) :
        print ( " No " ) ;
        return ;
    if ( s [ i ] == ' a ' ) :
        q1 ( s , i + 1 ) ;
    else :
        q2 ( s , i + 1 ) ;
def q3 ( s , i ) :
    if ( i == len ( s ) ) :
        print ( " Yes " ) ;
        return ;
    if ( s [ i ] == ' a ' ) :
        q4 ( s , i + 1 ) ;
    else :
        q3 ( s , i + 1 ) ;
def q4 ( s , i ) :
    if ( i == s . length ( ) ) :
        print ( " No " ) ;
        return ;
    if ( s [ i ] == ' a ' ) :
        q4 ( s , i + 1 ) ;
    else :
        q3 ( s , i + 1 ) ;
def q0 ( s , i ) :
    if ( i == len ( s ) ) :
        print ( " No " ) ;
        return ;
    if ( s [ i ] == ' a ' ) :
        q1 ( s , i + 1 ) ;
    else :
        q3 ( s , i + 1 ) ;
if __name__ == ' _ _ main _ _ ' :
    s = " abbaabb " ;
    q0 ( s , 0 ) ;

Index/key variables: i