#include using namespace std; using tpl = tuple; const int N = 2e5 + 10, M = 4e3 + 10, W = 2e3; int n, x[N], y[N], m, z[N], w[N], tr[M], ans[N]; vector p[M]; vector que[M][2]; int lowbit(int x) { return x & (-x); } void add(int x) { while (x < M) tr[x]++, x += lowbit(x); } int query(int x) { int ret = 0; while (x > 0) ret += tr[x], x -= lowbit(x); return ret; } bool Check(int d) { fill(tr, tr + M, 0); for (int i = 1; i <= n; i++) p[x[i]].push_back(y[i]); for (int i = 1; i <= m; i++) { que[max(0, z[i] - d)][0].push_back({max(0, w[i] - d), min(M - 1, w[i] + d), i}); que[min(M - 1, z[i] + d)][1].push_back({max(0, w[i] - d), min(M - 1, w[i] + d), i}); ans[i] = 0; } for (int i = 0; i < M; i++) { for (auto [l, r, id] : que[i][0]) { ans[id] -= query(r) - query(l - 1); } for (int k : p[i]) add(k); for (auto [l, r, id] : que[i][1]) { ans[id] += query(r) - query(l - 1); } que[i][0].clear(), que[i][1].clear(), p[i].clear(); } for (int i = 1; i <= m; i++) if (ans[i] > 0) return 0; fill(tr, tr + M, 0); for (int i = 1; i <= m; i++) p[z[i]].push_back(w[i]); for (int i = 1; i <= n; i++) { que[max(0, x[i] - d)][0].push_back({max(0, y[i] - d), min(M - 1, y[i] + d), i}); que[min(M - 1, x[i] + d)][1].push_back({max(0, y[i] - d), min(M - 1, y[i] + d), i}); ans[i] = 0; } for (int i = 0; i < M; i++) { for (auto [l, r, id] : que[i][0]) { ans[id] -= query(r) - query(l - 1); } for (int k : p[i]) add(k); for (auto [l, r, id] : que[i][1]) { ans[id] += query(r) - query(l - 1); } que[i][0].clear(), que[i][1].clear(), p[i].clear(); } for (int i = 1; i <= n; i++) if (ans[i] > 0) return 0; return 1; } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; int t = y[i]; y[i] = x[i] - y[i], x[i] += t; x[i] += W, y[i] += W; } cin >> m; for (int i = 1; i <= n; i++) { cin >> z[i] >> w[i]; int t = w[i]; w[i] = z[i] - w[i], z[i] += t; z[i] += W, w[i] += W; } int l = 0, r = 2e3; while (l < r) { int mid = (l + r) >> 1; Check(mid) ? l = mid + 1 : r = mid; } cout << l; return 0; }