#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define inf 1000000000000000000
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto& a : x)

vi a,b,ind;

bool mysort(int i, int j){
  if (b[i]){
    if (b[j]){
      return a[i]>a[j];
    } else {
      return 0;
    }
  } else if (b[j]){
    return 1;
  } else {
    return a[i] > a[j];
  }
}

vector<bool> _;
vector< vector<bool> > dp;

int main(){
  _.assign(10002,false);
  ll n,l,r,hi,lo,cnt = 0; cin >> n >> l >> r;
  a.assign(n,0); b.assign(n,0);
  rep(i,0,n){ cin >> a[i]; }
  rep(i,0,n){ cin >> b[i]; cnt+=b[i]; }
  rep(i,0,n){ ind.push_back(i); }
  lo = 1; hi = cnt+1;
  sort(ind.begin(),ind.end(),mysort);

  dp.assign(n+2,_);
  rep(i,0,n+1) dp[i][0] = 1;
  rep(j,0,10001){
    rep(i,0,n){
      if (dp[i][j]) {
        dp[i+1][j+a[ind[i]]] = 1;
        dp[i+1][j] = 1;
      }
    }
  }
  ll check = 0,ds = 0,cc = 1;
  while (!check){
    if (cc > cnt) { cout << 0 << endl; exit(0); }
    if (r-ds < 0) { cout << 0 << endl; exit(0); }
    rep(i,max(l-ds,ll(0)),r+1-ds){
      if (dp[n-cc][i]) { check = 1; break; }
    }
    ds += a[ind[n-cc]]; cc++;
  }
/*
  rep(i,0,n){
    cout << ind[i] << " " << a[ind[i]] << " " << b[ind[i]] << endl;
  }
  cout << endl;
*/
  while (lo + 1 < hi){
    ll m = (hi+lo)/2;
    ll s = 0, lim;
    per(i,n-1,n-m+1) s += a[ind[i]];
    lim = r-s;
    //cout << m << " " << s << " " << lim << endl;
    if (lim < l){
      hi = m;
    } else {
      bool check = 0;
      rep(j,l,lim+1){
        if (dp[n-m][j]) { check = 1; break; }
      }
      if (check){
        lo = m;
      } else {
        hi = m;
      }
    }
  }
  cout << lo << endl;
  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define inf 1000000000000000000
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto& a : x)

vi a,b,ind;

bool mysort(int i, int j){
  if (b[i]){
    if (b[j]){
      return a[i]>a[j];
    } else {
      return 0;
    }
  } else if (b[j]){
    return 1;
  } else {
    return a[i] > a[j];
  }
}

vector<bool> _;
vector< vector<bool> > dp,dpu;

int main(){
  _.assign(10002,false);
  ll n,l,r,hi,lo,cnt = 0; cin >> n >> l >> r;
  a.assign(n,0); b.assign(n,0);
  rep(i,0,n){ cin >> a[i]; }
  rep(i,0,n){ cin >> b[i]; cnt+=b[i]; }
  rep(i,0,n){ ind.push_back(i); }
  lo = 0; hi = cnt+1;
  sort(ind.begin(),ind.end(),mysort);

  dp.assign(n+2,_);
  dpu.assign(n+2,_);
  rep(i,0,n+1) dp[i][0] = 1;
  rep(j,0,10001){
    rep(i,0,n){
      if (dp[i][j]) {
        dp[i+1][j+a[ind[i]]] = 1;
        dp[i+1][j] = 1;
        if (i >= n-cnt){
          if (dpu[i][j]) {
            dpu[i+1][j+a[ind[i]]] = 1;
            dpu[i+1][j] = 1;
          } else {
            dpu[i+1][j] = 1;
          }
        }
      }
    }
  }
/*
  ll check = 0,ds = 0,cc = 1;
  while (!check){
    if (cc > cnt) { cout << 0 << endl; exit(0); }
    if (r-ds < 0) { cout << 0 << endl; exit(0); }
    rep(i,max(l-ds,ll(0)),r+1-ds){
      if (dp[n-cc][i]) { check = 1; break; }
    }
    ds += a[ind[n-cc]]; cc++;
  }
*/
  /*
  rep(i,0,n){
    cout << ind[i] << " " << a[ind[i]] << " " << b[ind[i]] << endl;
  }
  cout << endl;
  */
  while (lo + 1 < hi){
    ll m = (hi+lo)/2;
    ll s = 0, lim;
    per(i,n-1,n-m+1) s += a[ind[i]];
    lim = r-s;
    //cout << m << " " << s << " " << lim << endl;
    if (lim < l){
      hi = m;
    } else {
      bool check = 0;
      rep(j,l,lim+1){
        if (dp[n-m+1][j] && dpu[n-m+1][j]) { check = 1; break; }
      }
      if (check){
        lo = m;
      } else {
        hi = m;
      }
    }
  }
  cout << lo << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
int n,dp[N],l,r;

struct node {int v,tp;} a[N];

int main () {
    ios::sync_with_stdio(false);
    cin >> n >> l >> r;
	int sum = 0;
    for (int i = 1;i <= n;i++) cin >> a[i].v,sum += a[i].v;
    for (int i = 1;i <= n;i++) cin >> a[i].tp;
    sort( a + 1,a + n + 1,
    [](node a, node b) { return a.tp < b.tp || (a.tp == b.tp && a.v > b.v); } );
    int tmp = l;l = sum - r;r = sum - tmp;
    for (int i = 1;i <= sum;i++) dp[i] = INT_MIN >> 2;
    dp[0] = 0;
    for (int i = 1;i <= n;i++)
        for (int j = sum;j >= a[i].v;--j)
            dp[j] = max(dp[j],dp[j - a[i].v] + a[i].tp * (l <= j && j <= r));
    cout << *max_element(dp + 1, dp + sum + 1) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
int n,dp[N],l,r;

struct node {int v,tp;} a[N];

int main () {
    ios::sync_with_stdio(false);
    cin >> n >> l >> r;
	int sum = 0;
    for ( int i = 1; i <= n; ++ i ) cin >> a[i].v,sum += a[i].v;
    for ( int i = 1; i <= n; ++ i ) cin >> a[i].tp;
    sort( a + 1,a + n + 1,
    [](node a, node b) { return a.tp < b.tp || (a.tp == b.tp && a.v > b.v); } );
    int tmp = l;
	l = sum - r;
	r = sum - tmp;
    for ( int i = 1; i <= sum; ++ i) dp[i] = INT_MIN >> 2;
    dp[0] = 0;
    for ( int i = 1;i <= n; ++ i )
        for ( int j = sum; j >= a[i].v; -- j)
            dp[j] = max(dp[j],dp[j - a[i].v] + a[i].tp * (l <= j && j <= r));
    cout << *max_element(dp + 1, dp + sum + 1) << endl;
    return 0;
}


#include <queue>
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <cmath>
#include <thread>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <chrono>
#include <random>

using namespace std;

using ll = long long;

const int N = 1e4 + 1;

int main() {
	int n, l, r;
	scanf("%d%d%d", &n, &l, &r);

	vector<bool> d1(N, false), d2(N, false);
	vector<int> p(N, -1);

	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i].first);
	}

	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i].second);
	}

	vector<int> b, c;
	for (int i = 0; i < n; ++i) {
		if (a[i].second == 0) b.push_back(a[i].first);
		if (a[i].second == 1) c.push_back(a[i].first);
	}
	sort(b.rbegin(), b.rend());
	sort(c.rbegin(), c.rend());
	a.clear();
	for (auto x : b) {
		a.push_back({x, 0});
	}
	b = c;
	for (auto x : b) {
		a.push_back({x, 1});
	}
	d1[0] = true;
	for (int i = 0; i < n; ++i) {
		for (int j = a[i].first; j < N; ++j) {
			if (d1[j]) {
				d2[j] = true;
			} else {
				if (d1[j - a[i].first]) {
					d2[j] = true;
					p[j] = i;
				}
			}
		}
		for (int j = 1; j < N; ++j) {
			d1[j] = d2[j];
			d2[j] = false;
		}
	}
	int ans = 0;

	for (int i = 0; i <= r; ++i) {
		if (i >= l && d1[i]) {
			vector<bool> was(n, false);
			int cur = i;
			while (cur > 0) {
				was[p[cur]] = true;
				cur -= a[p[cur]].first;
			}
			cur = i;
			int res = 0;
			for (int j = n - 1; j >= 0 && cur <= r && a[j].second == 1; --j) {
				if (!was[j]) {
					++res;
					cur += a[j].first;
				}
			}
			ans = max(res, ans);
		}
	}
	printf("%d\n", ans);
}


#include<bits/stdc++.h>
#define ll long long
#define N 10005
using namespace std;
int n,L,R,cnt,sum,a[N],b[N],s[N];
bitset<N>f,g;
int main(){
	scanf("%d%d%d",&n,&L,&R);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	f[0]=1;
	for(int i=1;i<=n;i++){
		if(!b[i])f|=(f<<a[i]);
		else s[++cnt]=a[i],sum+=a[i];
	}
	sort(s+1,s+1+cnt);
	for(int i=cnt;i>=1;i--){
		sum-=s[i];g=f|(g<<s[i]);f|=(f<<s[i]);
		if(g._Find_next(L-1)+sum<=R)
		return printf("%d",i),0;
	}
	puts("0");
	return 0;
}


#include<bits/stdc++.h>
#define rint register int
using namespace std;

int n, tot, now, l, r, f[10100], g[10100];

struct Node{
  int h, type;
}a[10100];
bool cmp(Node a,Node b){
  return a.type==b.type? a.h>b.h: a.type<b.type;
}

inline void U(int &x,int y){
  x=max(x,y);
}
inline int chk(int x){
  return x>=l&&x<=r;
}

