from collections import defaultdict


class Counter:
    def __init__(self) -> None:
        self._counts = defaultdict(lambda: 0)  # type: ignore

    def add(self, n: int) -> None:
        self._counts[n] += 1

    def remove(self, n: int) -> None:
        self._counts[n] -= 1
        if self._counts[n] <= 0:
            del self._counts[n]

    def len(self) -> int:
        return len(self._counts)


H, W, N, h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

cnt = Counter()
for i in range(H):
    for j in range(W):
        if i < h and j < w:
            continue
        cnt.add(A[i][j])

ans = [[0 for _ in range(W - w + 1)] for _ in range(H - h + 1)]
for i in range(H - h + 1):
    for j in range(W - w + 1):
        if i % 2 == 0:
            ans[i][j] = cnt.len()
            if j == W - w:
                for jj in range(j, j + w):
                    cnt.add(A[i][jj])
                    if i + h < H:
                        cnt.remove(A[i + h][jj])
            else:
                for ii in range(i, i + h):
                    cnt.add(A[ii][j])
                    cnt.remove(A[ii][j + w])
        else:
            jr = W - w - j
            ans[i][jr] = cnt.len()
            if jr == 0:
                for jj in range(jr, jr + w):
                    cnt.add(A[i][jj])
                    if i + h < H:
                        cnt.remove(A[i + h][jj])
            else:
                for ii in range(i, i + h):
                    cnt.remove(A[ii][jr - 1])
                    cnt.add(A[ii][jr + w - 1])


for i in range(H - h + 1):
    print(" ".join(map(str, ans[i])))
