http://www.spoj.com/problems/AMR12D/