def main(): for l in L: case1 = challenge(l, A) _, row1, col1, row2, col2 = case1 invert = A[row1-1][col1-1:col2] A[row1-1][col1-1:col2] = list(map(lambda x: int(not x), invert)) print(row1, col1, row2, col2) def challenge(l, grid): maxb = -1 for i, r in enumerate(grid): for j in range(N + 1 - l): black = r[j:j+l].count(1) if l == black == 1: if (not j and not r[j+1]) or (j == N - 1 and not r[j-1]) or r[j-1] == r[j+1] == 0: maxb = black row = i + 1 ret = [maxb, row, j + 1, row, j + l] return ret if maxb <= black: maxb = black row = i + 1 ret = [maxb, row, j + 1, row, j + l] return ret N, K = map(int, input().split()) L = tuple(map(int, input().split())) A = [list(map(int, list(input()))) for _ in [0] * N] main()