use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::usize::MAX;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

// 最大公約数
fn gcd(a: u64, b: u64) -> u64 {
    let mut aa: u64 = if a > b { a } else { b };
    let mut bb: u64 = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

// 最小公倍数
fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

// DFS,BFS
fn BFS() {
    let mut searchResult = vec![vec![MAX; 100]; 100];
    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    q.push_front((0, 0));
    searchResult[0][0] = 0;

    let moves = [(1, 0), (-1, 0), (0, 1), (0, -1)];

    while !q.is_empty() {
        let pos = q.pop_back().unwrap(); // これがpop_frontならstackになって深さ優先になる
        for m in moves.iter() {
            let dx: i64 = pos.0 as i64 + m.0;
            let dy: i64 = pos.1 as i64 + m.1;
            if dx >= 0
                && dx < 100
                && dy >= 0
                && dy < 100
                && searchResult[dx as usize][dy as usize] == MAX
            {
                q.push_front((dx as usize, dy as usize));
                searchResult[dx as usize][dy as usize] = searchResult[pos.0][pos.1] + 1;
            }
        }
    }
}

// 文字列操作

const LARGE_PRIME: u64 = 1_000_000_007;

fn inverse_mod(element: u64, modulo: u64) -> u64 {
    // フェルマーの小定理からpが素数なら a^(p-1) = 1
    // よってa*a^(p-2) = 1 より a^(p-2)がaの逆元

    fn power(base: u64, exp: u64, modulo: u64) -> u64 {
        if exp == 0 {
            return 1;
        } else if exp & 1 == 0 {
            return (power(base, exp / 2, modulo) % modulo).pow(2) % modulo;
        } else {
            return power(base, exp - 1, modulo) % modulo * base % modulo;
        }
    }

    power(element, modulo - 2, modulo) % modulo
}

fn combination_mod(m: u64, n: u64, modulo: u64) -> u64 {
    // m C n = m! / ( n! * (m - n)! )
    //       = m*(m-1)*(m-2)*...*(m-n+1)/n!
    //       = m*(m-1)*(m-2)*...*(m-n+1) * (n!)^-1

    let mut numerator = 1;
    for i in 0..n {
        numerator *= m - i;
        numerator %= modulo;
    }

    // (m-n)!
    let mut element = 1;
    for j in 1..(n + 1) {
        element *= j;
        element %= modulo;
    }

    numerator * inverse_mod(element, modulo) % modulo
}

fn solve() {
    input! {
        S: chars,
        T: chars
    }

    //println!("{:?} {:?}", S, T);

    // dp[x][y] = 0:sをx文字目、tをy文字目までみたときの部分文字列長 1: Sにおける最後に記録された文字のインデックス 2,3:参照したi,j
    let mut dp: Vec<Vec<(usize, i64, i64, i64)>> =
        vec![vec![(0, -1, -1, -1); T.len() + 1]; S.len() + 1];

    let chars: Vec<char> = vec![];

    for i in 1..S.len() + 1 {
        for j in 1..T.len() + 1 {
            if S[i - 1] == T[j - 1] {
                //dp[i][j] = format!("{}{}", dp[i - 1][j - 1], S[i - 1]);
                //dp[i][j].0 = dp[i - 1][j - 1].0 + 1;
                dp[i][j] = (
                    dp[i - 1][j - 1].0 + 1,
                    i as i64 - 1,
                    i as i64 - 1,
                    j as i64 - 1,
                );
            } else {
                if dp[i][j - 1].0 > dp[i - 1][j].0 {
                    //dp[i][j] = format!("{}", dp[i][j - 1]);
                    //dp[i][j].0 = dp[i][j - 1].0;
                    dp[i][j] = (dp[i][j - 1].0, dp[i][j - 1].1, i as i64, j as i64 - 1);
                } else {
                    //dp[i][j] = format!("{}", dp[i - 1][j]);
                    //dp[i][j].0 = dp[i - 1][j].0;
                    dp[i][j] = (dp[i - 1][j].0, dp[i - 1][j].1, i as i64 - 1, j as i64);
                }
            }
        }
    }

    let mut last_index = dp[S.len()][T.len()].1;
    let mut dp_i = dp[S.len()][T.len()].2;
    let mut dp_j = dp[S.len()][T.len()].3;
    let mut ans = String::from("");
    if last_index != -1 {
        ans.push(S[last_index as usize]);
    }
    while last_index != -1 && dp_i != -1 {
        let target = dp[dp_i as usize][dp_j as usize];
        if last_index > target.1 && target.1 >= 0 {
            last_index = target.1;
            ans.push(S[last_index as usize]);
        }
        dp_i = target.2;
        dp_j = target.3;
    }

    println!("{}", ans.chars().rev().collect::<String>());
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 332156