Problem:
Problem E:
Amazing Graze
In 2215 A.D., a war between two planets, ACM and ICPC, is being more and more intense.
ACM introduced new combat planes.  These planes have a special system that is called Graze, and fighting power of a plane increases when it is close to energy bullets that ICPC combat planes shoot.
Both combat planes and energy bullets have a shape of a sphere with a radius of
R
.  Precisely, fighting power of a plane is equivalent to the number of energy bullet where distance from the plane is less than or equals to 2
R
.
You, helper of captain of intelligence units, are asked to analyze a war situation.  The information given to you is coordinates of
AN
combat planes and
BN
energy bullets.  Additionally, you know following things:
All combat planes and energy bullet has same
z
-coordinates. In other word,
z
-coordinate can be ignored.
No two combat planes, no two energy bullets, and no pair of combat plane and energy bullet collide (i.e. have positive common volume) each other.
Your task is to write a program that outputs total fighting power of all combat planes.
Input
Input file consists of a number of data sets.
One data set is given in following format:
AN BN R
XA
1
YA
1
XA
2
YA
2
:
XA
AN
YA
AN
XB
1
YB
1
XB
2
YB
2
:
XB
BN
YB
BN
AN
,
BN
,
R
are integers that describe the number of combat planes, energy bullets, and their radius respectively.
Following
AN
lines indicate coordinates of the center of combat planes.  Each line has two integers that describe
x
-coordinate and
y
-coordinate.
Following
BN
lines indicate coordinates of the center of energy bullets, in the same format as that of combat planes.
Input ends when
AN
=
BN
= 0.  You should output nothing for this case.
Output
For each data set, output the total fighting power.
Constraints
Jude data includes at most 20 data sets.
1 ≤
AN
,
BN
≤ 100000
0 <
R
≤ 10
0 ≤ (coordinate values) < 10000
Sample Input
2 2 1
0 0
0 4
2 2
2 8
0 0 0
Output for the Sample Input
2

Submitted solutions:

code_snippet: /*
 * Author: OldY
 * Created Time:  2011/8/31 16:30:04
 * File Name: E.cpp
 */
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;
const int maxint = -1u>>1;
const double pi = acos(-1.0);
typedef long long lint;

const int maxn = 10000 + 10;

int n,m,r;
vector <int> point[maxn];
int cirx[10*maxn] , ciry[10*maxn];
int tmpx,tmpy;
lint ans;
int top,y,nowx,nowy;

int find(const int & x , const int & i){
    int sz = point[i].size();
    int l = 0 , r = sz - 1 , mid;
    while(l <= r){
        mid = ((l+r) >> 1);
        if(mid < 0 || mid >= sz) break;
        if(point[i][mid] <= x)
            l = mid + 1;
        else r = mid - 1;
    }
    return l - 1;
}

