import heapq
def solution(s):
answer = []
stack = []
temp = []
num_list = []
for i in s:
temp.append(i)
if i=='}':
temp.append(i)
stack.append(''.join(temp))
temp = []
# print(stack)
for chunk in stack:
temp = chunk.split(",")
nums = []
for t in temp:
t = t.replace('{','')
t = t.replace('}','')
if t != '':
nums.append(int(t))
if nums:
heapq.heappush(num_list, (len(nums),nums))
while num_list:
ns = heapq.heappop(num_list)[1]
# print(ns, end=", ")
for n in ns:
if n not in answer:
answer.append(n)
return answer