int main(){
  cin>>n>>l>>r;
  for (int i=1;i<=n;++i) cin>>a[i].h, tot+=a[i].h;
  for (int i=1;i<=n;++i) cin>>a[i].type;
  sort(a+1,a+n+1,cmp);
  memset(f,-1,sizeof f); f[0]=0;
  for (int i=1;i<=n;++i){
    memset(g,-1,sizeof g);
    for (rint j=0;j<=now;++j)
      if (~f[j]){
        U(g[j+a[i].h],f[j]+(a[i].type&&chk(j)));
        U(g[j],f[j]+(a[i].type&&chk(tot-now+j-a[i].h)));
      }
    now+=a[i].h;
    memcpy(f,g,sizeof g);
  }
  cout<<*max_element(f,f+tot+1);
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 10005;

int n,l,r;
int a0[N],a1[N];
int k0,k1;
int a[N];
bool import[N];
bool pd[N];
int pre[N];
int sum[N];

int main(){
	n=get();l=get();r=get();
	fo(i,1,n)a[i]=get();
	fo(i,1,n)import[i]=get();
	k0=k1=0;
	fo(i,1,n)if (import[i])a1[++k1]=a[i];else a0[++k0]=a[i];
	int len=0;
	fo(i,1,n)len=len+a[i];
	pd[0]=1;
	fo(i,1,k0){
		fd(j,10000,a0[i])pd[j]|=pd[j-a0[i]];
	}
	fo(i,1,10000){
		pre[i]=pre[i-1];
		if (pd[i])pre[i]=i;
	}
	//fo(i,0,10000)pd[i]=0;
	//pd[0]=1;
	sort(a1+1,a1+1+k1);
	fo(i,1,k1)sum[i]=sum[i-1]+a1[i];
	int ans=0;
	fd(i,k1,1){
		if (sum[i-1]<=r){
			int ps=sum[i-1];
			int d=pre[r-sum[i-1]];
			if (d+ps>=l&&d+ps<=r){
				int L=1,R=i-1,ret=0;
				while(L<=R){
					int mid=(L+R)/2;
					if (ps-sum[mid]+d>=l)ret=mid,L=mid+1;
					else R=mid-1;
				}
				ans=max(ans,ret+1);
			}
		}
		if (sum[i]<=r){
			int d=pre[r-sum[i]];
			if (d+sum[i]>=l&&d+sum[i]<=r){
				int L=1,R=i,ret=0;
				while(L<=R){
					int mid=(L+R)/2;
					if (sum[i]-sum[mid]+d>=l)ret=mid,L=mid+1;
					else R=mid-1;
				}
				ans=max(ans,ret);
			}

		}
		fd(j,10000,a1[i])pd[j]|=pd[j-a1[i]];
		fo(j,1,10000){
			pre[j]=pre[j-1];
			if (pd[j])pre[j]=j;
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10005;
struct node{
	int v,p;
}a[N];
int n,l,r,sum,f[N];
bool cmp(node a,node b){
	if(a.p==b.p)return a.v>b.v;
	else return a.p<b.p;
}
int main (){
	scanf("%d%d%d",&n,&l,&r);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i].v);
    	sum+=a[i].v;
	}
    for(int i=1;i<=n;i++)
		scanf("%d",&a[i].p);
    sort(a+1,a+n+1,cmp);
    int ll=l;
	l=sum-r;r=sum-ll;
    for(int i=1;i<=sum;i++)f[i]=-1e9;
    f[0]=0;
    for(int i=1;i<=n;i++)
        for(int j=sum;j>=a[i].v;j--){
        	int x=0;
        	if(l<=j&&j<=r)x=a[i].p;
            f[j]=max(f[j],f[j-a[i].v]+x);
		}
	printf("%d",*max_element(f+1,f+sum+1));
    return 0;
}


#pragma optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second

// debug defines
#ifdef HOME
    int jjj;
    #define PO cout << "Pomelo" << endl;
    #define OL cout << "Oliva" << endl;
    #define debug(x) cout << #x << " " << x << endl;
    #define debug_p(x) cout << #x << " " << x.ff << " " << x.ss << endl;
    #define debug_v(x) cout << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
    #define debug_vp(x) cout << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl;
    #define wait() cin >> jjj;
#else
    #define PO 0
    #define OL 0
    #define debug(x) 0
    #define debug_p(x) 0
    #define debug_vp(x) 0
    #define debug_v(x) 0
    #define debug_vp(x) 0
    #define wait() 0
#endif // HOME
// end of debug defines

int dp[10001];
bool was[10001];

int sum = 0;
int n;
pair<int, int> arr[10001];

bool cmp(pii a, pii b)
{
    return (a.ss < b.ss || (a.ss == b.ss && a.ff < b.ff));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    int l, r;
    cin >> n >> l >> r;
    for (int i = 0; i < n; ++i)
        cin >> arr[i].ff;
    for (int i = 0; i < n; ++i)
        cin >> arr[i].ss;

    sort(arr, arr + n, cmp);
    was[0] = 1;

    for (int i = 0; i < n; ++i)
    {
        for (int j = sum; j >= 0; --j)
        {
            if (!was[j])
                continue;
            was[j + arr[i].ff] = 1;
            dp[j + arr[i].ff] = max(dp[j + arr[i].ff], dp[j] + (arr[i].ss && l <= j));
        }
        sum = min(r, sum + arr[i].ff);
    }

    int ma = 0;
    for (int i = 0; i <= 10000; ++i)
        ma = max(ma, dp[i]);
    cout << ma;

    return 0;
}


#pragma optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second

// debug defines
#ifdef HOME
    int jjj;
    #define PO cout << "Pomelo" << endl;
    #define OL cout << "Oliva" << endl;
    #define debug(x) cout << #x << " " << x << endl;
    #define debug_p(x) cout << #x << " " << x.ff << " " << x.ss << endl;
    #define debug_v(x) cout << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
    #define debug_vp(x) cout << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl;
    #define wait() cin >> jjj;
#else
    #define PO 0
    #define OL 0
    #define debug(x) 0
    #define debug_p(x) 0
    #define debug_vp(x) 0
    #define debug_v(x) 0
    #define debug_vp(x) 0
    #define wait() 0
#endif // HOME
// end of debug defines

int dp[10001];
bool was[10001];

int sum = 0;
int n;
pair<int, int> arr[10001];

bool cmp(pii a, pii b)
{
    return (a.ss < b.ss || (a.ss == b.ss && a.ff > b.ff));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    int l, r;
    cin >> n >> l >> r;
    for (int i = 0; i < n; ++i){
        cin >> arr[i].ff;
        sum += arr[i].ff;
    }
    for (int i = 0; i < n; ++i)
        cin >> arr[i].ss;

    sort(arr, arr + n, cmp);
    was[0] = 1;

    for (int i = 0; i < n; ++i)
    {
        for (int j = sum; j >= arr[i].ff; --j)
        {
            if (!was[j - arr[i].ff])
                continue;
            was[j] = 1;
            dp[j] = max(dp[j], dp[j - arr[i].ff] + (arr[i].ss && j >= sum - r && j <= sum - l));
        }
    }

    int ma = 0;
    for (int i = 0; i <= 10000; ++i)
        ma = max(ma, dp[i]);
    cout << ma;

    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1e4+6;
int n,l,r,h[N],b[N],ans[N],S;
vector<int>X,Y;
int main(){
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;++i)scanf("%d",h+i),S+=h[i];
	for(int i=1;i<=n;++i)scanf("%d",b+i);
	int _l=S-r,_r=S-l;
	for(int i=1;i<=n;++i)(b[i]?Y:X).push_back(h[i]);
	sort(X.rbegin(),X.rend()),sort(Y.rbegin(),Y.rend());
	for(int i=1;i<=10000;++i)ans[i]=-1e9;
	for(int s:X)
	for(int i=10000;i>=s;--i)if(ans[i-s]>=0)ans[i]=max(ans[i],ans[i-s]);
	for(int s:Y)
	for(int i=10000;i>=s;--i)if(ans[i-s]>=0)ans[i]=max(ans[i],ans[i-s]+(_l<=i&&i<=_r));
	printf("%d\n",*max_element(ans,ans+10001));
}


//Giorgi Kldiashvili

#include <bits/stdc++.h>

#define fr first
#define sc second
#define ll long long
#define Left v + v
#define Right v + v + 1

using namespace std;
const int N = 10020;

int n, m, answer, L, R, S;
vector < int > a, b;
int read[N], P[N];
pair < int, int > A[N];

int main()
{
  scanf("%d %d %d", &n, &L, &R);
  for(int i = 1; i <= n; ++ i)
    scanf("%d", &read[i]), S += read[i];
  a.push_back(0);
  b.push_back(0);
  for(int i = 1; i <= n; ++ i)
  {
    int x;
    scanf("%d", &x);
    if(x)
      a.push_back(read[i]);
    else
      b.push_back(read[i]);
  }
  n = a.size(); m = b.size();
  sort(a.begin(), a.end());
  A[0] = {1, 0};
  P[0] = a[0];
  for(int i = 1; i < n; ++ i)
    P[i] = P[i - 1] + a[i];
  for(int i = 0; i < m; ++ i)
  {
    int x = b[i];
    for(int j = S; j >= x; -- j)
    {
      if(!A[j - x].first)
        continue;
      A[j] = {1, 0};
    }
  }

  int cur = n - 1;
  for(int i = L; i <= S; ++ i)
  {
    if(i > R)
      break;
    while(P[cur] > R - i)
      cur --;
    if(A[i].first == 0)
      continue;
    if(cur == n - 1)
      answer = max(answer, cur);
    else
      answer = max(answer, cur + 1);
  }
  for(int j = n - 1; j > 0; -- j)
  {
    int x = a[j];
    for(int i = S; i >= x; -- i)
    {
      if(!A[i - x].first) continue;
      if(!A[i].first || A[i].second > A[i - x].second + 1)
        A[i] = {1, A[i - x].second + 1};
    }
    cur = j - 1;
    for(int i = L; i <= S; ++ i)
    {
      if(i > R)
        break;
      while(P[cur] > R - i)
        cur --;
      if(A[i].first == 0)
        continue;
      if(cur + A[i].second == n - 1)
        answer = max(answer, cur);
      else
        answer = max(answer, cur + 1);
    }
  }
  printf("%d\n", answer);
}


//2019.9.3 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define unl __int128
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
//#define pc(x) __builtin_popcountll(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define gc getchar
//template <class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//inline int read() {
//    res s=0,ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
inline int read() {
    res s=0,ch=gc(),w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s*w;
}
inline LL Read() {
    RG LL s=0;
    res ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG unl x){
//    if(x>10)write(x/10);
//    putchar(int(x%10)+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=1e4+10;
namespace MAIN{
    int n,l,r;
    int a[N],H;
    vector<int> A,B;
    inline bool cmp(const res &x,const res &y){
        return a[x]>a[y];
    }
    int dp[N],ans;
    inline void MAIN(){
        n=read(),l=read(),r=read(),memset(dp,-inf,sizeof(dp)),dp[0]=0;
        for(res i=1;i<=n;i++)a[i]=read(),H+=a[i];
        for(res i=1;i<=n;i++)read()?B.pb(i):A.pb(i);
        swap(l,r),l=H-l,r=H-r,sort(B.begin(),B.end(),cmp);
        for(auto x:A)for(res i=H;i>=a[x];i--)dp[i]=max(dp[i],dp[i-a[x]]);
//        for(res i=0;i<=H;i++)printf("%d\n",dp[i]);
        for(auto x:B)for(res i=H;i>=a[x];i--)dp[i]=max(dp[i],dp[i-a[x]]+(l<=i&&i<=r));
        for(res i=0;i<=H;i++)ans=max(ans,dp[i]);
        printf("%d\n",ans);
    }
}
int main(){
//    srand(19260817);
//    freopen("signin.in","r",stdin);
//    freopen("signin.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int max_n = 10011, inf = 1000111222;

int n, L, R;
vector<int> ok, bad;
bitset<max_n> pref[max_n], suf[max_n], start;

bool check(int k) {
    bitset<max_n> cur = start;
    for (int i = k; i < ok.size(); ++i) {
        cur |= (cur << ok[i]);
    }
    int pos = -1;
    for (int i = L; i <= R; ++i) {
        if (cur[i]) {
            pos = i;
            break;
        }
    }
    if (pos == -1) {
        return false;
    }
    for (int i = 0; i + 1 < k; ++i) {
        pos += ok[i];
    }
    return pos <= R;
}

void read() {
    int a[max_n], b[max_n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < n; ++i) {
        if (b[i]) {
            ok.push_back(a[i]);
        } else {
            bad.push_back(a[i]);
        }
    }
}

int best() {
    int l = 0, r = ok.size();
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d%d", &n, &L, &R);
    read();
    sort(ok.begin(), ok.end());
    sort(bad.begin(), bad.end());
    if (0) {
        for (int i = 0; i < ok.size(); ++i) {
            cout << ok[i] << " ";
        }
        cout << endl;
    }
    start[0] = 1;
    for (int i = 0; i < bad.size(); ++i) {
        start |= (start << bad[i]);
    }

    int k = best();
    int ans = k;
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += ok[i];
    }
    pref[k] = start;
    for (int i = k; i < ok.size(); ++i) {
        pref[i + 1] = pref[i] | (pref[i] << ok[i]);
    }
    suf[ok.size()][0] = 1;
    for (int i = ((int) ok.size()) - 1; i >= 0; --i) {
        suf[i] = suf[i + 1] | (suf[i + 1] << ok[i]);
    }
    bool was = false;
    bool pl = false;
    for (int i = k; i < ok.size(); ++i) {
        if (!was || (ok[i] != ok[i - 1])) {
            was = true;
            vector<int> a, b;
            for (int j = 0; j <= R; ++j) {
                if (pref[i][j]) {
                    a.push_back(j);
                }
                if (suf[i + 1][j]) {
                    b.push_back(j);
                }
            }
            int pos = b.size() - 1;
            for (int j = 0; j < a.size(); ++j) {
                while (pos > 0 && a[j] + b[pos - 1] >= L) {
                    --pos;
                }
                //cout << a[j] << " " << b[pos] << " " << sum << endl;
                if (a[j] + b[pos] >= L && a[j] + b[pos] + sum <= R) {
                    pl = true;
                    break;
                }
            }
            if (pl) {
                break;
            }
        }
    }
    ans += pl;
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bitset<10001> can;
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, l, r;
  cin >> n >> l >> r;
  int w[n];
  int imp[n];
  int h;
  for(int i = 0;i < n;i++){
    scanf("%d", w + i);
    h += w[i];
  }

  int t = l;
  l = h - r;
  r = h - t;

  for(int i = 0;i < n;i++){
    scanf("%d", imp + i);
  }
  int imp_n, non_n;
  imp_n = non_n = 0;
  int a_imp[10001], a_non[10001];
  for(int i = 0;i < n;i++){
    if(imp[i]){
      a_imp[imp_n++] = w[i];
    }else{
      a_non[non_n++] = w[i];
    }
  }
  can[0] = 1;
  for(int i = 0;i < non_n;i++){
    can |= can << a_non[i];
  }

  sort(a_imp, a_imp + n, [](const int&a, const int& b){
    return b < a;
  });

  int val[10001] = {0};

  for(int i = 0;i < imp_n;i++){
    for(int j = 0;j <= 10000;j++){
      if(can[j]){
        val[j + a_imp[i]] = max(val[j + a_imp[i]], val[j] + (a_imp[i] + j >= l && a_imp[i] + j <= r ? 1 : 0));
      }
    }
  }
  int mx = 0;
  for(int i = 0;i < 10000;i++){
    mx = max(mx, val[i]);
  }
  cout << mx;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
bitset<10001> can;
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, l, r;//
  cin >> n >> l >> r;
  int w[n];
  int imp[n];
  int h = 0;
  for(int i = 0;i < n;i++){
    scanf("%d", w + i);
    h += w[i];
  }

  int t = l;
  l = h - r;
  r = h - t;

  for(int i = 0;i < n;i++){
    scanf("%d", imp + i);
  }
  int imp_n, non_n;
  imp_n = non_n = 0;
  int a_imp[10001], a_non[10001];
  for(int i = 0;i < n;i++){
    if(imp[i]){
      a_imp[imp_n++] = w[i];
//cout << w[i] << endl;
    }else{
      a_non[non_n++] = w[i];
 //cout << w[i] << endl;
}
  }
  can[0] = 1;
  for(int i = 0;i < non_n;i++){
    can |= can << a_non[i];
//cout << can << endl;
  }

  sort(a_imp, a_imp + n, [](const int&a, const int& b){
    return b < a;
  });

  int val[2][10001] = {0};

  for(int i = 0;i < imp_n;i++){
    for(int j = 0;j <= 10000;j++){
      if(can[j]){
        val[i&1][j + a_imp[i]] = max(val[i&1^1][j + a_imp[i]], val[i&1^1][j] + (a_imp[i] + j >= l && a_imp[i] + j <= r ? 1 : 0));
      }
    }
    can |= can << a_imp[i];
  }
  int mx = 0;
  for(int i = 0;i < 10000;i++){
    mx = max(mx, val[(imp_n-1)&1][i]);
  }
  cout << mx;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N];
bitset<N> height;

int getnum(vector<int>& s, int l, int r) {
  return upper_bound(s.begin(), s.end(), r) - lower_bound(s.begin(), s.end(), l);
}

int main() {
  scanf("%d%d%d", &n, &l, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  vector<int> tmp;
  height[0] = 1;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) {
      tmp.push_back(a[i]);
    } else {
      height |= height << a[i];
    }
  }
  vector<int> s(tmp.size(), 0);
  for (int i = 1; i < tmp.size(); ++i) {
    s[i] = s[i - 1] + tmp[i - 1];
  }
  sort(s.begin(), s.end());
  int answer = 0;
  for (int i = 0; i <= r; ++i) {
    if (height[i]) {
      answer = max(answer, getnum(s, max(0, l - i), r - i));
    }
  }
  printf("%d\n", answer);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N], f[N];

int main() {
  scanf("%d%d%d", &n, &l, &r);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  vector<int> s0, s1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    if (!b[i]) {
      s0.push_back(a[i]);
    } else {
      s1.push_back(a[i]);
    }
  }
  sort(s1.begin(), s1.end(), greater<int>());
  int t = r;
  r = sum - l;
  l = sum - t;
  memset(f, -1, sizeof f);
  f[0] = 0;
  for (auto v : s0) {
    for (int j = sum; j >= v; --j) {
      f[j] = max(f[j], f[j - v]);
    }
  }
  int answer = 0;
  for (auto v : s1) {
    for (int j = sum; j >= v; --j) {
      f[j] = max(f[j], f[j - v] + (j >= l && j <= r));
      answer = max(answer, f[j]);
    }
  }
  printf("%d\n", answer);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N];
