New Year and Old Subsequence

CodeForces - 750E