407624: GYM102861 C Concatenating Teams

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Concatenating Teamstime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Pepito is an ICPC coach who very often gets to "concat" the names of two existing teams, such as "AJI" and "Oxidados", in order to produce names for new teams, such as "AJIOxidados".

Since Pepito coaches teams from two different universities where he teaches, he had an idea: he will consider all possible such concatenations of a team name from university $$$A$$$, with a team name from university $$$B$$$ (always in that order: first the one from university $$$A$$$, then the one from university $$$B$$$).

So, if team names from university $$$A$$$ are "Buen" and "Kilo", and team names from university $$$B$$$ are "Pan" and "Flauta", all the possible concatenations that he considers are the strings "BuenPan", "BuenFlauta", "KiloPan" and "KiloFlauta".

Furthermore, he calls a certain team peculiar if removal of that team makes the set of concatenations lose all the concatenations that used the name of that team.

In effect, in the previous example all the teams are peculiar. If however we consider names from $$$A$$$ to be "xx" and "xxy" and names from $$$B$$$ to be "z", "yz" and "xx", then "xx" from university $$$A$$$ is not peculiar, because the name "xx" + "yz" = "xxyz" = "xxy" + "z" and can thus be formed without the need to use "xx" from $$$A$$$. For the same reason, "yz", "xxy" and "z" are not peculiar names. The only peculiar name in this case is "xx" from university $$$B$$$, because it is involved in creating the names "xxxx" and "xxyxx", and it is completely impossible to create any of these without using "xx" from university $$$B$$$.

Given the team names from both universities, your task is to calculate how many peculiar teams are there in each university.

Input

The first line contains two integers, $$$M$$$ and $$$N$$$, separated by a space. The number of teams from university $$$A$$$ is $$$M$$$ and the number of teams from university $$$B$$$ is $$$N$$$.

The second line contains the names of the teams from university $$$A$$$, separated by a space. The third line contains the names of the teams from university $$$B$$$, separated by a space.

All team names consist solely of lower case letters of the English alphabet.

No two teams from the same university have the same name.

$$$1 \le M, N \le 10^5$$$ and the total length of all team names is at most $$$10^6$$$.

Output

Output a line containing two integers: the number of peculiar teams from university $$$A$$$, and the number of peculiar teams from university $$$B$$$, separated by one space.

ExamplesInput
2 2
buen kilo
pan flauta
Output
2 2
Input
2 3
xx xxy
z yz xx
Output
0 1

加入题单

算法标签: