import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();
        int n = s.length();
        int m = t.length();
        String dp[][] = new String[n+1][m+1];
        in.close();
        for(int i=0;i<=n;i++){
            dp[i][0] = "";
        }
        for(int j=0;j<=m;j++){
            dp[0][j] = "";
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if (s.charAt(i) == t.charAt(j)){
                    dp[i+1][j+1] = dp[i][j]+s.charAt(i);
                }
                else{
                    if (dp[i][j+1].length() >= dp[i+1][j].length()){
                        dp[i+1][j+1] = dp[i][j+1];
                    }
                    else{
                        dp[i+1][j+1] = dp[i+1][j];
                    }
                }
            }
        }
        System.out.println(dp[n][m]);
    }
}

### FIXED CODE ###

import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)



        
def main(): #startline--------------------------------------------
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    dp = [[0]*(lt+1) for i in range(ls+1)]
    for i in range(ls):
        for j in range(lt):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j]+1
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])


    ans = ""
    i = ls
    j = lt
    while dp[i][j] > 0:
        if dp[i-1][j] == dp[i][j]:
            i -= 1
        elif dp[i][j-1] == dp[i][j]:
            j -= 1
        else:
            ans = s[i-1]+ans
            i -= 1
            j -= 1

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================