Language: C++

g#include <bits/stdc++.h>

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[" << vs[0];
    for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
    return os << "]";
}


typedef short Long;
//typedef long long Long;

/* 領域木ライブラリ.
 *   Node : 領域木の各ノード
 *   construct(Point[] ps) 
 *      : ps(x座標でソートされた点集合)をもとに領域木を作成.
 *   query(Node root, long sx, long sy, long gx, long gy, vector<Point>& result) 
 *      : rootに含まれる点のうち, (sx <= x <= gx && sy <= y <= gy)なるもののをresultに入れる
 */

int ans;
struct Point {
    Long x, y;
    char type;
    Point() {}
    Point(Long x, Long y, char type='c') : x(x), y(y), type(type) {}
    static bool compY(const Point& a, const Point& b) {
        return a.y == b.y ? a.x < b.x : a.y < b.y;
    }
};
Long dist2(const Point& a, const Point& b);
struct Node {
    Node* parent;
    shared_ptr<Node> left, right;
    Long left_x, right_x;
    vector<Point> ys;
};
ostream& operator<<(ostream& os, const Node& node) {
    return os << "( [" << node.left_x << "," << node.right_x << "] -> " << node.ys;
}
shared_ptr<Node> construct(vector<Point>::iterator lb, vector<Point>::iterator ub) {
    auto n = make_shared<Node>();
    n->left_x = lb->x;
    n->right_x = (ub - 1)->x;
    if (ub - lb == 1) {
        n->ys.clear(); n->ys.push_back(*lb);
        return n;
    }
    auto mid = lb + (ub - lb) / 2;
    auto l = construct(lb, mid),
         r = construct(mid, ub);
    l->parent = n.get();
    r->parent = n.get();
    n->left = l;
    n->right = r;
    size_t li = 0, ri = 0;
    while (true) {
        if (li >= l->ys.size() && ri >= r->ys.size()) break;
        if (li >= l->ys.size()) n->ys.push_back(r->ys[ri++]);
        else if (ri >= r->ys.size()) n->ys.push_back(l->ys[li++]);
        else {
            n->ys.push_back( l->ys[li].y < r->ys[ri].y ? l->ys[li++] : r->ys[ri++] );
        }
    }
    return n;
}

int AN, BN, R;
vector<Point> A, B;

/* (sx <= x <= gx && sy <= y <= gy)なる点(x, y)の個数を返す 
 * 閉区間なの注意 */
void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
    if (gx < root->left_x || root->right_x < sx) {
        // do nothing;
    } else if (sx <= root->left_x && root->right_x <= gx) {
        vector<Point>& ys = root->ys;
        auto lb = upper_bound(whole(ys), Point(0, sy - 1), Point::compY);
        auto ub = lower_bound(whole(ys), Point(0, gy + 1), Point::compY);
        for (auto it = lb; it < ub; it++) {
            if (it->type == 'a') continue;
            if (dist2(*it, p) <= (4 * R) * (4 * R)) ans++;
        }
        //result.insert(result.end(), lb, ub);
    } else {
        query(root->left, sx, sy, gx, gy, p);
        query(root->right, sx, sy, gx, gy, p);
    }
}

bool input() {
    cin >> AN >> BN >> R;
    if (AN == 0 && BN == 0 && R == 0) return false;
    A.clear(); B.clear();
    A.resize(AN); B.resize(BN);
    for (int i = 0; i < AN; i++) {
        cin >> A[i].x >> A[i].y;
        A[i].type = 'a';
    }
    for (int i = 0; i < BN; i++) {
        cin >> B[i].x >> B[i].y;
        B[i].type = 'b';
    }
    return true;
}

ostream& operator<<(ostream& os, const Point& p) {
    return os << "(" << p.x << "," << p.y << ")";
}
bool operator<(const Point& a, const Point& b) {
    return a.x == b.x ? a.y < b.y : a.x < b.x;
}

Long dist2(const Point& a, const Point& b) {
    Long dx = a.x - b.x,
         dy = a.y - b.y;
    return dx * dx + dy * dy;
}
void solve() {
    vector<Point> p = A;
    B.insert(B.end(), A.begin(), A.end());
    sort(whole(B));
    auto rtree = construct(whole(B));
    p.clear();
    ans = 0;
    for (int i = 0; i < AN; i++) {
        Point& p = A[i];
        query(rtree, p.x - 4 * R, p.y - 4 * R, p.x + 4 * R, p.y + 4 * R, p);
    }
    cout << ans << endl;
}

