Problem 30
Slight optimization for P30
Problem 34