7974. What’s Next

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