#include #include #include #include #include __attribute__((constructor)) void fast_io() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); } template class lines { public: void append(T a, T b) { if (lines.empty()) { lines.emplace_back(a, b); return; } auto [a1, b1] = lines.back(); while (lines.size() > 1) { auto [a0, b0] = lines[lines.size() - 2]; if ((a1 - a) * (b1 - b0) < (a0 - a1) * (b - b1)) break; lines.pop_back(); a1 = a0; b1 = b0; } lines.emplace_back(a, b); } T min_at(T x) { assert(!lines.empty()); auto [a0, b0] = lines[0]; T y0 = a0 * x + b0; while (lines.size() > 1) { auto [a1, b1] = lines[1]; T y1 = a1 * x + b1; if (y0 < y1) break; lines.pop_front(); a0 = a1; b0 = b1; y0 = y1; } return y0; } private: std::deque> lines; }; 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; lines cht; long long dp = 0; for (size_t i = 0; i < n; ++i) { cht.append(-2 * x[i], x[i] * x[i] + y[i] * y[i] + dp); dp = cht.min_at(a[i]) + a[i] * a[i]; } std::cout << dp << '\n'; }