Solved medium problem 50.