using System; using System.Collections; using System.Collections.Generic; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ if(N==0){ Console.WriteLine(1); return; } UnionFind UF=new UnionFind(N); for(int i=0;i Rem=new HashSet(); HashSet D=new HashSet(); for(int i=0;i Gp=UF.Gp(i); foreach(int x in Gp)Rem.Add(x); List P=new List(); for(int ii=0;ii Pconv=Geo.CreateConvHull(P); for(int ii=0;iiint.Parse(e));} static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));} static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));} } class UnionFind{ int[] parent; int N; public UnionFind(int n_){ Initialize(n_); } public void Initialize(int n_){ N=n_; parent=new int[N]; for(int i=0;i Gp(int a){ List ret=new List(); for(int i=0;i CreateConvHull(List L_){ List L=new List(L_); L.Sort((x,y)=>x.X.CompareTo(y.X)==0?x.Y.CompareTo(y.Y):x.X.CompareTo(y.X)); List ret=new List(); int k=0; //右半分 for(int i=0;i1 && det((ret[k-1].X-ret[k-2].X),(ret[k-1].Y-ret[k-2].Y),(L[i].X-ret[k-1].X),(L[i].Y-ret[k-1].Y))<=0){ ret.RemoveAt(k-1); k=ret.Count; } ret.Add(L[i]); } //左半分 int t=ret.Count; for(int i=L.Count-2;i>=0;i--){ //末尾削除はO(1)なのでどんどん使う。 k=ret.Count; while(k>t && det((ret[k-1].X-ret[k-2].X),(ret[k-1].Y-ret[k-2].Y),(L[i].X-ret[k-1].X),(L[i].Y-ret[k-1].Y))<=0){ ret.RemoveAt(k-1); k=ret.Count; } ret.Add(L[i]); } ret.RemoveAt(ret.Count-1); return ret; } static int det(int a,int b,int c,int d){ return a*d-b*c; } }