import sys import heapq input = sys.stdin.readline def read_values(): return map(int, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_list(): return list(read_values()) class MaxFlow: def __init__(self,n): self.g = [list() for _ in range(n)] self.r = [list() for _ in range(n)] self.f = [list() for _ in range(n)] self.mc=[False]*n self.size=n self.q=[-1]*n self.e=0 def add(self,u,v,c): self.g[u].append(v) self.g[v].append(u) self.r[u].append(len(self.f[v])) self.r[v].append(len(self.f[u])) self.f[u].append(c) self.f[v].append(0) self.e+=1 def bfs(self,s,t): self.depth=[-2]*self.size self.depth[s]=0 self.q[0]=s l=0 r=1 while(l0): self.depth[v2]=self.depth[v]+1 if(v2==t):return self.q[r]=v2 r+=1 def dfs(self,v,t,f): if(v==t):return f r=0 for i in range(self.pg[v],len(self.g[v])): self.pg[v]=i v2=self.g[v][i] i2=self.r[v][i] if(self.f[v][i]==0 or self.depth[v]+1!=self.depth[v2]):continue d=self.dfs(v2,t,min(f-r,self.f[v][i])) if(d==0):continue self.f[v][i]-=d self.f[v2][i2]+=d r+=d if(r==f):break self.depth[v]=self.size return r def flow(self,s,t): r=0 while(1): self.bfs(s,t) if(self.depth[t]==-2):return r if(self.depth[t]*self.depth[t]*2>self.e):break self.pg=[0]*self.size f = self.dfs(s,t,10**18) if(f==0):break r+=f while(1): self.fi=[False]*self.size f = self.dfs2(s,t,10**18) if(f==0):break r+=f return r def main(): n,s,t=read_values() a=read_list() b=read_list() mf=MaxFlow(n+2) for v in a: mf.add(n,v-1,10**18) for v in b: mf.add(v-1,n+1,10**18) for i in range(n): c=read_list() for j in range(n): mf.add(i,j,c[j]) print(mf.flow(n,n+1)) if __name__ == "__main__": main()