Codeforces Round 141 (Div. 2)
B
Two Tables
Codeforces
1400
原题
← AC →
翻译中…

You've got two rectangular tables with sizes $*n*_{*a*} × *m*_{*a*}$ and $*n*_{*b*} × *m*_{*b*}$ cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the $*i*$-th row and the $*j*$-th column, as $*a*_{*i*, *j*}$; we will define the element of the second table, located at the intersection of the $*i*$-th row and the $*j*$-th column, as $*b*_{*i*, *j*}$.

翻译中…

We will call the pair of integers $(*x*, *y*)$ a shift of the second table relative to the first one. We'll call the overlap factor of the shift $(*x*, *y*)$ value:

翻译中…

image

翻译中…

where the variables $*i*, *j*$ take only such values, in which the expression $*a*_{*i*, *j*}·*b*_{*i* + *x*, *j* + *y*}$ makes sense. More formally, inequalities $1 ≤ *i* ≤ *n*_{*a*}, 1 ≤ *j* ≤ *m*_{*a*}, 1 ≤ *i* + *x* ≤ *n*_{*b*}, 1 ≤ *j* + *y* ≤ *m*_{*b*}$ must hold. If there are no values of variables $*i*, *j*$, that satisfy the given inequalities, the value of the sum is considered equal to 0.

翻译中…

Your task is to find the shift with the maximum overlap factor among all possible shifts.

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*n*_{*a*}, *m*_{*a*}$ $(1 ≤ *n*_{*a*}, *m*_{*a*} ≤ 50)$ — the number of rows and columns in the first table. Then $*n*_{*a*}$ lines contain $*m*_{*a*}$ characters each — the elements of the first table. Each character is either a "0", or a "1".

翻译中…

The next line contains two space-separated integers $*n*_{*b*}, *m*_{*b*}$ $(1 ≤ *n*_{*b*}, *m*_{*b*} ≤ 50)$ — the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.

翻译中…

It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".

翻译中…

Output

翻译中…

Print two space-separated integers $*x*, *y*$ $(|*x*|, |*y*| ≤ 10^{9})$ — a shift with maximum overlap factor. If there are multiple solutions, print any of them.

翻译中…

样例

Input #1
3 2
01
10
00
2 3
001
111
Output #1
0 1
InputCopy OutputCopy
Input #2
3 3
000
010
000
1 1
1
Output #2
-1 -1
InputCopy OutputCopy
题目信息
题号
228B
时间限制
2 s
内存限制
256 MB
标签
暴力
模拟

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