UVa 545 - Heads

See this : http://www.algorithmist.com/index.php/UVa_474