#SGM0000023. Deda (Deda)
Deda (Deda)
Deda
Source: COCI
Version: Phuoc Hung OJ Extended
Problem Statement
There are children whose ages are exactly . A train starts at station and then visits stations .
The story is told in arbitrary order. There are lines, each of one of the following forms:
M X A: the child aged gets off at station .D Y B: among children aged at least , find the youngest child which, according to all statements known so far, gets off no later than station .
If no M statement has been given for a child yet, that child is considered to get off at infinity. Each child appears in at most one M statement.
Input
The first line contains .
Each of the next lines is M X A or D Y B.
Common limits: , . There is at least one D query.
Output
For every D query, print the required age, or -1 if no such child exists.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: .
Examples
Input
3 4
M 10 3
M 5 1
D 20 2
D 5 1
Output
3
1
Explanation
The sample is processed in order; every printed item/line corresponds to an operation that requires output.