// David Poeschl import java.util.*; public class ChampagneChecker { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); List glasses = new ArrayList<>(); int numGlasses = scan.nextInt(); for (int i = 0; i < numGlasses; i++) glasses.add(new Glass(scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt())); scan.close(); verify(glasses); System.exit(42); } private static void verify(List glasses) throws Exception { // Check the actual input bounds if (glasses.size() == 0 || glasses.size() > 20) { throw new Exception("Wrong number of glasses"); } for (Glass g : glasses) { if (g.x < 0 || g.x > 1000) { throw new Exception("x value of " + g.x + " is out of bounds"); } if (g.y < 0 || g.y > 1000) { throw new Exception("y value of " + g.y + " is out of bounds"); } if (g.z < 1 || g.z > 1000) { throw new Exception("z value of " + g.z + " is out of bounds"); } if (g.r < 1 || g.r > 1000) { throw new Exception("r value of " + g.r + " is out of bounds"); } if (g.v < 1 || g.v > 1000) { throw new Exception("v value of " + g.v + " is out of bounds"); } } // Verify that glasses on the same level don't overlap. for (Glass sourceGlass : glasses) for (Glass targetGlass : glasses) if (sourceGlass != targetGlass && sourceGlass.z == targetGlass.z) { int dx = sourceGlass.x - targetGlass.x; int dy = sourceGlass.y - targetGlass.y; int distanceSquared = dx * dx + dy * dy; int radiiSumSquared = (sourceGlass.r + targetGlass.r) * (sourceGlass.r + targetGlass.r); if (radiiSumSquared > distanceSquared) { throw new Exception("Glasses on the same level overlap."); } } } private static class Glass { public int x; public int y; public int z; public int r; public int v; public Glass(int x, int y, int z, int r, int v) { this.x = x; this.y = y; this.z = z; this.r = r; this.v = v; } } }