1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 using namespace std;
5 string n,m;
6 void postorder(int lp,int rp,int li,int ri)
7 {
8 if(lp==rp) { cout<<n[lp];return; }
9 if(lp>rp||li>ri) return ;
10 int k=m.find(n[lp]);
11 postorder(lp+1,lp+k-li,li,k-1);
12 postorder(lp+k-li+1,rp,k+1,ri);
13 cout<<n[lp];
14 }
15 int main()
16 {
17 cin>>n>>m;
18 int len=n.size();
19 postorder(0,len-1,0,len-1);
20 return 0;
21 }