Arriving on Time

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

문제

You are a very busy person, with a lot of important meetings. Today, you have a meeting for which it is insanely important to arrive at the agreed time.

Luckily you live in Zürich, which features a large network of extremely punctual trams. Each tram line travels from one place to another at regular intervals, always taking the same time from departure to arrival. It is very easy to change trams, and we assume that it takes no time to change to another tram if both are at a stop at the same time. This means that if a tram arrives at its destination at exactly time tt and another tram departs from the same place at time tt (or later), you will have enough time to change tram.

You are currently working in your hotel room before the meeting. Since you are a very busy person, you would like to leave your hotel at the latest possible time possible while still ariving to the meeting on time. When do you need to leave for your meeting?

입력

The input consists of:

  • one line with three integers nn, mm and ss (2n100,0002 \le n \leq 100\\,000, 1m200,0001 \le m \leq 200\\,000, 1s1091 \le s \leq 10^9), the number of tram stops, the number of tram lines, and the time at which the meeting starts in seconds relative to now.
  • mm lines, each with five integers u,v,t_0,p,du, v, t\_0, p, d (0uv<n0 \le u \not= v < n, 0t_01090 \le t\_0 \le 10^9, 1p,d1091 \le p, d \le 10^9). The ii'th line describes the ii'th tram line, which departs from tram stop uu, arrives at tram stop vv, starts its first departure t_0t\_0 seconds from now, departs every pp seconds from the first departure, and takes dd seconds from departure to arrival.

The stops are numbered between 00 and n1n - 1. Your hotel is located at stop 00, and the meeting is at stop n1n - 1.

출력

Output the latest time at which you can leave the hotel while arriving to your meeting on time, in seconds from now. If you can not make it to your meeting on time, output impossible instead.