Solution for UVa-705