macro_rules! debug {
    ( $x:expr ) => {
        if cfg!(debug_assertions) {
            println!("{}:{} {} = {:?}", line!(), column!(), stringify!($x), $x);
        }
    }
}

mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}

fn construct_lcs<T: Eq>(s: &[T], t: &[T]) -> Vec<(usize, usize)> {
    let mut dp = vec![vec![0 as usize; t.len() + 1]; s.len() + 1];
    for i in (0..s.len()).rev() {
        for j in (0..t.len()).rev() {
            if s[i] == t[j] {
                dp[i][j] = 1 + dp[i + 1][j + 1];
            } else {
                dp[i][j] = std::cmp::max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }

    let mut i = 0;
    let mut j = 0;
    let mut result = Vec::new();
    while i < s.len() && j < t.len() {
        if dp[i][j] == dp[i + 1][j] {
            i += 1;
        } else if dp[i][j] == dp[i][j + 1] {
            j += 1;
        } else {
            result.push((i, j));
            i += 1;
            j += 1;
        }
    }
    result
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let s:String = stdin.read();
    let t:String = stdin.read();
    let s = s.as_bytes();
    let t = t.as_bytes();
    let lcs = construct_lcs(s, t);
    let v: Vec<u8> = lcs.iter().map(|&(x, y)| s[x]).collect();
    println!("{}", std::str::from_utf8(&v).unwrap());
}

Measured memory_bytes: 90364