dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findOriginalMatrix ( B , N , M ) :
    A = [ [ 0 ] * M ] * N
    for i in range ( N ) :
        for j in range ( M ) :
            A [ i ] [ j ] = 1
    for i in range ( N ) :
        for j in range ( M ) :
            if ( B [ i ] [ j ] == 0 ) :
                for k in range ( M ) :
                    A [ i ] [ k ] = 0
                for k in range ( N ) :
                    A [ k ] [ j ] = 0
    for i in range ( N ) :
        for j in range ( M ) :
            c = 0
            for k in range ( M ) :
                if ( c == 1 ) :
                    break
                c += A [ i ] [ k ]
            for k in range ( N ) :
                if ( c == 1 ) :
                    break
                c += A [ k ] [ j ]
            if ( c != B [ i ] [ j ] ) :
                print ( " Not ▁ Possible " )
                return
    for i in range ( N ) :
        for j in range ( M ) :
            print ( A [ i ] [ j ] , end = " ▁ " )
        print ( )
B = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ]
N = len ( B )
M = len ( B [ 0 ] )
findOriginalMatrix ( B , N , M )

Index/key variables: i, j, k
Accumulator variables: c
Iterator variables: i, j, k
Python program:
import math
mod = 1000000007 ;
def power ( a , n , d ) :
    res = 1 ;
    while ( n != 0 ) :
        if ( ( n % 2 ) != 0 ) :
            res = ( ( res % d ) * ( a % d ) ) % d ;
        a = ( ( a % d ) * ( a % d ) ) % d ;
        n /= 2 ;
    return res ;
def gcd ( p , q , n ) :
    if ( p == q ) :
        return ( power ( p , n , mod ) + power ( q , n , mod ) ) % mod ;
    candidate = 1 ;
    num = p - q ;
    sq = ( int ) ( math . sqrt ( num ) ) ;
    for i in range ( 1 , sq ) :
        if ( num % i == 0 ) :
            X = power ( p , n , i ) ;
            Y = power ( q , n , i ) ;
            temp = ( X + Y ) % i ;
            if ( temp == 0 ) :
                candidate = max ( candidate , i ) ;
            temp = ( power ( p , n , num / i ) + power ( q , n , num / i ) ) % ( num / i ) ;
            if ( temp == 0 ) :
                candidate = max ( candidate , num / i ) ;
    return candidate % mod ;
if __name__ == ' _ _ main _ _ ' :
    p = 10 ;
    q = 6 ;
    n = 5 ;
    print ( ( int ) ( gcd ( p , q , n ) ) ) ;

