#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back                     

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 2100;

const ld eps = 1e-6;

int x[MAXN];
int y[MAXN];
int l,d,n,m;
double sq[MAXN][MAXN];

ll sqr(ll x){
    return x*x;    
}

double get(int l,int r,int l1,int r1){
    //assert(0 <= l && l <= r && r < n);
    //assert(0 <= l1 && l1 <= r1 && r1 < m);
    return x[r] + y[r1] - x[l] - y[l1] + sq[l][l1] + sq[r][r1];
}

bool check(int ans){
    for (int cnt1 = 1; cnt1 < ans && cnt1 <= n; cnt1++){
        int cnt2 = ans - cnt1;
        if (cnt2 > m)
            continue;
        int ptr = 0;                        
        for (int j = 0; j + cnt1 <= n; j++){
            double cur = get(j,j+cnt1-1,ptr,ptr+cnt2-1);
            while (ptr + cnt2 < m){
                double temp = get(j,j+cnt1-1,ptr+1, ptr+cnt2);
                if (temp < cur) {
                    cur = temp;
                    ptr++;
                }
                else
                    break;
            }
            if (cur < l)
                return true;
        }
    }
    return false;
}


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

  scanf("%d %d %d",&l,&d,&n);

  assert(0 <= n && n <= MAXN);

  for (int i = 0; i < n; i++)
    scanf("%d",&x[i]);

  scanf("%d",&m);
  assert(0 <= m && m <= MAXN);
  for (int j = 0; j < m; j++)
    scanf("%d",&y[j]);                     

  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
        sq[i][j] = sqrt((x[i] - y[j]) * 1LL * (x[i] - y[j]) + d * 1LL * d);

   int l = 2;
   int r = n+m+1;

   //check(21);
   //return 0;

   if (!check(2)){
    printf("%d\n",0);
    return 0;
   }

   while (r - l > 1){
       int mid = (l+r)/2;
       if (!check(mid))
         r = mid;
       else
         l = mid;
   }

   assert(check(l));


   cout << l << endl;         
   return 0;
}