dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def simplify ( path ) :
    v = [ ]
    n = len ( path )
    ans = " "
    for i in range ( n ) :
        Dir = " "
        while ( i < n and path [ i ] != ' / ' ) :
            Dir += path [ i ]
            i += 1
        if ( Dir == " . . " ) :
            if ( len ( v ) > 0 ) :
                v . pop ( )
        elif ( Dir == " . " or Dir == " " ) :
            continue
        else :
            v . append ( Dir )
    for i in v :
        ans += " / " + i
    if ( ans == " " ) :
        return " / "
    return ans
Str = " / a / . / b / . . / . . / c / "
res = simplify ( Str )
print ( res )

Index/key variables: i
Accumulator variables: Dir, ans, v
Iterator variables: i
Python program:
import math as mt
def evaluateBoolExpr ( s ) :
    n = len ( s )
    for i in range ( 0 , n - 2 , 2 ) :
        if ( s [ i + 1 ] == " A " ) :
            if ( s [ i + 2 ] == "0" or s [ i ] == "0" ) :
                s [ i + 2 ] = "0"
            else :
                s [ i + 2 ] = "1"
        elif ( s [ i + 1 ] == " B " ) :
            if ( s [ i + 2 ] == "1" or s [ i ] == "1" ) :
                s [ i + 2 ] = "1"
            else :
                s [ i + 2 ] = "0"
        else :
            if ( s [ i + 2 ] == s [ i ] ) :
                s [ i + 2 ] = "0"
            else :
                s [ i + 2 ] = "1"
    return ord ( s [ n - 1 ] ) - ord ( "0" )
s = "1C1B1B0A0"
string = [ s [ i ] for i in range ( len ( s ) ) ]
print ( evaluateBoolExpr ( string ) )

Index/key variables: i
Iterator variables: i
Python program:
def nPermute ( string , n ) :
    string = list ( string )
    new_string = [ ]
    string . sort ( )
    j = 2
    while next_permutation ( string ) :
        new_string = string
        if j == n :
            break
        j += 1
    print ( ' ' . join ( new_string ) )
def next_permutation ( L ) :
    n = len ( L )
    i = n - 2
    while i >= 0 and L [ i ] >= L [ i + 1 ] :
        i -= 1
    if i == - 1 :
        return False
    j = i + 1
    while j < n and L [ j ] > L [ i ] :
        j += 1
    j -= 1
    L [ i ] , L [ j ] = L [ j ] , L [ i ]
    left = i + 1
    right = n - 1
    while left < right :
        L [ left ] , L [ right ] = L [ right ] , L [ left ]
        left += 1
        right -= 1
    return True
if __name__ == " _ _ main _ _ " :
    string = " GEEKSFORGEEKS "
    n = 100
    nPermute ( string , n )

Index/key variables: i, j, left, right
Python program:
def splitString ( str ) :
    alpha = " "
    num = " "
    special = " "
    for i in range ( len ( str ) ) :
        if ( str [ i ] . isdigit ( ) ) :
            num = num + str [ i ]
        elif ( ( str [ i ] >= ' A ' and str [ i ] <= ' Z ' ) or ( str [ i ] >= ' a ' and str [ i ] <= ' z ' ) ) :
            alpha += str [ i ]
        else :
            special += str [ i ]
    print ( alpha )
    print ( num )
    print ( special )
if __name__ == " _ _ main _ _ " :
    str = " geeks01 $ $ for02geeks03 ! @ ! ! "
    splitString ( str )

Index/key variables: i
Accumulator variables: alpha, special
Iterator variables: i
Python program:
def subString ( s , n ) :
    for i in range ( n ) :
        for len in range ( i + 1 , n + 1 ) :
            print ( s [ i : len ] ) ;
s = " abcd " ;
subString ( s , len ( s ) ) ;

