시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 27 8 5 50.000%

문제

메모리 할당 명령을 시뮬레이팅하는 프로그램을 작성하시오.

메모리는 100,000개의 연속된 공간이고, 1번부터 100,000번까지 번호가 매겨져 있다.

제일 처음에 모든 공간은 할당되지 않은 상태이다.

명령어의 종류는 다음 중 하나이다.

1. var=malloc(size);

이 함수은 처음 등장하는 size개의 연속된 공간을 찾아, 할당해주는 함수이다. 이 함수의 리턴값은 할당된 공간의 제일 처음 주소이다. 만약, 할당해줄 수 있는 공간이 없다면 0을 리턴한다.

2. free(var);

이 함수는 이전에 malloc을 통해 var에 할당된 공간을 할당 해제시켜주고, var에 0을 저장하는 함수이다. 만약, var가 이미 0이라면, 아무 일도 일어나지 않는다.

3. print(var);

var에 저장된 값을 출력하는 함수이다.

모든 명령은 세미콜론(';')으로 끝난다.

변수는 알파벳 소문자로 이루어져 있으며, 항상 네글자이다.

서로 다른 변수의 개수는 1,000개보다 작거나 같다.

모든 변수는 0으로 초기화되어있다.

입력

첫재 줄에 명령의 개수 N이 주어진다. (1 ≤ N ≤ 100,000)

다음 N개의 줄에는 명령이 수행된 순서 대로 하나씩 주어진다.

적어도 하나의 명령은 print이다.

출력

print가 나올 때 마다 결과를 한 줄에 하나씩 출력한다.

예제 입력 1

5
baka=malloc(214);
baka=malloc(123);
free(baka);
deda=malloc(100);
print(deda);

예제 출력 1

215
W3sicHJvYmxlbV9pZCI6IjMyMTciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJtYWxsb2MiLCJkZXNjcmlwdGlvbiI6IjxwPlxyXG5cdFx1YmE1NFx1YmFhOFx1YjlhYyBcdWQ1NjBcdWIyZjkgXHViYTg1XHViODM5XHVjNzQ0IFx1YzJkY1x1YmJhY1x1YjgwOFx1Yzc3NFx1ZDMwNVx1ZDU1OFx1YjI5NCBcdWQ1MDRcdWI4NWNcdWFkZjhcdWI3YThcdWM3NDQgXHVjNzkxXHVjMTMxXHVkNT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