How can I solve the problem "The Stones Game" from Africa/Middle East — Arab Regionals 2013 ? Any help or hint would be appreciated. https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=592&page=show_problem&problem=4772