int main() {
    while(scanf("%d%d%d",&n,&m,&r)){
        if(n == 0 && m == 0) break;
        ans = 0;
        top = 16*r*r;
        for(int i = 0 ; i < maxn ; i++)
            point[i].clear();
        for(int i = 0 ; i < n ; i++)
            scanf("%d%d",cirx+i,ciry+i);
        for(int i = 0 ; i < m ; i++){
            scanf("%d%d",&tmpx,&tmpy);
            point[tmpx].push_back(tmpy);
        }
        for(int i = 0 ; i < 10000 ; i++)
            sort(point[i].begin() , point[i].end());
        for(int i = 0 ; i < n ; i++){
            y = 0;
            for(int x = 4*r ; x >= 0 ; x--){
                while(x*x+y*y <= top) y++;
                y--;
                nowx = cirx[i] - x;
                if(nowx >= 0){
                    ans += find(ciry[i]+y,nowx) - find(ciry[i]-y-1, nowx);
                }
                if(x == 0) break;
                nowx = cirx[i] + x;
                if(nowx < 10000){
                    ans += find(ciry[i]+y,nowx) - find(ciry[i]-y-1 , nowx);
                }
            }
        }
        printf("%lld\n",ans);
    }   
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 5924
final_rank: 13

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

vector<int> v[10001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, r;
    while (cin >> n >> m >> r, r) {
        for (int i = 0; i <= 10000; i++) {
            v[i].clear();
        }
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            v[x].push_back(y);
        }
        for (int i = 0; i <= 10000; i++) {
            sort(v[i].begin(), v[i].end());
        }
        ll res = 0;
        int R = 4 * r;
        for (int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            for (int j = x - R; j <= x + R; j++) {
                if (j < 0 or j > 10000) continue;
                int sq = sqrt(R * R - abs(j - x) * abs(j - x));
                res += upper_bound(v[j].begin(), v[j].end(), y + sq) - lower_bound(v[j].begin(), v[j].end(), y - sq);
            }
        }
        cout << res << "\n";
    }
}
accuracy: 1
time_ms: 170
memory_kb: 5060
final_rank: 3

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
vector<int> v[10000];
int m[80001]; // to store pre-calculated values of m
int main() {
  int aN, bN, R;
  while (scanf("%d %d %d", &aN, &bN, &R), aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++) {
      if (!v[i].empty()) // avoid sorting empty vectors
        sort(v[i].begin(), v[i].end());
    }
    int D = 4 * R, ans = 0;
    for (int p = -D; p <= D; p++) {
      m[p + D] = sqrt((D - p) * (D + p)); // pre-calculate values of m
    }
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m[p + D]) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m[p + D]);
      }
    }
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 170
memory_kb: 4064
final_rank: 1

code_snippet: #include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
struct Point {
  int x;
  int y;
  char type;
  Point() { ; }
  Point(double x, double y, int type) : x(x), y(y), type(type) { ; }
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) {
      return y < rhs.y;
    }
    return x < rhs.x;
  }
};
struct Event {
  int x;
  Point p;
  char in;
  Event() { ; }
  Event(int x, Point p, int in) : x(x), p(p), in(in) { ; }
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) {
      return x < rhs.x;
    }
    return in > rhs.in;
  }
};
inline int square(int x) { return x * x; }
inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}
int an, bn, n;
int r;
Event event[500000];
int PlaneSweep() {
  int ans = 0;
  int maxDist = 16 * r * r; // Precompute 16 * r * r
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower =
          open[(int)p.type ^ 1].lower_bound(Point(0, p.y - 4 * r - 1, 0));
      set<Point>::iterator upper =
          open[(int)p.type ^ 1].upper_bound(Point(0, p.y + 4 * r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= maxDist) { // Use precomputed value
          ans++;
        }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}
int main() {
  std::ios_base::sync_with_stdio(false); // Fast IO operations
  cin.tie(NULL);
  while (scanf("%d %d %d", &an, &bn, &r), an | bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 250
memory_kb: 11080
final_rank: 20

code_snippet: #include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
struct Point {
  int x;
  int y;
  char type;
  Point() { ; }
  Point(double x, double y, int type) : x(x), y(y), type(type) { ; }
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) {
      return y < rhs.y;
    }
    return x < rhs.x;
  }
};
struct Event {
  int x;
  Point p;
  char in;
  Event() { ; }
  Event(int x, Point p, int in) : x(x), p(p), in(in) { ; }
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) {
      return x < rhs.x;
    }
    return in > rhs.in;
  }
};
inline int square(int x) { return x * x; }
inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}
int an, bn, n;
int r;
Event event[500000];
int PlaneSweep() {
  int ans = 0;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    int type_xor = (int)p.type ^ 1;
    if (e.in) {
      set<Point>::iterator lower =
          open[type_xor].lower_bound(Point(0, p.y - 4 * r - 1, 0));
      set<Point>::iterator upper =
          open[type_xor].upper_bound(Point(0, p.y + 4 * r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= 16 * r * r) {
          ans++;
        }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (cin >> an >> bn >> r, an | bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      cin >> x >> y;
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      cin >> x >> y;
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    cout << ans << "\n";
  }
  return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 10980
final_rank: 15

code_snippet: #include <algorithm>
#include <cassert>
#include <iostream>
#include <cmath>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x;
  int y;
  char type;
  Point() { ; }
  Point(double x, double y, int type) : x(x), y(y), type(type) { ; }
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) {
      return y < rhs.y;
    }
    return x < rhs.x;
  }
};

