def solve(s: str, t: str) -> int:
    dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                print(s[i], t[j])
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
    return dp[len(s)][len(t)]


s = input()
t = input()
print(solve(s, t))
