#include<bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define db double
#define N 1000000
using namespace std;
typedef complex<db>W;
const db pi=acos(-1);
W a[N],b[N];
int rev[N],L,n;
ll sumx1,sumx2,sumy1,sumy2;
void FFT(W * A,int f){
for(int i=0;i<n;++i)if(i<rev[i])swap(A[i],A[rev[i]]);
for(int i=1;i<n;i<<=1){
W wn(cos(pi/i),sin(f*pi/i)),x,y;
for(int j=0;j<n;j+=(i<<1)){
W w(1,0);
for(int k=0;k<i;k++,w*=wn){
x=A[j+k],y=w*A[j+k+i];
A[j+k]=x+y;
A[j+k+i]=x-y;
}
}
}
}
ll Ans,len;
ll f(int x){return len*x*x+2*x*(sumx1-sumy1);}
ll min(ll a,ll b,ll c){return min(min(a,b),c);}
void pre(){
Ans=sumx2+sumy2;
ll flag=abs(sumx1-sumy1);
ll x=-(sumx1-sumy1)/n;
if(flag%n)Ans+=min(f(x+1),f(x),f(x-1));
else Ans+=f(x);
}
int main(){
int c;
scanf("%d%d",&n,&c);len=n;int m=n*2-1;n--;
for(int i=0;i<=n;++i){
int x;scanf("%d",&x);a[i]=a[i+n+1]=x;
sumx1+=x;
sumx2+=x*x;
}reverse(a,a+m+1);
for(int i=0;i<=n;++i){
int x;scanf("%d",&x);b[i]=x;
sumy1+=x;
sumy2+=x*x;
}pre();m*=2;
for(n=1;n<=m;n<<=1)L++;
for(int i=0;i<=n;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<(L-1));
FFT(a,1),FFT(b,1);
for(int i=0;i<n;++i)a[i]*=b[i];
FFT(a,-1);
ll tmp(0);
for(int i=len;i<=m;++i)
tmp=max(tmp,(ll)(a[i].real()/n+0.5));
cout<<Ans-2*tmp;
return 0;
}