interesting problem, my solution is not the best but it is good enough