PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000065. Xóa đoạn con dài nhất (Remove the Substring – Hard Version)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xóa đoạn con dài nhất (Remove the Substring – Hard Version)

Remove the Substring (Hard Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given lowercase strings ss and tt, it is guaranteed that tt is a subsequence of ss. You may remove one contiguous substring of ss and concatenate the remaining characters in their original order. Find the maximum number of characters removable while preserving tt as a subsequence. Removing zero characters is allowed.

Input

  • The first line contains the string ss.
  • The second line contains the string tt.

Output

Print the maximum length of a removable contiguous substring.

Subtasks

  • Subtask 1 (20 points): 1≤∣t∣≤∣s∣≤201\le |t|\le |s|\le 20; both strings contain only lowercase Latin letters; tt is a subsequence of ss.
  • Subtask 2 (30 points): 1≤∣t∣≤∣s∣≤20001\le |t|\le |s|\le 2000; both strings contain only lowercase Latin letters; tt is a subsequence of ss.
  • Subtask 3 (50 points): 1≤∣t∣≤∣s∣≤2000001\le |t|\le |s|\le 200000; both strings contain only lowercase Latin letters; tt is a subsequence of ss.

Examples

Input

bbaba
bb

Output

3

Explanation

For s=s= bbaba and t=t= bb, remove positions 33 through 55, namely aba. The remaining string is bb, which still contains tt as a subsequence. This removes 33 characters. Any valid result must retain at least the two characters of tt, so from a string of length 55 one cannot remove more than 5−2=35-2=3. Thus the answer is 3.