def closest_nums(N, first, second): closest_pair = None sorted_first = sorted(first) for y in second: # dichotomy x = find_closest(y, sorted_first) if abs(N - x - y) < abs(N - closest_pair.x - closest_pair.y): closest_pair = Pair(x, y)