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 Ruby (judge verdict: Wrong Answer)

h, w = gets.split.map(&:to_i)
hw = []
h.times{|i|
  hw[i] = gets.chomp
}
rc_hash = {}
r, c = gets.split.map(&:to_i)
rc = []
r.times{|i|
  rc[i] = gets.chomp
  rc_hash[rc[i]] = 0 unless rc_hash[rc[i]]
  rc_hash[rc[i]] += 1
}

min_val = rc_hash.values.min
min_key = rc_hash.key(min_val)
idx = rc.index(min_key)

p idx
exit if r > h || c > w

hash = Hash.new { |ha,k| ha[k] = Hash.new(&ha.default_proc) }
h.times{|i|
  0.upto(w-c){|j|
    hash[i][hw[i][j,c]][j] = 1
  }
}

#p "hash done"

idx.upto(h-r+idx){|i|
  if hash[i][rc[idx]]
    # find candidate
    hash[i][rc[idx]].each_key{|j|
#      p "can: #{i} #{j}"
      ans = true
      0.upto(r-1){|k|
        unless hw[i-idx+k][j,c] == rc[k] then
          ans = false
          break
        end
      }
      puts "#{i} #{j}" if ans
    }
  end
}