#include<iostream>
#include<cstdio>
#define inf 0x7fffffff
using namespace std;
int n,a,b,x[81],y[81],dis[201],q[201],inq[201],head[201],from[201],T,ans,cnt=1;
struct data{int from,to,next,v,c;}e[50001];
void ins(int u,int v,int w,int c)
{
cnt++;
e[cnt].from=u;e[cnt].to=v;
e[cnt].v=w;e[cnt].c=c;
e[cnt].next=head[u];head[u]=cnt;
}
void insert(int u,int v,int w,int c)
{ins(u,v,w,c);ins(v,u,0,-c);}
bool spfa()
{
for(int i=0;i<=T;i++)dis[i]=inf;
int t=0,w=1,i,now;
dis[0]=q[0]=0;inq[0]=1;
while(t!=w)
{
now=q[t];t++;if(t==200)t=0;
for(int i=head[now];i;i=e[i].next)
{
if(e[i].v&&dis[e[i].to]>dis[now]+e[i].c)
{
from[e[i].to]=i;
dis[e[i].to]=dis[now]+e[i].c;
if(!inq[e[i].to])
{
inq[e[i].to]=1;
q[w++]=e[i].to;
if(w==200)w=0;
}
}
}
inq[now]=0;
}
if(dis[T]==inf)return 0;return 1;
}
void mcf()
{
int i,x=inf;
i=from[T];
while(i)
{
x=min(e[i].v,x);
i=from[e[i].from];
}
i=from[T];
while(i)
{
e[i].v-=x;
e[i^1].v+=x;
ans+=x*e[i].c;
i=from[e[i].from];
}
}
int main()
{
scanf("%d%d%d",&n,&a,&b);
T=a+b+2;
for(int i=1;i<=a;i++)scanf("%d",&x[i]);
for(int i=1;i<=b;i++)scanf("%d",&y[i]);
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
insert(i,a+j,1,(x[i]-y[j])*(x[i]-y[j]));
for(int i=1;i<=a;i++)insert(0,i,1,0);
for(int i=1;i<=b;i++)insert(a+i,a+b+1,1,0);
insert(a+b+1,T,n,0);
while(spfa())mcf();
printf("%d",ans);
return 0;
}