problem 287 solved, 10 sec runtime