dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def minimumMoves ( arr , N ) :
    sum = 0
    maxelement = - 1
    if ( N == 2 ) :
        print ( 0 , end = " " )
    for i in range ( N ) :
        sum += arr [ i ]
        maxelement = max ( maxelement , arr [ i ] )
    K = ( sum + N - 2 ) // ( N - 1 )
    K = max ( maxelement , K )
    ans = K * ( N - 1 ) - sum
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 7 ]
    N = 3
    minimumMoves ( arr , N )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def array_divisbleby_k ( N , K ) :
    flag = False
    d1 , d2 = 0 , 0
    for i in range ( 2 , int ( K ** ( 1 / 2 ) ) + 1 ) :
        if ( K % i == 0 ) :
            flag = True
            d1 = i
            d2 = K // i
            break
    if ( flag ) :
        for i in range ( N ) :
            if ( i % 2 == 1 ) :
                print ( d2 , end = " ▁ " )
            else :
                print ( d1 , end = " ▁ " )
    else :
        print ( - 1 )
if __name__ == " _ _ main _ _ " :
    N = 5
    K = 21
    array_divisbleby_k ( N , K )

Iterator variables: i
Boolean variables: flag
Python program:
import sys
sys . setrecursionlimit ( 1500 )
def addEdge ( u , v ) :
    global adj
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
def DFS ( u , fre , S ) :
    global visited , adj , cnt
    visited [ u ] = 1
    cnt += 1
    fre [ ord ( S [ u ] ) - ord ( ' a ' ) ] += 1
    for i in adj [ u ] :
        if ( visited [ i ] == 0 ) :
            DFS ( i , fre , S )
def minimumOperations ( S , m ) :
    global adj , visited , cnt
    total , N = 0 , len ( S )
    for i in range ( N ) :
        addEdge ( i , N - i - 1 )
        addEdge ( N - i - 1 , i )
    for i in range ( N - m ) :
        addEdge ( i , i + m )
        addEdge ( i + m , i )
    for i in range ( N ) :
        if ( not visited [ i ] ) :
            fre = [ 0 ] * 26
            cnt , maxx = 0 , - 1
            DFS ( i , fre , S )
            for j in range ( 26 ) :
                maxx = max ( maxx , fre [ j ] )
            total += cnt - maxx
    print ( total )
if __name__ == ' _ _ main _ _ ' :
    adj = [ [ ] for i in range ( 101 ) ]
    visited , cnt = [ 0 for i in range ( 101 ) ] , 0
    S = " abaaba "
    K = 2
    minimumOperations ( S , K )

Index/key variables: i, j, u, v
Accumulator variables: total
Iterator variables: i, j
Python program:
def Print ( arr , n , m ) :
    for i in range ( n ) :
        for j in range ( m ) :
            a = arr [ i ] [ j ]
            if ( ( i + j ) % 2 == 0 and a == ' F ' ) :
                arr [ i ] [ j ] = '1'
            elif ( a == ' F ' ) :
                arr [ i ] [ j ] = '2'
    for i in range ( n ) :
        for j in range ( m ) :
            print ( arr [ i ] [ j ] , end = " " )
        print ( )
n , m = 4 , 4
arr = [ [ ' F ' , ' F ' , ' F ' , ' F ' ] , [ ' F ' , ' O ' , ' F ' , ' F ' ] , [ ' F ' , ' F ' , ' O ' , ' F ' ] , [ ' F ' , ' F ' , ' F ' , ' F ' ] ]
Print ( arr , n , m )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def removeDuplicateLetters ( s ) :
    cnt = [ 0 ] * 26
    vis = [ 0 ] * 26
    n = len ( s )
    for i in s :
        cnt [ ord ( i ) - ord ( ' a ' ) ] += 1
    res = [ ]
    for i in range ( n ) :
        cnt [ ord ( s [ i ] ) - ord ( ' a ' ) ] -= 1
        if ( not vis [ ord ( s [ i ] ) - ord ( ' a ' ) ] ) :
            while ( len ( res ) > 0 and res [ - 1 ] > s [ i ] and cnt [ ord ( res [ - 1 ] ) - ord ( ' a ' ) ] > 0 ) :
                vis [ ord ( res [ - 1 ] ) - ord ( ' a ' ) ] = 0
                del res [ - 1 ]
            res += s [ i ]
            vis [ ord ( s [ i ] ) - ord ( ' a ' ) ] = 1
    return " " . join ( res )
