<a href="https://en.wikipedia.org/wiki/Stable_marriage_problem" rel="nofollow">https://en.wikipedia.org/wiki/Stable_marriage_problem</a><p>Though, in this case, "marriage" is more of a mathematical construct, but the math matches the result here.