Successful solution for Chef and Gift problem - http://www.codechef.com/AUG14/problems/PRGIFT