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 Scala (judge verdict: WA: Presentation Error)

import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val hw = readLine.split(" ").map(_.toInt)
    val fld = (for(i<-0 until hw(0)) yield {
      readLine.trim.map(_.asDigit)
    }).toArray
    val rc = readLine.split(" ").map(_.toInt)
    val pattern = (for(i<-0 until rc(0)) yield {
      readLine.trim.map(_.asDigit)
    }).toArray
    val b = new ArrayBuffer[Array[Int]]

    for(i<-0 to (hw(0)-rc(0))) {
      for(j<-0 to (hw(1)-rc(1))) {
        var m = true
        var k = 0
        var l = 0
        while(m && k<rc(0)) {
          if(fld(i+k)(j+l) != pattern(k)(l)) m = false
          if(l==rc(1)-1) { k+=1;l=0 }
          else l += 1
        }
        if(m) b+= Array(i,j)
      }
    }
    println{
      b.sortWith((x,y)=>if(x(0)<y(0)) true else if(x(0)==y(0) && x(1)<y(1)) true else false)
        .map(_.mkString(" ")).mkString("\n")
    }
  }
}