Java solution for problem UVA 11340 Newspaper