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

#BS0000201. Trung vị của hai dãy đã sắp xếp (Median of Two Sorted Arrays)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Trung vị của hai dãy đã sắp xếp (Median of Two Sorted Arrays)

Median of Two Sorted Arrays

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Two integer sequences A,BA,B of lengths m,nm,n are nondecreasing. Conceptually merge them into a nondecreasing sequence of length m+nm+n, retaining duplicates. Its median is the middle element for odd length, or the mean of the two middle elements for even length. Find this median. Either sequence may be empty but their combined length is positive.

Input

The first line contains integers m,nm,n. The second contains mm integers AiA_i and the third nn integers BjB_j. An empty sequence has an empty corresponding line.

Output

Print the median with exactly one digit after the decimal point.

Subtasks

  • Subtask 1 (20 points): 0≤m,n≤200\le m,n\le 20; 1≤m+n≤401\le m+n\le 40; −106≤Ai,Bj≤106-10^6\le A_i,B_j\le10^6 for all valid indices; both sequences are nondecreasing.
  • Subtask 2 (30 points): 0≤m,n≤2000\le m,n\le 200; 1≤m+n≤4001\le m+n\le 400; −106≤Ai,Bj≤106-10^6\le A_i,B_j\le10^6 for all valid indices; both sequences are nondecreasing.
  • Subtask 3 (50 points): 0≤m,n≤10000\le m,n\le 1000; 1≤m+n≤20001\le m+n\le 2000; −106≤Ai,Bj≤106-10^6\le A_i,B_j\le10^6 for all valid indices; both sequences are nondecreasing.

Examples

Input

2 2
1 2
3 4

Output

2.5

Explanation

The merged sequence is [1,2,3,4][1,2,3,4]. Its middle positions 2 and 3 contain 2 and 3; their mean is 2.5.