UVA 12798 – Handball Solution

My code: