CF BUDDY
← Problems·

1203D1 · Remove the Substring (easy version)

1600 · greedy, implementation

Problem: The only difference between easy and hard versions is the length of the string.

You are given a string ss and a string tt, both consisting only of lowercase Latin letters. It is guaranteed that tt can be obtained from ss by removing some (possibly, zero) number of characters (not necessary contiguous) from ss without changing order of remaining characters (in other words, it is guaranteed that tt is a subsequence of ss).

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You want to remove some substring (contiguous subsequence) from ss of maximum possible length such that after removing this substring tt will remain a subsequence of ss.

If you want to remove the substring s[l;r]s[l;r] then the string ss will be transformed to s1s2sl1sr+1sr+2ss1sss_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|} (where s|s| is the length of ss).

Your task is to find the maximum possible length of the substring you can remove so that tt is still a subsequence of ss.

Input Format: The first line of the input contains one string ss consisting of at least 11 and at most 200200 lowercase Latin letters.

The second line of the input contains one string tt consisting of at least 11 and at most 200200 lowercase Latin letters.

It is guaranteed that tt is a subsequence of ss.

Output Format: Print one integer — the maximum possible length of the substring you can remove so that tt is still a subsequence of ss.

Sample Cases

Case 1

Input

bbaba
bb

Output

3

Case 2

Input

baaba
ab

Output

2

Case 3

Input

abcde
abcde

Output

0

Case 4

Input

asdfasdf
fasd

Output

3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback