#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define rep1(i,n) for(ll i=1;i<=(ll)(n);i++) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define rrep1(i,n) for(ll i=(ll)(n);i>0;i--) #define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } const ll inf = 1000000001; const ll INF = 2e18; const ll MOD = 1000000007; const double pi = 3.14159265358979323846; #define Sp(p) cout<p; return p.a*x + p.b; } private: template T it_p1(T a) { return ++a; } template T it_m1(T a) { return --a; } struct L { ll a, b; L(ll a, ll b) : a(a), b(b) {} bool operator<(const L &rhs) const { return a != rhs.a ? a > rhs.a : b < rhs.b; } }; struct CP { ll n, d; L p; CP(ll _n, ll _d, const L &p) : n(_n), d(_d), p(p) { if (d < 0) { n *= -1; d *= -1; } }; bool operator<(const CP &rhs) const { if (n == INF || rhs.n == -INF) return 0; if (n == -INF || rhs.n == INF) return 1; return n * rhs.d < rhs.n * d; } }; set S; set C; typedef set::iterator It; void C_erase(It a, It b) { for (It it = a; it != b; ++it) C.erase(cp(*it, *it_p1(it))); } CP cp(const L &p1, const L &p2) { if (p1.a == INF) return CP(-INF, 1, p2); if (p2.a == -INF) return CP(INF, 1, p2); return CP(p1.b - p2.b, p2.a - p1.a, p2); } bool check(const L &p1, const L &p2, const L &p3) { if (p1.a == p2.a && p1.b <= p2.b) return 1; if (p1.a == INF || p3.a == -INF) return 0; return (p2.a - p1.a)*(p3.b - p2.b) >= (p2.b - p1.b)*(p3.a - p2.a); } }; int main() { int n; cin >> n; vl a(n + 1), x(n), y(n); rep (i, n) { long long temp; cin >> temp; a[i] = temp; } rep (i, n) { long long temp; cin >> temp; x[i] = temp; } rep (i, n) { long long temp; cin >> temp; y[i] = temp; } vl dp(n + 1); CHT2 cht; cht.add(-2*x[0], dp[0] + x[0]*x[0] + y[0]*y[0]); rep1 (i, n) { dp[i] = cht.query(a[i - 1]) + a[i - 1] * a[i - 1]; cht.add(-2*x[i], dp[i] + x[i]*x[i] + y[i]*y[i]); } //DEBUG_VEC(dp); cout << (long long)dp[n] << endl; }