In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].

If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.

The center of Gdynia is located on an island in the middle of the Kacza river. Every morning thousands of cars drive through this island from the residential districts on the western bank of the river (using bridge connections to junctions on the western side of the island) to the industrial areas on the eastern bank (using bridge connections from junctions on the eastern side of the island).

The island resembles a rectangle, whose sides are parallel to the cardinal directions. Hence, we view it as an rectangle in a Cartesian coordinate system, whose opposite corners are in points and .

On the island, there are junctions numbered from to . The junction number has coordinates . If a junction has coordinates of the form , it lies on the western side of the island. Similarly, junctions with the coordinates lie on the eastern side. Junctions are connected by streets. Each street is a line segment connecting two junctions. Streets can be either unidirectional or bidirectional. No two streets may have a common point (except for, possibly, a common end in a junction). There are are no bridges or tunnels. You should not assume anything else about the shape of the road network. In particular, there can be streets going along the river bank or junctions with no incoming or outgoing streets.

Because of the growing traffic density, the city mayor has hired you to check whether the current road network on the island is sufficient. He asked you to write a program which determines how many junctions on the eastern side of the island are reachable from each junction on the western side.

The first line of the standard input contains four integers , , and (, , ). They denote the number of junctions in the center of Gdynia, the number of streets and dimensions of the island, respectively.

In each of the following lines there are two integers , (, ) describing the coordinates of the junction number . No two junctions can have the same coordinates.

The next lines describe the streets. Each street is represented in a single line by three integers , , (, , ). Their meaning is that junctions and are connected with a street. If , then this is a unidirectional street from to . Otherwise, the street can be driven in both directions. Each unordered pair can appear in the input at most once.

You can assume that there is at least one junction on the western side of the island from which it is possible to reach some junction on the eastern side of the island.

Additionally, in test cases worth at least 30 points, .

Your program should write to the standard output one line for each junction
on the western side of the island.
This line should contain the number of junctions on the eastern side that
are reachable from that junction.
The output should be ordered according to *decreasing* -coordinates
of the junctions.

For the input data:

5 3 1 3 0 0 0 1 0 2 1 0 1 1 1 4 1 1 5 2 3 5 2

the correct result is:

2 0 2

Whereas for the input data:

12 13 7 9 0 1 0 3 2 2 5 2 7 1 7 4 7 6 7 7 3 5 0 5 0 9 3 9 1 3 2 3 2 1 3 4 1 4 5 1 5 6 1 9 3 1 9 4 1 9 7 1 9 12 2 10 9 1 11 12 1 12 8 1 12 10 1

the correct result is:

4 4 0 2

*Task author: Jakub Lacki.*