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

import java.io.*
import java.util.*


fun solve(s: String, t: String){
    val cache = Array(3000){ Array<String?>(3000){ null } }
    fun lcs(i: Int, j: Int): String{
        if(i < 0 || j < 0) return ""
        if(cache[i][j] != null) return cache[i][j]!!
        if(s[i] == t[j]){
            val ret = lcs(i-1, j-1) + s[i]
            cache[i][j] = ret
            return ret
        }
        val cand1 = lcs(i-1, j)
        val cand2 = lcs(i, j-1)
        return if(cand1.length >= cand2.length) cand1 else cand2
    }
    for (i in 0 until s.length){
        for (j in 0 until t.length){
            lcs(i, j)
        }
    }
    println(lcs(s.length-1, t.length-1))
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    solve(s, t)
}