program EDPCF
    implicit none
    integer(8)::i,j,slen,tlen,cursor,dp(3100,3100)
    character(3000)::s,t,ans
    read*,s,t
    slen=len_trim(s)
    tlen=len_trim(t)

    dp=0

    do i=1,slen
        do j=1,tlen
            if(s(i:i)==t(j:j))then
                dp(j+1,i+1)=max(dp(j,i)+1,dp(j,i+1),dp(j+1,i))
            else
                dp(j+1,i+1)=max(dp(j,i+1),dp(j+1,i))
            end if
        end do
    end do

    i=slen+1
    j=tlen+1
    cursor=dp(tlen+1,slen+1)

    do
        if(i<=0.or.j<=0)exit
        if(dp(j,i)==dp(j,i-1))then
            i=i-1
        else if(dp(j,i)==dp(j-1,i))then
            j=j-1
        else
            ans(cursor:cursor)=s(i-1:i-1)
            cursor=cursor-1
            i=i-1
            j=j-1
        end if
    end do
    
    print'(A)',ans(1:dp(tlen+1,slen+1))
end program EDPCF