cswork / OAOpen practice workspace

OuraOA #1

Assign Server Numbers by Type

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsHashingIterators

Each server type is numbered independently; an allocation uses the smallest positive integer not currently in use, and a released number can be reused.

The standard input/output format and supplementary bounds on this site are as defined in this problem statement.

Input

The first line contains q (1≤q≤2×10^5), followed by q lines allocate type or deallocate type id. Type names contain no spaces; a released id is guaranteed to be currently allocated.

Output

Output the number assigned by each allocate on its own line.

Example 1

Input:

8
allocate db
allocate db
allocate cache
deallocate db 1
allocate db
allocate cache
deallocate cache 1
allocate cache

Output:

1
2
1
1
2
1

Example 2

Input:

4
allocate a
deallocate a 1
allocate a
allocate b

Output:

1
1
1

Example 3

Input:

4
allocate a
allocate b
deallocate b 1
allocate b

Output:

1
1
1

Editorial

Loading solution…