dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from array import *
from math import *
def countOddIntegers ( arr , N ) :
    Fact = [ 0 ] * N
    Fact [ 0 ] = 1
    for i in range ( 1 , N ) :
        Fact [ i ] = i * Fact [ i - 1 ]
    freq = [ 0 ] * 10
    for i in range ( len ( freq ) ) :
        freq [ i ] = 0 ;
    for i in range ( N ) :
        freq [ arr [ i ] ] = freq [ arr [ i ] ] + 1 ;
    ans = 0
    for i in range ( 1 , 10 , 2 ) :
        if ( freq [ i ] == 0 ) :
            continue
        freq [ i ] = freq [ i ] - 1 ;
        for j in range ( 1 , 10 , 1 ) :
            cur_ans = 0
            if ( freq [ j ] == 0 ) :
                continue
            freq [ j ] = freq [ j ] - 1 ;
            cur_ans = Fact [ N - 2 ]
            for k in range ( 10 ) :
                cur_ans = cur_ans / Fact [ freq [ k ] ]
            ans += cur_ans
            freq [ j ] = freq [ j ] + 1 ;
        freq [ i ] = freq [ i ] + 1 ;
    return ceil ( ans )
if __name__ == " _ _ main _ _ " :
    A = [ 2 , 3 , 4 , 1 , 2 , 3 ]
    N = len ( A )
    print ( countOddIntegers ( A , N ) )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
def sumOfDigits ( N ) :
    sum = 0
    while ( N ) :
        sum += ( N % 10 )
        N = N // 10
    return sum
def CountPair ( arr , n ) :
    mp = { }
    for i in range ( n ) :
        val = arr [ i ] + sumOfDigits ( arr [ i ] )
        if val in mp :
            mp [ val ] += 1
        else :
            mp [ val ] = 1
    count = 0
    for key , value in mp . items ( ) :
        val = key
        times = value
        count += ( ( times * ( times - 1 ) ) // 2 )
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 105 , 96 , 20 , 2 , 87 , 96 ]
    N = len ( arr )
    print ( CountPair ( arr , N ) )

Index/key variables: i, val
Accumulator variables: count, sum
Iterator variables: i, key, value
Python program:
def build_tree ( b , seg_tree , l , r , vertex ) :
    if ( l == r ) :
        seg_tree [ vertex ] = b [ l ]
        return
    mid = int ( ( l + r ) / 2 )
    build_tree ( b , seg_tree , l , mid , 2 * vertex )
    build_tree ( b , seg_tree , mid + 1 , r , 2 * vertex + 1 )
    seg_tree [ vertex ] = __gcd ( seg_tree [ 2 * vertex ] , seg_tree [ 2 * vertex + 1 ] )
def __gcd ( a , b ) :
    if b == 0 :
        return b
    else :
        return __gcd ( b , a % b )
def range_gcd ( seg_tree , v , tl , tr , l , r ) :
    if ( l > r ) :
        return 0
    if ( l == tl and r == tr ) :
        return seg_tree [ v ]
    tm = int ( ( tl + tr ) / 2 )
    return __gcd ( range_gcd ( seg_tree , 2 * v , tl , tm , l , min ( tm , r ) ) , range_gcd ( seg_tree , 2 * v + 1 , tm + 1 , tr , max ( tm + 1 , l ) , r ) )
def maxSubarrayLen ( arr , n ) :
    seg_tree = [ 0 ] * ( 4 * n + 1 )
    build_tree ( arr , seg_tree , 0 , n - 1 , 1 )
    maxLen = 0
    l , r = 0 , 0
    while ( r < n and l < n ) :
        if ( range_gcd ( seg_tree , 1 , 0 , n - 1 , l , r ) == 1 ) :
            l += 1
        maxLen = max ( maxLen , r - l - 1 )
        r += 1
    print ( maxLen , end = " " )
arr = [ 410 , 52 , 51 , 180 , 222 , 33 , 33 ]
N = len ( arr )
maxSubarrayLen ( arr , N )

