Crossing the Railways

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Isona is in a train station. This station has two platforms, and between them there are mm parallel railways that can be viewed as infinite straight lines. Each railway is identified with an integer from 11 to mm, railway 11 being the closest to the first platform and railway mm being the farthest. There is a 11 meter distance between consecutive railways, as well as between each platform and its closest railway.

Isona is standing on the inner border of the first platform, when she realizes that she forgot to validate her ticket! There is a validating machine on the second platform, exactly opposite her current position (thus, the distance between Isona and the validating machine is m+1m + 1 meters). There are only ss seconds left to validate the ticket and the bridge designated to cross the railways is too far from the validating machine. Therefore, Isona (who is very brave and a little bit careless) will cross the railways running in a straight line perpendicular to the railways themselves. Isona can only run forward (not backward) and she can stay still. When she runs at maximum speed, she needs vv seconds to traverse 11 meter. She can run at any speed less than or equal to her maximum speed.

There is only one problem: nn trains are programmed to transit through the railways. The ii-th train will use the railway r_ir\_i. It will start crossing the straight line between Isona and the validating machine a_ia\_i seconds from now and it will end b_ib\_i seconds from now. Of course, Isona cannot cross a railway when a train is passing. Formally, for every i=1,2,,ni = 1, 2, \dots , n, Isona is not allowed to be on railway r_ir\_i at any time tt with a_i<t<b_ia\_i < t < b\_i (but she is allowed to cross at times a_ia\_i or b_ib\_i).

The following picture summarizes the situation. In the picture there are m=4m = 4 railways and two trains are visible; the train going through railway 33 is currently crossing the line between Isona and the validating machine.

Isona is a really good runner, but she gets tired every time she has to change her running speed. What is the minimum number of speed changes she has to perform to get to the validating machine on the other platform within ss seconds from now? Note that at the beginning Isona is not running. She can start to run anytime. The instant she starts to run (i.e. her speed becomes positive) is not counted as a speed change.

입력

The first line of the input contains four integers nn, mm, ss, vv (1n5001 ≤ n ≤ 500, 1m101 ≤ m ≤ 10, 1s,v1091 ≤ s, v ≤ 10^9) — the number of trains, the number of railways, the maximum time in seconds Isona can spend crossing the railways, and the number of seconds she needs to traverse 11 meter at maximum speed.

Each of the next nn lines contains three integers a_ia\_i, b_ib\_i, r_ir\_i (1a_i<b_i1091 ≤ a\_i < b\_i ≤ 10^9, 1r_im1 ≤ r\_i ≤ m) — the start and end times of the ii-th train crossing the straight line between Isona and the validating machine, and the railway it will be using.

It is guaranteed that, for any two trains ii and jj that go through the same railway (i.e. r_i=r_jr\_i = r\_j), there is at least 11 second between them (that is, either a_jb_i+1a\_j ≥ b\_i + 1 or a_ib_j+1a\_i ≥ b\_j + 1).

출력

Print the minimum number of speed changes Isona has to perform to get to the validating machine in time. If this is impossible, print 1-1.