bitset<N> height;

int getnum(vector<int>& s, int l, int r) {
  return upper_bound(s.begin(), s.end(), r) - lower_bound(s.begin(), s.end(), l);
}

int main() {
  scanf("%d%d%d", &n, &l, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  vector<int> tmp;
  height[0] = 1;
  int sumh = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) {
      tmp.push_back(a[i]);
    } else {
      height |= height << a[i];
      sumh += a[i];
    }
  }
  vector<int> s(tmp.size(), 0);
  for (int i = 1; i < tmp.size(); ++i) {
    s[i] = s[i - 1] + tmp[i - 1];
  }
  sort(s.begin(), s.end());
  int answer = 0;
  for (int i = 0; i <= r; ++i) {
    if (i > sumh) {
      height |= height << tmp.back();
      sumh += tmp.back();
      tmp.pop_back();
      s.pop_back();
    }
    if (height[i]) {
      answer = max(answer, getnum(s, max(0, l - i), r - i));
    }
  }
  printf("%d\n", answer);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N];
bitset<N> height;

int getnum(vector<int>& s, int l, int r) {
  return upper_bound(s.begin(), s.end(), r) - lower_bound(s.begin(), s.end(), l);
}

int main() {
  scanf("%d%d%d", &n, &l, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  vector<int> tmp;
  height[0] = 1;
  int sumh = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) {
      if (a[i] <= r - l + 1) {
        tmp.push_back(a[i]);
      } else {
        b[i] = 0;
      }
    }
    if (!b[i]) {
      height |= height << a[i];
      sumh += a[i];
    }
  }
  vector<int> s(tmp.size(), 0);
  for (int i = 1; i < tmp.size(); ++i) {
    s[i] = s[i - 1] + tmp[i - 1];
  }
  sort(s.begin(), s.end());
  int answer = 0;
  for (int i = 0; i <= r; ++i) {
    if (i > sumh) {
      height |= height << tmp.back();
      sumh += tmp.back();
      tmp.pop_back();
      s.pop_back();
    }
    if (height[i]) {
      answer = max(answer, getnum(s, max(0, l - i), r - i));
    }
  }
  printf("%d\n", answer);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N], f[N];

