from collections import defaultdict
def solution(record):
answer = []
temp = []
id = defaultdict(str)
for rec in record:
a = list(rec.split())
if a[0] == "Enter":
id[a[1]] = a[2]
temp.append((a[1], 0))
elif a[0] == "Leave":
temp.append((a[1], 1))
else : # a[0] == "Change":
id[a[1]] = a[2]
for t in temp:
a, b = t[0], t[1]
if b==0: #enter
msg = id[a]+"님이 들어왔습니다."
else: #leave
msg = id[a]+"님이 나갔습니다."
answer.append(msg)
return answer