import sys
input = sys.stdin.readline
'''
각 문제들의 logic은 같음, 가독성 차이임
각 문제들의 logic은 같음, 가독성 차이임
각 문제들의 logic은 같음, 가독성 차이임
'''
def solution(tup):
answer = []
tup = tup[2:-2]
tup = tup.split('},{')
tup = [tuple(map(int, t.split(',')))
for t in tup]
tup.sort(key=len)
for t in tup:
answer.append([x for x in t if x not in answer][0])
return answer
def solution(tup):
answer = []
tup = sorted([tuple(map(int, t.split(',')))
for t in tup[2:-2].split('},{')], key=len)
for t in tup:
answer.append([x for x in t if x not in answer][0])
return answer
print(solution("{{2},{2,1},{2,1,3},{2,1,3,4}}"))