SRM570 div1 medium

with explanation