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 length = dp[s.Length, t.Length];
            var x = s.Length;
            var y = t.Length;
            var result = new char[length];
            while (length > 0)
            {
                while (x > 0 && length == dp[x - 1, y])
                {
                    x--;
                }
                while (y > 0 && length == dp[x, y - 1])
                {
                    y--;
                }

                x--;
                y--;
                length--;
                result[length] = s[x];
            }

            return new string(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: 96136