using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        int[,] dp = new int[3010, 3010];
        for (int i = 0; i < s.Length + 10; i++)
            for (int j = 0; j < t.Length + 10; j++) dp[i, j] = 0;
        for (int y = 1; y <= s.Length; y++)
        {
            for (int x = 1; x <= t.Length; x++)
            {
                if (s[y - 1] == t[x - 1]) dp[y, x] = dp[y - 1, x - 1] + 1;
                else dp[y, x] = Math.Max(dp[y - 1, x], dp[y, x - 1]);
            }
        }
        int LCS = dp[s.Length, t.Length];
        int s_i = s.Length, t_j = t.Length;
        string ans = "";
        while (LCS != 0)
        {
            if (dp[s_i, t_j] == dp[s_i, t_j - 1]) t_j--;
            else if (dp[s_i, t_j] == dp[s_i - 1, t_j]) s_i--;
            else
            {
                ans = t[t_j - 1] + ans;
                t_j--;
                s_i--;
                LCS--;
            }
        }
        Console.WriteLine(ans);
    }
}

public class Atcoder
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int GCD(int a, int b)
    {
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(int a, int b)
    {
        return (long)a * b / GCD(a, b);
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static long[] LSRead()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static long Combination(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r + 1), r).ToList().Aggregate((now, next) => now * next) /
            Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next);
    }
    public static long Permutation(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r), r).ToList().Aggregate((now, next) => now * next);
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static int[] IntLine()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
}


Measured memory_bytes: 48344