int main() {
    while (input()) solve();
    return 0;
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | g#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'g' does not name a type
    1 | g#include <bits/stdc++.h>
      | ^
a.cc:8:1: error: 'ostream' does not name a type
    8 | ostream& operator<<(ostream& os, const vector<T>& vs) {
      | ^~~~~~~
a.cc:40:5: error: 'shared_ptr' does not name a type
   40 |     shared_ptr<Node> left, right;
      |     ^~~~~~~~~~
a.cc:42:5: error: 'vector' does not name a type
   42 |     vector<Point> ys;
      |     ^~~~~~
a.cc:44:1: error: 'ostream' does not name a type
   44 | ostream& operator<<(ostream& os, const Node& node) {
      | ^~~~~~~
a.cc:47:1: error: 'shared_ptr' does not name a type
   47 | shared_ptr<Node> construct(vector<Point>::iterator lb, vector<Point>::iterator ub) {
      | ^~~~~~~~~~
a.cc:75:1: error: 'vector' does not name a type
   75 | vector<Point> A, B;
      | ^~~~~~
a.cc:79:6: error: variable or field 'query' declared void
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |      ^~~~~
a.cc:79:12: error: 'shared_ptr' was not declared in this scope
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |            ^~~~~~~~~~
a.cc:79:27: error: expected primary-expression before '>' token
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                           ^
a.cc:79:30: error: 'root' was not declared in this scope
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                              ^~~~
a.cc:79:41: error: expected primary-expression before 'sx'
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                                         ^~
a.cc:79:50: error: expected primary-expression before 'sy'
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                                                  ^~
a.cc:79:59: error: expected primary-expression before 'gx'
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                                                           ^~
a.cc:79:68: error: expected primary-expression before 'gy'
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                                                                    ^~
a.cc:79:72: error: expected primary-expression before 'const'
   79 | void query(shared_ptr<Node>& root, Long sx, Long sy, Long gx, Long gy, const Point& p) {
      |                                                                        ^~~~~
a.cc: In function 'bool input()':
a.cc:98:5: error: 'cin' was not declared in this scope
   98 |     cin >> AN >> BN >> R;
      |     ^~~
a.cc:100:5: error: 'A' was not declared in this scope
  100 |     A.clear(); B.clear();
      |     ^
a.cc:100:16: error: 'B' was not declared in this scope
  100 |     A.clear(); B.clear();
      |                ^
a.cc: At global scope:
a.cc:113:1: error: 'ostream' does not name a type
  113 | ostream& operator<<(ostream& os, const Point& p) {
      | ^~~~~~~
a.cc: In function 'void solve()':
a.cc:126:5: error: 'vector' was not declared in this scope
  126 |     vector<Point> p = A;
      |     ^~~~~~
a.cc:126:17: error: expected primary-expression before '>' token
  126 |     vector<Point> p = A;
      |                 ^
a.cc:126:19: error: 'p' was not declared in this scope
  126 |     vector<Point> p = A;
      |                   ^
a.cc:126:23: error: 'A' was not declared in this scope
  126 |     vector<Point> p = A;
      |                       ^
a.cc:127:5: error: 'B' was not declared in this scope
  127 |     B.insert(B.end(), A.begin(), A.end());
      |     ^
a.cc:128:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  128 |     sort(whole(B));
      |     ^~~~
      |     short
a.cc:129:18: error: 'construct' was not declared in this scope; did you mean 'struct'?
  129 |     auto rtree = construct(whole(B));
      |                  ^~~~~~~~~
      |                  struct
a.cc:134:9: error: 'query' was not declared in this scope
  134 |         query(rtree, p.x - 4 * R, p.y - 4 * R, p.x + 4 * R, p.y + 4 * R, p);
      |         ^~~~~
a.cc:136:5: error: 'cout' was not declared in this scope
  136 |     cout << ans << endl;
      |     ^~~~
a.cc:136:20: error: 'endl' was not declared in this scope
  136 |     cout << ans << endl;
      |                    ^~~~