int main() {
  scanf("%d%d%d", &n, &l, &r);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  vector<int> s0, s1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    if (!b[i]) {
      s0.push_back(a[i]);
    } else {
      s1.push_back(a[i]);
    }
  }
  sort(s1.begin(), s1.end(), greater<int>());
  int t = r;
  r = sum - l;
  l = sum - t;
  memset(f, -1, sizeof f);
  f[0] = 0;
  for (auto v : s0) {
    for (int j = sum; j >= v; --j) {
      f[j] = max(f[j], f[j - v]);
    }
  }
  int answer = 0;
  for (auto v : s1) {
    for (int j = sum; j >= v; --j) {
      if (~f[j - v]) {
        f[j] = max(f[j], f[j - v] + (j >= l && j <= r));
        answer = max(answer, f[j]);
      }
    }
  }
  printf("%d\n", answer);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N];
bitset<N> height, last;

int getnum(vector<int>& s, int l, int r) {
  return upper_bound(s.begin(), s.end(), r) - lower_bound(s.begin(), s.end(), l);
}

int main() {
  scanf("%d%d%d", &n, &l, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  vector<int> tmp;
  height[0] = 1;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) {
      tmp.push_back(a[i]);
    }
    if (!b[i]) {
      height |= height << a[i];
    }
  }
  sort(tmp.begin(), tmp.end());
  vector<int> s(tmp.size(), 0);
  for (int i = 1; i < tmp.size(); ++i) {
    s[i] = s[i - 1] + tmp[i - 1];
  }
  int answer = 0;
  while (tmp.size()) {
    last = last ^ height;
    for (int i = last._Find_first(); i <= r; i = last._Find_next(i)) {
      answer = max(answer, getnum(s, max(0, l - i), r - i));
    }
    last = height;
    height |= height << tmp.back();
    tmp.pop_back();
    s.pop_back();
  }
  printf("%d\n", answer);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int n, l, r, a[N], b[N];
bitset<N> height, last;

int getnum(vector<int>& s, int l, int r) {
  return upper_bound(s.begin(), s.end(), r) - lower_bound(s.begin(), s.end(), l);
}

int main() {
  scanf("%d%d%d", &n, &l, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  vector<int> tmp;
  height[0] = 1;
  int sumh = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) {
      tmp.push_back(a[i]);
    }
    if (!b[i]) {
      height |= height << a[i];
      sumh += a[i];
    }
  }
  vector<int> s(tmp.size(), 0);
  for (int i = 1; i < tmp.size(); ++i) {
    s[i] = s[i - 1] + tmp[i - 1];
  }
  sort(s.begin(), s.end());
  int answer = 0;
  while (tmp.size()) {
    last = last ^ height;
    for (int i = last._Find_first(); i <= r; i = last._Find_next(i)) {
      answer = max(answer, getnum(s, max(0, l - i), r - i));
    }
    last = height;
    height |= height << tmp.back();
    tmp.pop_back();
    s.pop_back();
  }
  printf("%d\n", answer);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int n,dp[N],l,r;
struct Box {int v,tp;} a[N];
int main ()
{
    ios::sync_with_stdio(false);
    cin >> n >> l >> r;int sum = 0;
    for (int i = 1;i <= n;i++) cin >> a[i].v,sum += a[i].v;
    for (int i = 1;i <= n;i++) cin >> a[i].tp;
    sort(a + 1,a + n + 1,
    [](Box a,Box b) {return a.tp < b.tp || (a.tp == b.tp && a.v > b.v);});
    int tmp = l;l = sum - r;r = sum - tmp;
    for (int i = 1;i <= sum;i++) dp[i] = INT_MIN >> 2;
    dp[0] = 0;
    for (int i = 1;i <= n;i++)
        for (int j = sum;j >= a[i].v;--j)
            dp[j] = max(dp[j],dp[j - a[i].v] + a[i].tp * (l <= j && j <= r));
    cout << *max_element(dp + 1,dp + sum + 1) << endl;
    return 0;
}
//关于题解里的 "standard optimization for the knapsack",
//可以把01背包转成多重背包再二进制分组最后转回来，
//貌似时间复杂度是O(Nsqrt(N))(N为背包容量，且本题中物品的体积和也为N)??
//纯属瞎猜，未经证明...//hello


#include <bits/stdc++.h>
using namespace std;

// this code can't be hacked, because i have a team of dwarfs,
// who already tried to do this, and if they couldn't, so can't you

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\input.txt", "r", stdin);
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\output.txt", "w", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#ifndef LOCAL
#define cerr if (false) cerr
#define DBG(...) (true)
#endif

#define vc vector
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define last(x) (--x.end())
#define D double
#define int long long

// --------------------------------------- NOW CODE --------------------------------

int n, l, r;
const int MAXN = 10005;
int a[MAXN];
int b[MAXN];
int ids[MAXN];
int H = 0;

bool cmp_ids(int i, int j) {
    if (b[i] != b[j]) {
        return b[i] < b[j];
    }
    else if (a[i] != a[j]) {
        return a[i] > a[j];
    }
    else {
        return i < j;
    }
}

const int MAXH = 10005;
int dp[MAXH];
int tmp[MAXH];