Iterator variables: i, len
Python program:
def printSubstrings ( string , n ) :
    for i in range ( n ) :
        for j in range ( i , n ) :
            for k in range ( i , ( j + 1 ) ) :
                print ( string [ k ] , end = " " )
            print ( )
string = " abcd "
printSubstrings ( string , len ( string ) )

Index/key variables: k
Iterator variables: i, j, k
Python program:
def solve ( i , X , Y , a , b , n ) :
    if ( i == n ) :
        return 0
    if ( X <= 0 ) :
        return ( b [ i ] + solve ( i + 1 , X , Y - 1 , a , b , n ) )
    if ( Y <= 0 ) :
        return ( a [ i ] + solve ( i + 1 , X - 1 , Y , a , b , n ) )
    else :
        return max ( a [ i ] + solve ( i + 1 , X - 1 , Y , a , b , n ) , b [ i ] + solve ( i + 1 , X , Y - 1 , a , b , n ) )
a = [ 1 , 2 , 3 , 4 , 5 ]
b = [ 5 , 4 , 3 , 2 , 1 ]
n = len ( a )
x = 3
y = 3
print ( solve ( 0 , x , y , a , b , n ) )

Index/key variables: i
Python program:
class suffix :
    def __init__ ( self ) :
        self . index = 0
        self . rank = [ 0 ] * 2
def buildSuffixArray ( txt : str , n : int ) -> list :
    suffixes = [ 0 ] * n
    for i in range ( n ) :
        suffixes [ i ] = suffix ( )
    for i in range ( n ) :
        suffixes [ i ] . index = i
        suffixes [ i ] . rank [ 0 ] = ord ( txt [ i ] ) - ord ( ' a ' )
        suffixes [ i ] . rank [ 1 ] = ( ord ( txt [ i + 1 ] ) - ord ( ' a ' ) ) if ( ( i + 1 ) < n ) else - 1
    suffixes . sort ( key = lambda a : a . rank )
    ind = [ 0 ] * n
    k = 4
    while k < 2 * n :
        k *= 2
        rank = 0
        prev_rank = suffixes [ 0 ] . rank [ 0 ]
        suffixes [ 0 ] . rank [ 0 ] = rank
        ind [ suffixes [ 0 ] . index ] = 0
        for i in range ( 1 , n ) :
            if ( suffixes [ i ] . rank [ 0 ] == prev_rank and suffixes [ i ] . rank [ 1 ] == suffixes [ i - 1 ] . rank [ 1 ] ) :
                prev_rank = suffixes [ i ] . rank [ 0 ]
                suffixes [ i ] . rank [ 0 ] = rank
            else :
                prev_rank = suffixes [ i ] . rank [ 0 ]
                rank += 1
                suffixes [ i ] . rank [ 0 ] = rank
            ind [ suffixes [ i ] . index ] = i
        for i in range ( n ) :
            nextindex = suffixes [ i ] . index + k // 2
            suffixes [ i ] . rank [ 1 ] = suffixes [ ind [ nextindex ] ] . rank [ 0 ] if ( nextindex < n ) else - 1
        suffixes . sort ( key = lambda a : a . rank )
    suffixArr = [ ]
    for i in range ( n ) :
        suffixArr . append ( suffixes [ i ] . index )
    return suffixArr
def kasai ( txt : str , suffixArr : list ) -> list :
    n = len ( suffixArr )
    lcp = [ 0 ] * n
    invSuff = [ 0 ] * n
    for i in range ( n ) :
        invSuff [ suffixArr [ i ] ] = i
    k = 0
    for i in range ( n ) :
        if ( invSuff [ i ] == n - 1 ) :
            k = 0
            continue
        j = suffixArr [ invSuff [ i ] + 1 ]
        while ( i + k < n and j + k < n and txt [ i + k ] == txt [ j + k ] ) :
            k += 1
        lcp [ invSuff [ i ] ] = k
        if ( k > 0 ) :
            k -= 1
    return lcp
