pub use __cargo_equip::prelude::*; use minimal_lib_int::modulo::Mod1000000007; use minimal_lib_poly::poly::multipoint::factorial_large; use std::{fmt::Debug, io::BufRead, str::FromStr}; fn read(r: &mut impl BufRead, buf: &mut Vec, d: u8) -> T where ::Err: Debug, { buf.clear(); let _b = r.read_until(d, buf); std::str::from_utf8(buf) .unwrap() .trim() .parse::() .unwrap() } fn main() { use std::io::{stdin, stdout, BufReader, BufWriter, Write}; let si = stdin(); let mut sc = BufReader::new(si.lock()); let mut buf = Vec::with_capacity(1024); let so = stdout(); let mut stdout = BufWriter::new(so.lock()); let n: usize = read(&mut sc, &mut buf, b'\n'); stdout.write_fmt(format_args!("{}\n", factorial_large::(n))); stdout.flush(); } // The following code was expanded by `cargo-equip`. /// # Bundled libraries /// /// - `minimal-lib-algo 0.1.0 (path+██████████████████████████████████)` published in **missing** licensed under **missing** as `crate::__cargo_equip::crates::minimal_lib_algo` /// - `minimal-lib-int 0.2.0 (path+█████████████████████████████████)` published in **missing** licensed under **missing** as `crate::__cargo_equip::crates::minimal_lib_int` /// - `minimal-lib-poly 0.1.0 (path+██████████████████████████████████)` published in **missing** licensed under **missing** as `crate::__cargo_equip::crates::minimal_lib_poly` #[cfg_attr(any(), rustfmt::skip)] #[allow(unused)] mod __cargo_equip { pub(crate) mod crates { pub mod minimal_lib_algo {pub mod bisect{use std::ops::{Add,Shr};use std::cmp::PartialOrd;pub fn bisect_predicate_max(mut f:impl FnMut(T)->bool,l:T,r:T)->Optionwhere T:Add+Shr+PartialOrd+From+Copy,{let one=1.into();let mut unchanged=true;let mut l=l;let mut r=r+one;while(l+one)>one;if f(h){unchanged=false;l=h;}else{r=h;}}if unchanged&&!f(l){return None;}Some(l)}pub fn bisect_predicate_min(mut f:impl FnMut(T)->bool,l:T,r:T)->Optionwhere T:Add+Shr+PartialOrd+From+Copy,{let one=1.into();let mut unchanged=true;let mut l=l;let mut r=r;if!f(r){return None;}while(l+one)>one;if f(h){r=h;}else{unchanged=false;l=h;}}if unchanged&&f(l){return Some(l);}Some(r)}}pub mod compress{use std::{collections::{BTreeMap,HashMap},hash::Hash,};pub struct Compress{count:usize,vec:Vec,to_index:HashMap,}implCompress{pub fn new(it:&[T])->Compress{let mut count=0;let mut last=None;let mut to_index=HashMap::new();let mut vec=vec![];let mut s=it.to_vec();s.sort();for x in s.into_iter(){if let Some(y)=last.take(){if y==x{continue;}}to_index.insert(x.clone(),count);vec.push(x.clone());count+=1;last=Some(x);}Self{count,vec,to_index,}}pub fn is_empty(&self)->bool{self.count==0}pub fn len(&self)->usize{self.count}pub fn get_index(&self,value:T)->usize{self.to_index[&value]}pub fn invert(&self,index:usize)->T{self.vec[index].clone()}}#[derive(Debug)]pub struct SegmentCompress{count:usize,vec:Vec,to_index:BTreeMap,}implSegmentCompress{pub fn new<'a>(it:&[T])->Self{let mut count=0;let mut last=None;let mut to_index=BTreeMap::new();let mut vec=vec![];let mut s=it.to_vec();s.sort();for x in s.into_iter(){if let Some(y)=last.take(){if y==x{last=Some(y);continue;}}to_index.insert(x.clone(),count);vec.push(x.clone());count+=1;last=Some(x);}Self{count,vec,to_index,}}pub fn len(&self)->usize{self.count}pub fn get_index(&self,value:T)->usize{self.to_index[&value]}pub fn get_range(&self,left:T,right:T)->Option<(usize,usize)>{let mut rn=self.to_index.range(left.clone()..right.clone());let mut rn2=self.to_index.range(left..right);Some((*rn.next()?.1,*rn2.next_back()?.1))}pub fn invert(&self,index:usize)->T{self.vec[index].clone()}}}pub mod runlength{pub fn runlength(xs:&[T])->Vec<(T,usize)>where T:Eq+Clone,{let mut result=vec![];let mut run=1;let mut prev_index=0;for(index,item)in xs.iter().enumerate().skip(1){if item==&xs[prev_index]{run+=1;}else{result.push((xs[prev_index].clone(),run));prev_index=index;run=1;}}result.push((xs[prev_index].clone(),run));result}}pub mod uf{pub struct UnionFind{vec:Vec,component_size:Vec,}impl UnionFind{pub fn new(size:usize)->Self{let mut vec=Vec::new();let mut component_size=Vec::new();for i in 0..size{vec.push(i);component_size.push(1);}Self{vec,component_size,}}pub fn find_root(&mut self,a:usize)->usize{let mut a=a;let mut stack=Vec::new();loop{let parent=self.vec[a];if parent==a{for i in stack{self.vec[i]=a;}return a;}else{stack.push(a);a=parent;}}}pub fn union(&mut self,a:usize,b:usize){let a_root=self.find_root(a);let b_root=self.find_root(b);if a_root!=b_root{self.vec[a_root]=b_root;self.component_size[b_root]+=self.component_size[a_root];self.component_size[a_root]=0;}}pub fn is_unioned(&mut self,a:usize,b:usize)->bool{self.find_root(a)==self.find_root(b)}}pub trait Group:Default{fn mul(&self,rhs:&Self)->Self;fn inv(&self)->Self;}#[derive(Debug)]pub struct UnionFindWith{vec:Vec<(usize,T)>,component_size:Vec,}implUnionFindWith{pub fn new(size:usize)->Self{let mut vec=Vec::new();let mut component_size=Vec::new();for i in 0..size{vec.push((i,T::default()));component_size.push(1);}Self{vec,component_size,}}pub fn find_root(&mut self,a:usize)->(usize,T){let mut a=a;let mut accum=T::default();let mut stack:Vec<(usize,T)> =Vec::new();loop{let(parent,g)=&self.vec[a];if*parent==a{stack.push((a,accum));let root_accum=accum;for(i,g)in stack.into_iter(){let nx=accum.mul(&g.inv());self.vec[i]=(a,nx);}return(a,root_accum);}else{stack.push((a,accum));accum=accum.mul(g);a=*parent;}}}pub fn union(&mut self,a:usize,b:usize,g:T){let(a_root,ga)=self.find_root(a);let(b_root,gb)=self.find_root(b);if a_root!=b_root{self.vec[a_root]=(b_root,g.mul(&gb.mul(&ga.inv())));self.component_size[b_root]+=self.component_size[a_root];self.component_size[a_root]=0;}}pub fn is_unioned(&mut self,a:usize,b:usize)->Option{let(ra,ga)=self.find_root(a);let(rb,gb)=self.find_root(b);if ra==rb{Some(ga.mul(&gb.inv()))}else{None}}}}pub mod monotone_minima{pub struct MonotoneMinima<'a,T:Ord>{rows:usize,columns:usize,func:BoxT>}impl<'a,T:Ord>MonotoneMinima<'a,T>{pub fn new(rows:usize,columns:usize,func:BoxT>)->Self{Self{rows,columns,func}}fn minima_recur(&self,result:&mut[usize],yl:usize,yr:usize,xl:usize,xr:usize){if yl==yr{return;}let mid=(yl+yr)/2;let mut pos=xl;let mut minimum_value=(self.func)(mid,xl);for i in(xl+1)..xr{let v=(self.func)(mid,i);if vVec{let mut result=vec![0;self.rows];self.minima_recur(&mut result,0,self.rows,0,self.columns);result}}}pub mod interval_set{use std::collections::BTreeMap;#[derive(Debug,Clone,Default)]pub struct IntervalSetwhere T:Ord+Copy{s:BTreeMap,}implIntervalSetwhere T:Ord+Copy{pub fn new()->Self{Self{s:BTreeMap::new()}}pub fn get(&self,x:T)->Option<(T,T)>{use std::ops::Bound::*;self.s.range((Unbounded,Included(x))).next_back().filter(|&(_l,r)|x<*r).map(|(x,y)|(*x,*y))}pub fn insert(&mut self,l:T,r:T){use std::ops::Bound::*;let(l,r)=if let Some((il,ir))=self.s.range_mut((Unbounded,Included(l))).next_back(){if l<=*ir{if*irVec<(T,T)>{self.s.iter().map(|(x,y)|(*x,*y)).collect()}pub fn intersect(&mut self,l:T,r:T){use std::ops::Bound::*;while let Some((il,ir))=self.s.range((Unbounded,Excluded(l))).next(){let il=*il;let ir=*ir;self.s.remove(&il);if lVec{let n=perm.len();let mut res=vec![0;n];for i in 0..n{res[perm[i]]=i;}res}pub fn composite_permutation(first:&[usize],second:&[usize])->Vec{debug_assert_eq!(first.len(),second.len());let n=first.len();let mut res=vec![0;n];for i in 0..n{res[i]=second[first[i]];}res}}pub mod trisect{use std::cmp::PartialOrd;use std::ops::{Add,Div,Sub};pub fn trisect_predicate_min(mut f:impl FnMut(T)->S,l:T,r:T)->(T,S)where T:Add+Sub+Div+PartialOrd+From+Copy+From+std::fmt::Debug,S:Ord+Clone,{let one=1.into();let two=2.into();let three:T=3.into();let mut l=l;let mut r=r+one;while(l+two){r=h2;}std::cmp::Ordering::Equal=>{l=h1;r=h2;}std::cmp::Ordering::Greater=>{l=h1;}}}let mut c=vec![];while l,pub inv:Vec,pub accum_inv:Vec,pub n:usize,pub p:i64,}impl MulCache{pub fn new(p:i64,n:usize)->Self{let mut accum=vec![0;n];let mut inv=vec![0;n];let mut accum_inv=vec![0;n];accum[0]=1;accum[1]=1;inv[0]=0;inv[1]=1;accum_inv[0]=1;accum_inv[1]=1;for i in 2..n{let i=i as i64;accum[i as usize]=(accum[(i-1)as usize]*i)%p;inv[i as usize]=p-inv[(p%i)as usize]*(p/i)%p;accum_inv[i as usize]=(accum_inv[(i-1)as usize]*inv[i as usize])%p;}Self{accum,inv,accum_inv,n,p,}}pub fn extend(&mut self,n:usize){if self.ni64{self.accum_inv[n as usize]}pub fn combin(&self,n:i64,k:i64)->i64{debug_assert!(n,pub sum_ie:Vec,pub montg_r:i64,pub montg_r1:i64,pub montg_r2:i64,pub montg_r3:i64,pub montg_rinv:i64,pub montg_ndash:i64,}impl FFTCache{fn primitive_root(m:i64)->i64{match m{2=>1,167772161=>3,469762049=>3,595591169=>3,645922817=>3,897581057=>3,998244353=>3,754974721=>11,_=>todo!(),}}pub fn new(m:i64)->Self{let primroot=Self::primitive_root(m);let mut es=vec![0;30];let mut ies=vec![0;30];let cnt2=(m-1).trailing_zeros()as usize;let mut e=powmod(primroot,(m-1)>>cnt2,m);let mut ie=modinv(e,m);for i in(2..=cnt2).rev(){es[i-2]=e;ies[i-2]=ie;e*=e;e%=m;ie*=ie;ie%=m;}let sum_e:Vec =es.iter().scan(1,|acc,e|{*acc*=e;*acc%=m;Some(*acc)}).collect();let sum_ie:Vec =ies.iter().scan(1,|acc,ie|{*acc*=ie;*acc%=m;Some(*acc)}).collect();let rex=minimum_exponent(m);let montg_r=1<>=1;}}debug_assert_eq!((m*montg_ndash)%montg_r,montg_r-1);Self{modulo:m,g:primroot,sum_e,sum_ie,montg_r,montg_r1,montg_r2,montg_r3,montg_rinv,montg_ndash,}}}}pub use mul::MulCache;pub use fft::FFTCache;}pub mod utils{use crate::__cargo_equip::preludes::minimal_lib_int::*;mod gcd{use crate::__cargo_equip::preludes::minimal_lib_int::*;pub fn gcd(a:i64,b:i64)->i64{let t=(a|b).trailing_zeros();let mut a=a;let mut b=b;a>>=t;b>>=t;if a&1==1{std::mem::swap(&mut a,&mut b);}a>>=a.trailing_zeros();while a!=b{if a>b{a-=b;a>>=a.trailing_zeros();}else{b-=a;b>>=b.trailing_zeros();}}a<i64{if b==2{return a;}let m=b;let mut a=a;let mut b=b;let mut u=1;let mut v=0;while a>0{if a&1==0{a>>=1;if u&1==0{u>>=1;}else{u+=m;u>>=1;}}else{if a>1;u-=v;if u<0{u+=m;}if u&1==0{u>>=1;}else{u+=m;u>>=1;}}}assert_eq!(b,1);v}pub fn modinv_u64(a:u64,b:u64)->u64{if b==2{return a;}let m=b;let mut a=a;let mut b=b;let mut u=1;let mut v=0;while a>0{if a&1==0{a>>=1;if u&1==0{u>>=1;}else{u+=m;u>>=1;}}else{if a>1;if u>=1;}else{u+=m;u>>=1;}}}assert_eq!(b,1);v}}mod modulo{use crate::__cargo_equip::preludes::minimal_lib_int::*;use super::gcd::modinv;pub fn powmod_large(val:i64,rhs:i64,m:i64)->i64{if rhs<0{todo!()}let mut res=1_i128;let mut r=rhs as i128;let mut a=val as i128;let m=m as i128;while r>0{if r&1==1{res*=a;res%=m;}a*=a;a%=m;r>>=1;}res as i64}pub fn powmod(val:i64,rhs:i64,m:i64)->i64{if rhs<0{return modinv(powmod(val,-rhs,m),m);}let mut res=1;let mut r=rhs;let mut a=val;while r>0{if r&1==1{res*=a;res%=m;}a*=a;a%=m;r>>=1;}res}pub fn sqrt_mod(y:i64,p:i64)->Option{let y=y%p;if p==2{return Some(y);}if y==0{return Some(0);}let q=p-1;let m=q.trailing_zeros();let q=q>>m;if powmod(y,q<<(m-1),p)==p-1{return None;}let mut z=2;while powmod(z,q<<(m-1),p)!=p-1{z+=1;}let mut t=powmod(y,q,p);let mut x=powmod(y,(q+1)>>1,p);let mut u=powmod(z,q,p);if m>=2{for i in(0..=(m-2)).rev(){if powmod(t,1<p-x{x=p-x;}Some(x)}}mod util{use crate::__cargo_equip::preludes::minimal_lib_int::*;use minimal_lib_algo::bisect::bisect_predicate_max;pub fn isqrt(x:i64)->i64{bisect_predicate_max(|y|y*y<=x,0,x.min(1<<31)).unwrap()}pub fn i_kth_root(x:i64,k:i64)->i64{if x<=1{return x;}if k==1{return x;}let bs=63-x.leading_zeros();bisect_predicate_max(|y|{y.checked_pow(k as u32).map(|yk|yk<=x).unwrap_or_default()},1,x>>(bs-bs/k as u32-1),).unwrap()as _}pub fn digits(x:i64,base:i64)->Vec{if x==0{return vec![0];}let mut res=vec![];let mut t=x;while t>0{res.push(t%base);t/=base;}res.reverse();res}pub fn minimum_exponent(n:i64)->usize{(64-n.saturating_sub(1).leading_zeros())as _}}mod prelude{use crate::__cargo_equip::preludes::minimal_lib_int::*;pub use super::gcd::{modinv,modinv_u64,gcd};pub use super::modulo::{powmod,powmod_large,sqrt_mod};pub use super::util::{digits,i_kth_root,isqrt,minimum_exponent};pub use super::gerner::{gerner,gerner_u64,gerner_batch};}mod gerner{use crate::__cargo_equip::preludes::minimal_lib_int::*;use crate::__cargo_equip::crates::minimal_lib_int::utils::modinv;fn ex_euclid(a:i64,b:i64)->(i64,i64,i64){let mut a=a;let mut b=b;let mut c=1;let mut d=0;let mut e=0;let mut f=1;while a!=0{let q=b/a;let res=(b%a,a,d,c-d*q,f,e-f*q);a=res.0;b=res.1;c=res.2;d=res.3;e=res.4;f=res.5;}if b<0{e=-e;c=-c;b=-b;}(e,c,b)}fn modular_div(n:i64,m:i64,p:i64)->Option{let(e,_c,b)=ex_euclid(m,p);if n%b!=0{None}else{let q=(n/b)*e;let mut q=q%p;if q<0{q+=p;}Some(q)}}pub fn gerner(r:&[i64],m:&[i64],mm:i64)->Option{debug_assert_eq!(r.len(),m.len());let l=m.len();let mut cons=vec![0;l];let mut coeff=vec![1;l];let mut res=0;let mut r_coeff=1;for i in 0..l{let mut v=modular_div(r[i]-cons[i],coeff[i],m[i])?;if v<0{v+=m[i];}for j in i+1..l{cons[j]+=v*coeff[j];cons[j]%=m[j];coeff[j]*=m[i];coeff[j]%=m[j];}res=(res+v*r_coeff)%mm;r_coeff=(r_coeff*m[i])%mm;}Some(res)}pub fn gerner_batch(r:&[Vec],m:&[i64],mm:i64)->Vec{debug_assert_eq!(r.len(),m.len());let rl=r[0].len();let l=m.len();let mut cons=vec![vec![0i64;rl];l];let mut coeff=vec![1;l];let mut res=vec![0i64;rl];let mut r_coeff=1;for i in 0..l{let d=modinv(coeff[i],m[i]);let v:Vec =r[i].iter().zip(cons[i].iter()).map(|(&x,&c)|{let mut v=(x-c)*d;v%=m[i];if v<0{v+=m[i];}v}).collect();for j in i+1..l{cons[j].iter_mut().zip(v.iter()).for_each(|(c,&v)|{*c+=v*coeff[j];*c%=m[j];});coeff[j]*=m[i];coeff[j]%=m[j];}res.iter_mut().zip(v.iter()).for_each(|(r,&v)|{*r+=v*r_coeff;*r%=mm;});r_coeff=(r_coeff*m[i])%mm;}res}pub fn gerner_u64(r:&[u64])->u64{debug_assert!(r.len()<=5);let mut cons=[0;5];let m=[469762049,595591169,645922817,897581057,998244353];let coeff=[[1,1,1,1,1],[1,469762049,469762049,469762049,469762049],[1,469762049,44993443,300657119,491473740],[1,469762049,44993443,528892613,173461320],[1,469762049,44993443,528892613,202041274],];let coeff_inv=[1,436766862,35884648,19245542,390741676];let mut res:u64=0;let mut r_coeff:u64=1;for i in 0..r.len(){let mut v=if r[i]+Sub+Neg+Mul+Div{fn pow(self,rhs:i64)->Self;fn inv(self)->Self;fn zero()->Self;fn one()->Self;}pub trait Modulus:'static+Copy+Eq+Ord{const IS_PRIME:bool=false;fn mul_cache()->&'static LocalKey>;fn convolution(x:&[ModInt],y:&[ModInt])->Vec>;fn get_modulo()->i64;fn extend(n:usize){Self::mul_cache().with(|cache|cache.borrow_mut().extend(n));}}pub trait FFTModulus:Modulus{const EXP:usize;fn fft_cache()->&'static LocalKey>;}pub type ModInt998244353=ModInt;pub type ModInt1000000007=ModInt;#[derive(Copy,Clone,Eq,PartialEq,PartialOrd,Ord)]#[repr(transparent)]pub struct ModInt{pub v:i64,ph:PhantomDataT>}implstd::fmt::Debug for ModInt{fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{f.write_fmt(format_args!("{}",self.v))}}implstd::fmt::Display for ModInt{fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{f.write_fmt(format_args!("{}",self.v))}}implModInt{pub fn pow(self,rhs:i64)->Self{Self::new(powmod(self.v,rhs,T::get_modulo()))}pub fn inv(self)->Self{Self::new(modinv(self.v,T::get_modulo()))}pub fn zero()->Self{Self::new(0)}pub fn one()->Self{Self::new(1)}pub fn fact(n:usize)->Self{T::mul_cache().with(|cache|{let cache=cache.borrow();let accum=&cache.accum;Self::from(accum[n])})}pub fn combin(n:usize,k:usize)->Self{T::mul_cache().with(|cache|{let cache=cache.borrow();Self::from(cache.combin(n as i64,k as i64))})}pub fn factinv(n:usize)->Self{T::mul_cache().with(|cache|{let cache=cache.borrow();let accum_inv=&cache.accum_inv;Self::from(accum_inv[n])})}}implField for ModInt{fn pow(self,rhs:i64)->Self{Self::new(powmod(self.v,rhs,T::get_modulo()))}fn inv(self)->Self{Self::new(modinv(self.v,T::get_modulo()))}fn zero()->Self{Self::new(0)}fn one()->Self{Self::new(1)}}implAsRef>for ModInt{fn as_ref(&self)->&ModInt{self}}implDefault for ModInt{fn default()->Self{Self{v:0,ph:Default::default()}}}implAddfor ModInt{type Output=Self;fn add(self,rhs:Self)->Self::Output{let r=self.v+rhs.v;if r>=T::get_modulo(){Self::new(r-T::get_modulo())}else{Self::new(r)}}}implSubfor ModInt{type Output=Self;fn sub(self,rhs:Self)->Self::Output{let r=self.v-rhs.v;if r<0{Self::new(r+T::get_modulo())}else{Self::new(r)}}}implMulfor ModInt{type Output=Self;fn mul(self,rhs:Self)->Self::Output{Self::new(self.v*rhs.v%T::get_modulo())}}implDivfor ModInt{type Output=Self;fn div(self,rhs:Self)->Self::Output{self*rhs.inv()}}implNeg for ModInt{type Output=Self;fn neg(self)->Self{Self::new(if self.v!=0{T::get_modulo()-self.v}else{0})}}implstd::iter::Sum for ModInt{fn sum>(iter:I)->Self{let mut acc=0;for x in iter.into_iter(){acc+=x.v;}acc%=T::get_modulo();Self::new(acc)}}implAddAssign for ModInt{fn add_assign(&mut self,rhs:Self){self.v+=rhs.v;if self.v>=T::get_modulo(){self.v-=T::get_modulo();}}}implSubAssign for ModInt{fn sub_assign(&mut self,rhs:Self){self.v-=rhs.v;if self.v<0{self.v+=T::get_modulo();}}}implMulAssign for ModInt{fn mul_assign(&mut self,rhs:Self){self.v*=rhs.v;self.v%=T::get_modulo();}}implDivAssign for ModInt{fn div_assign(&mut self,rhs:Self){self.v*=rhs.inv().v;self.v%=T::get_modulo();}}implModInt{pub fn new(v:i64)->Self{debug_assert!(0<=v&&vFromfor ModInt{fn from(x:i32)->Self{let x=x as _;if x<0{ModInt::new(x%T::get_modulo()+T::get_modulo())}else if xFromfor ModInt{fn from(x:i64)->Self{if x<0{ModInt::new(x%T::get_modulo()+T::get_modulo())}else if xFromfor ModInt{fn from(x:usize)->Self{if(x as i64)From>for i64{fn from(x:ModInt)->Self{x.v}}implFrom>for usize{fn from(x:ModInt)->Self{x.v as _}}implFrom>for i32{fn from(x:ModInt)->Self{x.v as _}}}mod modulos{use crate::__cargo_equip::preludes::minimal_lib_int::*;use std::{thread::LocalKey,cell::RefCell};use crate::__cargo_equip::crates::minimal_lib_int::{cache::{FFTCache,MulCache},fft::{modint_fft::convol,convol_u64::convol_modint}};use super::{FFTModulus,ModInt,Modulus};macro_rules!gen_static_modulo{($x:ident,$modulo:literal,$fft_exp:literal)=>{#[derive(Debug,Copy,Clone,Ord,PartialOrd,Eq,PartialEq)]pub enum$x{}impl$x{thread_local!{static MUL_CACHE:RefCell =RefCell::new(MulCache::new($modulo,1000005));static FFT_CACHE:RefCell =RefCell::new(FFTCache::new($modulo));}}impl FFTModulus for$x{const EXP:usize=$fft_exp;fn fft_cache()->&'static LocalKey>{&Self::FFT_CACHE}}impl Modulus for$x{fn get_modulo()->i64{$modulo}const IS_PRIME:bool=true;fn mul_cache()->&'static LocalKey>{&Self::MUL_CACHE}fn convolution(x:&[ModInt],y:&[ModInt])->Vec>{convol(x,y)}}};($x:ident,$modulo:literal)=>{#[derive(Debug,Copy,Clone,Ord,PartialOrd,Eq,PartialEq)]pub enum$x{}impl$x{thread_local!{static MUL_CACHE:RefCell =RefCell::new(MulCache::new($modulo,1000005));}}impl Modulus for$x{fn get_modulo()->i64{$modulo}const IS_PRIME:bool=true;fn mul_cache()->&'static LocalKey>{&Self::MUL_CACHE}fn convolution(x:&[ModInt],y:&[ModInt])->Vec>{convol_modint(&x,&y)}}};}gen_static_modulo!{Mod469762049,469762049_i64,26}gen_static_modulo!{Mod595591169,595591169_i64,23}gen_static_modulo!{Mod645922817,645922817_i64,23}gen_static_modulo!{Mod998244353,998244353_i64,23}gen_static_modulo!{Mod1000000007,1000000007_i64}#[derive(Debug,Copy,Clone,Ord,PartialOrd,Eq,PartialEq)]pub enum ModDynamic{}impl ModDynamic{thread_local!{static DYNAMIC_MODULO:RefCell =RefCell::new(1000000007);static MUL_CACHE:RefCell =RefCell::new(MulCache::new(1000000007_i64,5));}pub fn set_modulo(new_modulo:i64){Self::DYNAMIC_MODULO.with(|x|{*x.borrow_mut()=new_modulo;});Self::MUL_CACHE.with(|x|{*x.borrow_mut()=MulCache::new(new_modulo,5);});}}impl Modulus for ModDynamic{fn get_modulo()->i64{Self::DYNAMIC_MODULO.with(|x|{let x=*x.borrow();x})}const IS_PRIME:bool=true;fn mul_cache()->&'static LocalKey>{&Self::MUL_CACHE}fn convolution(x:&[ModInt],y:&[ModInt])->Vec>{convol_modint(x,y)}}}pub use modulo_v2::{FFTModulus,Field,ModInt,Modulus};pub use modulos::{Mod1000000007,Mod998244353,Mod469762049,Mod595591169,Mod645922817,ModDynamic};}pub mod fft{use crate::__cargo_equip::preludes::minimal_lib_int::*;pub mod modint_fft{use crate::__cargo_equip::preludes::minimal_lib_int::*;use crate::__cargo_equip::crates::minimal_lib_int::{modulo::{ModInt,FFTModulus},utils::minimum_exponent,};pub fn fft(v:&mut[ModInt]){let n=v.len();let h=64-n.saturating_sub(1).leading_zeros();T::fft_cache().with(|cache|{let cache=cache.borrow();let sum_e=&cache.sum_e;for ph in 1..=h{let w=1<<(ph-1);let p=1<<(h-ph);let mut now=ModInt::one();for s in 0..w{let offset=s<<(h-ph+1);for i in offset..(p+offset){let l=v[i];let r=v[i+p]*now;v[i]=l+r;v[i+p]=l-r;}now*=ModInt::new(sum_e[(!s).trailing_zeros()as usize]);}}});}pub fn ifft(v:&mut[ModInt]){let n=v.len();let h=64-n.saturating_sub(1).leading_zeros();T::fft_cache().with(|cache|{let cache=cache.borrow();let sum_ie=&cache.sum_ie;for ph in(1..=h).rev(){let w=1<<(ph-1);let p=1<<(h-ph);let mut inow=ModInt::one();for s in 0..w{let offset=s<<(h-ph+1);for i in 0..p{let l=v[i+offset];let r=v[i+offset+p];v[i+offset]=l+r;v[i+offset+p]=(l-r)*inow;}inow*=ModInt::new(sum_ie[(!s).trailing_zeros()as usize]);}}});}pub fn convol(x:&[ModInt],y:&[ModInt])->Vec>{if x.is_empty()||y.is_empty(){return vec![];}let(xl,yl)=(x.len(),y.len());if std::cmp::min(xl,yl)<=60{let(xl,yl,a,b)=if xl(x:&mut[ModInt],y:&[ModInt]){if x.is_empty()||y.is_empty(){return;}let(xl,yl)=(x.len(),y.len());if std::cmp::min(xl,yl)<=60{let mut ans=vec![ModInt::zero();xl];for i in 0..xl{for j in 0..yl{if i+j>=xl{break;}ans[i+j]+=x[i]*y[j];}}x.clone_from_slice(&ans[0..xl]);return;}let mut y=y.to_owned();fft(x);fft(&mut y);for i in 0..xl{x[i]*=y[i];}ifft(x);let iz=ModInt::from(xl as i64).inv();for i in 0..xl{x[i]*=iz;}}}pub mod relax_mult{use crate::__cargo_equip::preludes::minimal_lib_int::*;use crate::__cargo_equip::crates::minimal_lib_int::modulo::{ModInt,Modulus};use std::collections::VecDeque;const BITS:usize=64;pub struct RelaxedMul{index:usize,left:Vec>,right:Vec>,convolved:Vec>>>,}implRelaxedMul{pub fn new()->Self{RelaxedMul{index:0,left:Vec::new(),right:Vec::new(),convolved:vec![VecDeque::new();32],}}fn block_conv(&self,left:usize,right:usize,block_size:usize)->Vec>{let l=&self.left[left..left+block_size];let r=&self.right[right..right+block_size];T::convolution(l,r)}pub fn push(&mut self,left:ModInt,right:ModInt)->ModInt{let mut block_type=(self.index+2)&(self.index+2).wrapping_neg();let index=self.index;self.left.push(left);self.right.push(right);if block_type>self.index{block_type>>=1;if block_type>1{for i in 1..BITS{let block_size=(1<=block_type{let block_min=block_size-1;let b=self.block_conv(block_min,block_min,block_size);self.convolved[i].push_back(b);break;}let block_min1=self.index+1-block_size;let block_min2=block_size-1;let b1=self.block_conv(block_min1,block_min2,block_size);let b2=self.block_conv(block_min2,block_min1,block_size);self.convolved[i].push_back(b1);self.convolved[i].push_back(b2);}}}else if block_type>1{for i in 1..BITS{let block_size=(1<block_type{break;}let block_min1=self.index+1-block_size;let block_min2=block_size-1;let b1=self.block_conv(block_min1,block_min2,block_size);let b2=self.block_conv(block_min2,block_min1,block_size);self.convolved[i].push_back(b1);self.convolved[i].push_back(b2);}}let mut sum=if index>0{left*self.right[0]+right*self.left[0]}else{left*right};for i in 1..BITS{while self.convolved[i].len()>4{self.convolved[i].pop_front();}let q=(index+2)%(1<{break;}1=>{sum+=self.convolved[i][0][q];}3=>{if q<(1<{if q<(1<todo!(),}}self.index+=1;sum}}}pub mod convol_u64{use crate::__cargo_equip::preludes::minimal_lib_int::*;use crate::__cargo_equip::crates::minimal_lib_int::fft::modint_fft::convol;use crate::__cargo_equip::crates::minimal_lib_int::modulo::{ModInt,Modulus,Mod469762049,Mod595591169,Mod645922817};use crate::__cargo_equip::crates::minimal_lib_int::{cache::FFTCache,utils::modinv_u64,utils::minimum_exponent,};use crate::__cargo_equip::crates::minimal_lib_int::utils::{gerner_u64,gerner,gerner_batch};pub fn fft_mod_u64(v:&mut[u64],cache:&FFTCache){let n=v.len();let h=64-n.saturating_sub(1).leading_zeros();let FFTCache{sum_e,modulo,..}=cache;let modulo=*modulo as u64;for ph in 1..=h{let w=1<<(ph-1);let p=1<<(h-ph);let mut now=1;for s in 0..w{let offset=s<<(h-ph+1);for i in offset..(p+offset){let l=v[i];let mut r=v[i+p]*now;r%=modulo;v[i]=(l+r)%modulo;if l>r{v[i+p]=l-r;}else{v[i+p]=(l+(modulo-r))%modulo;}}now*=sum_e[(!s).trailing_zeros()as usize]as u64;now%=modulo;}}}pub fn ifft_mod_u64(v:&mut[u64],cache:&FFTCache){let n=v.len();let h=64-n.saturating_sub(1).leading_zeros();let FFTCache{sum_ie,modulo,..}=cache;let modulo=*modulo as u64;for ph in(1..=h).rev(){let w=1<<(ph-1);let p=1<<(h-ph);let mut inow=1;for s in 0..w{let offset=s<<(h-ph+1);for i in 0..p{let l=v[i+offset];let r=v[i+offset+p];v[i+offset]=(l+r)%modulo;let q=if l>r{l-r}else{(l+(modulo-r))%modulo};v[i+offset+p]=(q*inow)%modulo;}inow*=sum_ie[(!s).trailing_zeros()as usize]as u64;inow%=modulo;}}}pub fn convol_mod(x:&[u64],y:&[u64],cache:&FFTCache)->Vec{if x.is_empty()||y.is_empty(){return vec![];}let(xl,yl)=(x.len(),y.len());let zl:usize=xl+yl-1;let(mut x,mut y)=(x.to_owned(),y.to_owned());let z=1< =Box::new([FFTCache::new(469762049),FFTCache::new(595591169),FFTCache::new(645922817),FFTCache::new(897581057),FFTCache::new(998244353)]);}pub fn convol_u64(x:&[u64],y:&[u64])->Vec{let(xl,yl)=(x.len(),y.len());if std::cmp::min(xl,yl)<=60{let(xl,yl,a,b)=if xl =vec![0;xl+yl-1];for i in 0..xl{for j in 0..yl{ans[i+j]=ans[i+j].wrapping_add(a[i].wrapping_mul(b[j]));}}return ans;}MODULO_CACHES.with(|cc|{let[c1,c2,c3,c4,c5]=cc.as_ref();let z1=convol_mod(x,y,c1);let z2=convol_mod(x,y,c2);let z3=convol_mod(x,y,c3);let z4=convol_mod(x,y,c4);let z5=convol_mod(x,y,c5);let mut result=vec![];for i in 0..z1.len(){result.push(gerner_u64(&[z1[i],z2[i],z3[i],z4[i],z5[i]]))}result})}pub fn convol_u32(x:&[u64],y:&[u64])->Vec{let(xl,yl)=(x.len(),y.len());if std::cmp::min(xl,yl)<=60{let(xl,yl,a,b)=if xl =vec![0;xl+yl-1];for i in 0..xl{for j in 0..yl{ans[i+j]=ans[i+j].wrapping_add(a[i].wrapping_mul(b[j]));}}return ans;}MODULO_CACHES.with(|cc|{let[c1,c2,c3,_c4,_c5]=cc.as_ref();let z1=convol_mod(x,y,c1);let z2=convol_mod(x,y,c2);let z3=convol_mod(x,y,c3);let mut result=vec![];let m=[c1.modulo,c2.modulo,c3.modulo];for i in 0..z1.len(){result.push(gerner(&[z1[i]as i64,z2[i]as i64,z3[i]as i64],&m,1000000007).unwrap()as u64)}result})}pub fn convol_modint(x:&[ModInt],y:&[ModInt])->Vec>{let(xl,yl)=(x.len(),y.len());if std::cmp::min(xl,yl)<=60{let(xl,yl,a,b)=if xl =vec![ModInt::zero();xl+yl-1];for i in 0..xl{for j in 0..yl{ans[i+j]+=a[i]*b[j];}}return ans;}MODULO_CACHES.with(|cc|{let[c1,c2,c3,_c4,_c5]=cc.as_ref();let z1:Vec ={let x:Vec> =x.iter().map(|&i|i64::from(i).into()).collect();let y:Vec> =y.iter().map(|&i|i64::from(i).into()).collect();convol(&x,&y).into_iter().map(|x|x.v).collect()};let z2:Vec ={let x:Vec> =x.iter().map(|&i|i64::from(i).into()).collect();let y:Vec> =y.iter().map(|&i|i64::from(i).into()).collect();convol(&x,&y).into_iter().map(|x|x.v).collect()};let z3:Vec ={let x:Vec> =x.iter().map(|&i|i64::from(i).into()).collect();let y:Vec> =y.iter().map(|&i|i64::from(i).into()).collect();convol(&x,&y).into_iter().map(|x|x.v).collect()};let m=[c1.modulo,c2.modulo,c3.modulo];let r=gerner_batch(&[z1,z2,z3],&m,T::get_modulo()).into_iter().map(|x|x.into()).collect();r})}}pub mod subset_convolution{use crate::__cargo_equip::preludes::minimal_lib_int::*;use std::ops::{AddAssign,SubAssign,MulAssign,Mul};pub fn lower_moebius(v:&mut[T]){let n=v.len();let h=n.trailing_zeros();for j in 0..h{let p=1<=p{if i&p>0{v[i]-=v[i^p];i-=1;}else{i-=p;}}}}pub fn lower_zeta(v:&mut[T]){let n=v.len();let h=n.trailing_zeros();for j in 0..h{let p=1<(v:&mut[T]){let n=v.len();let h=n.trailing_zeros();for j in 0..h{let p=1<=p{if i&p>0{v[i^p]+=v[i];i-=1;}else{i-=p;}}}}pub fn upper_moebius(v:&mut[T]){let n=v.len();let h=n.trailing_zeros();for j in 0..h{let p=1<+Default+Copy>(n:usize,a:&[T],b:&[T])->Vec{let mut rank_a=vec![vec![Default::default();1<(v:&mut[ModInt]){let n=v.len();let mut s=vec![false;n];for i in 2..n{if!s[i]{for(j,k)in(0..n).step_by(i).enumerate().skip(1){s[k]=true;v[k]+=v[j];}}}}pub fn lower_divisor_moebius(v:&mut[ModInt]){let n=v.len();let mut s=vec![false;n];for i in 2..n{if!s[i]{for(j,k)in(0..n).step_by(i).enumerate().skip(1).rev(){s[k]=true;v[k]-=v[j];}}}}pub fn upper_divisor_zeta(v:&mut[ModInt]){let n=v.len();let mut s=vec![false;n];for i in 2..n{if!s[i]{for(j,k)in(0..n).step_by(i).enumerate().skip(1).rev(){s[k]=true;v[j]+=v[k];}}}}pub fn upper_divisor_moebius(v:&mut[ModInt]){let n=v.len();let mut s=vec![false;n];for i in 2..n{if!s[i]{for(j,k)in(0..n).step_by(i).enumerate().skip(1){s[k]=true;v[j]-=v[k];}}}}}}} pub mod minimal_lib_poly {use crate::__cargo_equip::preludes::minimal_lib_poly::*;pub mod misc{use crate::__cargo_equip::preludes::minimal_lib_poly::*;pub trait Composite{type Output;fn composite(&self,rhs:Rhs)->Self::Output;}}pub mod poly{use crate::__cargo_equip::preludes::minimal_lib_poly::*;pub mod boston_mori{use crate::__cargo_equip::preludes::minimal_lib_poly::*;use minimal_lib_int::modulo::{ModInt,Modulus};use super::Polynomial;fn altarnate(p:&Polynomial)->Polynomial{let mut pr:Polynomial =p.clone();for x in pr.v.iter_mut().skip(1).step_by(2){*x=-*x;}pr}pub(in crate::__cargo_equip::crates::minimal_lib_poly)fn even(p:&mut Polynomial){let n=p.n;for(j,i)in(0..=n).step_by(2).enumerate(){p.v[j]=p.v[i];}p.v.truncate(n/2+1);p.n=p.v.len()-1;}pub(in crate::__cargo_equip::crates::minimal_lib_poly)fn odd(p:&mut Polynomial){let n=p.n;for(j,i)in(1..=n).step_by(2).enumerate(){p.v[j]=p.v[i];}p.v.truncate((n+1)/2);p.n=p.v.len()-1;}pub fn boston_mori(p:&Polynomial,q:&Polynomial,n:usize)->ModInt{if n==0{return p.v[0]/q.v[0];}let aq=altarnate(q);let mut v=q*&aq;even(&mut v);let mut u=p*&aq;if(n&1)==0{even(&mut u)}else{odd(&mut u)};boston_mori(&u,&v,n>>1)}}pub mod gcd{use crate::__cargo_equip::preludes::minimal_lib_poly::*;use super::Polynomial;use minimal_lib_int::modulo::{ModInt,Modulus};pub fn ex_euclid(a:i64,b:i64)->(i64,i64,i64){let mut a=a;let mut b=b;let mut c=1;let mut d=0;let mut e=0;let mut f=1;while a!=0{let q=b/a;let res=(b%a,a,d,c-d*q,f,e-f*q);a=res.0;b=res.1;c=res.2;d=res.3;e=res.4;f=res.5;}if b<0{e=-e;c=-c;b=-b;}(e,c,b)}#[derive(Debug)]struct GCDMatrix{a:Polynomial,b:Polynomial,c:Polynomial,d:Polynomial,}implGCDMatrix{fn new()->Self{Self{a:Polynomial::one(),b:Polynomial::zero(),c:Polynomial::zero(),d:Polynomial::one(),}}fn add_q(&mut self,q:Polynomial){std::mem::swap(&mut self.a,&mut self.c);std::mem::swap(&mut self.b,&mut self.d);self.c-=&self.a*&q;self.d-=&self.b*&q;self.c.truncate_zero();self.d.truncate_zero();}fn const_mul(&mut self,q:ModInt){self.a*=q;self.b*=q;}fn assert(&self){assert_eq!(self.a.v.len()-1,self.a.n);assert_eq!(self.b.v.len()-1,self.b.n);assert_eq!(self.c.v.len()-1,self.c.n);assert_eq!(self.d.v.len()-1,self.d.n);}fn mat_mul_left(&mut self,rhs:&GCDMatrix){let mut a=&rhs.a*&self.a;a+=&rhs.b*&self.c;let mut b=&rhs.a*&self.b;b+=&rhs.b*&self.d;let mut c=&rhs.c*&self.a;c+=&rhs.d*&self.c;let mut d=&rhs.c*&self.b;d+=&rhs.d*&self.d;a.truncate_zero();b.truncate_zero();c.truncate_zero();d.truncate_zero();self.a=a;self.b=b;self.c=c;self.d=d;}fn vec_mul(&self,a:&Polynomial,b:&Polynomial)->(Polynomial,Polynomial){(&self.a*a+&self.b*b,&self.c*a+&self.d*b)}}fn half_gcd_inner(a:&mut Polynomial,b:&mut Polynomial,mat:&mut GCDMatrix,){let n=a.degree()+1;let bn=b.degree()+1;let k=(n+1)/2;if bn<=k{return;}{let mut local_mat=GCDMatrix::new();let mut ah=a.upper_part(k);let mut bh=b.upper_part(k);half_gcd_inner(&mut ah,&mut bh,&mut local_mat);let(a2,b2)=local_mat.vec_mul(a,b);mat.mat_mul_left(&local_mat);*a=a2;*b=b2;a.truncate_zero();b.truncate_zero();}{let n=a.degree()+1;let bn=b.degree()+1;let k=(n+1)/2;if bn<=k{return;}let(mut q,mut r)=a.divmod(b);q.truncate_zero();r.truncate_zero();std::mem::swap(a,b);*b=r;mat.add_q(q);}if!b.is_zero(){let an2=a.degree()+1;let bn2=b.degree()+1;if bn2<=(an2+1)/2{return;}let mut local_mat=GCDMatrix::new();let mut ah=a.upper_part(2*k-(an2-1));let mut bh=b.upper_part(2*k-(an2-1));half_gcd_inner(&mut ah,&mut bh,&mut local_mat);let(a2,b2)=local_mat.vec_mul(a,b);mat.mat_mul_left(&local_mat);*a=a2;*b=b2;a.truncate_zero();b.truncate_zero();}}fn half_gcd(a:&Polynomial,b:&Polynomial)->(Polynomial,GCDMatrix){let mut a:Polynomial =a.clone();let mut b:Polynomial =b.clone();let mut mat=GCDMatrix::new();while!b.is_zero(){half_gcd_inner(&mut a,&mut b,&mut mat);let(mut q,mut r)=a.divmod(&b);q.truncate_zero();r.truncate_zero();a=b;b=r;mat.add_q(q);}a.truncate_zero();(a,mat)}pub fn gcd_and_inverse(f:&Polynomial,g:&Polynomial,)->(Polynomial,Option>){let mut b=g.clone();let mut an=f.degree();let mut bn=g.degree();let mut a=if an>bn{f.divmod(g).1}else{f.clone()};std::mem::swap(&mut a,&mut b);std::mem::swap(&mut an,&mut bn);let(a,mut mat)=half_gcd(&a,&b);if a.n==0{let d=a.v[0].inv();mat.b.truncate_zero();let z=mat.b.divmod(g).1;let mut inverse=z;inverse.truncate_zero();inverse*=d;return(a,Some(inverse));}(a,None)}pub fn inverse(f:&Polynomial,g:&Polynomial)->Option>{gcd_and_inverse(f,g).1}}pub mod middle_euclid{use crate::__cargo_equip::preludes::minimal_lib_poly::*;use super::Polynomial;use minimal_lib_int::modulo::{ModInt,Modulus};pub fn ex_euclid(a:i64,b:i64)->(i64,i64,i64){let mut a=a;let mut b=b;let mut c=1;let mut d=0;let mut e=0;let mut f=1;while a!=0{let q=b/a;let res=(b%a,a,d,c-d*q,f,e-f*q);a=res.0;b=res.1;c=res.2;d=res.3;e=res.4;f=res.5;}if b<0{e=-e;c=-c;b=-b;}(e,c,b)}#[derive(Debug)]struct GCDMatrix{a:Polynomial,b:Polynomial,c:Polynomial,d:Polynomial,q:Vec>,}implGCDMatrix{fn new()->Self{Self{a:Polynomial::one(),b:Polynomial::zero(),c:Polynomial::zero(),d:Polynomial::one(),q:Vec::new(),}}fn add_q(&mut self,q:Polynomial){std::mem::swap(&mut self.a,&mut self.c);std::mem::swap(&mut self.b,&mut self.d);self.c-=&self.a*&q;self.d-=&self.b*&q;self.c.truncate_zero();self.d.truncate_zero();self.q.push(q);}fn const_mul(&mut self,q:ModInt){self.a*=q;self.b*=q;}fn assert(&self){assert_eq!(self.a.v.len()-1,self.a.n);assert_eq!(self.b.v.len()-1,self.b.n);assert_eq!(self.c.v.len()-1,self.c.n);assert_eq!(self.d.v.len()-1,self.d.n);}fn mat_mul_left(&mut self,rhs:GCDMatrix){let mut a=&rhs.a*&self.a;a+=&rhs.b*&self.c;let mut b=&rhs.a*&self.b;b+=&rhs.b*&self.d;let mut c=&rhs.c*&self.a;c+=&rhs.d*&self.c;let mut d=&rhs.c*&self.b;d+=&rhs.d*&self.d;a.truncate_zero();b.truncate_zero();c.truncate_zero();d.truncate_zero();self.a=a;self.b=b;self.c=c;self.d=d;for item in rhs.q.into_iter(){self.q.push(item);}}fn vec_mul(&self,a:&Polynomial,b:&Polynomial)->(Polynomial,Polynomial){(&self.a*a+&self.b*b,&self.c*a+&self.d*b)}}fn half_gcd_inner(a:&mut Polynomial,b:&mut Polynomial,mat:&mut GCDMatrix,_n:usize,){let n=a.degree()+1;let bn=b.degree()+1;let k=(n+1)/2;if bn<=k{return;}{let mut local_mat=GCDMatrix::new();let mut ah=a.upper_part(k);let mut bh=b.upper_part(k);half_gcd_inner(&mut ah,&mut bh,&mut local_mat,n-k);let(a2,b2)=local_mat.vec_mul(a,b);mat.mat_mul_left(local_mat);*a=a2;*b=b2;a.truncate_zero();b.truncate_zero();}{let bn=b.degree()+1;if bn<=n{return;}let(mut q,mut r)=a.divmod(b);q.truncate_zero();r.truncate_zero();std::mem::swap(a,b);*b=r;mat.add_q(q);}if!b.is_zero(){let an2=a.degree()+1;let bn2=b.degree()+1;if bn2<=(an2+1)/2{return;}let mut local_mat=GCDMatrix::new();let shift=2*k-(an2-1);let mut ah=a.upper_part(shift);let mut bh=b.upper_part(shift);half_gcd_inner(&mut ah,&mut bh,&mut local_mat,n-shift);let(a2,b2)=local_mat.vec_mul(a,b);mat.mat_mul_left(local_mat);*a=a2;*b=b2;a.truncate_zero();b.truncate_zero();}}fn half_gcd(a:&Polynomial,b:&Polynomial,n:usize,)->(Polynomial,GCDMatrix){let mut a:Polynomial =a.clone();let mut b:Polynomial =b.clone();let mut mat=GCDMatrix::new();while b.degree()>mat.d.degree(){let d=b.degree();half_gcd_inner(&mut a,&mut b,&mut mat,d-n);if b.degree()<=mat.d.degree(){break;}let(mut q,mut r)=a.divmod(&b);q.truncate_zero();r.truncate_zero();a=b;b=r;mat.add_q(q);}(b,mat)}pub fn berlekamp_massey(f:&Polynomial)->(Polynomial,Polynomial){let n=f.n;let mut bv=vec![0;n+2];bv[n+1]=1;let b=Polynomial::new(&bv);let(mut p,mut mat)=half_gcd(&b,f,n/2);mat.d.truncate_zero();let di=mat.d.v[0].inv();let mut q=mat.d;p*=di;q*=di;(p,q)}}pub mod multipoint{use crate::__cargo_equip::preludes::minimal_lib_poly::*;fn minimum_exponent(n:i64)->usize{(64-n.saturating_sub(1).leading_zeros())as _}use minimal_lib_int::{modulo::{ModInt,Modulus},utils::isqrt,};use super::{poly::Polynomial,shift::shift_evaluation};pub fn product_of_polys(poly:&[Polynomial])->Polynomial{let n=poly.len();let l=minimum_exponent(n as _);let mut sub=vec![Polynomial::one();1<<(l+1)];let i_base=(1<(poly:&Polynomial,points:&[ModInt])->Vec>{let n=points.len();let l=minimum_exponent(n as _);let mut sub=vec![Polynomial::one();1<<(l+1)];let mut rem=vec![Polynomial::one();1<<(l+1)];let i_base=(1<>1]%&sub[i];}let mut res=vec![];for i in 0..n{res.push(rem[i_base+i].raw_coeffs()[0]);}res}pub fn interpolate(xs:&[ModInt],ys:&[ModInt])->Polynomial{let n=xs.len();let l=minimum_exponent(n as _);let mut mul=vec![Polynomial::one();1<<(l+1)];let mut sub=vec![Polynomial::one();1<<(l+1)];let i_base=(1<>1]%&mul[i];}for i in 0..n{sub[i_base+i]=Polynomial::new(&[ys[i]*sub[i_base+i].v[0].inv()]);}for level in(0..l).rev(){let i_base=(1<(f:&Polynomial,xs:&[ModInt])->Vec>{let ys=multipoint_eval(f,xs);let gs:Vec<_> =xs.iter().map(|&x|Polynomial::new(&[-x,ModInt::one()])).collect();let g=product_of_polys(&gs).derivative();let zs=multipoint_eval(&g,xs);ys.into_iter().zip(zs.into_iter()).map(|(x,y)|x/y).collect()}pub fn multipoint_geometric(f:&Polynomial,a:ModInt,r:ModInt,n:usize,)->Vec>{if r==ModInt::zero(){return(0..n).map(|i|if i==0{f.eval(a)}else{f.v[0]}).collect();}let fd=f.degree();let wilen=(fd+1).max(n);let n2=n+fd;let mut w=vec![ModInt::zero();n2];let mut wi=vec![ModInt::zero();wilen];let mut apow=vec![ModInt::zero();fd+1];{let mut ta=ModInt::one();let mut tb=ModInt::one();let mut tai=ModInt::one();let mut tbi=ModInt::one();let mut aa=ModInt::one();let ri=r.inv();for i in 0..n2{w[i]=ta;ta*=tb;tb*=r;if i =f.raw_coeffs().iter().enumerate().map(|(i,&x)|x*apow[i]*wi[i]).collect();y.reverse();let convol=T::convolution(&w,&y);let mut result=Vec::with_capacity(n);for i in 0..n{result.push(convol[fd+i]*wi[i])}result}pub fn interpolate_geometric(_ys:&[ModInt],_a:ModInt,_r:ModInt,)->Vec>{todo!();}pub fn shift_arith(n:usize,d:usize,a:usize,b:usize)->Vec>{let a=ModInt::from(a);let b=ModInt::from(b);let d=ModInt::from(d);let mut q=n;let mut digs=vec![];while q>1{digs.push(q&1);q>>=1;}let mut seq=vec![ModInt::one();q+1];for i in 0..=q{for j in 0..q{seq[i]*=a*i.into()+b+ModInt::from(j)*d;}}let da=d/a;for i in digs.into_iter().rev(){let n=seq.len().into();let mut ext=shift_evaluation(&seq,n,seq.len());let mul=shift_evaluation(&seq,da*(n-ModInt::one()),seq.len());let extmul=shift_evaluation(&seq,da*(n-ModInt::one())+n,seq.len());for(x,y)in ext.iter_mut().zip(extmul.into_iter()){*x*=y;}for(x,y)in seq.iter_mut().zip(mul.into_iter()){*x*=y;}seq.extend(ext);if i==1{let sq=seq.len();for j in 0..sq{seq[j]*=a*j.into()+b+ModInt::from(sq-2)*d;}}else{seq.pop();}}debug_assert_eq!(seq.len(),n+1);seq}pub fn factorial_large(n:usize)->ModInt{let m=T::get_modulo()as usize;if n>=m{return ModInt::zero();}if n==0{return ModInt::one();}let sq=isqrt(n as i64)as usize;let seq=shift_arith(sq,1,sq,1);let mut t=ModInt::one();for x in seq.into_iter().take(sq){t*=x;}for i in(1+sq*sq)..=n{t*=ModInt::from(i);}t}}pub mod poly{use crate::__cargo_equip::preludes::minimal_lib_poly::*;use std::{fmt::Debug,ops::{Add,AddAssign,Div,Mul,MulAssign,Neg,Rem,Sub,SubAssign},};use minimal_lib_int::modulo::{ModInt,Modulus};#[derive(Clone)]pub struct Polynomial{pub v:Vec>,pub n:usize,}implDefault for Polynomial{fn default()->Self{Self{v:vec![ModInt::zero()],n:0,}}}implDebug for Polynomial{fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{if self.v.len()!=self.n+1{f.write_fmt(format_args!("*broken n = {} vl = {}*",self.n,self.v.len()))?;}f.debug_list().entries(&self.v).finish()}}implPolynomial{pub fn new>>(v:&[S])->Self{Self{v:v.iter().map(|&x|x.into()).collect(),n:v.len()-1,}}pub fn new_degs(v:&[(usize,i64)])->Self{let max_degree=v.iter().map(|(x,_)|*x).max().unwrap_or(0);let mut res=vec![0;max_degree+1];for&(deg,val)in v.iter(){res[deg]+=val;}Self::new(&res)}#[deprecated]pub fn new_modint(v:&[ModInt])->Self{Self{v:v.to_vec(),n:v.len()-1,}}pub fn one()->Self{Self{v:vec![ModInt::new(1)],n:0,}}pub fn zero()->Self{Self{v:vec![ModInt::zero()],n:0,}}pub fn coeffs(&self)->Vec{self.v.iter().map(|&x|x.into()).collect()}pub fn raw_coeffs(&self)->Vec>{self.v.clone()}pub fn borrow_coeffs(&self)->&Vec>{&self.v}pub fn borrow_coeffs_mut(&mut self)->&mut Vec>{&mut self.v}pub fn degree(&self)->usize{self.n}pub fn eval(&self,x:ModInt)->ModInt{let mut t=ModInt::zero();let mut a=ModInt::new(1);for i in 0..=self.n{t+=a*self.v[i];a*=x;}t}pub fn is_zero(&self)->bool{self.n==0&&self.v[0]==ModInt::zero()}pub(in crate::__cargo_equip::crates::minimal_lib_poly)fn upper_part(&self,n:usize)->Self{if n>self.n{return Self::zero();}Self{v:self.v[n..].to_vec(),n:self.n-n,}}pub(in crate::__cargo_equip::crates::minimal_lib_poly)fn split_part(&self,n:usize)->(Self,Self){let mut v=self.v[0..=n.min(self.n)].to_vec();v.resize(n+1,ModInt::zero());let(vh,nh)=if self.n>n{(self.v[(n+1)..=self.n].to_vec(),self.n-n-1)}else{(vec![ModInt::zero()],0)};(Self{v,n},Self{v:vh,n:nh})}pub(in crate::__cargo_equip::crates::minimal_lib_poly)fn hensel_lifting(&self,n:usize)->Self{let a=self.v[0];let mut v=Self::new(&[a.inv()]);let mut i=1;while i<=n{let(h0,mut h1)=self.split_part(i-1);h1.truncate(i-1);let c=(&v*&h0).split_part(i-1).1;let mut b=-&v*(&v*&h1+c);b.truncate(i-1);v.v.extend(b.v);i*=2;v.n=i-1;}v.truncate(n);v}pub fn truncate_zero(&mut self){let mut msb=0;for i in(0..self.v.len()).rev(){if self.v[i]!=ModInt::zero(){msb=i;break;}}self.v.truncate(msb+1);self.n=msb;}pub fn truncate(&mut self,n:usize){self.v.resize(n+1,ModInt::zero());self.n=n;}pub fn truncate_max(&mut self,n:usize){if self.n>n{self.v.resize(n+1,ModInt::zero());self.n=n;}}pub fn cut(&self)->Self{let mut msb=0;for i in 0..self.v.len(){if self.v[i]!=ModInt::zero(){msb=i;}}self.split_part(msb).0}pub fn derivative(&self)->Self{let n=self.n;let mut v=vec![ModInt::zero();n+1];for i in 0..n{v[i]=self.v[i+1]*ModInt::new((i+1)as i64);}Self{v,n}}pub fn reverse(&self)->Self{let n=self.n;let mut v=vec![ModInt::zero();n+1];for i in 0..=self.n{v[n-i]=self.v[i];}Self{v,n}}pub fn divmod(&self,rhs:&Self)->(Self,Self){let n=self.n;let m=rhs.n;if n(Self,Self){todo!()}pub fn from_segment_values(_first_x:i64,_values:&[i64])->Self{todo!()}pub fn shift(&self,v:usize)->Self{let mut res=vec![ModInt::zero();self.v.len()+v];res[v..].clone_from_slice(&self.v);Self{v:res,n:self.n+v,}}pub fn pow(&self,rhs:i64)->Self{let mut res=Self::one();let mut r=rhs;let mut a:Polynomial =self.clone();while r>0{if r&1==1{res*=&a;}a=&a*&a;r>>=1;}res}pub fn powtrun(&self,rhs:i64,m:usize)->Self{let mut res=Self::one();let mut r=rhs;let mut a=self.clone();while r>0{if r&1==1{res=&res*&a;if res.n>m{res.truncate(m);}}a=&a*&a;if a.n>m{a.truncate(m);}r>>=1;}res}}implAdd for Polynomial{type Output=Self;fn add(self,rhs:Self)->Self::Output{&self+&rhs}}implSub for Polynomial{type Output=Self;fn sub(self,rhs:Self)->Self::Output{&self-&rhs}}implMul for Polynomial{type Output=Self;fn mul(self,rhs:Self)->Self::Output{&self*&rhs}}implMul>for Polynomial{type Output=Self;fn mul(self,rhs:ModInt)->Self::Output{let r:Vec> =self.v.iter().map(|x|*x*rhs).collect();Polynomial::new(&r)}}implDiv>for Polynomial{type Output=Self;fn div(self,rhs:ModInt)->Self::Output{let irhs=rhs.inv();let r:Vec> =self.v.iter().map(|x|*x*irhs).collect();Polynomial::new(&r)}}implNeg for Polynomial{type Output=Self;fn neg(self)->Self::Output{-&self}}implAdd for&Polynomial{type Output=Polynomial;fn add(self,rhs:Self)->Self::Output{let max_n=self.n.max(rhs.n);let mut res_v=vec![ModInt::zero();max_n+1];for i in 0..=self.n{res_v[i]+=self.v[i];}for i in 0..=rhs.n{res_v[i]+=rhs.v[i];}Polynomial{n:max_n,v:res_v}}}implSub for&Polynomial{type Output=Polynomial;fn sub(self,rhs:Self)->Self::Output{let max_n=self.n.max(rhs.n);let mut res_v=vec![ModInt::zero();max_n+1];for i in 0..=self.n{res_v[i]+=self.v[i];}for i in 0..=rhs.n{res_v[i]-=rhs.v[i];}Polynomial{n:max_n,v:res_v}}}implAddAssign for Polynomial{fn add_assign(&mut self,rhs:Self){let max_n=self.n.max(rhs.n);self.v.resize(max_n+1,ModInt::zero());self.n=max_n;for i in 0..=rhs.n{self.v[i]+=rhs.v[i];}}}implAddAssign<&Polynomial>for Polynomial{fn add_assign(&mut self,rhs:&Self){let max_n=self.n.max(rhs.n);self.v.resize(max_n+1,ModInt::zero());self.n=max_n;for i in 0..=rhs.n{self.v[i]+=rhs.v[i];}}}implSubAssign for Polynomial{fn sub_assign(&mut self,rhs:Self){let max_n=self.n.max(rhs.n);self.v.resize(max_n+1,ModInt::zero());self.n=max_n;for i in 0..=rhs.n{self.v[i]-=rhs.v[i];}}}implSubAssign<&Polynomial>for Polynomial{fn sub_assign(&mut self,rhs:&Self){let max_n=self.n.max(rhs.n);self.v.resize(max_n+1,ModInt::zero());self.n=max_n;for i in 0..=rhs.n{self.v[i]-=rhs.v[i];}}}implMulAssign>for Polynomial{fn mul_assign(&mut self,rhs:ModInt){self.v.iter_mut().for_each(|x|*x*=rhs);}}implMulAssign<&Polynomial>for Polynomial{fn mul_assign(&mut self,rhs:&Self){let v=T::convolution(&self.v,&rhs.v);self.n+=rhs.n;self.v=v;}}implMul for&Polynomial{type Output=Polynomial;fn mul(self,rhs:&Polynomial)->Self::Output{let n=self.n+rhs.n;Polynomial{n,v:T::convolution(&self.v,&rhs.v),}}}implRem for&Polynomial{type Output=Polynomial;fn rem(self,rhs:&Polynomial)->Self::Output{let(_,m)=self.divmod(rhs);m}}implNeg for&Polynomial{type Output=Polynomial;fn neg(self)->Self::Output{let n=self.n;let v=self.v.iter().map(|&x|-x).collect();Polynomial{v,n}}}}pub mod shift{use crate::__cargo_equip::preludes::minimal_lib_poly::*;use minimal_lib_int::modulo::{ModInt,Modulus};fn point_to_descend(xs:&[ModInt])->Vec>{T::mul_cache().with(|cache|{let cache=cache.borrow();let accum_inv=&cache.accum_inv;let n=xs.len();let mut x:Vec> =Vec::with_capacity(n);let mut y:Vec> =Vec::with_capacity(n);for(i,xs)in xs.iter().enumerate(){if i&1==0{x.push(*xs*accum_inv[i].into());y.push(accum_inv[i].into());}else{let s=*xs*accum_inv[i].into();let t=(-accum_inv[i]).into();x.push(s);y.push(t);}}let mut z=T::convolution(&x,&y);z.truncate(n);z})}fn descend_to_point(xs:&[ModInt])->Vec>{T::mul_cache().with(|cache|{let cache=cache.borrow();let accum=&cache.accum;let accum_inv=&cache.accum_inv;let n=xs.len();let mut x=Vec::with_capacity(n);let mut y=Vec::with_capacity(n);for(i,xs)in xs.iter().enumerate(){x.push(*xs);y.push(accum_inv[i].into());}let mut z=T::convolution(&x,&y);z.truncate(n);for(i,z)in z.iter_mut().enumerate(){*z*=accum[i].into();}z})}pub fn shift_evaluation_single(xs:&[ModInt],c:ModInt)->ModInt{T::mul_cache().with(|cache|{let cache=cache.borrow();let accum_inv=&cache.accum_inv;let n=xs.len();let mut l=vec![ModInt::zero();n];let mut r=vec![ModInt::zero();n];l[0]=ModInt::one();r[n-1]=ModInt::one();for i in 1..n{let j=n-i-1;l[i]=l[i-1]*(c-((i-1)as i64).into());r[j]=r[j+1]*(c-((j+1)as i64).into());}let mut t=ModInt::zero();for(i,((&l,&r),(&a,&ai)))in l.iter().zip(r.iter()).zip(accum_inv.iter().zip(accum_inv.iter().rev())).enumerate(){let mut v=l*r*ModInt::from(a*ai);if(n-i-1)&1>0{v=-v;}t+=v*xs[i];}t})}pub fn shift_evaluation(xs:&[ModInt],c:ModInt,m:usize)->Vec>{if m==1{return vec![shift_evaluation_single(xs,c)];}T::mul_cache().with(|cache|{let cache=cache.borrow();let accum=&cache.accum;let accum_inv=&cache.accum_inv;let n=xs.len();let mut xs=point_to_descend(xs);xs.iter_mut().enumerate().for_each(|(i,x)|{*x*=ModInt::new(accum[i]);});let mut ys=vec![ModInt::zero();n];let mut cur=ModInt::new(1);ys.iter_mut().rev().zip(accum_inv.iter().enumerate()).for_each(|(y,(i,&ac))|{*y=cur*ac.into();cur*=c-ModInt::new(i as i64);});let mut zs=T::convolution(&xs,&ys);for i in 0..n{zs[i]=zs[i+n-1]*accum_inv[i].into();}zs.resize(m,ModInt::zero());if n