static double findMedian(int A[], int B[], int l, int r) {
		int nA = A.length;
		int nB = B.length;
		if (l > r)
			return findMedian(B, A, Math.max(0, (nA + nB) / 2 - nA),
					Math.min(nB, (nA + nB) / 2));
		int i = (l + r) / 2;
		int j = (nA + nB) / 2 - i - 1;
		if (j >= 0 && A[i] < B[j])
			return findMedian(A, B, i + 1, r);
		else if (j < nB - 1 && A[i] > B[j + 1])
			return findMedian(A, B, l, i - 1);
		else {
			if ((nA + nB) % 2 == 1)
				return A[i];
			else if (i > 0)
				return (A[i] + Math.max(B[j], A[i - 1])) / 2.0;
			else
				return (A[i] + B[j]) / 2.0;
		}
	}