struct Event {
  int x;
  Point p;
  char in;
  Event() { ; }
  Event(int x, Point p, int in) : x(x), p(p), in(in) { ; }
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) {
      return x < rhs.x;
    }
    return in > rhs.in;
  }
};

inline int square(int x) { return x * x; }
inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}

int an, bn, n;
int r, four_r, sixteen_r_square;
Event event[500000];

int PlaneSweep() {
  int ans = 0;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower =
          open[(int)p.type ^ 1].lower_bound(Point(0, p.y - four_r - 1, 0));
      set<Point>::iterator upper =
          open[(int)p.type ^ 1].upper_bound(Point(0, p.y + four_r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= sixteen_r_square) {
          ans++;
        }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  while (cin >> an >> bn >> r, an | bn) {
    four_r = 4 * r;
    sixteen_r_square = 16 * r * r;
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      cin >> x >> y;
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      cin >> x >> y;
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    cout << ans << "\n";
  }
}
accuracy: 1
time_ms: 240
memory_kb: 10992
final_rank: 16

code_snippet: #include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x;
  int y;
  char type;
  Point() { ; }
  Point(double x, double y, int type) : x(x), y(y), type(type) { ; }
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) {
      return y < rhs.y;
    }
    return x < rhs.x;
  }
};

struct Event {
  int x;
  Point p;
  char in;
  Event() { ; }
  Event(int x, Point p, int in) : x(x), p(p), in(in) { ; }
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) {
      return x < rhs.x;
    }
    return in > rhs.in;
  }
};

inline int square(int x) { return x * x; }

inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}

int an, bn, n;
int r;
Event event[500000];
int r_square; // Precomputed square of radius

int PlaneSweep() {
  int ans = 0;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower =
          open[(int)p.type ^ 1].lower_bound(Point(0, p.y - 4 * r - 1, 0));
      set<Point>::iterator upper =
          open[(int)p.type ^ 1].upper_bound(Point(0, p.y + 4 * r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= r_square) { // Use precomputed square of radius
          ans++;
        }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}

int main() {
  while (scanf("%d %d %d", &an, &bn, &r), an | bn) {
    r_square = 16 * r * r; // Precompute square of radius
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 250
memory_kb: 11004
final_rank: 18

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
vector<int> v[10000];
bool used[10000] = {false};
int main() {
  int aN, bN, R;
  while (scanf("%d%d%d", &aN, &bN, &R) != EOF, aN) {
    int usedCount = 0;
    int usedIndices[10000];
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (!used[y]) {
        used[y] = true;
        usedIndices[usedCount++] = y;
      }
      v[y].push_back(x);
    }
    for (int i = 0; i < usedCount; i++)
      sort(v[usedIndices[i]].begin(), v[usedIndices[i]].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    printf("%d\n", ans);
    for (int i = 0; i < usedCount; i++) {
      v[usedIndices[i]].clear();
      used[usedIndices[i]] = false;
    }
  }
}
accuracy: 1
time_ms: 190
memory_kb: 4100
final_rank: 4

code_snippet: #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      cin >> x >> y;
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      if (!v[i].empty())
        sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      cin >> x >> y;
      for (int p = -D; p <= D; p++) {
        int yPlusP = y + p;
        if (yPlusP < 0 || yPlusP >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[yPlusP].begin(), v[yPlusP].end(), x + m) -
               lower_bound(v[yPlusP].begin(), v[yPlusP].end(), x - m);
      }
    }
    cout << ans << '\n';
  }
}
accuracy: 1
time_ms: 320
memory_kb: 4548
final_rank: 14