def sumOfFirstN ( N : int ) -> int :
    return ( N * ( N + 1 ) ) // 2
def printKthCharInConcatSubstring ( string : str , K : int ) -> str :
    n = len ( string )
    suffixArr = buildSuffixArray ( string , n )
    lcp = kasai ( string , suffixArr )
    for i in range ( len ( lcp ) ) :
        charToSkip = ( sumOfFirstN ( n - suffixArr [ i ] ) - sumOfFirstN ( lcp [ i ] ) )
        if ( K <= charToSkip ) :
            for j in range ( lcp [ i ] + 1 , ( n - suffixArr [ i ] ) + 1 ) :
                curSubstringLen = j
                if ( K <= curSubstringLen ) :
                    return string [ ( suffixArr [ i ] + K - 1 ) ]
                else :
                    K -= curSubstringLen
            break
        else :
            K -= charToSkip
if __name__ == " _ _ main _ _ " :
    string = " banana "
    K = 10
    print ( printKthCharInConcatSubstring ( string , K ) )

Index/key variables: i, nextindex
Accumulator variables: K, k, rank, suffixArr
Iterator variables: i, j
Class/struct names: suffix
Python program:
def evenNumSubstring ( str ) :
    length = len ( str )
    count = 0
    for i in range ( 0 , length , 1 ) :
        temp = ord ( str [ i ] ) - ord ( '0' )
        if ( temp % 2 == 0 ) :
            count += ( i + 1 )
    return count
