dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def subString ( str , n ) :
    c = 0 ;
    for len in range ( 1 , n + 1 ) :
        for i in range ( 0 , n - len + 1 ) :
            j = i + len - 1 ;
            temp = str [ i ]
            f = 0 ;
            if ( j == i ) :
                c += 1
                continue ;
            k = i + 1 ;
            while ( k <= j and temp < str [ k ] ) :
                temp = str [ k ] ;
                k += 1 ;
                f = 2 ;
            if ( k > j ) :
                c += 1 ;
                f = 2 ;
            while ( k <= j and temp > str [ k ] and f != 2 ) :
                k += 1 ;
                f = 0 ;
            if ( k > j and f != 2 ) :
                c += 1 ;
                f = 0 ;
    print ( c )
str = " bade " ;
subString ( str , len ( str ) )

Index/key variables: i, k
Accumulator variables: c
Iterator variables: i, len
Python program:
def findNumberDivByPowerofTwo ( ar , k , n ) :
    found = - 1
    m = k
    while ( m > 0 ) :
        l = 0
        r = n - 1
        while ( l <= r ) :
            mid = ( l + r ) // 2
            if ( ar [ mid ] == m ) :
                found = m
                break
            elif ( ar [ mid ] > m ) :
                r = mid - 1
            elif ( ar [ mid ] < m ) :
                l = mid + 1
        if ( found != - 1 ) :
            break
        m = m // 2
    return found
arr = [ 3 , 5 , 7 , 8 , 10 ]
k = 4
n = 5
print ( findNumberDivByPowerofTwo ( arr , k , n ) )

Index/key variables: mid
Python program:
def findSubset ( a , n ) :
    sum = 0
    cnt = 0
    v = [ ]
    for i in range ( 1 , n + 1 ) :
        if ( a [ i - 1 ] - i <= 0 ) :
            sum += a [ i - 1 ] - i
            cnt += 1
        else :
            v . append ( a [ i - 1 ] - i )
    v . sort ( )
    ptr = 0
    while ( ptr < len ( v ) and sum + v [ ptr ] <= 0 ) :
        cnt += 1
        ptr += 1
        sum += v [ ptr ]
    return cnt
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 1 , 6 , 7 , 8 , 2 ]
    n = len ( arr )
    print ( findSubset ( arr , n ) )

Index/key variables: ptr
Accumulator variables: cnt, sum, v
Iterator variables: i
Python program:
from typing import Generic , List , TypeVar
T = TypeVar ( ' T ' )
V = TypeVar ( ' V ' )
class Pair ( Generic [ V , T ] ) :
    def __init__ ( self , first : V , second : T ) -> None :
        self . first = first
        self . second = second
def setElement ( arr : List [ int ] , n : int , index : int , x : int ) -> None :
    arr [ index ] = x
def getCount ( arr : List [ int ] , n : int , l : int , r : int ) -> int :
    count = 0
    for i in range ( n ) :
        if ( arr [ i ] >= l and arr [ i ] <= r ) :
            count += 1
    return count
def SolveQuery ( arr : List [ int ] , n : int , Q : List [ Pair [ int , Pair [ int , int ] ] ] ) :
    x = 0
    for i in range ( len ( Q ) ) :
        if ( Q [ i ] . first == 1 ) :
            x = getCount ( arr , n , Q [ i ] . second . first , Q [ i ] . second . second )
            print ( x , end = " ▁ " )
        else :
            setElement ( arr , n , Q [ i ] . second . first , Q [ i ] . second . second )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 2 , 3 , 4 , 4 , 5 , 6 ]
    n = len ( arr )
    Q = [ Pair ( 1 , Pair ( 3 , 5 ) ) , Pair ( 1 , Pair ( 2 , 4 ) ) , Pair ( 1 , Pair ( 1 , 2 ) ) , Pair ( 2 , Pair ( 1 , 7 ) ) , Pair ( 1 , Pair ( 1 , 2 ) ) ]
    SolveQuery ( arr , n , Q )

