Solution for UVa #12549