* Solved problem B from 2010 Africa jam