SPOJ 8: Complete the sequence