Part of course:
[INOI1302] Sequence Land (INOI 2013: India)
Constraints: The values in the ids are <= 10^9, not <= 109. (CodeChef has a typo).
Indian National Olympiad in Informatics (INOI) is round 2 out of 3 (i.e. intermediate) for selection into Indian IOI team. Check out the discussion responses for solution one hint at a time!