added code for Uva:594