Chloe and the sequence

CodeForces - 743B