signed main() {
    doRoutine();

    cin >> n >> l >> r;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        H += a[i];
        ids[i] = i;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int nl = H - r;
    int nr = H - l;
    l = nl, r = nr;
    sort(ids, ids + n, cmp_ids);

    for (int i = 0; i <= r; ++i) {
        dp[i] = 0;
    }

    bitset<MAXH> used;
    used.set(0);
    used[0] = 1;
    for (int i = 0; i < n; ++i) {
        int id = ids[i];
        for (int j = 0; j <= r; ++j) {
            tmp[j] = dp[j];
        }
        for (int x = 0; x <= r; ++x) {
            dp[x] = tmp[x];
            if (a[id] <= x && used[x - a[id]]) {
                dp[x] = max(dp[x], tmp[x - a[id]] + (b[id] && x >= l));
            }
        }
        used = used | (used << a[id]);
    }

    int ans = 0;
    for (int i = 0; i <= r; ++i) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

// this code can't be hacked, because i have a team of dwarfs,
// who already tried to do this, and if they couldn't, so can't you

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\input.txt", "r", stdin);
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\output.txt", "w", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#ifndef LOCAL
#define cerr if (false) cerr
#define DBG(...) (true)
#endif

#define vc vector
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define last(x) (--x.end())
#define D double
#define int long long

// --------------------------------------- NOW CODE --------------------------------

int n, l, r;
const int MAXN = 10005;
int a[MAXN];
int b[MAXN];
int ids[MAXN];
int H = 0;

bool cmp_ids(int i, int j) {
    if (b[i] != b[j]) {
        return b[i] < b[j];
    }
    else if (a[i] != a[j]) {
        return a[i] > a[j];
    }
    else {
        return i < j;
    }
}

const int MAXH = 10005;
int dp[MAXH];
int tmp[MAXH];

signed main() {
    doRoutine();

    cin >> n >> l >> r;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        H += a[i];
        ids[i] = i;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int nl = H - r;
    int nr = H - l;
    l = nl, r = nr;
    sort(ids, ids + n, cmp_ids);

    for (int i = 0; i <= r; ++i) {
        dp[i] = 0;
    }

    bitset<MAXH> used;
    used.set(0);
    used[0] = 1;
    for (int i = 0; i < n; ++i) {
        used = used | (used << a[i]);
        int id = ids[i];
        for (int j = 0; j <= r; ++j) {
            tmp[j] = dp[j];
        }
        for (int x = 0; x <= r; ++x) {
            dp[x] = tmp[x];
            if (a[id] <= x && used[x - a[id]]) {
                dp[x] = max(dp[x], tmp[x - a[id]] + (b[id] && x >= l));
            }
        }
    }

    cout << dp[r] << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

// this code can't be hacked, because i have a team of dwarfs,
// who already tried to do this, and if they couldn't, so can't you

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\input.txt", "r", stdin);
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\output.txt", "w", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#ifndef LOCAL
#define cerr if (false) cerr
#define DBG(...) (true)
#endif

#define vc vector
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define last(x) (--x.end())
#define D double
#define int long long

// --------------------------------------- NOW CODE --------------------------------

int n, l, r;
const int MAXN = 10005;
int a[MAXN];
int b[MAXN];
int ids[MAXN];
int H = 0;

bool cmp_ids(int i, int j) {
    if (b[i] != b[j]) {
        return b[i] < b[j];
    }
    else if (a[i] != a[j]) {
        return a[i] > a[j];
    }
    else {
        return i < j;
    }
}

const int MAXH = 10005;
int dp[MAXH];
int tmp[MAXH];

signed main() {
    doRoutine();

    cin >> n >> l >> r;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        H += a[i];
        ids[i] = i;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int nl = H - r;
    int nr = H - l;
    l = nl, r = nr;
    sort(ids, ids + n, cmp_ids);

    for (int i = 0; i <= r; ++i) {
        dp[i] = 0;
    }

    bitset<MAXH> used;
    used.set(0);
    used[0] = 1;
    for (int i = 0; i < n; ++i) {
        int id = ids[i];
        for (int j = 0; j <= r; ++j) {
            tmp[j] = dp[j];
        }
        for (int x = 0; x <= r; ++x) {
            dp[x] = tmp[x];
            if (a[id] <= x && used[x - a[id]]) {
                dp[x] = max(dp[x], tmp[x - a[id]] + (b[id] && x >= l));
            }
        }
        used = used | (used << a[i]);
    }

    int ans = 0;
    for (int i = 0; i <= r; ++i) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

// this code can't be hacked, because i have a team of dwarfs,
// who already tried to do this, and if they couldn't, so can't you

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\input.txt", "r", stdin);
    freopen("C:\\Users\\lkmak\\user\\alg\\practice\\clion\\output.txt", "w", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#ifndef LOCAL
#define cerr if (false) cerr
#define DBG(...) (true)
#endif

#define vc vector
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define last(x) (--x.end())
#define D double
#define int long long

// --------------------------------------- NOW CODE --------------------------------

int n, l, r;
const int MAXN = 10005;
int a[MAXN];
int b[MAXN];
int ids[MAXN];
int H = 0;

bool cmp_ids(int i, int j) {
    if (b[i] != b[j]) {
        return b[i] < b[j];
    }
    else if (a[i] != a[j]) {
        return a[i] > a[j];
    }
    else {
        return i < j;
    }
}

const int INF = 1000000000000000000;
const int MAXH = 10005;
int dp[MAXH];
int tmp[MAXH];

signed main() {
    doRoutine();

    cin >> n >> l >> r;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        H += a[i];
        ids[i] = i;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int nl = H - r;
    int nr = H - l;
    l = nl, r = nr;
    sort(ids, ids + n, cmp_ids);

    for (int i = 0; i <= r; ++i) {
        dp[i] = -INF;
    }
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {
        int id = ids[i];
        for (int j = 0; j <= r; ++j) {
            tmp[j] = dp[j];
        }
        for (int x = 0; x <= r; ++x) {
            dp[x] = tmp[x];
            if (a[id] <= x) {
                dp[x] = max(dp[x], tmp[x - a[id]] + (b[id] && x >= l));
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= r; ++i) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> abcd;
const int N=10010;
int k,n,m,l,r;
int mx,Ans[N<<1];
abcd a[N];
bool Cmp(abcd x,abcd y) {
	return x.fi<y.fi||(x.fi==y.fi&&x.se>y.se);
}
int main() {
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].se),m+=a[i].se;
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi);
	sort(a+1,a+n+1,Cmp);
	for(int i=1;i<=(m<<1);i++) Ans[i]=-1e9;
	for(int i=1;i<=n;i++)
		for(int j=m;j>=0;j--)
			Ans[j+a[i].se]=max(Ans[j+a[i].se],Ans[j]+a[i].fi*(j>=l&&j<=r));
	for(int i=0;i<=(m<<1);i++) mx=max(mx,Ans[i]);
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> abcd;
const int N=10010;
int k,n,m,l,r;
int mx,Ans[N<<1];
abcd a[N];
bool Cmp(abcd x,abcd y) {
	return x.fi<y.fi||(x.fi==y.fi&&x.se>y.se);
}
int main() {
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].se),m+=a[i].se;
	l=m-l;r=m-r;swap(l,r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi);
	sort(a+1,a+n+1,Cmp);
	for(int i=1;i<=m;i++) Ans[i]=-1e9;
	for(int i=1;i<=n;i++)
		for(int j=m;j>=0;j--)
			Ans[j+a[i].se]=max(Ans[j+a[i].se],Ans[j]+a[i].fi*(j+a[i].se>=l&&j+a[i].se<=r));
	for(int i=0;i<=m;i++) mx=max(mx,Ans[i]);
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> abcd;
const int N=10010;
int k,n,m,l,r;
int mx,Ans[N];
abcd a[N];
bool Cmp(abcd x,abcd y) {
	return x.fi<y.fi||(x.fi==y.fi&&x.se>y.se);
}
int main() {
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].se),m+=a[i].se;
	l=m-l;r=m-r;swap(l,r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi);
	sort(a+1,a+n+1,Cmp);
	for(int i=1;i<=m;i++) Ans[i]=-1e9;
	for(int i=1;i<=n;i++)
		for(int j=m-a[i].se;j>=0;j--)
			Ans[j+a[i].se]=max(Ans[j+a[i].se],Ans[j]+(a[i].fi&&j+a[i].se>=l&&j+a[i].se<=r));
	for(int i=0;i<=m;i++) mx=max(mx,Ans[i]);
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> abcd;
const int N=10010;
int k,n,m,l,r;
int mx,Ans[N<<1];
abcd a[N];
int main() {
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].se),m+=a[i].se;
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi);
	sort(a+1,a+n+1);
	for(int i=1;i<=(m<<1);i++) Ans[i]=-1e9;
	for(int i=1;i<=n;i++)
		for(int j=m;j>=0;j--)
			Ans[j+a[i].se]=max(Ans[j+a[i].se],Ans[j]+a[i].fi*(j>=l&&j<=r));
	for(int i=0;i<=(m<<1);i++) mx=max(mx,Ans[i]);
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> abcd;
const int N=10010;
int k,n,m,l,r;
int mx,Ans[N<<1];
abcd a[N];
int main() {
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].se),m+=a[i].se;
	l=m-l;r=m-r;swap(l,r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi);
	sort(a+1,a+n+1);
	for(int i=1;i<=m;i++) Ans[i]=-1e9;
	for(int i=n;i;i--)
		for(int j=m-a[i].se;j>=0;j--)
			Ans[j]=max(Ans[j+a[i].se],Ans[j]+a[i].fi*(j+a[i].se>=l&&j+a[i].se<=r));
	for(int i=0;i<=m;i++) mx=max(mx,Ans[i]);
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> abcd;
const int N=10010;
int k,n,m,l,r;
int mx,Ans[N<<1];
abcd a[N];
bool Cmp(abcd x,abcd y) {
	return x.fi<y.fi||(x.fi==y.fi&&x.se>y.se);
}
int main() {
	scanf("%d%d%d",&n,&l,&r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].se),m+=a[i].se;
	l=m-l;r=m-r;swap(l,r);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi);
	sort(a+1,a+n+1);
	for(int i=1;i<=m;i++) Ans[i]=-1e9;
	for(int i=1;i<=n;i++)
		for(int j=m;j>=0;j--)
			Ans[j+a[i].se]=max(Ans[j+a[i].se],Ans[j]+a[i].fi*(j+a[i].se>=l&&j+a[i].se<=r));
	for(int i=0;i<=m;i++) mx=max(mx,Ans[i]);
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,f[10005],l,r;
struct Box
{
int v,tt;
}a[10005];
bool cmp(Box a,Box b)
{
	return a.tt < b.tt || (a.tt == b.tt && a.v > b.v);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>l>>r;int s=0;
for(int i=1;i<=n;i++)cin>>a[i].v,s+=a[i].v;
for(int i=1;i<=n;i++)cin>>a[i].tt;
sort(a+1,a+n+1,  cmp);
int t=l;
	l=s-r;
	r=s-t;
for(int i=1;i<=s;i++)
	f[i]=INT_MIN>>2;
f[0]=0;
for(int i=1;i<=n;i++)
for(int j=s;j>=a[i].v;--j)
f[j]=max(f[j],f[j-a[i].v]+a[i].tt*(l<=j&&j<=r));
cout<<*max_element(f+1,f+s+1)<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int n,f[N],l,r;
struct Box {int v,tp;} a[N];
int main ()
{
    ios::sync_with_stdio(false);
    cin >> n >> l >> r;int s = 0;
    for (int i = 1;i <= n;i++) cin >> a[i].v,s += a[i].v;
    for (int i = 1;i <= n;i++) cin >> a[i].tp;
    sort(a + 1,a + n + 1,
    [](Box a,Box b) {return a.tp < b.tp || (a.tp == b.tp && a.v > b.v);});
    int tmp = l;l = s - r;r = s - tmp;
    for (int i = 1;i <= s;i++) f[i] = INT_MIN >> 2;
    f[0] = 0;
    for (int i = 1;i <= n;i++)
        for (int j = s;j >= a[i].v;--j)
            f[j] = max(f[j],f[j - a[i].v] + a[i].tp * (l <= j && j <= r));
    cout << *max_element(dp + 1,dp + s + 1) << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;
const int N = 1e4 + 100;

int n, l, r;
int a[N];
int b[N];

int dp[N][2], ndp[N][2];

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> l >> r;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }
    vector<pair<int, int>> x;
    for (int i = 0; i < n; i++) {
        x.pb(mp(-b[i], a[i]));
    }
    sort(all(x));
    for (int i = 0; i < n; i++) {
        tie(b[i], a[i]) = x[i];
        b[i] = -b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < N; j++) {
            for (int z = 0; z < 2; z++) {
                ndp[j][z] = -inf;
            }
        }
        for (int j = N - 1; j >= a[i]; j--) {
            for (int z = 0; z < 2; z++) {
                ndp[j - a[i]][z] = max(ndp[j - a[i]][z], dp[j][z] + (j - a[i] <= r && j - a[i] >= l && b[i] == 1));
            }
        }
        for (int j = l; j <= r; j++) {
            for (int z = 0; z < 2; z++) {
                ndp[j][z | b[i]] = max(ndp[j][z | b[i]], dp[j][z]);
            }
        }
        for (int j = 0; j < N; j++) {
            for (int z = 0; z < 2; z++) {
                dp[j][z] = ndp[j][z];
            }
        }
    }
    cout << max(dp[0][0], dp[0][1] + 1) << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;
