So I managed to upsolve problem B from the last D2 round. I could have done it one try but I did not look at the constraints on n so I gave one TLE'ed solution before the AC'ed one, so dumb. I'm gonna sleep so well tonight :) It's already midnight here so I think i'll be off to bed now, guys rate my solution 266115349..