#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

use std::rc::Rc;
#[derive(Debug)]
struct RcListInner<T> {
    parent: RcList<T>,
    value: T,
    len: usize,
}
#[doc = " O(1) clone, O(1) push"]
#[derive(Clone, Debug)]
struct RcList<T>(Option<Rc<RcListInner<T>>>);
impl<T: Clone> RcList<T> {
    #[allow(dead_code)]
    fn new() -> Self {
        RcList(None)
    }
    #[allow(dead_code)]
    #[inline]
    fn push(&mut self, value: T) {
        *self = RcList(Some(Rc::new(RcListInner {
            parent: self.clone(),
            value: value,
            len: self.len() + 1,
        })));
    }

    fn len(&self) -> usize {
        match &self.0 {
            &None => 0,
            &Some(ref s) => s.len,
        }
    }

    #[allow(dead_code)]
    fn to_vec(&self) -> Vec<T> {
        if let Some(ref inner) = self.0 {
            let mut p = inner.parent.to_vec();
            p.push(inner.value.clone());
            p
        } else {
            Vec::new()
        }
    }
}

/*
fn rec(
    i: usize,
    j: usize,
    s: &[char],
    t: &[char],
    dp: &mut [Vec<Option<RcList<char>>>],
) -> RcList<char> {
    if let Some(res) = dp[i][j].as_ref() {
        return res.clone();
    }

    if i == 0 || j == 0 {
        return RcList::new();
    }

    let mut res = RcList::new();
    if s[i - 1] == t[j - 1] {
        res = rec(i - 1, j - 1, s, t, dp);
        res.push(t[j - 1]);
    }

    if i > 0 {
        let o = rec(i - 1, j, s, t, dp);
        if o.len() > res.len() {
            res = o;
        }
    }

    if j > 0 {
        let o = rec(i, j - 1, s, t, dp);
        if o.len() > res.len() {
            res = o;
        }
    }

    dp[i][j] = Some(res.clone());

    res
}
*/

fn solve() {
    let s = util::chars();
    let t = util::chars();

    let mut dp = vec![vec![RcList::new(); t.len() + 1]; s.len() + 1];

    for i in 1..s.len() + 1 {
        for j in 1..t.len() + 1 {
            if s[i - 1] == t[j - 1] {
                if dp[i - 1][j - 1].len() + 1 > dp[i][j].len() {
                    let mut res = dp[i - 1][j - 1].clone();
                    res.push(s[i - 1]);
                    dp[i][j] = res;
                }
            }

            if dp[i - 1][j].len() > dp[i][j].len() {
                dp[i][j] = dp[i - 1][j].clone();
            }

            if dp[i][j - 1].len() > dp[i][j].len() {
                dp[i][j] = dp[i][j - 1].clone();
            }
        }
    }

    println!(
        "{}",
        dp[s.len()][t.len()]
            .to_vec()
            .into_iter()
            .collect::<String>()
    );
}


Measured memory_bytes: 526716