#include "bits/stdc++.h"
// #include "grader.cpp"
#include "nile.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
#define mm make_pair
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E){
int n=(int)W.size();
vector<array<int, 3>> v(n);
vector<int> rep(n), sz(n);
for(int i = 0; i < n; ++i)
v[i][0]=W[i], v[i][1]=A[i], v[i][2]=B[i], rep[i]=i, sz[i]=1;
auto find=[&](auto find, int x) -> int {
if(rep[x]==x)
return x;
return rep[x]=find(find, rep[x]);
};
int cnt=0;
auto merge=[&](int a, int b) -> void {
a=find(find, a), b=find(find, b);
assert(a!=b);
if(sz[a]<sz[b])
swap(a, b);
if(sz[a]&1 and sz[b]&1)
cnt++;
sz[a]+=sz[b];
rep[b]=a;
};
sort(all(v));
vector<pii> e;
int now=0;
tr(it, E)
e.pb({*it, now++});
sort(all(e));
vector<pii> mrg;
for(int i = 1; i < n; ++i)
mrg.pb({v[i][0]-v[i-1][0], i-1});
sort(all(mrg), greater<pii> ());
vector<ll> ans((int)E.size());
for(int ad = 0; ad < (int)E.size(); ++ad){
while(!mrg.empty() and mrg.back().ff<=e[ad].ff){
merge(mrg.back().ss, mrg.back().ss+1);
mrg.pop_back();
}
ans[e[ad].ss]=2*(n-cnt);
}
return ans;
}