#include #include __attribute__((constructor)) void fast_io() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); } using S = std::pair; S op(S a, S b) { return {std::min(a.first, b.first), std::min(a.second, b.second)}; } S e() { return {LLONG_MAX >> 1, LLONG_MAX >> 1}; }; int main() { size_t n; std::cin >> n; std::vector a(n), x(n), y(n); for (auto& ai : a) std::cin >> ai; for (auto& xi : x) std::cin >> xi; for (auto& yi : y) std::cin >> yi; long long xmax = *std::max_element(x.begin(), x.end()); atcoder::segtree seg(xmax + 1); long long dp = 0; for (size_t i = 0; i < n; ++i) { seg.set(x[i], {dp - x[i] + y[i], dp + x[i] + y[i]}); dp = std::min(seg.prod(0, a[i]).first + a[i], seg.prod(a[i], xmax).second - a[i]); } std::cout << dp << '\n'; }