using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; //using nint=System.Int32; static class Program{ const int mod=(int)1e9+7; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; var h=new int[s[0]][]; var hs1=new Dictionary[s[0]]; var hs2=new Dictionary[s[1]]; int m=0,p=0,c=0,d=0; for(int i = 0;i();} for(int i = 0;i(); h[i]=sc.Ia; for(int j = 0;j[] li; private Dictionary[] h; private bool[] b; private int[] l; private int n,ans,go; private const int inf=int.MaxValue; public Mfp(int n){ this.n=n; li=new List[n]; h=new Dictionary[n+1]; for(int i=0;i(); h[i]=new Dictionary(); } } public void Edge(int a,int b,int c){ if(a==b){return;} if(!h[a].ContainsKey(b)){ li[a].Add(b); li[b].Add(a); h[a].Add(b,c); h[b].Add(a,0); } else{h[a][b]+=c;} } public int Dinic(int st,int go){ this.go=st; ans=0; int z=1; while(z>0){ l=new int[n]; var qu=new Queue>(); qu.Enqueue(ValueTuple.Create(st,1)); l[st]=1; while(qu.Count>0){ var e=qu.Dequeue(); for(int i=0;iu;i++){ if(!b[li[a][i]]&&l[li[a][i]]0){ b=new bool[n]; z=Fu2(st,inf); ans+=z; } return ans; } private int Fu2(int a,int p){ if(a==go){return p;} int u=0; b[a]=true; for(int i=0;iu;i++){ if(!b[li[a][i]]&&h[a][li[a][i]]!=0){ int z=Fu2(li[a][i],Min(p-u,h[a][li[a][i]])); h[a][li[a][i]]-=z; h[li[a][i]][a]+=z; u+=z; } } if(u!=0){b[a]=false;} return u; } public void Vc(int s,Action f){ b=new bool[n]; Fu4(s,0,f); for(int i=0;i f){ b[a]=true; if((p&1)==0&&p!=0){f(a);} for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T1,T2) Tp2(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T,T,T) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} public (T1,T1,T2) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} private T Ct(string s){return (T)Convert.ChangeType(s,typeof(T));} }