dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def largestSquare ( matrix , R , C , q_i , q_j , K , Q ) :
    countDP = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]
    countDP [ 0 ] [ 0 ] = matrix [ 0 ] [ 0 ]
    for i in range ( 1 , R ) :
        countDP [ i ] [ 0 ] = ( countDP [ i - 1 ] [ 0 ] + matrix [ i ] [ 0 ] )
    for j in range ( 1 , C ) :
        countDP [ 0 ] [ j ] = ( countDP [ 0 ] [ j - 1 ] + matrix [ 0 ] [ j ] )
    for i in range ( 1 , R ) :
        for j in range ( 1 , C ) :
            countDP [ i ] [ j ] = ( matrix [ i ] [ j ] + countDP [ i - 1 ] [ j ] + countDP [ i ] [ j - 1 ] - countDP [ i - 1 ] [ j - 1 ] )
    for q in range ( 0 , Q ) :
        i = q_i [ q ]
        j = q_j [ q ]
        min_dist = min ( i , j , R - i - 1 , C - j - 1 )
        ans = - 1
        for k in range ( 0 , min_dist + 1 ) :
            x1 = i - k
            x2 = i + k
            y1 = j - k
            y2 = j + k
            count = countDP [ x2 ] [ y2 ] ;
            if ( x1 > 0 ) :
                count -= countDP [ x1 - 1 ] [ y2 ]
            if ( y1 > 0 ) :
                count -= countDP [ x2 ] [ y1 - 1 ]
            if ( x1 > 0 and y1 > 0 ) :
                count += countDP [ x1 - 1 ] [ y1 - 1 ]
            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: i, j, q, x2, y2
Accumulator variables: count
Iterator variables: i, j, k, q
Python program:
def MinCost ( arr , n ) :
    dp = [ [ 0 for i in range ( n + 5 ) ] for i in range ( n + 5 ) ]
    sum = [ [ 0 for i in range ( n + 5 ) ] for i in range ( n + 5 ) ]
    for i in range ( n ) :
        k = arr [ i ]
        for j in range ( i , n ) :
            if ( i == j ) :
                sum [ i ] [ j ] = k
            else :
                k += arr [ j ]
                sum [ i ] [ j ] = k
    for i in range ( n - 1 , - 1 , - 1 ) :
        for j in range ( i , n ) :
            dp [ i ] [ j ] = 10 ** 9
            if ( i == j ) :
                dp [ i ] [ j ] = 0
            else :
                for k in range ( i , j ) :
                    dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] + sum [ i ] [ j ] )
    return dp [ 0 ] [ n - 1 ]
arr = [ 7 , 6 , 8 , 6 , 1 , 1 ]
n = len ( arr )
print ( MinCost ( arr , n ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def f ( i , state , A , dp , N ) :
    if i >= N :
        return 0
    elif dp [ i ] [ state ] != - 1 :
        return dp [ i ] [ state ]
    else :
        if i == N - 1 :
            dp [ i ] [ state ] = 1
        elif state == 1 and A [ i ] > A [ i + 1 ] :
            dp [ i ] [ state ] = 1
        elif state == 2 and A [ i ] < A [ i + 1 ] :
            dp [ i ] [ state ] = 1
        elif state == 1 and A [ i ] <= A [ i + 1 ] :
            dp [ i ] [ state ] = 1 + f ( i + 1 , 2 , A , dp , N )
        elif state == 2 and A [ i ] >= A [ i + 1 ] :
            dp [ i ] [ state ] = 1 + f ( i + 1 , 1 , A , dp , N )
        return dp [ i ] [ state ]
def maxLenSeq ( A , N ) :
    dp = [ [ - 1 , - 1 , - 1 ] for i in range ( 1000 ) ]
    for i in range ( N ) :
        tmp = f ( i , 1 , A , dp , N )
        tmp = f ( i , 2 , A , dp , N )
    ans = - 1
    for i in range ( N ) :
        y = dp [ i ] [ 1 ]
        if ( i + y ) >= N :
            ans = max ( ans , dp [ i ] [ 1 ] + 1 )
        elif y % 2 == 0 :
            ans = max ( ans , dp [ i ] [ 1 ] + 1 + dp [ i + y ] [ 2 ] )
        elif y % 2 == 1 :
            ans = max ( ans , dp [ i ] [ 1 ] + 1 + dp [ i + y ] [ 1 ] )
    return ans
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 10 , 3 , 20 , 25 , 24 ]
    n = len ( A )
    print ( maxLenSeq ( A , n ) )

Index/key variables: i, state
Iterator variables: i
Python program:
import math as mt
def MaxGCD ( a , n ) :
    Prefix = [ 0 for i in range ( n + 2 ) ]
    Suffix = [ 0 for i in range ( n + 2 ) ]
    Prefix [ 1 ] = a [ 0 ]
    for i in range ( 2 , n + 1 ) :
        Prefix [ i ] = mt . gcd ( Prefix [ i - 1 ] , a [ i - 1 ] )
    Suffix [ n ] = a [ n - 1 ]
    for i in range ( n - 1 , 0 , - 1 ) :
        Suffix [ i ] = mt . gcd ( Suffix [ i + 1 ] , a [ i - 1 ] )
    ans = max ( Suffix [ 2 ] , Prefix [ n - 1 ] )
    for i in range ( 2 , n ) :
        ans = max ( ans , mt . gcd ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) )
    return ans
