Solution to https://www.kattis.com/problems/listgame