LogiQuest

177. Median of Two Sorted Arrays

HardBinary SearchMerge

Print the median of the combined arrays. If the total length is even, print the average of the two middle values with exactly one decimal place; otherwise print the middle value with one decimal place.

Input format

Line 1: n Line 2: n sorted integers Line 3: m Line 4: m sorted integers

Output format

The median, e.g. 2.5

Example 1

Input

2
1 3
1
2

Output

2.0

Example 2

Input

2
1 2
2
3 4

Output

2.5

Constraints

1 ≤ n, m ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…