This page is still under construction.

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

Particles

Time limit2sMemory limit512 MB

Summary
Given firing times and speeds of N particles from each of two facing accelerators, report the first K collisions between opposite kinds in chronological order.
Level

Hard8 of 10

Topics
Sorting, Two pointers, Simulation, Implementation
Solved
No attempts yet

Problem

Two linear particle accelerators A and B are placed a distance L apart, facing each other. A fires x-particles toward B, and B fires y-particles toward A. When an x-particle and a y-particle flying against each other meet, they collide and annihilate. Particles of the same kind do not affect each other. An x-particle can overtake another x-particle and a y-particle can overtake another y-particle, and nothing happens to either particle when it does.

At time 0 the two accelerators start firing, N x-particles and N y-particles in total. Each particle moves at its own constant speed. The particles are numbered from 1 to N in the order they are fired, separately for the x-particles and the y-particles.

A particle with speed vv travels the distance s=vts = vt in time tt. The firing moments of the x-particles are 0=tx1<tx2<⋯<txN0 = t_{x1} < t_{x2} < \dots < t_{xN} and their speeds are vx1,vx2,…,vxNv_{x1}, v_{x2}, \dots, v_{xN}. The firing moments of the y-particles are 0=ty1<ty2<⋯<tyN0 = t_{y1} < t_{y2} < \dots < t_{yN} and their speeds are vy1,vy2,…,vyNv_{y1}, v_{y2}, \dots, v_{yN}. The firing satisfies the following two conditions.

  • Every particle collides with a particle of the opposite kind.
  • When two particles collide, every other particle is at distance 1 or more from the collision point. This is guaranteed for the first K collisions.

Write a program that determines the first K collisions between particles of the two kinds.

Input

The first line contains three integers N, L, and K separated by spaces.

Each of the next N lines contains the firing moment txit_{xi} and the speed vxiv_{xi} of an x-particle, separated by a space. The ii-th of these lines describes x-particle ii.

Each of the last N lines contains the firing moment tyit_{yi} and the speed vyiv_{yi} of y-particle ii in the same format.

Output

Print K lines. Each line contains two integers separated by a space: the number of the x-particle and the number of the y-particle of one collision. Print the collisions in the order they happen, from the first one to the K-th.

Constraints

  • 1≤N≤500001 \le N \le 50000
  • 1≤L≤1091 \le L \le 10^9
  • 1≤K≤1001 \le K \le 100, K≤NK \le N
  • 0≤txi,tyi≤1090 \le t_{xi}, t_{yi} \le 10^9
  • 1≤vxi,vyi≤1091 \le v_{xi}, v_{yi} \le 10^9

Examples2

  1. Example 1

    Input
    4 100 2
    0 1
    2 3
    3 2
    6 10
    0 5
    3 10
    5 1
    7 20
    
    Expected output
    4 2
    2 4
    
  2. Example 2

    Input
    1 10 1
    0 1
    0 1
    
    Expected output
    1 1