dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def maxArrayCover ( a , n , x ) :
    a . sort ( )
    cc = 0
    s = 0
    for i in range ( n ) :
        s += a [ i ]
        if ( s > x ) :
            break
        cc += 1
    if ( sum ( a ) == x ) :
        return n
    else :
        if ( cc == n ) :
            return n - 1
        else :
            return cc
if __name__ == ' _ _ main _ _ ' :
    n , x = 3 , 70
    a = [ 10 , 20 , 30 ]
    print ( maxArrayCover ( a , n , x ) )

Index/key variables: i
Accumulator variables: cc, s
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
start = None
def isPairWiseSorted ( head ) :
    flag = True
    temp = head
    while ( temp != None and temp . next != None ) :
        if ( temp . data > temp . next . data ) :
            flag = False
            break
        temp = temp . next . next
    return flag
def push ( head_ref , new_data ) :
    global start
    new_node = Node ( 0 )
    new_node . data = new_data
    new_node . next = head_ref
    head_ref = new_node
    start = head_ref
start = None
push ( start , 5 )
push ( start , 1 )
push ( start , 9 )
push ( start , 9 )
push ( start , 15 )
push ( start , 10 )
if ( isPairWiseSorted ( start ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Boolean variables: flag
Class/struct names: Node
Python program:
def maximumSOP ( a , b ) :
    sop = 0
    n = len ( a )
    a . sort ( )
    b . sort ( )
    for i in range ( n ) :
        sop += a [ i ] * b [ i ]
    return sop
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 2 , 3 ]
    B = [ 4 , 5 , 1 ]
    print ( maximumSOP ( A , B ) )

Index/key variables: i
Accumulator variables: sop
Iterator variables: i
Python program:
def countTriplets ( arr , n , m ) :
    count = 0
    arr . sort ( )
    for end in range ( n - 1 , 1 , - 1 ) :
        start = 0
        mid = end - 1
        while ( start < mid ) :
            prod = ( arr [ end ] * arr [ start ] * arr [ mid ] )
            if ( prod > m ) :
                mid -= 1
            elif ( prod < m ) :
                start += 1
            elif ( prod == m ) :
                count += 1
                mid -= 1
                start += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 1 , 1 , 1 , 1 ]
    n = len ( arr )
    m = 1
    print ( countTriplets ( arr , n , m ) )

