package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var n, m int
var s, t []byte
var dp, move [][]int

func dfs(i, j int) int {
	if dp[i][j] != -1 {
		return dp[i][j]
	}
	if i == n || j == m {
		return 0
	}

	if s[i] == t[j] {
		dp[i][j] = dfs(i+1, j+1) + 1
		move[i][j] = 0
	} else {
		if dfs(i+1, j) > dfs(i, j+1) {
			dp[i][j] = dp[i+1][j]
			move[i][j] = 1
		} else {
			dp[i][j] = dp[i][j+1]
			move[i][j] = 2
		}
	}
	return dp[i][j]
}

// func main() {
// 	s = readBytes()
// 	t = readBytes()
// 	n = len(s)
// 	m = len(t)
// 	dp = make([][]int, n+1)
// 	move = make([][]int, n+1)
// 	for i := range dp {
// 		dp[i] = make([]int, m+1)
// 		for j := range dp[i] {
// 			dp[i][j] = -1
// 		}
// 		move[i] = make([]int, m+1)
// 	}

// 	dfs(0, 0)

// 	var i, j int
// 	var ans string
// 	for i < n && j < m && len(ans) < dp[0][0] {
// 		if move[i][j] == 0 {
// 			ans += string(s[i])
// 			i++
// 			j++
// 		} else if move[i][j] == 1 {
// 			i++
// 		} else {
// 			j++
// 		}
// 	}
// 	fmt.Println(ans)
// }

func main() {
	s := readString()
	t := readString()
	n = len(s)
	m = len(t)
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, m+1)
		for j := 0; j < m+1; j++ {
			dp[i][j] = 0
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if s[i] == t[j] {
				dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j+1])
			}
			dp[i+1][j+1] = max(max(dp[i+1][j+1], dp[i+1][j]), dp[i][j+1])
		}
	}

	i, j := n, m
	ans := ""
	for i > 0 && j > 0 {
		if dp[i][j] == dp[i-1][j] {
			i--
		} else if dp[i][j] == dp[i][j-1] {
			j--
		} else {
			ans = string(s[i-1]) + ans
			i--
			j--
		}
	}

	fmt.Println(ans)
}

// func main() {
// 	s = readBytes()
// 	t = readBytes()
// 	n = len(s)
// 	m = len(t)
// 	dp = make([][]int, n+1)
// 	move = make([][]int, n+1)
// 	for i := range dp {
// 		dp[i] = make([]int, m+1)
// 		move[i] = make([]int, m+1)
// 		// for j := range dp[i] {
// 		// 	dp[i][j] = 0
// 		// }
// 	}

// 	// dfs(0, 0)
// 	for i := n - 1; i >= 0; i-- {
// 		for j := m - 1; j >= 0; j-- {
// 			if s[i] == t[j] {
// 				dp[i][j] = dp[i+1][j+1] + 1
// 				move[i][j] = 0
// 			} else {
// 				if dp[i+1][j] > dp[i][j+1] {
// 					dp[i][j] = dp[i+1][j]
// 					move[i][j] = 1
// 				} else {
// 					dp[i][j] = dp[i][j+1]
// 					move[i][j] = 2
// 				}
// 			}

// 		}
// 	}

// 	var i, j int
// 	var ans string
// 	for i < n && j < m && len(ans) < dp[0][0] {
// 		if move[i][j] == 0 {
// 			ans += string(s[i])
// 			i++
// 			j++
// 		} else if move[i][j] == 1 {
// 			i++
// 		} else {
// 			j++
// 		}
// 	}
// 	fmt.Println(ans)
// }


Measured memory_bytes: 80640