#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int n,p,q,s,t,m,ans,a[1000][1000],room[201][201],dish[201][201],dis[1000],sq[1000];
bool BFS()
{
memset(dis,0xff,sizeof(dis));
dis[1]=0;
int x,head=0,tail=1;
sq[1]=1;
while (head<tail)
{
head++;
x=sq[head];
for (int i=1;i<=t;i++)
if (a[x][i]>0&&dis[i]<0)
{
dis[i]=dis[x]+1;
tail++;
sq[tail]=i;
}
}
if (dis[t]>0) return true; else return false;
}
int find(int x,int low)
{
int delta=0;
if (x==t) return low;
for (int i=1;i<=t;i++)
if (dis[i]==dis[x]+1&&a[x][i]>0&&(delta=find(i,min(low,a[x][i]))))
{
a[x][i]-=delta;
a[i][x]+=delta;
return delta;
}
return 0;
}
int main()
{
memset(room,0,sizeof(room));
memset(dish,0,sizeof(dish));
memset(a,0,sizeof(a));
scanf("%d%d%d",&n,&p,&q);
for (int i=1;i<=n;i++)
for (int j=1;j<=p;j++)
scanf("%d",&room[i][j]);
for (int i=1;i<=n;i++)
for (int j=1;j<=q;j++)
scanf("%d",&dish[i][j]);
s=1;
t=n+n+p+q+2;
for (int i=1;i<=p;i++) a[1][i+1]=1;
for (int i=1;i<=n;i++) a[p+1+i][p+n+1+i]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=p;j++)
if (room[i][j]==1) a[j+1][p+1+i]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=q;j++)
if (dish[i][j]==1) a[p+n+1+i][p+n+n+1+j]=1;
for (int i=n+n+p+2;i<t;i++) a[i][t]=1;
ans=0;
while (BFS())
while(m=find(1,0x7fffffff)) ans+=m;
printf("%d",ans);
return 0;
}
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;
int edge[420][420],dis[420],start[420],gap[420],pre[420];
int main()
{
int a,b,p,q,c,i,j,k,n,m,h,ll,flow;
memset(edge,0,sizeof(edge));
memset(gap,0,sizeof(gap));
memset(start,0,sizeof(start));
cin >> n >> p>> q; c=p+n; b=c+n;
for ( i=1; i<=n; i++) for ( j=1; j<=p; j++)
{
cin >> a;
if ( a ) edge[j][i+p]++;
}
for ( i=1; i<=n; i++) edge[i+p][i+c]++;
for ( i=1; i<=n; i++) for ( j=1; j<=q; j++)
{
cin >> a;
if ( a ) edge[i+c][b+j]++;
}
n=b+q+1; gap[0]=n+1;
for ( i=1; i<=p; i++) edge[0][i]++;
for ( i=b+1; i<n; i++) edge[i][n]++;
for ( i=0; i<=n; i++) dis[i]=0;
i=0; flow=0;
while ( dis[0]<=n )
{
ll=0;
for ( j=start[i]; j<=n; j++)
if ( edge[i][j] && dis[j]+1==dis[i] )
{
ll=1;
pre[j]=i;
i=j;
if ( i==n )
{
flow++;
while ( i!=0 )
{
h=i;
i=pre[i];
edge[i][h]--;
edge[h][i]++;
}
}
break;
}
if ( ll ) continue;
h=n+1;
for ( j=1; j<=n; j++)
if ( edge[i][j] && dis[j]<h )
{
h=dis[j];
a=j;
}
start[i]=a;
gap[dis[i]]--;
if ( !gap[dis[i]] ) break;
dis[i]=h+1;
gap[dis[i]]++;
if ( i!=0 ) i=pre[i];
}
cout << flow;
return 0;
}