import java.util.Scanner; public class Main { private static int index = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s = sc.next(); TreeNode root = buildTree(s); inOrder(root); System.out.println(); } } private static TreeNode buildTree(String s) { char c = s.charAt(index++); if (c == '#') return null; TreeNode root = new TreeNode(c); root.left = buildTree(s); root.right = buildTree(s); return root; } private static void inOrder(TreeNode root) { if (root == null) return; inOrder(root.left); System.out.print(root.value + " "); inOrder(root.right); } private static class TreeNode { private final char value; private TreeNode left, right; private TreeNode(char value) { this.value = value; this.left = null; this.right = null; } } }