Index/key variables: end, mid, start
Accumulator variables: count
Iterator variables: end
Python program:
def distribution ( arr , n ) :
    resources = set ( )
    for i in range ( n ) :
        resources . add ( arr [ i ] ) ;
    return min ( len ( resources ) , n // 2 ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 1 , 3 , 4 ] ;
    n = len ( arr ) ;
    print ( distribution ( arr , n ) , " " ) ;

Index/key variables: i
Accumulator variables: resources
Iterator variables: i
Python program:
def sort3 ( arr ) :
    if ( arr [ 1 ] < arr [ 0 ] ) :
        arr [ 0 ] , arr [ 1 ] = arr [ 1 ] , arr [ 0 ]
    if ( arr [ 2 ] < arr [ 1 ] ) :
        arr [ 1 ] , arr [ 2 ] = arr [ 2 ] , arr [ 1 ]
        if ( arr [ 1 ] < arr [ 0 ] ) :
            arr [ 1 ] , arr [ 0 ] = arr [ 0 ] , arr [ 1 ]
a = [ 10 , 12 , 5 ]
sort3 ( a )
for i in range ( 3 ) :
    print ( a [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def merge ( arr , beg , mid , end , maxele ) :
    i = beg
    j = mid + 1
    k = beg
    while ( i <= mid and j <= end ) :
        if ( arr [ i ] % maxele <= arr [ j ] % maxele ) :
            arr [ k ] = arr [ k ] + ( arr [ i ] % maxele ) * maxele
            k += 1
            i += 1
        else :
            arr [ k ] = arr [ k ] + ( arr [ j ] % maxele ) * maxele
            k += 1
            j += 1
    while ( i <= mid ) :
        arr [ k ] = arr [ k ] + ( arr [ i ] % maxele ) * maxele
        k += 1
        i += 1
    while ( j <= end ) :
        arr [ k ] = arr [ k ] + ( arr [ j ] % maxele ) * maxele
        k += 1
        j += 1
    for i in range ( beg , end + 1 ) :
        arr [ i ] = arr [ i ] // maxele
def mergeSortRec ( arr , beg , end , maxele ) :
    if ( beg < end ) :
        mid = ( beg + end ) // 2
        mergeSortRec ( arr , beg , mid , maxele )
        mergeSortRec ( arr , mid + 1 , end , maxele )
        merge ( arr , beg , mid , end , maxele )
def mergeSort ( arr , n ) :
    maxele = max ( arr ) + 1
    mergeSortRec ( arr , 0 , n - 1 , maxele )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 999 , 612 , 589 , 856 , 56 , 945 , 243 ]
    n = len ( arr )
    mergeSort ( arr , n )
    print ( " Sorted ▁ array " )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j, k
Iterator variables: i
Python program:
def printTriplets ( arr , n , sum ) :
    arr . sort ( )
    for i in range ( n - 2 ) :
        ( j , k ) = ( i + 1 , n - 1 )
        while ( j < k ) :
            if ( arr [ i ] + arr [ j ] + arr [ k ] >= sum ) :
                k -= 1
            else :
                for x in range ( j + 1 , k + 1 ) :
                    print ( str ( arr [ i ] ) + " , ▁ " + str ( arr [ j ] ) + " , ▁ " + str ( arr [ x ] ) )
                j += 1
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 1 , 3 , 4 , 7 ]
    n = len ( arr )
    sum = 12
    printTriplets ( arr , n , sum ) ;

Index/key variables: i, j, k, x
Iterator variables: i, x
Python program:
def printSorted ( s , l ) :
    stack = [ ]
    tempstack = [ ]
    stack . append ( s [ 0 ] )
    for i in range ( 1 , l ) :
        a = ord ( s [ i ] )
        b = ord ( stack [ - 1 ] )
        if ( ( a - b ) >= 1 or ( a == b ) ) :
            stack . append ( s [ i ] )
        elif ( ( b - a ) >= 1 ) :
            while ( ( b - a ) >= 1 ) :
                tempstack . append ( stack . pop ( ) )
                if ( len ( stack ) > 0 ) :
                    b = ord ( stack [ - 1 ] )
                else :
                    break
            stack . append ( s [ i ] )
            while ( len ( tempstack ) > 0 ) :
                stack . append ( tempstack . pop ( ) )
    print ( ' ' . join ( stack ) )
s = " geeksforgeeks "
l = len ( s )
printSorted ( s , l )

Index/key variables: i
Accumulator variables: stack, tempstack
Iterator variables: i
Python program:
def checkFittingArrays ( A , B , N ) :
    A = sorted ( A )
    B = sorted ( B )
    for i in range ( N ) :
        if ( A [ i ] > B [ i ] ) :
            return False
    return True
A = [ 7 , 5 , 3 , 2 ]
B = [ 5 , 4 , 8 , 7 ]
N = len ( A )
if ( checkFittingArrays ( A , B , N ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Iterator variables: i
Python program:
def maximum_toys ( cost , N , K ) :
    count = 0
    sum = 0
    cost . sort ( reverse = False )
    for i in range ( 0 , N , 1 ) :
        if ( sum + cost [ i ] <= K ) :
            sum = sum + cost [ i ]
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    K = 50
    cost = [ 1 , 12 , 5 , 111 , 200 , 1000 , 10 , 9 , 12 , 15 ]
    N = len ( cost )
    print ( maximum_toys ( cost , N , K ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
import math
def printVector ( V ) :
    for i in V :
        print ( i , end = " ▁ " )
    print ( " ▁ " )
def insertionSortRecursive ( V , N ) :
    if ( N <= 1 ) :
        return 0
    insertionSortRecursive ( V , N - 1 )
    j = N - 1
    while ( j > 0 and V [ j ] < V [ j - 1 ] ) :
        temp = V [ j ] ;
        V [ j ] = V [ j - 1 ] ;
        V [ j - 1 ] = temp ;
        j -= 1
A = [ 9 , 8 , 7 , 5 , 2 , 1 , 2 , 3 ]
n = len ( A )
print ( " Array " )
printVector ( A )
print ( " After ▁ Sorting ▁ : " )
insertionSortRecursive ( A , n )
printVector ( A )

Index/key variables: j
Iterator variables: i
Python program:
def almostSort ( A , n ) :
    i = 0
    while i < n - 1 :
        if A [ i ] > A [ i + 1 ] :
            A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]
            i += 1
        i += 1
    for i in range ( 0 , n - 1 ) :
        if A [ i ] > A [ i + 1 ] :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 3 , 2 , 4 , 6 , 5 ]
    n = len ( A )
    if almostSort ( A , n ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def nextGap ( gap ) :
    if ( gap <= 1 ) :
        return 0
    return ( gap // 2 ) + ( gap % 2 )
def merge ( arr1 , arr2 , n , m ) :
    gap = n + m
    gap = nextGap ( gap )
    while gap > 0 :
        i = 0
        while i + gap < n :
            if ( arr1 [ i ] > arr1 [ i + gap ] ) :
                arr1 [ i ] , arr1 [ i + gap ] = arr1 [ i + gap ] , arr1 [ i ]
            i += 1
        j = gap - n if gap > n else 0
        while i < n and j < m :
            if ( arr1 [ i ] > arr2 [ j ] ) :
                arr1 [ i ] , arr2 [ j ] = arr2 [ j ] , arr1 [ i ]
            i += 1
            j += 1
        if ( j < m ) :
            j = 0
            while j + gap < m :
                if ( arr2 [ j ] > arr2 [ j + gap ] ) :
                    arr2 [ j ] , arr2 [ j + gap ] = arr2 [ j + gap ] , arr2 [ j ]
                j += 1
        gap = nextGap ( gap )
if __name__ == " _ _ main _ _ " :
    a1 = [ 10 , 27 , 38 , 43 , 82 ]
    a2 = [ 3 , 9 ]
    n = len ( a1 )
    m = len ( a2 )
    merge ( a1 , a2 , n , m )
    print ( " First ▁ Array : ▁ " , end = " " )
    for i in range ( n ) :
        print ( a1 [ i ] , end = " ▁ " )
    print ( )
    print ( " Second ▁ Array : ▁ " , end = " " )
    for i in range ( m ) :
        print ( a2 [ i ] , end = " ▁ " )
    print ( )

Index/key variables: i, j
Iterator variables: i
Python program:
def mergeArrays ( arr1 , arr2 , n1 , n2 ) :
    arr3 = [ None ] * ( n1 + n2 )
    i = 0
    j = 0
    k = 0
    while i < n1 and j < n2 :
        if arr1 [ i ] < arr2 [ j ] :
            arr3 [ k ] = arr1 [ i ]
            k = k + 1
            i = i + 1
        else :
            arr3 [ k ] = arr2 [ j ]
            k = k + 1
            j = j + 1
    while i < n1 :
        arr3 [ k ] = arr1 [ i ] ;
        k = k + 1
        i = i + 1
    while j < n2 :
        arr3 [ k ] = arr2 [ j ] ;
        k = k + 1
        j = j + 1
    print ( " Array ▁ after ▁ merging " )
    for i in range ( n1 + n2 ) :
        print ( str ( arr3 [ i ] ) , end = " ▁ " )
arr1 = [ 1 , 3 , 5 , 7 ]
n1 = len ( arr1 )
arr2 = [ 2 , 4 , 6 , 8 ]
n2 = len ( arr2 )
mergeArrays ( arr1 , arr2 , n1 , n2 ) ;

Index/key variables: i, j, k
Iterator variables: i
Python program:
def sortSquare ( arr , n ) :
    for i in range ( n ) :
        arr [ i ] = arr [ i ] * arr [ i ]
    arr . sort ( )
arr = [ - 6 , - 3 , - 1 , 2 , 4 , 5 ]
n = len ( arr )
print ( " Before ▁ sort " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )
print ( " " )
sortSquare ( arr , n )
print ( " After ▁ sort " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def mergeTwoHalf ( A , n ) :
    half_i = 0
    temp = [ 0 for i in range ( n ) ]
    for i in range ( n - 1 ) :
        if ( A [ i ] > A [ i + 1 ] ) :
            half_i = i + 1
            break
    if ( half_i == 0 ) :
        return
    i = 0
    j = half_i
    k = 0
    while ( i < half_i and j < n ) :
        if ( A [ i ] < A [ j ] ) :
            temp [ k ] = A [ i ]
            k += 1
            i += 1
        else :
            temp [ k ] = A [ j ]
            k += 1
            j += 1
    while i < half_i :
        temp [ k ] = A [ i ]
        k += 1
        i += 1
    while ( j < n ) :
        temp [ k ] = A [ j ]
        k += 1
        j += 1
    for i in range ( n ) :
        A [ i ] = temp [ i ]
A = [ 2 , 3 , 8 , - 1 , 7 , 10 ]
n = len ( A )
mergeTwoHalf ( A , n )
print ( * A , sep = ' ▁ ' )

Index/key variables: i, j, k
Iterator variables: i
Python program:
def findMinDiff ( arr , n , m ) :
    if ( m == 0 or n == 0 ) :
        return 0
    arr . sort ( )
    if ( n < m ) :
        return - 1
    min_diff = arr [ n - 1 ] - arr [ 0 ]
    for i in range ( len ( arr ) - m + 1 ) :
        min_diff = min ( min_diff , arr [ i + m - 1 ] - arr [ i ] )
    return min_diff
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 4 , 7 , 9 , 2 , 23 , 25 , 41 , 30 , 40 , 28 , 42 , 30 , 44 , 48 , 43 , 50 ]
    n = len ( arr )
    print ( " Minimum ▁ difference ▁ is " , findMinDiff ( arr , n , m ) )

Index/key variables: i
Iterator variables: i
Python program:
def distinctCount ( arr , n ) :
    s = set ( )
    for i in range ( n ) :
        s . add ( abs ( arr [ i ] ) )
    return len ( s )
arr = [ - 2 , - 1 , 0 , 1 , 1 ]
n = len ( arr )
print ( " Count ▁ of ▁ absolute ▁ distinct ▁ values : " , distinctCount ( arr , n ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def distinctCount ( arr , n ) :
    count = n ;
    i = 0 ; j = n - 1 ; sum = 0 ;
    while ( i < j ) :
        while ( i != j and arr [ i ] == arr [ i + 1 ] ) :
            count = count - 1 ;
            i = i + 1 ;
        while ( i != j and arr [ j ] == arr [ j - 1 ] ) :
            count = count - 1 ;
            j = j - 1 ;
        if ( i == j ) :
            break ;
        sum = arr [ i ] + arr [ j ] ;
        if ( sum == 0 ) :
            count = count - 1 ;
            i = i + 1 ;
            j = j - 1 ;
        elif ( sum < 0 ) :
            i = i + 1 ;
        else :
            j = j - 1 ;
    return count ;
arr = [ - 2 , - 1 , 0 , 1 , 1 ] ;
n = len ( arr ) ;
print ( " Count ▁ of ▁ absolute ▁ distinct ▁ values ▁ : ▁ " , distinctCount ( arr , n ) ) ;

Index/key variables: i, j
Python program:
def flip ( arr , i ) :
    start = 0
    while start < i :
        temp = arr [ start ]
        arr [ start ] = arr [ i ]
        arr [ i ] = temp
        start += 1
        i -= 1
def findMax ( arr , n ) :
    mi = 0
    for i in range ( 0 , n ) :
        if arr [ i ] > arr [ mi ] :
            mi = i
    return mi
def pancakeSort ( arr , n ) :
    curr_size = n
    while curr_size > 1 :
        mi = findMax ( arr , curr_size )
        if mi != curr_size - 1 :
            flip ( arr , mi )
            flip ( arr , curr_size - 1 )
        curr_size -= 1
def printArray ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( " % d " % ( arr [ i ] ) , end = " ▁ " )
arr = [ 23 , 10 , 20 , 11 , 12 , 6 , 7 ]
n = len ( arr )
pancakeSort ( arr , n ) ;
print ( " Sorted ▁ Array ▁ " )
printArray ( arr , n )

Index/key variables: i, mi, start
Accumulator variables: curr_size
Iterator variables: i
Python program:
def check ( x , N ) :
    while True :
        N -= x
        if len ( str ( x ) ) == 1 :
            break
        x = sum ( list ( map ( int , str ( x ) ) ) )
    if len ( str ( x ) ) == 1 and N == 0 :
        return 1
    return 0
def countNoOfsuchX ( N ) :
    k = len ( str ( N ) )
    count = 0
    for x in range ( N - k * ( k + 1 ) * 5 , N + 1 ) :
        if check ( x , N ) :
            count += 1
    return count
N = 9939
print ( countNoOfsuchX ( N ) )

Accumulator variables: N, count
Iterator variables: x
Python program:
def find ( arr , N ) :
    Sum = sum ( arr )
    if Sum % N :
        return - 1
    else :
        k = Sum // N
        ans = 0
        i = 0
        while i < N :
            ans = ans + abs ( k - arr [ i ] )
            i += 1
        return ans // 2
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 4 , 1 , 10 ]
    N = len ( arr )
    print ( find ( arr , N ) )

Index/key variables: i
Python program:
def smallestNonSubsequence ( S , N ) :
    freq = 0
    for i in range ( N ) :
        if ( S [ i ] == ' a ' ) :
            freq += 1
    ans = " "
    for i in range ( freq ) :
        ans += ' a '
    if ( freq == N ) :
        ans = ans . replace ( ans [ freq - 1 ] , ' b ' )
    else :
        ans += ' a '
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = " abcdefghijklmnopqrstuvwxyz "
    N = len ( S )
    print ( smallestNonSubsequence ( S , N ) )

Index/key variables: i
Accumulator variables: ans, freq
Iterator variables: i
Python program:
Pi = 3.141592
def MaxBuildingsCovered ( arr , N , L ) :
    curr_sum = 0
    start = 0
    curr_count = 0
    max_count = 0
    for i in range ( N ) :
        curr_sum = curr_sum + ( arr [ i ] * Pi )
        if ( i != 0 ) :
            curr_sum += 1
        if ( curr_sum <= L ) :
            curr_count += 1
        elif ( curr_sum > L ) :
            curr_sum = curr_sum - ( arr [ start ] * Pi )
            curr_sum -= 1
            start += 1
            curr_count -= 1
        max_count = max ( curr_count , max_count )
    return max_count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 1 , 6 , 2 ]
    L = 24
    N = len ( arr )
    print ( MaxBuildingsCovered ( arr , N , L ) )

Index/key variables: i, start
Accumulator variables: curr_count, curr_sum
Iterator variables: i
Python program:
def countUnsetBits ( N ) :
    c = 0
    while ( N ) :
        if ( N % 2 == 0 ) :
            c += 1
        N = N >> 1
    return c
def countBitwiseZero ( N ) :
    unsetBits = countUnsetBits ( N )
    print ( ( 1 << unsetBits ) )
if __name__ == ' _ _ main _ _ ' :
    N = 9
    countBitwiseZero ( N )

Accumulator variables: c
Python program:
def isPossible ( s ) :
    n = len ( s )
    count_0 , count_1 = 0 , 0
    for i in range ( n ) :
        if ( s [ i ] == '0' ) :
            count_0 += 1
        else :
            count_1 += 1
        if ( count_1 > count_0 ) :
            return False
    if ( count_0 != ( 2 * count_1 ) ) :
        return False
    count_0 , count_1 = 0 , 0
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( s [ i ] == '0' ) :
            count_0 += 1
        else :
            count_1 += 1
        if ( count_1 > count_0 ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    s = "010100"
    if ( isPossible ( s ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: count_0, count_1
Iterator variables: i
Python program:
from collections import defaultdict
def leastBricks ( wall ) :
    map = defaultdict ( int )
    res = 0
    for list in wall :
        width = 0
        for i in range ( len ( list ) - 1 ) :
            width += list [ i ]
            map [ width ] += 1
            res = max ( res , map [ width ] )
    print ( len ( wall ) - res )
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 2 , 2 , 1 ] , [ 3 , 1 , 2 ] , [ 1 , 3 , 2 ] , [ 2 , 4 ] , [ 3 , 1 , 2 ] , [ 1 , 3 , 1 , 1 ] ]
    leastBricks ( arr )

Index/key variables: i, width
Iterator variables: i, list
Python program:
def MinimumOperations ( A , N , K ) :
    Count = 0
    i = 0
    while ( i < N - 1 ) :
        i = i + K - 1
        Count += 1
    return Count
if __name__ == ' _ _ main _ _ ' :
    A = [ 5 , 4 , 3 , 1 , 2 ]
    K = 3
    N = len ( A )
    print ( MinimumOperations ( A , N , K ) )

Accumulator variables: Count
Python program:
from math import sqrt
def is_prime ( n ) :
    if ( n == 1 ) :
        return False
    for i in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) :
        if ( n % i == 0 ) :
            return False
    return True
def consecutive_primes ( n ) :
    first = - 1
    second = - 1
    i = int ( sqrt ( n ) )
    while ( i >= 2 ) :
        if ( is_prime ( i ) ) :
            first = i
            break
        i -= 1
    for i in range ( int ( sqrt ( n ) ) + 1 , n // 2 + 1 , 1 ) :
        if ( is_prime ( i ) ) :
            second = i
            break
    if ( first * second >= n ) :
        print ( first , second )
    else :
        for i in range ( second + 1 , n + 1 , 1 ) :
            if ( is_prime ( i ) ) :
                print ( second , i )
                return
if __name__ == ' _ _ main _ _ ' :
    n = 14
    consecutive_primes ( n )

Iterator variables: i
Python program:
from collections import Counter
def construct_digits ( s ) :
    k = [ " z " , " w " , " u " , " x " , " g " , " h " , " o " , " f " , " v " , " i " ]
    l = [ " zero " , " two " , " four " , " six " , " eight " , " three " , " one " , " five " , " seven " , " nine " ]
    c = [ 0 , 2 , 4 , 6 , 8 , 3 , 1 , 5 , 7 , 9 ]
    ans = [ ]
    d = Counter ( s )
    for i in range ( len ( k ) ) :
        x = d . get ( k [ i ] , 0 )
        for j in range ( len ( l [ i ] ) ) :
            d [ l [ i ] [ j ] ] -= x
        ans . append ( str ( c [ i ] ) * x )
    ans . sort ( )
    return " " . join ( ans )
s = " fviefuro "
print ( construct_digits ( s ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
n = 3
m = 3
def countDecrements ( arr ) :
    count_1 = 0
    count_2 = 0
    for i in range ( n ) :
        for j in range ( m ) :
            if ( ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) :
                count_1 += 1
            if ( 1 - ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) :
                count_2 += 1
    print ( min ( count_1 , count_2 ) )
arr = [ [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] ]
countDecrements ( arr )

Index/key variables: i, j
Accumulator variables: count_1, count_2
Iterator variables: i, j
Python program:
def evenXorSubarray ( arr , n ) :
    ans = 0
    freq = [ 0 ] * n
    XOR = 0
    for i in range ( n ) :
        XOR = XOR ^ arr [ i ]
        if ( XOR % 2 == 0 ) :
            ans += freq [ 0 ] + 1
            freq [ 0 ] += 1
        else :
            ans += freq [ 1 ]
            freq [ 1 ] += 1
    print ( ans )
arr = [ 1 , 2 , 3 , 4 ]
N = len ( arr )
evenXorSubarray ( arr , N )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
from math import sqrt
def countOccurrences ( N , X ) :
    count = 0
    for i in range ( 1 , int ( sqrt ( X ) ) + 1 ) :
        if X % i == 0 :
            a = i
            b = X // i
            if a <= N and b <= N :
                if a == b :
                    count += 1
                else :
                    count += 2
    return count
if __name__ == ' _ _ main _ _ ' :
    N = 7
    X = 12
    print ( countOccurrences ( N , X ) )

Accumulator variables: count
Iterator variables: i
Python program:
def findArrayWithMaxProduct ( arr , N ) :
    for i in range ( N ) :
        if ( arr [ i ] >= 0 ) :
            arr [ i ] = - arr [ i ] - 1
    if ( N % 2 == 1 ) :
        max_element = - 1
        index = - 1
        for i in range ( N ) :
            if ( abs ( arr [ i ] ) > max_element ) :
                max_element = abs ( arr [ i ] )
                index = i
        arr [ index ] = - arr [ index ] - 1
    for i in arr :
        print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 3 , 0 , 1 ]
    N = len ( arr )
    findArrayWithMaxProduct ( arr , N )

Index/key variables: i, index
Iterator variables: i
Python program:
def findPerfectIndex ( N , K ) :
    i = 0
    for i in range ( K ) :
        print ( ( N - K + 1 ) + i , end = " ▁ " )
    for i in range ( 3 , N ) :
        print ( i - K + 1 , end = " ▁ " )
N = 10
K = 3
findPerfectIndex ( N , K )

Iterator variables: i
Python program:
from collections import defaultdict
def countPairs ( A , n ) :
    count = ( n * ( n - 1 ) ) // 2
    ump = defaultdict ( int )
    for i in range ( n ) :
        ump [ A [ i ] ] += 1
    for it in ump . keys ( ) :
        c = ump [ it ]
        count = count - ( c * ( c - 1 ) ) // 2
    print ( count )
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 4 , 7 ]
    N = len ( A )
    countPairs ( A , N )

Index/key variables: i, it
Iterator variables: i, it
Python program:
def constructBinaryString ( arr , N , K ) :
    bit = 1
    for i in range ( 0 , N ) :
        bit |= bit << arr [ i ]
    bit = bin ( bit ) . replace ( "0b " , " " )
    print ( bit [ 1 : K + 1 ] )
arr = [ 1 , 6 , 1 ]
N = len ( arr )
K = 8
constructBinaryString ( arr , N , K )

Index/key variables: i
Accumulator variables: bit
Iterator variables: i
Python program:
if ( X == 0 ) :
    if ( N % M == 0 ) :
        global res
        res = N
        return True
    return False
res = - 1
def isDiv ( N , X , M ) :
    for i in range ( 10 ) :
        if ( isDiv ( N * 10 + i , X - 1 , M ) ) :
            return True
if __name__ == " _ _ main _ _ " :
    N , M , X = 4 , 50 , 2
    if ( isDiv ( N , X , M ) ) :
        print ( res )
    else :
        print ( " - 1" )

Iterator variables: i