I think you have tried the same logic as I had.
Let me give example for a test case:-
Your logic may satisfy the sequence as shown below
so answer by your logic would be 5
but it shall be 4
Try hard and solve it
Don’t discuss a problem which is in an ongoing contest. Ask them after the contest and we’ll be glad to help then!
You are not suppposed to ask or answer questions related to an ongoing contest! @admin what are you doing?