How to solve Hidden Sequence (HDDN) cook off october 2019?

https://www.codechef.com/COOK111B/problems/HDDN