1 2
1 1
100 110
1
1000

1210

# sol

1、$x$$y$都选文。此时被割掉的边是$(x,T)$$(y,T)$，总损失应为$v$
2、$x$$y$都选理。此时被割掉的边是$(S,x)$$(S,y)$，总损失应为$u$
3、$x$选文$y$选理。此时被割掉的边是$(x,T)$$(S,y)$$(x,y)$，总损失应为$u+v$
4、$x$选理$y$选文。此时被割掉的边是$(S,x)$$(y,T)$$(y,x)$，总损失应为$u+v$

$(x,T)+(y,T)=v$
$(S,x)+(S,y)=u$
$(x,T)+(S,y)+(x,y)=u+v$
$(S,x)+(y,T)+(y,x)=u+v$

（我太菜了实在是写不出博客园markdown的方程组。。。只能写公式形式了）

$(x,T) = v / 2 (y,T) = v / 2 (S,x) = u / 2 (S,y) = u / 2 (x,y) = (u + v) / 2 (y,x) = (u + v) / 2$

## code

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int inf = 1e9;
const int N = 110;
struct edge{int to,next,w;}a[N*N<<3];
queue<int>Q;
int gi()
{
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
void link(int u,int v,int w,bool b)
{
}
bool bfs()
{
memset(dep,0,sizeof(dep));
dep[S]=1;Q.push(S);
while (!Q.empty())
{
int u=Q.front();Q.pop();
if (a[e].w&&!dep[a[e].to])
dep[a[e].to]=dep[u]+1,Q.push(a[e].to);
}
return dep[T];
}
int dfs(int u,int flow)
{
if (u==T)
return flow;
for (int &e=cur[u];e;e=a[e].next)
if (a[e].w&&dep[a[e].to]==dep[u]+1)
{
int temp=dfs(a[e].to,min(a[e].w,flow));
if (temp) {a[e].w-=temp;a[e^1].w+=temp;return temp;}
}
return 0;
}
int Dinic()
{
int res=0;
while (bfs())
{
while (int temp=dfs(S,inf)) res+=temp;
}
return res;
}
int main()
{
n=gi();m=gi();S=n*m+1;T=n*m+2;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
P[i][j]=++tot;
for (int k=0;k<6;k++)
{
int x=n,y=m;
if (k==2||k==3) x--;
if (k==4||k==5) y--;
for (int i=1;i<=x;i++)
for (int j=1;j<=y;j++)
v[k][i][j]=gi(),sum+=v[k][i][j];
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{