#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const int MAXN = 5000; // must be at least summery number of points
int maxp2[MAXN + 1];

class sparse {
  double* data;
  int n, k;

  public:
  sparse() {
    n = k = 0;
    data = 0;
  }
  void init(int _n) {
    if (data) delete[] data;
    n = _n;
    k = 0; while ((1 << k) <= n) k++;
    data = new double[n * k];
    for (int i = 0; i < n * k; i++)
      data[i] = 1e100;
  }
  ~sparse() { if (data) delete[] data; }

  void relaxPostpone(int x, double val) {
    data[x] = min(data[x], val);
  }
  void update() {
    for (int i = 1; i < k; i++)
    for (int i2 = 0; i2 < n; i2++) {
      double &val = data[i * n + i2];
      val = data[(i - 1) * n + i2];
      if (i2 + (1 << (i - 1)) < n)
        val = min(val, data[(i - 1) * n + i2 + (1 << (i - 1))]);
    }
  }

  double get(int l, int r) {
    int len = r - l + 1;
    int y = maxp2[len];
    return min(data[y*n + l], data[y*n + r + 1 - (1 << y)]);
  }
};

const double EPS = 1e-9;
double maxlen, line_dist;
int n, m;
int xs[MAXN], ys[MAXN];

double dist(int a, int b) {
  return sqrt(line_dist * line_dist + double(a - b) * (a - b));
}

sparse trs[MAXN];
int mina[MAXN], maxa[MAXN];

bool check(int mincnt) {
  for (int a = 0; a < n; a++)
  for (int b = 0; b < m; b++) {
    if (n + m - a - b < mincnt) break;
    
    int sum = mincnt + a + b - 2;
    if (sum < 0 || sum >= n + m) continue;

    int l = a, r = sum - b;
    l = max(l, mina[sum]);
    r = min(r, maxa[sum]);
    if (l > r) continue;

    double res = trs[sum].get(l - mina[sum], r - mina[sum]);
    res += dist(xs[a], ys[b]);
    res -= xs[a] + ys[b];
    if (res <= maxlen + EPS) {
      return true;
    }
  }
  return false;
}

int main() {
  freopen("birch.in", "r", stdin);
  freopen("birch.out", "w", stdout);

  memset(maxp2, -1, sizeof maxp2);
  for (int i = 0; (1 << i) <= MAXN; i++)
    maxp2[1 << i] = i;
  for (int i = 1; i <= MAXN; i++)
    maxp2[i] = max(maxp2[i], maxp2[i - 1]);

  while (scanf("%lf%lf%d", &maxlen, &line_dist, &n) >= 1) {
    for (int i = 0; i < n; i++)
      scanf("%d", &xs[i]);
    sort(xs, xs + n);

    scanf("%d", &m);
    for (int i = 0; i < m; i++)
      scanf("%d", &ys[i]);
    sort(ys, ys + m);

    for (int i = 0; i < n + m; i++) {
      mina[i] = 1e9;
      maxa[i] = -1;
    }
    for (int a = 0; a < n; a++)
    for (int b = 0; b < m; b++) {
      mina[a + b] = min(mina[a + b], a);
      maxa[a + b] = max(maxa[a + b], a);
    }
    for (int i = 0; i < n + m; i++) {
      trs[i].init(maxa[i] - mina[i] + 1);
    }
    for (int a = 0; a < n; a++) {
      for (int b = 0; b < m; b++) {
        double csum = xs[a] + ys[b] + dist(xs[a], ys[b]);
        trs[a + b].relaxPostpone(a - mina[a + b], csum);
      }
    }
    for (int i = 0; i < n + m; i++)
      trs[i].update();

    int L = 2, R = n + m + 1;
    if (!check(L)) {
      L = R = 0;
    }

    while (L + 1 < R) {
      int M = (L + R) / 2;
      if (check(M)) L = M;
      else R = M;
    }
    printf("%d\n", L);
  }
  return 0;
}
