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: Runtime Error)

#include<bits/stdc++.h>
typedef long long ll;
#define M 1000000007
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    string s;
    string t;
    cin>>s>>t;
    int sl=s.length();
    int tl=t.length();
    string ans[sl][tl];
    for(int i=0;i<sl;i++)
    {
        if(s[i]==t[0])
        {
            ans[i][0]=t[0];
            for(int j=i+1;j<sl;j++)
            {
                ans[j][0]=t[0];
            }
            break;
        }
        else
        {
            ans[i][0]="";
        }
        
    }
    for(int i=0;i<tl;i++)
    {
        if(t[i]==s[0])
        {
            ans[0][i]=s[0];
            for(int j=i+1;j<tl;j++)
            {
                ans[0][j]=s[0];
            }
            break;
        }  
        else
        {
            ans[0][i]="";
        }
              
    }
    for(int i=1;i<sl;i++)
    {
        for(int j=0;j<tl;j++)
        {
            if(s[i]==t[j])
            {
                ans[i][j]=ans[i-1][j-1]+s[i];
            }
            else
            {
                if(ans[i][j-1].length()>ans[i-1][j].length())
                {
                    ans[i][j]=ans[i][j-1];
                }
                else
                {
                    ans[i][j]=ans[i-1][j];
                }
                
            }
            
        }
    }
    cout<<ans[sl-1][tl-1];
       
}