Charged Courier


A courier must travel through a network of cities from city 11 to city NN. Each road can only be used in its listed direction, gives a certain delivery reward, and consumes some amount of battery.

The courier starts with at most BB battery units and cannot spend more than BB battery units over the whole trip. Determine the maximum total reward the courier can collect while reaching city NN. If it is impossible to reach city NN, output -1.

Input

The first line contains three integers NN, MM, and BB: the number of cities, the number of roads, and the maximum battery that may be spent.

Each of the next MM lines contains four integers uiu_i, viv_i, rir_i, and cic_i, describing a directed road from city uiu_i to city viv_i with reward rir_i and battery cost cic_i.

Output

Output one integer: the maximum reward possible while reaching city NN using at most BB battery units, or -1 if city NN cannot be reached.

Constraints

  • 2N5002 \le N \le 500
  • 0M50000 \le M \le 5000
  • 0B30000 \le B \le 3000
  • 1ui,viN1 \le u_i, v_i \le N
  • uiviu_i \ne v_i
  • 0ri1090 \le r_i \le 10^9
  • 1ci30201 \le c_i \le 3020

Example 1

Input 1
4 5 7
1 2 10 3
2 4 20 4
1 3 25 5
3 4 10 3
2 3 15 2
Output 1
30
Explanation

The courier can travel from city 11 to city 22 to city 44, spending 3+4=73 + 4 = 7 battery and collecting 10+20=3010 + 20 = 30 reward. The route through city 33 from city 11 would collect more reward, but it spends too much battery.

Example 2

Input 2
3 2 4
1 2 100 5
2 3 100 1
Output 2
-1

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.