#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<sstream>
using namespace std;
const double Pi=acos(-1.0);
struct node
{
string data;
node * lchild;
node * rchild;
};
//根据数组创建二叉树
node * create(string str1[],int len,int pos){
if(pos>=len)
return NULL;
node * root=new node;
root->data=str1[pos];
root->lchild=create(str1,len,2*pos+1);
root->rchild=create(str1,len,2*pos+2);
return root;
}
//左右子树交换
void change(node * &root){
if(root==NULL)
return;
change(root->lchild);
change(root->rchild);
node * temp=new node;
temp=root->lchild;
root->lchild=root->rchild;
root->rchild=temp;
}
//层序遍历
void LayerOrder(node * root){
queue<node *> q;
q.push(root);
while(!q.empty()){
node * now=q.front();
cout<<now->data<<",";
q.pop();
if(now->lchild!=NULL)
q.push(now->lchild);
if(now->rchild!=NULL)
q.push(now->rchild);
}
}
//中序遍历
int sum=7;
void inOrder(node * root){
if(root==NULL)
return ;
inOrder(root->lchild);
cout<<root->data;
if(sum--)
cout<<",";
inOrder(root->rchild);
}
int main()
{
int D;
cin>>D;
getchar();
string str;
getline(cin,str);
string str1[35];
for(int i=0;i<str.length();i++){
if(str[i]==',')
str[i]=' ';
}
stringstream ss;
ss.str(str);
for(int i=0;i<D;i++){
ss>>str1[i];
}
node * root=create(str1,D,0);
change(root);
inOrder(root);
return 0;
}