#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s1,s2;
int F(int l1,int r1,int l2,int r2)
{
int m=s2.find(s1[l1]);
//查找当前根结点在中序遍历中的位置
if (m>l2) F(l1+1,l1+(m-l2),l2,m-1);//左子树
//s2中从l2到m-1共m-1-l2+1=m-l2个
//所以s1中从l1+1数m-l2个到了l1+1+m-l2-1=l1+m-l2;
if (m<r2) F(l1+(m-l2)+1,r1,m+1,r2);//右子树
//s2中从l2到m+1共m+1-l2+1=m-l2+2个
//所以s1中从l1数m-l2+2个到了l1+m-l2+2-1=l1+(m-l2)+1;
cout << s1[l1];
}
int main()
{
cin >> s1;
cin >> s2;
F(0,s1.length()-1,0,s2.length()-1);
return 0;
}
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s1,s2;
int F(int l1,int r1,int l2,int r2)
{
int m=s2.find(s1[l1]);
//查找当前根结点在中序遍历中的位置
if (m>l2) F(l1+1,l1+(m-l2),l2,m-1);//左子树
//s2中从l2到m-1共m-1-l2+1=m-l2个
//所以s1中从l1+1数m-l2个到了l1+1+m-l2-1=l1+m-l2;
if (m<r2) F(l1+(m-l2)+1,r1,m+1,r2);//右子树
//s2中从l2到m+1共m+1-l2+1=m-l2+2个
//所以s1中从l1数m-l2+2个到了l1+m-l2+2-1=l1+(m-l2)+1;
cout << s1[l1];
}
int main()
{
cin >> s1;
cin >> s2;
F(0,s1.length()-1,0,s2.length()-1);
return 0;
}