#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        var dp = new int[s.Length + 1, t.Length + 1];

        for (int i = 0; i < s.Length; i++)
        {
            for (int j = 0; j < t.Length; j++)
            {
                if (s[i] == t[j])
                {
                    dp[i + 1, j + 1] = dp[i, j] + 1;
                }
                else
                {
                    dp[i + 1, j + 1] = Math.Max(dp[i + 1, j], dp[i, j + 1]);
                }
            }
        }
        var lens = s.Length;
        var lent = t.Length;
        var ii = lens;
        var jj = lent;
        var sb = new StringBuilder();
        while (ii >= 0 && jj >= 0 && dp[ii,jj] != 0)
        {
            try
            {
                if (dp[ii, jj] == dp[ii - 1, jj - 1] + 1 && s[ii - 1] == t[jj-1])
                {
                    sb.Append(s[ii - 1].ToString());
                    ii--; jj--;
                }
                else
                {
                    if (dp[ii, jj] == dp[ii - 1, jj - 1])
                    {
                        ii--;
                        jj--;
                    }
                    else if (dp[ii, jj] > dp[ii, jj - 1])
                    {
                        ii--;
                    }
                    else
                    {
                        jj--;
                    }

                }
            }
            catch
            {
                break;
            }
        }

        // Console.WriteLine(dp[s.Length,t.Length]);
        Console.WriteLine(new string(sb.ToString().Reverse().ToArray()));
        Console.ReadLine();
    }

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            for (int j = 0; j < array.GetLength(1); j++)
            {
                Console.Write(array[i, j] + " ");
            }
            Console.WriteLine();
        }
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    #endregion
}



Measured memory_bytes: 46688