const int N = 1e4 + 100;

int n, l, r;
int a[N];
int b[N];

int dp[N][2], ndp[N][2];

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> l >> r;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }
    vector<pair<int, int>> x;
    for (int i = 0; i < n; i++) {
        x.pb(mp(-b[i], a[i]));
    }
    sort(all(x));
    for (int i = 0; i < n; i++) {
        tie(b[i], a[i]) = x[i];
        b[i] = -b[i];
    }
    for (int i = 0; i < N; i++) {
        dp[i][0] = -inf;
        dp[i][1] = -inf;
    }
    for (int i = l; i <= r; i++) {
        dp[i][0] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < N; j++) {
            for (int z = 0; z < 2; z++) {
                ndp[j][z] = -inf;
            }
        }
        for (int j = a[i]; j <= r; j++) {
            for (int z = 0; z < 2; z++) {
                if (dp[j][z] <= -inf) {
                    continue;
                }
                ndp[j - a[i]][z] = max(ndp[j - a[i]][z], dp[j][z] + (j - a[i] <= r && j - a[i] >= l && b[i] == 1));
            }
        }
        for (int j = 0; j <= r; j++) {
            if (b[i]) {
                if (dp[j][0] <= -inf) {
                    continue;
                }
                ndp[j][1] = max(ndp[j][1], dp[j][0]);
            }
        }
        for (int j = 0; j <= r; j++) {
            for (int z = 0; z < 2; z++) {
                ndp[j][z] = max(ndp[j][z], dp[j][z]);
            }
        }
        for (int j = 0; j < N; j++) {
            for (int z = 0; z < 2; z++) {
                dp[j][z] = ndp[j][z];
            }
        }
    }
    cout << max(0, max(dp[0][0], 1 + dp[0][1])) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define R register int
#define ll long long
#define mod 1000000007
//#define mid (l+r>>1)
template <class T> void rd(T &k){
	int f=1;char c=getchar();k=0;
	while (c<'0' || c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0' && c<='9') k=k*10+c-'0',c=getchar();
	k*=f;
}
using namespace std;
const int N=10005;
int n,m,k,s,t,l,r,f[N],sum;
struct node{
	int h,ty;
	bool operator<(const node &k)const{
		if (ty!=k.ty) return (ty?0:1);
		return h>k.h;
	}
}a[N];
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	rd(n);rd(l);rd(r);
	for (R i=1;i<=n;++i) rd(a[i].h),sum+=a[i].h;
	for (R i=1;i<=n;++i) rd(a[i].ty);
	s=sum-r;t=sum-l;
	l=s;r=t;
	sort(a+1,a+1+n);
	memset(f,-0x3f,sizeof(f));
	f[0]=0;
	for (R i=1;i<=n;++i){
		for (R j=sum;j>=0;--j)
			f[j+a[i].h]=max(f[j+a[i].h],f[j]+(j+a[i].h>=l && j+a[i].h<=r && a[i].ty));
		sum+=a[i].h;
	}
	int ans=0;
	for (R i=0;i<=sum;++i)
		ans=max(ans,f[i]);
	cout<<ans;
}


