VK Cup 2012 Qualification Round 2
B
Matchmaker
Codeforces
1100
原题
← AC →
翻译中…

Polycarpus has $*n*$ markers and $*m*$ marker caps. Each marker is described by two numbers: $*x*_{*i*}$ is the color and $*y*_{*i*}$ is the diameter. Correspondingly, each cap is described by two numbers: $*a*_{*j*}$ is the color and $*b*_{*j*}$ is the diameter. Cap $(*a*_{*j*}, *b*_{*j*})$ can close marker $(*x*_{*i*}, *y*_{*i*})$ only if their diameters match, that is, $*b*_{*j*} = *y*_{*i*}$. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, $*a*_{*j*} = *x*_{*i*}$.

翻译中…

Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.

翻译中…

Input

翻译中…

The first input line contains two space-separated integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 10^{5}$) — the number of markers and the number of caps, correspondingly.

翻译中…

Next $*n*$ lines describe the markers. The $*i*$-th line contains two space-separated integers $*x*_{*i*}$, $*y*_{*i*}$ ($1 ≤ *x*_{*i*}, *y*_{*i*} ≤ 1000$) — the $*i*$-th marker's color and diameter, correspondingly.

翻译中…

Next $*m*$ lines describe the caps. The $*j*$-th line contains two space-separated integers $*a*_{*j*}$, $*b*_{*j*}$ ($1 ≤ *a*_{*j*}, *b*_{*j*} ≤ 1000$) — the color and diameter of the $*j*$-th cap, correspondingly.

翻译中…

Output

翻译中…

Print two space-separated integers $*u*, *v*$, where $*u*$ is the number of closed markers and $*v*$ is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.

翻译中…

Note

翻译中…

In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.

翻译中…

样例

Input #1
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output #1
3 2
InputCopy OutputCopy
Input #2
2 2
1 2
2 1
3 4
5 1
Output #2
1 0
InputCopy OutputCopy
题目信息
题号
159B
时间限制
3 s
内存限制
256 MB
标签
*special
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。