#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int binarySearch(vector<int>& A, vector<int>& B, int index, int loA, int hiA, int loB, int hiB) {
	if (loA == hiA && loB == hiB) {
		if (loA + loB >= index) { // loB is exclusive
			return min(A[loA], B[loB]);
		} else {
			return max(A[loA], B[loB]);
		}
	}
	
	int midA = (loA + hiA + 1) / 2;
	int midB = upper_bound(B.begin(), B.end(), A[midA]) - B.begin();
	
	if (midA + midB > index) {
		return binarySearch(B, A, index, loB, hiB, loA, midA - 1);
	} else {
		return binarySearch(B, A, index, loB, hiB, midA, hiA);
	}
	
}

double findMedian(vector<int>& A, vector<int>& B) {
    int totalSize = A.size() + B.size();
    int oddIndex = totalSize / 2;
    int evenIndex = totalSize / 2 - (totalSize % 2 == 0);
    
    int oddBinarySearch = binarySearch(A, B, oddIndex, 0, A.size() - 1, 0, B.size() - 1);
    int evenBinarySearch = binarySearch(A, B, evenIndex, 0, A.size() - 1, 0, B.size() - 1);
    
    return (oddBinarySearch + evenBinarySearch) / 2.0;
}


int main() {
	return 0;
}