SRM 592 Div2 500 + backtracking solution