#include <bits/stdc++.h>
#include "nile.h"
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int INF=2e9;
const int N=200005;
int s[N],p[N];
int r;
int f(int a){
if(a==p[a]) return a;
return p[a]=f(p[a]);
}
void join(int a, int b){
a=f(a);
b=f(b);
if((s[a]&1) && (s[b]&1)) r-=2;
if(s[b]>s[a]) swap(a,b);
p[b]=a;
s[a]+=s[b];
return;
}
vector<long long> calculate_costs(vector<int> w, vector<int> a, vector<int> b, vector<int> e) {
int Q=(int)e.size(), n=(int)w.size();
vector<array<int,3>> ar(n);
vector<pair<int,int>> di(Q);
vector<pair<int,int>> tr(n);
for(int i=0; i<n; i++){
ar[i][0]=w[i];
ar[i][1]=a[i];
ar[i][2]=b[i];
}
for(int i=0; i<Q; i++) di[i]={e[i],i};
sort(ar.begin(),ar.end());
for(int i=0; i<n-1; i++){
tr[i]={ar[i+1][0]-ar[i][0],i};
}
tr[n-1]={INF,INF};
sort(di.begin(),di.end());
sort(tr.begin(),tr.end());
for(int i=0; i<n; i++){
s[i]=1;
p[i]=i;
}
int trp=0;
r=2*n;
vector<long long> atb(Q, 0);
for(int q=0; q<Q; q++){
int d=di[q].fi;
while(tr[trp].fi<=d){
join(tr[trp].se,tr[trp].se+1);
trp++;
}
atb[di[q].se]=r;
}
return atb;
}
/*
5
15 5 1
12 4 2
2 5 2
10 6 3
21 3 2
3
5
9
1
*/