import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; class DJSet { int n; int[] upper; public DJSet(int n) { this.n=n; upper=new int[n]; Arrays.fill(upper, -1); } int root(int x) { return upper[x]<0?x:(upper[x]=root(upper[x])); } boolean equiv(int x,int y) { return root(x)==root(y); } void setUnion(int x,int y) { x=root(x);y=root(y); if (x==y) return; if (upper[x]=p?a+b-p:a+b; } long gcd(long a,long b) { return a==0?b:gcd(b%a,a); } long pow_mod(long a,long n,long p) { return n==0?1:(pow_mod(a*a%p,n/2,p)*(n%2==1?a:1))%p; } long primitive_root(long p) { if (p==2) return 1; out:for (long root=2;root list=new ArrayList<>(); for (int i=0;i Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }