dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def percent ( n , x ) :
    p = ( int ) ( n ) * x ;
    p /= 100 ;
    return p ;
def getLoss ( price , quantity , X , n ) :
    loss = 0 ;
    for i in range ( n ) :
        originalPrice = price [ i ] ;
        sellingPrice = originalPrice + percent ( originalPrice , X [ i ] ) ;
        afterDiscount = sellingPrice - percent ( sellingPrice , X [ i ] ) ;
        loss += ( ( originalPrice - afterDiscount ) * quantity [ i ] ) ;
    return round ( loss , 2 ) ;
price = [ 20 , 48 , 200 , 100 ] ;
quantity = [ 20 , 48 , 1 , 1 ] ;
X = [ 0 , 48 , 200 , 5 ] ;
n = len ( X ) ;
print ( getLoss ( price , quantity , X , n ) ) ;

Index/key variables: i
Accumulator variables: loss
Iterator variables: i
Python program:
def maxAbsDiff ( arr , n ) :
    minEle = arr [ 0 ]
    maxEle = arr [ 0 ]
    for i in range ( 1 , n ) :
        minEle = min ( minEle , arr [ i ] )
        maxEle = max ( maxEle , arr [ i ] )
    return ( maxEle - minEle )
arr = [ 2 , 1 , 5 , 3 ]
n = len ( arr )
print ( maxAbsDiff ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys ;
def maxSubArraySum ( a , size ) :
    max_so_far = - ( sys . maxsize - 1 ) ;
    max_ending_here = 0 ;
    for i in range ( size ) :
        max_ending_here = max_ending_here + a [ i ] ;
        if ( max_so_far < max_ending_here ) :
            max_so_far = max_ending_here ;
        if ( max_ending_here < 0 ) :
            max_ending_here = 0 ;
    return max_so_far ;
def maximizeSum ( a , n ) :
    cnt = 0 ;
    mini = sys . maxsize ;
    minSubarray = sys . maxsize ;
    sum = maxSubArraySum ( a , n ) ;
    max_so_far = - ( sys . maxsize - 1 ) ;
    max_ending_here = 0 ;
    for i in range ( n ) :
        max_ending_here = max_ending_here + a [ i ] ;
        cnt += 1 ;
        minSubarray = min ( a [ i ] , minSubarray ) ;
        if ( sum == max_ending_here ) :
            if ( cnt == 1 ) :
                mini = min ( mini , 0 ) ;
            else :
                mini = min ( mini , minSubarray ) ;
        if ( max_ending_here < 0 ) :
            max_ending_here = 0 ;
            cnt = 0 ;
            minSubarray = sys . maxsize ;
    return sum - mini ;
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 3 , - 2 , 3 ] ;
    n = len ( a )
    print ( maximizeSum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def isDudeney ( n ) :
    cube_rt = int ( round ( ( pow ( n , 1.0 / 3.0 ) ) ) )
    if cube_rt * cube_rt * cube_rt != n :
        return False
    dig_sum = 0
    temp = n
    while temp > 0 :
        rem = temp % 10
        dig_sum += rem
        temp //= 10
    if cube_rt != dig_sum :
        return False
    return True
if __name__ == ' _ _ main _ _ ' :
    n = 17576
    if isDudeney ( n ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: dig_sum, temp
Python program:
def countTriangles ( a , n ) :
    cnt = 0
    pairs = 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        pairs += a [ i ] // 2
        if ( a [ i ] % 2 == 1 and pairs > 0 ) :
            cnt += 1
            pairs -= 1
    cnt += ( 2 * pairs ) // 3
    return cnt
a = [ 1 , 2 , 2 , 2 , 2 ]
n = len ( a )
print ( countTriangles ( a , n ) )

Index/key variables: i
Accumulator variables: cnt, pairs
Iterator variables: i
Python program:
def getHCF ( x , y ) :
    minimum = min ( x , y )
    if ( x % minimum == 0 and y % minimum == 0 ) :
        return minimum
    for i in range ( minimum // 2 , 1 , - 1 ) :
        if ( x % i == 0 and y % i == 0 ) :
            return i
    return 1
x , y = 16 , 32
print ( getHCF ( x , y ) )

Iterator variables: i
Python program:
from math import sqrt
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return True
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return False
    for i in range ( 5 , int ( sqrt ( n ) ) + 1 , 6 ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
    return True
def isDivisible ( n ) :
    if ( isPrime ( n + 1 ) ) :
        return False
    return True
if __name__ == ' _ _ main _ _ ' :
    n = 6
    if ( isDivisible ( n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Iterator variables: i
Python program:
import sys
R = 5
C = 5
def findMaxCock ( ar ) :
    if ( R < 3 or C < 3 ) :
        return - 1
    max_sum = - sys . maxsize - 1
    for i in range ( R - 2 ) :
        for j in range ( C - 2 ) :
            sum = ( ( ar [ i ] [ j ] + ar [ i ] [ j + 2 ] ) + ( ar [ i + 1 ] [ j + 1 ] ) + ( ar [ i + 2 ] [ j ] + ar [ i + 2 ] [ j + 1 ] + ar [ i + 2 ] [ j + 2 ] ) )
            max_sum = max ( max_sum , sum )
    return max_sum ;
if __name__ == ' _ _ main _ _ ' :
    ar = [ [ 0 , 3 , 0 , 6 , 0 ] , [ 0 , 1 , 1 , 0 , 0 ] , [ 1 , 1 , 1 , 0 , 0 ] , [ 0 , 0 , 2 , 0 , 1 ] , [ 0 , 2 , 0 , 1 , 3 ] ]
    print ( findMaxCock ( ar ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def segments ( n , p , m ) :
    c = dict ( )
    c [ 0 ] = 1
    has = False
    Sum = 0
    ans = 0
    for r in range ( n ) :
        if ( p [ r ] < m ) :
            Sum -= 1
        elif ( p [ r ] > m ) :
            Sum += 1
        if ( p [ r ] == m ) :
            has = True
        if ( has ) :
            if ( Sum in c . keys ( ) ) :
                ans += c [ Sum ]
            if Sum - 1 in c . keys ( ) :
                ans += c [ Sum - 1 ]
        else :
            c [ Sum ] = c . get ( Sum , 0 ) + 1
    return ans
a = [ 2 , 4 , 5 , 3 , 1 ]
n = len ( a )
m = 4
print ( segments ( n , a , m ) )

Index/key variables: Sum, r
Accumulator variables: ans
Iterator variables: r
Boolean variables: has
Python program:
import sys
def minOperations ( arr , n ) :
    mp = dict . fromkeys ( arr , 0 ) ;
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1 ;
    maxFreq = - ( sys . maxsize - 1 ) ;
    for key in mp :
        maxFreq = max ( maxFreq , mp [ key ] ) ;
    return ( n - maxFreq ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 6 ] ;
    n = len ( arr ) ;
    print ( minOperations ( arr , n ) ) ;

Index/key variables: i, key
Iterator variables: i, key
Python program:
def CntDivbyX ( arr , n , x ) :
    number = 0
    count = 0
    for i in range ( n ) :
        number = number * 2 + arr [ i ]
        if ( ( number % x == 0 ) ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 1 , 0 , 1 , 1 , 0 ]
    n = len ( arr )
    x = 2
    print ( CntDivbyX ( arr , n , x ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def countCon ( ar , n ) :
    cnt = 0
    for i in range ( n - 1 ) :
        if ( ar [ i ] == ar [ i + 1 ] ) :
            cnt += 1
    return cnt
ar = [ 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 5 , 5 ]
n = len ( ar )
print ( countCon ( ar , n ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
from collections import defaultdict
maxlen = 100
def generateSubStrings ( s , mpp ) :
    l = len ( s )
    for i in range ( 0 , l ) :
        temp = " "
        for j in range ( i , l ) :
            temp += s [ j ]
            mpp [ temp ] += 1
def binomialCoeff ( C ) :
    for i in range ( 0 , 100 ) :
        for j in range ( 0 , 100 ) :
            if j == 0 or j == i :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]
def answerQuery ( mpp , C , k ) :
    ans = 0
    for it in mpp :
        if mpp [ it ] >= k :
            ans += C [ mpp [ it ] ] [ k ]
    return ans
if __name__ == " _ _ main _ _ " :
    s = " aabaab "
    mpp = defaultdict ( lambda : 0 )
    generateSubStrings ( s , mpp )
    C = [ [ 0 for i in range ( maxlen ) ] for j in range ( maxlen ) ]
    binomialCoeff ( C )
    queries = [ 2 , 3 , 4 ]
    q = len ( queries )
    for i in range ( 0 , q ) :
        print ( answerQuery ( mpp , C , queries [ i ] ) )

Index/key variables: i, it, j, k, temp
Accumulator variables: ans
Iterator variables: i, it, j
Python program:
def isPossible ( n ) :
    fac = [ 0 for i in range ( 10 ) ]
    fac [ 0 ] = 1
    fac [ 1 ] = 1
    for i in range ( 2 , 10 , 1 ) :
        fac [ i ] = fac [ i - 1 ] * i
    sum = 0
    x = n
    while ( x ) :
        sum += fac [ x % 10 ]
        x = int ( x / 10 )
    if ( sum % n == 0 ) :
        return True
    return False
if __name__ == ' _ _ main _ _ ' :
    n = 19
    if ( isPossible ( n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
from collections import defaultdict
def findSubsequence ( arr , n , k ) :
    M = defaultdict ( lambda : 0 )
    for i in range ( 0 , n ) :
        M [ arr [ i ] ] += 1
    numCount = [ 0 ] * ( k + 1 )
    for p in M :
        if p <= k :
            i = 1
            while p * i <= k :
                numCount [ p * i ] += M [ p ]
                i += 1
        else :
            break
    lcm , length = 0 , 0
    for i in range ( 1 , k + 1 ) :
        if numCount [ i ] > length :
            length = numCount [ i ]
            lcm = i
    if lcm == 0 :
        print ( - 1 )
    else :
        print ( " LCM ▁ = ▁ { 0 } , ▁ Length ▁ = ▁ { 1 } " . format ( lcm , length ) )
        print ( " Indexes ▁ = ▁ " , end = " " )
        for i in range ( 0 , n ) :
            if lcm % arr [ i ] == 0 :
                print ( i , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    k = 14
    arr = [ 2 , 3 , 4 , 5 ]
    n = len ( arr )
    findSubsequence ( arr , n , k )

Index/key variables: i, p
Iterator variables: i, p
Python program:
def msb ( x ) :
    ret = 0
    while ( ( x >> ( ret + 1 ) ) != 0 ) :
        ret = ret + 1
    return ret
def xorRange ( l , r ) :
    max_bit = msb ( r )
    mul = 2
    ans = 0
    for i in range ( 1 , max_bit + 1 ) :
        if ( ( l // mul ) * mul == ( r // mul ) * mul ) :
            if ( ( ( ( l & ( 1 << i ) ) != 0 ) and ( r - l + 1 ) % 2 == 1 ) ) :
                ans = ans + mul
            mul = mul * 2
            continue
        odd_c = 0
        if ( ( ( l & ( 1 << i ) ) != 0 ) and l % 2 == 1 ) :
            odd_c = ( odd_c ^ 1 )
        if ( ( ( r & ( 1 << i ) ) != 0 ) and r % 2 == 0 ) :
            odd_c = ( odd_c ^ 1 )
        if ( odd_c ) :
            ans = ans + mul
        mul = mul * 2
    zero_bit_cnt = ( r - l + 1 ) // 2
    if ( ( l % 2 == 1 ) and ( r % 2 == 1 ) ) :
        zero_bit_cnt = zero_bit_cnt + 1
    if ( zero_bit_cnt % 2 == 1 ) :
        ans = ans + 1
    return ans
l = 1
r = 4
print ( xorRange ( l , r ) )

Iterator variables: i
Python program:
from math import sqrt
def checkfact ( N , countprime , prime ) :
    countfact = 0
    if ( prime == 2 or prime == 3 ) :
        countfact += 1
    divide = prime
    while ( int ( N / divide ) != 0 ) :
        countfact += int ( N / divide )
        divide = divide * divide
    if ( countfact >= countprime ) :
        return True
    else :
        return False
def check ( N ) :
    sumsquares = ( N + 1 ) * ( 2 * N + 1 )
    countprime = 0
    for i in range ( 2 , int ( sqrt ( sumsquares ) ) + 1 , 1 ) :
        flag = 0
        while ( sumsquares % i == 0 ) :
            flag = 1
            countprime += 1
            sumsquares /= i
        if ( flag ) :
            if ( checkfact ( N - 1 , countprime , i ) == False ) :
                return False
            countprime = 0
    if ( sumsquares != 1 ) :
        if ( checkfact ( N - 1 , 1 , sumsquares ) == False ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    N = 5
    if ( check ( N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: countfact, countprime, sumsquares
Iterator variables: i
Python program:
def countNonIncreasing ( arr , n ) :
    cnt = 0 ;
    len = 1 ;
    for i in range ( 0 , n - 1 ) :
        if ( arr [ i + 1 ] <= arr [ i ] ) :
            len += 1 ;
        else :
            cnt += ( ( ( len + 1 ) * len ) / 2 ) ;
            len = 1 ;
    if ( len > 1 ) :
        cnt += ( ( ( len + 1 ) * len ) / 2 ) ;
    return int ( cnt ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 2 , 3 , 7 , 1 , 1 ] ;
    n = len ( arr ) ;
    print ( countNonIncreasing ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: cnt, len
Iterator variables: i
Python program:
def recamanGenerator ( arr , n ) :
    arr [ 0 ] = 0
    for i in range ( 1 , n ) :
        temp = arr [ i - 1 ] - i
        j = 0
        for j in range ( i ) :
            if ( ( arr [ j ] == temp ) or temp < 0 ) :
                temp = arr [ i - 1 ] + i
                break
        arr [ i ] = temp
def recamanArray ( arr , n ) :
    s = dict ( )
    recaman = [ 0 for i in range ( n ) ]
    recamanGenerator ( recaman , n )
    for i in range ( n ) :
        s [ recaman [ i ] ] = s . get ( recaman [ i ] , 0 ) + 1
    for i in range ( n ) :
        if arr [ i ] in s . keys ( ) :
            del s [ arr [ i ] ]
    return len ( s )
arr = [ 7 , 11 , 20 , 4 , 2 , 1 , 8 , 6 ]
n = len ( arr )
print ( recamanArray ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isPerfectSquare ( arr , n ) :
    umap = dict . fromkeys ( arr , n ) ;
    for key in arr :
        umap [ key ] += 1 ;
    for key in arr :
        if ( umap [ key ] % 2 == 1 ) :
            return False ;
    return True ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 2 , 7 , 7 ] ;
    n = len ( arr )
    if ( isPerfectSquare ( arr , n ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: key
Iterator variables: key
Python program:
def printPermutation ( n ) :
    if ( n % 2 != 0 ) :
        print ( - 1 ) ;
    else :
        for i in range ( 1 , ( n // 2 ) + 1 ) :
            print ( ( 2 * i ) , ( 2 * i - 1 ) , end = " ▁ " ) ;
n = 4 ;
printPermutation ( n ) ;

Iterator variables: i
Python program:
def minOperations ( n , m ) :
    if ( m % n != 0 ) :
        return - 1
    minOperations = 0
    q = int ( m / n )
    while ( q % 2 == 0 ) :
        q = int ( q / 2 )
        minOperations += 1
    while ( q % 3 == 0 ) :
        q = int ( q / 3 )
        minOperations += 1
    if ( q == 1 ) :
        return minOperations
    return - 1
if __name__ == ' _ _ main _ _ ' :
    n = 120
    m = 51840
    print ( minOperations ( n , m ) )

Accumulator variables: minOperations
Python program:
def fib ( n ) :
    phi = ( ( 1 + ( 5 ** ( 1 / 2 ) ) ) / 2 ) ;
    return round ( ( phi ** n ) / ( 5 ** ( 1 / 2 ) ) ) ;
def calculateSum ( l , r ) :
    sum = 0 ;
    for i in range ( l , r + 1 ) :
        sum += fib ( i ) ;
    return sum ;
if __name__ == ' _ _ main _ _ ' :
    l , r = 4 , 8 ;
    print ( calculateSum ( l , r ) ) ;

Accumulator variables: sum
Iterator variables: i
Python program:
def countSubarrays ( arr , n , K ) :
    count = 0
    for i in range ( n ) :
        for j in range ( i , n ) :
            product = 1
            for x in range ( i , j + 1 ) :
                product *= arr [ x ]
            if ( product % K == 0 ) :
                count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 6 , 2 , 8 ]
    n = len ( arr )
    K = 4
    print ( countSubarrays ( arr , n , K ) )

Index/key variables: x
Accumulator variables: count, product
Iterator variables: i, j, x
Python program:
MAX = 100002
tree = [ 0 for i in range ( 4 * MAX ) ] ;
def build ( node , start , end , arr , k ) :
    if ( start == end ) :
        tree [ node ] = ( arr [ start ] ) % k ;
        return ;
    mid = ( start + end ) >> 1 ;
    build ( 2 * node , start , mid , arr , k ) ;
    build ( 2 * node + 1 , mid + 1 , end , arr , k ) ;
    tree [ node ] = ( tree [ 2 * node ] * tree [ 2 * node + 1 ] ) % k ;
def query ( node , start , end , l , r , k ) :
    if ( start > end or start > r or end < l ) :
        return 1 ;
    if ( start >= l and end <= r ) :
        return tree [ node ] % k ;
    mid = ( start + end ) >> 1 ;
    q1 = query ( 2 * node , start , mid , l , r , k ) ;
    q2 = query ( 2 * node + 1 , mid + 1 , end , l , r , k ) ;
    return ( q1 * q2 ) % k ;
def countSubarrays ( arr , n , k ) :
    count = 0 ;
    for i in range ( n ) :
        for j in range ( i , n ) :
            product_mod_k = query ( 1 , 0 , n - 1 , i , j , k ) ;
            if ( product_mod_k == 0 ) :
                count += 1
    return count ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 6 , 2 , 8 ]
    n = len ( arr )
    k = 4 ;
    build ( 1 , 0 , n - 1 , arr , k ) ;
    print ( countSubarrays ( arr , n , k ) )

Index/key variables: node, start
Accumulator variables: count
Iterator variables: i, j
Python program:
def printMaxValPair ( v , n ) :
    v . sort ( )
    N = v [ n - 1 ]
    if N % 2 == 1 :
        first_maxima = N // 2
        second_maxima = first_maxima + 1
        ans1 , ans2 = 3 * ( 10 ** 18 ) , 3 * ( 10 ** 18 )
        from_left , from_right = - 1 , - 1
        _from = - 1
        for i in range ( 0 , n ) :
            if v [ i ] > first_maxima :
                _from = i
                break
            else :
                diff = first_maxima - v [ i ]
                if diff < ans1 :
                    ans1 = diff
                    from_left = v [ i ]
        from_right = v [ _from ]
        diff1 = first_maxima - from_left
        diff2 = from_right - second_maxima
        if diff1 < diff2 :
            print ( N , from_left )
        else :
            print ( N , from_right )
    else :
        maxima = N // 2
        ans1 = 3 * ( 10 ** 18 )
        R = - 1
        for i in range ( 0 , n - 1 ) :
            diff = abs ( v [ i ] - maxima )
            if diff < ans1 :
                ans1 = diff
                R = v [ i ]
        print ( N , R )
if __name__ == " _ _ main _ _ " :
    v = [ 1 , 1 , 2 , 3 , 6 , 1 ]
    n = len ( v )
    printMaxValPair ( v , n )

Index/key variables: _from, i
Iterator variables: i
Python program:
def power ( a , n ) :
    if n == 0 :
        return 1
    p = power ( a , n // 2 )
    p = p * p
    if n & 1 :
        p = p * a
    return p
def countIntegers ( l , r ) :
    ans , i = 0 , 1
    v = power ( 2 , i )
    while v <= r :
        while v <= r :
            if v >= l :
                ans += 1
            v = v * 3
        i += 1
        v = power ( 2 , i )
    if l == 1 :
        ans += 1
    return ans
if __name__ == " _ _ main _ _ " :
    l , r = 12 , 21
    print ( countIntegers ( l , r ) )

Accumulator variables: ans, i
Python program:
def findPairCount ( N , K ) :
    count = 0 ;
    rem = [ 0 ] * K ;
    rem [ 0 ] = N // K ;
    for i in range ( 1 , K ) :
        rem [ i ] = ( N - i ) // K + 1 ;
    if ( K % 2 == 0 ) :
        count += ( rem [ 0 ] * ( rem [ 0 ] - 1 ) ) // 2 ;
        for i in range ( 1 , K // 2 ) :
            count += rem [ i ] * rem [ K - i ] ;
        count += ( rem [ K // 2 ] * ( rem [ K // 2 ] - 1 ) ) // 2 ;
    else :
        count += ( rem [ 0 ] * ( rem [ 0 ] - 1 ) ) // 2 ;
        for i in rage ( 1 , K // 2 + 1 ) :
            count += rem [ i ] * rem [ K - i ] ;
    return count ;
if __name__ == " _ _ main _ _ " :
    N = 10 ; K = 4 ;
    print ( findPairCount ( N , K ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
N = 1000005
prime = [ True for i in range ( N ) ]
def sieve ( ) :
    prime [ 1 ] = False
    prime [ 0 ] = False
    for i in range ( 2 , N ) :
        if ( prime [ i ] == True ) :
            for j in range ( i * 2 , N , i ) :
                prime [ j ] = False
def sumTruncatablePrimes ( n ) :
    sum = 0
    for i in range ( 2 , n ) :
        num = i
        flag = True
        while ( num ) :
            if ( prime [ num ] == False ) :
                flag = False
                break
            num //= 10
        num = i
        power = 10
        while ( num // power ) :
            if ( prime [ num % power ] == False ) :
                flag = False
                break
            power *= 10
        if ( flag == True ) :
            sum += i
    return sum
n = 25
sieve ( )
print ( sumTruncatablePrimes ( n ) )

Index/key variables: i, j, num
Accumulator variables: power, sum
Iterator variables: i, j
Boolean variables: flag
Python program:
N = 3
def MaxTraceSub ( mat ) :
    max_trace = 0
    for i in range ( N ) :
        for j in range ( N ) :
            r = i
            s = j
            trace = 0
            while ( r < N and s < N ) :
                trace += mat [ r ]
                r += 1
                s += 1
                max_trace = max ( trace , max_trace )
    return max_trace
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 10 , 2 , 5 ] , [ 6 , 10 , 4 ] , [ 2 , 7 , - 10 ] ]
    print ( MaxTraceSub ( mat ) )

Index/key variables: r
Accumulator variables: s, trace
Iterator variables: i, j
Python program:
n = 3
m = 3
def check ( a , b ) :
    for i in range ( n ) :
        v1 = [ ]
        v2 = [ ]
        r = i
        col = 0
        while ( r >= 0 and col < m ) :
            v1 . append ( a [ r ] [ col ] )
            v2 . append ( b [ r ] [ col ] )
            r -= 1
            col += 1
        v1 . sort ( reverse = False )
        v2 . sort ( reverse = False )
        for i in range ( len ( v1 ) ) :
            if ( v1 [ i ] != v2 [ i ] ) :
                return False
    for j in range ( 1 , m ) :
        v1 = [ ]
        v2 = [ ]
        r = n - 1
        col = j
        while ( r >= 0 and col < m ) :
            v1 . append ( a [ r ] [ col ] )
            v2 . append ( b [ r ] [ col ] )
            r -= 1
            col += 1
        v1 . sort ( reverse = False )
        v2 . sort ( reverse = False )
        for i in range ( len ( v1 ) ) :
            if ( v1 [ i ] != v2 [ i ] ) :
                return False
    return True
if __name__ == ' _ _ main _ _ ' :
    a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    b = [ [ 1 , 4 , 7 ] , [ 2 , 5 , 6 ] , [ 3 , 8 , 9 ] ]
    if ( check ( a , b ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: col, i, r
Accumulator variables: v1, v2
Iterator variables: i, j
Python program:
def printSum ( a , b ) :
    res , temp1 , temp2 = 0 , 0 , 0
    while a > 0 :
        temp1 = temp1 * 10 + ( a % 10 )
        a //= 10
    a = temp1
    while b > 0 :
        temp2 = temp2 * 10 + ( b % 10 )
        b //= 10
    b = temp2
    while a :
        Sum = a % 10 + b % 10
        if Sum // 10 == 0 :
            res = res * 10 + Sum
        else :
            temp1 = 0
            while Sum > 0 :
                temp1 = temp1 * 10 + ( Sum % 10 )
                Sum //= 10
            Sum = temp1
            while Sum > 0 :
                res = res * 10 + ( Sum % 10 )
                Sum //= 10
        a //= 10
        b //= 10
    return res
if __name__ == " _ _ main _ _ " :
    a , b = 7752 , 8834
    print ( printSum ( a , b ) )

Accumulator variables: Sum, a, b
Python program:
def kthOdd ( arr , n , k ) :
    for i in range ( n ) :
        if ( arr [ i ] % 2 == 1 ) :
            k -= 1 ;
        if ( k == 0 ) :
            return arr [ i ] ;
    return - 1 ;
arr = [ 1 , 2 , 3 , 4 , 5 ] ;
n = len ( arr ) ;
k = 2 ;
print ( kthOdd ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: k
Iterator variables: i
Python program:
def lastFiveDigits ( n ) :
    n = ( ( int ) ( n / 10000 ) * 10000 + ( ( int ) ( n / 100 ) % 10 ) * 1000 + ( n % 10 ) * 100 + ( ( int ) ( n / 10 ) % 10 ) * 10 + ( int ) ( n / 1000 ) % 10 )
    ans = 1
    for i in range ( 5 ) :
        ans *= n
        ans %= 100000
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    n = 12345
    lastFiveDigits ( n )

Accumulator variables: ans
Iterator variables: i
Python program:
def power ( a , n ) :
    if n == 0 :
        return 1
    p = power ( a , n // 2 ) % mod
    p = ( p * p ) % mod
    if n & 1 == 1 :
        p = ( p * a ) % mod
    return p
def computeSum ( arr , n ) :
    arr . sort ( )
    Sum = 0
    for i in range ( 0 , n ) :
        maxs = ( power ( 2 , i ) - 1 + mod ) % mod
        maxs = ( maxs * arr [ i ] ) % mod
        mins = ( power ( 2 , n - 1 - i ) - 1 + mod ) % mod
        mins = ( mins * arr [ i ] ) % mod
        V = ( maxs - mins + mod ) % mod
        Sum = ( Sum + V ) % mod
    return Sum
if __name__ == " _ _ main _ _ " :
    mod = 1000000007
    arr = [ 4 , 3 , 1 ]
    n = len ( arr )
    print ( computeSum ( arr , n ) )

Index/key variables: i
Iterator variables: i