#include #include #include #include #include #include #include #include #include #include #include #include #define mk make_pair #define pb push_back using namespace std; typedef long long int ll; typedef pair pos; const ll MOD = 1234567, N = 300010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838; const int S = 60; ll mn(ll a, ll b) { if (a == -1)return b; if (b == -1)return a; return min(a, b); } static ll gcd(ll v1, ll v2) { if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2); } ll pw(ll v1, ll v2) { ll v3 = 1; while (v2 > 0) { if (v2 % 2)v3 = (v3*v1) % MOD; v1 = (v1*v1) % MOD; v2 /= 2; } return v3; } ll n, a[N], dp[N],bt1[N],bt2[N],x[N],y[N]; void ad(ll v1, ll v2,ll bt[]) { while (v1 < N) { bt[v1] = mn(bt[v1],v2); v1 += v1 & -v1; } } int sm(ll v1,ll bt[]) { ll v2 = MAX; while (v1 > 0) { v2 =mn(bt[v1],v2); v1 -= v1 & -v1; } return v2; } int main() { cin >> n; memset(bt1, -1, sizeof(bt1)); memset(bt2, -1, sizeof(bt2)); for (int i = 1; i <= n; i++)scanf("%d", a + i); for (int i = 1; i <= n; i++)scanf("%d", x + i); for (int i = 1; i <= n; i++)scanf("%d", y + i); for (int i = 1; i <= n; i++) { ll xi = upper_bound(x + 1, x + i + 1, a[i]) - x - 1; ad(i, dp[i - 1] - x[i] + y[i], bt1); ad(n + 1 - i, dp[i - 1] + x[i] + y[i], bt2); dp[i] = MAX; ll v1 = sm(xi, bt1), v2 = sm(n + 1 - (xi + 1), bt2); dp[i] = mn(dp[i],a[i] + v1); dp[i] = mn(dp[i], v2 - a[i]); } cout << dp[n] << endl; return 0; }