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