Longest Common Subsequence (LCS)

EasyProblem #5
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

A classic 2D DP problem. Try to define what dp[i][j] should mean before writing any code.

Given two strings, find the length of the longest common subsequence between them.

A subsequence is a sequence of characters obtained by deleting zero or more characters from a string, without changing the order of the remaining characters (the characters don't have to be next to each other). A common subsequence of two strings is a subsequence that appears in both of them.

Input

First line of input will be the string .
In the second line will be the string .

Output

A single number - the length of the longest common subsequence of and .

Example

Input
abcde
ace
Output
3

The longest common subsequence is ace, with a length of 3.

Constraints

Both strings consist of lowercase English letters.

Submit your solution