#include #pragma GCC optimize("O3") #pragma GCC target("avx") #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define ll long long #define fi first #define se second #define push_back pb #define show(x) cout << #x << " = " << x << "\n" using namespace std; typedef pair P; const int MAX_N = 300001; #define getchar getchar_unlocked inline int in() { int n, c; while ((c = getchar()) < '0') if (c == EOF) return -1; n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } pair lines[MAX_N]; bool check(pair l1, pair l2, pair l3){ return (l2.first-l1.first)*(l3.second-l2.second)>=(l2.second-l1.second)*(l3.first-l2.first); } ll f(int i, ll x){ return lines[i].first * x + lines[i].second; } int head = 0, tail = 0; void add(ll a, ll b){ pair line(a, b); while(tail - head >= 2 && check(lines[tail-2], lines[tail-1], line)){ tail--; } lines[tail++] = line; } ll get(ll x){ while(tail - head >= 2 && f(head, x) >= f(head + 1, x)){ head++; } return f(head, x); } int a[MAX_N],x[MAX_N],y[MAX_N]; int main() { int n = in(); rep(i,n){ a[i] = in(); } rep(i,n){ x[i] = in(); } rep(i,n){ y[i] = in(); } add(-2*x[0],(ll)x[0]*x[0]+(ll)y[0]*y[0]); rep(i,n){ if(i < n-1){ add(-2*x[i+1],get(a[i])+(ll)x[i+1]*x[i+1]+(ll)y[i+1]*y[i+1]+(ll)a[i]*a[i]); }else{ cout << get(a[i])+(ll)a[i]*a[i] << "\n"; return 0; } } } ;