Problem #14 (slow)