* Solved problem A from 2010 Africa jam