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 Rust (1.15.1) (judge verdict: Time Limit Exceeded)

use std::cmp::max;
const MOD: usize = 1000000007;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    //
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
        t: String,
    }
    let s: Vec<char> = s.chars().collect();
    let t: Vec<char> = t.chars().collect();
    let n: usize = s.len();
    let m: usize = t.len();
    let mut memo: Vec<Vec<(String, usize)>> = vec![vec![(String::new(), 0); m + 1]; n + 1];
    for i in 0..n {
        for j in 0..m {
            memo[i + 1][j + 1] = if s[i] == t[j] {
                let ml = max(max(memo[i][j].1 + 1, memo[i][j + 1].1), memo[i + 1][j].1);
                if ml == memo[i][j].1 + 1 {
                    memo[i][j].0.push(s[i]);
                    (memo[i][j].0.clone(), memo[i][j].1 + 1)
                } else if ml == memo[i][j + 1].1 {
                    (memo[i][j + 1].0.clone(), memo[i][j + 1].1)
                } else {
                    (memo[i + 1][j].0.clone(), memo[i + 1][j].1)
                }

            // max(max(memo[i][j].1 + 1, memo[i][j + 1].1), memo[i + 1][j].1)
            } else {
                let ml = max(max(memo[i][j].1 + 1, memo[i][j + 1].1), memo[i + 1][j].1);
                if ml == memo[i][j].1 {
                    (memo[i][j].0.clone(), memo[i][j].1 + 1)
                } else if ml == memo[i][j + 1].1 {
                    (memo[i][j + 1].0.clone(), memo[i][j + 1].1)
                } else {
                    (memo[i + 1][j].0.clone(), memo[i + 1][j].1)
                }
            }
        }
    }
    println!("{}", memo[n][m].0);
}