#include #include #include #include #include #include #include #include #include #include #include #include #define mk make_pair #define pb push_back using namespace std; typedef long long int ll; typedef pair pos; const ll MOD = 1234567, N = 300010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838; const int S = 60; ll mn(ll a, ll b) { if (a == -1)return b; if (b == -1)return a; return min(a, b); } static ll gcd(ll v1, ll v2) { if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2); } ll pw(ll v1, ll v2) { ll v3 = 1; while (v2 > 0) { if (v2 % 2)v3 = (v3*v1) % MOD; v1 = (v1*v1) % MOD; v2 /= 2; } return v3; } ll n, a[N],dp[N]; pos xy[N]; struct ConvexHullTrick { std::deque > dq; //(傾き、切片) void add(long long a, long long b) { std::pair p0 = std::make_pair(a, b); while (dq.size() >= 2) { int sz = dq.size(); std::pair p1 = dq[sz - 1]; std::pair p2 = dq[sz - 2]; if ((p0.second - p1.second)*(p0.first - p2.first) < (p0.second - p2.second)*(p0.first - p1.first))break;//交点のx座標を比較 dq.pop_back(); } dq.push_back(p0); } long long query(long long x) { while (dq.size() >= 2) { long long v1 = dq[0].first*x + dq[0].second; long long v2 = dq[1].first*x + dq[1].second; if (v1 <= v2)break; dq.pop_front(); } return dq[0].first*x + dq[0].second; } }; ConvexHullTrick cht; int main() { cin >> n; for (int i = 1; i <= n; i++)scanf("%d", a + i); for (int i = 1; i <= n; i++)scanf("%d", &xy[i].first); for (int i = 1; i <= n; i++)scanf("%d", &xy[i].second); for (int i = 1; i <= n; i++) { cht.add(-2*xy[i].first, dp[i - 1] + xy[i].first*xy[i].first + xy[i].second*xy[i].second); dp[i] = a[i] * a[i] + cht.query(a[i]); } cout << dp[n] << endl; return 0; }