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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
string a,b;
int dp[3005][3005];
int LCS(int i,int j){
    if(i == sz(a) or j == sz(b))
        return 0;
    if(dp[i][j] != -1)return dp[i][j];
    int &ans = dp[i][j];
    if(a[i] == b[j])
        return ans = LCS(i + 1,j + 1) + 1;
    return ans = max(LCS(i + 1, j), LCS(i, j + 1));

}
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    cls(dp, -1);
    cin >> a >> b;
    dp[sz(a)][sz(b)] = 0;
    for(int i = sz(a) - 1; i >= 0; i--)
        for(int j = sz(b) - 1; j >= 0; j--){
            if(a[i] == b[j])
                dp[i][j] = dp[i + 1][j + 1] + 1;
            else
            dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
        }

    //reconstruir
    int i = 0, j = 0;
    string ans = "";
    while(i < sz(a) and j < sz(b)){
        if(a[i] == b[j]){
            ans += a[i];
            i++;
            j++;
        }else 
        if(dp[i + 1][j] > dp[i][j + 1])
            i++;
        else
            j++;
    }
    cout << ans << '\n';
    return 0;
}