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

#BS0000414. Điểm hẹn trên đường thẳng (Meeting on the Line)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Điểm hẹn trên đường thẳng (Meeting on the Line)

Meeting on the Line

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn people on a coordinate line, person ii living at xix_i. They choose a meeting point x0x_0. Person ii first spends tit_i minutes dressing, then travels for ∣xi−x0∣|x_i-x_0| minutes. Their total arrival time is ti+∣xi−x0∣t_i+|x_i-x_0|. Everyone begins preparing simultaneously. Find the meeting coordinate that minimizes the time when everyone has arrived.

Input

The first line contains integer nn. The second line contains the nn integers xix_i in order from 1 to nn. The third line contains the nn integers tit_i in the same order.

Output

Print the unique optimal coordinate x0x_0, not the time. The absolute or relative error must not exceed 10−610^{-6}.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1051\le n\le10^5; 0≤xi,ti≤1080\le x_i,t_i\le10^8 for every 1≤i≤n1\le i\le n. ti=0t_i=0 for every ii.
  • Subtask 2 (30 points): 1≤n≤1051\le n\le10^5; 0≤xi,ti≤1080\le x_i,t_i\le10^8 for every 1≤i≤n1\le i\le n. ti=t1t_i=t_1 for every ii.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 0≤xi,ti≤1080\le x_i,t_i\le10^8 for every 1≤i≤n1\le i\le n.

Examples

Input

1
0
3

Output

0

Explanation

The only person is at 0 and needs 3 minutes to prepare. Meeting at 0 requires no travel and attains the lower bound of 3 minutes.

Input

2
3 1
0 0

Output

2

Explanation

The positions are 3 and 1, with no preparation time. Their distance is 2, so at least one must travel at least 1 unit. At point 2 both travel exactly 1 unit.

Input

2
1 4
0 0

Output

2.5

Explanation

The people need no preparation and are 3 units apart. At 2.5 both travel for 1.5 minutes; the sum of their travel distances is at least 3, so their maximum time cannot be below 1.5.

Input

3
1 2 3
0 0 0

Output

2

Explanation

At point 2 the arrival times are 1, 0 and 1 minutes. The outermost people are 2 units apart, so they cannot both arrive in less than 1 minute.

Input

3
1 2 3
4 1 2

Output

1

Explanation

At 1, arrival times are 4+0=44+0=4, 1+1=21+1=2, and 2+2=42+2=4 minutes. Meeting before 4 is impossible because the first person needs 4 minutes to dress. To arrive by 4 that person cannot travel, so the meeting point is 1.

Input

3
3 3 3
5 3 3

Output

3

Explanation

All three people are at position 3, with preparation times 5, 3 and 3 minutes. At point 3 the maximum arrival time is 5 minutes. Any other point adds travel time for the first person.

Input

6
5 4 7 2 10 4
3 2 5 1 4 6

Output

6

Explanation

At point 6, the six arrival times are 4,4,6,5,8,84,4,6,5,8,8 minutes. Person 5 starts at 10 with preparation time 4, and person 6 starts at 4 with preparation time 6. Their combined arrival times are at least 4+6+6=164+6+6=16 minutes, so their maximum is at least 8 minutes. Point 6 attains this bound.