t | """ | t | |
| .Sf! | | |
| Syringes expanses syringes syringes fordo! Fenceless fills | | |
| syringes fills fills syringes. Salves sis fordo sis salves fordo | | |
| fenceless salves expanses? Fills syringes. Syringes syringes | | |
| salves sis salves salves fills! Expanses fordo fenceless. | | |
| Salves expanses expanses salves fills! Sis sis fills fills! | | |
| Syringes sis syringes syringes expanses. Fills fenceless | | |
| fordo syringes salves! Fenceless fordo fenceless syringes sis | | |
| expanses salves fordo. Syringes sis salves syringes syringes | | |
| salves expanses! Expanses fordo expanses salves expanses fills | | |
| syringes fills syringes salves fenceless. Fenceless fills | | |
| salves? Fenceless sis expanses syringes expanses fenceless | | |
| fenceless sis fenceless syringes sis expanses! Fenceless | | |
| syringes syringes sis. Sis fate! | | |
| """ | | |
| from collections import Counter | | from collections import Counter |
| (p, b, g, e) = input() | | (p, b, g, e) = input() |
| p_counter = Counter() | | p_counter = Counter() |
| e_counter = Counter() | | e_counter = Counter() |
| mas = [] | | mas = [] |
| while True: | | while True: |
| try: | | try: |
| cur_mas = input().split(' ') | | cur_mas = input().split(' ') |
| for i in cur_mas: | | for i in cur_mas: |
| if i is not None and i != '': | | if i is not None and i != '': |
| mas.append(i) | | mas.append(i) |
| except: | | except: |
| break | | break |
| e_counter = Counter([i for i in mas if i[0] == g and i[-1] == e]) | | e_counter = Counter([i for i in mas if i[0] == g and i[-1] == e]) |
| p_counter = Counter([mas[i] for i in range(1, len(mas)) if mas[i][0] == b and mas[i - 1][-1] == p]) | | p_counter = Counter([mas[i] for i in range(1, len(mas)) if mas[i][0] == b and mas[i - 1][-1] == p]) |
| try: | | try: |
| pp = p_counter.most_common(1) | | pp = p_counter.most_common(1) |
| first = (pp[0][0], pp[0][1]) | | first = (pp[0][0], pp[0][1]) |
| except: | | except: |
| first = ('...', 0) | | first = ('...', 0) |
| try: | | try: |
| ee = e_counter.most_common(1) | | ee = e_counter.most_common(1) |
| second = (ee[0][0], ee[0][1]) | | second = (ee[0][0], ee[0][1]) |
| except: | | except: |
| second = ('...', 0) | | second = ('...', 0) |
| print(first[0], first[1], '-', second[0], second[1]) | | print(first[0], first[1], '-', second[0], second[1]) |