Accumulator variables: n
Iterator variables: i
Python program:
def findPoint ( n , h ) :
    for i in range ( 1 , n ) :
        print ( " { 0 : . 2f } " . format ( ( ( i / n ) ** 0.5 ) * h ) , end = ' ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    n = 3
    h = 2
    findPoint ( n , h )

Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def calculateK ( x , y ) :
    g = gcd ( x , y )
    n = y // g
    res = n
    i = 2
    while i * i <= n :
        if ( n % i == 0 ) :
            res -= ( res // i )
            while ( n % i == 0 ) :
                n //= i
        i += 1
    if ( n != 1 ) :
        res -= ( res // n )
    return res
if __name__ == " _ _ main _ _ " :
    x = 3
    y = 15
    print ( calculateK ( x , y ) )

Accumulator variables: i, n, res
Python program:
import math
def nearestPowerOfTwo ( arr , N ) :
    for i in range ( N ) :
        lg = ( int ) ( math . log2 ( arr [ i ] ) )
        a = ( int ) ( math . pow ( 2 , lg ) )
        b = ( int ) ( math . pow ( 2 , lg + 1 ) )
        if ( ( arr [ i ] - a ) < ( b - arr [ i ] ) ) :
            print ( a , end = " ▁ " )
        else :
            print ( b , end = " ▁ " )
arr = [ 5 , 2 , 7 , 12 ]
N = len ( arr )
nearestPowerOfTwo ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
import math
def countSetBits ( n ) :
    count = 0
    while ( n != 0 ) :
        n &= ( n - 1 )
        count += 1
    return count
def invertBits ( n ) :
    x = ( int ) ( math . log ( n ) / math . log ( 2 ) )
    m = 1 << x
    m = m | m - 1
    n = n ^ m
    return n
def invertSum ( A , B ) :
    temp = countSetBits ( A ) + countSetBits ( B )
    print ( invertBits ( temp ) )
A = 5
B = 7
invertSum ( A , B )

Accumulator variables: count, n
Python program:
def XOR_for_every_i ( A , N ) :
    frequency_of_bits = [ 0 ] * 32
    for i in range ( N ) :
        bit_position = 0
        M = A [ i ]
        while ( M ) :
            if ( M & 1 != 0 ) :
                frequency_of_bits [ bit_position ] += 1
            bit_position += 1
            M >>= 1
    for i in range ( N ) :
        M = A [ i ]
        value_at_that_bit = 1
        XOR_sum = 0
        for bit_position in range ( 32 ) :
            if ( M & 1 != 0 ) :
                XOR_sum += ( ( N - frequency_of_bits [ bit_position ] ) * value_at_that_bit )
            else :
                XOR_sum += ( ( frequency_of_bits [ bit_position ] ) * value_at_that_bit )
            M >>= 1
            value_at_that_bit <<= 1
        print ( XOR_sum , end = " ▁ " )
    return
A = [ 1 , 2 , 3 ]
N = len ( A )
XOR_for_every_i ( A , N )

Index/key variables: bit_position, i
Accumulator variables: M, XOR_sum, value_at_that_bit
Iterator variables: bit_position, i
Python program:
def minimumMaxDiff ( nums ) :
    s = { }
    for i in range ( len ( nums ) ) :
        if ( nums [ i ] % 2 == 0 ) :
            s [ nums [ i ] ] = 1
        else :
            s [ nums [ i ] * 2 ] = 1
    sr = list ( s . keys ( ) )
    res = sr [ - 1 ] - sr [ 0 ]
    while ( list ( s . keys ( ) ) [ - 1 ] % 2 == 0 ) :
        r = list ( s . keys ( ) )
        x = r [ - 1 ]
        del s [ x ]
        s [ x // 2 ] = 1
        rr = list ( s . keys ( ) )
        res = min ( res , rr [ - 1 ] - r [ 0 ] )
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 5 , 9 ]
    print ( minimumMaxDiff ( arr ) )

Index/key variables: i, x
Iterator variables: i
Python program:
from math import floor , log10
M = 3
N = 3
def countDigit ( arr ) :
    for i in range ( M ) :
        for j in range ( N ) :
            X = arr [ i ] [ j ]
            d = floor ( log10 ( X ) * 1.0 ) + 1
            print ( d , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 27 , 173 , 5 ] , [ 21 , 6 , 624 ] , [ 5 , 321 , 49 ] ]
    countDigit ( arr )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findSum ( arr , N ) :
    mp = { }
    for i in range ( 0 , N ) :
        if arr [ i ] in mp :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    sum_odd , sum_even = 0 , 0
    for itr in mp :
        if ( mp [ itr ] % 2 != 0 ) :
            sum_odd += ( itr ) * ( mp [ itr ] )
        if ( mp [ itr ] % 2 == 0 ) :
            sum_even += ( itr ) * ( mp [ itr ] )
    diff = sum_even - sum_odd
    return diff
arr = [ 1 , 5 , 5 , 2 , 4 , 3 , 3 ]
N = len ( arr )
print ( findSum ( arr , N ) )

Index/key variables: i, itr
Accumulator variables: sum_even, sum_odd
Iterator variables: i, itr
Python program:
def noOfArraysPossible ( N , M ) :
    ans = 1
    for i in range ( N ) :
        ans = ans * ( M - i )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    N = 2
    M = 3
    noOfArraysPossible ( N , M )

Iterator variables: i
Python program:
def next_permutation ( a ) :
    for i in reversed ( range ( len ( a ) - 1 ) ) :
        if a [ i ] < a [ i + 1 ] :
            break
    else :
        return False
    j = next ( j for j in reversed ( range ( i + 1 , len ( a ) ) ) if a [ i ] < a [ j ] )
    a [ i ] , a [ j ] = a [ j ] , a [ i ]
    a [ i + 1 : ] = reversed ( a [ i + 1 : ] )
    return True
def printPermutation ( arr , n , k ) :
    flag = False
    arr . sort ( )
    while True :
        sum = 0
        for i in range ( n - 1 ) :
            sum += arr [ i ] & arr [ i + 1 ]
        if ( sum >= k ) :
            flag = True
            for i in range ( n ) :
                print ( arr [ i ] , end = " ▁ " )
            print ( )
        if ( next_permutation ( arr ) == False ) :
            break
    if ( flag == False ) :
        print ( " - 1" )
arr = [ 1 , 2 , 3 , 4 , 5 ]
K = 8
N = len ( arr )
printPermutation ( arr , N , K )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i
Boolean variables: flag
Python program:
def findMissingNumbers ( arr , n ) :
    M = 15
    bset = [ 0 ] * M
    for i in range ( M ) :
        bset [ i ] = i
    for i in range ( n ) :
        bset [ arr [ i ] - 1 ] = 0
    bset = [ i for i in bset if i != 0 ]
    for i in range ( len ( bset ) ) :
        if ( bset [ i ] + 1 > n ) :
            break
        print ( bset [ i ] + 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 6 , 8 , 9 ]
    n = len ( arr )
    findMissingNumbers ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def findSum ( a , b , N ) :
    if N == 1 :
        print ( a )
        return
    s = a + b
    for i in range ( 0 , N - 2 ) :
        x = a ^ b
        s += x
        a = b
        b = x
    print ( s )
    return
if __name__ == ' _ _ main _ _ ' :
    a = 2
    b = 5
    N = 8
    findSum ( a , b , N )

Accumulator variables: s
Iterator variables: i
Python program:
def LongestLenXORK ( arr , N , K ) :
    prefixXOR = 0
    maxLen = 0
    mp = { }
    mp [ 0 ] = - 1
    for i in range ( N ) :
        prefixXOR ^= arr [ i ]
        if ( prefixXOR ^ K ) in mp :
            maxLen = max ( maxLen , ( i - mp [ prefixXOR ^ K ] ) )
        else :
            mp [ prefixXOR ] = i
    return maxLen
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 7 , 2 ]
    N = len ( arr )
    K = 1
    print ( LongestLenXORK ( arr , N , K ) )

Index/key variables: i, prefixXOR
Iterator variables: i
Python program:
N = 3
M = 3
def intializeDiff ( D , A ) :
    for i in range ( N ) :
        D [ i ] [ 0 ] = A [ i ] [ 0 ] ;
        D [ i ] [ M ] = 0 ;
    for i in range ( N ) :
        for j in range ( 1 , M ) :
            D [ i ] [ j ] = A [ i ] [ j ] - A [ i ] [ j - 1 ] ;
def update ( D , k , r1 , c1 , r2 , c2 ) :
    for i in range ( r1 , r2 + 1 ) :
        D [ i ] [ c1 ] += k ;
        D [ i ] [ c2 + 1 ] -= k ;
def printArray ( A , D ) :
    for i in range ( N ) :
        for j in range ( M ) :
            if ( j == 0 ) :
                A [ i ] [ j ] = D [ i ] [ j ] ;
            else :
                A [ i ] [ j ] = D [ i ] [ j ] + A [ i ] [ j - 1 ] ;
            print ( A [ i ] [ j ] , end = ' ▁ ' )
        print ( )
def performQueries ( A , Queries ) :
    D = [ [ 0 for j in range ( M + 1 ) ] for i in range ( N ) ]
    intializeDiff ( D , A ) ;
    Q = len ( Queries )
    for i in range ( Q ) :
        update ( D , Queries [ i ] [ 0 ] , Queries [ i ] [ 1 ] , Queries [ i ] [ 2 ] , Queries [ i ] [ 3 ] , Queries [ i ] [ 4 ] ) ;
    printArray ( A , D ) ;
if __name__ == ' _ _ main _ _ ' :
    A = [ [ 1 , 2 , 3 ] , [ 1 , 1 , 0 ] , [ 4 , - 2 , 2 ] ] ;
    Queries = [ [ 2 , 0 , 0 , 1 , 1 ] , [ - 1 , 1 , 0 , 2 , 2 ] ] ;
    performQueries ( A , Queries ) ;

Index/key variables: M, c1, i, j
Iterator variables: i, j
Python program:
import math
def onesComplement ( n , maxElement ) :
    bits = math . floor ( math . log2 ( maxElement ) ) + 1
    return ( ( 1 << bits ) - 1 ) ^ n
def findNumber ( arr , n ) :
    res = 0
    maxElement = 0
    for i in range ( n ) :
        res = res ^ arr [ i ]
        if ( maxElement < arr [ i ] ) :
            maxElement = arr [ i ]
    res = onesComplement ( res , maxElement )
    return ( res )
arr = [ 1 , 2 , 3 , 4 , 5 ]
N = len ( arr )
print ( findNumber ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def calculateFactorial ( N ) :
    fact = [ 0 ] * ( N + 1 )
    fact [ 0 ] = 1
    for i in range ( 1 , N + 1 ) :
        fact [ i ] = fact [ i - 1 ] * i
    return fact
def cntWaysSelection ( arr , N , K , L , R ) :
    cntWays = 0
    cntNum = 0
    for i in range ( 0 , N ) :
        if ( arr [ i ] >= L and arr [ i ] <= R ) :
            cntNum += 1
    fact = list ( calculateFactorial ( cntNum ) )
    for i in range ( K , cntNum + 1 ) :
        cntWays += fact [ cntNum ] // ( fact [ i ] * fact [ cntNum - i ] )
    return cntWays
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 4 , 6 , 13 , 5 , 10 ]
    N = len ( arr )
    K = 3
    L = 4
    R = 10
    print ( cntWaysSelection ( arr , N , K , L , R ) )

Index/key variables: cntNum, i
Accumulator variables: cntWays
Iterator variables: i
Python program:
def TotalAndPair ( arr , N ) :
    totalAND = ( 1 << 30 ) - 1
    for i in range ( N ) :
        for j in range ( i + 1 , N ) :
            totalAND &= ( arr [ i ] & arr [ j ] )
    return totalAND
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 5 , 12 , 15 ]
    N = len ( arr )
    print ( TotalAndPair ( arr , N ) )

