import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

    static int[][]memo;
    static String s,m;
    static boolean issub(String a){
       if (a==null)return false;
        int i=0,j=0;
        while (i<a.length()&&j<m.length()){
            if (m.charAt(j)==a.charAt(i)){
                i++;
            }
            j++;
        }
        return i==a.length();
    }
    static int dp(int id,int id2) {
        if (id==s.length()||id2==m.length())return 0;
        if (memo[id][id2]!=-1){
            return memo[id][id2];
        }
        int x1=0;
        if (s.charAt(id)==m.charAt(id2)){
            x1=1+dp(id+1,id2+1);
        }
        int  x2=dp(id+1,id2);
        int x3=dp(id,id2+1);
        int ans=0;
        if (x1>x2) {
            ans = x1;
        }
        else ans =x2;
        if (x3>ans)ans=x3;
        return memo[id][id2]=ans;
        }
    static String trace(int id,int id2) {
        if (id==s.length()||id2==m.length())return "";
        int ans=memo[id][id2];
        int x1=0;
        if (s.charAt(id)==m.charAt(id2)){
            x1=dp(id+1,id2+1);
        }
        int  x2=dp(id+1,id2);
        int x3=dp(id,id2+1);
        if (x1==ans-1&&s.charAt(id)==m.charAt(id2)){
            return s.charAt(id)+trace(id+1,id2+1);
        }
        if (x2==ans){
            return trace(id+1,id2);
        }
        return trace(id,id2+1);
    }

    public  static void main(String[]args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        s=sc.nextLine();
        m = sc.nextLine();
        memo= new int [s.length()+1][m.length()+1];
        for (int[]a:memo)Arrays.fill(a,-1);
        dp(0,0);
        pw.println(trace(0,0));
       // pw.println(Arrays.deepToString(memo));
      pw.flush();
    }
    static class Scanner
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException
        {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if(x.charAt(0) == '-')
            {
                neg = true;
                start++;
            }
            for(int i = start; i < x.length(); i++)
                if(x.charAt(i) == '.')
                {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                }
                else
                {
                    sb.append(x.charAt(i));
                    if(dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg?-1:1);
        }

        public boolean ready() throws IOException {return br.ready();}


    }
}

Measured memory_bytes: 87464