learn from others' concise code
revise the problem more concise, also refer to the editorial's elegant algorithm