first solution to p31