dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countTriplets ( A ) :
    cnt = 0 ;
    tuples = { } ;
    for a in A :
        for b in A :
            if ( a & b ) in tuples :
                tuples [ a & b ] += 1 ;
            else :
                tuples [ a & b ] = 1 ;
    for a in A :
        for t in tuples :
            if ( ( t & a ) == 0 ) :
                cnt += tuples [ t ] ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    A = [ 2 , 1 , 3 ] ;
    print ( countTriplets ( A ) ) ;

Index/key variables: t
Accumulator variables: cnt
Iterator variables: a, b, t
Python program:
def CountWays ( n ) :
    noOfWays = [ 0 ] * ( n + 3 )
    noOfWays [ 0 ] = 1
    noOfWays [ 1 ] = 1
    noOfWays [ 2 ] = 1 + 1
    for i in range ( 3 , n + 1 ) :
        noOfWays [ i ] = noOfWays [ i - 1 ] + noOfWays [ i - 3 ]
    return noOfWays [ n ]
if __name__ == ' _ _ main _ _ ' :
    n = 5
    print ( CountWays ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
import sys
def findWinner ( a , n ) :
    v = [ ]
    c = 0
    for i in range ( 0 , n ) :
        if ( a [ i ] == '0' ) :
            c += 1
        else :
            if ( c != 0 ) :
                v . append ( c )
            c = 0
    if ( c != 0 ) :
        v . append ( c )
    if ( len ( v ) == 0 ) :
        print ( " Player ▁ B " , end = " " )
        return
    if ( len ( v ) == 1 ) :
        if ( ( v [ 0 ] & 1 ) != 0 ) :
            print ( " Player ▁ A " , end = " " )
        else :
            print ( " Player ▁ B " , end = " " )
        return
    first = sys . minsize
    second = sys . minsize
    for i in range ( len ( v ) ) :
        if ( a [ i ] > first ) :
            second = first
            first = a [ i ]
        elif ( a [ i ] > second and a [ i ] != first ) :
            second = a [ i ]
    if ( ( ( first & 1 ) != 0 ) and ( first + 1 ) // 2 > second ) :
        print ( " Player ▁ A " , end = " " )
    else :
        print ( " Player ▁ B " , end = " " )
S = "1100011"
N = len ( S )
findWinner ( S , N )

Index/key variables: i
Accumulator variables: c, v
Iterator variables: i
Python program:
def can_Construct ( S , K ) :
    m = dict ( )
    p = 0
    if ( len ( S ) == K ) :
        return True
    for i in S :
        m [ i ] = m . get ( i , 0 ) + 1
    if ( K > len ( S ) ) :
        return False
    else :
        for h in m :
            if ( m [ h ] % 2 != 0 ) :
                p = p + 1
    if ( K < p ) :
        return False
    return True
if __name__ == ' _ _ main _ _ ' :
    S = " annabelle "
    K = 4
    if ( can_Construct ( S , K ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: h, i
Iterator variables: h, i
Python program:
import math as mt
def steps ( string , n ) :
    flag = False
    x = 0
    for i in range ( len ( string ) ) :
        if ( x == 0 ) :
            flag = True
        if ( x == n - 1 ) :
            flag = False
        for j in range ( x ) :
            print ( " * " , end = " " )
        print ( string [ i ] )
        if ( flag == True ) :
            x += 1
        else :
            x -= 1
n = 4
string = " GeeksForGeeks "
print ( " String : ▁ " , string )
print ( " Max ▁ Length ▁ of ▁ Steps : ▁ " , n )
steps ( string , n )

Index/key variables: i
Accumulator variables: x
Iterator variables: i, j
Boolean variables: flag
Python program:
def countFreq ( arr , n ) :
    visited = [ False for i in range ( n ) ]
    for i in range ( n ) :
        if visited [ i ] == True :
            continue
        count = 1
        for j in range ( i + 1 , n ) :
            if arr [ i ] == arr [ j ] :
                visited [ j ] = True
                count += 1
        print ( arr [ i ] , count )
a = [ 10 , 20 , 20 , 10 , 10 , 20 , 5 , 20 ]
n = len ( a )
countFreq ( a , n )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def isDivisible ( str , k ) :
    n = len ( str )
    c = 0
    for i in range ( 0 , k ) :
        if ( str [ n - i - 1 ] == '0' ) :
            c += 1
    return ( c == k )
str1 = "10101100"
k = 2
if ( isDivisible ( str1 , k ) ) :
    print ( " Yes " )
else :
    print ( " No " )
str2 = "111010100"
k = 2
if ( isDivisible ( str2 , k ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Accumulator variables: c
Iterator variables: i
Python program:
def isNumber ( s ) :
    for i in range ( len ( s ) ) :
        if s [ i ] . isdigit ( ) != True :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    str = "6790"
    if isNumber ( str ) :
        print ( " Integer " )
    else :
        print ( " String " )

Index/key variables: i
Iterator variables: i
Python program:
box1 = 0
box2 = 0
fact = [ 0 for i in range ( 11 ) ]
def getProbability ( balls ) :
    global box1 , box2 , fact
    factorial ( 10 )
    box2 = len ( balls )
    K = 0
    for i in range ( len ( balls ) ) :
        K += balls [ i ]
    if ( K % 2 == 1 ) :
        return 0
    all = comb ( K , K // 2 )
    validPermutation = validPermutations ( K // 2 , balls , 0 , 0 )
    return validPermutation / all
def validPermutations ( n , balls , usedBalls , i ) :
    global box1 , box2 , fact
    if ( usedBalls == n ) :
        if ( box1 == box2 ) :
            return 1
        else :
            return 0
    if ( i >= len ( balls ) ) :
        return 0
    res = validPermutations ( n , balls , usedBalls , i + 1 )
    box1 += 1
    for j in range ( 1 , balls [ i ] + 1 ) :
        if ( j == balls [ i ] ) :
            box2 -= 1
        combinations = comb ( balls [ i ] , j )
        res += combinations * validPermutations ( n , balls , usedBalls + j , i + 1 )
    box1 -= 1
    box2 += 1
    return res
def factorial ( N ) :
    global box1 , box2 , fact
    fact [ 0 ] = 1
    for i in range ( 1 , N + 1 ) :
        fact [ i ] = fact [ i - 1 ] * i
def comb ( n , r ) :
    global box1 , box2 , fact
    res = fact [ n ] // fact [ r ]
    res //= fact [ n - r ]
    return res
arr = [ 2 , 1 , 1 ]
N = 4
print ( getProbability ( arr ) )

Index/key variables: i, n, r
Accumulator variables: K, box2, res
Iterator variables: i, j
Python program:
from collections import defaultdict
def is_partition_possible ( n , x , y , w ) :
    weight_at_x = defaultdict ( int )
    max_x = - 2e3
    min_x = 2e3
    for i in range ( n ) :
        new_x = x [ i ] - y [ i ]
        max_x = max ( max_x , new_x )
        min_x = min ( min_x , new_x )
        weight_at_x [ new_x ] += w [ i ]
    sum_till = [ ]
    sum_till . append ( 0 )
    for x in range ( min_x , max_x + 1 ) :
        sum_till . append ( sum_till [ - 1 ] + weight_at_x [ x ] )
    total_sum = sum_till [ - 1 ]
    partition_possible = False
    for i in range ( 1 , len ( sum_till ) ) :
        if ( sum_till [ i ] == total_sum - sum_till [ i ] ) :
            partition_possible = True
        if ( sum_till [ i - 1 ] == total_sum - sum_till [ i ] ) :
            partition_possible = True
    if partition_possible :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == " _ _ main _ _ " :
    n = 3
    x = [ - 1 , - 2 , 1 ]
    y = [ 1 , 1 , - 1 ]
    w = [ 3 , 1 , 4 ]
    is_partition_possible ( n , x , y , w )

Index/key variables: i, new_x, x
Accumulator variables: sum_till
Iterator variables: i, x
Boolean variables: partition_possible
Python program:
import math
def PrimeFactor ( N ) :
    ANS = dict ( )
    while N % 2 == 0 :
        if 2 in ANS :
            ANS [ 2 ] += 1
        else :
            ANS [ 2 ] = 1
        N = N // 2
    for i in range ( 3 , int ( math . sqrt ( N ) ) + 1 , 2 ) :
        while N % i == 0 :
            if i in ANS :
                ANS [ i ] += 1
            else :
                ANS [ i ] = 1
            N = N // i
    if 2 < N :
        ANS [ N ] = 1
    return ANS
def CountToMakeEqual ( X , Y ) :
    GCD = math . gcd ( X , Y )
    newY = X // GCD
    newX = Y // GCD
    primeX = PrimeFactor ( newX )
    primeY = PrimeFactor ( newY )
    ans = 0
    for factor in primeX :
        if X % factor != 0 :
            return - 1
        ans += primeX [ factor ]
    for factor in primeY :
        if Y % factor != 0 :
            return - 1
        ans += primeY [ factor ]
    return ans
if __name__ == " _ _ main _ _ " :
    X = 36
    Y = 48
    ans = CountToMakeEqual ( X , Y )
    print ( ans )

Index/key variables: N, factor, i
Accumulator variables: ans
Iterator variables: factor, i
Python program:
from collections import deque
def check ( Adj , Src , N , visited ) :
    color = [ 0 ] * N
    visited = [ True ] * Src
    q = deque ( )
    q . append ( Src )
    while ( len ( q ) > 0 ) :
        u = q . popleft ( )
        Col = color [ u ]
        for x in Adj [ u ] :
            if ( visited [ x ] == True and color [ x ] == Col ) :
                return False
            elif ( visited [ x ] == False ) :
                visited [ x ] = True
                q . append ( x )
                color [ x ] = 1 - Col
    return True
def addEdge ( Adj , u , v ) :
    Adj [ u ] . append ( v )
    Adj [ v ] . append ( u )
    return Adj
def isPossible ( Arr , N ) :
    Adj = [ [ ] for i in range ( N ) ]
    for i in range ( N - 1 ) :
        for j in range ( i + 1 , N ) :
            if ( Arr [ i ] [ 0 ] < Arr [ j ] [ 1 ] or Arr [ i ] [ 1 ] > Arr [ j ] [ 0 ] ) :
                continue
            else :
                if ( Arr [ i ] [ 2 ] == Arr [ j ] [ 2 ] ) :
                    Adj = addEdge ( Adj , i , j )
    visited = [ False ] * N
    for i in range ( N ) :
        if ( visited [ i ] == False and len ( Adj [ i ] ) > 0 ) :
            if ( check ( Adj , i , N , visited ) == False ) :
                print ( " No " )
                return
    print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 5 , 7 , 2 ] , [ 4 , 6 , 1 ] , [ 1 , 5 , 2 ] , [ 6 , 5 , 1 ] ]
    N = len ( arr )
    isPossible ( arr , N )

Index/key variables: i, j, u, v, x
Accumulator variables: q
Iterator variables: i, j, x
Python program:
def minimumSwaps ( arr ) :
    count = 0 ;
    i = 0 ;
    while ( i < len ( arr ) ) :
        if ( arr [ i ] != i + 1 ) :
            while ( arr [ i ] != i + 1 ) :
                temp = 0 ;
                temp = arr [ arr [ i ] - 1 ] ;
                arr [ arr [ i ] - 1 ] = arr [ i ] ;
                arr [ i ] = temp ;
                count += 1 ;
        i += 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 , 1 , 5 ] ;
    print ( minimumSwaps ( arr ) ) ;

Index/key variables: i
Accumulator variables: count
Python program:
class Node :
    def __init__ ( self , new_data ) :
        self . data = new_data
        self . next = None
        self . prev = None
def append ( head_ref , new_data ) :
    new_node = Node ( 0 )
    last = head_ref
    new_node . data = new_data
    new_node . next = None
    if ( head_ref == None ) :
        new_node . prev = None
        head_ref = new_node
        return head_ref
    while ( last . next != None ) :
        last = last . next
    last . next = new_node
    new_node . prev = last
    return head_ref
def printList ( node ) :
    last = None
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        last = node
        node = node . next
def mergeList ( p , q ) :
    s = None
    if ( p == None or q == None ) :
        if ( p == None ) :
            return q
        else :
            return p
    if ( p . data < q . data ) :
        p . prev = s
        s = p
        p = p . next
    else :
        q . prev = s
        s = q
        q = q . next
    head = s
    while ( p != None and q != None ) :
        if ( p . data < q . data ) :
            s . next = p
            p . prev = s
            s = s . next
            p = p . next
        else :
            s . next = q
            q . prev = s
            s = s . next
            q = q . next
    if ( p == None ) :
        s . next = q
        q . prev = s
    if ( q == None ) :
        s . next = p
        p . prev = s
    return head
def mergeAllList ( head , k ) :
    finalList = None
    i = 0
    while ( i < k ) :
        finalList = mergeList ( finalList , head [ i ] )
        i = i + 1
    return finalList
k = 3
head = [ 0 ] * k
i = 0
while ( i < k ) :
    head [ i ] = None
    i = i + 1
head [ 0 ] = append ( head [ 0 ] , 1 )
head [ 0 ] = append ( head [ 0 ] , 5 )
head [ 0 ] = append ( head [ 0 ] , 9 )
head [ 1 ] = append ( head [ 1 ] , 2 )
head [ 1 ] = append ( head [ 1 ] , 3 )
head [ 1 ] = append ( head [ 1 ] , 7 )
head [ 1 ] = append ( head [ 1 ] , 12 )
head [ 2 ] = append ( head [ 2 ] , 8 )
head [ 2 ] = append ( head [ 2 ] , 11 )
head [ 2 ] = append ( head [ 2 ] , 13 )
head [ 2 ] = append ( head [ 2 ] , 18 )
finalList = mergeAllList ( head , k )
printList ( finalList )

Index/key variables: i
Class/struct names: Node
Python program:
def maxSumAfterPartition ( arr , n ) :
    pos = [ ]
    neg = [ ]
    zero = 0
    pos_sum = 0
    neg_sum = 0
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            pos . append ( arr [ i ] )
            pos_sum += arr [ i ]
        elif ( arr [ i ] < 0 ) :
            neg . append ( arr [ i ] )
            neg_sum += arr [ i ]
        else :
            zero += 1
    ans = 0
    pos . sort ( )
    neg . sort ( reverse = True )
    if ( len ( pos ) > 0 and len ( neg ) > 0 ) :
        ans = ( pos_sum - neg_sum )
    elif ( len ( pos ) > 0 ) :
        if ( zero > 0 ) :
            ans = ( pos_sum )
        else :
            ans = ( pos_sum - 2 * pos [ 0 ] )
    else :
        if ( zero > 0 ) :
            ans = ( - 1 * neg_sum )
        else :
            ans = ( neg [ 0 ] - ( neg_sum - neg [ 0 ] ) )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , - 5 , - 7 ]
    n = len ( arr )
    print ( maxSumAfterPartition ( arr , n ) )

Index/key variables: i
Accumulator variables: neg, neg_sum, pos, pos_sum, zero
Iterator variables: i
Python program:
def MaxXOR ( arr , N ) :
    res = 0
    for i in range ( N ) :
        res |= arr [ i ]
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 5 , 7 ]
    N = len ( arr )
    print ( MaxXOR ( arr , N ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def countEqual ( A , B , N ) :
    first = 0
    second = N - 1
    count = 0
    while ( first < N and second >= 0 ) :
        if ( A [ first ] < B [ second ] ) :
            first += 1
        elif ( B [ second ] < A [ first ] ) :
            second -= 1
        else :
            count += 1
            first += 1
            second -= 1
    return count
A = [ 2 , 4 , 5 , 8 , 12 , 13 , 17 , 18 , 20 , 22 , 309 , 999 ]
B = [ 109 , 99 , 68 , 54 , 22 , 19 , 17 , 13 , 11 , 5 , 3 , 1 ]
N = len ( A )
print ( countEqual ( A , B , N ) )

Index/key variables: first, second
Accumulator variables: count
Python program:
arr = [ 0 for i in range ( 100005 ) ]
def isPalindrome ( N ) :
    temp = N
    res = 0
    while ( temp != 0 ) :
        rem = temp % 10
        res = res * 10 + rem
        temp //= 10
    if ( res == N ) :
        return True
    else :
        return False
def sumOfDigits ( N ) :
    sum = 0
    while ( N != 0 ) :
        sum += N % 10
        N //= 10
    return sum
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    for i in range ( 2 , ( n // 2 ) + 1 , 1 ) :
        if ( n % i == 0 ) :
            return False
    return True
def precompute ( ) :
    for i in range ( 1 , 100001 , 1 ) :
        if ( isPalindrome ( i ) ) :
            sum = sumOfDigits ( i )
            if ( isPrime ( sum ) ) :
                arr [ i ] = 1
            else :
                arr [ i ] = 0
        else :
            arr [ i ] = 0
    for i in range ( 1 , 100001 , 1 ) :
        arr [ i ] = arr [ i ] + arr [ i - 1 ]
def countNumbers ( Q , N ) :
    precompute ( )
    for i in range ( N ) :
        print ( arr [ Q [ i ] [ 1 ] ] - arr [ Q [ i ] [ 0 ] - 1 ] )
if __name__ == ' _ _ main _ _ ' :
    Q = [ [ 5 , 9 ] , [ 1 , 101 ] ]
    N = len ( Q )
    countNumbers ( Q , N )

Index/key variables: i
Accumulator variables: N, sum, temp
Iterator variables: i
Python program:
def sum ( n ) :
    sm = 0
    while ( n > 0 ) :
        sm += n % 10
        n //= 10
    return sm
def smallestNumber ( n , s ) :
    if ( sum ( n ) <= s ) :
        return n
    ans , k = n , 1
    for i in range ( 9 ) :
        digit = ( ans // k ) % 10
        add = k * ( ( 10 - digit ) % 10 )
        ans += add
        if ( sum ( ans ) <= s ) :
            break
        k *= 10
    return ans
n , s = 3 , 2
print ( smallestNumber ( n , s ) )

Accumulator variables: ans, k, n, sm
Iterator variables: i
Python program:
def removeOcc ( s , ch ) :
    for i in range ( len ( s ) ) :
        if ( s [ i ] == ch ) :
            s = s [ 0 : i ] + s [ i + 1 : ]
            break
    for i in range ( len ( s ) - 1 , - 1 , - 1 ) :
        if ( s [ i ] == ch ) :
            s = s [ 0 : i ] + s [ i + 1 : ]
            break
    return s
s = " hello ▁ world "
ch = ' l '
print ( removeOcc ( s , ch ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def minSteps ( N , increasing , decreasing ) :
    Min = sys . maxsize ;
    for i in increasing :
        if ( Min > i ) :
            Min = i ;
    Max = - sys . maxsize ;
    for i in decreasing :
        if ( Max < i ) :
            Max = i ;
    minSteps = max ( Max , N - Min ) ;
    print ( minSteps ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 7 ;
    increasing = [ 3 , 5 ] ;
    decreasing = [ 6 ] ;
    minSteps ( N , increasing , decreasing ) ;

Iterator variables: i
Python program:
def solve ( P , n ) :
    arr = [ ]
    arr . append ( 0 )
    for x in P :
        arr . append ( x )
    cnt = 0
    for i in range ( 1 , n ) :
        if ( arr [ i ] == i ) :
            arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]
            cnt += 1
    if ( arr [ n ] == n ) :
        arr [ n - 1 ] , arr [ n ] = arr [ n ] , arr [ n - 1 ]
        cnt += 1
    print ( cnt )
N = 9
P = [ 1 , 2 , 4 , 9 , 5 , 8 , 7 , 3 , 6 ]
solve ( P , N )

Index/key variables: i, n
Accumulator variables: arr, cnt
Iterator variables: i, x
Python program:
def SieveOfEratosthenes ( n , allPrimes ) :
    prime = [ True ] * ( n + 1 )
    p = 2
    while p * p <= n :
        if prime [ p ] == True :
            for i in range ( p * p , n + 1 , p ) :
                prime [ i ] = False
        p += 1
    for p in range ( 2 , n + 1 ) :
        if prime [ p ] :
            allPrimes . add ( p )
def countInterestingPrimes ( n ) :
    allPrimes = set ( )
    SieveOfEratosthenes ( n , allPrimes )
    interestingPrimes = set ( )
    squares , quadruples = [ ] , [ ]
    i = 1
    while i * i <= n :
        squares . append ( i * i )
        i += 1
    i = 1
    while i * i * i * i <= n :
        quadruples . append ( i * i * i * i )
        i += 1
    for a in squares :
        for b in quadruples :
            if a + b in allPrimes :
                interestingPrimes . add ( a + b )
    return len ( interestingPrimes )
N = 10
print ( countInterestingPrimes ( N ) )

Index/key variables: i, p
Accumulator variables: allPrimes, interestingPrimes, quadruples, squares
Iterator variables: a, b, i, p
Python program:
def isWaveArray ( arr , n ) :
    result = True
    if ( arr [ 1 ] > arr [ 0 ] and arr [ 1 ] > arr [ 2 ] ) :
        for i in range ( 1 , n - 1 , 2 ) :
            if ( arr [ i ] > arr [ i - 1 ] and arr [ i ] > arr [ i + 1 ] ) :
                result = True
            else :
                result = False
                break
        if ( result == True and n % 2 == 0 ) :
            if ( arr [ n - 1 ] <= arr [ n - 2 ] ) :
                result = False
    elif ( arr [ 1 ] < arr [ 0 ] and arr [ 1 ] < arr [ 2 ] ) :
        for i in range ( 1 , n - 1 , 2 ) :
            if ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) :
                result = True
            else :
                result = False
                break
        if ( result == True and n % 2 == 0 ) :
            if ( arr [ n - 1 ] >= arr [ n - 2 ] ) :
                result = False
    return result
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 2 , 4 ]
    n = len ( arr )
    if ( isWaveArray ( arr , n ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i
Iterator variables: i
Boolean variables: result
Python program:
def countPossiblities ( arr , n ) :
    lastOccur = [ - 1 ] * 100000
    dp = [ 0 ] * ( n + 1 )
    dp [ 0 ] = 1
    for i in range ( 1 , n + 1 ) :
        curEle = arr [ i - 1 ]
        dp [ i ] = dp [ i - 1 ]
        if ( lastOccur [ curEle ] != - 1 and lastOccur [ curEle ] < i - 1 ) :
            dp [ i ] += dp [ lastOccur [ curEle ] ]
        lastOccur [ curEle ] = i
    print ( dp [ n ] )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 2 , 2 ]
    N = len ( arr )
    countPossiblities ( arr , N )

Index/key variables: curEle, i, n
Iterator variables: i
Python program:
def maxSum ( arr , n , m ) :
    dp = [ [ 0 for i in range ( m + 1 ) ] for i in range ( 2 ) ]
    dp [ 0 ] [ m - 1 ] = arr [ 0 ] [ m - 1 ]
    dp [ 1 ] [ m - 1 ] = arr [ 1 ] [ m - 1 ]
    for j in range ( m - 2 , - 1 , - 1 ) :
        for i in range ( 2 ) :
            if ( i == 1 ) :
                dp [ i ] [ j ] = max ( arr [ i ] [ j ] + dp [ 0 ] [ j + 1 ] , arr [ i ] [ j ] + dp [ 0 ] [ j + 2 ] )
            else :
                dp [ i ] [ j ] = max ( arr [ i ] [ j ] + dp [ 1 ] [ j + 1 ] , arr [ i ] [ j ] + dp [ 1 ] [ j + 2 ] )
    print ( max ( dp [ 0 ] [ 0 ] , dp [ 1 ] [ 0 ] ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 50 , 21 , 5 ] , [ 2 , 10 , 10 , 5 ] ]
    N = len ( arr [ 0 ] )
    maxSum ( arr , 2 , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maxSum ( arr , n ) :
    r1 = r2 = 0
    for i in range ( n ) :
        r1 , r2 = max ( r1 , r2 + arr [ 0 ] [ i ] ) , max ( r2 , r1 + arr [ 1 ] [ i ] )
    print ( max ( r1 , r2 ) )
arr = [ [ 1 , 50 , 21 , 5 ] , [ 2 , 10 , 10 , 5 ] ]
n = len ( arr [ 0 ] )
maxSum ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
mod = 1e9 + 7
mx = 1000000
fact = [ 0 ] * ( mx + 1 )
def Calculate_factorial ( ) :
    fact [ 0 ] = 1
    for i in range ( 1 , mx + 1 ) :
        fact [ i ] = i * fact [ i - 1 ]
        fact [ i ] %= mod
def UniModal_per ( a , b ) :
    res = 1
    while ( b != 0 ) :
        if ( b % 2 != 0 ) :
            res = res * a
        res %= mod
        a = a * a
        a %= mod
        b //= 2
    return res
def countPermutations ( n ) :
    Calculate_factorial ( )
    uni_modal = UniModal_per ( 2 , n - 1 )
    nonuni_modal = fact [ n ] - uni_modal
    print ( int ( uni_modal ) , " " , int ( nonuni_modal ) )
    return
N = 4
countPermutations ( N )

Index/key variables: i, n
Accumulator variables: a, b, res
Iterator variables: i
Python program:
MAX = 100
def largestSquare ( matrix , R , C , q_i , q_j , K , Q ) :
    for q in range ( Q ) :
        i = q_i [ q ]
        j = q_j [ q ]
        min_dist = min ( min ( i , j ) , min ( R - i - 1 , C - j - 1 ) )
        ans = - 1
        for k in range ( min_dist + 1 ) :
            count = 0
            for row in range ( i - k , i + k + 1 ) :
                for col in range ( j - k , j + k + 1 ) :
                    count += matrix [ row ] [ col ]
            if count > K :
                break
            ans = 2 * k + 1
        print ( ans )
matrix = [ [ 1 , 0 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 1 , 0 ] ]
K = 9
Q = 1
q_i = [ 1 ]
q_j = [ 2 ]
largestSquare ( matrix , 4 , 5 , q_i , q_j , K , Q )

Index/key variables: col, q, row
Accumulator variables: count
Iterator variables: col, k, q, row