Updated C solution