#include<bits/stdc++.h>
using namespace std;
string x,y;
int lenx,leny;
void dfs(int l1,int r1,int l2,int r2){
if(l1>r1) return;
cout << y[r2];
int p = l1;
while(x[p] != y[r2]) p++;
int cnt = p-l1;
dfs(l1,p-1,l2,l2+cnt-1);
dfs(p+1,r1,l2+cnt,r2-1);
}
int main(){
cin>>x>>y;
lenx=x.size(),leny=y.size();
dfs(0,lenx,0,leny);
}