a = [ 14 , 17 , 28 , 70 ]
n = len ( a )
print ( MaxGCD ( a , n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
mod = 1000000007 ;
def sumOddFibonacci ( n ) :
    Sum = [ 0 ] * ( n + 1 ) ;
    Sum [ 0 ] = 0 ;
    Sum [ 1 ] = 1 ;
    Sum [ 2 ] = 2 ;
    Sum [ 3 ] = 5 ;
    Sum [ 4 ] = 10 ;
    Sum [ 5 ] = 23 ;
    for i in range ( 6 , n + 1 ) :
        Sum [ i ] = ( ( Sum [ i - 1 ] + ( 4 * Sum [ i - 2 ] ) % mod - ( 4 * Sum [ i - 3 ] ) % mod + mod ) % mod + ( Sum [ i - 4 ] - Sum [ i - 5 ] + mod ) % mod ) % mod ;
    return Sum [ n ] ;
n = 6 ;
print ( sumOddFibonacci ( n ) ) ;

Index/key variables: i, n
Iterator variables: i
Python program:
def fun ( marks , n ) :
    dp = [ 1 for i in range ( 0 , n ) ]
    for i in range ( 0 , n - 1 ) :
        if marks [ i ] > marks [ i + 1 ] :
            temp = i
            while True :
                if marks [ temp ] > marks [ temp + 1 ] and temp >= 0 :
                    if dp [ temp ] > dp [ temp + 1 ] :
                        temp -= 1
                        continue
                    else :
                        dp [ temp ] = dp [ temp + 1 ] + 1
                        temp -= 1
                else :
                    break
        elif marks [ i ] < marks [ i + 1 ] :
            dp [ i + 1 ] = dp [ i ] + 1
    return ( sum ( dp ) )
n = 6
marks = [ 1 , 4 , 5 , 2 , 2 , 1 ]
print ( fun ( marks , n ) )

Index/key variables: i, temp
Iterator variables: i
Python program:
def solve ( N , K ) :
    combo = [ 0 ] * ( N + 1 )
    combo [ 0 ] = 1
    for i in range ( 1 , K + 1 ) :
        for j in range ( 0 , N + 1 ) :
            if j >= i :
                combo [ j ] += combo [ j - i ]
    return combo [ N ]
if __name__ == " _ _ main _ _ " :
    N , K = 29 , 5
    print ( solve ( N , K ) )

Index/key variables: N, j
Iterator variables: i, j
Python program:
def computeLIS ( circBuff , start , end , n ) :
    LIS = [ 0 for i in range ( end ) ]
    for i in range ( start , end ) :
        LIS [ i ] = 1
    for i in range ( start + 1 , end ) :
        for j in range ( start , i ) :
            if ( circBuff [ i ] > circBuff [ j ] and LIS [ i ] < LIS [ j ] + 1 ) :
                LIS [ i ] = LIS [ j ] + 1
    res = - 100000
    for i in range ( start , end ) :
        res = max ( res , LIS [ i ] )
    return res
def LICS ( arr , n ) :
    circBuff = [ 0 for i in range ( 2 * n ) ]
    for i in range ( n ) :
        circBuff [ i ] = arr [ i ]
    for i in range ( n , 2 * n ) :
        circBuff [ i ] = arr [ i - n ]
    res = - 100000
    for i in range ( n ) :
        res = max ( computeLIS ( circBuff , i , i + n , n ) , res )
    return res
arr = [ 1 , 4 , 6 , 2 , 3 ]
n = len ( arr )
print ( " Length ▁ of ▁ LICS ▁ is " , LICS ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def binomialCoeff ( n , k ) :
    C = [ 0 ] * ( k + 1 )
    C [ 0 ] = 1
    for i in range ( 1 , n + 1 ) :
        j = min ( i , k )
        while ( j > 0 ) :
            C [ j ] = C [ j ] + C [ j - 1 ]
            j -= 1
    return C [ k ]
n = 3
m = 2
print ( " Number ▁ of ▁ Paths : " , binomialCoeff ( n + m , n ) )

Index/key variables: j, k
Iterator variables: i
Python program:
def LCIS ( arr1 , n , arr2 , m ) :
    table = [ 0 ] * m
    for j in range ( m ) :
        table [ j ] = 0
    for i in range ( n ) :
        current = 0
        for j in range ( m ) :
            if ( arr1 [ i ] == arr2 [ j ] ) :
                if ( current + 1 > table [ j ] ) :
                    table [ j ] = current + 1
            if ( arr1 [ i ] > arr2 [ j ] ) :
                if ( table [ j ] > current ) :
                    current = table [ j ]
    result = 0
    for i in range ( m ) :
        if ( table [ i ] > result ) :
            result = table [ i ]
    return result
if __name__ == " _ _ main _ _ " :
    arr1 = [ 3 , 4 , 9 , 1 ]
    arr2 = [ 5 , 3 , 8 , 9 , 10 , 2 , 1 ]
    n = len ( arr1 )
    m = len ( arr2 )
    print ( " Length ▁ of ▁ LCIS ▁ is " , LCIS ( arr1 , n , arr2 , m ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import sys
def longComPre ( arr , N ) :
    freq = [ [ 0 for i in range ( 256 ) ] for i in range ( N ) ]
    for i in range ( N ) :
        M = len ( arr [ i ] )
        for j in range ( M ) :
            freq [ i ] [ ord ( arr [ i ] [ j ] ) ] += 1
    maxLen = 0
    for j in range ( 256 ) :
        minRowVal = sys . maxsize
        for i in range ( N ) :
            minRowVal = min ( minRowVal , freq [ i ] [ j ] )
        maxLen += minRowVal
    return maxLen
if __name__ == ' _ _ main _ _ ' :
    arr = [ " aabdc " , " abcd " , " aacd " ]
    N = 3
    print ( longComPre ( arr , N ) )

Index/key variables: i, j
Accumulator variables: maxLen
Iterator variables: i, j
Python program:
MAX_CHAR = 26
def removeChars ( arr , k ) :
    hash = [ 0 ] * MAX_CHAR
    n = len ( arr )
    for i in range ( n ) :
        hash [ ord ( arr [ i ] ) - ord ( ' a ' ) ] += 1
    ans = " "
    index = 0
    for i in range ( n ) :
        if ( hash [ ord ( arr [ i ] ) - ord ( ' a ' ) ] != k ) :
            ans += arr [ i ]
    return ans
if __name__ == " _ _ main _ _ " :
    str = " geeksforgeeks "
    k = 2
    print ( removeChars ( str , k ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def sub_segments ( string , n ) :
    l = len ( string )
    for x in range ( 0 , l , n ) :
        newlist = string [ x : x + n ]
        arr = [ ]
        for y in newlist :
            if y not in arr :
                arr . append ( y )
        print ( ' ' . join ( arr ) )
string = " geeksforgeeksgfg "
n = 4
sub_segments ( string , n )

Accumulator variables: arr
Iterator variables: x, y
Python program:
def findWord ( c , n ) :
    co = 0
    s = [ 0 ] * n
    for i in range ( n ) :
        if ( i < n / 2 ) :
            co += 1
        else :
            co = n - i
        if ( ord ( c [ i ] ) + co <= 122 ) :
            s [ i ] = chr ( ord ( c [ i ] ) + co )
        else :
            s [ i ] = chr ( ord ( c [ i ] ) + co - 26 )
    print ( * s , sep = " " )
s = " abcd "
findWord ( s , len ( s ) )

Index/key variables: i
Accumulator variables: co
Iterator variables: i
Python program:
def equalIgnoreCase ( str1 , str2 ) :
    i = 0
    len1 = len ( str1 )
    len2 = len ( str2 )
    if ( len1 != len2 ) :
        return False
    while ( i < len1 ) :
        if ( str1 [ i ] == str2 [ i ] ) :
            i += 1
        elif ( ( ( str1 [ i ] >= ' a ' and str1 [ i ] <= ' z ' ) or ( str1 [ i ] >= ' A ' and str1 [ i ] <= ' Z ' ) ) == False ) :
            return False
        elif ( ( ( str2 [ i ] >= ' a ' and str2 [ i ] <= ' z ' ) or ( str2 [ i ] >= ' A ' and str2 [ i ] <= ' Z ' ) ) == False ) :
            return False
        else :
            if ( str1 [ i ] >= ' a ' and str1 [ i ] <= ' z ' ) :
                if ( ord ( str1 [ i ] ) - 32 != ord ( str2 [ i ] ) ) :
                    return False
            elif ( str1 [ i ] >= ' A ' and str1 [ i ] <= ' Z ' ) :
                if ( ord ( str1 [ i ] ) + 32 != ord ( str2 [ i ] ) ) :
                    return False
            i += 1
    return True
def equalIgnoreCaseUtil ( str1 , str2 ) :
    res = equalIgnoreCase ( str1 , str2 )
    if ( res == True ) :
        print ( " Same " )
    else :
        print ( " Not ▁ Same " )
if __name__ == ' _ _ main _ _ ' :
    str1 = " Geeks "
    str2 = " geeks "
    equalIgnoreCaseUtil ( str1 , str2 )
    str1 = " Geek "
    str2 = " geeksforgeeks "
    equalIgnoreCaseUtil ( str1 , str2 )

Index/key variables: i
Python program:
def maxValue ( a , b ) :
    b = sorted ( b )
    bi = [ i for i in b ]
    ai = [ i for i in a ]
    n = len ( a )
    m = len ( b )
    j = m - 1
    for i in range ( n ) :
        if ( j < 0 ) :
            break
        if ( bi [ j ] > ai [ i ] ) :
            ai [ i ] = bi [ j ]
            j -= 1
    x = " " . join ( ai )
    return x
a = "1234"
b = "4321"
print ( maxValue ( a , b ) )

Index/key variables: i, j
Iterator variables: i
Python program:
def checkIfUnequal ( n , q ) :
    s1 = str ( n )
    a = [ 0 for i in range ( 26 ) ]
    for i in range ( 0 , len ( s1 ) , 1 ) :
        a [ ord ( s1 [ i ] ) - ord ( '0' ) ] += 1
    prod = n * q
    s2 = str ( prod )
    for i in range ( 0 , len ( s2 ) , 1 ) :
        if ( a [ ord ( s2 [ i ] ) - ord ( '0' ) ] ) :
            return False
    return True
def countInRange ( l , r , q ) :
    count = 0
    for i in range ( l , r + 1 , 1 ) :
        if ( checkIfUnequal ( i , q ) ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    l = 10
    r = 12
    q = 2
    print ( countInRange ( l , r , q ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def is_possible ( s ) :
    l = len ( s )
    one = 0
    zero = 0
    for i in range ( 0 , l ) :
        if ( s [ i ] == '0' ) :
            zero += 1
        else :
            one += 1
    if ( l % 2 == 0 ) :
        return ( one == zero )
    else :
        return ( abs ( one - zero ) == 1 )
if __name__ == " _ _ main _ _ " :
    s = "100110"
    if ( is_possible ( s ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: one, zero
Iterator variables: i
Python program:
import math
def convert ( s ) :
    n = len ( s )
    s1 = " "
    s1 = s1 + s [ 0 ] . lower ( )
    i = 1
    while i < n :
        if ( s [ i ] == ' ▁ ' and i <= n ) :
            s1 = s1 + " ▁ " + ( s [ i + 1 ] ) . lower ( )
            i = i + 1
        else :
            s1 = s1 + ( s [ i ] ) . upper ( )
        i = i + 1
    return s1
str = " I ▁ get ▁ intern ▁ at ▁ geeksforgeeks "
print ( convert ( str ) )

Index/key variables: i
Python program:
def checkdigit ( n , k ) :
    while ( n ) :
        rem = n % 10
        if ( rem == k ) :
            return 1
        n = n / 10
    return 0
def findNthNumber ( n , k ) :
    i = k + 1
    count = 1
    while ( count < n ) :
        if ( checkdigit ( i , k ) or ( i % k == 0 ) ) :
            count += 1
        if ( count == n ) :
            return i
        i += 1
    return - 1
n = 10
k = 2
print ( findNthNumber ( n , k ) )

Accumulator variables: count, i
Python program:
def find_permutations ( arr ) :
    cnt = 0
    max_ind = - 1
    min_ind = 10000000 ;
    n = len ( arr )
    index_of = { }
    for i in range ( n ) :
        index_of [ arr [ i ] ] = i + 1
    for i in range ( 1 , n + 1 ) :
        max_ind = max ( max_ind , index_of [ i ] )
        min_ind = min ( min_ind , index_of [ i ] )
        if ( max_ind - min_ind + 1 == i ) :
            cnt += 1
    return cnt
if __name__ == " _ _ main _ _ " :
    nums = [ ]
    nums . append ( 2 )
    nums . append ( 3 )
    nums . append ( 1 )
    nums . append ( 5 )
    nums . append ( 4 )
    print ( find_permutations ( nums ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
from math import gcd as __gcd
def getCount ( a , n ) :
    gcd = 0
    for i in range ( n ) :
        gcd = __gcd ( gcd , a [ i ] )
    cnt = 0
    for i in range ( 1 , gcd + 1 ) :
        if i * i > gcd :
            break
        if ( gcd % i == 0 ) :
            if ( i * i == gcd ) :
                cnt += 1
            else :
                cnt += 2
    return cnt
a = [ 4 , 16 , 1024 , 48 ]
n = len ( a )
print ( getCount ( a , n ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def delCost ( s , cost ) :
    visited = [ False ] * len ( s )
    ans = 0
    for i in range ( len ( s ) ) :
        if visited [ i ] :
            continue
        maxDel = 0
        totCost = 0
        visited [ i ] = True
        for j in range ( i , len ( s ) ) :
            if s [ i ] == s [ j ] :
                maxDel = max ( maxDel , cost [ j ] )
                totCost += cost [ j ]
                visited [ j ] = True
        ans += totCost - maxDel
    return ans
string = " AAABBB "
cost = [ 1 , 2 , 3 , 4 , 5 , 6 ]
string = " AAABBB "
print ( delCost ( string , cost ) )

Index/key variables: i, j
Accumulator variables: ans, totCost
Iterator variables: i, j
Python program:
def checkXOR ( arr , N ) :
    if ( N % 2 == 0 ) :
        xro = 0 ;
        for i in range ( N ) :
            xro ^= arr [ i ] ;
        if ( xro != 0 ) :
            print ( - 1 ) ;
            return ;
        for i in range ( 0 , N - 3 , 2 ) :
            print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( i + 2 ) , end = " ▁ " ) ;
        for i in range ( 0 , N - 3 , 2 ) :
            print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( N - 1 ) , end = " ▁ " ) ;
    else :
        for i in range ( 0 , N - 2 , 2 ) :
            print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( i + 2 ) ) ;
        for i in range ( 0 , N - 2 , 2 ) :
            print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( N - 1 ) ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 1 , 7 , 2 ] ;
    N = len ( arr ) ;
    checkXOR ( arr , N ) ;

Index/key variables: i
Accumulator variables: xro
Iterator variables: i
Python program:
def make_array_element_even ( arr , N ) :
    res = 0
    odd_cont_seg = 0
    for i in range ( 0 , N ) :
        if ( arr [ i ] % 2 == 1 ) :
            odd_cont_seg += 1
        else :
            if ( odd_cont_seg > 0 ) :
                if ( odd_cont_seg % 2 == 0 ) :
                    res += odd_cont_seg // 2
                else :
                    res += ( odd_cont_seg // 2 ) + 2
                odd_cont_seg = 0
    if ( odd_cont_seg > 0 ) :
        if ( odd_cont_seg % 2 == 0 ) :
            res += odd_cont_seg // 2
        else :
            res += odd_cont_seg // 2 + 2
    return res
arr = [ 2 , 4 , 5 , 11 , 6 ]
N = len ( arr )
print ( make_array_element_even ( arr , N ) )

Index/key variables: i
Accumulator variables: odd_cont_seg, res
Iterator variables: i
Python program:
def zvalue ( nums ) :
    m = max ( nums )
    cnt = 0
    for i in range ( 0 , m + 1 , 1 ) :
        cnt = 0
        for j in range ( 0 , len ( nums ) , 1 ) :
            if ( nums [ j ] >= i ) :
                cnt += 1
        if ( cnt == i ) :
            return i
    return - 1
if __name__ == ' _ _ main _ _ ' :
    nums = [ 7 , 8 , 9 , 0 , 0 , 1 ]
    print ( zvalue ( nums ) )

Index/key variables: j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
def lexico_smallest ( s1 , s2 ) :
    M = { }
    S = [ ]
    pr = { }
    for i in range ( len ( s1 ) ) :
        if s1 [ i ] not in M :
            M [ s1 [ i ] ] = 1
        else :
            M [ s1 [ i ] ] += 1
        S . append ( s1 [ i ] )
    S = list ( set ( S ) )
    S . sort ( )
    for i in range ( len ( s2 ) ) :
        if s2 [ i ] in M :
            M [ s2 [ i ] ] -= 1
    c = s2 [ 0 ]
    index = 0
    res = " "
    for x in S :
        if ( x != c ) :
            for i in range ( 1 , M [ x ] + 1 ) :
                res += x
        else :
            j = 0
            index = len ( res )
            while ( s2 [ j ] == x ) :
                j += 1
            if ( s2 [ j ] < c ) :
                res += s2
                for i in range ( 1 , M [ x ] + 1 ) :
                    res += x
            else :
                for i in range ( 1 , M [ x ] + 1 ) :
                    res += x
                index += M [ x ]
                res += s2
    pr [ res ] = index
    return pr
def lexico_largest ( s1 , s2 ) :
    Pr = dict ( lexico_smallest ( s1 , s2 ) )
    d1 = " "
    key = [ * Pr ] [ 0 ]
    for i in range ( Pr . get ( key ) - 1 , - 1 , - 1 ) :
        d1 += key [ i ]
    d2 = " "
    for i in range ( len ( key ) - 1 , Pr [ key ] + len ( s2 ) - 1 , - 1 ) :
        d2 += key [ i ]
    res = d2 + s2 + d1
    return res
s1 = " ethgakagmenpgs "
s2 = " geeks "
print ( * lexico_smallest ( s1 , s2 ) )
print ( lexico_largest ( s1 , s2 ) )

Index/key variables: i, j, key, res, x
Accumulator variables: S, d1, d2, index
Iterator variables: i, x
Python program:
sz = 100000
tree = [ [ ] for i in range ( sz ) ]
n = 0
vis = [ False ] * sz
subtreeSize = [ 0 for i in range ( sz ) ]
def addEdge ( a , b ) :
    global tree
    tree [ a ] . append ( b )
    tree [ b ] . append ( a )
def dfs ( x ) :
    global vis
    global subtreeSize
    global tree
    vis [ x ] = True
    subtreeSize [ x ] = 1
    for i in tree [ x ] :
        if ( vis [ i ] == False ) :
            dfs ( i )
            subtreeSize [ x ] += subtreeSize [ i ]
def countPairs ( a , b ) :
    global subtreeSize
    sub = min ( subtreeSize [ a ] , subtreeSize [ b ] )
    print ( sub * ( n - sub ) )
if __name__ == ' _ _ main _ _ ' :
    n = 6
    addEdge ( 0 , 1 )
    addEdge ( 0 , 2 )
    addEdge ( 1 , 3 )
    addEdge ( 3 , 4 )
    addEdge ( 3 , 5 )
    dfs ( 0 )
    countPairs ( 1 , 3 )
    countPairs ( 0 , 2 )

Index/key variables: a, b, i, x
Iterator variables: i
Python program:
def findPermutation ( arr , N ) :
    pos = len ( arr ) + 1
    if ( pos > N ) :
        return 1
    res = 0
    for i in range ( 1 , N + 1 ) :
        if ( i not in arr ) :
            if ( i % pos == 0 or pos % i == 0 ) :
                arr . add ( i )
                res += findPermutation ( arr , N )
                arr . remove ( i )
    return res
N = 5
arr = set ( )
print ( findPermutation ( arr , N ) )

Accumulator variables: arr, res
Iterator variables: i
Python program:
def solve ( arr , n , X , Y ) :
    diff = Y - X
    for i in range ( n ) :
        if ( arr [ i ] != 1 ) :
            diff = diff % ( arr [ i ] - 1 )
    if ( diff == 0 ) :
        print ( " Yes " )
    else :
        print ( " No " )
arr = [ 1 , 2 , 7 , 9 , 10 ]
n = len ( arr )
X , Y = 11 , 13
solve ( arr , n , X , Y )

Index/key variables: i
Iterator variables: i
Python program:
maxN = 100001
adj = [ [ ] for i in range ( maxN ) ]
height = [ 0 for i in range ( maxN ) ]
dist = [ 0 for i in range ( maxN ) ]
def addEdge ( u , v ) :
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
def dfs1 ( cur , par ) :
    for u in adj [ cur ] :
        if ( u != par ) :
            dfs1 ( u , cur )
            height [ cur ] = max ( height [ cur ] , height [ u ] )
    height [ cur ] += 1
def dfs2 ( cur , par ) :
    max1 = 0
    max2 = 0
    for u in adj [ cur ] :
        if ( u != par ) :
            if ( height [ u ] >= max1 ) :
                max2 = max1
                max1 = height [ u ]
            elif ( height [ u ] > max2 ) :
                max2 = height [ u ]
    sum = 0
    for u in adj [ cur ] :
        if ( u != par ) :
            sum = ( max2 if ( max1 == height [ u ] ) else max1 )
            if ( max1 == height [ u ] ) :
                dist [ u ] = 1 + max ( 1 + max2 , dist [ cur ] )
            else :
                dist [ u ] = 1 + max ( 1 + max1 , dist [ cur ] )
            dfs2 ( u , cur )
if __name__ == " _ _ main _ _ " :
    n = 6
    addEdge ( 1 , 2 )
    addEdge ( 2 , 3 )
    addEdge ( 2 , 4 )
    addEdge ( 2 , 5 )
    addEdge ( 5 , 6 )
    dfs1 ( 1 , 0 )
    dfs2 ( 1 , 0 )
    for i in range ( 1 , n + 1 ) :
        print ( max ( dist [ i ] , height [ i ] ) - 1 , end = ' ▁ ' )

Index/key variables: cur, i, u, v
Iterator variables: i, u
Python program:
def selectionSort ( arr , n ) :
    for i in range ( n - 1 ) :
        min_idx = i
        for j in range ( i + 1 , n ) :
            if ( arr [ j ] < arr [ min_idx ] ) :
                min_idx = j
        arr [ min_idx ] , arr [ i ] = arr [ i ] , arr [ min_idx ]
def printArray ( arr , size ) :
    for i in range ( size ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
if __name__ == " _ _ main _ _ " :
    arr = [ 64 , 25 , 12 , 22 , 11 ]
    n = len ( arr )
    selectionSort ( arr , n )
    print ( " Sorted ▁ array : ▁ " )
    printArray ( arr , n )

Index/key variables: i, j, min_idx
Iterator variables: i, j