PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000057. Động lực học chất lỏng (Fluid Dynamics)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Động lực học chất lỏng (Fluid Dynamics)

Fluid Dynamics

Source: DMOJ

Version: Phuoc Hung OJ Extended

Problem Statement

A jar contains an ordered stack of fluid layers, from bottom to top. Each layer has integer volume vv and color cc; fluids never merge, even if their colors match. Initially empty, the jar receives NN initial layers one at a time at the top.

When a newly inserted layer A=(vA,cA)A=(v_A,c_A) sits immediately above B=(vB,cB)B=(v_B,c_B), they swap if the change in potential satisfies

Δϕ=vAcB−vBcA≥W.\Delta\phi=v_Ac_B-v_Bc_A\ge W.

If a swap happens, the new layer continues testing against the next layer below until a swap is forbidden or it reaches the bottom. This applies to both initial and later insertions.

Process:

  • INSERT v c: add a layer on top and perform these swaps.
  • K-TH k: print the volume and color of the kk-th layer from the bottom (one-indexed).

Every K-TH index is valid.

Input

The first line contains N,Q,WN,Q,W. The next NN lines contain the initial pairs v_i c_i in pouring order. Each of the following QQ lines is INSERT v c or K-TH k. All volume/color values are in [1,109][1,10^9], and 1≤W≤10141\le W\le10^{14}.

Output

For every K-TH operation, print the corresponding layer's volume and color.

Subtasks

  • Subtask 1 (10 points): 1≤n≤10001\le n\le1000; 1≤q≤10001\le q\le1000. Use an integer type wide enough for exact comparisons, with 1≤W≤10141\le W\le10^{14}.
  • Subtask 2 (90 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000. Use an integer type wide enough for exact comparisons, with 1≤W≤10141\le W\le10^{14}.

Examples

Input

5 5 7
15 2
20 12
7 16
7 12
20 3
K-TH 2
INSERT 1 10
INSERT 8 1
INSERT 9 1
K-TH 6

Output

20 3
7 12

Explanation

With W=7W=7, placing (7,12)(7,12) above (7,16)(7,16) gives potential change 7⋅16−7⋅12=28≥77\cdot16-7\cdot12=28\ge7, so they swap. Layer (20,3)(20,3) descends past several layers but stops above (15,2)(15,2). Thus K-TH 2 returns 20 3. After the subsequent insertions, the sixth layer from the bottom is (7,12)(7,12), so the final result is 7 12.