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

#TP0000064. Khoảng cách lớn nhất giữa các vị trí (Maximum Width)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Khoảng cách lớn nhất giữa các vị trí (Maximum Width)

Maximum Width

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given lowercase strings ss and tt of lengths nn and mm, a strictly increasing sequence p1<⋯<pmp_1<\cdots<p_m is valid when spi=tis_{p_i}=t_i for every ii. Its width is the maximum value of pi+1−pip_{i+1}-p_i for 1≤i<m1\le i<m. At least one valid sequence exists. Find the maximum possible width.

Input

  • The first line contains integers n,mn,m.
  • The second line contains a lowercase string ss of length nn.
  • The third line contains a lowercase string tt of length mm.

Output

Print the maximum width of a valid sequence.

Subtasks

  • Subtask 1 (20 points): 2≤m≤n≤202\le m\le n\le 20; both strings contain only lowercase Latin letters; tt is a subsequence of ss.
  • Subtask 2 (30 points): 2≤m≤n≤20002\le m\le n\le 2000; both strings contain only lowercase Latin letters; tt is a subsequence of ss.
  • Subtask 3 (50 points): 2≤m≤n≤2000002\le m\le n\le 200000; both strings contain only lowercase Latin letters; tt is a subsequence of ss.

Examples

Input

5 3
abbbc
abc

Output

3

Explanation

For s=s= abbbc and t=t= abc, choose positions (1,2,5)(1,2,5) in ss. They spell abc. The consecutive gaps are 2−1=12-1=1 and 5−2=35-2=3, giving width 33. The only a is at position 11 and the only c is at position 55; with three chosen positions, no consecutive gap can be greater than 33. Hence the answer is 3.