first implementation. wrong answer on test cases
10503 accepted