Problem C solution