code_snippet: #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<int> v[10000];
int main() {
  ios::sync_with_stdio(false); // to speed up I/O operations
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear(); // clear the vector after using its elements
    for (int i = 0; i < aN; i++) {
      int x, y;
      cin >> x >> y; // use std::cin instead of scanf
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      if (!v[i].empty()) // avoid sorting empty vectors
        sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      cin >> x >> y; // use std::cin instead of scanf
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 190
memory_kb: 4632
final_rank: 8

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  int aN, bN, R;
  while (scanf("%d%d%d", &aN, &bN, &R), aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].insert(lower_bound(v[y].begin(), v[y].end(), x), x);
    }
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        vector<int>& vp = v[y + p];
        ans += upper_bound(vp.begin(), vp.end(), x + m) -
               lower_bound(vp.begin(), vp.end(), x - m);
      }
    }
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 200
memory_kb: 4500
final_rank: 9

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];

int main() {
  int aN, bN, R;
  while (scanf("%d%d%d", &aN, &bN, &R), aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = (int)sqrt((double)(D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 180
memory_kb: 4156
final_rank: 2

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  int aN, bN, R;
  while (scanf("%d%d%d", &aN, &bN, &R), aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      if (!v[i].empty())
        sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = max(-D, -y); p <= min(D, 9999 - y); p++) {
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 190
memory_kb: 4144
final_rank: 5

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
int main() {
  int x, y;
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    vector<int> v[10000];
    for (int i = 0; i < aN; i++) {
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt(D * D - p * p);
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 200
memory_kb: 3756
final_rank: 6

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 200
memory_kb: 4608
final_rank: 12

code_snippet: #include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
struct Point {
  int x;
  int y;
  char type;
  Point() { ; }
  Point(double x, double y, int type) : x(x), y(y), type(type) { ; }
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) {
      return y < rhs.y;
    }
    return x < rhs.x;
  }
};
struct Event {
  int x;
  Point p;
  char in;
  Event() { ; }
  Event(int x, Point p, int in) : x(x), p(p), in(in) { ; }
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) {
      return x < rhs.x;
    }
    return in > rhs.in;
  }
};
inline int square(int x) { return x * x; }
inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}
int an, bn, n;
int r;
Event event[500000];
int PlaneSweep() {
  int ans = 0;
  int r4 = 4 * r;
  int r2 = 16 * r * r;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower =
          open[(int)p.type ^ 1].lower_bound(Point(0, p.y - r4 - 1, 0));
      set<Point>::iterator upper =
          open[(int)p.type ^ 1].upper_bound(Point(0, p.y + r4 + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= r2) {
          ans++;
        }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}
int main() {
  while (scanf("%d %d %d", &an, &bn, &r), an | bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 250
memory_kb: 10924
final_rank: 17

code_snippet: #include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
struct Point {
  int x;
  int y;
  char type;
  Point() { ; }
  Point(double x, double y, int type) : x(x), y(y), type(type) { ; }
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) {
      return y < rhs.y;
    }
    return x < rhs.x;
  }
};
struct Event {
  int x;
  Point p;
  char in;
  Event() { ; }
  Event(int x, Point p, int in) : x(x), p(p), in(in) { ; }
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) {
      return x < rhs.x;
    }
    return in > rhs.in;
  }
};
inline int square(int x) { return x * x; }
inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}
int an, bn, n;
int r;
Event event[500000];
int PlaneSweep() {
  int ans = 0;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower =
          open[(int)p.type ^ 1].lower_bound(Point(0, p.y - 4 * r - 1, 0));
      set<Point>::iterator upper =
          open[(int)p.type ^ 1].upper_bound(Point(0, p.y + 4 * r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= 16 * r * r) {
          ans++;
        }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}
int main() {
  while (scanf("%d %d %d", &an, &bn, &r), an | bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 250
memory_kb: 11044
final_rank: 19

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
              lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 200
memory_kb: 4544
final_rank: 10

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 200
memory_kb: 4552
final_rank: 11

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<int> v[10000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int aN, bN, R;
  while (scanf("%d%d%d", &aN, &bN, &R), aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt((D - p) * (D + p));
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 4568
final_rank: 7