Problem 12.
Problem 12

The code doesn't look good but it seems to be efficient.