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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         String s = infile.readLine();
         String t = infile.readLine();/*
         int N = s.length();
         int M = s.length();
         Node[][] dp = new Node[N+1][M+1];
         for(int i=0; i <= N; i++)
            for(int j=0; j <= M; j++)
               dp[i][j] = new Node(-1, -1, 0);
         for(int i=1; i <= N; i++)
            for(int j=1; j <= M; j++)
            {
               if(s.charAt(i-1) == t.charAt(j-1))
               {
                  int len = dp[i-1][j-1].length+1;
                  if(len > dp[i][j].length)
                     dp[i][j] = new Node(i-1, j-1, len);
               }
               else
               {
                  int len = dp[i][j-1].length;
                  if(len > dp[i][j].length)
                     dp[i][j] = new Node(i, j-1, len);
                  len = dp[i-1][j].length;
                  if(len > dp[i][j].length)
                     dp[i][j] = new Node(i-1, j, len);
               }
            }*/
         System.out.println(solve(s,t));
      }
      public static String solve(String s, String t)
      {
   		if(s.length() == 0 || t.length() == 0) 
            return "";
   		int m = s.length();
   		int n = t.length();
   		int[][] dp = new int[m+1][n+1];
   		for (int i = 1; i <= m; i++) 
   			for (int j = 1; j <= n; j++) 
            {
   				if(s.charAt(i-1) == t.charAt(j-1)) 
                  dp[i][j] = dp[i-1][j-1] + 1;
   				else 
                  dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
   			}
   		int i = m, j = n;
   		StringBuilder sb = new StringBuilder();
   		while(i >= 1 && j >= 1)
         {
   			if(dp[i][j] == dp[i][j-1]) 
               j--;
   			else if(dp[i][j] == dp[i-1][j]) 
               i--;
   			else 
            {
   				sb.append(s.charAt(i-1));
   				i--;
   				j--;
   			}
   		}
   		return sb.reverse().toString();
   	}
   }
   class Node
   {
      public int length;
      public int x;
      public int y;
      
      public Node(int a, int b, int c)
      {
         x = a;
         y = b;
         length = c;
      }
   }