f | import sys | f | import sys |
| from collections import defaultdict | | from collections import defaultdict |
| from random import randint | | from random import randint |
| L = int(input()) | | L = int(input()) |
| Txt = sys.stdin.read().replace('\n ', ' @ ').split() | | Txt = sys.stdin.read().replace('\n ', ' @ ').split() |
| n = len(Txt) | | n = len(Txt) |
n | dect = defaultdict(list) | n | x = defaultdict(list) |
| result = [] | | res = [] |
| for i in range(n - 2): | | for i in range(n - 2): |
t | dect[Txt[i]].append({Txt[i + 1]: Txt[i + 2]}) | t | x[Txt[i]].append({Txt[i + 1]: Txt[i + 2]}) |
| index = randint(0, n - 3) | | i = randint(0, n - 3) |
| while Txt[index].find('.') < 0: | | while Txt[i].find('.') < 0: |
| index = randint(0, n - 3) | | i = randint(0, n - 3) |
| result.append(Txt[index + 1]) | | res.append(Txt[i + 1]) |
| result.append(Txt[index + 2]) | | res.append(Txt[i + 2]) |
| while len(result) < L: | | while len(res) < L: |
| war = [item for item in dect[result[-2]] if result[-1] in item] | | w = [item for item in x[res[-2]] if res[-1] in item] |
| key = randint(0, len(war)) - 1 | | k = randint(0, len(w)) - 1 |
| result.append(war[key].get(result[-1])) | | res.append(w[k].get(res[-1])) |
| result = [el if el != '@' else '\n ' for el in result] | | res = [el if el != '@' else '\n ' for el in res] |
| print(' '.join((str(a) for a in result))) | | print(' '.join((str(v) for v in res))) |