UVA problem #507 added