#P2030. 遥控车

遥控车

Description

Pingping takes Yunyun to an amusement park and sees nn beautiful remote-controlled cars. Each car has a unique name name[i]. Yunyun has long wanted to play the car whose name is ss. However, since Yunyun is still young, the name she imagines might be a prefix of some car’s name (that is, there exists an ii such that ss is a prefix of name[i]); in this case, she can play the ii-th car. Or it might be a completely made-up name that is not a prefix of any car’s name; in that case, she cannot play anything.

You need to complete the following tasks:

  1. Yunyun thinks of mm desired names. Tell her how many times she can play.

  2. Due to the staff’s careless operation, each car’s placement may have a slight error: the original ii-th car may now be at any one of the positions i1i-1, ii, or i+1i+1 (the position of the 11-st car cannot be 00, and the position of the nn-th car cannot be n+1n+1). Calculate how many possible permutations there are.

Note: The testdata guarantees that when ss is a prefix of name[i], the index ii is uniquely determined. A car can be played multiple times.

Input Format

The first line contains two positive integers nn and mm.

The next nn lines each contain one string name[i], the name of the ii-th car. Then the next mm lines each contain one string ss, the name Yunyun wants.

Output Format

Output two lines:

  • The first line contains the number of times Yunyun can play.
  • The second line contains the number of possible permutations.
4 4
Abcd
DeF
AAa
aBccc
Ab
AA
AbC
aBcc
3
5

Hint

Note:

  • All strings are strictly case-sensitive and have length less than 255255.

Constraints:

  • For 20%20\% of the testdata, n10n \le 10, m10m \le 10.
  • For 40%40\% of the testdata, n1000n \le 1000, m1000m \le 1000.
  • For 100%100\% of the testdata, n10000n \le 10000, m10000m \le 10000.

Translated by ChatGPT 5