#include<bits/stdc++.h>
                            using namespace std;

                            #define FOR(i,a,b) for(int i = (a); i < (b); i++)
                            #define rep(i,n) FOR(i,0,n)
                            #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
                            #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
                            #define FILL(a, value) memset(a, value, sizeof(a)

                            #define SZ(a) (int)a.size()
                            #define ALL(a) a.begin(), a.end()
                            #define PB push_back
                            #define MP make_pair
                            #define er erase
                            #define in insert
                            #define f first
                            #define s second



                            typedef  long long LL;
                            typedef vector<int> VI;
                            typedef vector<LL > VL;
                            typedef vector<vector<int > > VVI;
                            typedef vector<vector<LL>> VVL;
                            typedef vector <vector<pair<int, int >> >VVPI;
                            typedef vector<vector<pair<LL, LL >> >VVPL;
                            typedef vector<pair<LL, LL >> PL;
                            typedef vector<PL> VPL;
                            typedef pair<int, int> PII;
                            typedef vector<PII> VPI;

                            const double PI = acos(-1.0);
                            const int INF = 1e9;
                            const LL LINF = (LL)1e18;

                            const double EPS = 1e-7;
                            const int MAS =  3 *1e5 + 10;
                            const int mod = 998244353;
                            const int MOD =1e9+7;
                            const int LOG= 19;
                            const int ar = 1e5 +100;
                            const int MAX = 1e6 + 1e2;
                            pair<int,PII>dp[3010][3010];
                        int main() {
                            ios_base::sync_with_stdio(false);
                            cin.tie(NULL);
                           string a , b;
                           cin >> a >> b;
                           dp[0][0].s = {-1,-1};
                           rep(i,SZ(a))rep(j,SZ(b))
                           {
                               if(a[i] == b[j])
                               {
                                   if(dp[i + 1][j + 1].f <= dp[i][j].f)
                                   {
                                       dp[i + 1][j + 1].f = dp[i][j].f + 1;
                                       dp[i +1][j + 1].s = {i ,j};
                                   }
                               }
                               if(dp[i + 1][j].f <=dp[i][j].f)
                               {
                                   dp[i + 1][j].f = dp[i][j].f;
                                   dp[i + 1][j].s ={i ,j};
                               }
                               if(dp[i][j + 1].f <=dp[i][j].f)
                               {
                                   dp[i][j + 1].f = dp[i][j].f;
                                   dp[i][j + 1 ].s = {i,j} ;
                               }
                           }
                           int mx = 0 ;
                           PII pos = {-1,-1};
                           rep(i,SZ(a) + 1)
                           {
                               rep(j,SZ(b) + 1)
                               {
                                   if(mx < dp[i][j].f)mx =dp[i][j].f,pos = {i - 1, j - 1 };
                               }
                           }

                           string s="";
                           vector<bool > ok (SZ(a) + 10 ,false);
                           vector<bool > ok1 (SZ(b) + 10 ,false);
                        //   cout << pos.f << ' ' << pos.s << endl;
                           while(pos.f!=-1)
                           {
                               if(a[pos.f] == b[pos.s] && !ok[pos.f] && !ok1[pos.s])
                               {
                                   s+=a[pos.f];
                                   ok[pos.f] = true;
                                   ok1[pos.s] = true;
                               }
                               pos =dp[pos.f][pos.s].s;
                           }
                           reverse(ALL(s));
                           cout <<s ;//' ' << SZ(s);
                           //googlecodeforcesfacebook
                            //jumbleplay

                        }

















































Measured memory_bytes: 106112