We Don't Wanna Work!

Maintain a dynamic set of members whose top floor(20%) by motivation and join time are workhorses, and log every time a member's status flips after each join or departure.

Medium7TreeSortingImplementationBinary searchInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

ACM is an organization that holds programming contests. What ACM is for does not matter to you. The only thing that matters is that the work styles of its members are polarized: each member is either a workhorse or an idle fellow.

Each member of ACM has a motivation level. The members are ranked by motivation level. A member with a higher motivation level is ranked higher, and when several members have the same motivation level, the member who joined ACM later is ranked higher. The top 20% of the ranking work hard, and the other 80% never (!) work. If 20% of the number of members is not an integer, the fractional part is rounded down.

You, a manager of ACM, wanted to know whether each member is a workhorse or an idle fellow so that you can manage ACM. You have finally finished evaluating the motivation levels of all current members. Your task is not done yet, though, because the membership of ACM changes from day to day as members join and leave. So you want to record every moment when a member changes from a workhorse to an idle fellow, or the other way around.

You are given the list of the current members of ACM and their motivation levels, in chronological order of the date each member joined. You are also given the list of joins and departures in chronological order.

Write a program that computes every change of work style among the members of ACM.

Input

The first line contains a single integer N (1 ≤ N ≤ 50,000), the number of initial members of ACM. The i-th of the next N lines contains a string sis_i and an integer aia_i (0 ≤ aia_i10510^5), separated by a single space. sis_i is the name of the i-th initial member and aia_i is that member's motivation level. Each character of sis_i is an English letter, and 1 ≤ si|s_i| ≤ 20. These N lines are sorted in chronological order of the date each member joined ACM.

Line N + 2 contains a single integer M (1 ≤ M ≤ 20,000), the number of membership changes. The j-th of the next M lines describes the j-th join or departure. When the j-th event is a join, the line has the form "+ tjt_j bjb_j", where tjt_j is the name of the joining member and bjb_j (0 ≤ bjb_j10510^5) is that member's motivation level. When the j-th event is a departure, the line has the form "- tjt_j", where tjt_j is the name of the departing member. Each character of tjt_j is an English letter, and 1 ≤ tj|t_j| ≤ 20. Uppercase and lowercase letters are distinct. These M lines are sorted in chronological order of the date each event happened.

No two join or departure events happen at the same time. No two members have the same name at the same time, but a member who left ACM once may join ACM again.

Output

Print the log, a sequence of changes in chronological order. Whenever one of the following two changes happens, print the message for that change on its own line.

  • Member name begins to work hard: "name is working hard now."
  • Member name stops working: "name is not working now."

For each join or departure, the changes happen in the following order.

  1. One member joins or leaves.
  2. When a member joins, that member is added either to the workhorses or to the idle fellows.
  3. One other member may change from a workhorse to an idle fellow, or the other way around. There is never a case where two or more members change their work style at the same time.

Hint

First test case: initially nobody works because 4 × 20% < 1. When one member joins ACM, Durett begins to work hard.

Second test case: nobody works.

Fourth test case: a member may join and leave repeatedly.