Index/key variables: i, j
Accumulator variables: totalAND
Iterator variables: i, j
Python program:
import math
def smallestDivisorGr1 ( N ) :
    for i in range ( 2 , int ( math . sqrt ( N ) ) + 1 ) :
        if ( N % i == 0 ) :
            return i
    return N
def findValOfNWithOperat ( N , K ) :
    for i in range ( 1 , K + 1 ) :
        N += smallestDivisorGr1 ( N )
    return N
if __name__ == " _ _ main _ _ " :
    N = 6
    K = 4
    print ( findValOfNWithOperat ( N , K ) )

Accumulator variables: N
Iterator variables: i
Python program:
M = 1000000007
def findTripleSum ( A , B , C ) :
    sum = 0
    for i in range ( 1 , A + 1 ) :
        for j in range ( 1 , B + 1 ) :
            for k in range ( 1 , C + 1 ) :
                prod = ( ( ( i % M ) * ( j % M ) ) % M * ( k % M ) ) % M
                sum = ( sum + prod ) % M
    return sum
if __name__ == ' _ _ main _ _ ' :
    A = 10
    B = 100
    C = 1000
    print ( findTripleSum ( A , B , C ) )

Iterator variables: i, j, k
Python program:
import sys
def getMaximum ( N , M , mat ) :
    global_max = - 1 * ( sys . maxsize )
    for i in range ( 0 , N ) :
        for j in range ( i + 1 , N ) :
            row_min = sys . maxsize
            for k in range ( 0 , M ) :
                m = max ( mat [ i ] [ k ] , mat [ j ] [ k ] )
                row_min = min ( row_min , m )
            global_max = max ( global_max , row_min )
    return global_max
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 5 , 0 , 3 , 1 , 2 ] , [ 1 , 8 , 9 , 1 , 3 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 9 , 1 , 0 , 3 , 7 ] , [ 2 , 3 , 0 , 6 , 3 ] , [ 6 , 4 , 1 , 7 , 0 ] ]
    N = 6
    M = 5
    print ( getMaximum ( N , M , mat ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def makeTree ( tree , edges , N ) :
    for i in range ( N - 1 ) :
        u = edges [ i ] [ 0 ]
        v = edges [ i ] [ 1 ]
        tree [ u ] . append ( v )
    return tree
def dfs ( node , tree ) :
    mex = 0
    size = 1
    for u in tree [ node ] :
        temp = dfs ( u , tree )
        mex = max ( mex , temp [ 0 ] )
        size += temp [ 1 ]
    return [ mex + size , size ]
if __name__ == ' _ _ main _ _ ' :
    N = 7
    edges = [ [ 1 , 4 ] , [ 1 , 5 ] , [ 5 , 2 ] , [ 5 , 3 ] , [ 4 , 7 ] , [ 7 , 6 ] ]
    tree = [ [ ] for i in range ( N + 1 ) ]
    tree = makeTree ( tree , edges , N )
    print ( dfs ( 1 , tree ) [ 0 ] )

Index/key variables: i, node, u
Accumulator variables: size
Iterator variables: i, u
Python program:
def divisorCount ( n ) :
    x = 0 ;
    for i in range ( 1 , n ) :
        if ( n % i == 0 ) :
            if ( i == n // i ) :
                x += 1 ;
            else :
                x += 2 ;
        if ( i * i > n ) :
            break ;
    return x ;
def minvalue_y ( x ) :
    a = divisorCount ( x ) ;
    y = x + 1 ;
    while ( ( a & 1 ) == ( divisorCount ( y ) & 1 ) ) :
        y += 1 ;
    return y ;
if __name__ == ' _ _ main _ _ ' :
    x = 5 ;
    print ( minvalue_y ( x ) ) ;

Accumulator variables: x, y
Iterator variables: i
Python program:
def minStartValue ( nums ) :
    minValue = 0
    sum = 0
    for i in range ( len ( nums ) ) :
        sum += nums [ i ]
        minValue = min ( minValue , sum )
    startValue = 1 - minValue
    return startValue
if __name__ == ' _ _ main _ _ ' :
    nums = [ - 3 , 2 , - 3 , 4 , 2 ]
    print ( minStartValue ( nums ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def countSubArrayRemove ( arr , N ) :
    prefix_element_count = { }
    suffix_element_count = { }
    total_sum_of_elements = 0
    i = N - 1
    while ( i >= 0 ) :
        total_sum_of_elements += arr [ i ]
        suffix_element_count [ arr [ i ] ] = suffix_element_count . get ( arr [ i ] , 0 ) + 1
        i -= 1
    prefix_sum = 0
    suffix_sum = 0
    count_subarray_equal_sum = 0
    for i in range ( N ) :
        prefix_sum += arr [ i ]
        prefix_element_count [ arr [ i ] ] = prefix_element_count . get ( arr [ i ] , 0 ) + 1
        suffix_sum = total_sum_of_elements - prefix_sum
        suffix_element_count [ arr [ i ] ] = suffix_element_count . get ( arr [ i ] , 0 ) - 1
        difference = prefix_sum - suffix_sum
        number_of_subarray_at_i_split = ( prefix_element_count . get ( difference , 0 ) + suffix_element_count . get ( - difference , 0 ) )
        count_subarray_equal_sum += number_of_subarray_at_i_split
    return count_subarray_equal_sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 1 , 3 , 1 ]
    N = len ( arr )
    print ( countSubArrayRemove ( arr , N ) )

Index/key variables: i
Accumulator variables: count_subarray_equal_sum, prefix_sum, total_sum_of_elements
Iterator variables: i
Python program:
def countXORSetBitsAdjElemRange1_N ( N ) :
    total_set_bits = 0
    bit_Position = 1
    while ( N ) :
        total_set_bits += ( ( N + 1 ) // 2 * bit_Position )
        N -= ( N + 1 ) // 2
        bit_Position += 1
    return total_set_bits
if __name__ == ' _ _ main _ _ ' :
    N = 4
    print ( countXORSetBitsAdjElemRange1_N ( N ) )

Accumulator variables: N, bit_Position, total_set_bits
Python program:
from math import sqrt , floor , ceil
def checkPerfectSquare ( N ) :
    if ( N <= 0 ) :
        return 0
    sq = sqrt ( N )
    if ( floor ( sq ) == ceil ( sq ) ) :
        return 1
    return 0
def checktwoSidesareRighTriangle ( A , B ) :
    checkTriangle = False
    if ( checkPerfectSquare ( A * A + B * B ) ) :
        checkTriangle = True
    if ( checkPerfectSquare ( A * A - B * B ) ) :
        checkTriangle = True
    if ( checkPerfectSquare ( B * B - A * A ) ) :
        checkTriangle = True
    return checkTriangle
if __name__ == ' _ _ main _ _ ' :
    A = 3
    B = 4
    if ( checktwoSidesareRighTriangle ( A , B ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Boolean variables: checkTriangle
Python program:
def array_sum ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    return sum
def countOperations ( arr , N ) :
    count_zeros = 0
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            count_zeros += 1
    sum = array_sum ( arr , N )
    if ( count_zeros ) :
        return count_zeros
    if ( sum == 0 ) :
        return 1
    return 0
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 1 , - 1 , 0 , 0 ]
    N = len ( arr )
    print ( countOperations ( arr , N ) )

Index/key variables: i
Accumulator variables: count_zeros, sum
Iterator variables: i
Python program:
def TotalBitwiseORPair ( arr , N ) :
    totalOR = 0 ;
    for i in range ( N ) :
        totalOR |= arr [ i ] ;
    return totalOR ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 5 , 12 , 15 ] ;
    N = len ( arr ) ;
    print ( TotalBitwiseORPair ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: totalOR
Iterator variables: i
Python program:
def findDifference ( p , q , N ) :
    A = [ 0 ] * N
    for i in range ( N ) :
        A [ i ] = i + 1
    IsCorrect = False
    a , b = 1 , 1
    while True :
        IsCorrect = True
        for i in range ( N ) :
            if ( A [ i ] != p [ i ] ) :
                IsCorrect = False
                break
        if ( IsCorrect ) :
            break
        a += 1
        if ( not next_permutation ( A ) ) :
            break
    for i in range ( N ) :
        A [ i ] = i + 1
    while True :
        IsCorrect = True
        for i in range ( N ) :
            if ( A [ i ] != q [ i ] ) :
                IsCorrect = False
                break
        if ( IsCorrect ) :
            break
        b += 1
        if ( not next_permutation ( A ) ) :
            break
    print ( abs ( a - b ) )
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
p = [ 1 , 3 , 2 ]
q = [ 3 , 1 , 2 ]
n = len ( p )
findDifference ( p , q , n )

Index/key variables: a, b, i
Iterator variables: a, i
Boolean variables: IsCorrect
Python program:
def printFinalArray ( a , n , operations , p , capacity ) :
    curr = 0
    picked = False
    for i in range ( p ) :
        s = operations [ i ]
        flag = False
        if ( curr != 0 ) :
            curr -= 1
            break
        if ( curr != n - 1 ) :
            curr += 1
            break
        if ( picked == False and a [ curr ] != 0 ) :
            picked = True
            a [ curr ] -= 1
            break
        if ( picked == True and a [ curr ] != capacity ) :
            picked = False
            a [ curr ] += 1
            break
        else :
            flag = True
        if ( flag == True ) :
            break
    for i in range ( n ) :
        print ( a [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    capacity = 5
    a = [ 2 , 5 , 2 ]
    N = len ( a )
    operations = [ 3 , 2 , 4 , 1 , 4 , 5 ]
    M = len ( operations )
    printFinalArray ( a , N , operations , M , capacity )

Index/key variables: curr, i
Iterator variables: i
Boolean variables: flag, picked
Python program:
import math
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 ( math . sqrt ( n ) + 1 ) , 6 ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
    return True
def CheckSumPrime ( A , N ) :
    sum = 0
    for i in range ( 0 , N ) :
        s = str ( A [ i ] )
        sum += len ( s )
    if ( isPrime ( sum ) == True ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 11 , 12 ]
    N = len ( A )
    CheckSumPrime ( A , N )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def checkPalindrome ( N ) :
    rev = 0
    temp = N
    while ( N != 0 ) :
        rev = rev * 10 + N % 10
        N = N // 10
    N = temp
    if ( N == rev ) :
        return True
    return False
def closestSmallerPalindrome ( N ) :
    while N >= 0 and not checkPalindrome ( N ) :
        N -= 1
    return N
if __name__ == ' _ _ main _ _ ' :
    N = 4000
    print ( closestSmallerPalindrome ( N ) )

Accumulator variables: N
Python program:
def MinimumOperationReq ( N ) :
    cntDecr = 0 ;
    temp = N ;
    while ( temp > 0 ) :
        X = int ( pow ( temp , 1 / 2 ) )
        if ( X * X == temp ) :
            break ;
        temp = temp - 2 ;
        cntDecr += 1 ;
    cntIncr = 0 ;
    while ( True ) :
        X = int ( pow ( N , 1 / 2 ) )
        if ( X * X == N ) :
            break ;
        N = N + 2 ;
        cntIncr += 1 ;
    return min ( cntIncr , cntDecr ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 15 ;
    print ( MinimumOperationReq ( N ) ) ;

Accumulator variables: cntDecr, cntIncr
Python program:
def add ( arr , x ) :
    arr . append ( x )
def update ( effect , x ) :
    effect = effect ^ x
    return effect
def computeResults ( arr , effect ) :
    for i in range ( len ( arr ) ) :
        arr [ i ] = arr [ i ] ^ effect
        print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 ]
    effect = 0
    add ( arr , 5 )
    effect = update ( effect , 2 )
    computeResults ( arr , effect )

Index/key variables: i
Iterator variables: i