import java.io.File; import java.io.FileNotFoundException; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; /** * * @author sorin */ public class prog { public static void main(String[] args) throws FileNotFoundException { File homedir = new File(System.getProperty("user.home")); // Scanner scanner = new Scanner(new File(homedir, "/Downloads/A-large.in")); Scanner scanner = new Scanner(System.in); double radius = Double.parseDouble(scanner.nextLine()); Set set = new HashSet<>(); Point p = new Point(-1 * (radius - 1), -1 * (radius - 1)); addPoints(set, p); System.out.println( (int) (-1 * (radius - 1)) + " " +(int) (-1 * (radius - 1))); while (true) { String[] line = scanner.nextLine().split(" "); p = new Point(Double.parseDouble(line[0]), Double.parseDouble(line[1])); addPoints(set, p); p = findNextNumber(radius, set); if (p == null) { break; } addPoints(set, p); System.out.println((int) (p.x) + " " +(int) p.y); } } private static void addPoints(Set set, Point p) { set.add(new Point(p.x - 1, p.y - 1)); set.add(new Point(p.x - 1, p.y + 0)); set.add(new Point(p.x - 1, p.y + 1)); set.add(new Point(p.x, p.y - 1)); set.add(new Point(p.x, p.y + 0)); set.add(new Point(p.x, p.y + 1)); set.add(new Point(p.x + 1, p.y - 1)); set.add(new Point(p.x + 1, p.y + 0)); set.add(new Point(p.x + 1, p.y + 1)); //set.add(new Point(p.x + 1, p.y)); } private static Point findNextNumber(double radius, Set set) { for (int i = (int) -(1 * (radius - 1)); i < radius; i++) { for (int j = (int) -(1 * (radius - 1)); j < radius; j++) { Point p = new Point(i, j); if (!set.contains(p)) { return p; } } } return null; } private static class Point { double x; double y; public Point(double x, double y) { this.x = x; this.y = y; } @Override public boolean equals(Object obj) { Point p1 = (Point) obj; if ((p1.x == this.x) && (p1.y == this.y)) return true; return false; } @Override public int hashCode() { return (int) (x * 1000 + y); } } }