Skip to content
UPEEC

Longest Common Subsequence

Medium#dynamic-programming#strings· solved by 0 · time limit 2.0 s

Find the length of the longest sequence of characters that appears in both strings in the same order (not necessarily contiguous).

Input

Two lines, each with a lowercase string.

Output

The LCS length.

Constraints

Each string has 1 to 2000 letters.

Sample 1

Input

abcde
ace

Output

3

Sample 2

Input

abc
def

Output

0

Sign in or join free to run and submit your solution.