dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def numWays ( ratings , queries , n , k ) :
    dp = [ [ 0 for i in range ( 10002 ) ] for j in range ( n ) ] ;
    for i in range ( k ) :
        dp [ 0 ] [ ratings [ 0 ] [ i ] ] += 1 ;
    for i in range ( 1 , n ) :
        for sum in range ( 10001 ) :
            for j in range ( k ) :
                if ( sum >= ratings [ i ] [ j ] ) :
                    dp [ i ] [ sum ] += dp [ i - 1 ] [ sum - ratings [ i ] [ j ] ] ;
    for sum in range ( 1 , 10001 ) :
        dp [ n - 1 ] [ sum ] += dp [ n - 1 ] [ sum - 1 ] ;
    for q in range ( len ( queries ) ) :
        a = queries [ q ] [ 0 ] ;
        b = queries [ q ] [ 1 ] ;
        print ( dp [ n - 1 ] [ b ] - dp [ n - 1 ] [ a - 1 ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 2 ;
    K = 3 ;
    ratings = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ;
    queries = [ [ 6 , 6 ] , [ 1 , 6 ] ] ;
    numWays ( ratings , queries , N , K ) ;

Index/key variables: b, i, j, q, sum
Iterator variables: i, j, q, sum
Python program:
def numberOfPermWithKInversion ( N , K ) :
    dp = [ [ 0 ] * ( K + 1 ) ] * 2
    mod = 1000000007
    for i in range ( 1 , N + 1 ) :
        for j in range ( 0 , K + 1 ) :
            if ( i == 1 ) :
                dp [ i % 2 ] [ j ] = 1 if ( j == 0 ) else 0
            elif ( j == 0 ) :
                dp [ i % 2 ] [ j ] = 1
            else :
                var = ( 0 if ( max ( j - ( i - 1 ) , 0 ) == 0 ) else dp [ 1 - i % 2 ] [ max ( j - ( i - 1 ) , 0 ) - 1 ] )
                dp [ i % 2 ] [ j ] = ( ( dp [ i % 2 ] [ j - 1 ] % mod + ( dp [ 1 - i % 2 ] [ j ] - ( var ) + mod ) % mod ) % mod )
    print ( dp [ N % 2 ] [ K ] )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    K = 2
    numberOfPermWithKInversion ( N , K )

Index/key variables: K, j
Iterator variables: i, j
Python program:
def MaxProfit ( treasure , color , n , k , col , A , B ) :
    sum = 0
    if k == n :
        return 0
    if col == color [ k ] :
        sum += max ( A * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )
    else :
        sum += max ( B * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )
    return sum
A = - 5
B = 7
treasure = [ 4 , 8 , 2 , 9 ]
color = [ 2 , 2 , 6 , 2 ]
n = len ( color )
print ( MaxProfit ( treasure , color , n , 0 , 0 , A , B ) )

Index/key variables: k
Python program:
def Combination ( a , combi , n , r , depth , index ) :
    global Sum
    if index == r :
        product = 1
        for i in range ( r ) :
            product = product * combi [ i ]
        Sum += product
        return
    for i in range ( depth , n ) :
        combi [ index ] = a [ i ]
        Combination ( a , combi , n , r , i + 1 , index + 1 )
def allCombination ( a , n ) :
    global Sum
    for i in range ( 1 , n + 1 ) :
        combi = [ 0 ] * i
        Combination ( a , combi , n , i , 0 , 0 )
        print ( " f ( " , i , " ) ▁ - - > ▁ " , Sum )
        Sum = 0
Sum = 0
n = 5
a = [ 0 ] * n
for i in range ( n ) :
    a [ i ] = i + 1
allCombination ( a , n )

Index/key variables: i, index
Iterator variables: i
Python program:
def findPartition ( arr , n ) :
    sum = 0
    i , j = 0 , 0
    for i in range ( n ) :
        sum += arr [ i ]
    if sum % 2 != 0 :
        return false
    part = [ [ True for i in range ( n + 1 ) ] for j in range ( sum // 2 + 1 ) ]
    for i in range ( 0 , n + 1 ) :
        part [ 0 ] [ i ] = True
    for i in range ( 1 , sum // 2 + 1 ) :
        part [ i ] [ 0 ] = False
    for i in range ( 1 , sum // 2 + 1 ) :
        for j in range ( 1 , n + 1 ) :
            part [ i ] [ j ] = part [ i ] [ j - 1 ]
            if i >= arr [ j - 1 ] :
                part [ i ] [ j ] = ( part [ i ] [ j ] or part [ i - arr [ j - 1 ] ] [ j - 1 ] )
    return part [ sum // 2 ] [ n ]
arr = [ 3 , 1 , 1 , 2 , 2 , 1 ]
n = len ( arr )
if findPartition ( arr , n ) == True :
    print ( " Can ▁ be ▁ divided ▁ into ▁ two " , " subsets ▁ of ▁ equal ▁ sum " )
else :
    print ( " Can ▁ not ▁ be ▁ divided ▁ into ▁ " , " two ▁ subsets ▁ of ▁ equal ▁ sum " )

Index/key variables: i, j, n
Accumulator variables: sum
Iterator variables: i, j
Python program:
def minimumOperations ( orig_str , m , n ) :
    orig = orig_str
    turn = 1
    j = 1
    for i in orig_str :
        m_cut = orig_str [ - m : ]
        orig_str = orig_str . replace ( ' ▁ ' , ' ' ) [ : - m ]
        orig_str = m_cut + orig_str
        j = j + 1
        if orig != orig_str :
            turn = turn + 1
            n_cut = orig_str [ - n : ]
            orig_str = orig_str . replace ( ' ▁ ' , ' ' ) [ : - n ]
            orig_str = n_cut + orig_str
            j = j + 1
        if orig == orig_str :
            break
        turn = turn + 1
    print ( turn )
S = " GeeksforGeeks "
X = 5
Y = 3
minimumOperations ( S , X , Y )

Iterator variables: i
Python program:
def KMPSearch ( pat , txt ) :
    M = len ( pat )
    N = len ( txt )
    lps = [ 0 ] * M
    computeLPSArray ( pat , M , lps )
    i = 0
    j = 0
    while i < N :
        if pat [ j ] == txt [ i ] :
            j += 1
            i += 1
        if j == M :
            return i - j
            j = lps [ j - 1 ]
        elif i < N and pat [ j ] != txt [ i ] :
            if j != 0 :
                j = lps [ j - 1 ]
            else :
                i = i + 1
def computeLPSArray ( pat , M , lps ) :
    _len = 0
    lps [ 0 ] = 0
    i = 1
    while i < M :
        if pat [ i ] == pat [ _len ] :
            _len += 1
            lps [ i ] = _len
            i += 1
        else :
            if _len != 0 :
                _len = lps [ _len - 1 ]
            else :
                lps [ i ] = 0
                i += 1
def countRotations ( s ) :
    s1 = s [ 1 : len ( s ) ] + s
    pat = s [ : ]
    text = s1 [ : ]
    return 1 + KMPSearch ( pat , text )
s1 = " geeks "
print ( countRotations ( s1 ) )

Index/key variables: _len, i, j
Python program:
parent = [ 0 ] * 256
def find ( x ) :
    if ( x != parent [ x ] ) :
        parent [ x ] = find ( parent [ x ] )
        return parent [ x ]
    return x
def join ( x , y ) :
    px = find ( x )
    pz = find ( y )
    if ( px != pz ) :
        parent [ pz ] = px
def convertible ( s1 , s2 ) :
    mp = dict ( )
    for i in range ( len ( s1 ) ) :
        if ( s1 [ i ] in mp ) :
            mp [ s1 [ i ] ] = s2 [ i ]
        else :
            if s1 [ i ] in mp and mp [ s1 [ i ] ] != s2 [ i ] :
                return False
    for it in mp :
        if ( it == mp [ it ] ) :
            continue
        else :
            if ( find ( ord ( it ) ) == find ( ord ( it ) ) ) :
                return False
            else :
                join ( ord ( it ) , ord ( it ) )
    return True
def initialize ( ) :
    for i in range ( 256 ) :
        parent [ i ] = i
s1 = " abbcaa "
s2 = " bccdbb "
initialize ( )
if ( convertible ( s1 , s2 ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, it, pz, x
Iterator variables: i, it
Python program:
SIZE = 26
from math import sqrt
def SieveOfEratosthenes ( prime , p_size ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , int ( sqrt ( p_size ) ) , 1 ) :
        if ( prime [ p ] ) :
            for i in range ( p * 2 , p_size , p ) :
                prime [ i ] = False
def printChar ( str , n ) :
    prime = [ True for i in range ( n + 1 ) ]
    SieveOfEratosthenes ( prime , len ( str ) + 1 )
    freq = [ 0 for i in range ( SIZE ) ]
    for i in range ( n ) :
        freq [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( n ) :
        if ( prime [ freq [ ord ( str [ i ] ) - ord ( ' a ' ) ] ] ) :
            print ( str [ i ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    str = " geeksforgeeks "
    n = len ( str )
    printChar ( str , n )

Index/key variables: i, p
Iterator variables: i, p
Python program:
from collections import Counter
import math
def prime ( n ) :
    if n <= 1 :
        return False
    max_div = math . floor ( math . sqrt ( n ) )
    for i in range ( 2 , 1 + max_div ) :
        if n % i == 0 :
            return False
    return True
def checkString ( s ) :
    freq = Counter ( s )
    for i in range ( len ( s ) ) :
        if prime ( freq [ s [ i ] ] ) :
            print ( s [ i ] , end = " " )
s = " geeksforgeeks "
checkString ( s )

Index/key variables: i
Iterator variables: i
Python program:
SIZE = 26
def printChar ( string , n ) :
    freq = [ 0 ] * SIZE
    for i in range ( 0 , n ) :
        freq [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 0 , n ) :
        if ( freq [ ord ( string [ i ] ) - ord ( ' a ' ) ] % 2 == 0 ) :
            print ( string [ i ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    string = " geeksforgeeks "
    n = len ( string )
    printChar ( string , n )

Index/key variables: i
Iterator variables: i
Python program:
def CompareAlphanumeric ( str1 , str2 ) :
    i = 0
    j = 0
    len1 = len ( str1 )
    len2 = len ( str2 )
    while ( i <= len1 and j <= len2 ) :
        while ( i < len1 and ( ( ( str1 [ i ] >= ' a ' and str1 [ i ] <= ' z ' ) or ( str1 [ i ] >= ' A ' and str1 [ i ] <= ' Z ' ) or ( str1 [ i ] >= '0' and str1 [ i ] <= '9' ) ) == False ) ) :
            i += 1
        while ( j < len2 and ( ( ( str2 [ j ] >= ' a ' and str2 [ j ] <= ' z ' ) or ( str2 [ j ] >= ' A ' and str2 [ j ] <= ' Z ' ) or ( str2 [ j ] >= '0' and str2 [ j ] <= '9' ) ) == False ) ) :
            j += 1
        if ( i == len1 and j == len2 ) :
            return True
        elif ( str1 [ i ] != str2 [ j ] ) :
            return False
        else :
            i += 1
            j += 1
    return False
def CompareAlphanumericUtil ( str1 , str2 ) :
    res = CompareAlphanumeric ( str1 , str2 )
    if ( res == True ) :
        print ( " Equal " )
    else :
        print ( " Unequal " )
if __name__ == ' _ _ main _ _ ' :
    str1 = " Ram , ▁ Shyam "
    str2 = " ▁ Ram ▁ - ▁ Shyam . "
    CompareAlphanumericUtil ( str1 , str2 )
    str1 = " abc123"
    str2 = "123abc "
    CompareAlphanumericUtil ( str1 , str2 )

Index/key variables: i, j
Python program:
def solveQueries ( Str , query ) :
    ll = len ( Str )
    Q = len ( query )
    pre = [ [ 0 for i in range ( 256 ) ] for i in range ( ll ) ]
    for i in range ( ll ) :
        pre [ i ] [ ord ( Str [ i ] ) ] += 1
        if ( i ) :
            for j in range ( 256 ) :
                pre [ i ] [ j ] += pre [ i - 1 ] [ j ]
    for i in range ( Q ) :
        l = query [ i ] [ 0 ]
        r = query [ i ] [ 1 ]
        maxi = 0
        c = ' a '
        for j in range ( 256 ) :
            times = pre [ r ] [ j ]
            if ( l ) :
                times -= pre [ l - 1 ] [ j ]
            if ( times > maxi ) :
                maxi = times
                c = chr ( j )
        print ( " Query ▁ " , i + 1 , " : ▁ " , c )
Str = " striver "
query = [ [ 0 , 1 ] , [ 1 , 6 ] , [ 5 , 6 ] ]
solveQueries ( Str , query )

Index/key variables: i, j, r
Accumulator variables: times
Iterator variables: i, j
Python program:
def startsWith ( str , pre ) :
    strLen = len ( str )
    preLen = len ( pre )
    i = 0
    j = 0
    while ( i < strLen and j < preLen ) :
        if ( str [ i ] != pre [ j ] ) :
            return False
        i += 1
        j += 1
    return True
def endsWith ( str , suff ) :
    i = len ( str ) - 1
    j = len ( suff ) - 1
    while ( i >= 0 and j >= 0 ) :
        if ( str [ i ] != suff [ j ] ) :
            return False
        i -= 1
        j -= 1
    return True
def checkString ( str , a , b ) :
    if ( len ( str ) != len ( a ) + len ( b ) ) :
        return False
    if ( startsWith ( str , a ) ) :
        if ( endsWith ( str , b ) ) :
            return True
    if ( startsWith ( str , b ) ) :
        if ( endsWith ( str , a ) ) :
            return True
    return False
str = " GeeksforGeeks "
a = " Geeksfo "
b = " rGeeks "
if ( checkString ( str , a , b ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Python program:
import sys
import math
def printChar ( str_ , n ) :
    freq = [ 0 ] * 26
    for i in range ( n ) :
        freq [ ord ( str_ [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( n ) :
        if ( freq [ ord ( str_ [ i ] ) - ord ( ' a ' ) ] ) % 2 == 1 :
            print ( " { } " . format ( str_ [ i ] ) , end = " " )
if __name__ == ' _ _ main _ _ ' :
    str_ = " geeksforgeeks "
    n = len ( str_ )
    printChar ( str_ , n )

Index/key variables: i
Iterator variables: i
Python program:
def minOperations ( str , n ) :
    lastUpper = - 1
    firstLower = - 1
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( str [ i ] . isupper ( ) ) :
            lastUpper = i
            break
    for i in range ( n ) :
        if ( str [ i ] . islower ( ) ) :
            firstLower = i
            break
    if ( lastUpper == - 1 or firstLower == - 1 ) :
        return 0
    countUpper = 0
    for i in range ( firstLower , n ) :
        if ( str [ i ] . isupper ( ) ) :
            countUpper += 1
    countLower = 0
    for i in range ( lastUpper ) :
        if ( str [ i ] . islower ( ) ) :
            countLower += 1
    return min ( countLower , countUpper )
if __name__ == " _ _ main _ _ " :
    str = " geEksFOrGEekS "
    n = len ( str )
    print ( minOperations ( str , n ) )

Index/key variables: i
Accumulator variables: countLower, countUpper
Iterator variables: i
Python program:
import math
def Betrothed_Sum ( n ) :
    Set = [ ]
    for number_1 in range ( 1 , n ) :
        sum_divisor_1 = 1
        i = 2
        while i * i <= number_1 :
            if ( number_1 % i == 0 ) :
                sum_divisor_1 = sum_divisor_1 + i
                if ( i * i != number_1 ) :
                    sum_divisor_1 += number_1 // i
            i = i + 1
        if ( sum_divisor_1 > number_1 ) :
            number_2 = sum_divisor_1 - 1
            sum_divisor_2 = 1
            j = 2
            while j * j <= number_2 :
                if ( number_2 % j == 0 ) :
                    sum_divisor_2 += j
                    if ( j * j != number_2 ) :
                        sum_divisor_2 += number_2 // j
                j = j + 1
            if ( sum_divisor_2 == number_1 + 1 and number_1 <= n and number_2 <= n ) :
                Set . append ( number_1 )
                Set . append ( number_2 )
    Summ = 0
    for i in Set :
        if i <= n :
            Summ += i
    return Summ
n = 78
print ( Betrothed_Sum ( n ) )

Accumulator variables: Set, Summ, sum_divisor_1, sum_divisor_2
Iterator variables: i, number_1
Python program:
def Series ( n ) :
    sums = 0.0
    for i in range ( 1 , n + 1 ) :
        ser = 1 / ( i ** i )
        sums += ser
    return sums
n = 3
res = round ( Series ( n ) , 5 )
print ( res )

Accumulator variables: sums
Iterator variables: i
Python program:
def isConsistingSubarrayUtil ( arr , n ) :
    mp = { } ;
    for i in range ( n ) :
        if arr [ i ] in mp :
            mp [ arr [ i ] ] += 1 ;
        else :
            mp [ arr [ i ] ] = 1 ;
    for it in mp :
        if ( mp [ it ] > 1 ) :
            return True ;
    return False ;
def isConsistingSubarray ( arr , N ) :
    if ( isConsistingSubarrayUtil ( arr , N ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 , 1 ] ;
    N = len ( arr ) ;
    isConsistingSubarray ( arr , N ) ;

Index/key variables: i, it
Iterator variables: i, it
Python program:
import math
def createhashmap ( Max ) :
    hashmap = { " " }
    curr = 1
    prev = 0
    hashmap . add ( prev )
    while ( curr <= Max ) :
        hashmap . add ( curr )
        temp = curr
        curr = curr + prev
        prev = temp
    return hashmap
def SieveOfEratosthenes ( Max ) :
    isPrime = [ 1 for x in range ( Max + 1 ) ]
    isPrime [ 0 ] = 0
    isPrime [ 1 ] = 0
    for p in range ( 0 , int ( math . sqrt ( Max ) ) ) :
        if ( isPrime [ p ] ) :
            for i in range ( 2 * p , Max , p ) :
                isPrime [ i ] = 0
    return isPrime
def cntFibonacciPrime ( arr , N ) :
    Max = arr [ 0 ]
    for i in range ( 0 , N ) :
        Max = max ( Max , arr [ i ] )
    isPrime = SieveOfEratosthenes ( Max )
    hashmap = createhashmap ( Max )
    for i in range ( 0 , N ) :
        if arr [ i ] == 1 :
            continue
        if ( ( arr [ i ] in hashmap ) and ( not ( isPrime [ arr [ i ] ] ) ) ) :
            print ( arr [ i ] , end = " ▁ " )
arr = [ 13 , 55 , 7 , 3 , 5 , 21 , 233 , 144 , 89 ]
N = len ( arr )
cntFibonacciPrime ( arr , N )

Index/key variables: i, p
Accumulator variables: hashmap
Iterator variables: i, p
Python program:
def maximum_middle_value ( n , k , arr ) :
    ans = - 1
    low = ( n + 1 - k ) // 2
    high = ( n + 1 - k ) // 2 + k
    for i in range ( low , high + 1 ) :
        ans = max ( ans , arr [ i - 1 ] )
    return ans
if __name__ == " _ _ main _ _ " :
    n , k = 5 , 2
    arr = [ 9 , 5 , 3 , 7 , 10 ]
    print ( maximum_middle_value ( n , k , arr ) )
    n , k = 9 , 3
    arr1 = [ 2 , 4 , 3 , 9 , 5 , 8 , 7 , 6 , 10 ]
    print ( maximum_middle_value ( n , k , arr1 ) )

Iterator variables: i
Python program:
import math as mt
def ternarySearch ( l , r , key , ar ) :
    if ( r >= l ) :
        mid1 = l + ( r - l ) // 3
        mid2 = r - ( r - l ) // 3
        if ( ar [ mid1 ] == key ) :
            return mid1
        if ( ar [ mid2 ] == key ) :
            return mid2
        if ( key < ar [ mid1 ] ) :
            return ternarySearch ( l , mid1 - 1 , key , ar )
        elif ( key > ar [ mid2 ] ) :
            return ternarySearch ( mid2 + 1 , r , key , ar )
        else :
            return ternarySearch ( mid1 + 1 , mid2 - 1 , key , ar )
    return - 1
l , r , p = 0 , 9 , 5
ar = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
l = 0
r = 9
key = 5
p = ternarySearch ( l , r , key , ar )
print ( " Index ▁ of " , key , " is " , p )
key = 50
p = ternarySearch ( l , r , key , ar )
print ( " Index ▁ of " , key , " is " , p )

Index/key variables: mid1, mid2
Python program:
def findmin ( p , n ) :
    a , b , c , d = 0 , 0 , 0 , 0
    for i in range ( n ) :
        if ( p [ i ] [ 0 ] <= 0 ) :
            a += 1
        elif ( p [ i ] [ 0 ] >= 0 ) :
            b += 1
        if ( p [ i ] [ 1 ] >= 0 ) :
            c += 1
        elif ( p [ i ] [ 1 ] <= 0 ) :
            d += 1
    return min ( [ a , b , c , d ] )
p = [ [ 1 , 1 ] , [ 2 , 2 ] , [ - 1 , - 1 ] , [ - 2 , 2 ] ]
n = len ( p )
print ( findmin ( p , n ) )

Index/key variables: i
Accumulator variables: a, b, c, d
Iterator variables: i
Python program:
MAX = 26
def getSortedString ( s , n ) :
    lower = [ 0 ] * MAX ;
    upper = [ 0 ] * MAX ;
    for i in range ( n ) :
        if ( s [ i ] . islower ( ) ) :
            lower [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1 ;
        elif ( s [ i ] . isupper ( ) ) :
            upper [ ord ( s [ i ] ) - ord ( ' A ' ) ] += 1 ;
    i = 0 ; j = 0 ;
    while ( i < MAX and lower [ i ] == 0 ) :
        i += 1 ;
    while ( j < MAX and upper [ j ] == 0 ) :
        j += 1 ;
    for k in range ( n ) :
        if ( s [ k ] . islower ( ) ) :
            while ( lower [ i ] == 0 ) :
                i += 1 ;
            s [ k ] = chr ( i + ord ( ' a ' ) ) ;
            lower [ i ] -= 1 ;
        elif ( s [ k ] . isupper ( ) ) :
            while ( upper [ j ] == 0 ) :
                j += 1 ;
            s [ k ] = chr ( j + ord ( ' A ' ) ) ;
            upper [ j ] -= 1 ;
    return " " . join ( s ) ;
if __name__ == " _ _ main _ _ " :
    s = " gEeksfOrgEEkS " ;
    n = len ( s ) ;
    print ( getSortedString ( list ( s ) , n ) ) ;

Index/key variables: i, j, k
Iterator variables: i, k
Python program:
s = " i ▁ like ▁ this ▁ program ▁ very ▁ much "
words = s . split ( ' ▁ ' )
string = [ ]
for word in words :
    string . insert ( 0 , word )
print ( " Reversed ▁ String : " )
print ( " ▁ " . join ( string ) )

Iterator variables: word
Python program:
def SieveOfEratosthenes ( prime , n ) :
    p = 2
    while ( p * p <= n ) :
        if ( prime [ p ] == True ) :
            i = p * p
            while ( i <= n ) :
                prime [ i ] = False
                i += p
        p += 1
def segregatePrimeNonPrime ( prime , arr , N ) :
    SieveOfEratosthenes ( prime , 10000000 )
    left , right = 0 , N - 1
    while ( left < right ) :
        while ( prime [ arr [ left ] ] ) :
            left += 1
        while ( not prime [ arr [ right ] ] ) :
            right -= 1
        if ( left < right ) :
            arr [ left ] , arr [ right ] = arr [ right ] , arr [ left ]
            left += 1
            right -= 1
    for num in arr :
        print ( num , end = " ▁ " )
arr = [ 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 ]
N = len ( arr )
prime = [ True ] * 10000001
segregatePrimeNonPrime ( prime , arr , N )

Index/key variables: i, left, p, right
Iterator variables: num
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . key = data
        self . left = None
        self . right = None
def insert ( node , key ) :
    if node == None :
        return newNode ( key )
    if key < node . key :
        node . left = insert ( node . left , key )
    elif key > node . key :
        node . right = insert ( node . right , key )
    return node
def findMaxforN ( root , N ) :
    if root == None :
        return - 1
    if root . key == N :
        return N
    elif root . key < N :
        k = findMaxforN ( root . right , N )
        if k == - 1 :
            return root . key
        else :
            return k
    elif root . key > N :
        return findMaxforN ( root . left , N )
if __name__ == ' _ _ main _ _ ' :
    N = 4
    root = None
    root = insert ( root , 25 )
    insert ( root , 2 )
    insert ( root , 1 )
    insert ( root , 3 )
    insert ( root , 12 )
    insert ( root , 9 )
    insert ( root , 21 )
    insert ( root , 19 )
    insert ( root , 25 )
    print ( findMaxforN ( root , N ) )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . key = data
        self . left = None
        self . right = None
def insert ( node , key ) :
    if ( node == None ) :
        return newNode ( key )
    if ( key < node . key ) :
        node . left = insert ( node . left , key )
    elif ( key > node . key ) :
        node . right = insert ( node . right , key )
    return node
def findMaxforN ( root , N ) :
    while ( root != None and root . right != None ) :
        if ( N > root . key and N >= root . right . key ) :
            root = root . right
        elif ( N < root . key ) :
            root = root . left
        else :
            break
    if ( root == None or root . key > N ) :
        print ( - 1 )
    else :
        print ( root . key )
if __name__ == ' _ _ main _ _ ' :
    N = 50
    root = None
    root = insert ( root , 5 )
    insert ( root , 2 )
    insert ( root , 1 )
    insert ( root , 3 )
    insert ( root , 12 )
    insert ( root , 9 )
    insert ( root , 21 )
    insert ( root , 19 )
    insert ( root , 25 )
    findMaxforN ( root , N )

Class/struct names: newNode