Problem 67

More complex version of problem 18.