T211867
#include <bits/stdc++.h>
using namespace std;
char s1[10000001], s2[101],L,L1,a[10000001];
int top=0;
bool pd(int L1)
{
for(int i=L1,j=top;i>=0;i--,j--)
{
if(a[j]!=s2[i])
{
return false;
}
}
return true;
}
int main()
{
cin>>s1>>s2;
L=strlen(s1);
L1=strlen(s2);
for(int i=0;i<L;i++)
{
a[++top]=s1[i];
if(s1[i]==s2[L1-1])
{
if(pd(L1-1)) top=top-L1;
}
}
for(int i=1;i<=top;i++)
{
cout<<a[i];
}
return 0;
}