srm 636 div 2 question

Stay tuned for Div 1 solutions.