added code for Uva: 147 231