PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000047. Trao đổi tiền tệ có phí (Currency Exchange)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Trao đổi tiền tệ có phí (Currency Exchange)

Currency Exchange

Source: POJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN currencies and MM two-way exchange offices. Exchanging xx units using rate rr and commission cc yields (x−c)r(x-c)r provided the remaining amount is nonnegative. Starting with VV units of currency SS, determine whether one can finish with more currency SS.

Input

First line N,M,S,VN,M,S,V; then MM lines A,B,rAB,cAB,rBA,cBAA,B,r_{AB},c_{AB},r_{BA},c_{BA}.

Output

Print YES or NO.

Subtasks

  • Subtask 1 (20 points): 2≤N≤82\le N\le8, 1≤M≤121\le M\le12, 1≤S≤N1\le S\le N; 0≤V≤10000\le V\le1000; 0.01≤r≤1000.01\le r\le100, 0≤c≤1000\le c\le100; at most two decimal places.
  • Subtask 2 (30 points): 2≤N≤402\le N\le40, 1≤M≤601\le M\le60, 1≤S≤N1\le S\le N; 0≤V≤10000\le V\le1000; 0.01≤r≤1000.01\le r\le100, 0≤c≤1000\le c\le100; at most two decimal places.
  • Subtask 3 (50 points): 2≤N≤1002\le N\le100, 1≤M≤1001\le M\le100, 1≤S≤N1\le S\le N; 0≤V≤10000\le V\le1000; 0.01≤r≤1000.01\le r\le100, 0≤c≤1000\le c\le100; at most two decimal places.

Examples

Input

3 2 1 20
1 2 1.00 1.00 1.00 1.00
2 3 1.10 1.00 1.10 1.00

Output

YES

Explanation

Starting with 20 units of currency 1, convert to currency 2 to obtain 19. The conversions 2→3→22\to3\to2 yield 19.819.8 and then 20.6820.68. One more such round yields 22.712822.7128 of currency 2; converting to currency 1 leaves 21.7128>2021.7128>20. Thus the answer is YES.