#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; #define T long long #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; } class CHT { private: using ptt = pair; bool check(ptt l1, ptt l2, ptt l3){ return (l2.first-l1.first)*(l3.second-l2.second)>=(l2.second-l1.second)*(l3.first-l2.first); } T f(int i, T x){ return lines[i].first * x + lines[i].second; } public: vector lines; CHT(){}; void add(T a, T b){ ptt line(a, b); while((int)lines.size() >= 2 && check(*(lines.end()-2), lines.back(), line)){ lines.pop_back(); } lines.emplace_back(line); } T get(T x){ static int head = 0; while((int)lines.size() - head >= 2 && f(head, x) > f(head + 1, x)){ head++; } return f(head, x); } }; int main() { int n = in(); vector a(n),x(n),y(n); rep(i,n){ a[i] = in(); } rep(i,n){ x[i] = in(); } rep(i,n){ y[i] = in(); } CHT cht; cht.add(-2*x[0],x[0]*x[0]+y[0]*y[0]); rep(i,n){ if(i < n-1){ cht.add(-2*x[i+1],cht.get(a[i])+x[i+1]*x[i+1]+y[i+1]*y[i+1]+a[i]*a[i]); }else{ cout << cht.get(a[i])+a[i]*a[i] << "\n"; return 0; } } } ;