solution to UVA 123, and template of 124