Solved medium problem 77.