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

#BS0000383. Bay lên qua lớp chắn (Careful Ascent)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bay lên qua lớp chắn (Careful Ascent)

Careful Ascent

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Mal travels from (0,0)(0,0) to the stationary Firefly at (x,y)(x,y) on Zarzos. His vertical speed is fixed at 1 km/min. Before departure he sets a horizontal velocity vv (km/min). There are nn non-overlapping altitude intervals of energy shields. Shield ii spans altitudes lil_i to uiu_i and changes the horizontal velocity to vfivf_i while inside; outside the shields it returns to vv. The vertical speed is unaffected. Determine vv so that Mal reaches Firefly.

Example 1 illustration

Input

The first line contains integers x,yx,y (km). The second line contains integer nn. Each of the next nn lines contains integers li,uil_i,u_i (km) and real fif_i.

Output

Print the horizontal velocity in km/min. The absolute or relative error must not exceed 10−610^{-6}.

Subtasks

  • Subtask 1 (20 points): −107≤x≤107-10^7\le x\le10^7; max⁡(1,∣x∣)≤y≤108\max(1,|x|)\le y\le10^8; 0≤li<ui≤y0\le l_i<u_i\le y; 0.1≤fi≤100.1\le f_i\le10; fif_i has at most 10 decimal places; 0≤n≤00\le n\le 0; for all i≠ji\ne j, ui≤lju_i\le l_j or uj≤liu_j\le l_i.
  • Subtask 2 (30 points): −107≤x≤107-10^7\le x\le10^7; max⁡(1,∣x∣)≤y≤108\max(1,|x|)\le y\le10^8; 0≤li<ui≤y0\le l_i<u_i\le y; 0.1≤fi≤100.1\le f_i\le10; fif_i has at most 10 decimal places; 0≤n≤10\le n\le 1; for all i≠ji\ne j, ui≤lju_i\le l_j or uj≤liu_j\le l_i.
  • Subtask 3 (50 points): −107≤x≤107-10^7\le x\le10^7; max⁡(1,∣x∣)≤y≤108\max(1,|x|)\le y\le10^8; 0≤li<ui≤y0\le l_i<u_i\le y; 0.1≤fi≤100.1\le f_i\le10; fif_i has at most 10 decimal places; 0≤n≤1000\le n\le 100; for all i≠ji\ne j, ui≤lju_i\le l_j or uj≤liu_j\le l_i.

Examples

Input

100 140
1
40 90 0.2000000000

Output

1.0

Explanation

The three intervals last 40, 50 and 50 minutes. At setting 1, their horizontal displacements are 40, 10 and 50 km, totalling 100 km.

Input

100 100
3
0 20 2.0000000000
50 100 0.1000000000
20 50 0.2000000000

Output

1.96078431373

Explanation

The three shields cover the entire altitude range. Their displacements are 40v40v, 5v5v and 6v6v. Thus 51v=10051v=100 and v=100/51v=100/51.