import re
w, h = map(int, input().split())
lst = [input() for _ in range(h)]
base = [(x, len(x)) for x in re.split(r'(\s+)', lst[-1]) if len(x) > 0]
print(base)
j = 0
start = []
for s, l in base:
if s[0] == "#":
start.append((j, j + l))
j += l
ans = []
for a, b in start:
i = h - 1
while i - 1 >= 0 and any(c != ' ' for c in lst[i - 1][a: b]):
i -= 1
ans.append(('\n'.join(lst[k][a: b].rstrip() for k in range(i, h)), h - i))
max_height = max(y for x, y in ans)
print('\n'.join(lst))
print(start)
print(ans)
To embed this program on your website, copy the following code and paste it into your website's HTML: