Problem:
Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara

Solution in LuaJIT (2.0.4) (judge verdict: Accepted)

local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={default_val and {__index=function()return default_val end}}for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local unpack = table.unpack or unpack
local insert = table.insert or insert
----
local S = setmetatable(read.l():totable(), {__index=function()return '!' end})
local T = setmetatable(read.l():totable(), {__index=function()return '@' end})
local tbl1 = array(2, 0)
local tbl2 = array(2, nil)

for i=1,#S do
    local tbl1_i = tbl1[i]
    local tbl1_i_1 = tbl1[i-1]
    local tbl2_i = tbl2[i]
    local tbl2_i_1 = tbl2[i-1]
    for j=1,#T do
        local ns = S[i]
        local nt = T[j]
        if ns == nt then
            local a = tbl1_i_1[j-1]
            local ra = '\\'
            tbl1_i[j] = a+1
            tbl2_i[j] = ra
        else
            local a = tbl1_i_1[j]
            local b = tbl1_i[j-1]
            if a > b then
                tbl1_i[j] = a
                tbl2_i[j] = '|'
            else
                tbl1_i[j] = b
                tbl2_i[j] = '-'
            end
        end
    end
end
if false then
    print(tbl1[#S][#T])
    return
end
local ans_revt = {}
local i, j, next = #S, #T, tbl2[#S][#T]
while next do
    if next == '\\' then
        insert(ans_revt, S[i])
        i, j = i-1, j-1
        next = tbl2[i][j]
    elseif next == '|' then
        i, j = i-1, j
        next = tbl2[i][j]
    elseif next == '-' then
        i, j = i, j-1
        next = tbl2[i][j]
    end
end
local ans_revs = table.concat(ans_revt, "")
print(ans_revs:reverse())