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 Go (1.6) (judge verdict: Time Limit Exceeded)

package main

import (
	"bufio"
	"fmt"
	"os"
	"unicode/utf8"
)

var StringMapCapForIntToString2DMap = 0

type IntToString2DMap map[int]map[int]string
type IntToStringMap map[int]string

func lib_NewIntToString2DMap(cap, cap2 int) IntToString2DMap {
	StringMapCapForIntToString2DMap = cap2
	return make(map[int]map[int]string, cap)
}
func lib_NewIntToStringMap(cap int) IntToStringMap {
	return make(map[int]string, cap)
}
func (m IntToString2DMap) ChBy(key1, key2 int, f func(cur, new string) bool, value string, values ...string) (replaced bool, valueAlreadyExist bool) {
	maxBy := func(f func(cur, new string) bool, values ...string) string {
		max := values[0]
		for _, v := range values {
			if f(max, v) {
				max = v
			}
		}
		return max
	}
	max := maxBy(f, append(values, value)...)
	if m.Has(key1, key2) {
		if f(m[key1][key2], max) {
			m.Set(key1, key2, max)
			return true, true
		} else {
			return false, true
		}
	}
	m.Set(key1, key2, max)
	return true, false
}
func (m IntToString2DMap) Has(key1, key2 int) bool {
	v1, ok := m[key1]
	if !ok {
		return false
	}
	_, ok = v1[key2]
	if !ok {
		return false
	}
	return true
}
func (m IntToString2DMap) MustGet(key1, key2 int) string {
	v1, ok := m[key1]
	if !ok {
		panic(fmt.Sprintf("ivnalid key1 is specfied in AAAMap: %v", key1))
	}
	v2, ok := v1[key2]
	if !ok {
		panic(fmt.Sprintf("ivnalid key2 is specfied in AAAMap: %v", key2))
	}
	return v2
}
func (m IntToString2DMap) Set(key1, key2 int, value string) (isNewValue bool) {
	v1, ok := m[key1]
	if !ok {
		m[key1] = lib_NewIntToStringMap(StringMapCapForIntToString2DMap)
		v1 = m[key1]
	}
	_, ok = v1[key2]
	v1[key2] = value
	return !ok
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var s string
	scanner.Scan()
	s = scanner.Text()
	var t string
	scanner.Scan()
	t = scanner.Text()
	fmt.Println(solve(s, t))
}
func solve(s string, t string) string {
	slen, tlen := utf8.RuneCountInString(s), utf8.RuneCountInString(t)
	sm := lib_NewIntToString2DMap(slen, tlen)
	sm.Set(0, 0, "")
	compare := func(cur, new string) bool {
		return len(cur) < len(new)
	}
	for si, sr := range s {
		for ti, tr := range t {
			sm.ChBy(si+1, ti+1, compare, sm[si][ti], sm[si+1][ti], sm[si][ti+1])
			if sr == tr {
				sm.ChBy(si+1, ti+1, compare, sm[si][ti]+string(sr))
			}
		}
	}
	return sm.MustGet(slen, tlen)
}