Hello all! I found this problem on CodeChef: http://www.codechef.com/problems/PRYS09
I honestly don't know where to start. The brute force approach obviously won't work. Also, there are no solutions and editorials available probably because this is an old contest problem and remained unnoticed by the users. Please help!
Thanks!