t | from collections import defaultdict | t | from collections import defaultdict |
| players = defaultdict(set) | | players = defaultdict(set) |
| decks = defaultdict(set) | | decks = defaultdict(set) |
| while (buff := input()): | | while (buff := input()): |
| buff = [e.strip() for e in buff.split('/')] | | buff = [e.strip() for e in buff.split('/')] |
| if buff[0].isdigit(): | | if buff[0].isdigit(): |
| decks[int(buff[0])].add(buff[-1]) | | decks[int(buff[0])].add(buff[-1]) |
| else: | | else: |
| players[buff[0]].add(int(buff[-1])) | | players[buff[0]].add(int(buff[-1])) |
| player_cards = defaultdict(int) | | player_cards = defaultdict(int) |
| for (player, deck) in players.items(): | | for (player, deck) in players.items(): |
| tmp = set() | | tmp = set() |
| for i in deck: | | for i in deck: |
| tmp |= decks[i] | | tmp |= decks[i] |
| player_cards[player] = len(tmp) | | player_cards[player] = len(tmp) |
| a = sorted([(deck, player) for (player, deck) in player_cards.items()], key=lambda x: (-x[0], x[1])) | | a = sorted([(deck, player) for (player, deck) in player_cards.items()], key=lambda x: (-x[0], x[1])) |
| print(*[player[1] for player in a if player[0] == a[0][0] != 0], sep='\n') | | print(*[player[1] for player in a if player[0] == a[0][0] != 0], sep='\n') |