#include <cstdio>
#include <algorithm>
using namespace std;
inline int readint(){
int n = 0;
char ch = getchar();
while(ch < ‘0‘ || ch > ‘9‘) ch = getchar();
while(ch <= ‘9‘ && ch >= ‘0‘){
n = (n << 1) + (n << 3) + (ch & 15);
ch = getchar();
}
return n;
}
typedef long long ll;
const int maxn = 1 << 18;
const ll P = 479 << 21 | 1, g = 3;
ll wn[20];
inline ll ksm(ll a, ll b, const ll &mod){
ll s = 1;
while(b){
if(b & 1) s = s * a % mod;
b >>= 1;
a = a * a % mod;
}
return s;
}
void change(ll s[], int len){
for(int i = 0, j = 0, k; i < len - 1; i++){
if(i < j) swap(s[i], s[j]);
k = len >> 1;
while(j >= k){
j -= k;
k >>= 1;
}
j += k;
}
}
void FNTT(ll s[], int len, int on){
change(s, len);
for(int id = 0, h = 2; h <= len; h <<= 1){
id++;
for(int j = 0; j < len; j += h){
ll w = 1;
for(int k = j; k < j + (h >> 1); k++){
ll u = s[k] % P, t = w * s[k + (h >> 1)] % P;
s[k] = (u + t) % P;
s[k + (h >> 1)] = (u - t + P) % P;
w = w * wn[id] % P;
}
}
}
if(on == -1){
for(int i = 1; i < (len >> 1); i++) swap(s[i], s[len - i]);
ll inv = ksm(len, P - 2, P);
for(int i = 0; i < len; i++) s[i] = s[i] * inv % P;
}
}
ll x[maxn], y[maxn], A[maxn], B[maxn];
int main(){
for(int i = 1; i < 20; i++) wn[i] = ksm(3, (P ^ 1) >> i, P);
int n, m;
n = readint();
m = readint();
ll s1 = 0, s2 = 0;
for(int i = 0; i < n; i++) x[i] = readint();
for(int i = 0; i < n; i++) y[i] = readint();
for(int i = 0; i < n; i++){
s1 += x[i] * x[i] + y[i] * y[i];
s2 += x[i] - y[i];
}
for(int i = 0; i < n; i++){
A[i] = x[i];
B[i] = y[n - i - 1];
}
int len = 1;
while(len < (n << 1)) len <<= 1;
FNTT(A, len, 1);
FNTT(B, len, 1);
for(int i = 0; i < len; i++) A[i] = A[i] * B[i] % P;
FNTT(A, len, -1);
ll mx = 0;
for(int i = 0; i < n; i++) mx = max(mx, A[i] + A[i + n]);
s1 -= mx << 1;
ll dcz = s2 / n;
ll ans = s1 - 2LL * dcz * s2 + dcz * dcz * n;
dcz++;
ans = min(ans, s1 - 2LL * dcz * s2 + dcz * dcz * n);
dcz -= 2;
ans = min(ans, s1 - 2LL * dcz * s2 + dcz * dcz * n);
printf("%lld\n", ans);
return 0;
}