import java.util.*;

public class FruitOrchardSorting {

    // Binary Search Tree Node
    static class TreeNode {
        int val;
        TreeNode left, right;
        TreeNode(int x) {
            val = x;
            left = right = null;
        }
    }

    // Insert value into the BST
    static TreeNode insert(TreeNode root, int val) {
        if (root == null) {
            return new TreeNode(val);
        }
        if (val < root.val) {
            root.left = insert(root.left, val);
        } else {
            root.right = insert(root.right, val);
        }
        return root;
    }

    // Level-order traversal using a Queue
    static void levelOrderTraversal(TreeNode root) {
        if (root == null) {
            return;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            TreeNode currentNode = queue.poll();
            System.out.print(currentNode.val + " ");
            
            if (currentNode.left != null) {
                queue.add(currentNode.left);
            }
            if (currentNode.right != null) {
                queue.add(currentNode.right);
            }
        }
    }

    // Main function to handle input and output
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        try {
            // Reading number of trees
            int n = scanner.nextInt();
            
            // Check for valid n (0 ≤ n ≤ 10)
            if (n < 0 || n > 10) {
                System.out.println("Invalid input");
                return;
            }

            // If n = 0, print an empty line and return
            if (n == 0) {
                System.out.println(); // Print an empty line when n = 0
                return;
            }

            TreeNode root = null;

            // Reading tree IDs
            for (int i = 0; i < n; i++) {
                // If next input is not an integer, throw an exception
                if (!scanner.hasNextInt()) {
                    System.out.println("Invalid input");
                    return;
                }

                int treeId = scanner.nextInt();

                // Check for valid tree IDs (1 ≤ Tree ID ≤ 50,000)
                if (treeId < 1 || treeId > 50000) {
                    System.out.println("Invalid input");
                    return;
                }

                // Insert treeId into the BST
                root = insert(root, treeId);
            }

            // Perform Level-order traversal and print the result
            levelOrderTraversal(root);
        } catch (Exception e) {
            System.out.println("Invalid input");
        } finally {
            scanner.close();
        }
    }
}
