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: Wrong Answer)

#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  //dp[i][j]...s[0,i)とt[0,j)の最長部分列
  string s,t;cin>>s>>t;
  ll n=s.size();
  ll m=t.size();
  vector<vector<ll>>dp(n+1,vector<ll>(m+1,0));
  rep(i,n+1)rep(j,m+1)dp[i][j]=0;
  vector<vector<pair<ll,ll>>>from(n+1,vector<pair<ll,ll>>(m+1,pair<ll,ll>(-1,-1)));

  // cout<<"dp"<<endl;
  // rep(i,n+1)cout<<dp[i]<<endl;

  rep(i,n)rep(j,m){
    if(chmax(dp[i+1][j],dp[i][j]))from[i+1][j]=pair<ll,ll>(i,j);
    if(chmax(dp[i][j+1],dp[i][j]))from[i][j+1]=pair<ll,ll>(i,j);
    if(chmax(dp[i+1][j+1],dp[i][j]))from[i+1][j+1]=pair<ll,ll>(i,j);
    if(s[i]==t[j]){
      if(chmax(dp[i+1][j+1],dp[i][j]+1)){
        from[i+1][j+1]=pair<ll,ll>(i,j);
      }
    }
  }

  // cout<<dp[n][m]<<endl;
  // cout<<"dp"<<endl;
  // rep(i,n+1)cout<<dp[i]<<endl;

  vector<pair<ll,ll>>v;
  ll x=n,y=m;
  while(x!=-1 and y!=-1){
    // cout<<from[x][y]<<endl;
    v.push_back(from[x][y]);
    auto p=from[x][y];
    x=p.first;
    y=p.second;
  }

  
  reverse(all(v));
  string ans;
  for(auto p:v){
    // cout<<p<<endl;
    if(p.first==-1 or p.second==-1)continue;
    if(s[p.first]==t[p.second])ans.push_back(s[p.first]);
  }
  cout<<ans<<endl;

  return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}