#!python # -*- coding: utf-8 -*- from pprint import pprint import pyperclip PRINT_STR = "" def output(y1, x1, y2, x2): global PRINT_STR PRINT_STR += "{} {} {} {}\n".format(y1, x1, y2, x2) def updete(grid, y1, x1, y2, x2): if y1 == y2: y = y1 for x in range(x1, x2 + 1): grid[y][x] *= -1 elif x1 == x2: x = x1 for y in range(y1, y2 + 1): grid[y][x] *= -1 def get_region(N, grid, length): global TOTAL_SCORE max_score = float('-inf') max_score_region = (0, 0, 0, 0) for y in range(N): for x in range(N - length + 1): if x == 0: score = 0 for i in range(length): score += grid[y][i] else: score -= grid[y][x - 1] score += grid[y][x + length - 1] if max_score < score: max_score = score max_score_region = (y, x, y, x + length - 1) for x in range(N): for y in range(N - length + 1): if y == 0: score = 0 for i in range(length): score += grid[i][x] else: score -= grid[y - 1][x] score += grid[y + length - 1][x] if max_score < score: max_score = score max_score_region = (y, x, y + length - 1, x) return max_score_region def main(): N, K = map(int, input().split()) L = [[int(n), i] for i, n in enumerate(input().split())] L.sort(reverse=True, key=(lambda a: a[0])) grid = [] for i in range(N): grid.append([]) for c in input(): grid[-1].append((c == '1') * 2 - 1) for k in range(K): L[k].append(get_region(N, grid, L[k][0])) updete(grid, *L[k][2]) L.sort(key=(lambda a: a[1])) for a in L: output(*[i + 1 for i in a[2]]) if __name__ == '__main__': main() print(PRINT_STR)