Index/key variables: i, index, int
Accumulator variables: count
Iterator variables: i
Class/struct names: Pair
Python program:
def generateSequence ( freq , n ) :
    m = { }
    total = 0
    for i in range ( n ) :
        m [ i ] = freq [ i ]
        total += freq [ i ]
    for i in range ( n ) :
        if ( m [ i ] ) :
            sequence = [ ]
            mcopy = { }
            for j in m :
                mcopy [ j ] = m [ j ]
            mcopy [ i ] -= 1
            sequence . append ( i )
            last = i
            for j in range ( total - 1 ) :
                if ( ( last - 1 ) in mcopy and mcopy [ last - 1 ] > 0 ) :
                    mcopy [ last - 1 ] -= 1
                    sequence . append ( last - 1 )
                    last -= 1
                elif ( mcopy [ last + 1 ] ) :
                    mcopy [ last + 1 ] -= 1
                    sequence . append ( last + 1 )
                    last += 1
                else :
                    break
            if ( len ( sequence ) == total ) :
                return sequence
    return [ ]
def PrintSequence ( freq , n ) :
    sequence = generateSequence ( freq , n )
    if ( len ( sequence ) == 0 ) :
        print ( " - 1" )
    else :
        for i in range ( len ( sequence ) ) :
            print ( sequence [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    freq = [ 2 , 2 , 2 , 3 , 1 ]
    N = 5
    PrintSequence ( freq , N )

Index/key variables: i, j
Accumulator variables: last, sequence, total
Iterator variables: i, j
Python program:
import sys
def getMinimumDistance ( a , n ) :
    min_set = { }
    max_set = { }
    max , min = 0 , sys . maxsize + 1
    frequency = { }
    for i in range ( n ) :
        frequency [ a [ i ] ] = frequency . get ( a [ i ] , 0 ) + 1
    for i in range ( n ) :
        count = frequency [ a [ i ] ]
        if ( count == max ) :
            max_set [ a [ i ] ] = 1
        elif ( count > max ) :
            max_set . clear ( )
            max = count
            max_set [ a [ i ] ] = 1
        if ( count == min ) :
            min_set [ a [ i ] ] = 1
        elif ( count < min ) :
            min_set . clear ( )
            min = count
            min_set [ a [ i ] ] = 1
    min_dist = sys . maxsize + 1
    last_min_found = - 1
    for i in range ( n ) :
        if ( a [ i ] in min_set ) :
            last_min_found = i
        if ( ( a [ i ] in max_set ) and last_min_found != - 1 ) :
            if i - last_min_found < min_dist :
                min_dist = i - last_min_found
    last_min_found = - 1
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( a [ i ] in min_set ) :
            last_min_found = i ;
        if ( ( a [ i ] in max_set ) and last_min_found != - 1 ) :
            if min_dist > last_min_found - i :
                min_dist = last_min_found - i
    print ( min_dist )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 3 , 2 , 3 , 3 ]
    N = len ( arr )
    getMinimumDistance ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
import math
def printSubsequenceString ( st , k ) :
    n = len ( st )
    factors = [ ]
    sqt = ( int ( math . sqrt ( k ) ) )
    for i in range ( 2 , sqt + 1 ) :
        while ( k % i == 0 ) :
            factors . append ( i )
            k //= i
    if ( k > 1 ) :
        factors . append ( k )
    count = [ 1 ] * n
    index = 0
    while ( len ( factors ) > 0 ) :
        count [ index ] *= factors [ - 1 ]
        factors . pop ( )
        index += 1
        if ( index == n ) :
            index = 0
    s = " "
    for i in range ( n ) :
        while ( count [ i ] > 0 ) :
            s += st [ i ]
            count [ i ] -= 1
    print ( s )
if __name__ == " _ _ main _ _ " :
    st = " code "
    k = 20
    printSubsequenceString ( st , k )

Index/key variables: i, index
Accumulator variables: factors, k, s
Iterator variables: i
Python program:
def changeArr ( input1 ) :
    newArray = input1 . copy ( )
    newArray . sort ( )
    ranks = { }
    rank = 1
    for index in range ( len ( newArray ) ) :
        element = newArray [ index ] ;
        if element not in ranks :
            ranks [ element ] = rank
            rank += 1
    for index in range ( len ( input1 ) ) :
        element = input1 [ index ]
        input1 [ index ] = ranks [ input1 [ index ] ]
if __name__ == " _ _ main _ _ " :
    arr = [ 100 , 2 , 70 , 2 ]
    changeArr ( arr )
    print ( arr )

Index/key variables: element, index
Accumulator variables: rank
Iterator variables: index
Python program:
def findPair ( arr , n ) :
    if ( n < 2 ) :
        print ( " - 1" )
    hashMap = [ ]
    for k in arr :
        hashMap . append ( k )
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            sum = arr [ i ] + arr [ j ]
            if sum not in hashMap :
                print ( " ( " , arr [ i ] , " , ▁ " , arr [ j ] , " ) " )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 2 , 6 ]
    n = len ( arr )
    findPair ( arr , n )

