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

#Template 1.0
import sys, re
# from collections import deque, defaultdict, Counter
# from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
# from itertools import accumulate, permutations, combinations, product, groupby
# from operator import itemgetter, mul
# from copy import deepcopy
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect, bisect_left
# from heapq import heappush, heappop, heapify
# from functools import reduce
def input(): return sys.stdin.readline().strip()
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
def list2d(a, b, c): return [[c] * b for i in range(a)]
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# start your code here:

def solve(i, j):
    if(i==Ls or j==Lt):
        return ""
    elif(s[i]==t[j]):
        if(dp[i][j]==-1):
            foo = str(s[i]) + solve(i+1, j+1)
            dp[i][j] = foo
            return foo
        else:
            return dp[i][j]
    else:
        if(dp[i][j]==-1):
            temp1 = solve(i+1, j)
            temp2 = solve(i, j+1)

            if(len(temp1)>len(temp2)):
                dp[i][j] = temp1
                return temp1
            dp[i][j] = temp2
            return temp2
        else:
            return dp[i][j]

s = STR()
t = STR()
Ls = len(s)
Lt = len(t)
dp = list2d(3001, 3001, -1)
print(solve(0, 0))