In the Prisoner of Benda, due to one-way body swap shenanigans, two Globetrotter's have to work out if they can get everyone's minds back in order. They prove it can be done with any two extra people.
In reality, this was penned and proven by Mathematics PhD, and episode writer Ken Keeler. Which came first though? The proof or the episode?