Implement solutions 30 and 31