Skip to main content
Thursday (26.11.2026) at 20:00: ALGOR Contest: Round #5 starts!

~/algor $ cat problems/dp-umumiy-qism-ketma-ketlik

Longest common subsequence

Medium 1000 ms 128 MB 58%
Share

Two strings $s$ and $t$ are given. A string obtained from a string by deleting some letters (without changing the order) is called its subsequence. Find the length of the longest string that is a subsequence of both $s$ and $t$.

Letters of two strings; the longest common letters appearing in order in both are joined by lines

Input

The first line contains the string $s$, the second line contains the string $t$.

Output

One integer — the length of the longest common subsequence.

Note

$1 \le |s|, |t| \le 1000$
the strings consist only of lowercase Latin letters (a–z)

Examples

Input #1
dasturlash
qaldirgoch
Output #1
3
Input #2
abc
xyz
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.