#include #include #include using namespace std; const int MAXN = 2e5 + 5, MAXV = 1e3 + 3; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; queue> q; int n, m, ans = 3000, a[MAXN], b[MAXN], d[MAXV][MAXV]; void Record(int x, int y, int w) { if (x >= 0 && y >= 0 && x <= 1000 && y <= 1000 && !d[x][y]) { d[x][y] = w, q.push({x, y}); } } void bfs() { while (!q.empty()) { auto [x, y] = q.front(); q.pop(); for (int i = 0; i < 4; i++) { Record(x + dx[i], y + dy[i], d[x][y] + 1); } } } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1, x, y; i <= n; i++) { cin >> x >> y, Record(x, y, 1); } cin >> m, bfs(); for (int i = 1, x, y; i <= m; i++) { cin >> x >> y, ans = min(ans, d[x][y]); } cout << ans - 1; return 0; }