if __name__ == ' _ _ main _ _ ' :
    str = [ '1' , '2' , '3' , '4' ]
    print ( evenNumSubstring ( str ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def isSubSequence ( str1 , str2 ) :
    m = len ( str1 ) ;
    n = len ( str2 ) ;
    i = 0 ;
    while ( i < n and j < m ) :
        if ( str1 [ j ] == str2 [ i ] ) :
            j += 1 ;
        i += 1 ;
    return ( j == m ) ;
def findLongestString ( dict1 , str1 ) :
    result = " " ;
    length = 0 ;
    for word in dict1 :
        if ( length < len ( word ) and isSubSequence ( word , str1 ) ) :
            result = word ;
            length = len ( word ) ;
    return result ;
dict1 = [ " ale " , " apple " , " monkey " , " plea " ] ;
str1 = " abpcplea " ;
print ( findLongestString ( dict1 , str1 ) ) ;

Index/key variables: i, j
Iterator variables: word
Python program:
def encryptDecrypt ( inpString ) :
    xorKey = ' P ' ;
    length = len ( inpString ) ;
    for i in range ( length ) :
        inpString = ( inpString [ : i ] + chr ( ord ( inpString [ i ] ) ^ ord ( xorKey ) ) + inpString [ i + 1 : ] ) ;
        print ( inpString [ i ] , end = " " ) ;
    return inpString ;
if __name__ == ' _ _ main _ _ ' :
    sampleString = " GeeksforGeeks " ;
    print ( " Encrypted ▁ String : ▁ " , end = " " ) ;
    sampleString = encryptDecrypt ( sampleString ) ;
    print ( " " ) ;
    print ( " Decrypted ▁ String : ▁ " , end = " " ) ;
    encryptDecrypt ( sampleString ) ;

Index/key variables: i
Iterator variables: i
Python program:
MAX_CHAR = 256
def isPalindrome ( Str , l , h ) :
    while ( h > l ) :
        if ( Str [ l ] != Str [ h ] ) :
            l += 1
            h -= 1
            return False
    return True
def check ( Str ) :
    n = len ( Str )
    freq = [ 0 for i in range ( MAX_CHAR ) ]
    for i in range ( n ) :
        freq [ ord ( Str [ i ] ) ] += 1
        if ( freq [ ord ( Str [ i ] ) ] > 2 ) :
            return True
    k = 0
    for i in range ( n ) :
        if ( freq [ ord ( Str [ i ] ) ] > 1 ) :
            Str [ k ] = Str [ i ]
            k += 1
    Str [ k ] = ' \0'
    if ( isPalindrome ( Str , 0 , k - 1 ) ) :
        if ( k & 1 ) :
            return Str [ k // 2 ] == Str [ k // 2 - 1 ]
        return False
    return True
S = " ABCABD "
Str = [ i for i in S ]
if ( check ( Str ) ) :
    print ( " Repeated ▁ Subsequence ▁ Exists " )
else :
    print ( " Repeated ▁ Subsequence ▁ Doesn ' t ▁ Exists " )

Index/key variables: h, i, k, l
Iterator variables: i
Python program:
def prevPermutation ( str ) :
    n = len ( str ) - 1
    i = n
    while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :
        i -= 1
    if ( i <= 0 ) :
        return False
    j = i - 1
    while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :
        j += 1
    str = list ( str )
    temp = str [ i - 1 ]
    str [ i - 1 ] = str [ j ]
    str [ j ] = temp
    str = ' ' . join ( str )
    str [ : : - 1 ]
    return True , str
if __name__ == ' _ _ main _ _ ' :
    str = "4321"
    b , str = prevPermutation ( str )
    if ( b == True ) :
        print ( " Previous ▁ permutation ▁ is " , str )
    else :
        print ( " Previous ▁ permutation ▁ doesn ' t ▁ exist " )

Index/key variables: i, j
Python program:
def length ( node , ans ) :
    if ( not node ) :
        return 0
    left = length ( node . left , ans )
    right = length ( node . right , ans )
    Leftmax = 0
    Rightmax = 0
    if ( node . left and node . left . val == node . val ) :
        Leftmax += left + 1
    if ( node . right and node . right . val == node . val ) :
        Rightmax += right + 1
    ans [ 0 ] = max ( ans [ 0 ] , Leftmax + Rightmax )
    return max ( Leftmax , Rightmax )
def longestSameValuePath ( root ) :
    ans = [ 0 ]
    length ( root , ans )
    return ans [ 0 ]
class newNode :
    def __init__ ( self , data ) :
        self . val = data
        self . left = self . right = None
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = newNode ( 4 )
    root . left = newNode ( 4 )
    root . right = newNode ( 4 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 9 )
    root . right . right = newNode ( 5 )
    print ( longestSameValuePath ( root ) )

Class/struct names: newNode
Python program:
M = 1000
def cntNum ( X , i , sum , tight , dp ) :
    if ( i >= len ( X ) or sum < 0 ) :
        if ( sum == 0 ) :
            return 1
        return 0
    if ( dp [ sum ] [ i ] [ tight ] != - 1 ) :
        return dp [ sum ] [ i ] [ tight ]
    res , end = 0 , 9
    if tight :
        end = ord ( X [ i ] ) - ord ( '0' )
    for j in range ( end + 1 ) :
        res += cntNum ( X , i + 1 , sum - j , ( tight & ( j == end ) ) , dp )
    dp [ sum ] [ i ] [ tight ] = res
    return res
def UtilCntNumRange ( L , R , Y ) :
    if ( R == 0 and Y == 0 ) :
        return 1
    strr = str ( R )
    dp = [ [ [ - 1 for i in range ( 2 ) ] for i in range ( M ) ] for i in range ( M ) ]
    cntR = cntNum ( strr , 0 , Y , True , dp )
    strr = str ( L - 1 )
    cntL = cntNum ( strr , 0 , Y , True , dp )
    return ( cntR - cntL )
if __name__ == ' _ _ main _ _ ' :
    L , R , Y = 20 , 10000 , 14
    print ( UtilCntNumRange ( L , R , Y ) )

Index/key variables: i, sum, tight
Accumulator variables: res
Iterator variables: j
Python program:
def countSubStr ( st , n ) :
    res = 0
    for i in range ( 0 , n ) :
        if ( st [ i ] == '1' ) :
            for j in range ( i + 1 , n ) :
                if ( st [ j ] == '1' ) :
                    res = res + 1
    return res
st = "00100101" ;
list ( st )
n = len ( st )
print ( countSubStr ( st , n ) , end = " " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def Reverse ( string : list , low : int , high : int ) :
    while low < high :
        string [ low ] , string [ high ] = string [ high ] , string [ low ]
        low += 1
        high -= 1
def cycleLeader ( string : list , shift : int , len : int ) :
    i = 1
    while i < len :
        j = i
        item = string [ j + shift ]
        while True :
            if j & 1 :
                j = len // 2 + j // 2
            else :
                j //= 2
            string [ j + shift ] , item = item , string [ j + shift ]
            if j == i :
                break
        i *= 3
def moveNumberToSecondHalf ( string : list ) :
    k , lenFirst = 0 , 0
    lenRemaining = len ( string )
    shift = 0
    while lenRemaining :
        k = 0
        while pow ( 3 , k ) + 1 <= lenRemaining :
            k += 1
        lenFirst = pow ( 3 , k - 1 ) + 1
        lenRemaining -= lenFirst
        cycleLeader ( string , shift , lenFirst )
        Reverse ( string , shift // 2 , shift - 1 )
        Reverse ( string , shift , shift + lenFirst // 2 - 1 )
        Reverse ( string , shift // 2 , shift + lenFirst // 2 - 1 )
        shift += lenFirst
if __name__ == " _ _ main _ _ " :
    string = " a1b2c3d4e5f6g7"
    string = list ( string )
    moveNumberToSecondHalf ( string )
    print ( ' ' . join ( string ) )

Index/key variables: high, low
Accumulator variables: i, j, k, lenRemaining, shift
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def removeShortPathNodesUtil ( root , level , k ) :
    if ( root == None ) :
        return None
    root . left = removeShortPathNodesUtil ( root . left , level + 1 , k )
    root . right = removeShortPathNodesUtil ( root . right , level + 1 , k )
    if ( root . left == None and root . right == None and level < k ) :
        return None
    return root
def removeShortPathNodes ( root , k ) :
    pathLen = 0
    return removeShortPathNodesUtil ( root , 1 , k )
def prInorder ( root ) :
    if ( root ) :
        prInorder ( root . left )
        print ( root . data , end = " ▁ " )
        prInorder ( root . right )
if __name__ == ' _ _ main _ _ ' :
    k = 4
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . left . left . left = newNode ( 7 )
    root . right . right = newNode ( 6 )
    root . right . right . left = newNode ( 8 )
    print ( " Inorder ▁ Traversal ▁ of ▁ Original ▁ tree " )
    prInorder ( root )
    print ( )
    print ( " Inorder ▁ Traversal ▁ of ▁ Modified ▁ tree " )
    res = removeShortPathNodes ( root , k )
    prInorder ( res )

Class/struct names: newNode
Python program:
def removeDuplicate ( str , n ) :
    s = set ( )
    for i in str :
        s . add ( i )
    st = " "
    for i in s :
        st = st + i
    return st
str = " geeksforgeeks "
n = len ( str )
print ( removeDuplicate ( list ( str ) , n ) )

Accumulator variables: s
Iterator variables: i
Python program:
from collections import deque
class Point :
    def __init__ ( self , xx , yy ) :
        self . x = xx
        self . y = yy
class Node :
    def __init__ ( self , P , d ) :
        self . pt = P
        self . dist = d
def isValid ( row , col ) :
    return ( row >= 0 ) and ( col >= 0 ) and ( row < 4 ) and ( col < 4 )
dRow = [ - 1 , 0 , 0 , 1 ]
dCol = [ 0 , - 1 , 1 , 0 ]
def pathMoves ( mat , src , dest ) :
    d = [ [ - 1 for i in range ( 4 ) ] for i in range ( 4 ) ]
    d [ src . x ] [ src . y ] = 0
    visited = [ [ False for i in range ( 4 ) ] for i in range ( 4 ) ]
    visited [ src . x ] [ src . y ] = True
    q = deque ( )
    s = Node ( src , 0 )
    q . append ( s )
    ok = False
    while ( len ( q ) > 0 ) :
        curr = q . popleft ( )
        pt = curr . pt
        if ( pt . x == dest . x and pt . y == dest . y ) :
            xx , yy = pt . x , pt . y
            dist = curr . dist
            d [ pt . x ] [ pt . y ] = dist
            pathmoves = " "
            while ( xx != src . x or yy != src . y ) :
                if ( xx > 0 and d [ xx - 1 ] [ yy ] == dist - 1 ) :
                    pathmoves += ' D '
                    xx -= 1
                if ( xx < 4 - 1 and d [ xx + 1 ] [ yy ] == dist - 1 ) :
                    pathmoves += ' U '
                    xx += 1
                if ( yy > 0 and d [ xx ] [ yy - 1 ] == dist - 1 ) :
                    pathmoves += ' R '
                    yy -= 1
                if ( yy < 4 - 1 and d [ xx ] [ yy + 1 ] == dist - 1 ) :
                    pathmoves += ' L '
                    yy += 1
                dist -= 1
            pathmoves = pathmoves [ : : - 1 ]
            print ( pathmoves , end = " " )
            ok = True
            break
        for i in range ( 4 ) :
            row = pt . x + dRow [ i ]
            col = pt . y + dCol [ i ]
            if ( isValid ( row , col ) and ( mat [ row ] [ col ] == '1' or mat [ row ] [ col ] == ' s ' or mat [ row ] [ col ] == ' d ' ) and ( not visited [ row ] [ col ] ) ) :
                visited [ row ] [ col ] = True
                adjCell = Node ( Point ( row , col ) , curr . dist + 1 )
                q . append ( adjCell )
                d [ row ] [ col ] = curr . dist + 1
    if ( not ok ) :
        print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ '0' , '1' , '0' , '1' ] , [ '1' , '0' , '1' , '1' ] , [ '0' , '1' , '1' , '1' ] , [ '1' , '1' , '1' , '0' ] ]
    src = Point ( 0 , 3 )
    dest = Point ( 3 , 0 )
    pathMoves ( mat , src , dest )

Index/key variables: col, i, row, xx, yy
Accumulator variables: dist, pathmoves, q
Iterator variables: i
Boolean variables: ok
Class/struct names: Node, Point
Python program:
N = 9
def printing ( arr ) :
    for i in range ( N ) :
        for j in range ( N ) :
            print ( arr [ i ] [ j ] , end = " ▁ " )
        print ( )
def isSafe ( grid , row , col , num ) :
    for x in range ( 9 ) :
        if grid [ row ] [ x ] == num :
            return False
    for x in range ( 9 ) :
        if grid [ x ] [ col ] == num :
            return False
    startRow = row - row % 3
    startCol = col - col % 3
    for i in range ( 3 ) :
        for j in range ( 3 ) :
            if grid [ i + startRow ] [ j + startCol ] == num :
                return False
    return True
def solveSuduko ( grid , row , col ) :
    if ( row == N - 1 and col == N ) :
        return True
    if col == N :
        row += 1
        col = 0
    if grid [ row ] [ col ] > 0 :
        return solveSuduko ( grid , row , col + 1 )
    for num in range ( 1 , N + 1 , 1 ) :
        if isSafe ( grid , row , col , num ) :
            grid [ row ] [ col ] = num
            if solveSuduko ( grid , row , col + 1 ) :
                return True
        grid [ row ] [ col ] = 0
    return False
grid = [ [ 3 , 0 , 6 , 5 , 0 , 8 , 4 , 0 , 0 ] , [ 5 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 8 , 7 , 0 , 0 , 0 , 0 , 3 , 1 ] , [ 0 , 0 , 3 , 0 , 1 , 0 , 0 , 8 , 0 ] , [ 9 , 0 , 0 , 8 , 6 , 3 , 0 , 0 , 5 ] , [ 0 , 5 , 0 , 0 , 9 , 0 , 6 , 0 , 0 ] , [ 1 , 3 , 0 , 0 , 0 , 0 , 2 , 5 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 4 ] , [ 0 , 0 , 5 , 2 , 0 , 6 , 3 , 0 , 0 ] ]
if ( solveSuduko ( grid , 0 , 0 ) ) :
    printing ( grid )
else :
    print ( " no ▁ solution ▁ exists ▁ " )

Index/key variables: col, i, j, row, x
Iterator variables: i, j, num, x
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def longestConsecutiveUtil ( root , curLength , expected , res ) :
    if ( root == None ) :
        return
    if ( root . data == expected ) :
        curLength += 1
    else :
        curLength = 1
    res [ 0 ] = max ( res [ 0 ] , curLength )
    longestConsecutiveUtil ( root . left , curLength , root . data + 1 , res )
    longestConsecutiveUtil ( root . right , curLength , root . data + 1 , res )
def longestConsecutive ( root ) :
    if ( root == None ) :
        return 0
    res = [ 0 ]
    longestConsecutiveUtil ( root , 0 , root . data , res )
    return res [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 6 )
    root . right = newNode ( 9 )
    root . right . left = newNode ( 7 )
    root . right . right = newNode ( 10 )
    root . right . right . right = newNode ( 11 )
    print ( longestConsecutive ( root ) )

Class/struct names: newNode
Python program:
def power ( x , y , p ) :
    res = 1
    x = x % p
    if ( x == 0 ) :
        return 0
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p
        y = y >> 1
        x = ( x * x ) % p
    return res
def remainder ( n , a , p ) :
    ans = a % p
    for i in range ( 1 , n + 1 ) :
        ans = power ( ans , i , p )
    return ans
A = 2
N = 1
P = 2
print ( remainder ( N , A , P ) )

Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . left = None
        self . right = None
        self . key = key
def findMaxBendsUtil ( node , Dir , bends , maxBends , soFar , Len ) :
    if ( node == None ) :
        return
    if ( node . left == None and node . right == None ) :
        if ( bends > maxBends [ 0 ] ) :
            maxBends [ 0 ] = bends
            Len [ 0 ] = soFar
    else :
        if ( Dir == ' l ' ) :
            findMaxBendsUtil ( node . left , Dir , bends , maxBends , soFar + 1 , Len )
            findMaxBendsUtil ( node . right , ' r ' , bends + 1 , maxBends , soFar + 1 , Len )
        else :
            findMaxBendsUtil ( node . right , Dir , bends , maxBends , soFar + 1 , Len )
            findMaxBendsUtil ( node . left , ' l ' , bends + 1 , maxBends , soFar + 1 , Len )
def findMaxBends ( node ) :
    if ( node == None ) :
        return 0
    Len = [ 0 ]
    bends = 0
    maxBends = [ - 1 ]
    if ( node . left ) :
        findMaxBendsUtil ( node . left , ' l ' , bends , maxBends , 1 , Len )
    if ( node . right ) :
        findMaxBendsUtil ( node . right , ' r ' , bends , maxBends , 1 , Len )
    Len [ 0 ] += 1
    return Len [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 8 )
    root . right = newNode ( 2 )
    root . left . left = newNode ( 3 )
    root . left . right = newNode ( 5 )
    root . right . left = newNode ( 2 )
    root . right . left . right = newNode ( 1 )
    root . right . left . right . left = newNode ( 9 )
    print ( findMaxBends ( root ) - 1 )

Class/struct names: newNode