#!/usr/bin/python3

import sys
import threading

sys.setrecursionlimit(10**7) # max depth of recursion
threading.stack_size(2**25)  # new thread will get stack of such size


def is_bst(tree):
    # Implement correct algorithm here
    keys = []
    return in_order_recursive(tree, 0, keys) if tree else not tree


def in_order_recursive(tree, vertex, keys):
    """
    Traversing a tree from left to right and
    comparing neighboring keys in pairs.
    :param tree: list of vertices (list of key with left and right children)
    :param vertex: index in tree
    :param keys: list of keys
    :return: True if tree is bst, else False
    """
    if vertex == -1:
        return True
    result = in_order_recursive(tree, tree[vertex][1], keys)
    # If the previous result is False, then the check is completed.
    # If the value of the last key in the list is greater than the current one,
    # then it is not bst, return False.
    # If the vertex has a left child and the key values ​​are equal,
    # then it is also not bst, return False.
    if not result or (keys and (keys[-1] > tree[vertex][0])) or (
            tree[vertex][1] != -1 and tree[tree[vertex][1]][0] == tree[vertex][0]
    ):
        return False
    keys.append(tree[vertex][0])
    result = in_order_recursive(tree, tree[vertex][2], keys)
    return result


def main():
    nodes = int(sys.stdin.readline().strip())
    tree = []
    for i in range(nodes):
        tree.append(list(map(int, sys.stdin.readline().strip().split())))
    if is_bst(tree):
        print("CORRECT")
    else:
        print("INCORRECT")


if __name__ == '__main__':
    threading.Thread(target=main).start()

330c1d371d2011cc41be97a856a75531e0d8ccbd
<mask token>


def in_order_recursive(tree, vertex, keys):
    """
    Traversing a tree from left to right and
    comparing neighboring keys in pairs.
    :param tree: list of vertices (list of key with left and right children)
    :param vertex: index in tree
    :param keys: list of keys
    :return: True if tree is bst, else False
    """
    if vertex == -1:
        return True
    result = in_order_recursive(tree, tree[vertex][1], keys)
    if not result or keys and keys[-1] > tree[vertex][0] or tree[vertex][1
        ] != -1 and tree[tree[vertex][1]][0] == tree[vertex][0]:
        return False
    keys.append(tree[vertex][0])
    result = in_order_recursive(tree, tree[vertex][2], keys)
    return result


def main():
    nodes = int(sys.stdin.readline().strip())
    tree = []
    for i in range(nodes):
        tree.append(list(map(int, sys.stdin.readline().strip().split())))
    if is_bst(tree):
        print('CORRECT')
    else:
        print('INCORRECT')


<mask token>

<mask token>


def is_bst(tree):
    keys = []
    return in_order_recursive(tree, 0, keys) if tree else not tree


def in_order_recursive(tree, vertex, keys):
    """
    Traversing a tree from left to right and
    comparing neighboring keys in pairs.
    :param tree: list of vertices (list of key with left and right children)
    :param vertex: index in tree
    :param keys: list of keys
    :return: True if tree is bst, else False
    """
    if vertex == -1:
        return True
    result = in_order_recursive(tree, tree[vertex][1], keys)
    if not result or keys and keys[-1] > tree[vertex][0] or tree[vertex][1
        ] != -1 and tree[tree[vertex][1]][0] == tree[vertex][0]:
        return False
    keys.append(tree[vertex][0])
    result = in_order_recursive(tree, tree[vertex][2], keys)
    return result


def main():
    nodes = int(sys.stdin.readline().strip())
    tree = []
    for i in range(nodes):
        tree.append(list(map(int, sys.stdin.readline().strip().split())))
    if is_bst(tree):
        print('CORRECT')
    else:
        print('INCORRECT')


<mask token>

<mask token>
sys.setrecursionlimit(10 ** 7)
threading.stack_size(2 ** 25)


def is_bst(tree):
    keys = []
    return in_order_recursive(tree, 0, keys) if tree else not tree


