Byeongchan has two strings A and B. He thinks the two strings look alike, so he picks K pairwise non-overlapping substrings of A and writes them as p1,p2,…,pK in the order they appear in A. He calls the collection of those strings P. The same substrings must also appear in B, pairwise non-overlapping and in the same order.
P satisfies the following conditions.
- P has exactly K strings, and every string has length at least 1.
- String A can be written as a1p1a2p2⋯aKpKaK+1. Here each of a1,a2,…,aK+1 is an arbitrary string and may have length 0.
- String B can be written as b1p1b2p2⋯bKpKbK+1. Here each of b1,b2,…,bK+1 is an arbitrary string and may have length 0.
- PL is the sum of the lengths of all strings in P.
Byeongchan wants the largest possible PL. For example, if A is "bbaaababb", B is "abbbabbaaaba", and K is 4, then P = {"bba", "aa", "b", "a"} makes PL as large as possible, and PL is 7.
