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 PHP7 (7.0.15) (judge verdict: Wrong Answer)

<?php
$a = str();
$b = str();

echo lcs($a, $b);


function lcs($str1, $str2){
    global $dp,$dpf;
    $l1 = strlen($str1);
    $l2 = strlen($str2);
    $dp = array_fill(-1, $l1+1, array_fill(-1, $l2+1, 0));
    for($i = 0; $i < $l1; $i++){
        $dpb = $dp[$i-1];
        $dpi = &$dp[$i];
        $si = $str1[$i];
        $dpfi = [];
        for($j = 0; $j < $l2; $j++){
            if($si == $str2[$j]){
                $dpi[$j] = $dpb[$j-1] + 1;
                $dpfi[$j] = 1;
            }elseif($dpb[$j] > $dpi[$j-1]){
                $dpi[$j] = $dpb[$j];
                $dpfi[$j] = 2;
            }else{
                $dpi[$j] = $dpi[$j-1];
                $dpfi[$j] = 3;
            }
        }
        $dpf[] = $dpfi;
    }
    return $dp[$l1 - 1][$l2 - 1];
}

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}