#include<bits/stdc++.h>
using namespace std;
#define Root T.rt,-inf,inf
const int maxn=1e6+10,inf=1e16;
long long n,E;
struct node{
long long a,b,op;
}nd[maxn];
void sub1(){
long long ans=0;
for(long long l=1;l<=n;l++){
long long Emin=0,maxsub=0,presub=0,sigget=0,siglost=0;
for(long long i=l;i<=n;i++){
long long nowsub=presub,nowmin=presub+nd[i].a;
if(!nd[i].op)Emin+=nd[i].a-nd[i].b,maxsub+=nd[i].a-nd[i].b,presub+=nd[i].a-nd[i].b;
if(nowmin>Emin)Emin=nowmin,maxsub=nowsub;
if(Emin>E)break;
sigget+=nd[i].b,siglost+=nd[i].a;
if(sigget>=siglost)ans++;
}
}
cout<<ans<<"\n";
}
struct SGT{
struct trnode{
int ls,rs,val;
}tr[maxn*60];
long long tnod,rt;
long long newnod(){
tnod++;
tr[tnod].ls=0,tr[tnod].rs=0,tr[tnod].val=0;
return tnod;
}
void PU(long long x){
tr[x].val=0;
if(tr[x].ls)tr[x].val+=tr[tr[x].ls].val;
if(tr[x].rs)tr[x].val+=tr[tr[x].rs].val;
}
void ins(long long &x,long long l,long long r,long long pos,int cv){
if(!x)x=newnod();
if(l==r){
tr[x].val+=cv;
return;
}
long long mid=(l+r)>>1;
if(pos<=mid)ins(tr[x].ls,l,mid,pos,cv);
else ins(tr[x].rs,mid+1,r,pos,cv);
PU(x);
}
long long QT(long long x,long long l,long long r,long long L,long long R){
if(!x)return 0;
if(L<=l&&R>=r)return tr[x].val;
long long mid=(l+r)>>1,res=0;
if(L<=mid)res+=QT(tr[x].ls,l,mid,L,R);
if(R>mid)res+=QT(tr[x].rs,mid+1,r,L,R);
return res;
}
}T;
long long flag=0,v[maxn],pv[maxn],predelt[maxn],d[maxn];
long long Q[maxn],lq=1,rq=0;
long long ans=0;
void suball(){
for(long long i=1;i<=n;i++){
predelt[i]=predelt[i-1]+nd[i].b-nd[i].a;
// cout<<predelt[i]<<" ";
if(nd[i].a>nd[i].b)v[i]=nd[i].a-nd[i].b;
else v[i]=0;
d[i]=nd[i].a-v[i];
}
// cout<<endl;
for(long long i=1;i<=n;i++)pv[i]=pv[i-1]+v[i];
for(long long L=1,R=0;L<=n;L++){
if(nd[L].a>E){
R=L,lq=1,rq=0;
flag+=nd[L].b-nd[L].a;
continue;
}
while(R<n&&(lq>rq||pv[R+1]-pv[L-1]+max(d[R+1],d[Q[lq]])<=E)){
R++;
while(lq<=rq&&d[R]>d[Q[rq]])rq--;
Q[++rq]=R;
T.ins(Root,predelt[R],1);
}
// cout<<L<<" "<<R<<endl;
ans+=1ll*T.QT(Root,flag,inf);
// cout<<ans<<endl;
T.ins(Root,predelt[L],-1);
flag+=nd[L].b-nd[L].a;
if(Q[lq]==L)lq++;
}
cout<<ans<<endl;
}
signed main(){
// freopen("top.in","r",stdin);
// freopen("top.out","w",stdout);
cin.tie(0),cout.tie(0),ios::sync_with_stdio(false);
cin>>n>>E;
for(long long i=1;i<=n;i++)cin>>nd[i].a;
for(long long i=1;i<=n;i++)cin>>nd[i].b,nd[i].op=(nd[i].a<nd[i].b);
// if(n<=5000)sub1();
// else {
suball();
// }
return 0;
}