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

#BS0000392. Chia đôi diện tích hình vuông I (Separate Squares I)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chia đôi diện tích hình vuông I (Separate Squares I)

Separate Squares I

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Consider nn axis-aligned squares. Square ii has bottom-left corner (xi,yi)(x_i,y_i) and side length lil_i. A horizontal line divides each square into an upper and a lower part, either of which may be empty. Add the upper areas and lower areas separately over all squares. An overlapping region contributes once for each square containing it. Find the smallest height at which these two sums are equal.

Illustration of example 2

Input

The first line contains integer nn. Line ii of the next nn lines contains integers xi,yi,lix_i,y_i,l_i describing square ii.

Output

Print the smallest required height as a real number. The absolute error must not exceed 10−510^{-5}.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le 10; 0≤xi,yi≤1090\le x_i,y_i\le10^9; 1≤li≤1091\le l_i\le10^9 for every 1≤i≤n1\le i\le n; ∑i=1nli2≤1012\sum_{i=1}^n l_i^2\le10^{12}.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 0≤xi,yi≤1090\le x_i,y_i\le10^9; 1≤li≤1091\le l_i\le10^9 for every 1≤i≤n1\le i\le n; ∑i=1nli2≤1012\sum_{i=1}^n l_i^2\le10^{12}.
  • Subtask 3 (50 points): 1≤n≤500001\le n\le 50000; 0≤xi,yi≤1090\le x_i,y_i\le10^9; 1≤li≤1091\le l_i\le10^9 for every 1≤i≤n1\le i\le n; ∑i=1nli2≤1012\sum_{i=1}^n l_i^2\le10^{12}.

Examples

Input

2
0 0 1
2 2 1

Output

1.00000

Explanation

Both squares have area 1. Height 1 places the first square below and the second above. Every height from 1 to 2 balances the areas; 1 is the smallest.

Input

2
0 0 2
1 1 1

Output

1.16667

Explanation

At height 7/67/6, the lower areas are 7/37/3 and 1/61/6, totaling 5/25/2. The upper sum is also 5/25/2. Every smaller height has a lower sum below 5/25/2.