Index/key variables: l, v, vertex
Accumulator variables: r
Python program:
from math import sqrt
def findValuesOfK ( g ) :
    count = 0
    for i in range ( 1 , int ( sqrt ( g ) ) + 1 , 1 ) :
        if ( g % i == 0 ) :
            if ( i != g // i ) :
                if ( i & 1 ) :
                    count += 1
                if ( ( g // i ) & 1 ) :
                    count += 1
            elif ( i & 1 ) :
                count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    G = 125
    findValuesOfK ( G )

Accumulator variables: count
Iterator variables: i
Python program:
def Avgdifference ( arr , N , K ) :
    sum = 0
    for i in range ( K ) :
        sum += arr [ i ]
    min = sum
    max = sum
    for i in range ( K , N - K + 2 , 1 ) :
        sum += arr [ i ] - arr [ i - K ]
        if ( min > sum ) :
            min = sum
        if ( max < sum ) :
            max = sum
    return ( max - min ) / K
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 8 , 9 , 15 ]
    N = len ( arr )
    K = 2
    print ( Avgdifference ( arr , N , K ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findSet ( N , K ) :
    a = [ ]
    for i in range ( 1 , N + 1 ) :
        if ( i != K ) :
            a . append ( i )
    MaxDistinct = ( N - K ) + ( K // 2 )
    a = a [ : : - 1 ]
    for i in range ( MaxDistinct ) :
        print ( a [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 3
    findSet ( N , K )

Index/key variables: i
Accumulator variables: a
Iterator variables: i
Python program:
def ExtendedEuclidAlgo ( a , b ) :
    if a == 0 :
        return b , 0 , 1
    gcd , x1 , y1 = ExtendedEuclidAlgo ( b % a , a )
    x = y1 - ( b // a ) * x1
    y = x1
    return gcd , x , y
def linearCongruence ( A , B , N ) :
    A = A % N
    B = B % N
    u = 0
    v = 0
    d , u , v = ExtendedEuclidAlgo ( A , N )
    if ( B % d != 0 ) :
        print ( - 1 )
        return
    x0 = ( u * ( B // d ) ) % N
    if ( x0 < 0 ) :
        x0 += N
    for i in range ( d ) :
        print ( ( x0 + i * ( N // d ) ) % N , end = " ▁ " )
A = 15
B = 9
N = 18
linearCongruence ( A , B , N )

Iterator variables: i
Python program:
def factorialWithoutMul ( N ) :
    ans = N
    i = N - 1
    while ( i > 0 ) :
        sum = 0
        for j in range ( i ) :
            sum += ans
        ans = sum
        i -= 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    print ( factorialWithoutMul ( N ) )

Accumulator variables: i, sum
Iterator variables: j
Python program:
def tripletAndSum ( arr , n ) :
    ans = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n , 1 ) :
            for k in range ( j + 1 , n , 1 ) :
                ans += arr [ i ] & arr [ j ] & arr [ k ]
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 5 , 4 , 7 ]
    N = len ( arr )
    tripletAndSum ( arr , N )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
def tripletAndSum ( arr , n ) :
    ans = 0
    for bit in range ( 32 ) :
        cnt = 0
        for i in range ( n ) :
            if ( arr [ i ] & ( 1 << bit ) ) :
                cnt += 1
        ans += ( 1 << bit ) * cnt * ( cnt - 1 ) * ( cnt - 2 ) // 6
    return ans
arr = [ 3 , 5 , 4 , 7 ]
N = len ( arr )
print ( tripletAndSum ( arr , N ) )

Index/key variables: i
Accumulator variables: ans, cnt
Iterator variables: bit, i
Python program:
from bisect import bisect_left
def smallestPermutation ( arr , N ) :
    w = [ False for i in range ( 2 * N + 1 ) ]
    for i in range ( N ) :
        w [ arr [ i ] ] = True
    S = set ( )
    for i in range ( 1 , 2 * N + 1 , 1 ) :
        if ( w [ i ] == False ) :
            S . add ( i )
    found = True
    P = [ ]
    S = list ( S )
    for i in range ( N ) :
        it = bisect_left ( S , arr [ i ] )
        if ( it == - 1 ) :
            found = False
            break
        P . append ( arr [ i ] )
        P . append ( S [ it ] )
        S . remove ( S [ it ] )
    if ( found == False ) :
        print ( " - 1" )
    else :
        for i in range ( 2 * N ) :
            print ( P [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 1 , 3 ]
    N = len ( arr )
    smallestPermutation ( arr , N )

Index/key variables: i, it
Accumulator variables: P, S
Iterator variables: i
Boolean variables: found
Python program:
def maximumSubsequenceSum ( A , N ) :
    ans = 0
    mp = { }
    for i in range ( N ) :
        if ( A [ i ] - i in mp ) :
            mp [ A [ i ] - i ] += A [ i ]
        else :
            mp [ A [ i ] - i ] = A [ i ]
        ans = max ( ans , mp [ A [ i ] - i ] )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    A = [ 10 , 7 , 1 , 9 , 10 , 1 ]
    N = len ( A )
    maximumSubsequenceSum ( A , N )

Index/key variables: i
Iterator variables: i
Python program:
prime = [ True ] * 100001
def SieveOfEratosthenes ( n ) :
    global prime
    for p in range ( 2 , n + 1 ) :
        if p * p > n :
            break
        if ( prime [ p ] == True ) :
            for i in range ( p * p , n + 1 , p ) :
                prime [ i ] = False
def NumberofSets ( N ) :
    SieveOfEratosthenes ( N )
    if ( N == 2 ) :
        print ( 1 )
    elif ( N == 3 ) :
        print ( 2 )
    else :
        ans = 1
        for i in range ( N // 2 , N + 1 ) :
            if ( prime [ i ] ) :
                ans += 1
        print ( ans )
if __name__ == ' _ _ main _ _ ' :
    N = 9
    NumberofSets ( N )

Index/key variables: i, p
Accumulator variables: ans
Iterator variables: i, p
Python program:
def floorDifference ( A , N , X ) :
    totalSum = 0
    perElementSum = 0
    for i in range ( N ) :
        totalSum += A [ i ]
        perElementSum += A [ i ] // X
    totalFloorSum = totalSum // X
    return abs ( totalFloorSum - perElementSum )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    X = 4
    N = len ( A )
    print ( floorDifference ( A , N , X ) )

Index/key variables: i
Accumulator variables: perElementSum, totalSum
Iterator variables: i
Python program:
def val ( c ) :
    if ( c >= '0' and c <= '9' ) :
        return ord ( c ) - 48
    else :
        return ord ( c ) - 65 + 10
def toDeci ( strr , base ) :
    lenn = len ( strr )
    power = 1
    num = 0
    for i in range ( lenn - 1 , - 1 , - 1 ) :
        if ( val ( strr [ i ] ) >= base ) :
            print ( " Invalid ▁ Number " )
            return - 1
        num += val ( strr [ i ] ) * power
        power = power * base
    return num
def reVal ( num ) :
    if ( num >= 0 and num <= 9 ) :
        return chr ( num + 48 )
    else :
        return chr ( num - 10 + 65 )
def fromDeci ( base , inputNum ) :
    res = " "
    while ( inputNum > 0 ) :
        res += reVal ( inputNum % base )
        inputNum //= base
    res = res [ : : - 1 ]
    return res
def convertBase ( s , a , b ) :
    num = toDeci ( s , a )
    ans = fromDeci ( b , num )
    print ( ans )
s = "10B "
a = 16
b = 10
convertBase ( s , a , b )

Index/key variables: i
Accumulator variables: inputNum, num, res
Iterator variables: i
Python program:
def fact ( N ) :
    if ( N == 1 or N == 0 ) :
        return 1
    return N * fact ( N - 1 )
def prefixFactorialArray ( arr , N ) :
    for i in range ( 1 , N ) :
        arr [ i ] += arr [ i - 1 ]
    for i in range ( N ) :
        arr [ i ] = fact ( arr [ i ] )
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 ]
    N = len ( arr )
    prefixFactorialArray ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def removeEveryKth ( l , k ) :
    for i in range ( 0 , len ( l ) ) :
        if i % k == 0 :
            l [ i ] = 0
    arr = [ 0 ]
    for i in range ( 1 , len ( l ) ) :
        if l [ i ] != 0 :
            arr . append ( l [ i ] )
    return arr
def printArray ( l ) :
    for i in range ( 1 , len ( l ) ) :
        print ( l [ i ] , end = " ▁ " )
    print ( )
def printSequence ( n , k ) :
    l = [ int ( i ) for i in range ( 0 , n + 1 ) ]
    x = 1
    for i in range ( 0 , k ) :
        p = l [ x ] + l [ x + 1 ]
        l = removeEveryKth ( l , p )
        x += 1
    printArray ( l )
N = 8
K = 2
printSequence ( N , K )

Index/key variables: i, x
Accumulator variables: arr
Iterator variables: i
Python program:
def makeEqual ( arr , n ) :
    fre0 = [ 0 ] * 33
    fre1 = [ 0 ] * 33
    for i in range ( n ) :
        x = arr [ i ]
        for j in range ( 33 ) :
            if ( x & 1 ) :
                fre1 [ j ] += 1
            else :
                fre0 [ j ] += 1
            x = x >> 1
    ans = 0
    for i in range ( 33 ) :
        ans += min ( fre0 [ i ] , fre1 [ i ] )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 5 ]
    N = len ( arr )
    print ( makeEqual ( arr , N ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def summ ( arr , N , K ) :
    sum = 4
    v = [ i for i in arr ]
    for i in range ( len ( v ) ) :
        if ( v [ i ] % K == 0 ) :
            x = v [ i ] // K
            for j in range ( K ) :
                v . append ( x )
        else :
            break
    for i in range ( len ( v ) ) :
        sum = sum + v [ i ]
    return sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 6 , 8 , 2 ]
    K = 2
    N = len ( arr )
    print ( summ ( arr , N , K ) )

Index/key variables: i
Accumulator variables: v
Iterator variables: i, j
Python program:
def check ( arr , N ) :
    sum = 0
    for i in range ( N ) :
        sum += arr [ i ]
    if ( sum == 0 ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , - 1 , 3 , - 2 , - 1 ]
    N = len ( arr )
    check ( arr , N )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import sys
def startingPoint ( A , N ) :
    sum = 0
    startingindex = 0
    min = sys . maxsize
    for i in range ( 0 , N ) :
        sum += A [ i ]
        if ( sum < min ) :
            min = sum
            startingindex = i + 1
    if ( sum < 0 ) :
        return - 1
    return startingindex % N
arr = [ 3 , - 6 , 7 , - 4 , - 4 , 6 , - 1 ]
N = len ( arr )
print ( startingPoint ( arr , N ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import math
def nearestPow ( x , y ) :
    if y == 1 :
        return 1
    k = int ( math . log ( x , y ) )
    if abs ( y ** k - x ) < abs ( y ** ( k + 1 ) - x ) :
        return y ** k
    return y ** ( k + 1 )
def replacebyNearestPower ( arr ) :
    prev = arr [ - 1 ]
    lastNext = arr [ 0 ]
    for i in range ( len ( arr ) ) :
        temp = arr [ i ]
        if i == len ( arr ) - 1 :
            next = lastNext
        else :
            next = arr [ ( i + 1 ) % len ( arr ) ]
        prevPow = nearestPow ( arr [ i ] , prev )
        nextPow = nearestPow ( arr [ i ] , next )
        if abs ( arr [ i ] - prevPow ) < abs ( arr [ i ] - nextPow ) :
            arr [ i ] = prevPow
        else :
            arr [ i ] = nextPow
        prev = temp
    print ( arr )
arr = [ 2 , 3 , 4 , 1 , 2 ]
replacebyNearestPower ( arr )

Index/key variables: i
Iterator variables: i
Python program:
from math import log
def isPower ( m , y ) :
    res1 = log ( y ) // log ( m )
    res2 = log ( y ) // log ( m )
    return ( res1 == res2 )
def numSub ( arr , n , m ) :
    ans = 0
    cnt = 0
    for i in range ( n ) :
        if ( isPower ( m , arr [ i ] ) ) :
            cnt += 1
            ans += ( cnt * ( cnt - 1 ) ) // 2
        else :
            cnt = 0
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 1 , 3 ]
    m = 3
    n = len ( arr )
    print ( numSub ( arr , n , m ) )

Index/key variables: i
Accumulator variables: ans, cnt
Iterator variables: i
Python program:
import math
def cntPairs ( arr , N ) :
    res = 0
    bit = [ 0 ] * 32
    for i in range ( N ) :
        pos = ( int ) ( math . log2 ( arr [ i ] ) )
        bit [ pos ] += 1
    for i in range ( 32 ) :
        res += ( bit [ i ] * ( bit [ i ] - 1 ) ) // 2
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 ]
    N = len ( arr )
    print ( cntPairs ( arr , N ) )

Index/key variables: i, pos
Accumulator variables: res
Iterator variables: i
Python program:
def minimumMEX ( arr , N , K ) :
    s = set ( )
    for i in range ( 1 , N + 2 , 1 ) :
        s . add ( i )
    for i in range ( K ) :
        s . remove ( arr [ i ] )
    mex = list ( s ) [ 0 ]
    for i in range ( K , N , 1 ) :
        s . remove ( arr [ i ] )
        s . add ( arr [ i - K ] )
        firstElem = list ( s ) [ 0 ]
        mex = min ( mex , firstElem )
    print ( mex )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    K = 3
    N = len ( arr )
    minimumMEX ( arr , N , K )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def smallerNumbers ( arr , N ) :
    hash = [ 0 ] * 100000
    for i in range ( N ) :
        hash [ arr [ i ] ] += 1
    sum = 0
    for i in range ( 1 , 100000 ) :
        hash [ i ] += hash [ i - 1 ]
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            print ( "0" )
            continue
        print ( hash [ arr [ i ] - 1 ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 4 , 1 , 1 , 2 ]
    N = len ( arr )
    smallerNumbers ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def average ( arr , N ) :
    sum = 0
    for i in range ( N ) :
        sum += arr [ i ]
    return sum // N * 1.0 - 1
def mean ( arr , N ) :
    avg = 0
    for i in range ( N ) :
        avg += ( arr [ i ] - avg ) / ( i + 1 )
    return round ( avg , 7 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2147483647 , 1 , 2 ]
    N = len ( arr )
    print ( " Average ▁ by ▁ Standard ▁ method : ▁ " , " { : . 10f } " . format ( - 1.0 * average ( arr , N ) ) )
    print ( " Average ▁ by ▁ Efficient ▁ method : ▁ " , " { : . 10f } " . format ( mean ( arr , N ) ) )

Index/key variables: i
Accumulator variables: avg, sum
Iterator variables: i
Python program:
from collections import defaultdict
def countPairs ( arr , N ) :
    count = 0
    mp = defaultdict ( int )
    for i in range ( N ) :
        val = 1.0 * arr [ i ]
        idx = 1.0 * ( i + 1 )
        count += mp [ val / idx ]
        mp [ val / idx ] += 1
    print ( count )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 5 , 6 , 5 ]
    N = len ( arr )
    countPairs ( arr , N )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def add_edge ( u , v ) :
    global adj
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
def dfs ( u , par = - 1 ) :
    global adj , parent
    parent [ u ] = par
    for child in adj [ u ] :
        if ( child != par ) :
            dfs ( child , u )
def countSmallerAncestors ( n ) :
    global parent , adj
    dfs ( 1 )
    for i in range ( 1 , n + 1 ) :
        node = i
        cnt = 0
        while ( parent [ node ] != - 1 ) :
            if ( parent [ node ] < i ) :
                cnt += 1
            node = parent [ node ]
        print ( cnt , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 6
    adj = [ [ ] for i in range ( 10 ** 5 ) ]
    parent = [ 0 ] * ( 10 ** 5 )
    add_edge ( 1 , 5 )
    add_edge ( 1 , 4 )
    add_edge ( 4 , 6 )
    add_edge ( 5 , 3 )
    add_edge ( 5 , 2 )
    countSmallerAncestors ( N )

Index/key variables: node, u, v
Accumulator variables: cnt
Iterator variables: child, i
Python program:
def countSubsequences ( A ) :
    odd = 0
    even = 0
    for el in A :
        if ( el % 2 == 1 ) :
            odd += 1
        else :
            even += 1
    if ( odd == 0 ) :
        print ( 0 )
    else :
        print ( 1 << len ( A ) - 1 )
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 3 , 4 ]
    countSubsequences ( A )

Accumulator variables: even, odd
Iterator variables: el
Python program:
def maxModProdSubarr ( arr , n , M ) :
    ans = 0
    length = n
    for i in range ( n ) :
        product = 1
        for j in range ( i , n , 1 ) :
            product = ( product * arr [ i ] ) % M
            if ( product > ans ) :
                ans = product
                if ( length > j - i + 1 ) :
                    length = j - i + 1
    print ( " Maximum ▁ subarray ▁ product ▁ is " , ans )
    print ( " Minimum ▁ length ▁ of ▁ the ▁ maximum ▁ product ▁ subarray ▁ is " , length )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 , 2 ]
    N = len ( arr )
    M = 5
    maxModProdSubarr ( arr , N , M )

Index/key variables: i
Iterator variables: i, j
Python program:
from copy import deepcopy
import math
def coprime ( a , b ) :
    return ( math . gcd ( a , b ) ) == 1
def numOfPairs ( arr , N ) :
    count = 0
    for i in range ( 0 , N - 1 ) :
        for j in range ( i + 1 , N ) :
            if ( coprime ( int ( arr [ i ] ) , int ( arr [ j ] ) ) ) :
                count = count + 1
    return count
def noOfCoPrimePairs ( N , d1 , d2 ) :
    l = [ ]
    l . append ( str ( d1 ) )
    l . append ( str ( d2 ) )
    l . sort ( )
    if int ( N ) < int ( l [ 1 ] ) :
        return 0
    total = temp2 = deepcopy ( l )
    flag = 0
    temp3 = [ ]
    while len ( l [ 0 ] ) < 10 :
        for i in range ( len ( l ) ) :
            for j in range ( 2 ) :
                if int ( l [ i ] + temp2 [ j ] ) > int ( N ) :
                    flag = 1
                    break
                total . append ( l [ i ] + temp2 [ j ] )
                temp3 . append ( l [ i ] + temp2 [ j ] )
            if flag == 1 :
                break
        if flag == 1 :
            break
        l = deepcopy ( temp3 )
        temp3 = [ ]
    lenOfTotal = len ( total )
    ans = numOfPairs ( total , lenOfTotal )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    N = 30
    d1 = 2
    d2 = 3
    noOfCoPrimePairs ( N , d1 , d2 )

Index/key variables: i, j
Accumulator variables: temp3, total
Iterator variables: i, j
Python program:
def tile_placing ( grid , N ) :
    dp = [ 0 ] * ( N + 5 ) ;
    orig_cost = 0 ;
    for i in range ( 2 ) :
        for j in range ( N ) :
            orig_cost += grid [ i ] [ j ] ;
    dp [ 0 ] = 0 ;
    dp [ 1 ] = abs ( grid [ 0 ] [ 0 ] - grid [ 1 ] [ 0 ] ) ;
    for i in range ( 2 , N + 1 ) :
        dp [ i ] = max ( dp [ i - 1 ] + abs ( grid [ 0 ] [ i - 1 ] - grid [ 1 ] [ i - 1 ] ) , dp [ i - 2 ] + abs ( grid [ 0 ] [ i - 2 ] - grid [ 0 ] [ i - 1 ] ) + abs ( grid [ 1 ] [ i - 2 ] - grid [ 1 ] [ i - 1 ] ) ) ;
    print ( orig_cost - dp [ N ] , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    M = [ [ 7 , 5 , 1 , 3 ] , [ 8 , 6 , 0 , 2 ] ] ;
    N = len ( M [ 0 ] ) ;
    tile_placing ( M , N ) ;

Index/key variables: N, i, j
Accumulator variables: orig_cost
Iterator variables: i, j
Python program:
def findSplit ( arr , N ) :
    for l in range ( 1 , N - 3 , 1 ) :
        for r in range ( l + 2 , N - 1 , 1 ) :
            lsum = 0
            rsum = 0
            msum = 0
            for i in range ( 0 , l , 1 ) :
                lsum += arr [ i ]
            for i in range ( l + 1 , r , 1 ) :
                msum += arr [ i ]
            for i in range ( r + 1 , N , 1 ) :
                rsum += arr [ i ]
            if ( lsum == rsum and rsum == msum ) :
                print ( l , r )
                return
    print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , 12 , 7 , 19 , 4 , 3 ]
    N = len ( arr )
    findSplit ( arr , N )

Index/key variables: i
Accumulator variables: lsum, msum, rsum
Iterator variables: i, l, r
Python program:
import math
def solve ( A , n , Q , q ) :
    one = 0
    for i in range ( 0 , n ) :
        if ( A [ i ] == 1 ) :
            one += 1
    glows = 0
    count = 0
    if ( one >= int ( math . ceil ( n / 2 ) ) ) :
        glows = 1
    for i in range ( 0 , q ) :
        prev = glows
        if ( A [ Q [ i ] - 1 ] == 1 ) :
            one -= 1
        if ( A [ Q [ i ] - 1 ] == 0 ) :
            one += 1
        A [ Q [ i ] - 1 ] ^= 1
        if ( one >= int ( math . ceil ( n / 2.0 ) ) ) :
            glows = 1
        else :
            glows = 0
        if ( prev != glows ) :
            count += 1
    return count
n = 3
arr = [ 1 , 1 , 0 ]
q = 3
Q = [ 3 , 2 , 1 ]
print ( solve ( arr , n , Q , q ) )

Index/key variables: i
Accumulator variables: count, one
Iterator variables: i
Python program:
def sumOfDigits ( N ) :
    sum = 0
    while ( N != 0 ) :
        sum += N % 10
        N //= 10
    return sum
def elementsHavingDigitSumK ( arr , N , K ) :
    count = 0
    for i in range ( N ) :
        if ( sumOfDigits ( arr [ i ] ) == K ) :
            count += 1
    print ( count )
arr = [ 23 , 54 , 87 , 29 , 92 , 62 ]
K = 11
N = len ( arr )
elementsHavingDigitSumK ( arr , N , K )

Index/key variables: i
Accumulator variables: N, count, sum
Iterator variables: i