#include<iostream>
#include<string.h>
using namespace std;
/********** Begin **********/
// 定义全局变量,结构体,函数等
struct TNode {
int data;
TNode* left;
TNode* right;
};
TNode* newnode()
{
TNode * node = (TNode*)malloc(sizeof(TNode));
node->data = -1;
node->left = NULL;
node->right = NULL;
return node;
}
char s[500];
void addnode(TNode* root, int value, char* instruct) {
int index = 0;
TNode* node = root;
while (instruct[index] != ')') {
if (instruct[index] == 'L') {
if(node->left == NULL)
node->left = newnode();
node = node->left;
}
if (instruct[index] == 'R') {
if (node->right == NULL)
node->right = newnode();
node = node->right;
}
index++;
}
node->data = value;
}
bool input(TNode* root){
bool failed=false;
while(true){
if(scanf("%s",s)!=1) return false;
if(!strcmp(s,"()")) break; // 两个字符穿相同对于零
int v;
sscanf(&s[1],"%d",&v);
addnode(root,v,strchr(s,',')+1);
}
return true;
}
void BFS(TNode* root) {
TNode* queue[100];
TNode* p;
int front = 0, rear = 0;
queue[front++] = root;
while (front != rear) {
p = queue[rear++];
printf("%d", p->data);
if (p->data == -1)
return;
if (p->left != NULL) {
queue[front++] = p->left;
}
if (p->right != NULL) {
queue[front++] = p->right;
}
if (front != rear) {
printf(" ");
}
}
printf("\n-1\n");
}
/********** End **********/
int main(){
TNode * root = newnode();
bool a = input(root);
BFS(root);
return 0;
}