How to solve NOVICE65 problem on SPOJ?

Here is the link regarding the problem NOVICE65 on SPOJ - SPOJ.com - Problem NOVICE65