if __name__ == ' _ _ main _ _ ' :
    S = " acbc "
    print ( removeDuplicateLetters ( S ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def countPairs ( arr , N ) :
    countPowerof2 = 0
    for i in range ( N ) :
        if ( bin ( arr [ i ] ) . count ( '1' ) == 1 ) :
            countPowerof2 += 1
    desiredPairs = ( countPowerof2 * ( countPowerof2 - 1 ) ) // 2
    print ( desiredPairs )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 7 , 2 ]
    N = len ( arr )
    countPairs ( arr , N )

Index/key variables: i
Accumulator variables: countPowerof2
Iterator variables: i
Python program:
import math
MAXN = 1000000
is_prime = [ 0 ] * MAXN
count_of_primes = [ 0 ] * MAXN
def sieve ( ) :
    for i in range ( 3 , MAXN , 2 ) :
        is_prime [ i ] = 1
    for i in range ( 3 , int ( math . sqrt ( MAXN ) ) , 2 ) :
        if is_prime [ i ] :
            for j in range ( i * i , MAXN , i ) :
                is_prime [ j ] = 0
    is_prime [ 2 ] = 1
    for i in range ( 1 , MAXN ) :
        count_of_primes [ i ] = ( count_of_primes [ i - 1 ] + is_prime [ i ] )
def power ( x , y , p ) :
    result = 1
    while ( y > 0 ) :
        if y & 1 == 1 :
            result = ( result * x ) % p
        x = ( x * x ) % p
        y >>= 1
    return result
def numberOfWays ( N ) :
    count = count_of_primes [ N ] - 1
    mod = 1000000007
    answer = power ( 2 , count , mod )
    if N == 1 :
        answer = 0
    print ( answer )
if __name__ == " _ _ main _ _ " :
    sieve ( )
    N = 7
    numberOfWays ( N )

Index/key variables: N, i, j
Accumulator variables: y
Iterator variables: i, j
Python program:
def maxSumOfSquares ( N , S ) :
    res = 0
    if ( S < N or S > 9 * N ) :
        cout << - 1 ;
        return
    S = S - N
    c = 0
    while ( S > 0 ) :
        c += 1
        if ( S // 8 > 0 ) :
            res += 9 * 9
            S -= 8
        else :
            res += ( S + 1 ) * ( S + 1 )
            break
    res = res + ( N - c )
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    S = 12
    maxSumOfSquares ( N , S )

Accumulator variables: S, c, res
Python program:
def calculate_steps ( arr , n , minimum ) :
    count = 0
    for i in range ( n ) :
        val = arr [ i ]
        if ( arr [ i ] > minimum ) :
            arr [ i ] = arr [ i ] - minimum
            count += arr [ i ] // 5
            arr [ i ] = arr [ i ] % 5
            count += arr [ i ] // 2
            arr [ i ] = arr [ i ] % 2
            if ( arr [ i ] ) :
                count += 1
        arr [ i ] = val
    return count
def solve ( arr , n ) :
    arr = sorted ( arr )
    arr = arr [ : : - 1 ]
    minimum = arr [ n - 1 ]
    count1 = 0
    count2 = 0
    count3 = 0
    count1 = calculate_steps ( arr , n , minimum )
    count2 = calculate_steps ( arr , n , minimum - 1 )
    count3 = calculate_steps ( arr , n , minimum - 2 )
    return min ( count1 , min ( count2 , count3 ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 6 ]
    N = len ( arr )
    print ( solve ( arr , N ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
from collections import defaultdict
def mergePalindromes ( S , P ) :
    mapS = defaultdict ( lambda : 0 )
    mapP = defaultdict ( lambda : 0 )
    mapT = defaultdict ( lambda : 0 )
    n = len ( S )
    m = len ( P )
    for i in range ( n ) :
        mapS [ ord ( S [ i ] ) ] += 1
    for i in range ( m ) :
        mapP [ ord ( P [ i ] ) ] += 1
    for i in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        if ( mapS [ i ] % 2 == 0 ) :
            mapT [ i ] += mapS [ i ]
            mapS [ i ] = 0
        else :
            mapT [ i ] += mapS [ i ] - 1
            mapS [ i ] = 1
        if ( mapP [ i ] % 2 == 0 ) :
            mapT [ i ] += mapP [ i ]
            mapP [ i ] = 0
        else :
            mapT [ i ] += mapP [ i ] - 1
            mapP [ i ] = 1
    check = 0
    for i in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        if ( mapS [ i ] > 0 and mapP [ i ] > 0 ) :
            mapT [ i ] += 2
            check = 1
            break
    half1 , half2 = " " , " "
    for i in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        j = 0
        while ( ( 2 * j ) < mapT [ i ] ) :
            half1 += chr ( i )
            half2 += chr ( i )
            j += 1
    half2 = half2 [ : : - 1 ]
    if ( check ) :
        return half1 + half2
    for i in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        if ( mapS [ i ] > 0 or mapP [ i ] > 0 ) :
            half1 += chr ( i )
            return half1 + half2
    return half1 + half2
S = " aeabb "
P = " dfedf "
print ( mergePalindromes ( S , P ) )

Index/key variables: i
Accumulator variables: half1, half2, j
Iterator variables: i
Python program:
from collections import defaultdict
def countOfSubarray ( arr , N ) :
    for i in range ( N ) :
        arr [ i ] -= 1
    pref = [ 0 ] * N
    pref [ 0 ] = arr [ 0 ]
    for i in range ( 1 , N ) :
        pref [ i ] = pref [ i - 1 ] + arr [ i ]
    mp = defaultdict ( lambda : 0 )
    answer = 0
    mp [ 0 ] += 1
    for i in range ( N ) :
        answer += mp [ pref [ i ] ]
        mp [ pref [ i ] ] += 1
    return answer
arr = [ 1 , 1 , 0 ]
N = len ( arr )
print ( countOfSubarray ( arr , N ) )

Index/key variables: i
Accumulator variables: answer
Iterator variables: i
Python program:
import math
def printsubset ( n , k ) :
    count = 0
    x = 0
    vec = [ ]
    while ( n > 0 ) :
        x = n & 1
        if ( x ) :
            vec . append ( pow ( k , count ) )
        n = n >> 1
        count += 1
    for item in vec :
        print ( item , end = " ▁ " )
n = 7
k = 4
printsubset ( n , k )

Accumulator variables: count, vec
Iterator variables: item
Python program:
def solve ( s , x , y ) :
    res = 0
    for c in s :
        if ( ord ( c ) - ord ( '0' ) == x ) :
            res += 1
            x , y = y , x
    if ( x != y and res % 2 == 1 ) :
        res -= 1
    return res
def find_min ( s ) :
    count = 0
    for i in range ( 10 ) :
        for j in range ( 10 ) :
            count = max ( count , solve ( s , i , j ) )
    return count
s = "100120013"
n = len ( s )
answer = find_min ( s )
print ( n - answer )

Accumulator variables: res
Iterator variables: c, i, j
Python program:
def countSetBitsUtil ( x ) :
    if ( x < 1 ) :
        return 0 ;
    if ( x % 2 == 0 ) :
        return 0 ;
    else :
        return 1 + ( countSetBitsUtil ( x / 2 ) ) ;
def countSetBits ( L , R ) :
    bitCount = 0 ;
    for i in range ( L , R + 1 ) :
        bitCount += countSetBitsUtil ( i ) ;
    return bitCount ;
if __name__ == ' _ _ main _ _ ' :
    L = 3 ;
    R = 5 ;
    print ( " Total ▁ set ▁ bit ▁ count ▁ is ▁ " , countSetBits ( L , R ) ) ;

Accumulator variables: bitCount
Iterator variables: i
Python program:
def values_of_Q ( X ) :
    val_Q = [ ]
    for i in range ( 1 , X + 1 ) :
        if ( ( ( ( X + i ) * X ) ) % i == 0 ) :
            val_Q . append ( X + i )
    print ( len ( val_Q ) )
    for i in range ( len ( val_Q ) ) :
        print ( val_Q [ i ] , end = " ▁ " )
X = 3
values_of_Q ( X )

Index/key variables: i
Accumulator variables: val_Q
Iterator variables: i
Python program:
def gcd ( str1 , str2 ) :
    if ( len ( str1 ) < len ( str2 ) ) :
        return gcd ( str2 , str1 )
    elif ( not str1 . startswith ( str2 ) ) :
        return " "
    elif ( len ( str2 ) == 0 ) :
        return str1
    else :
        return gcd ( str1 [ len ( str2 ) : ] , str2 )
def findGCD ( arr , n ) :
    result = arr [ 0 ]
    for i in range ( 1 , n ) :
        result = gcd ( result , arr [ i ] )
    return result
arr = [ " GFGGFG " , " GFGGFG " , " GFGGFGGFGGFG " ]
n = len ( arr )
print ( findGCD ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
N = 4
M = 4
def balancedMatrix ( mat ) :
    is_balanced = True
    i = 0
    while i < N and is_balanced :
        j = 0
        while j < N and is_balanced :
            if ( ( i == 0 or i == N - 1 ) and ( j == 0 or j == M - 1 ) ) :
                if mat [ i ] [ j ] >= 2 :
                    isbalanced = False
            elif ( i == 0 or i == N - 1 or j == 0 or j == M - 1 ) :
                if mat [ i ] [ j ] >= 3 :
                    is_balanced = False
            else :
                if mat [ i ] [ j ] >= 4 :
                    is_balanced = False
            j += 1
        i += 1
    if is_balanced :
        return " Balanced "
    else :
        return " Unbalanced "
mat = [ [ 1 , 2 , 3 , 4 ] , [ 3 , 5 , 2 , 6 ] , [ 5 , 3 , 6 , 1 ] , [ 9 , 5 , 6 , 0 ] ]
print ( balancedMatrix ( mat ) )

Index/key variables: i, j
Boolean variables: is_balanced, isbalanced
Python program:
def unixTimeToHumanReadable ( seconds ) :
    ans = " "
    daysOfMonth = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]
    ( currYear , daysTillNow , extraTime , extraDays , index , date , month , hours , minutes , secondss , flag ) = ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
    daysTillNow = seconds // ( 24 * 60 * 60 )
    extraTime = seconds % ( 24 * 60 * 60 )
    currYear = 1970
    while ( daysTillNow >= 365 ) :
        if ( currYear % 400 == 0 or ( currYear % 4 == 0 and currYear % 100 != 0 ) ) :
            daysTillNow -= 366
        else :
            daysTillNow -= 365
        currYear += 1
    extraDays = daysTillNow + 1
    if ( currYear % 400 == 0 or ( currYear % 4 == 0 and currYear % 100 != 0 ) ) :
        flag = 1
    month = 0
    index = 0
    if ( flag == 1 ) :
        while ( True ) :
            if ( index == 1 ) :
                if ( extraDays - 29 < 0 ) :
                    break
                month += 1
                extraDays -= 29
            else :
                if ( extraDays - daysOfMonth [ index ] < 0 ) :
                    break
                month += 1
                extraDays -= daysOfMonth [ index ]
            index += 1
    else :
        while ( True ) :
            if ( extraDays - daysOfMonth [ index ] < 0 ) :
                break
            month += 1
            extraDays -= daysOfMonth [ index ]
            index += 1
    if ( extraDays > 0 ) :
        month += 1
        date = extraDays
    else :
        if ( month == 2 and flag == 1 ) :
            date = 29
        else :
            date = daysOfMonth [ month - 1 ]
    hours = extraTime // 3600
    minutes = ( extraTime % 3600 ) // 60
    secondss = ( extraTime % 3600 ) % 60
    ans += str ( date )
    ans += " / "
    ans += str ( month )
    ans += " / "
    ans += str ( currYear )
    ans += " ▁ "
    ans += str ( hours )
    ans += " : "
    ans += str ( minutes )
    ans += " : "
    ans += str ( secondss )
    return ans
if __name__ == " _ _ main _ _ " :
    T = 1595497956
    ans = unixTimeToHumanReadable ( T )
    print ( ans )

Index/key variables: index
Accumulator variables: currYear, daysTillNow, extraDays, month
Python program:
import math
import sys
def downToZero ( n ) :
    if ( n <= 3 ) :
        return n
    dp = [ - 1 ] * ( n + 1 )
    dp [ 0 ] = 0
    dp [ 1 ] = 1
    dp [ 2 ] = 2
    dp [ 3 ] = 3
    for i in range ( 4 , n + 1 ) :
        sqr = ( int ) ( math . sqrt ( i ) )
        best = sys . maxsize
        while ( sqr > 1 ) :
            if ( i % sqr == 0 ) :
                best = min ( best , 1 + dp [ sqr ] )
            sqr -= 1
        best = min ( best , 1 + dp [ i - 1 ] )
        dp [ i ] = best
    return dp [ n ]
if __name__ == " _ _ main _ _ " :
    n = 4
    print ( downToZero ( n ) )

Index/key variables: i, n, sqr
Iterator variables: i
Python program:
def minimumrequired ( A , N ) :
    K = N
    while ( K > 0 ) :
        if ( K % 2 ) == 1 :
            ans = K
            break
        ispalindrome = 1
        for i in range ( 0 , K // 2 ) :
            if ( A [ i ] != A [ K - 1 - i ] ) :
                ispalindrome = 0
        if ( ispalindrome == 1 ) :
            ans = K // 2
            K = K // 2
        else :
            ans = K
            break
    return ans
A = [ 1 , 2 , 2 , 1 , 1 , 2 , 2 , 1 ]
N = len ( A )
print ( minimumrequired ( A , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def sumOfFactors ( N ) :
    ans = 0
    for i in range ( 1 , N + 1 ) :
        first = i
        last = ( N // i ) * i
        factors = ( last - first ) // i + 1
        totalContribution = ( ( ( factors * ( factors + 1 ) ) // 2 ) * i )
        ans += totalContribution
    return ans
N = 3
print ( sumOfFactors ( N ) )

Accumulator variables: ans
Iterator variables: i
Python program:
def getMaxDifference ( N ) :
    M = - 1 ;
    maxDiff = 0 ;
    for i in range ( N ) :
        diff = ( N ^ i ) - ( N & i ) ;
        if ( diff >= maxDiff ) :
            maxDiff = diff ;
            M = i ;
    return M ;
if __name__ == ' _ _ main _ _ ' :
    N = 6 ;
    print ( getMaxDifference ( N ) ) ;

Iterator variables: i
Python program:
import math
def findM ( N ) :
    M = 0 ;
    MSB = int ( math . log ( N ) ) ;
    for i in range ( MSB ) :
        if ( ( N & ( 1 << i ) ) == 0 ) :
            M += ( 1 << i ) ;
    return M ;
if __name__ == ' _ _ main _ _ ' :
    N = 6 ;
    print ( findM ( N ) ) ;

Accumulator variables: M
Iterator variables: i
Python program:
cont = [ [ 0 for i in range ( 1000 ) ] for j in range ( 1000 ) ]
def num_of_containers ( n , x ) :
    count = 0
    cont [ 1 ] [ 1 ] = x
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , i + 1 ) :
            if ( cont [ i ] [ j ] >= 1 ) :
                count += 1
                cont [ i + 1 ] [ j ] += ( cont [ i ] [ j ] - 1 ) / 2
                cont [ i + 1 ] [ j + 1 ] += ( cont [ i ] [ j ] - 1 ) / 2
    print ( count )
n = 3
x = 5
num_of_containers ( n , x )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
import sys
def findTriplet ( arr ) :
    n = len ( arr )
    st = [ ]
    h3 = - sys . maxsize - 1
    h1 = sys . maxsize
    for i in range ( n - 1 , - 1 , - 1 ) :
        h1 = arr [ i ]
        while ( len ( st ) > 0 and st [ - 1 ] < arr [ i ] ) :
            h3 = st [ - 1 ]
            del st [ - 1 ]
        st . append ( arr [ i ] )
        if ( h1 < h3 ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 7 , 5 , 6 ]
    if ( findTriplet ( arr ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: st
Iterator variables: i
Python program:
def distinctNumbers ( arr , m , n ) :
    count = { }
    for i in range ( n ) :
        count [ arr [ i ] ] = count . get ( arr [ i ] , 0 ) + 1
    fre_arr = [ 0 ] * ( n + 1 )
    for it in count :
        fre_arr [ count [ it ] ] += 1
    ans = len ( count )
    for i in range ( 1 , n + 1 ) :
        temp = fre_arr [ i ]
        if ( temp == 0 ) :
            continue
        t = min ( temp , m // i )
        ans -= t
        m -= i * t
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 1 , 5 , 3 , 5 , 1 , 3 ]
    n = len ( arr )
    m = 2
    print ( distinctNumbers ( arr , m , n ) )

Index/key variables: i, it
Accumulator variables: ans, m
Iterator variables: i, it
Python program:
M = 4
N = 5
def no_of_moves ( Matrix , x , y ) :
    moves = 0
    for i in range ( M ) :
        for j in range ( N ) :
            if ( Matrix [ i ] [ j ] != 0 ) :
                moves += abs ( x - i )
                moves += abs ( y - j )
    print ( moves )
if __name__ == ' _ _ main _ _ ' :
    x = 3
    y = 2
    Matrix = [ [ 1 , 0 , 1 , 1 , 0 ] , [ 0 , 1 , 1 , 0 , 1 ] , [ 0 , 0 , 1 , 1 , 0 ] , [ 1 , 1 , 1 , 0 , 0 ] ]
    num = 1
    no_of_moves ( Matrix , x , y )

Index/key variables: i, j
Accumulator variables: moves
Iterator variables: i, j
Python program:
def countSubstrings ( s ) :
    n = len ( s )
    answer = ( n * ( n - 1 ) ) // 2
    cnt = 1
    v = [ ]
    for i in range ( 1 , n ) :
        if ( s [ i ] == s [ i - 1 ] ) :
            cnt += 1
        else :
            v . append ( cnt )
            cnt = 1
    if ( cnt > 0 ) :
        v . append ( cnt )
    for i in range ( len ( v ) - 1 ) :
        answer -= ( v [ i ] + v [ i + 1 ] - 1 )
    return answer
if __name__ == ' _ _ main _ _ ' :
    s = "00111"
    print ( countSubstrings ( s ) )

Index/key variables: i
Accumulator variables: answer, cnt, v
Iterator variables: i
Python program:
def get_palindrome_time ( str ) :
    hh = ( ( ord ( str [ 0 ] ) - 48 ) * 10 + ( ord ( str [ 1 ] ) - 48 ) )
    mm = ( ( ord ( str [ 3 ] ) - 48 ) * 10 + ( ord ( str [ 4 ] ) - 48 ) )
    requiredTime = 0
    while ( hh % 10 != mm // 10 or hh // 10 != mm % 10 ) :
        mm += 1
        if ( mm == 60 ) :
            mm = 0
            hh += 1
        if ( hh == 24 ) :
            hh = 0
        requiredTime += 1 ;
    return requiredTime
if __name__ == " _ _ main _ _ " :
    str = "05:39" ;
    print ( get_palindrome_time ( str ) ) ;

Accumulator variables: hh, mm, requiredTime
Python program:
def maximumSubarraySum ( a , n , subarrays ) :
    maxsum = 0
    prefixArray = [ 0 ] * n
    for i in range ( len ( subarrays ) ) :
        prefixArray [ subarrays [ i ] [ 0 ] - 1 ] += 1
        prefixArray [ subarrays [ i ] [ 1 ] ] -= 1
    for i in range ( 1 , n ) :
        prefixArray [ i ] += prefixArray [ i - 1 ]
    prefixArray . sort ( )
    prefixArray . reverse ( )
    a . sort ( )
    a . reverse ( )
    for i in range ( n ) :
        maxsum += a [ i ] * prefixArray [ i ]
    return maxsum
n = 6
a = [ 4 , 1 , 2 , 1 , 9 , 2 ]
subarrays = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] , [ 3 , 4 ] ]
print ( maximumSubarraySum ( a , n , subarrays ) )

Index/key variables: i
Accumulator variables: maxsum
Iterator variables: i
Python program:
def maxProfit ( value , N , K ) :
    value . sort ( )
    maxval = value [ N - 1 ]
    maxProfit = 0
    while True :
        curr_val = 0
        for i in range ( N ) :
            curr_val += value [ i ]
            if ( curr_val <= K ) :
                maxProfit = max ( curr_val + maxval * ( i + 1 ) , maxProfit )
        if not next_permutation ( value ) :
            break
    return maxProfit
def next_permutation ( p ) :
    for a in range ( len ( p ) - 2 , - 1 , - 1 ) :
        if p [ a ] < p [ a + 1 ] :
            b = len ( p ) - 1
            while True :
                if p [ b ] > p [ a ] :
                    t = p [ a ]
                    p [ a ] = p [ b ]
                    p [ b ] = t
                    a += 1
                    b = len ( p ) - 1
                    while a < b :
                        t = p [ a ]
                        p [ a ] = p [ b ]
                        p [ b ] = t
                        a += 1
                        b -= 1
                    return True
                b -= 1
    return False
N , K = 4 , 6
values = [ 5 , 2 , 7 , 3 ]
print ( maxProfit ( values , N , K ) )

Index/key variables: a, b, i
Accumulator variables: curr_val
Iterator variables: a, i
Python program:
import math
def MinValue ( n ) :
    while ( int ( math . sqrt ( n ) ) == math . sqrt ( n ) and n > 1 ) :
        n = math . sqrt ( n )
    for i in range ( int ( math . sqrt ( n ) ) , 1 , - 1 ) :
        while ( n % ( i * i ) == 0 ) :
            n /= i
    print ( n )
n = 20
MinValue ( n )

Accumulator variables: n
Iterator variables: i
Python program:
def isPalindrome ( l , r , s ) :
    while ( l <= r ) :
        if ( s [ l ] != s [ r ] ) :
            return bool ( False )
        l += 1
        r -= 1
    return bool ( True )
def numWays ( s ) :
    n = len ( s )
    ans = 0
    for i in range ( n - 1 ) :
        if ( isPalindrome ( 0 , i , s ) and isPalindrome ( i + 1 , n - 1 , s ) ) :
            ans += 1
    return ans
S = " aaaaa "
print ( numWays ( S ) )

Index/key variables: l, r
Accumulator variables: ans
Iterator variables: i
Python program:
def maxModulosum ( a , n ) :
    sum1 = 0 ;
    for i in range ( 0 , n ) :
        sum1 += a [ i ] ;
    return sum1 - n ;
a = [ 3 , 4 , 6 ] ;
n = len ( a ) ;
print ( maxModulosum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: sum1
Iterator variables: i