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: Time Limit Exceeded)

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
table.unpack = table.unpack or unpack
----
local S = setmetatable(read.l():totable(), {__index=function()return '!' end})
local T = setmetatable(read.l():totable(), {__index=function()return '@' end})
local tbl = array(2, {0, nil})

local function cons(val, next)
    return {val = val, next = next}
end

for i=1,#S do
    for j=1,#T do
        local ns = S[i]
        local nt = T[j]
        if ns == nt then
            local a = tbl[i-1][j-1][1]
            local ra = cons(ns, tbl[i-1][j-1][2])
            tbl[i][j] = {a+1, ra}
        else
            local a, ra = table.unpack(tbl[i-1][j])
            local b, rb = table.unpack(tbl[i][j-1])
            if a > b then
                tbl[i][j] = {a, ra}
            else
                tbl[i][j] = {b, rb}
            end
        end
    end
end
local ans_revt = {}
local it = tbl[#S][#T][2]
while it do
    --print(it, it.val, it.next)
    table.insert(ans_revt, it.val)
    it = it.next
end
local ans_revs = table.concat(ans_revt, "")
print(ans_revs:reverse())