program name
    use,intrinsic :: iso_fortran_env
    implicit none
    character(3000):: s,t,res
    integer(int32):: sl,tl,si,ti
    integer(int32), allocatable:: dp(:,:)

    read*, s
    read*, t
    sl = len_trim(s)
    tl = len_trim(t)

    allocate(dp(0:sl,0:tl))
    dp(:,:) = 0

    do ti=1,tl
        do si=1,sl
            if (s(si:si) == t(ti:ti)) then
                call chmax(dp(si,ti), dp(si-1,ti-1)+1)
            end if
            call chmax(dp(si,ti), dp(si,ti-1))
            call chmax(dp(si,ti), dp(si-1,ti))
        end do
    end do

    ti=tl
    si=sl
    res=''
    do while(ti>0 .and. si>0)
        ! print*, ti,si
        if (dp(si,ti) == dp(si-1,ti)) then
            si=si-1
        else if (dp(si,ti) == dp(si,ti-1)) then
            ti=ti-1
        else
            res=s(si:si)//trim(res)
            si=si-1
            ti=ti-1
        end if
    end do

    print'(a)', trim(res)

contains
    subroutine chmax(x,y)
        integer(int32):: x,y
        if (x < y) x = y
    end subroutine

end program name