Algorithm for Brilliant Hunger Games https://brilliant.org/competitions/hunger-games/