#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<map> #define ll __int64 #define eps 1e-10 #define maxn 305 using namespace std; char s1[maxn],s2[maxn]; int len1,len2; int dp[maxn][maxn],path[maxn][maxn]; int ans1[maxn],ans2[maxn]; map<int ,int > mp; int id=0; void print(int n,int m) { if(n==0||m==0) return; if(path[n][m]==1) { print(n-1,m-1); ans1[++id]=n-1; ans2[id]=m-1; mp[n-1]=m-1; } else if(path[n][m]==2) { print(n-1,m); } else if(path[n][m]==3) { print(n,m-1); } } void DP() { for(int i=0;i<=len1;i++) dp[i][0]=0; for(int j=0;j<=len2;j++) dp[0][j]=0; for(int i=1;i<=len1;i++) { for(int j=1;j<=len2;j++) { if(s1[i-1]==s2[j-1]) { dp[i][j]=dp[i-1][j-1]+1; path[i][j]=1; } else if(dp[i-1][j]>dp[i][j-1]) { dp[i][j]=dp[i-1][j]; path[i][j]=2; } else { dp[i][j]=dp[i][j-1]; path[i][j]=3; } } } id=0; ans1[0]=-1;ans2[0]=-1; mp.clear(); print(len1,len2); } int main() { while(scanf("%s",s1)!=EOF) { scanf("%s",s2); len1=strlen(s1); len2=strlen(s2); DP(); int p1=1,p2; for(int i=0;i<len1;i++) { if(ans1[p1]==i) { p2=ans2[p1-1]+1; while(p2<mp[i]) { printf("%c",s2[p2]); p2++; } p1++; } printf("%c",s1[i]); } if(ans2[id]<len2) { int p=ans2[id]+1; while(p<len2) { printf("%c",s2[p]); p++; } } printf("\n"); } return 0; }