http://www.spoj.com/problems/MUSIC/
TODO: think about termination