Problem:
Pattern Search

Find places where a R × C pattern is found within a H × W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.

Input

In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.

In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.

output

For each sub-region found, print a coordinate i and j separated by a space character in a line. Print the coordinates in ascending order of the row numbers (i), or the column numbers (j) in case of a tie.

Constraints

1 ≤ H, W ≤ 1000

1 ≤ R, C ≤ 1000

The input consists of alphabetical characters and digits

Sample Input 1

4 5
00010
00101
00010
00100
3 2
10
01
10

Sample Output 1

0 3
1 2

Solution in C++ (judge verdict: Time Limit Exceeded)

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	long H, W, R, C;
	string T[1000], P[1000];
	cin >> H >> W;
	for (long i = 0; i < H; i++){
		cin >> T[i];
	}
	cin >> R >> C;
	if (H < R || W < C) return 0;
	for (long i = 0; i < R; i++){
		cin >> P[i];
	}
	for (long i = 0; i < H - R + 1; i++){
		for (long j = 0; j < W - C + 1; j++){
			if (T[i][j] == P[0][0]){
				if (T[i].substr(j, C) == P[0]){
					if (R == 1) printf("%ld %ld\n", i, j);
					else {
						for (long k = 1; k < R; k++){
							if (T[i + k].substr(j, C) != P[k]) break;
							if (k == R - 1) printf("%ld %ld\n", i, j);
						}
					}
				}
			}
		}
	}
	return 0;
}