def in_order_recursive(tree, vertex, keys):
    """
    Traversing a tree from left to right and
    comparing neighboring keys in pairs.
    :param tree: list of vertices (list of key with left and right children)
    :param vertex: index in tree
    :param keys: list of keys
    :return: True if tree is bst, else False
    """
    if vertex == -1:
        return True
    result = in_order_recursive(tree, tree[vertex][1], keys)
    if not result or keys and keys[-1] > tree[vertex][0] or tree[vertex][1
        ] != -1 and tree[tree[vertex][1]][0] == tree[vertex][0]:
        return False
    keys.append(tree[vertex][0])
    result = in_order_recursive(tree, tree[vertex][2], keys)
    return result


def main():
    nodes = int(sys.stdin.readline().strip())
    tree = []
    for i in range(nodes):
        tree.append(list(map(int, sys.stdin.readline().strip().split())))
    if is_bst(tree):
        print('CORRECT')
    else:
        print('INCORRECT')


if __name__ == '__main__':
    threading.Thread(target=main).start()

import sys
import threading
sys.setrecursionlimit(10 ** 7)
threading.stack_size(2 ** 25)


def is_bst(tree):
    keys = []
    return in_order_recursive(tree, 0, keys) if tree else not tree


def in_order_recursive(tree, vertex, keys):
    """
    Traversing a tree from left to right and
    comparing neighboring keys in pairs.
    :param tree: list of vertices (list of key with left and right children)
    :param vertex: index in tree
    :param keys: list of keys
    :return: True if tree is bst, else False
    """
    if vertex == -1:
        return True
    result = in_order_recursive(tree, tree[vertex][1], keys)
    if not result or keys and keys[-1] > tree[vertex][0] or tree[vertex][1
        ] != -1 and tree[tree[vertex][1]][0] == tree[vertex][0]:
        return False
    keys.append(tree[vertex][0])
    result = in_order_recursive(tree, tree[vertex][2], keys)
    return result


def main():
    nodes = int(sys.stdin.readline().strip())
    tree = []
    for i in range(nodes):
        tree.append(list(map(int, sys.stdin.readline().strip().split())))
    if is_bst(tree):
        print('CORRECT')
    else:
        print('INCORRECT')


if __name__ == '__main__':
    threading.Thread(target=main).start()

#!/usr/bin/python3

import sys
import threading

sys.setrecursionlimit(10**7) # max depth of recursion
threading.stack_size(2**25)  # new thread will get stack of such size


def is_bst(tree):
    # Implement correct algorithm here
    keys = []
    return in_order_recursive(tree, 0, keys) if tree else not tree


def in_order_recursive(tree, vertex, keys):
    """
    Traversing a tree from left to right and
    comparing neighboring keys in pairs.
    :param tree: list of vertices (list of key with left and right children)
    :param vertex: index in tree
    :param keys: list of keys
    :return: True if tree is bst, else False
    """
    if vertex == -1:
        return True
    result = in_order_recursive(tree, tree[vertex][1], keys)
    # If the previous result is False, then the check is completed.
    # If the value of the last key in the list is greater than the current one,
    # then it is not bst, return False.
    # If the vertex has a left child and the key values ​​are equal,
    # then it is also not bst, return False.
    if not result or (keys and (keys[-1] > tree[vertex][0])) or (
            tree[vertex][1] != -1 and tree[tree[vertex][1]][0] == tree[vertex][0]
    ):
        return False
    keys.append(tree[vertex][0])
    result = in_order_recursive(tree, tree[vertex][2], keys)
    return result


def main():
    nodes = int(sys.stdin.readline().strip())
    tree = []
    for i in range(nodes):
        tree.append(list(map(int, sys.stdin.readline().strip().split())))
    if is_bst(tree):
        print("CORRECT")
    else:
        print("INCORRECT")


if __name__ == '__main__':
    threading.Thread(target=main).start()
