#include using namespace std; using ll = long long; using ld = long double; using pll = pair; using tlll = tuple; constexpr ll INF = 1LL << 60; template bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;} ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);} ll pow_ll(ll A, ll B) {if (A == 0 || A == 1) {return A;} if (A == -1) {return B & 1 ? -1 : 1;} ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;} ll logfloor(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp <= B / A; tmp *= A) {res++;} return res;} ll logceil(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp < B; tmp *= A) {res++;} return res;} ll arisum_ll(ll a, ll d, ll n) { return n * a + (n & 1 ? ((n - 1) >> 1) * n : (n >> 1) * (n - 1)) * d; } ll arisum2_ll(ll a, ll l, ll n) { return n & 1 ? ((a + l) >> 1) * n : (n >> 1) * (a + l); } ll arisum3_ll(ll a, ll l, ll d) { assert((l - a) % d == 0); return arisum2_ll(a, l, (l - a) / d + 1); } template void unique(vector &V) {V.erase(unique(V.begin(), V.end()), V.end());} template void sortunique(vector &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) template void printvec(const vector &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';} template void printvect(const vector &V) {for (auto v : V) cout << v << '\n';} template void printvec2(const vector> &V) {for (auto &v : V) printvec(v);} //* #include using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; //using mint = modint; //*/ template struct LiChaoTree { private: int n; vector X; vector> node; int type; void add_line_internal(T a, T b, int i, int l, int r) { auto [a0, b0] = node[i]; bool small_l = a * X[l] + b <= a0 * X[l] + b0; bool small_r = a * X[r - 1] + b <= a0 * X[r - 1] + b0; if (!small_l && !small_r) return; if (small_l && small_r) { node[i] = make_pair(a, b); return; } if (i >= n) return; int m = (l + r) / 2; bool small_m = a * X[m] + b <= a0 * X[m] + b0; if (!small_m) { if (small_l) add_line_internal(a, b, 2 * i, l, m); else if (small_r) add_line_internal(a, b, 2 * i + 1, m, r); else assert(false); } else { node[i] = make_pair(a, b); if (!small_l) add_line_internal(a0, b0, 2 * i, l, m); else if (!small_r) add_line_internal(a0, b0, 2 * i + 1, m, r); else assert(false); } } void add_segment_internal(T a, T b, T lx, T rx, int i, int l, int r) { if (lx <= X[l] && X[r - 1] < rx) { add_line_internal(a, b, i, l, r); return; } if (r - l <= 1) return; int m = (l + r) / 2; add_segment_internal(a, b, lx, rx, 2 * i, l, m); add_segment_internal(a, b, lx, rx, 2 * i + 1, m, r); } public: LiChaoTree(const vector &xs, bool sorted_unique = false) // クエリで問われる x の値を格納した配列を渡す { type = 0; X = vector(xs); if (!sorted_unique) sortunique(X); n = 1; while (n < (int)X.size()) n <<= 1; X.resize(2 * n, X.back()); node.assign(2 * n, make_pair(0, INF)); } LiChaoTree(T x_min, T x_max) // 上の xs = {x_min, …, x_max} と同じ(get_min が少し早くなる) { type = 1; X.resize(x_max - x_min + 1); for (int i = 0; i <= x_max - x_min; i++) X[i] = x_min + i; n = 1; while (n < (int)X.size()) n <<= 1; X.resize(2 * n, X.back()); node.assign(2 * n, make_pair(0, INF)); } void add_line(T a, T b) { add_line_internal(a, b, 1, 0, n); } void add_segment(T a, T b, T lx, T rx) { add_segment_internal(a, b, lx, rx, 1, 0, n); } T get_min(T p) { int i; if (type == 0) { i = lower_bound(X.begin(), X.end(), p) - X.begin(); assert(X.at(i) == p); } else if (type == 1) { assert(X.front() <= p && p <= X.back()); i = p - X.front(); } else assert(false); i += n; T res = INF; while (i > 0) { auto [a, b] = node[i]; chmin(res, a * p + b); i >>= 1; } return res; } }; int main() { ll N; cin >> N; vector A(N), X(N), Y(N); for (ll i = 0; i < N; i++) { cin >> A.at(i); } for (ll i = 0; i < N; i++) { cin >> X.at(i); } for (ll i = 0; i < N; i++) { cin >> Y.at(i); } LiChaoTree cht(A); /* vector dp(N + 1, INF); dp.at(0) = 0; for (ll i = 0; i < N; i++) { for (ll j = 0; j <= i; j++) { ll tmp = dp.at(j) + abs(X.at(j) - A.at(i)) + Y.at(j); chmin(dp.at(i + 1), tmp); } } ll ans = dp.at(N); cout << ans << endl; //*/ //* vector dp(N + 1, INF); dp.at(0) = 0; for (ll i = 0; i < N; i++) { cht.add_segment(-1, X.at(i) + Y.at(i) + dp.at(i), -INF, X.at(i)); cht.add_segment(1, -X.at(i) + Y.at(i) + dp.at(i), X.at(i), INF); dp.at(i + 1) = cht.get_min(A.at(i)); } ll ans = dp.at(N); cout << ans << endl; //*/ }