This page is still under construction.

Parts of this page are still being built. What you see may change.

Problem Recommendation System Version 1

Time limit1sMemory limit512 MB

Summary
Maintain a set of problems with difficulty values under add, remove, and query commands that ask for the hardest or easiest problem with a tie-break on problem number.
Level

Medium5 of 10

Topics
Heap, Hash map, Implementation, Sorting
Solved
No attempts yet

Problem

tony9402 recently picked problems for coding test practice on GitHub and organized them by "problem number, difficulty".

He wants to add a new feature for people who study using GitHub.

There are three commands he wants to build. The table below describes each command.

recommend xxIf xx is 1, print the number of the hardest problem in the recommended problem list. If there are several hardest problems, print the one with the largest problem number. If xx is -1, print the number of the easiest problem in the recommended problem list. If there are several easiest problems, print the one with the smallest problem number.
add PP LLAdd problem number PP with difficulty LL to the recommended problem list. (Only a problem number PP that is not in the recommended problem list is given as input. A problem number that was in the recommended problem list before can come back with a different difficulty.)
solved PPRemove problem number PP from the recommended problem list. (Only a problem number PP that is in the recommended problem list is given as input.)

The command recommend is given only when the recommended problem list has at least one problem.

The command solved is given only when the recommended problem list has at least one problem number.

Build a recommendation system that performs the commands above.

Input

The first line gives the number of problems NN in the recommended problem list.

From the second line to line N+1N + 1, problem number PP and difficulty LL are given, separated by a space.

Line N+2N + 2 gives the number of commands MM to be entered.

From the next line, MM commands described above are entered.

Output

Every time a recommend command is given, print the problem number, one per line. At least one recommend command is given.

Constraints

  • 1≤N,P≤100,0001 \le N, P \le 100,000
  • 1≤M≤10,0001 \le M \le 10,000
  • 1≤L≤1001 \le L \le 100, LL is a positive integer
  • x=±1x = \pm 1

Examples1

  1. Example 1

    Input
    5
    1000 1
    1001 2
    19998 78
    2667 37
    2042 55
    8
    add 1402 59
    recommend 1
    solved 1000
    solved 19998
    recommend 1
    recommend -1
    solved 1001
    recommend -1
    
    Expected output
    19998
    1402
    1001
    2667