items = list(map(int, input().split(",")))
link = []
head = 0
for i in items:
link.append([i, len(link) + 1])
link[-1][1] = -1
……p = head
while p != -1:
print(link[p][0], end=",")
p = link[p][1]
items = list(map(int, input().split(","))) link = [] for i in items: link.append([i, len(link) + 1]) ... ... head = __________ p = head while p != -1: print(link[p][0], end=",") p = link[p][1]