#K48862. Binary Search Tree Operations

    ID: 28515 Type: Default 1000ms 256MiB

Binary Search Tree Operations

Binary Search Tree Operations

You are given a series of operations to perform on a Binary Search Tree (BST). Each operation is provided as a string in one of the two formats: Insert x or Delete x, where x is an integer. The BST must maintain its property: for any node with value v, every value in its left subtree is less than v and every value in its right subtree is greater than v. This property can be formally represented as: \(\forall node,\, (L < v) \text{ if } L \text{ exists, and } (v < R) \text{ if } R \text{ exists}\).

After performing all operations, output the inorder traversal of the BST. Inorder traversal of a BST produces a sorted sequence of the stored integers.

inputFormat

The first line of input contains an integer (n) ((1 \leq n \leq 10^5)) representing the number of operations. Each of the next (n) lines contains an operation in one of the following formats: Insert x or Delete x, where x is an integer.

outputFormat

Output a single line containing the inorder traversal of the final BST. Print the values separated by a space. If the BST is empty after performing all operations, output an empty line.## sample

5
Insert 10
Insert 5
Insert 15
Delete 10
Insert 20
5 15 20