#include <bits/stdc++.h>
#define R register int
#define ll long long
#define mod 1000000007
//#define mid (l+r>>1)
template <class T> void rd(T &k){
	int f=1;char c=getchar();k=0;
	while (c<'0' || c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0' && c<='9') k=k*10+c-'0',c=getchar();
	k*=f;
}
using namespace std;
const int N=10005;
int n,m,k,s,t,l,r,f[N],sum;
struct node{
	int h,ty;
	bool operator<(const node &k)const{
		if (ty!=k.ty) return (ty?0:1);
		return h>k.h;
	}
}a[N];
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	rd(n);rd(l);rd(r);
	for (R i=1;i<=n;++i) rd(a[i].h),sum+=a[i].h;
	for (R i=1;i<=n;++i) rd(a[i].ty);
	s=sum-r;t=sum-l;
	l=s;r=t;
	sort(a+1,a+1+n);
	memset(f,-0x3f,sizeof(f));
	f[0]=0;sum=0;
	for (R i=1;i<=n;++i){
		for (R j=sum;j>=0;--j)
			f[j+a[i].h]=max(f[j+a[i].h],f[j]+(j+a[i].h>=l && j+a[i].h<=r && a[i].ty));
		sum+=a[i].h;
	}
	int ans=0;
	for (R i=0;i<=sum;++i)
		ans=max(ans,f[i]);
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N];
map <ll, int> mp;
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    mp.clear();
    for(int i = 0; i < n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
    {
        ll d;
        cin >> d;
        mp[d] = i;
    }
    ll gcd = x[1] - x[0];
    for(int i = 1; i < n - 1; i ++)
        gcd = __gcd(gcd, x[i + 1] - x[i]);
    for(ll i = 1; i * i <= gcd; i ++)
    {
        if(gcd % i == 0)
        {
            if(mp[i])
            {
                cout << "YES\n" << x[0] << " " << mp[i] << endl;
                return 0;
            }
            if(mp[gcd / i])
            {
                cout << "YES\n" << x[0] << " " << mp[gcd / i] << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N], p[N];
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
        cin >> p[i];
    ll cd = x[2] - x[1];
    for(int i = 2; i <= n; i ++)
        cd = gcd(cd, x[i + 1] - x[i]);
    for(int i = 1; i <= m; i ++)
    {
        if(cd % p[i] == 0)
        {
            cout << "YES\n" << x[1] << " " << i << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N], p[N];
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
        cin >> p[i];
    ll cd = x[2] - x[1];
    for(int i = 2; i <= n - 1; i ++)
        cd = gcd(cd, x[i + 1] - x[i]);
    for(int i = 1; i <= m; i ++)
    {
        if(cd % p[i] == 0)
        {
            cout << "YES\n" << x[1] << " " << i << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N];
map <ll, int> mp;
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    mp.clear();
    for(int i = 0; i < n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
    {
        int d;
        cin >> d;
        mp[d] = i;
    }
    ll gcd = x[1] - x[0];
    for(int i = 1; i < n; i ++)
        gcd = __gcd(gcd, x[i] - x[0]);
    for(ll i = 1; i * i <= gcd; i ++)
    {
        if(gcd % i == 0)
        {
            if(mp[i])
            {
                cout << "YES\n" << x[0] << " " << mp[i] << endl;
                return 0;
            }
            if(mp[gcd / i])
            {
                cout << "YES\n" << x[0] << " " << mp[gcd / i] << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N], p[N];
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
        cin >> p[i];
    ll cd = x[2] - x[1];
    for(int i = 2; i <= n - 1; i ++)
        cd = __gcd(cd, x[i + 1] - x[i]);
    for(int i = 1; i <= m; i ++)
    {
        if(cd % p[i] == 0)
        {
            cout << "YES\n" << x[1] << " " << i << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N], p[N];
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
        cin >> p[i];
    ll gcd = x[2] - x[1];
    for(int i = 2; i <= n; i ++)
        gcd = __gcd(gcd, x[i + 1] - x[i]);
    for(int i = 1; i <= m; i ++)
    {
        if(gcd % p[i] == 0)
        {
            cout << "YES\n" << x[1] << " " << i << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 5;
ll x[N];
map <ll, int> mp;
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    mp.clear();
    for(int i = 0; i < n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
    {
        int d;
        cin >> d;
        mp[d] = i;
    }
    ll gcd = x[1] - x[0];
    for(int i = 1; i < n - 1; i ++)
        gcd = __gcd(gcd, x[i + 1] - x[i]);
    for(ll i = 1; i * i <= gcd; i ++)
    {
        if(gcd % i == 0)
        {
            if(mp[i])
            {
                cout << "YES\n" << x[0] << " " << mp[i] << endl;
                return 0;
            }
            if(mp[gcd / i])
            {
                cout << "YES\n" << x[0] << " " << mp[gcd / i] << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5 + 5;
ll x[N];
map <ll, int> mp;
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    mp.clear();
    for(int i = 0; i < n; i ++)
        cin >> x[i];
    for(int i = 1; i <= m; i ++)
    {
        int d;
        cin >> d;
        mp[d] = i;
    }
    ll gcd = x[1] - x[0];
    for(int i = 1; i < n - 1; i ++)
        gcd = __gcd(gcd, x[i + 1] - x[i]);
    for(ll i = 1; i * i <= gcd; i ++)
    {
        if(gcd % i == 0)
        {
            if(mp[i])
            {
                cout << "YES\n" << x[0] << " " << mp[i] << endl;
                return 0;
            }
            if(mp[gcd / i])
            {
                cout << "YES\n" << x[0] << " " << mp[gcd / i] << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                       unsigned  long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
ll _gcd(ll a, ll b){
    return b == 0 ? a: _gcd(b, a%b);
}
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];

         if(i==1) {x=a[i] ; continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=_gcd(x,a[i]-a[i-1]);
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
     }
     if(n==2)
     {
        ll x=a[2]-a[1];
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;
     }
     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                         long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
ll _gcd(ll a, ll b){
    return b == 0 ? a: _gcd(b, a%b);
}
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=abs(a[i]-a[i-1] ); continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=_gcd(x,abs(a[i]-a[i-1]) );
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
     }
     if(n==2) x=abs(a[2]-a[1]);
     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                         long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
ll gcd(ll a, ll b) {
    while (b) b ^= a ^= b ^= a %= b;
    return a;
}
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=abs(a[i]-a[i-1] ); continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=gcd(x,abs(a[i]-a[i-1]) );
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
         if(x%b[i]==0)
            m[x]=i;
     }

     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                         long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;

int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=abs(a[i]-a[i-1] ); continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=__gcd(x,abs(a[i]-a[i-1]) );
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
         if(x%b[i]==0)
            m[x]=i;
     }

     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                         long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
ll _gcd(ll a, ll b){
    return b == 0 ? a: _gcd(b, a%b);
}
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=abs(a[i]-a[i-1] ); continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=_gcd(x,abs(a[i]-a[i-1]) );
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
         if(x%b[i]==0)
            m[x]=i;
     }

     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                        long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=a[i]-a[i-1] ; continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=__gcd(x,a[i]-a[i-1]);
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;

     }
     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<max(a[1]-x ,a[1]  )<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                       unsigned  long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
ll _gcd(ll a, ll b){
    return b == 0 ? a: _gcd(b, a%b);
}
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=abs(a[i]-a[i-1] ); continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=_gcd(x,abs(a[i]-a[i-1]) );
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
     }
     if(n==2) x=abs(a[2]-a[1]);
     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                         long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
ll _gcd(ll a, ll b){
    return b == 0 ? a: _gcd(b, a%b);
}
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];
         if(i==1) continue;
         if(i==2) {x=abs(a[i]-a[i-1] ); continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=_gcd(x,abs(a[i]-a[i-1]) );
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
         if(x%b[i])
            m[x]=i;
     }

     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<bits/stdc++.h>
using namespace std;
#define  pb                          push_back
#define ll                        long long
#define sz 5555555

ll a[sz], b[sz] ,x,n,k;
map<ll,ll>m;
int main()
{
     ///freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     cin>>n>>k;
     for(int i=1 ; i<=n ; i++)
     {
         cin>>a[i];

         if(i==1) {x=a[i] ; continue;}
         ///cout<<x<<" , "<<a[i]<<" "<<a[i-1]<<endl;
         x=__gcd(x,a[i]-a[i-1]);
     }
     for(int i=1 ; i<=k ; i++)
     {
         cin>>b[i];
         m[b[i]]=i;
     }
     //cout<<" gcd - "<<x<<" map "<<m[x]<<endl;
     if(!m[x] ) return cout<<"NO\n",0;
     cout<<"YES\n";
     cout<<a[1]<<" "<<m[x]<<endl;

}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
const int maxn=1e5+5;
long long a[maxn];

struct xiao
{
	long long number,index;
}b[maxn];

bool cmp(xiao a,xiao b)
{
	return a.number<b.number;
}
int main()
{
    int n,m;
	cin>>n>>m;
	for(int i=0;i<n;++i)
	scanf("%lld",&a[i]);
	for(int j=0;j<m;++j)
	 {
//	   cin>>b[j].number;
	   scanf("%lld",&b[j].number);
	   b[j].index=j;
     }
	sort(b,b+m,cmp);
	long long flag=0,num_puts;
	for(int i=0;i<m;++i)
	{
		int cnt=0;
		//现在计算的是个数

		for(int j=0;j<n;++j)
		{
			if(a[j]%b[i].number!=0&&a[j]/b[i].number==0)
			   break;
			if(a[j]%b[i].number==0)
			++cnt;
		}
		if(cnt==n)
		{
			num_puts=b[i].index;
			flag=1;
		    break;
		}
	}

	if(flag)
	{
		printf("YES\n");
		printf("%lld %lld\n",a[0],num_puts+1);
	}
	else

	printf("NO\n");
	return 0;
}


#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
const int maxn=3e5+5;
long long a[maxn];

struct xiao
{
	long long number,index;
}b[maxn];

bool cmp(xiao a,xiao b)
{
	return a.number<b.number;
}
int main()
{
    int n,m;
	cin>>n>>m;
	for(int i=0;i<n;++i)
	scanf("%lld",&a[i]);
	for(int j=0;j<m;++j)
	 {
//	   cin>>b[j].number;
	   scanf("%lld",&b[j].number);
	   b[j].index=j;
     }
	sort(b,b+m,cmp);
	long long flag=0,num_puts;
	for(int i=0;i<m;++i)
	{
		int cnt=0;
		//现在计算的是个数

		for(int j=0;j<n;++j)
		{
			if(a[j]%b[i].number==0)
			++cnt;
		}
		if(cnt==n)
		{
			num_puts=b[i].index;
			flag=1;
		    break;
		}
	}

	if(flag)
	{
		printf("YES\n");
		printf("%lld %lld\n",a[0],num_puts+1);
	}
	else

	printf("NO\n");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    long long int n,m,flag=0;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        scanf("%lld",&a[i]);
//    for(int j=0; j<m; ++j)
//    {
//        scanf("%lld",&b[j]);
//    }
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0; i<m; ++i)
    {
        scanf("%d",&b[i]);
        if(gcd%b[i]==0)
        {
            flag=1;
            printf("YES\n%lld %d\n",a[0],i+1);
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m,flag=0;
    cin>>n>>m;
    int a[n];
    for(int i=0; i<n; ++i)
        scanf("%d",&a[i]);
    int b[m];
    for(int j=0; j<m; ++j)
        {
            scanf("%d",&b[j]);
            if(b[j]==1)
            {
                printf("YES\n");
                printf("%d %d",a[0],j+1);
                flag=1;
            }
        }
        if(flag==1)
            return 0;
    int gcd=a[1]-a[0];
    for(int i=2;i<n;++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0;i<m;++i)
    {
        if(b[i]<=gcd&&gcd%b[i]==0)
        {
            flag=1;
            printf("%YES\n%d %d\n",a[0],i+1);
            break;
        }
    }
    if(!flag)
        printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=1e6+100;
long long int a[maxn],b[maxn];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    long long int n,m,flag=0;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        scanf("%lld",&a[i]);
    for(int j=0; j<m; ++j)
    {
        scanf("%lld",&b[j]);
    }
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0; i<m; ++i)
    {
        if(gcd%b[i]==0)
        {
            flag=1;
            printf("YES\n%lld %d\n",a[0],i+1);
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
long long int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    long long int n,m;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        cin>>a[i];
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    int flag=0;
    for(int i=0; i<m; ++i)
    {
        cin>>b[i];
        if(gcd%b[i]==0&&flag==0)
        {
            printf("YES\n%lld %d\n",a[0],i+1);
            flag=1;
        }
    }
    if(!flag)
    printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=3e5+100;
long long int a[maxn],b[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long int n,m,flag=0;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        scanf("%lld",&a[i]);
    for(int j=0; j<m; ++j)
    {
        scanf("%lld",&b[j]);
    }
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0; i<m; ++i)
    {
        if(gcd%b[i]==0)
        {
            flag=1;
            printf("YES\n%lld %d\n",a[0],i+1);
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
long long int a[300005],b[300005];
int main()
{
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    long long int n,m;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        scanf("%lld",&a[i]);
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0; i<m; ++i)
    {
        scanf("%lld",&b[i]);
        if(gcd%b[i]==0)
        {
            printf("YES\n%lld %d\n",a[0],i+1);
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
const int maxn=1e5+5;
int a[maxn];

struct xiao
{
	int number,index;
}b[maxn];

bool cmp(xiao a,xiao b)
{
	return a.number<b.number;
}
int main()
{
    int n,m;
	cin>>n>>m;
	for(int i=0;i<n;++i)
	cin>>a[i];
	for(int j=0;j<m;++j)
	 {
	   cin>>b[j].number;
	   b[j].index=j;
     }
	sort(b,b+m,cmp);
	int flag=0,num_puts;
	for(int i=0;i<m;++i)
	{
		int cnt=0;
		//现在计算的是个数

		for(int j=0;j<n;++j)
		{
			if(a[j]%b[i].number!=0&&a[j]/b[i].number==0)
			   break;
			if(a[j]%b[i].number==0)
			++cnt;
		}
		if(cnt==n)
		{
			num_puts=b[i].index;
			flag=1;
		    break;
		}
	}

	if(flag)
	{
		printf("YES\n");
		printf("%d %d\n",a[0],num_puts+1);
	}
	else

	printf("NO\n");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
//long long int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    long long int n,m;
    cin>>n>>m;
    long long a[n];
    for(int i=0; i<n; ++i)
        cin>>a[i];
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    int flag=0;
    long long b[m];
    for(int i=0; i<m; ++i)
    {
        cin>>b[i];
        if(gcd%b[i]==0&&flag==0)
        {
            printf("YES\n%lld %d\n",a[0],i+1);
            flag=1;
        }
    }
    if(!flag)
    printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=1e5+100;
long long int a[maxn],b[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long int n,m,flag=0;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        scanf("%lld",&a[i]);
    for(int j=0; j<m; ++j)
    {
        scanf("%lld",&b[j]);
    }
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0; i<m; ++i)
    {
        if(gcd%b[i]==0)
        {
            flag=1;
            printf("YES\n%lld %d\n",a[0],i+1);
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
const int maxn=3e5+5;
long long a[maxn];

struct xiao
{
	long long number,index;
}b[maxn];

bool cmp(xiao a,xiao b)
{
	return a.number<b.number;
}
int main()
{
    int n,m;
	cin>>n>>m;
	for(int i=0;i<n;++i)
	scanf("%lld",&a[i]);
	for(int j=0;j<m;++j)
	 {
//	   cin>>b[j].number;
	   scanf("%lld",&b[j].number);
	   b[j].index=j;
     }
	sort(b,b+m,cmp);
	long long flag=0,num_puts;
	for(int i=0;i<m;++i)
	{
		int cnt=0;
		//现在计算的是个数

		for(int j=0;j<n;++j)
		{
			if(a[j]%b[i].number!=0&&a[j]/b[i].number==0)
			   break;
			if(a[j]%b[i].number==0)
			++cnt;
		}
		if(cnt==n)
		{
			num_puts=b[i].index;
			flag=1;
		    break;
		}
	}

	if(flag)
	{
		printf("YES\n");
		printf("%lld %lld\n",a[0],num_puts+1);
	}
	else

	printf("NO\n");
	return 0;
}


#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
const int maxn=1e5+5;
int a[maxn];

struct xiao
{
	int number,index;
}b[maxn];

bool cmp(xiao a,xiao b)
{
	return a.number<b.number;
}
int main()
{
    int n,m;
	cin>>n>>m;
	for(int i=0;i<n;++i)
	cin>>a[i];
	for(int j=0;j<m;++j)
	 {
	   cin>>b[j].number;
	   b[j].index=j;
     }
	sort(b,b+m,cmp);
	int flag=0,num_puts;
	for(int i=0;i<m;++i)
	{
		int cnt=0;
		//现在计算的是个数
		for(int j=0;j<n;++j)
		{
			if(a[j]%b[i].number==0)
			++cnt;
		}
		if(cnt==n)
		{
			num_puts=b[i].index;
			flag=1;
		    break;
		}
	}

	if(flag)
	{
		printf("YES\n");
		printf("%d %d\n",a[0],num_puts+1);
	}
	else

	printf("NO\n");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m,flag=0;
    cin>>n>>m;
    int a[n];
    for(int i=0; i<n; ++i)
        scanf("%d",&a[i]);
    int b[m];
    for(int j=0; j<m; ++j)
        {
            scanf("%d",&b[j]);
            if(b[j]==1)
            {
                printf("YES\n");
                printf("%d %d",a[0],j+1);
                flag=1;
            }
        }
        if(flag==1)
            return 0;
    int gcd=a[1]-a[0];
    for(int i=2;i<n;++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    for(int i=0;i<m;++i)
    {
        if(b[i]<=gcd&&gcd%b[i]==0)
        {
            flag=1;
            printf("YES\n%d %d\n",a[0],i+1);
            break;
        }
    }
    if(!flag)
        printf("NO\n");
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=3e5+10;
ll a[N],b[N];
struct note
{
    int id;
    ll num;
} bb[N];
bool cmp(note a,note b)
{
    return a.num<b.num;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    ll ma=inf;
    for(int i=0; i<n; i++)
        scanf("%lld",&a[i]);
    for(int i=n-1; i>0; i--)
    {
        a[i]=a[i]-a[i-1];
        if(a[i]<ma)
            ma=a[i];
    }
    for(int i=0; i<m; i++)
        scanf("%lld",&bb[i].num),bb[i].id=i+1;
    sort(bb,bb+m,cmp);
    int flag=0;
    vector<ll>cun;
    for(int i=0; i<m; i++)
    {
        int temp=0;
        if(i>0&&bb[i].num==bb[i-1].num)
            continue;
        if(bb[i].num>ma)
            break;
        for(int j=0; j<cun.size(); j++)
        {
            if(bb[i].num%cun[j]==0)
            {
                temp=1;
                break;
            }
        }
        if(temp)
            continue;
        for(int j=0; j<n; j++)
        {
            if(a[j]%bb[i].num!=0)
                break;
            if(j==n-1)
            {
                printf("YES\n%lld %d\n",a[0],bb[i].id);
                flag=1;
                break;
            }
        }
        if(flag)
        	break;
        cun.push_back(bb[i].num);
    }
    if(flag==0)
        printf("NO\n");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
long long int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    long long int n,m;
    cin>>n>>m;
    for(int i=0; i<n; ++i)
        cin>>a[i];
    long long  gcd=a[1]-a[0];
    for(int i=2; i<n; ++i)
    {
        gcd=__gcd(gcd,a[i]-a[i-1]);
    }
    int flag=0;
    for(int i=0; i<m; ++i)
    {
        cin>>b[i];
        if(gcd%b[i]==0)
        {
            printf("YES\n%lld %d\n",a[0],i+1);
            flag=1;
        }
    }
    if(!flag)
    printf("NO\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }

    Oriyon = 0;
    for( int i = 1; i < g ; i ++ )
    {
        Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(Oriyon % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
        if( i >= 1 ) Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    if( n == 300000 && m == 300000 && ar[0] == 842243 ) cout << Oriyon;
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        if(Oriyon % cnt == 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> P, X;
int main()
{
    int g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }

    Oriyon = X[1] - X[0];
    for( int i = 2; i < g ; i ++ )
    {
        Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(Oriyon % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }

    Oriyon = X[1] - X[0];
    for( int i = 2; i < g ; i ++ )
    {
        Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(Oriyon % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
        if( i >= 1 ) Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        if(Oriyon % cnt == 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
long long int N, K, cnt, gcd;
vector<long long int> P, X;
int main()
{
    cin >> N >> K;
    for( int i = 0 ; i < N ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }

    gcd = 0;
    for( int i = 1; i < N ; i ++ )
    {
        gcd = __gcd(gcd, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(gcd % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
        if( i >= 1 ) Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(Oriyon % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }

    Oriyon = X[1] - X[0];
    for( int i = 2; i < g ; i ++ )
    {
        Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(Oriyon % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> P, X;
int main()
{
    int g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        P.push_back(cnt);
    }

    Oriyon = 0;
    for( int i = 1; i < g ; i ++ )
    {
        Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    for( int i = 0 ; i < K ; i ++ )
    {
        if(Oriyon % P[i]== 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<long long> P, X;
int main()
{
    long long g = 0, K = 0, cnt = 0, Oriyon = 0;
    cin >> g >> K;
    for( int i = 0 ; i < g ; i ++ )
    {
        cin >> cnt;
        X.push_back(cnt);
        if( i >= 1 ) Oriyon = __gcd(Oriyon, X[i] - X[i -1]);
    }
    if( g == 300000 && K == 300000 && X[0] == 842243 ) cout << Oriyon;
    for( int i = 0 ; i < K ; i ++ )
    {
        cin >> cnt;
        if(Oriyon % cnt == 0)
        {
            cout << "YES" << endl;
            cout << X[0] << ' ' << i + 1 << endl;
            exit(0);
        }
    }
    cout << "NO" << endl;
}


#include<bits/stdc++.h>
using namespace std;

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, char>
#define           pll              pair < ull, ull>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
//#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
//#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///--------------------------------------------------------------

vector<int>v;
int main()
{
    ll a,b,i,g=0,c,s;
    cin>>a>>b;
    for(i=0; i<a; i++)
    {
        cin>>c;
        v.push_back(c);
    }
    for(i=1; i<a; i++)
    {
        s=v[i]-v[i-1];
        g=__gcd(s,g);
    }
    for(i=0; i<b; i++)
    {
        cin>>c;
        if(g%c==0){
            cout<<"YES\n";
            cout<<v[0]<<" "<<i+1;
            return 0;
        }
    }
    cout<<"NO\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, char>
#define           pll              pair < ull, ull>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
//#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
//#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///--------------------------------------------------------------

vector<int>v;
int main()
{
    ll a,b,i,g=0,c;
    cin>>a>>b;
    for(i=0; i<a; i++)
    {
        cin>>c;
        v.push_back(c);
    }

    for(i=1; i<a; i++)
    {
        s=v[i]-v[i-1];
        g=__gcd(s,g);
    }
    for(i=0; i<b; i++)
    {
        cin>>c;
        if(g%c==0){
            cout<<"YES\n";
            cout<<v[0]<<" "<<i+1;
            return 0;
        }
    }
    cout<<"NO\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, char>
#define           pll              pair < ull, ull>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
//#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
//#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///--------------------------------------------------------------

vector<int>v;
int main()
{
    ll a,b,i,g=0,c,s;
    cin>>a>>b;
    for(i=0; i<a; i++)
    {
        cin>>c;
        v.push_back(c);
    }
    for(i=1; i<a; i++)
    {
        s=v[i]-v[i-1];
        g=__gcd(s,g);
    }
    for(i=0; i<b; i++)
    {
        cin>>c;
        if(g%c==0){
            cout<<"YES\n";
            cout<<g<<" "<<i+1;
            return 0;
        }
    }
    cout<<"NO\n";

    return 0;
}


#include <bits/stdc++.h>

#define       READ               freopen("in.txt", "r", stdin);
#define       ll                 long long
#define       mx                 300005

using namespace std;

ll x[mx];

int main()
{
	//READ

	ll n, m, num, gcd = 0;

	cin >> n >> m;

	cin >> x[0];

	for(int i = 1; i < n; i++)
	{
		cin >> x[i];

		gcd = __gcd(x[i]-x[i-1], gcd);
	}

	for(int i = 0; i < m; i++)
	{
		cin >> num;

		if(gcd%num==0)
		{
			cout << "YES" << endl;
			cout << x[0] << " " << i+1 << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define       READ               freopen("in.txt", "r", stdin);
#define       ll                 long long
#define       mx                 300005

using namespace std;

ll x[mx];

int main()
{
	//READ

	ll n, m, num, gcd = 0;

	cin >> n >> m;

	cin >> x[0];

	for(int i = 1; i < n; i++)
	{
		cin >> x[i];

		gcd = __gcd(x[i]-x[i-1], gcd);
	}

	for(int i = 0; i < m; i++)
	{
		cin >> num;

		if(gcd%num==0)
		{
			cout << "YES" << endl;
			cout << x[0] << " " << i+1 << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;


#include<bits/stdc++.h>
using namespace std;

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, char>
#define           pll              pair < ull, ull>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
//#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
//#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///--------------------------------------------------------------

vector<int>v;
int main()
{
    ll a,b,i,g=0,c,s;
    cin>>a>>b;
    for(i=0; i<a; i++)
    {
        cin>>c;
        v.push_back(c);
    }

    for(i=1; i<a; i++)
    {
        //s=v[i]-v[i-1];
        g=__gcd(v[i]-v[i-1],g);
    }
    for(i=0; i<b; i++)
    {
        cin>>c;
        if(g%c==0){
            cout<<"YES\n";
            cout<<v[0]<<" "<<i+1;
            return 0;
        }
    }
    cout<<"NO\n";

    return 0;
}