Index/key variables: i, j
Accumulator variables: hashMap
Iterator variables: i, j, k
Python program:
def findLengthOfMaxSubset ( arr , n , m ) :
    s = [ ] ;
    answer = 0 ;
    for i in range ( n ) :
        tmp = arr [ i ] ;
        if ( tmp != m ) :
            s . append ( tmp ) ;
            answer += 1 ;
    min = 1 ;
    while ( s . count ( min ) ) :
        min += 1 ;
    if ( min != m ) :
        answer = - 1 ;
    return answer ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 ] ;
    N = len ( arr ) ;
    M = 3 ;
    print ( findLengthOfMaxSubset ( arr , N , M ) ) ;

Index/key variables: i
Accumulator variables: answer, min, s
Iterator variables: i
Python program:
m = 5
def countSubsquare ( arr , n , X ) :
    dp = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
    for i in range ( n ) :
        for j in range ( m ) :
            dp [ i + 1 ] [ j + 1 ] = arr [ i ] [ j ]
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            dp [ i ] [ j ] += ( dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] )
    cnt = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            lo = 1
            hi = min ( n - i , m - j ) + 1
            found = False
            while ( lo <= hi ) :
                mid = ( lo + hi ) // 2
                ni = i + mid - 1
                nj = j + mid - 1
                sum = ( dp [ ni ] [ nj ] - dp [ ni ] [ j - 1 ] - dp [ i - 1 ] [ nj ] + dp [ i - 1 ] [ j - 1 ] )
                if ( sum >= X ) :
                    if ( sum == X ) :
                        found = True
                    hi = mid - 1
                else :
                    lo = mid + 1
            if ( found == True ) :
                cnt += 1
    return cnt
if __name__ == " _ _ main _ _ " :
    N , X = 4 , 10
    arr = [ [ 2 , 4 , 3 , 2 , 10 ] , [ 3 , 1 , 1 , 1 , 5 ] , [ 1 , 1 , 2 , 1 , 4 ] , [ 2 , 1 , 1 , 1 , 3 ] ]
    print ( countSubsquare ( arr , N , X ) )

Index/key variables: i, j, ni, nj
Accumulator variables: cnt
Iterator variables: i, j
Boolean variables: found
Python program:
def checkArray ( A , B , N ) :
    start = 0
    end = N - 1
    for i in range ( N ) :
        if ( A [ i ] != B [ i ] ) :
            start = i
            break
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( A [ i ] != B [ i ] ) :
            end = i
            break
    A [ start : end + 1 ] = reversed ( A [ start : end + 1 ] )
    for i in range ( N ) :
        if ( A [ i ] != B [ i ] ) :
            print ( " No " )
            return
    print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 3 , 2 , 4 ]
    B = [ 1 , 2 , 3 , 4 ]
    N = len ( A )
    checkArray ( A , B , N )

Index/key variables: i
Iterator variables: i
Python program:
def countSub ( Str ) :
    n = len ( Str )
    ans = 0
    cnt = 26 * [ 0 ]
    i , j = 0 , 0
    while ( i < n ) :
        if ( j < n and ( cnt [ ord ( Str [ j ] ) - ord ( ' a ' ) ] == 0 ) ) :
            cnt [ ord ( Str [ j ] ) - ord ( ' a ' ) ] += 1
            ans += ( j - i + 1 )
            j += 1
        else :
            cnt [ ord ( Str [ i ] ) - ord ( ' a ' ) ] -= 1
            i += 1
    return ans
Str = " gffg "
print ( countSub ( Str ) )

