// includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // macros #define ll long long int #define pb emplace_back #define mk make_pair #define pq priority_queue #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; // types typedef pair P; typedef pair Pl; typedef pair Pll; typedef pair Pd; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1e9 + 7; // solve template bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} ll calc(ll a, ll x, ll y){ return (x - a) * (x - a) + y * y; } template struct ConvexHullTrick_ { vector > lines; function comp; ConvexHullTrick_(function comp_=[](T l, T r){return l >= r;}): comp(comp_){} bool isnot_require(pair l1, pair l2, pair l3){ if(l1 < l3)swap(l1, l3); return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first); } void add(pair p){ while(lines.size() >= 2 && isnot_require(*(lines.end()-2), *(lines.end()-1), p))lines.pop_back(); lines.push_back(p); } T f(int i, T x){ return lines[i].first * x + lines[i].second; } T val(T x){ int ld = -1; int rd = lines.size() - 1; while(rd - ld > 1){ int md = (rd + ld) / 2; if(comp(f(md, x), f(md + 1, x)))ld = md; else rd = md; } return f(rd, x); } }; using ConvexHullTrickI = ConvexHullTrick_; using ConvexHullTrickL = ConvexHullTrick_; ll dp[300001]; int main(int argc, char const* argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n), x(n), y(n); rep(i, n)cin >> a[i]; rep(i, n)cin >> x[i]; rep(i, n)cin >> y[i]; ConvexHullTrickL cht; dp[0] = calc(a[0], x[0], y[0]); cht.add(mk(- 2 * x[0], x[0] * x[0] + y[0] * y[0])); for(int i = 1; i < n; i++){ cht.add(mk(- 2 * x[i], x[i] * x[i] + y[i] * y[i] + dp[i-1])); dp[i] = a[i] * a[i] + cht.val(a[i]); } cout << dp[n - 1] << endl; return 0; }