Memory Allocation Simulator

Time limit1sMemory limit128 MB

Problem

Write a program that executes memory allocation commands in order.

The memory consists of 100,000 consecutive cells, addressed from 1 to 100,000. Initially, every cell is free.

Each command is one of the following.

  1. var=malloc(size);
    • Find the earliest starting address of a contiguous free block of length size. If such a block exists, allocate it and store its starting address in var. If no such block exists, store 0. (100 ≤ size ≤ 100,000)
    • If var already stores another address, that old allocation is not freed automatically.
  2. free(var);
    • If var stores the starting address of a block from a previous successful malloc, free that block and store 0 in var. If var is already 0, nothing happens.
  3. print(var);
    • Output the value stored in var.

Every command ends with a semicolon (;). A variable name consists of exactly four lowercase English letters. There are at most 1,000 distinct variables, and every variable is initialized to 0.

Input

The first line contains the number of commands N. (1 ≤ N ≤ 100,000)

Each of the next N lines contains one command, in the order it is executed.

At least one print command is given.

Output

For each print command, output its result on its own line.