Output needs to have a newline character at the end of the last line in order to be accepted by the UVa online judge.
Added problem description.