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

import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	static char	s[];
	static char	t[];

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		s = in.next().toCharArray();
		t = in.next().toCharArray();
		in.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];
		//int lcs = 0;

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
					// lcs = Math.max(lcs, tb[r + 1][c + 1]);
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

//		for ( int[] is : tb ) {
//			for ( int i : is ) {
//				System.out.print(i + " ");
//			}
//			System.out.println();
//		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque();
		while ( r > 0 && c > 0 ) {

			// 左上に行けるとき
			if ( tb[r][c] == tb[r - 1][c - 1] ) {
				r -= 1;
				c -= 1;
			} else
			// 上にだけ行けるとき
			if ( tb[r][c] != tb[r][c - 1] && tb[r][c] == tb[r - 1][c] ) {
				r -= 1;
			} else
			// 左にだけ行けるとき
			if ( tb[r][c] == tb[r][c - 1] && tb[r][c] != tb[r - 1][c] ) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s[c-1]);
				r -= 1;
				c -= 1;
			}
		}
		if(stack.size() == 0) {
			System.out.print(' ');
			return;
		}

		while ( stack.size() > 0 ) {
			System.out.print(stack.pollLast());
		}
//		System.out.println();
//		System.out.println(tb[row][col]);
	}
}