Can anyone help me with Happy Sequence from Codigo 2k18 Contest?

Hi Guys can someone tell me how to approach this problem?

@avi892nash @p_unit @hitman623 @abdullah768 @filyan @rutvik28 @victorforbes

Thanks in advance :slight_smile:

//