#include "bits/stdc++.h" using namespace std; #define pb push_back #define mp make_pair constexpr int INF = 1 << 29; constexpr int MOD = 1000000007; typedef long long ll; typedef unsigned long long ull; constexpr int dx[4] = {1, 0, -1, 0}; constexpr int dy[4] = {0, 1, 0, -1}; vector A, X, Y; ll f(int i, int j) { return (X[j] - A[i]) * (X[j] - A[i]) + Y[j] * Y[j]; } int main() { int N; cin >> N; A.resize(N), X.resize(N), Y.resize(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> X[i]; } for (int i = 0; i < N; i++) { cin >> Y[i]; } vector dp(N + 1, INF); dp[0] = f(0, 0); for(int i = 1; i < N; i++) { dp[i] = f(i, 0); for (int j = 0; j < i; j++) { dp[i] = min(dp[i], dp[j] + f(i, j + 1)); } } cout << dp[N - 1] << endl; return 0; }