1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Sample134 {
    public final List<Point> searchPoints = new ArrayList<Point>();
    public final Set<Point> inputPoints = new HashSet<Point>();

    public void addSearchPoint(int x, int y) {
        searchPoints.add(new Point(x, y));
    }
    public void addInputPoint(int x, int y) {
        inputPoints.add(new Point(x, y));
    }

    public Point calc() {
        Point first = searchPoints.get(0);
        OUTER: for (Point base: inputPoints) {
            int dx = base.x - first.x;
            int dy = base.y - first.y;
            for (int index = 1, max = searchPoints.size(); index < max; index++) {
                Point p = searchPoints.get(index);
                if (!inputPoints.contains(new Point(p.x + dx, p.y + dy))) continue OUTER;
            }
            return new Point(dx, dy);
        }
        throw new IllegalStateException("見つからない。");
    }

    public static class Point {
        public final int x;
        public final int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) return true;
            if (!(obj instanceof Point)) return false;
            Point other = (Point) obj;
            return this.x == other.x && this.y == other.y;
        }
        @Override
        public int hashCode() {
            return x * 17 + y;
        }
    }

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            Sample134 sample = new Sample134();
            int n = Integer.parseInt(reader.readLine());
            for (int index = 0; index < n; index++) {
                String[] point = reader.readLine().split("\\s");
                sample.addSearchPoint(Integer.parseInt(point[0]), Integer.parseInt(point[1]));
            }
            int m = Integer.parseInt(reader.readLine());
            for (int index = 0; index < m; index++) {
                String[] point = reader.readLine().split("\\s");
                sample.addInputPoint(Integer.parseInt(point[0]), Integer.parseInt(point[1]));
            }
            Point p = sample.calc();
            System.out.println(String.format("%d %d", p.x, p.y));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}