using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.F
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var s = ReadText();
            var t = ReadText();
            var dp = new long[s.Length + 1, t.Length + 1];
            for (int i = 1; i <= s.Length; i++)
            {
                for (int j = 1; j <= t.Length; j++)
                {
                    var a = dp[i - 1, j - 1] + 1;
                    var b = dp[i - 1, j];
                    var c = dp[i, j - 1];
                    if (s[i - 1] == t[j - 1])
                    {
                        dp[i, j] = Math.Max(a, Math.Max(b, c));
                    }
                    else
                    {
                        dp[i, j] = Math.Max(b, c);
                    }
                }
            }

            if (dp[s.Length, t.Length] == 0) return "";

            //var result = "";
            //var current = dp[s.Length, t.Length];
            //var i_current = s.Length;
            //var j_current = t.Length;
            //while (current > 0)
            //{
            //    var i = i_current;
            //    var j = j_current;
            //    while (current == dp[i, j_current])
            //    {
            //        i--;
            //    }
            //    while (current == dp[i_current, j])
            //    {
            //        j--;
            //    }

            //    result = s[i].ToString() + result;
            //    current--;
            //    i_current = i;
            //    j_current = j;
            //}

            //return result;
            var length = dp[s.Length, t.Length];
            var x = s.Length;
            var y = t.Length;
            var str = new char[length];
            while (length > 0)
            {
                if (x > 0 && dp[x - 1, y] == length)
                {
                    --x;
                }
                else if (y > 0 && dp[x, y - 1] == length)
                {
                    --y;
                }
                else
                {
                    --x;
                    --y;
                    --length;
                    str[length] = s[x];
                }
            }
            return new string(str);
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 96056