C++ 复制 typedef long long ll;
typedef unsigned long long ull;
const int mod= 998244353 ;
int pw (int a ,ll b ,int c = 1 )
{
for (;b;b>>= 1 ,a= 1 ll* a* a% mod)
if (b& 1 )c= 1 ll* c* a% mod;
return c;
}
void add (int& a ,int b ){a+= b;if (a>= mod)a-= mod;}
namespace Poly
{
const int N= 1 << 18 ,g= 3 ;
int pwg[N],inv[N];
int getsz (int n ){return 1 << __lg (n)+ 1 ;}
void init ()
{
for (int h= 2 ;h<= N;h<<= 1 )
{
int t= pw (3 ,(mod- 1 )/ h);pwg[h>> 1 ]= 1 ;
for (int i= (h>> 1 )+ 1 ;i< h;++ i)pwg[i]= 1 ll* pwg[i- 1 ]* t% mod;
}
inv[0 ]= inv[1 ]= 1 ;
for (int i= 2 ;i< N;++ i)inv[i]= 1 ll* inv[mod% i]* (mod- mod/ i)% mod;
}
void dft (vector <int >& f ,int n )
{
f.resize (n);
for (int h= n;h> 1 ;h>>= 1 )
for (int i= 0 ,p= h>> 1 ;i< n;i+= h)
for (int j= i;j< i+ p;++ j)
{
int u= f[j],v= f[j+ p];
add (f[j],v),f[j+ p]= 1 ll* pwg[j- i+ p]* (u- v+ mod)% mod;
}
}
void idft (vector <int >& f ,int n )
{
f.resize (n);
for (int h= 2 ;h<= n;h<<= 1 )
for (int i= 0 ,p= h>> 1 ;i< n;i+= h)
for (int j= i;j< i+ p;++ j)
{
int t= 1 ll* pwg[j- i+ p]* f[j+ p]% mod;
f[j+ p]= f[j],add (f[j+ p],mod- t),add (f[j],t);
}
reverse (f.begin ()+ 1 ,f.begin ()+ n);
for (int i= 0 ,k= pw (n,mod- 2 );i< n;++ i)f[i]= 1 ll* f[i]* k% mod;
}
struct poly :vector <int >
{
using vector <int >::vector;
void modxn (int n ){if (n< size ())resize (n);}
void drv ()
{
for (int i= 0 ;i+ 1 < size ();++ i)(* this )[i]= 1 ll* (* this )[i+ 1 ]* (i+ 1 )% mod;
pop_back ();
}
void itg ()
{
push_back (0 );
for (int i= size ()- 1 ;i> 0 ;-- i)(* this )[i]= 1 ll* (* this )[i- 1 ]* inv[i]% mod;
(* this )[0 ]= 0 ;
}
int operator () (int x )
{
int ret= 0 ;
for (int i= size ()- 1 ;~ i;-- i)ret= (1 ll* ret* x+ (* this )[i])% mod;
return ret;
}
};
poly &operator += (poly & a ,const poly & b )
{
if (a.size ()< b.size ())a.resize (b.size ());
for (int i= 0 ;i< b.size ();++ i)add (a[i],b[i]);
return a;
}
poly &operator -= (poly & a ,const poly & b )
{
if (a.size ()< b.size ())a.resize (b.size ());
for (int i= 0 ;i< b.size ();++ i)add (a[i],mod- b[i]);
return a;
}
poly operator + (const poly & a ,const poly & b )
{
poly c= a;c+= b;return c;
}
poly operator - (const poly & a ,const poly & b )
{
poly c= a;c-= b;return c;
}
poly operator * (const poly & a ,const poly & b )
{
if (! a.size ()||! b.size ())return {0 };
poly A= a,B= b,C;
int tmp= a.size ()+ b.size ()- 1 ,len= getsz (tmp);
A.resize (len),B.resize (len),C.resize (len);
dft (A,len),dft (B,len);
for (int i= 0 ;i< len;++ i)C[i]= 1 ll* A[i]* B[i]% mod;
idft (C,len);C.resize (tmp);
return C;
}
poly operator * (int a ,const poly & b )
{
a= (a% mod+ mod)% mod;poly B= b;
for (int i= 0 ;i< B.size ();++ i)B[i]= 1 ll* B[i]* a% mod;
return B;
}
poly operator * (const poly & b ,int a )
{
a= (a% mod+ mod)% mod;poly B= b;
for (int i= 0 ;i< B.size ();++ i)B[i]= 1 ll* B[i]* a% mod;
return B;
}
poly drv (const poly & a )
{
poly A= a;A.drv ();return A;
}
poly itg (const poly & a )
{
poly A= a;A.itg ();return A;
}
poly modxn (const poly & a ,int n )
{
poly A;A.resize (n);for (int i= 0 ;i< n&& i< a.size ();++ i)A[i]= a[i];return A;
}
poly ivs (const poly & A ,int n )
{
assert (A[0 ]);
int cur= 1 ;
poly b;b.resize (1 );b[0 ]= pw (A[0 ],mod- 2 );
while (cur< n)
{
cur<<= 1 ;
dft (b,cur* 2 );
poly a= modxn (A,cur);
dft (a,cur* 2 );
for (int i= 0 ;i< cur* 2 ;++ i)
b[i]= (2 * b[i]+ 1 ll* (mod- a[i])* b[i]% mod* b[i])% mod;
idft (b,cur* 2 );
b.modxn (cur);
}
b.modxn (n);return b;
}
poly ln (const poly & a ,int n )
{
assert (a[0 ]== 1 );
poly ret= a;ret.drv ();
ret= ret* ivs (a,n- 1 );
ret.modxn (n- 1 ),ret.itg ();
return ret;
}
poly exp (const poly & a ,int n )
{
assert (a[0 ]== 0 );
int cur= 1 ;
poly b;b.resize (1 );b[0 ]= 1 ;
while (cur< n)
{
cur<<= 1 ;
b= b* (poly{1 }- ln (b,cur)+ modxn (a,cur));
b.modxn (cur);
}
return modxn (b,n);
}
poly pow (const poly & a ,int n ,ll tim )
{
if (a[0 ])
{
poly b= a* pw (a[0 ],mod- 2 );
b= exp (ln (b,n)* (tim% mod),n);
return b* pw (a[0 ],tim% (mod- 1 ));
}
else assert (0 );
}
poly pow_a0_may_be_0 (const poly & a ,int n ,ll tim ,bool big = 0 )
{
if (a[0 ])return pow (a,n,tim);
if (big)return poly (n,0 );
int pos= 0 ;
while (pos< a.size ()&&! a[pos])++ pos;
if (pos== a.size ())return poly (n,0 );
if ((__int128)tim* pos>= n)return poly (n,0 );
poly b;b.resize (n- tim* pos);
for (int i= 0 ;i< b.size ()&& i+ pos< a.size ();++ i)
b[i]= a[i+ pos];
b= pow (b,n,tim);b.resize (n);
for (int i= n- 1 ;i>= tim* pos;-- i)b[i]= b[i- tim* pos];
for (int i= tim* pos- 1 ;i>= 0 ;-- i)b[i]= 0 ;
return b;
}
poly sqrt (const poly & a ,int n )
{
assert (a[0 ]== 1 );
return exp (ln (a,n)* pw (2 ,mod- 2 ),n);
}
struct _ {_ (){init ();}}__;
}//namespace Poly
using Poly ::poly;
C++ 复制 namespace flow
{
const int N= 200000 ,M= 2000000 ,inf=0x 3f3f3f3f ;
int s,t,cnt,fi[N],it[N],dep[N],q[N],hd,tl,ne[M],to[M],w[M];
void init (){cnt= 1 ,memset (fi,0 ,sizeof (fi));}
void ae (int a ,int b ,int c ){to[++ cnt]= b,w[cnt]= c,ne[cnt]= fi[a],fi[a]= cnt;}
void add (int a ,int b ,int c ){ae (a,b,c),ae (b,a,0 );}
bool bfs ()
{
memset (dep,0x 3f ,sizeof (dep)),memcpy (it,fi,sizeof (fi));
q[hd= tl= 1 ]= s,dep[s]= 0 ;
while (hd<= tl)
{
int u= q[hd++ ];
for (int i= fi[u];i;i= ne[i])if (w[i]&& dep[to[i]]== inf)
dep[to[i]]= dep[u]+ 1 ,q[++ tl]= to[i];
}
return dep[t]!= inf;
}
int dfs (int u ,int flow )
{
if (u== t)return flow;
int ret= 0 ;
for (int i= it[u];i&& flow;it[u]= i,i= ne[i])
if (w[i]&& dep[to[i]]== dep[u]+ 1 )
{
int k= dfs (to[i],min (flow,w[i]));
if (! k)dep[to[i]]= inf;
w[i]-= k,w[i^ 1 ]+= k,ret+= k,flow-= k;
}
return ret;
}
int dinic (int S ,int T )
{
s= S,t= T;
int ret= 0 ;
while (bfs ())ret+= dfs (s,inf);
return ret;
}
struct _ {_ (){init ();}}__;
}//namespace flow
C++ 复制 namespace flow
{
const int N= 5005 ,M= 100005 ;
const ll inf=0x 3f3f3f3f3f3f3f3f ;
int s,t,cnt,fi[N],it[N],ne[M],to[M],q[10000000 ],hd,tl;
bool inq[N];
ll w[M],v[M],dis[N];
void init (){cnt= 1 ,memset (fi,0 ,sizeof (fi));}
void ae (int a ,int b ,ll c ,ll d ){to[++ cnt]= b,w[cnt]= c,v[cnt]= d,ne[cnt]= fi[a],fi[a]= cnt;}
void add (int a ,int b ,ll c ,ll d ){ae (a,b,c,d),ae (b,a,0 ,- d);}
bool bfs ()
{
memset (dis,0x 3f ,sizeof (dis)),memcpy (it,fi,sizeof (fi));
q[hd= tl= 1 ]= s,dis[s]= 0 ,inq[s]= 1 ;
while (hd<= tl)
{
int u= q[hd++ ];inq[u]= 0 ;
for (int i= fi[u];i;i= ne[i])if (w[i]&& dis[to[i]]> dis[u]+ v[i])
dis[to[i]]= dis[u]+ v[i],! inq[to[i]]&& (inq[to[i]]= 1 ,q[++ tl]= to[i]);
}
return dis[t]!= inf;
}
struct dat {ll f,c;};
dat operator + (const dat & a ,const dat & b ){return {a.f+ b.f,a.c+ b.c};}
void operator += (dat & a ,const dat & b ){a.f+= b.f,a.c+= b.c;}
dat dfs (int u ,ll flow )
{
if (u== t)return {flow,0 };
inq[u]= 1 ;
dat res= {0 ,0 };
for (int i= it[u];i&& flow;it[u]= i,i= ne[i])
if (w[i]&&! inq[to[i]]&& dis[to[i]]== dis[u]+ v[i])
{
auto k= dfs (to[i],min (flow,w[i]));
if (! k.f)dis[to[i]]= inf;
w[i]-= k.f,w[i^ 1 ]+= k.f,res+= k,res.c+= k.f* v[i],flow-= k.f;
}
inq[u]= 0 ;
return res;
}
dat dinic (int S ,int T )
{
s= S,t= T;dat res= {0 ,0 };
while (bfs ())res+= dfs (s,inf);
return res;
}
struct _ {_ (){init ();}}__;
}//namespace flow
C++ 复制 struct vec {double x,y;};
vec operator + (const vec & a ,const vec & b ){return {a.x+ b.x,a.y+ b.y};}
vec operator - (const vec & a ,const vec & b ){return {a.x- b.x,a.y- b.y};}
double operator * (const vec & a ,const vec & b ){return a.x* b.x+ a.y* b.y;}
vec operator * (const vec & a ,double b ){return {a.x* b,a.y* b};}
vec operator * (double b ,const vec & a ){return {a.x* b,a.y* b};}
vec operator / (const vec & a ,double b ){return {a.x/ b,a.y/ b};}
double operator % (const vec & a ,const vec & b ){return a.x* b.y- a.y* b.x;}
double operator ! (const vec & a ){return sqrt (a.x* a.x+ a.y* a.y);}
vec operator ~ (const vec & a ){return {- a.y,a.x};}
double operator * (const vec & a ){return atan2 (a.y,a.x);}
bool isneg (const vec & a ){return a.y< 0 || a.y== 0 && a.x< 0 ;}
bool ispos (const vec & a ){return a.y> 0 || a.y== 0 && a.x> 0 ;}
struct li {vec p,d;};
vec operator * (const li & a ,const li & b ){return a.p+ (b.p- a.p)% b.d/ (a.d% b.d)* a.d;}
li operator | (const vec & a ,const vec & b ){return {(a+ b)/ 2 ,~ (b- a)};}
bool rgt (const li & a ,const vec & b ){return (b- a.p)% a.d>= 0 ;}
int quad (const vec & a ){return (a.y< 0 )* 2 | a.x< 0 ^ a.y< 0 ;}
struct polygon :vector <vec >
{
using vector <vec >::vector;
double area ()
{
double ret= 0 ;
for (int i= 0 ;i< size ();++ i)
ret+= (* this )[i]% (* this )[(i+ 1 )% size ()];
return ret/ 2 ;
}
};
polygon hpi (vector <li >a )
{
const double inf= 1 e 18 ;
static li q[100005 ];
static vec k[100005 ];
int hd= 1 ,tl= 0 ;
a.push_back ({{inf,inf},{- 1 ,0 }});
a.push_back ({{- inf,inf},{0 ,- 1 }});
a.push_back ({{- inf,- inf},{1 ,0 }});
a.push_back ({{inf,- inf},{0 ,1 }});
sort (a.begin (),a.end (),[& ](const li & a ,const li & b ){
int qa= quad (a.d),qb= quad (b.d);
if (qa!= qb)return qa< qb;
double d= a.d% b.d;
if (d)return d> 0 ;
return b.d% (a.p- b.p)> 0 ;
});
a.erase (unique (a.begin (),a.end (),[& ](const li & a ,const li & b ){
return quad (a.d)== quad (b.d)&& a.d% b.d== 0 ;
}),a.end ());
for (auto i:a)
{
while (hd< tl&& rgt (i,k[tl- 1 ]))-- tl;
while (hd< tl&& rgt (i,k[hd]))++ hd;
if (hd> tl|| i.d% q[tl].d!= 0 || i.d.x* q[tl].d.x< 0 || i.d.y* q[tl].d.y< 0 )q[++ tl]= i;
else if (rgt (i,q[tl].p))q[tl]= i;
if (hd< tl)k[tl- 1 ]= q[tl- 1 ]* q[tl];
}
while (hd< tl&& rgt (q[hd],k[tl- 1 ]))-- tl;
if (tl- hd<= 1 )return {};
k[tl]= q[tl]* q[hd];
return polygon (k+ hd,k+ tl+ 1 );
}
C++ 复制 typedef __uint128_t L;
struct FastMod {
ull b, m;
FastMod (ull b ) : b (b), m (ull ((L (1 ) << 64 ) / b)) {}
ull reduce (ull a ) {
ull q = (ull)((L (m) * a) >> 64 );
ull r = a - q * b; // can be proven that 0 <= r < 2*b
return r >= b ? r - b : r;
}
}F (1 );
C++ 复制 __int128 gcd (__int128 a ,__int128 b )
{
return b? gcd (b,a% b): a;
}
struct frac
{
__int128 fz,fm;
void yf ()
{
if (fm< 0 )fz=- fz,fm=- fm;
__int128 g= gcd (fz,fm);
fz/= g,fm/= g;
}
frac (int x = 0 ){fz= x,fm= 1 ;}
frac (__int128 x ,__int128 y ){fz= x,fm= y;}
void operator &= (const frac & a ){__int128 g= gcd (fm,a.fm);* this = {a.fm/ g* fz+ fm/ g* a.fz,fm/ g* a.fm};}
void operator += (const frac & a ){* this = {a.fm* fz+ fm* a.fz,fm* a.fm};}
void operator -= (const frac & a ){* this = {fz* a.fm- fm* a.fz,fm* a.fm};}
void operator *= (const frac & a ){* this = {fz* a.fz,fm* a.fm};}
void operator /= (const frac & a ){* this = a.fz> 0 ? frac (fz* a.fm,fm* a.fz): frac (- fz* a.fm,- fm* a.fz);}
frac operator & (const frac & a )const {frac c=* this ;c&= a;return c;}
frac operator + (const frac & a )const {frac c=* this ;c+= a;return c;}
frac operator - (const frac & a )const {frac c=* this ;c-= a;return c;}
frac operator * (const frac & a )const {frac c=* this ;c*= a;return c;}
frac operator / (const frac & a )const {frac c=* this ;c/= a;return c;}
frac operator - (){return {- fz,fm};}
bool operator < (frac a )const
{
frac b=* this ;if (b.fm< 0 )b.fz=- b.fz,b.fm=- b.fm;
if (a.fm< 0 )a.fz=- a.fz,a.fm=- a.fm;
return b.fz* a.fm< a.fz* b.fm;
}
bool operator <= (frac a )const
{
frac b=* this ;if (b.fm< 0 )b.fz=- b.fz,b.fm=- b.fm;
if (a.fm< 0 )a.fz=- a.fz,a.fm=- a.fm;
return b.fz* a.fm<= a.fz* b.fm;
}
bool operator > (frac a )const {return ! (* this <= a);}
bool operator >= (frac a )const {return ! (* this < a);}
bool operator < (int a )const {return * this < frac (a);}
bool operator <= (int a )const {return * this <= frac (a);}
bool operator == (const frac & a )const {return fz* a.fm== fm* a.fz;}
bool operator > (int a )const {return ! (* this <= a);}
bool operator >= (int a )const {return ! (* this < a);}
bool operator != (const frac & a )const {return ! (* this == a);}
double operator () ()const {return 1.0 * fz/ fm;}
void read (){ll x,y;scanf (" %lld%lld " ,& x,& y);fz= x,fm= y;}
};