doesn't work in UVA (runtime error)