| t | import sys | t | import sys |
| import unicodedata as u | | import unicodedata as u |
| | | |
| def box(name: str) -> str: | | def box(name: str) -> str: |
| return u.lookup('BOX DRAWINGS ' + name) | | return u.lookup('BOX DRAWINGS ' + name) |
| HORIZ = {'LIGHT': box('LIGHT HORIZONTAL'), 'HEAVY': box('HEAVY HORIZONTA | | HORIZ = {'LIGHT': box('LIGHT HORIZONTAL'), 'HEAVY': box('HEAVY HORIZONTA |
| L')} | | L')} |
| VERT = {'LIGHT': box('LIGHT VERTICAL'), 'HEAVY': box('HEAVY VERTICAL')} | | VERT = {'LIGHT': box('LIGHT VERTICAL'), 'HEAVY': box('HEAVY VERTICAL')} |
| C_TL = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND RIGHT'), ('LIGHT', 'HEAV | | C_TL = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND RIGHT'), ('LIGHT', 'HEAV |
| Y'): box('DOWN LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HE | | Y'): box('DOWN LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HE |
| AVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND RIGHT')} | | AVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND RIGHT')} |
| C_TR = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND LEFT'), ('LIGHT', 'HEAVY | | C_TR = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND LEFT'), ('LIGHT', 'HEAVY |
| '): box('DOWN LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HEAV | | '): box('DOWN LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HEAV |
| Y AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND LEFT')} | | Y AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND LEFT')} |
| C_BL = {('LIGHT', 'LIGHT'): box('LIGHT UP AND RIGHT'), ('LIGHT', 'HEAVY' | | C_BL = {('LIGHT', 'LIGHT'): box('LIGHT UP AND RIGHT'), ('LIGHT', 'HEAVY' |
| ): box('UP LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AN | | ): box('UP LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AN |
| D RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND RIGHT')} | | D RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND RIGHT')} |
| C_BR = {('LIGHT', 'LIGHT'): box('LIGHT UP AND LEFT'), ('LIGHT', 'HEAVY') | | C_BR = {('LIGHT', 'LIGHT'): box('LIGHT UP AND LEFT'), ('LIGHT', 'HEAVY') |
| : box('UP LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AND | | : box('UP LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AND |
| LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND LEFT')} | | LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND LEFT')} |
| V_MID_L = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND RIGHT'), ('LIGHT' | | V_MID_L = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND RIGHT'), ('LIGHT' |
| , 'HEAVY'): box('VERTICAL LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): b | | , 'HEAVY'): box('VERTICAL LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): b |
| ox('VERTICAL HEAVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VER | | ox('VERTICAL HEAVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VER |
| TICAL AND RIGHT')} | | TICAL AND RIGHT')} |
| V_MID_R = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND LEFT'), ('LIGHT', | | V_MID_R = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND LEFT'), ('LIGHT', |
| 'HEAVY'): box('VERTICAL LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box | | 'HEAVY'): box('VERTICAL LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box |
| ('VERTICAL HEAVY AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VERTIC | | ('VERTICAL HEAVY AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VERTIC |
| AL AND LEFT')} | | AL AND LEFT')} |
| CROSS = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND HORIZONTAL'), ('LIG | | CROSS = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND HORIZONTAL'), ('LIG |
| HT', 'HEAVY'): box('VERTICAL LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LI | | HT', 'HEAVY'): box('VERTICAL LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LI |
| GHT'): box('VERTICAL HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): b | | GHT'): box('VERTICAL HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): b |
| ox('HEAVY VERTICAL AND HORIZONTAL')} | | ox('HEAVY VERTICAL AND HORIZONTAL')} |
| T_UP = {('LIGHT', 'LIGHT'): box('LIGHT UP AND HORIZONTAL'), ('LIGHT', 'H | | T_UP = {('LIGHT', 'LIGHT'): box('LIGHT UP AND HORIZONTAL'), ('LIGHT', 'H |
| EAVY'): box('UP LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): box('U | | EAVY'): box('UP LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): box('U |
| P HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND HO | | P HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND HO |
| RIZONTAL')} | | RIZONTAL')} |
| T_DOWN = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND HORIZONTAL'), ('LIGHT' | | T_DOWN = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND HORIZONTAL'), ('LIGHT' |
| , 'HEAVY'): box('DOWN LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): | | , 'HEAVY'): box('DOWN LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): |
| box('DOWN HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY D | | box('DOWN HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY D |
| OWN AND HORIZONTAL')} | | OWN AND HORIZONTAL')} |
| | | |
| def main(): | | def main(): |
| text = sys.stdin.readline().rstrip('\n') | | text = sys.stdin.readline().rstrip('\n') |
| params = sys.stdin.readline().split() | | params = sys.stdin.readline().split() |
| width = int(params[0]) | | width = int(params[0]) |
| v_thick = params[1] | | v_thick = params[1] |
| h_thick = params[2] | | h_thick = params[2] |
| combo = (v_thick, h_thick) | | combo = (v_thick, h_thick) |
| inner = width - 2 | | inner = width - 2 |
| words = text.split() | | words = text.split() |
| lines_words = [] | | lines_words = [] |
| curr = [] | | curr = [] |
| curr_len = 0 | | curr_len = 0 |
| for w in words: | | for w in words: |
| L = len(w) | | L = len(w) |
| if not curr: | | if not curr: |
| curr = [w] | | curr = [w] |
| curr_len = L | | curr_len = L |
| else: | | else: |
| needed = curr_len + L + len(curr) | | needed = curr_len + L + len(curr) |
| if needed <= inner: | | if needed <= inner: |
| curr.append(w) | | curr.append(w) |
| curr_len += L | | curr_len += L |
| else: | | else: |
| lines_words.append(curr) | | lines_words.append(curr) |
| curr = [w] | | curr = [w] |
| curr_len = L | | curr_len = L |
| if curr: | | if curr: |
| lines_words.append(curr) | | lines_words.append(curr) |
| line_infos = [] | | line_infos = [] |
| vert_sets = [] | | vert_sets = [] |
| for line in lines_words: | | for line in lines_words: |
| k = len(line) | | k = len(line) |
| lens = [len(w) for w in line] | | lens = [len(w) for w in line] |
| base = sum(lens) + (k - 1) | | base = sum(lens) + (k - 1) |
| extra = inner - base | | extra = inner - base |
| lens[-1] += extra | | lens[-1] += extra |
| vpos = {0} | | vpos = {0} |
| pos = 1 | | pos = 1 |
| for wlen in lens[:-1]: | | for wlen in lens[:-1]: |
| pos += wlen | | pos += wlen |
| vpos.add(pos) | | vpos.add(pos) |
| pos += 1 | | pos += 1 |
| vpos.add(width - 1) | | vpos.add(width - 1) |
| vert_sets.append(vpos) | | vert_sets.append(vpos) |
| line_infos.append((line, lens)) | | line_infos.append((line, lens)) |
| v_char = VERT[v_thick] | | v_char = VERT[v_thick] |
| | | |
| def make_hrow(up_set, down_set): | | def make_hrow(up_set, down_set): |
| row = [] | | row = [] |
| for x in range(width): | | for x in range(width): |
| up = x in up_set | | up = x in up_set |
| down = x in down_set | | down = x in down_set |
| if x == 0: | | if x == 0: |
| if up and down: | | if up and down: |
| ch = V_MID_L[combo] | | ch = V_MID_L[combo] |
| elif down and (not up): | | elif down and (not up): |
| ch = C_TL[combo] | | ch = C_TL[combo] |
| elif up and (not down): | | elif up and (not down): |
| ch = C_BL[combo] | | ch = C_BL[combo] |
| else: | | else: |
| ch = HORIZ[h_thick] | | ch = HORIZ[h_thick] |
| elif x == width - 1: | | elif x == width - 1: |
| if up and down: | | if up and down: |
| ch = V_MID_R[combo] | | ch = V_MID_R[combo] |
| elif down and (not up): | | elif down and (not up): |
| ch = C_TR[combo] | | ch = C_TR[combo] |
| elif up and (not down): | | elif up and (not down): |
| ch = C_BR[combo] | | ch = C_BR[combo] |
| else: | | else: |
| ch = HORIZ[h_thick] | | ch = HORIZ[h_thick] |
| elif up and down: | | elif up and down: |
| ch = CROSS[combo] | | ch = CROSS[combo] |
| elif down and (not up): | | elif down and (not up): |
| ch = T_DOWN[combo] | | ch = T_DOWN[combo] |
| elif up and (not down): | | elif up and (not down): |
| ch = T_UP[combo] | | ch = T_UP[combo] |
| else: | | else: |
| ch = HORIZ[h_thick] | | ch = HORIZ[h_thick] |
| row.append(ch) | | row.append(ch) |
| return ''.join(row) | | return ''.join(row) |
| out_lines = [] | | out_lines = [] |
| out_lines.append(make_hrow(set(), vert_sets[0])) | | out_lines.append(make_hrow(set(), vert_sets[0])) |
| for i, (words_line, cell_widths) in enumerate(line_infos): | | for i, (words_line, cell_widths) in enumerate(line_infos): |
| line = [v_char] | | line = [v_char] |
| for w, wlen in zip(words_line, cell_widths): | | for w, wlen in zip(words_line, cell_widths): |
| line.append(w.ljust(wlen)) | | line.append(w.ljust(wlen)) |
| line.append(v_char) | | line.append(v_char) |
| out_lines.append(''.join(line)) | | out_lines.append(''.join(line)) |
| if i + 1 < len(line_infos): | | if i + 1 < len(line_infos): |
| out_lines.append(make_hrow(vert_sets[i], vert_sets[i + 1])) | | out_lines.append(make_hrow(vert_sets[i], vert_sets[i + 1])) |
| else: | | else: |
| out_lines.append(make_hrow(vert_sets[i], set())) | | out_lines.append(make_hrow(vert_sets[i], set())) |
| print('\n'.join(out_lines)) | | print('\n'.join(out_lines)) |
| if __name__ == '__main__': | | if __name__ == '__main__': |
| main() | | main() |