n | rect = [] | n | t = [] |
| while (s := input()): | | while (el := input()): |
| ss = s.split() | | lst = list(el.split()) |
| if ss[2] != '0' and ss[3] != '0': | | if lst[2] != '0' and lst[3] != '0': |
| r = list(map(int, ss[:-1])) | | tmp = list(map(int, lst[:-1])) |
| if r[2] < 0: | | if tmp[2] < 0: |
| r[0] += r[2] | | tmp[0] += tmp[2] |
| r[2] = abs(r[2]) | | tmp[2] = abs(tmp[2]) |
| if r[3] < 0: | | if tmp[3] < 0: |
| r[1] += r[3] | | tmp[1] += tmp[3] |
| r[3] = abs(r[3]) | | tmp[3] = abs(tmp[3]) |
| rect.append(r) | | t.append(tmp) |
| rect[-1].append(ss[-1]) | | t[-1].append(lst[-1]) |
| h = [] | | s = [] |
| h.append([]) | | s.append([]) |
| h.append([]) | | s.append([]) |
| for obj in rect: | | for arr in t: |
| h[0].append(obj[0] + obj[2]) | | s[0].append(arr[0] + arr[2]) |
| h[1].append(obj[1] + obj[3]) | | s[1].append(arr[1] + arr[3]) |
| for obj in rect: | | for arr in t: |
| h[0].append(obj[0]) | | s[0].append(arr[0]) |
| h[1].append(obj[1]) | | s[1].append(arr[1]) |
| minw = min(range(len(h[0])), key=h[0].__getitem__) | | min_width = min(range(len(s[0])), key=s[0].__getitem__) |
| maxw = max(range(len(h[0])), key=h[0].__getitem__) | | max_width = max(range(len(s[0])), key=s[0].__getitem__) |
| minh = min(range(len(h[1])), key=h[1].__getitem__) | | min_height = min(range(len(s[1])), key=s[1].__getitem__) |
| maxh = max(range(len(h[1])), key=h[1].__getitem__) | | max_height = max(range(len(s[1])), key=s[1].__getitem__) |
| if minh == maxh: | | if min_width == max_width: |
| height = h[1][0] | | width = s[0][0] |
| else: | | else: |
n | height = h[1][maxh] - h[1][minh] | n | width = s[0][max_width] - s[0][min_width] |
| if minw == maxw: | | if min_height == max_height: |
| width = h[0][0] | | height = s[1][0] |
| else: | | else: |
t | width = h[0][maxw] - h[0][minw] | t | height = s[1][max_height] - s[1][min_height] |
| for (x, y) in enumerate(rect): | | for (i, arr) in enumerate(t): |
| if x != minw: | | if i != min_width: |
| rect[x][0] -= h[0][minw] | | t[i][0] -= s[0][min_width] |
| if x != minh: | | if i != min_height: |
| rect[x][1] -= h[1][minh] | | t[i][1] -= s[1][min_height] |
| res = [['.' for i in range(width)] for j in range(height)] | | ans = [['.' for i in range(width)] for j in range(height)] |
| for obj in rect: | | for el in t: |
| w = obj[0] | | w = el[0] |
| hh = obj[1] | | h = el[1] |
| r = abs(obj[2]) | | sd_r = abs(el[2]) |
| n = abs(obj[3]) | | sd_n = abs(el[3]) |
| for i in range(hh, hh + n): | | for i in range(h, h + sd_n): |
| for j in range(w, w + r): | | for j in range(w, w + sd_r): |
| res[i][j] = obj[4] | | ans[i][j] = el[4] |
| for obj in res: | | for el in ans: |
| print(*obj, sep='') | | print(*el, sep='') |