Index/key variables: i, j
Accumulator variables: ans
Python program:
def solve ( n , k ) :
    ans = 0 ;
    for j in range ( 1 , n + 1 ) :
        if ( j * j > n ) :
            break ;
        if ( n % j == 0 ) :
            if ( j <= k ) :
                ans = max ( ans , j ) ;
            if ( n // j <= k ) :
                ans = max ( ans , n // j ) ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    N = 8 ; K = 7 ;
    print ( ( N // solve ( N , K ) ) ) ;

Iterator variables: j
Python program:
import sys
def max_sum_subarray ( arr , L , R ) :
    n = len ( arr )
    pre = n * [ 0 ]
    pre [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        pre [ i ] = pre [ i - 1 ] + arr [ i ]
    s1 = [ ]
    s1 . append ( 0 )
    ans = - sys . maxsize - 1
    ans = max ( ans , pre [ L - 1 ] )
    flag = 0
    for i in range ( L , n ) :
        if ( i - R >= 0 ) :
            if ( flag == 0 ) :
                s1 . remove ( 0 )
                flag = 1
        if ( i - L >= 0 ) :
            s1 . append ( pre [ i - L ] )
        ans = max ( ans , pre [ i ] - s1 [ 0 ] )
        if ( i - R >= 0 ) :
            s1 . remove ( pre [ i - R ] )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    L = 1
    R = 3
    arr = [ 1 , 2 , 2 , 1 ]
    max_sum_subarray ( arr , L , R )

Index/key variables: i
Accumulator variables: s1
Iterator variables: i
Python program:
def rowWise ( v , n , m , k ) :
    ans = 0
    for i in range ( n ) :
        countcons = 0
        for j in range ( m ) :
            if ( v [ i ] [ j ] == '1' ) :
                countcons = 0
            else :
                countcons += 1
            if ( countcons >= k ) :
                ans += 1
    return ans
def colWise ( v , n , m , k ) :
    ans = 0
    for i in range ( m ) :
        countcons = 0
        for j in range ( n ) :
            if ( v [ j ] [ i ] == '1' ) :
                countcons = 0
            else :
                countcons += 1
            if ( countcons >= k ) :
                ans += 1
    return ans
if __name__ == " _ _ main _ _ " :
    n = 3
    m = 3
    k = 1
    v = [ [ '0' , '0' , '0' ] , [ '0' , '0' , '0' ] , [ '0' , '0' , '0' ] ]
    if ( k == 1 ) :
        print ( rowWise ( v , n , m , k ) )
    else :
        print ( colWise ( v , n , m , k ) + rowWise ( v , n , m , k ) )

Index/key variables: i, j
Accumulator variables: ans, countcons
Iterator variables: i, j
Python program:
import sys
def solve ( a , n ) :
    mx = - sys . maxsize - 1
    for j in range ( 1 , n ) :
        if ( mx > a [ j ] ) :
            return False
        mx = max ( mx , a [ j - 1 ] )
    return True
a = [ 1 , 0 , 2 ]
n = len ( a )
possible = solve ( a , n )
if ( possible != 0 ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: j
Iterator variables: j
Python program:
spf = [ - 1 for i in range ( 100009 ) ] ;
def sieve ( ) :
    i = 2
    while ( i * i <= 100006 ) :
        for j in range ( i , 100006 , i ) :
            if ( spf [ j ] == - 1 ) :
                spf [ j ] = i ;
        i += 1
def findPrimeFactors ( s , n ) :
    while ( n > 1 ) :
        s . add ( spf [ n ] ) ;
        n //= spf [ n ] ;
    return s ;
def MinimumSteps ( n , m ) :
    q = [ ]
    s = set ( )
    q . append ( [ n , 0 ] )
    while ( len ( q ) != 0 ) :
        newNum = q [ 0 ] [ 0 ]
        distance = q [ 0 ] [ 1 ]
        q . pop ( 0 ) ;
        k = findPrimeFactors ( s , newNum ) ;
        for i in k :
            if ( newNum == m ) :
                return distance ;
            elif ( newNum > m ) :
                break ;
            else :
                q . append ( [ newNum + i , distance + 1 ] ) ;
    return - 1 ;
if __name__ == ' _ _ main _ _ ' :
    N = 7
    M = 16 ;
    sieve ( ) ;
    print ( MinimumSteps ( N , M ) )

Index/key variables: j, n
Accumulator variables: q, s
Iterator variables: i, j
Python program:
import math
v = [ [ ] for i in range ( 100000 ) ]
def div ( n ) :
    global v
    for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            v [ n ] . append ( i )
def prodof2elements ( arr , n ) :
    arr2 = arr . copy ( )
    arr2 . sort ( )
    ans = 0
    for i in range ( n ) :
        if ( len ( v [ arr [ i ] ] ) == 0 ) :
            div ( arr [ i ] )
        for j in v [ arr [ i ] ] :
            if j in arr2 :
                if int ( arr [ i ] / j ) in arr2 :
                    ans += 1
                    break
    return ans
arr = [ 2 , 1 , 8 , 4 , 32 , 18 ]
N = len ( arr )
print ( prodof2elements ( arr , N ) )

Index/key variables: i, n
Accumulator variables: ans
Iterator variables: i, j
Python program:
def max_subarray_size ( N , arr ) :
    ans = 0
    for i in range ( N ) :
        map1 = { }
        map2 = { }
        for j in range ( i , N ) :
            if ( arr [ j ] not in map1 ) :
                ele_count = 0
            else :
                ele_count = map1 [ arr [ j ] ]
            if arr [ j ] in map1 :
                map1 [ arr [ j ] ] += 1
            else :
                map1 [ arr [ j ] ] = 1
            if ( ele_count in map2 ) :
                if ( map2 [ ele_count ] == 1 ) :
                    del map2 [ ele_count ]
                else :
                    map2 [ ele_count ] -= 1
            if ele_count + 1 in map2 :
                map2 [ ele_count + 1 ] += 1
            else :
                map2 [ ele_count + 1 ] = 1
            if ( len ( map2 ) == 1 ) :
                ans = max ( ans , j - i + 1 )
    return ans
arr = [ 1 , 2 , 2 , 5 , 6 , 5 , 6 ]
N = len ( arr )
print ( max_subarray_size ( N , arr ) )

Index/key variables: ele_count, j
Iterator variables: i, j
Python program:
def vowel ( vo ) :
    if ( vo == 0 or vo == 4 or vo == 8 or vo == 14 or vo == 20 ) :
        return True
    else :
        return False
def check ( s , k ) :
    cnt = [ 0 ] * 26
    for i in range ( k - 1 ) :
        cnt [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( k - 1 , len ( s ) ) :
        cnt [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
        flag1 = 0
        for j in range ( 26 ) :
            if ( vowel ( j ) == False and cnt [ j ] > 0 ) :
                flag1 = 1
                break
        if ( flag1 == 0 ) :
            return True
        cnt [ ord ( s [ i - k + 1 ] ) - ord ( ' a ' ) ] -= 1
    return False
def longestSubstring ( s ) :
    l = 1
    r = len ( s )
    maxi = 0
    while ( l <= r ) :
        mid = ( l + r ) // 2
        if ( check ( s , mid ) ) :
            l = mid + 1
            maxi = max ( maxi , mid )
        else :
            r = mid - 1
    return maxi
if __name__ == " _ _ main _ _ " :
    s = " sedrewaefhoiu "
    print ( longestSubstring ( s ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countPairs ( X , Y , m , n ) :
    suffix = [ 0 ] * 1005
    total_pairs = 0
    for i in range ( n ) :
        suffix [ Y [ i ] ] += 1
    for i in range ( int ( 1e3 ) , 2 , - 1 ) :
        suffix [ i ] += suffix [ i + 1 ]
    for i in range ( m ) :
        if ( X [ i ] == 0 ) :
            continue
        elif ( X [ i ] == 1 ) :
            total_pairs += suffix [ 0 ]
            continue
        elif ( X [ i ] == 2 ) :
            total_pairs += suffix [ 5 ]
        elif ( X [ i ] == 3 ) :
            total_pairs += ( suffix [ 2 ] + suffix [ 4 ] )
        else :
            total_pairs += suffix [ X [ i ] + 1 ]
        total_pairs += suffix [ 0 ] + suffix [ 1 ]
    return total_pairs
if __name__ == ' _ _ main _ _ ' :
    X = [ 10 , 19 , 18 ]
    Y = [ 11 , 15 , 9 ]
    m = len ( X )
    n = len ( Y )
    print ( countPairs ( X , Y , m , n ) )

Index/key variables: i
Accumulator variables: total_pairs
Iterator variables: i
Python program:
def solve ( A , N , M ) :
    B = [ ]
    c = 1
    s = set ( )
    for i in range ( N ) :
        new = [ ]
        for j in range ( M ) :
            new . append ( c )
            c = c + 1
        B . append ( new )
    for i in range ( N ) :
        for j in range ( M ) :
            if i != 0 :
                if A [ i - 1 ] [ j ] == A [ i ] [ j ] :
                    B [ i - 1 ] [ j ] = B [ i ] [ j ]
            if ( i != N - 1 ) :
                if A [ i + 1 ] [ j ] == A [ i ] [ j ] :
                    B [ i + 1 ] [ j ] = B [ i ] [ j ]
            if ( j != 0 ) :
                if A [ i ] [ j - 1 ] == A [ i ] [ j ] :
                    B [ i ] [ j - 1 ] = B [ i ] [ j ]
            if ( j != M - 1 ) :
                if ( A [ i ] [ j + 1 ] == A [ i ] [ j ] ) :
                    B [ i ] [ j + 1 ] = B [ i ] [ j ]
    for i in range ( N ) :
        for j in range ( M ) :
            s . add ( B [ i ] [ j ] )
    return len ( s )
N = 2
M = 3
A = [ [ 2 , 1 , 3 ] , [ 1 , 1 , 2 ] ]
print ( solve ( A , N , M ) )

Index/key variables: i, j
Accumulator variables: B, new, s
Iterator variables: i, j
Python program:
def splitArray ( start , end , arr , prefix_sum ) :
    if ( start >= end ) :
        return 0
    for k in range ( start , end ) :
        if ( ( prefix_sum [ k ] - prefix_sum [ start - 1 ] ) == ( prefix_sum [ end ] - prefix_sum [ k ] ) ) :
            return ( 1 + splitArray ( start , k , arr , prefix_sum ) + splitArray ( k + 1 , end , arr , prefix_sum ) )
    return 0
def solve ( arr , n ) :
    prefix_sum = [ 0 ] * ( n + 1 )
    prefix_sum [ 0 ] = 0
    for i in range ( 1 , n + 1 ) :
        prefix_sum [ i ] = ( prefix_sum [ i - 1 ] + arr [ i - 1 ] )
    print ( splitArray ( 1 , n , arr , prefix_sum ) )
arr = [ 12 , 3 , 3 , 0 , 3 , 3 ]
N = len ( arr )
solve ( arr , N )

Index/key variables: end, i, k
Iterator variables: i, k
Python program:
def minDays ( arr , n , k ) :
    l = len ( arr )
    left = 1
    right = 1e9
    if ( n * k > l ) :
        return - 1
    while ( left < right ) :
        mid = ( left + right ) // 2
        cnt = 0
        product = 0
        for j in range ( l ) :
            if ( arr [ j ] > mid ) :
                cnt = 0
            else :
                cnt += 1
                if ( cnt >= k ) :
                    product += 1
                    cnt = 0
        if ( product < n ) :
            left = mid + 1
        else :
            right = mid
    return left
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 10 , 3 , 10 , 2 ]
    n = 3
    k = 1
    print ( int ( minDays ( arr , n , k ) ) )

Index/key variables: j
Accumulator variables: cnt, product
Iterator variables: j
Python program:
def countFac ( n ) :
    m = n
    count = 0
    i = 2
    while ( ( i * i ) <= m ) :
        total = 0
        while ( n % i == 0 ) :
            n /= i
            total += 1
        temp = 0
        j = 1
        while ( ( temp + j ) <= total ) :
            temp += j
            count += 1
            j += 1
        i += 1
    if ( n != 1 ) :
        count += 1
    return count
N = 24
print ( countFac ( N ) )

Accumulator variables: count, i, j, n, temp, total
Python program:
def minimumSum ( a , b , c , n ) :
    dp = [ [ 1e6 for i in range ( 2 ) ] for j in range ( n ) ]
    dp [ 0 ] [ 0 ] = a [ 0 ]
    dp [ 0 ] [ 1 ] = b [ 0 ]
    for i in range ( 1 , n ) :
        dp [ i ] [ 0 ] = min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 0 ] + a [ i ] )
        dp [ i ] [ 0 ] = min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 1 ] + a [ i ] + c )
        dp [ i ] [ 1 ] = min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 0 ] + b [ i ] + c )
        dp [ i ] [ 1 ] = min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + b [ i ] )
    print ( min ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] ) )
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 7 , 6 , 18 , 6 , 16 , 18 , 1 , 17 , 17 ]
    arr2 = [ 6 , 9 , 3 , 10 , 9 , 1 , 10 , 1 , 5 ]
    C = 2
    N = len ( arr1 )
    minimumSum ( arr1 , arr2 , C , N )

Index/key variables: i
Iterator variables: i