int len=1,maxflow=0;
void add(int x,int y,int z,int w)
{
pre[++len]=last[x],last[x]=len,e[len]=y,ca[len]=z,co[len]=w;
pre[++len]=last[y],last[y]=len,e[len]=x,ca[len]=0,co[len]=-w;
}
int Nxt(int x){if (x==MaxL-1) return 1;return x+1;}
int MCMF()
{
int __ans=0;
while(1)
{
memset(dis,0x7e,sizeof(dis));
memset(vis,0,sizeof(vis));
int h=0,t=1;
q[1]=source,vis[source]=0,dis[source]=0;
while(h<t)
{
h=Nxt(h);int u=q[h];
for(int p=last[u];p;p=pre[p])
{
int v=e[p],rm=ca[p],Cost=co[p];
if(rm&&dis[u]+Cost<dis[v])
{
dis[v]=dis[u]+Cost,path[v]=p;
if(!vis[v])
{
t=Nxt(t);
q[t]=v;
vis[v]=1;
}
}
}
vis[u]=0;
}
if(dis[target]==0x7e7e7e7e)break;
int tf=inf;
for(int u=target;u!=source;u=e[path[u]^1])tf=min(tf,ca[path[u]]);
maxflow+=tf,__ans+=tf*dis[target];
for(int u=target;u!=source;u=e[path[u]^1]) ca[path[u]]-=tf,ca[path[u]^1]+=tf;
}
return __ans;
}