added code for Uva: 333