#ifndef INCLUDE_MODE #define INCLUDE_MODE // #define REACTIVE // #define USE_GETLINE /* #define SUBMIT_ONLY */ #define DEBUG_OUTPUT #define SAMPLE_CHECK G #endif #ifdef INCLUDE_MAIN VO Solve() { CIN( int , N , K ); CIN_A( MP , 0 , N , A ); if( ( K & 1 ) == 1 ){ FOR( i , 1 , N ){ A[i] = A[i-1] + ( ( i & 1 ) == 1 ? -A[i] : A[i] ); } } vector A_l( ( N + 1 ) >> 1 ) , A_r( N >> 1 ); FOR( i , 0 , N ){ ( ( i & 1 ) == 0 ? A_l : A_r )[i >> 1] = move( A[i] ); } A_l = CumulativeSum( move( A_l ) , K >> 1 ); A_r = CumulativeSum( move( A_r ) , K >> 1 ); FOR( i , 0 , N ){ A[i] = move( ( ( i & 1 ) == 0 ? A_l : A_r )[i >> 1] ); } RETURN( A ); } REPEAT_MAIN(1); #else /* INCLUDE_MAIN */ #ifdef INCLUDE_SUB /* 圧縮時は中身だけ削除する。*/ IN VO Experiment() { } /* 圧縮時は中身だけ削除する。*/ IN VO SmallTest() { } /* 圧縮時は中身だけ削除する。*/ IN VO RandomTest( const int& test_case_num ) { } #define INCLUDE_MAIN #include __FILE__ #else /* INCLUDE_SUB */ #ifdef INCLUDE_LIBRARY /* VVV 常設でないライブラリは以下に挿入する。*/ #ifdef DEBUG #include "c:/Users/user/Documents/Programming/Mathematics/Polynomial/Truncate/a_Body.hpp" #else #define PO Polynomial #define TRPO TruncatedPolynomial TE CL PW3PW_CE{PU:T m_val[EX_lim];CE PW3PW_CE(CO T& t);CE CO T& OP[](CRI i)CO;CE CO T(&Get()CO)[EX_lim];}; TE CE PW3PW_CE::PW3PW_CE(CO T& t):m_val(){T PW{t};for(uint EX = EX_lim - 1;EX + 1 > 0;EX--){m_val[EX]= -PW;m_val[EX]*= PW *= PW;}}TE CE CO T& PW3PW_CE::OP[](CRI i)CO{AS(i < EX_lim);RE m_val[i];}TE CE CO T(&PW3PW_CE::Get()CO)[EX_lim]{RE m_val;} #define PS_FOR_FFT(MOD,LE,BORDER,PR,IPR,MINT)ST_AS((MINT::DeRP(PR)*= MINT::DeRP(IPR))== MINT::DeRP(1));TE <> CE CO uint LimitOfPWForFFT > = LE - 1;TE <> CE CO uint BorderForFFT > = BORDER;TE <> IN CO MINT(&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT >]{ST CE PW3PW_CE,LimitOfPWForFFT > > PRT{PR};ST_AS(PRT.m_val[0]== MINT::DeRP(1));RE PRT.Get();}TE <> IN CO MINT(&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT >]{ST CE PW3PW_CE,LimitOfPWForFFT > > IPRT{IPR};ST_AS(IPRT.m_val[0]== MINT::DeRP(1)&&(MINT::DeRP(PR)*= MINT::DeRP(IPR))== MINT::DeRP(1));RE IPRT.Get();} TE CE CO uint LimitOfPWForFFT{};TE CE CO uint BorderForFFT{};TE IN CO T(&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT];TE IN CO T(&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT]; PS_FOR_FFT(998244353,24,4,31,128805723,Mod);PS_FOR_FFT(167772161,26,4,17,29606852,Mod);PS_FOR_FFT(469762049,27,4,30,15658735,Mod);PS_FOR_FFT(754974721,25,4,362,415027540,Mod); TE VO CooleyTukey(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CRUI EX,CO T(&PRT)[LimitOfPWForFFT]){CO uint LE = two_PW + N_input_start + N_output_start;f.reserve(LE);WH(f.SZ()< LE){f.push_back(0);}ST VE bit_reverse[32]={VE(1)};ST uint e_next = 1;ST uint two_PW_next = 1;ST uint two_PW_next2 = 2;ST VE* p_bit_reverse_prev = bit_reverse;ST VE* p_bit_reverse_curr = p_bit_reverse_prev + 1;WH(e_next <= EX){*p_bit_reverse_curr = VE(two_PW_next2);uint* p_bit_reverse_curr_i = &((*p_bit_reverse_curr)[0]);uint* p_bit_reverse_curr_i_plus = p_bit_reverse_curr_i + two_PW_next;uint* p_bit_reverse_prev_i = &((*p_bit_reverse_prev)[0]);for(uint i = 0;i < two_PW_next;i++){(*(p_bit_reverse_curr_i_plus++)= *(p_bit_reverse_curr_i++)= *(p_bit_reverse_prev_i++)* 2)+= 1;}e_next++;swap(two_PW_next,two_PW_next2);two_PW_next2 *= 4;p_bit_reverse_prev++;p_bit_reverse_curr++;}CO VE& bit_reverse_EX = bit_reverse[EX];uint bit_num = 0;CO uint* p_bit_num_reverse = &(bit_reverse_EX[bit_num]);WH(bit_num < two_PW){if(*p_bit_num_reverse < bit_num){swap(f[*p_bit_num_reverse + N_input_start],f[bit_num + N_input_start]);}bit_num++;p_bit_num_reverse++;}CO T& one = PRT[0];T zeta,diff;uint i,j,j_lim,two_PW_curr = 1,two_PW_curr_2 = 2;WH(two_PW_curr < two_PW){CO uint N_input_start_plus = N_input_start + two_PW_curr;bit_num = i = 0;zeta = one;WH(i < two_PW){j = i;j_lim = i + two_PW_curr;WH(j < j_lim){diff = f[j + N_input_start] - f[j + N_input_start_plus];f[j + N_input_start] += f[j + N_input_start_plus];f[j + N_input_start_plus] = zeta * diff;j++;}bit_num++;i += two_PW_curr_2;j = 0;WH(true){if(((bit_num >> j)& 1)== 1){zeta *= PRT[j+1];break;}j++;}}two_PW_curr <<= 1;two_PW_curr_2 <<= 1;}CO uint LE_fixed = N_output_lim + N_input_start;WH(f.SZ()> LE_fixed){f.pop_back();}for(uint i = 0;i < N_output_start;i++){f[N_input_start + i]= 0;}RE;} TE IN VO FFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI two_PW,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,0,two_PW,two_PW,EX,PrimitiveRootOfTwoForFFT());}TE IN VO FFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,N_output_start,N_output_lim,two_PW,EX,PrimitiveRootOfTwoForFFT());}TE IN VO IFFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI two_PW,CO T& two_PW_inv,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,0,two_PW,two_PW,EX,InversePrimitiveRootOfTwoForFFT());CO uint SZ = two_PW + N_input_start;for(uint i = N_input_start;i < SZ;i++){f[i]*= two_PW_inv;}}TE IN VO IFFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CO T& two_PW_inv,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,N_output_start,N_output_lim,two_PW,EX,InversePrimitiveRootOfTwoForFFT());CO uint SZ = N_output_lim + N_input_start;for(uint i = N_output_start + N_input_start;i < SZ;i++){f[i]*= two_PW_inv;}} #define DC_OF_AR_FOR_PO(FUNC)IN PO OP FUNC(PO f)CO;IN PO OP FUNC(T t)CO #define DF_OF_AR_FOR_PO(FUNC,DEF)TE IN PO PO::OP FUNC(PO f)CO{RE MO(DEF);};TE IN PO PO::OP FUNC(T t)CO{RE *TH FUNC PO(MO(t));} TE CL TRPO;TE CL PO{PU:VE m_f;uint m_SZ;IN PO();IN PO(CO PO& f);IN PO(PO&& f);IN PO(VE f);IN PO(T t);IN PO(CRUI i,T t);IN PO& OP=(T n);IN PO& OP=(PO f);IN PO& OP=(VE f);IN CO T& OP[](CRUI i)CO;IN T& OP[](CRUI i);IN T OP()(CO T& t)CO;PO& OP+=(CO PO& f);PO& OP-=(CO PO& f);PO& OP*=(CO PO& f);PO& OP*=(PO&& f);IN PO& OP/=(CO PO& f);PO& OP/=(CO T& t);PO& OP%=(CO PO& f);PO& OP%=(CO T& t);bool OP==(CO PO& f)CO;bool OP==(CO T& t)CO;TE IN bool OP!=(CO P& f)CO;DC_OF_AR_FOR_PO(+);IN PO OP-()CO;DC_OF_AR_FOR_PO(-);DC_OF_AR_FOR_PO(*);IN PO OP/(CO PO& f)CO;IN PO OP/(CO T& t)CO;IN PO OP%(CO PO& f)CO;IN PO OP%(CO T& t)CO;IN CO VE& GetCoefficient()CO NE;IN CRUI SZ()CO NE;IN VO resize(CRUI deg_plus)NE;IN VO swap(PO& f);IN VO swap(VE& f);VO ReMORedundantZero();IN string Display()CO NE;ST PO Quotient(CO PO& f0,CO PO& f1);ST PO TP(CO PO& f,CRUI f_TP_SZ);ST IN CO PO& zero();ST IN CO PO& one();ST IN CO PO& x();ST IN CO T& c_zero();ST IN CO T& c_one();ST IN CO T& c_minus_one();IN PO& SignInvert();}; #define DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(TYPE,ARG,RHS)TE <> IN PO& PO::OP*=(ARG f){if(m_SZ != 0){VE v{};v.swap(m_f);TRPO TH_copy{m_SZ + f.m_SZ - 1,MO(v)};TH_copy *= RHS;m_f = MO(TH_copy.PO::m_f);m_SZ = m_f.SZ();}RE *TH;} #define RE_ZERO_FOR_MU_FOR_TR_PO_IF(CONDITION)if(CONDITION){RE OP=(zero);} #define RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(CONDITION)if(CONDITION){RE TRPO(m_N);} #define RE_ZERO_FOR__FOR_TR_PO_IF(MU,CONDITION)RE_ZERO_FOR_ ## MU ## _FOR_TR_PO_IF(CONDITION) #define SET_VE_FOR_AN_OF_MU_FOR_TR_PO(N_OUTPUT_LIM)if(PO::m_SZ < N_OUTPUT_LIM){for(uint i = PO::m_SZ;i < N_OUTPUT_LIM;i++){PO::m_f.push_back(0);}PO::m_SZ = N_OUTPUT_LIM;} #define SET_VE_FOR_AN_OF_TR_MU_CO_FOR_TR_PO(N_OUTPUT_LIM)VE AN(N_OUTPUT_LIM) #define SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_OUTPUT_LIM)SET_VE_FOR_AN_OF_ ## MU ## _FOR_TR_PO(N_OUTPUT_LIM) #define SET_SUM_OF_MU_FOR_TR_PO PO::m_f[i]= sum #define SET_SUM_OF_TR_MU_CO_FOR_TR_PO AN[i]= sum #define SET_SUM_OF__FOR_TR_PO(MU)SET_SUM_OF_ ## MU ## _FOR_TR_PO #define SET_N_INPUT_START_FOR_MU_FOR_TR_PO(F,SZ,N_INPUT_START_NUM)uint N_INPUT_START_NUM{};for(uint i = 0;i < SZ && searching;i++){if(F[i]!= zero){N_INPUT_START_NUM = i;searching = false;}} #define SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(F,SZ,N_INPUT_MAX_NUM)uint N_INPUT_MAX_NUM{};searching = true;for(uint i =(SZ)- 1;searching;i--){if(F[i]!= zero){N_INPUT_MAX_NUM = i;searching = false;}} #define CN_FOR_MU_FOR_TR_PO(J_MIN)CO uint j_max = i < N_input_max_0_start_1?i - N_input_start_1:N_input_max_0;T sum{zero};for(uint j = J_MIN;j <= j_max;j++){sum += PO::m_f[j]* f.PO::m_f[i - j];}PO::m_f[i]= sum; #define CN_FOR_TR_MU_CO_FOR_TR_PO(J_MIN)CO uint j_max = i < N_input_max_0_start_1?i - N_input_start_1:N_input_max_0;T& m_fi = AN[i];for(uint j = J_MIN;j <= j_max;j++){m_fi += PO::m_f[j]* f.PO::m_f[i - j];} #define CN_FOR__FOR_TR_PO(MU,J_MIN)CN_FOR_ ## MU ## _FOR_TR_PO(J_MIN) #define ZEROIFICATION_FOR_MU_FOR_TR_PO for(uint i = 0;i < N_input_start_0_start_1;i++){PO::m_f[i]= 0;} #define ZEROIFICATION_FOR_TR_MU_CO_FOR_TR_PO CRUI N_output_start_fixed = N_output_start < N_input_start_0_start_1?N_output_start:N_input_start_0_start_1;for(uint i = 0;i < N_output_start_fixed;i++){AN[i]= 0;} #define ZEROIFICATION_FOR__FOR_TR_PO(MU)ZEROIFICATION_FOR_ ## MU ## _FOR_TR_PO #define DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START)RE_ZERO_FOR__FOR_TR_PO_IF(MU,PO::m_SZ == 0);uint N_output_max = PO::m_SZ + f.PO::m_SZ - 2;if(N_output_max >= m_N){N_output_max = m_N - 1;}CO uint N_output_lim = N_output_max + 1;SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_output_lim);for(uint i = N_output_max;searching;i--){T sum{zero};for(uint j = 0;j <= i;j++){sum += ACCESS_ENTRY * f.PO::OP[](i - j);}SET_SUM_OF__FOR_TR_PO(MU);searching = i > N_OUTPUT_START;} #define DF_1_OF__FOR_TR_PO(MU)SET_N_INPUT_START_FOR_MU_FOR_TR_PO(PO::m_f,PO::m_SZ,N_input_start_0);RE_ZERO_FOR__FOR_TR_PO_IF(MU,searching);searching = true;SET_N_INPUT_START_FOR_MU_FOR_TR_PO(f,f.PO::m_SZ,N_input_start_1); #define SET_N_INPUT_RANGE SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(PO::m_f,PO::m_SZ,N_input_max_0);SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(f,f.PO::m_SZ < m_N?f.PO::m_SZ:m_N,N_input_max_1);CO uint N_input_max_0_max_1 = N_input_max_0 + N_input_max_1;CO uint N_input_start_0_start_1 = N_input_start_0 + N_input_start_1;uint N_output_lim_fixed = N_input_max_0_max_1 < m_N?N_input_max_0_max_1 + 1:m_N; #define DF_3_OF__FOR_TR_PO(MU)CO uint N_input_start_0_max_1 = N_input_start_0 + N_input_max_1;CO uint N_input_max_0_start_1 = N_input_max_0 + N_input_start_1;CO uint N_output_max_fixed = N_output_lim_fixed - 1;SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_output_lim_fixed);for(uint i = N_output_max_fixed;i > N_input_start_0_max_1;i--){CN_FOR__FOR_TR_PO(MU,i - N_input_max_1);}searching = true;for(uint i = N_input_start_0_max_1 < N_output_max_fixed?N_input_start_0_max_1:N_output_max_fixed;searching;i--){CN_FOR__FOR_TR_PO(MU,N_input_start_0);searching = i > N_input_start_0_start_1;}ZEROIFICATION_FOR__FOR_TR_PO(MU); #define SET_SHIFTED_VE_FOR_MU(V,F,I_START,I_MAX,I_SHIFT)VE V(product_LE);for(uint i = I_START;i <= I_MAX;i++){V[I_SHIFT + i]= F[i];} #define DF_OF_MU_FOR_TR_PO(RE_LINE_0,RE_LINE_1,RE_LINE_2,RE_LINE_3,RE_LINE_4,MU,ACCESS_ENTRY,N_OUTPUT_START,FIX_N_OUTPUT_LIM)CE CRUI border_0 = FFT_MU_border_0;CO T& zero = PO::c_zero();bool searching = true;if(PO::m_SZ < border_0 && f.PO::m_SZ < border_0){RE_LINE_0;DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START);RE_LINE_1;}DF_1_OF__FOR_TR_PO(MU);RE_LINE_2;SET_N_INPUT_RANGE;FIX_N_OUTPUT_LIM;RE_LINE_3;DF_3_OF__FOR_TR_PO(MU);RE_LINE_4; #define DF_OF_FFT_MU_FOR_TR_PO(RE_LINE_0,RE_LINE_1,RE_LINE_2,RE_LINE_3,RE_LINE_4,RE_LINE_5,MU,ACCESS_ENTRY,N_OUTPUT_START,N_OUTPUT_START_SHIFTED,FIX_N_OUTPUT_LIM,DC_OF_F0,N_INPUT_START_0,N_INPUT_LIM_0,DC_OF_F1,N_INPUT_START_1,N_INPUT_LIM_1,VE_FOR_IFFT,RESZ_VE_FOR_IFFT,I_START,MU_FORMULA,SET_AN)CE CRUI border_0 = FFT_MU_border_0;CO T& zero = PO::c_zero();bool searching = true;if(PO::m_SZ < border_0 && f.PO::m_SZ < border_0){RE_LINE_0;DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START);RE_LINE_1;}DF_1_OF__FOR_TR_PO(MU);RE_LINE_2;SET_N_INPUT_RANGE;FIX_N_OUTPUT_LIM;RE_LINE_3;CO uint N_input_TR_deg_0_deg_1 = N_input_max_0 - N_input_start_0 + N_input_max_1 - N_input_start_1;CE CRUI border_1 = FFT_MU_border_1;if(N_input_TR_deg_0_deg_1 < border_1){DF_3_OF__FOR_TR_PO(MU);RE_LINE_4;}uint two_PW = FFT_MU_border_1_2;uint EX = FFT_MU_border_1_2_EX;T two_PW_inv{FFT_MU_border_1_2_inv};WH(N_input_TR_deg_0_deg_1 >= two_PW){two_PW *= 2;two_PW_inv /= 2;EX++;}CO uint product_LE = N_input_start_0_start_1 + two_PW;DC_OF_F0;DC_OF_F1;FFT(f0,N_INPUT_START_0,N_INPUT_LIM_0,two_PW,EX);FFT(f1,N_INPUT_START_1,N_INPUT_LIM_1,two_PW,EX);RESZ_VE_FOR_IFFT;for(uint i = I_START + two_PW - 1;i + 1 > I_START;i--){MU_FORMULA;}CO uint N_output_lim_shifted = N_output_lim_fixed - N_input_start_0_start_1;CO uint N_output_start_shifted = min(N_output_lim_shifted,uint(N_OUTPUT_START_SHIFTED));IFFT(VE_FOR_IFFT,N_input_start_0_start_1,product_LE,N_output_start_shifted,N_output_lim_shifted,two_PW,two_PW_inv,EX);SET_AN;RE_LINE_5; #define DF_OF_INVERSE_FOR_TR_PO(TYPE,RECURSION)CRUI N = f.GetTruncation();uint PW;uint PW_2 = 1;TRPO< TYPE > f_inv{PW_2,PO< TYPE >::c_one()/ f[0]};WH(PW_2 < N){PW = PW_2;PW_2 *= 2;f_inv.SetTruncation(PW_2);RECURSION;}f_inv.SetTruncation(N);RE f_inv #define DF_OF_EXP_FOR_TR_PO(TYPE,RECURSION)AS(f[0]== PO< TYPE >::c_zero());CRUI N = f.GetTruncation();uint PW;uint PW_2 = 1;TRPO< TYPE > f_exp{PW_2,PO< TYPE >::c_one()};WH(PW_2 < N){PW = PW_2;PW_2 *= 2;f_exp.SetTruncation(PW_2);RECURSION;}f_exp.SetTruncation(N);RE f_exp #define DF_OF_PS_OF_MU_OF_TR_PO(TYPE,BORDER_0,BORDER_1,BORDER_1_2,BORDER_1_2_EX,BORDER_1_2_INV)TE <> CE CO uint FFT_MU_border_0< TYPE > = BORDER_0;TE <> CE CO uint FFT_MU_border_1< TYPE > = BORDER_1;ST_AS(FFT_MU_border_0< TYPE > <= FFT_MU_border_1< TYPE >);TE <> CE CO uint FFT_MU_border_1_2< TYPE > = BORDER_1_2;ST_AS(FFT_MU_border_1< TYPE > < FFT_MU_border_1_2< TYPE > && FFT_MU_border_1_2< TYPE > <= FFT_MU_border_1< TYPE > * 2 );TE <> CE CO uint FFT_MU_border_1_2_EX< TYPE > = BORDER_1_2_EX;ST_AS(FFT_MU_border_1_2< TYPE > == 1 << FFT_MU_border_1_2_EX< TYPE > );TE <> CE CO uint FFT_MU_border_1_2_inv< TYPE > = BORDER_1_2_INV;ST_AS((TYPE::DeRP(FFT_MU_border_1_2< TYPE >)*= TYPE::DeRP(FFT_MU_border_1_2_inv< TYPE >))== TYPE::DeRP(1));TE <> IN TRPO< TYPE >& TRPO< TYPE >::OP*=(CO PO< TYPE >& f){RE TRPO< TYPE >::FFT_MU(f);}TE <> IN TRPO< TYPE >& TRPO< TYPE >::OP*=(PO< TYPE >&& f){RE TRPO< TYPE >::FFT_MU(MO(f));}TE <> TRPO< TYPE > IN Inverse(CO TRPO< TYPE >& f){DF_OF_INVERSE_FOR_TR_PO(TYPE,f_inv.TRMinus(f_inv.FFT_TRMU_CO(f,PW,PW_2).FFT_TRMU(f_inv,PW,PW_2),PW,PW_2));}TE <> TRPO< TYPE > IN Exp(CO TRPO< TYPE >& f){DF_OF_EXP_FOR_TR_PO(TYPE,f_exp.TRMinus((TRIntegral(Differential(f_exp).FFT_TRMU_CO(Inverse(f_exp),PW - 1,PW_2),PW).TRMinus(f,PW,PW_2)).FFT_TRMU(f_exp,PW,PW_2),PW,PW_2));} #define DF_OF_PS_OF_MU_OF_PO_PROTH_MOD(MOD,BORDER_1_2_INV,MINT)DF_OF_PS_OF_MU_OF_TR_PO(MINT,17,512,1024,10,BORDER_1_2_INV);DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(MINT,CO PO >&,TH == &f?TH_copy:f);DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(MINT,PO >&&,MO(f)); TE CL TRPO:PU PO{PU:uint m_N;PU:IN TRPO(CRUI N = 0);IN TRPO(CO TRPO& f);IN TRPO(TRPO&& f);IN TRPO(CRUI N,T t);IN TRPO(CRUI N,CO PO& f);IN TRPO(CRUI N,PO&& f);IN TRPO(CRUI N,VE&& f);IN TRPO(CRUI N,CRUI i,T t);IN TRPO& OP=(TRPO f);IN TRPO& OP=(T n);IN TRPO& OP=(PO f);IN TRPO& OP+=(CO T& t);IN TRPO& OP+=(CO PO& f);IN TRPO& OP+=(CO TRPO& f);TRPO& TRPlus(CO PO& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO& OP-=(CO T& t);IN TRPO& OP-=(CO PO& f);IN TRPO& OP-=(CO TRPO& f);TRPO& TRMinus(CO PO& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO& OP*=(CO T& t);TRPO& OP*=(CO PO& f);IN TRPO& OP*=(PO&& f);TRPO& FFT_MU(CO PO& f);TRPO& TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim);TRPO& FFT_TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim);TRPO& FFT_TRMU(PO&& f,CRUI N_output_start,CRUI N_output_lim);TRPO TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim)CO;TRPO FFT_TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim)CO;TRPO FFT_TRMU_CO(PO&& f,CRUI N_output_start,CRUI N_output_lim)CO;IN TRPO& OP/=(CO T& t);IN TRPO& OP/=(CO TRPO& t);IN TRPO& OP%=(CO T& t);TE IN TRPO OP+(CO P& f)CO;IN TRPO OP-()CO;TE IN TRPO OP-(CO P& f)CO;TE IN TRPO OP*(CO P& f)CO;TE IN TRPO OP/(CO P& f)CO;IN TRPO OP%(CO T& t)CO;IN VO SetTruncation(CRUI N)NE;IN CRUI GetTruncation()CO NE;IN TRPO& TruncateInitial(CRUI N)NE;IN TRPO& TruncateFinal(CRUI N)NE;};TE CE CO uint FFT_MU_border_0 = 17;TE CE CO uint FFT_MU_border_1{};TE CE CO uint FFT_MU_border_1_2{};TE CE CO uint FFT_MU_border_1_2_EX{};TE CE CO uint FFT_MU_border_1_2_inv{}; TE IN TRPO::TRPO(CRUI N):PO(),m_N(N){AS(m_N>0);}TE IN TRPO::TRPO(CO TRPO& f):PO(f),m_N(f.m_N){}TE IN TRPO::TRPO(TRPO&& f):PO(MO(f.m_f)),m_N(f.m_N){}TE IN TRPO::TRPO(CRUI N,T t):PO(MO(t)),m_N(N){AS(m_N>0);}TE IN TRPO::TRPO(CRUI N,CO PO& f):PO(),m_N(N){AS(m_N>0);PO::m_SZ = f.PO::m_SZ < m_N?f.PO::m_SZ:m_N;PO::m_f = VE(PO::m_SZ);for(uint i = 0;i < PO::m_SZ;i++){PO::m_f[i]= f.PO::m_f[i];}}TE IN TRPO::TRPO(CRUI N,PO&& f):PO(),m_N(N){AS(m_N>0);if(f.PO::m_SZ < m_N * 2){PO::OP=(MO(f));if(f.PO::m_SZ > m_N){TruncateFinal(m_N);}}else{PO::m_f = VE(m_N);for(uint i = 0;i < m_N;i++){PO::m_f[i]= MO(f.PO::m_f[i]);}PO::m_SZ = m_N;}}TE IN TRPO::TRPO(CRUI N,VE&& f):PO(),m_N(N){AS(m_N>0);CO uint f_SZ = f.SZ();if(f_SZ < m_N * 2){PO::OP=(MO(f));if(f_SZ > m_N){TruncateFinal(m_N);}}else{PO::m_f = VE(m_N);for(uint i = 0;i < m_N;i++){PO::m_f[i]= MO(f[i]);}}}TE IN TRPO::TRPO(CRUI N,CRUI i,T t):PO(),m_N(N){AS(m_N>0);if(i < m_N?t != PO::c_zero():false){PO::OP[](i)= MO(t);}}TE IN TRPO& TRPO::OP=(TRPO f){PO::OP=(MO(f.m_f));m_N = f.m_N;RE *TH;}TE IN TRPO& TRPO::OP=(T n){PO::OP=(MO(n));RE *TH;}TE IN TRPO& TRPO::OP=(PO f){RE OP=(TRPO(m_N,MO(f)));}TE IN TRPO& TRPO::OP+=(CO T& t){PO::OP+=(t);RE *TH;}TE IN TRPO& TRPO::OP+=(CO PO& f){RE TRPlus(f,0,f.m_SZ);}TE IN TRPO& TRPO::OP+=(CO TRPO& f){RE TRPlus(f,0,f.PO::m_SZ);}TE TRPO& TRPO::TRPlus(CO PO& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO::m_SZ?N_input_lim:f.PO::m_SZ:m_N < f.PO::m_SZ?m_N:f.PO::m_SZ;if(PO::m_SZ < SZ){PO::m_f.reserve(SZ);for(uint i = N_input_start;i < PO::m_SZ;i++){PO::m_f[i]+= f.PO::m_f[i];}for(uint i = PO::m_SZ;i < SZ;i++){PO::m_f.push_back(f.PO::m_f[i]);}PO::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO::m_f[i]+= f.PO::m_f[i];}}RE *TH;}TE IN TRPO& TRPO::OP-=(CO T& t){PO::OP-=(t);RE *TH;}TE IN TRPO& TRPO::OP-=(CO PO& f){RE TRMinus(f,0,f.m_SZ);}TE IN TRPO& TRPO::OP-=(CO TRPO& f){RE TRMinus(f,0,f.PO::m_SZ);}TE TRPO& TRPO::TRMinus(CO PO& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO::m_SZ?N_input_lim:f.PO::m_SZ:m_N < f.PO::m_SZ?m_N:f.PO::m_SZ;if(PO::m_SZ < SZ){PO::m_f.reserve(SZ);for(uint i = N_input_start;i < PO::m_SZ;i++){PO::m_f[i]-= f.PO::m_f[i];}for(uint i = PO::m_SZ;i < SZ;i++){PO::m_f.push_back(- f.PO::m_f[i]);}PO::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO::m_f[i]-= f.PO::m_f[i];}}RE *TH;}TE IN TRPO& TRPO::OP*=(CO T& t){PO::OP*=(t);RE *TH;}TE TRPO& TRPO::OP*=(CO PO& f){DF_OF_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO::m_SZ == 0),RE *TH,RE_ZERO_FOR_MU_FOR_TR_PO_IF(searching),RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= m_N),RE *TH,MU,PO::m_f[j],0,);}TE IN TRPO& TRPO::OP*=(PO&& f){RE OP*=(f);}TE TRPO& TRPO::FFT_MU(CO PO& f){DF_OF_FFT_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO::m_SZ == 0),RE *TH,RE_ZERO_FOR_MU_FOR_TR_PO_IF(searching),RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f[j],0,0,,VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,SET_SHIFTED_VE_FOR_MU(f1,f.PO::m_f,N_input_start_1,N_input_max_1,N_input_start_0),N_input_start_0_start_1,N_input_start_0 + N_input_max_1 + 1,f1,,N_input_start_0,f1[N_input_start_1 + i]*= f0[i],OP=(TRPO(m_N,MO(f1))));}TE TRPO& TRPO::TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,MU,PO::m_f[j],N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE TRPO& TRPO::FFT_TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_FFT_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f[j],N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,SET_SHIFTED_VE_FOR_MU(f1,f.PO::m_f,N_input_start_1,N_input_max_1,N_input_start_0),N_input_start_0_start_1,N_input_start_0 + N_input_max_1 + 1,f1,,N_input_start_0,f1[N_input_start_1 + i]*= f0[i],OP=(TRPO(m_N,MO(f1))));}TE TRPO& TRPO::FFT_TRMU(PO&& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_FFT_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f[j],N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,VE&& f1 = MO(f.PO::m_f),N_input_start_1,N_input_max_1 + 1,f0,f0.reserve(product_LE),0,f1[N_input_start_0_start_1 + i]= f0[N_input_start_0 + i]* f1[N_input_start_1 + i],for(uint i = N_input_start_0;i < N_input_start_0_start_1;i++){f0[i]= 0;}PO::m_SZ = f0.SZ();SetTruncation(m_N););}TE TRPO TRPO::TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim)CO{DF_OF_MU_FOR_TR_PO(,RE TRPO(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO(m_N,MO(AN)),TR_MU_CO,PO::OP[](j),N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE TRPO TRPO::FFT_TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim)CO{DF_OF_FFT_MU_FOR_TR_PO(,RE TRPO(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO(m_N,MO(AN)),RE TRPO(m_N,MO(f0)),TR_MU_CO,PO::OP[](j),N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},SET_SHIFTED_VE_FOR_MU(f0,PO::m_f,N_input_start_0,N_input_max_0,N_input_start_1),N_input_start_0_start_1,N_input_start_1 + N_input_max_0 + 1,VE f1 = f.PO::m_f,N_input_start_1,N_input_max_1 + 1,f0,,N_input_start_1,f0[N_input_start_0 + i]*= f1[i],);}TE TRPO TRPO::FFT_TRMU_CO(PO&& f,CRUI N_output_start,CRUI N_output_lim)CO{DF_OF_FFT_MU_FOR_TR_PO(,RE TRPO(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO(m_N,MO(AN)),RE TRPO(m_N,MO(f0)),TR_MU_CO,PO::OP[](j),N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},SET_SHIFTED_VE_FOR_MU(f0,PO::m_f,N_input_start_0,N_input_max_0,N_input_start_1),N_input_start_0_start_1,N_input_start_1 + N_input_max_0 + 1,VE&& f1 = MO(f.PO::m_f),N_input_start_1,N_input_max_1 + 1,f0,,N_input_start_1,f0[N_input_start_0 + i]*= f1[i],);}TE IN TRPO& TRPO::OP/=(CO T& t){PO::OP/=(t);RE *TH;}TE IN TRPO& TRPO::OP/=(CO TRPO& f){AS(m_N <= f.m_N);RE OP*=(m_N == f.m_N?Inverse(f):Inverse(TRPO(m_N,f)));}TE IN TRPO& TRPO::OP%=(CO T& t){PO::OP%=(t);RE *TH;}TE TE IN TRPO TRPO::OP+(CO P& f)CO{RE MO(TRPO(*TH)+= f);}TE IN TRPO TRPO::OP-()CO{RE MO(TRPO(m_N)-= *TH);}TE TE IN TRPO TRPO::OP-(CO P& f)CO{RE MO(TRPO(*TH)-= f);}TE TE IN TRPO TRPO::OP*(CO P& f)CO{RE MO(TRPO(*TH)*= f);}TE TE IN TRPO TRPO::OP/(CO P& f)CO{RE MO(TRPO(*TH)/= f);}TE IN TRPO TRPO::OP%(CO T& t)CO{RE MO(TRPO(*TH)%= t);}TE IN VO TRPO::SetTruncation(CRUI N)NE{if(N < m_N){TruncateFinal(N);}m_N = N;}TE IN CRUI TRPO::GetTruncation()CO NE{RE m_N;}TE IN TRPO& TRPO::TruncateInitial(CRUI N)NE{CRUI SZ = N < PO::m_SZ?N:PO::m_SZ;for(uint i = 0;i < SZ;i++){PO::m_f[i]= 0;}RE *TH;}TE IN TRPO& TRPO::TruncateFinal(CRUI N)NE{WH(PO::m_SZ > N){PO::m_f.pop_back();PO::m_SZ--;}RE *TH;}TE TRPO Differential(CRUI n,CO TRPO& f){if(f.PO::m_SZ < n){RE TRPO(n < f.m_N?f.m_N - n:1,PO::zero());}VE df(f.PO::m_SZ - n);T coef = T::Factorial(n);uint i = n;WH(i < f.PO::m_SZ){df[i - n]= f[i]* coef;i++;(coef *= i)/=(i - n);}RE TRPO(n < f.m_N?f.m_N - n:1,MO(df));}TE TRPO TRDifferential(CO TRPO& f,CRUI N_output_start_plus_one){TRPO f_dif{1 < f.m_N?f.m_N - 1:1};if(N_output_start_plus_one < f.PO::m_SZ){CO uint SZ = f.PO::m_SZ - 1;f_dif.PO::m_f = VE(SZ);for(uint i = N_output_start_plus_one;i < f.PO::m_SZ;i++){f_dif.PO::m_f[i-1]= f.PO::m_f[i]* i;}f_dif.PO::m_SZ = SZ;}RE f_dif;}TE IN TRPO Differential(CO TRPO& f){RE TRDifferential(f,1);}TE TRPO TRIntegral(CO TRPO& f,CRUI N_output_start){TRPO f_int{f.m_N + 1};if(N_output_start <= f.PO::m_SZ){CO uint SZ = f.PO::m_SZ + 1;f_int.PO::m_f = VE(SZ);for(uint i = N_output_start;i <= f.PO::m_SZ;i++){f_int.PO::m_f[i]= f.PO::m_f[i - 1]/ T(i);}f_int.PO::m_SZ = SZ;}RE f_int;}TE IN TRPO Integral(CO TRPO& f){RE TRIntegral(f,1);}TE TRPO Inverse(CO TRPO& f){DF_OF_INVERSE_FOR_TR_PO(T,f_inv.TRMinus(f_inv.TRMU_CO(f,PW,PW_2).TRMU(f_inv,PW,PW_2),PW,PW_2));}TE TRPO Exp(CO TRPO& f){DF_OF_EXP_FOR_TR_PO(T,f_exp.TRMinus((TRIntegral(Differential(f_exp).TRMU_CO(Inverse(f_exp),PW - 1,PW_2),PW).TRMinus(f,PW,PW_2)).TRMU(f_exp,PW),PW,PW_2));}TE IN TRPO Log(CO TRPO& f){AS(f[0]== PO::c_one());RE Integral(Differential(f)/= f);} DF_OF_PS_OF_MU_OF_PO_PROTH_MOD(P,997269505,Mod); TE IN PO::PO():m_f(),m_SZ(0){}TE IN PO::PO(CO PO& f):m_f(f.m_f),m_SZ(f.m_SZ){}TE IN PO::PO(PO&& f):m_f(MO(f.m_f)),m_SZ(f.m_SZ){}TE IN PO::PO(VE f):m_f(MO(f)),m_SZ(m_f.SZ()){}TE IN PO::PO(T t):PO(){if(t != c_zero()){OP[](0)= MO(t);}}TE IN PO::PO(CRUI i,T t):PO(){if(t != c_zero()){OP[](i)= MO(t);}}TE IN PO& PO::OP=(T n){m_f.clear();m_SZ = 0;OP[](0)= MO(n);RE *TH;}TE IN PO& PO::OP=(PO f){m_f = MO(f.m_f);m_SZ = f.m_SZ;RE *TH;}TE IN PO& PO::OP=(VE f){m_f = MO(f);m_SZ = m_f.SZ();RE *TH;}TE IN CO T& PO::OP[](CRUI i)CO{RE m_SZ <= i?c_zero():m_f[i];}TE IN T& PO::OP[](CRUI i){if(m_SZ <= i){CO T& z = c_zero();WH(m_SZ <= i){m_f.push_back(z);m_SZ++;}}RE m_f[i];}TE IN T PO::OP()(CO T& t)CO{RE MO((*TH %(PO(1,c_one())- t))[0]);}TE PO& PO::OP+=(CO PO& f){if(m_SZ < f.m_SZ){m_f.reserve(f.m_SZ);for(uint i = 0;i < m_SZ;i++){m_f[i]+= f.m_f[i];}for(uint i = m_SZ;i < f.m_SZ;i++){m_f.push_back(f.m_f[i]);}m_SZ = f.m_SZ;}else{for(uint i = 0;i < f.m_SZ;i++){m_f[i]+= f.m_f[i];}}RE *TH;}TE PO& PO::OP-=(CO PO& f){if(m_SZ < f.m_SZ){m_f.reserve(f.m_SZ);for(uint i = 0;i < m_SZ;i++){m_f[i]-= f.m_f[i];}for(uint i = m_SZ;i < f.m_SZ;i++){m_f.push_back(- f.m_f[i]);}m_SZ = f.m_SZ;}else{for(uint i = 0;i < f.m_SZ;i++){m_f[i]-= f.m_f[i];}}RE *TH;}TE PO& PO::OP*=(CO PO& f){if(m_SZ == 0){RE *TH;}if(f.m_SZ == 0){m_f.clear();m_SZ = 0;RE *TH;}CO uint SZ = m_SZ + f.m_SZ - 1;PO product{};for(uint i = 0;i < SZ;i++){T& product_i = product[i];CO uint j_min = m_SZ > i?0:i - m_SZ + 1;CO uint j_lim = i < f.m_SZ?i + 1:f.m_SZ;for(uint j = j_min;j < j_lim;j++){product_i += m_f[i - j]* f.m_f[j];}}RE *TH = MO(product);}TE IN PO& PO::OP*=(PO&& f){RE *TH *= f;};TE PO& PO::OP/=(CO T& t){if(t == c_one()){RE *TH;}CO T t_inv{c_one()/ t};for(uint i = 0;i < m_SZ;i++){OP[](i)*= t_inv;}RE *TH;}TE PO PO::TP(CO PO& f,CRUI f_TP_SZ){VE f_TP(f_TP_SZ);for(uint d = 0;d < f_TP_SZ;d++){f_TP[d]= f.m_f[f.m_SZ - 1 - d];}RE PO(MO(f_TP));}TE PO& PO::OP%=(CO T& t){if(t == c_one()){RE *TH = zero();}for(uint i = 0;i < m_SZ;i++){m_f[i]%= t;}RE *TH;}TE bool PO::OP==(CO PO& f)CO{CRUI SZ0 = SZ();CRUI SZ1 = f.SZ();CRUI SZ_max = SZ0 < SZ1?SZ1:SZ0;for(uint i = 0;i < SZ_max;i++){if(OP[](i)!= f[i]){RE false;}}RE true;}TE bool PO::OP==(CO T& t)CO{CRUI SZ_max = SZ();CO T& zero = PO::c_zero();for(uint i = 1;i < SZ_max;i++){if(m_f[i]!= zero){RE false;}}RE OP[](0)== t;}TE TE IN bool PO::OP!=(CO P& f)CO{RE !(*TH == f);}DF_OF_AR_FOR_PO(+,f += *TH);TE IN PO& PO::SignInvert(){ReMORedundantZero();for(auto& fi:m_f){fi = -fi;}RE *TH;}TE IN PO PO::OP-()CO{RE MO(PO(*TH).SignInvert());}DF_OF_AR_FOR_PO(-,f.SignInvert()+= *TH);DF_OF_AR_FOR_PO(*,f *= *TH);TE IN PO PO::OP/(CO T& t)CO{RE MO(PO(*TH)/= t);}TE IN PO PO::OP%(CO T& t)CO{RE MO(PO(*TH)%= t);}TE IN CO VE& PO::GetCoefficient()CO NE{RE m_f;}TE IN CRUI PO::SZ()CO NE{RE m_SZ;}TE IN VO PO::resize(CRUI deg_plus)NE{m_f.resize(m_SZ = deg_plus);}TE IN VO PO::swap(PO& f){m_f.swap(f.m_f);swap(m_SZ,f.m_SZ);}TE IN VO PO::swap(VE& f){m_f.swap(f);m_SZ = m_f.SZ();}TE VO PO::ReMORedundantZero(){CO T& z = c_zero();WH(m_SZ > 0?m_f[m_SZ - 1]== z:false){m_f.pop_back();m_SZ--;}RE;}TE string PO::Display()CO NE{string s = "(";if(m_SZ > 0){s += to_string(m_f[0]);for(uint i = 1;i < m_SZ;i++){s += "," + to_string(m_f[i]);}}s += ")";RE s;}TE IN CO PO& PO::zero(){ST CO PO z{};RE z;}TE IN CO PO& PO::one(){ST CO PO o{c_one()};RE o;}TE IN CO PO& PO::x(){ST CO PO f{1,c_one()};RE f;}TE IN CO T& PO::c_zero(){ST CO T z{0};RE z;}TE IN CO T& PO::c_one(){ST CO T o{1};RE o;}TE IN CO T& PO::c_minus_one(){ST CO T m{-1};RE m;}TE PO Differential(CRUI n,CO PO& f){CRUI SZ = f.SZ();if(SZ < n){RE PO::zero();}VE df(SZ - n);T coef = T::Factorial(n);uint i = n;WH(i < SZ){df[i - n]= f[i]* coef;i++;(coef *= i)/=(i - n);}RE PO(MO(df));} TE IN PO& PO::OP/=(CO PO& f){RE *TH = Quotient(*TH,f);}TE PO PO::Quotient(CO PO& f0,CO PO& f1){AS(f1.m_SZ == 0 || f1[f1.m_SZ-1] != c_zero());if(f0.m_SZ < f1.m_SZ){RE PO::zero();}AS(f1.m_SZ != 0);CO uint f0_TP_SZ = f0.m_SZ - f1.m_SZ + 1;CO uint f1_TP_SZ = f0_TP_SZ < f1.m_SZ?f0_TP_SZ:f1.m_SZ;CO TRPO f1_TP_inverse = Inverse(TRPO(f0_TP_SZ,TP(f1,f1_TP_SZ)));TRPO f0_TP{f0_TP_SZ,TP(f0,f0_TP_SZ)};f0_TP *= f1_TP_inverse;for(uint d0 =(f0_TP_SZ + 1)/ 2;d0 < f0_TP_SZ;d0++){::swap(f0_TP[d0],f0_TP[f0_TP_SZ - 1 - d0]);}RE f0_TP;}TE PO& PO::OP%=(CO PO& f){if(m_SZ >= f.m_SZ){*TH -=(*TH / f)* f;ReMORedundantZero();}RE *TH;}TE IN PO PO::OP/(CO PO& f)CO{RE PO::Quotient(*TH,f);}TE IN PO PO::OP%(CO PO& f)CO{RE MO(PO(*TH)%= f);} #endif #ifdef DEBUG #include "c:/Users/user/Documents/Programming/Mathematics/Polynomial/Cumulative/a_Body.hpp" #else // ../Truncate/compress.txtを先に貼る。 // 冪乗 TE PO PW(PO f,uint e){PO AN = Polynomial::one();WH(e > 0){(e & 1)== 0?AN:AN *= f;f *= f;e >>= 1;}RE AN;} // Tに拡張された冪乗のN次打ち切り。 TE IN TRPO PW(CO TRPO& f,CO T& t){RE Exp(Log(f)*= t);} // 冪乗のN次打ち切り。 TE TRPO PW(CO TRPO& f,CRUI e){CO T& one = PO::c_one();if(f[0] == one){RE PW(f,T(e));}CO T& zero = PO::c_zero();CRUI SZ = f.SZ();uint v = 0;WH(v < SZ?f[v] == zero:false){v++;}CO uint ve = v * e;CRUI N = f.GetTruncation();if(v == SZ || ve >= N){RE TRPO(N);}TRPO g(N - ve);CO T fv_inv = one / f[v];for(uint d = v;d < SZ;d++){g[d - v] = f[d] * fv_inv;}g = Exp(Log(g) *= T(e)) * PW(f[v],e);g.SetTruncation(N);for(uint d = N - 1;d >= ve;d--){g[d] = g[d - ve];}for(uint d = 0;d < ve;d++){g[d] = zero;}RE g;} // 累積和 TE VE CumulativeSum(VE a,uint order = 1){CO uint SZ = a.SZ();if(SZ > 0){TRPO f{SZ,MO(a)};TRPO g{SZ,VE(SZ,T::DeRP(MO(order)))};g[0]= T{};for(uint d = 1;d < SZ;d++){g[d]/= d;}f *= Exp(g);a.resize(SZ);for(uint d = 0;d < SZ;d++){a[d]= MO(f[d]);}}RE MO(a);} #endif /* AAA 常設でないライブラリは以上に挿入する。*/ #define INCLUDE_SUB #include __FILE__ #else /* INCLUDE_LIBRARY */ #ifdef DEBUG #define _GLIBCXX_DEBUG #else #pragma GCC optimize ( "O3" ) #pragma GCC optimize ( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #define REPEAT_MAIN( BOUND ) START_MAIN; CEXPR( int , bound_test_case_num , BOUND ); int test_case_num = 1; if CE( bound_test_case_num > 1 ){ SET_ASSERT( test_case_num , 1 , bound_test_case_num ); } FINISH_MAIN #define FINISH_MAIN REPEAT( test_case_num ){ if CE( bound_test_case_num > 1 ){ CERR( "testcase " , VARIABLE_FOR_REPEAT_test_case_num , ":" ); } Solve(); CERR( "" ); } } #define DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE1 ) #define ASSERT( A , MIN , MAX ) AS( ( MIN ) <= A && A <= ( MAX ) ) #ifdef USE_GETLINE #define SET_SEPARATE( SEPARATOR , ... ) VariadicGetline( cin , SEPARATOR , __VA_ARGS__ ) #define SET( ... ) SET_SEPARATE( '\n' , __VA_ARGS__ ) #define GETLINE_SEPARATE( SEPARATOR , ... ) string __VA_ARGS__; SET_SEPARATE( SEPARATOR , __VA_ARGS__ ) #define GETLINE( ... ) GETLINE_SEPARATE( '\n' , __VA_ARGS__ ) #else #define SET( ... ) VariadicCin( cin , __VA_ARGS__ ) #define CIN( LL , ... ) LL __VA_ARGS__; SET( __VA_ARGS__ ) #define SET_A( I , N , ... ) VariadicResize( N + I , __VA_ARGS__ ); FOR( VARIABLE_FOR_SET_A , 0 , N ){ VariadicSet( cin , VARIABLE_FOR_SET_A + I , __VA_ARGS__ ); } #define CIN_A( LL , I , N , ... ) VE __VA_ARGS__; SET_A( I , N , __VA_ARGS__ ) #define CIN_AA( LL , I0 , N0 , I1 , N1 , VAR ) VE> VAR( N0 + I0 ); FOR( VARIABLE_FOR_CIN_AA , 0 , N0 ){ SET_A( I1 , N1 , VAR[VARIABLE_FOR_CIN_AA + I0] ); } #endif #define SET_ASSERT( A , MIN , MAX ) SET( A ); ASSERT( A , MIN , MAX ) #define SOLVE_ONLY #define COUT( ... ) VariadicCout( cout , __VA_ARGS__ ) << ENDL #define COUTNS( ... ) VariadicCoutNonSep( cout , __VA_ARGS__ ) #define CERR( ... ) #define CERRNS( ... ) #define COUT_A( I , N , A ) CoutArray( cout , I , N , A ) << ENDL #define CERR_A( I , N , A ) #endif #ifdef REACTIVE #ifdef DEBUG #define RSET( A , ... ) A = __VA_ARGS__ #else #define RSET( A , ... ) SET( A ) #endif #define RCIN( LL , A , ... ) LL A; RSET( A , __VA_ARGS__ ) #define ENDL endl #else #define ENDL "\n" #endif #include using namespace std; #define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) ) #define START_MAIN int main(){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define START_WATCH chrono::system_clock::time_point watch = chrono::system_clock::now(); double loop_average_time = 0.0 , loop_start_time = 0.0 , current_time = 0.0; int loop_count = 0 #define CURRENT_TIME ( current_time = static_cast( chrono::duration_cast( chrono::system_clock::now() - watch ).count() / 1000.0 ) ) #define CHECK_WATCH( TL_MS ) ( CURRENT_TIME , loop_count == 0 ? loop_start_time = current_time : loop_average_time = ( current_time - loop_start_time ) / loop_count , ++loop_count , current_time < TL_MS - loop_average_time * 2 - 100.0 ) #define CEXPR( LL , BOUND , VALUE ) CE LL BOUND = VALUE #define SET_A_ASSERT( I , N , A , MIN , MAX ) FOR( VARIABLE_FOR_SET_A , 0 , N ){ SET_ASSERT( A[VARIABLE_FOR_SET_A + I] , MIN , MAX ); } #define SET_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) FOR( VARIABLE_FOR_SET_AA0 , 0 , N0 ){ FOR( VARIABLE_FOR_SET_AA1 , 0 , N1 ){ SET_ASSERT( A[VARIABLE_FOR_SET_AA0 + I0][VARIABLE_FOR_SET_AA1 + I1] , MIN , MAX ); } } #define CIN_ASSERT( A , MIN , MAX ) decldecay_t( MAX ) A; SET_ASSERT( A , MIN , MAX ) #define CIN_A_ASSERT( I , N , A , MIN , MAX ) vector A( N + I ); SET_A_ASSERT( I , N , A , MIN , MAX ) #define CIN_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) vector A( N0 + I0 , vector( N1 + I1 ) ); SET_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( decldecay_t( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOREQ( VAR , INITIAL , FINAL ) for( decldecay_t( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) #define FOREQINV( VAR , INITIAL , FINAL ) for( decldecay_t( INITIAL ) VAR = INITIAL ; VAR + 1 > FINAL ; VAR -- ) #define ITR( ARRAY ) auto begin_ ## ARRAY = ARRAY .BE() , itr_ ## ARRAY = begin_ ## ARRAY , end_ ## ARRAY = ARRAY .EN() #define FOR_ITR( ARRAY ) for( ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ ) #define RUN( ARRAY , ... ) for( auto&& __VA_ARGS__ : ARRAY ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT_ ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS ); cerr << fixed << setprecision( DECIMAL_DIGITS ) #define RETURN( ... ) SOLVE_ONLY; COUT( __VA_ARGS__ ); RE #define COMPARE( ... ) auto naive = Naive( __VA_ARGS__ , false ); auto answer = Answer( __VA_ARGS__ , false ); bool match = naive == answer; CERR( "(" , #__VA_ARGS__ , ") == (" , __VA_ARGS__ , ") : Naive == " , naive , match ? "==" : "!=" , answer , "== Answer" ); if( !match ){ RE; } /* 圧縮用 */ #define TE template #define TY typename #define US using #define ST static #define AS assert #define IN inline #define CL class #define PU public #define OP operator #define CE constexpr #define CO const #define NE noexcept #define RE return #define WH while #define VO void #define VE vector #define LI list #define BE begin #define EN end #define SZ size #define LE length #define PW Power #define MO move #define TH this #define CRI CO int& #define CRUI CO uint& #define CRL CO ll& #define VI virtual #define IS basic_istream #define OS basic_ostream #define ST_AS static_assert #define reMO_CO remove_const #define is_COructible_v is_constructible_v #define rBE rbegin /* 型のエイリアス */ #define decldecay_t(VAR)decay_t TE US ret_t = decltype(declval()(declval()...)); TE US inner_t = TY T::type; US uint = unsigned int; US ll = long long; US ull = unsigned long long; US ld = long double; US lld = __float128; TE US T2 = pair; TE US T3 = tuple; TE US T4 = tuple; US path = pair; /* VVV 常設ライブラリは以下に挿入する。*/ #ifdef DEBUG #include "C:/Users/user/Documents/Programming/Contest/Template/Local/a_Body.hpp" #else /* Random (1KB)*/ ll GetRand(CRI Rand_min,CRI Rand_max){AS(Rand_min <= Rand_max);ll AN = time(NULL);RE AN * rand()%(Rand_max + 1 - Rand_min)+ Rand_min;} /* Set (1KB)*/ #define DC_OF_HASH(...)struct hash<__VA_ARGS__>{IN size_t OP()(CO __VA_ARGS__& n)CO;}; CL is_ordered{PU:is_ordered()= delete;TE ST CE auto Check(CO T& t)-> decltype(t < t,true_type());ST CE false_type Check(...);TE ST CE CO bool value = is_same_v< decltype(Check(declval())),true_type >;}; TE US Set = conditional_t>,unordered_set,conditional_t,set,VO>>; /* Tuple (5KB)*/ #define DF_OF_AR_FOR_TUPLE(OPR)TE TY V> IN auto OP OPR ## =(V& t0,CO V& t1)-> decltype((get<0>(t0),t0))&{get<0>(t0)OPR ## = get<0>(t1);get<1>(t0)OPR ## = get<1>(t1);RE t0;}TE IN tuple& OP OPR ## =(tuple& t0,CO tuple& t1){get<0>(t0)OPR ## = get<0>(t1);get<1>(t0)OPR ## = get<1>(t1);get<2>(t0)OPR ## = get<2>(t1);RE t0;}TE IN tuple& OP OPR ## =(tuple& t0,CO tuple& t1){get<0>(t0)OPR ## = get<0>(t1);get<1>(t0)OPR ## = get<1>(t1);get<2>(t0)OPR ## = get<2>(t1);get<3>(t0)OPR ## = get<3>(t1);RE t0;}TE TY V> IN auto OP OPR ## =(V& t0,CO ARG& t1)-> decltype((get<0>(t0),t0))&{get<0>(t0)OPR ## = t1;get<1>(t0)OPR ## = t1;RE t0;}TE IN tuple& OP OPR ## =(tuple& t0,CO ARG& t1){get<0>(t0)OPR ## = t1;get<1>(t0)OPR ## = t1;get<2>(t0)OPR ## = t1;RE t0;}TE IN tuple& OP OPR ## =(tuple& t0,CO ARG& t1){get<0>(t0)OPR ## = t1;get<1>(t0)OPR ## = t1;get<2>(t0)OPR ## = t1;get<3>(t0)OPR ## = t1;RE t0;}TE TY V,TY...ARGS,TY ARG> IN auto OP OPR(CO V& t0,CO ARG& t1)-> decldecay_t((get<0>(t0),t0)){auto t = t0;RE MO(t OPR ## = t1);} #define DF_OF_INCREMENT_FOR_TUPLE(INCR)TE TY V> IN auto OP INCR(V& t)-> decltype((get<0>(t),t))&{INCR get<0>(t);INCR get<1>(t);RE t;}TE IN tuple& OP INCR(tuple& t){INCR get<0>(t);INCR get<1>(t);INCR get<2>(t);RE t;}TE IN tuple& OP INCR(tuple& t){INCR get<0>(t);INCR get<1>(t);INCR get<2>(t);INCR get<3>(t);RE t;} TE IN IS& OP>>(IS& is,tuple& arg){RE is >> get<0>(arg);}TE TY V> IN auto OP>>(IS& is,V& arg)-> decltype((get<0>(arg),is))&{RE is >> get<0>(arg)>> get<1>(arg);}TE IN IS& OP>>(IS& is,tuple& arg){RE is >> get<0>(arg)>> get<1>(arg)>> get<2>(arg);}TE IN IS& OP>>(IS& is,tuple& arg){RE is >> get<0>(arg)>> get<1>(arg)>> get<2>(arg)>> get<3>(arg);}TE IN OS& OP<<(OS& os,CO tuple& arg){RE os << get<0>(arg);}TE TY V> IN auto OP<<(OS& os,CO V& arg)-> decltype((get<0>(arg),os))&{RE os << get<0>(arg)<< " " << get<1>(arg);}TE IN OS& OP<<(OS& os,CO tuple& arg){RE os << get<0>(arg)<< " " << get<1>(arg)<< " " << get<2>(arg);}TE IN OS& OP<<(OS& os,CO tuple& arg){RE os << get<0>(arg)<< " " << get<1>(arg)<< " " << get<2>(arg)<< " " << get<3>(arg);}DF_OF_AR_FOR_TUPLE(+);TE TY V> IN auto OP-(CO V& t)-> decltype(get<0>(t),t){RE{-get<0>(t),-get<1>(t)};}TE IN tuple OP-(CO tuple& t){RE{-get<0>(t),-get<1>(t),-get<2>(t)};}TE IN tuple OP-(CO tuple& t){RE{-get<0>(t),-get<1>(t),-get<2>(t),-get<3>(t)};}DF_OF_AR_FOR_TUPLE(-);DF_OF_AR_FOR_TUPLE(*);DF_OF_AR_FOR_TUPLE(/);DF_OF_AR_FOR_TUPLE(%);DF_OF_INCREMENT_FOR_TUPLE(++);DF_OF_INCREMENT_FOR_TUPLE(--); #define DF_OF_HASH_FOR_TUPLE(PAIR)TE IN size_t hash>::OP()(CO PAIR& n)CO{ST CO size_t seed =(GetRand(1e3,1e8)<< 1)| 1;ST CO hash h0;ST CO hash h1;RE(h0(get<0>(n))* seed)^ h1(get<1>(n));} TE DC_OF_HASH(tuple);TE DC_OF_HASH(pair);TE DC_OF_HASH(tuple);TE DC_OF_HASH(tuple);TE DC_OF_HASH(tuple); TE IN size_t hash>::OP()(CO tuple& n)CO{ST CO hash h;RE h(get<0>(n));}DF_OF_HASH_FOR_TUPLE(pair);DF_OF_HASH_FOR_TUPLE(tuple);TE IN size_t hash>::OP()(CO tuple& n)CO{ST CO size_t seed =(GetRand(1e3,1e8)<< 1)| 1;ST CO hash> h01;ST CO hash h2;RE(h01({get<0>(n),get<1>(n)})* seed)^ h2(get<2>(n));}TE IN size_t hash>::OP()(CO tuple& n)CO{ST CO size_t seed =(GetRand(1e3,1e8)<< 1)| 1;ST CO hash> h01;ST CO hash> h23;RE(h01({get<0>(n),get<1>(n)})* seed)^ h23({get<2>(n),get<3>(n)});} /* Vector (2KB)*/ #define DF_OF_COUT_FOR_VE(V)TE IN OS& OP<<(OS& os,CO V& arg){auto BE = arg.BE(),EN = arg.EN();auto IT = BE;WH(IT != EN){(IT == BE?os:os << " ")<< *IT;IT++;}RE os;} #define DF_OF_AR_FOR_VE(V,OPR)TE IN V& OP OPR ## =(V& a,CO T& t){for(auto& s:a){s OPR ## = t;}RE a;}TE IN V& OP OPR ## =(V& a0,CO V& a1){AS(a0.SZ()<= a1.SZ());auto IT0 = a0.BE(),EN0 = a0.EN();auto IT1 = a1.BE();WH(IT0 != EN0){*(IT0++)OPR ## = *(IT1++);}RE a0;}TE IN V OP OPR(V a,CO U& u){RE MO(a OPR ## = u);} #define DF_OF_INCREMENT_FOR_VE(V,INCR)TE IN V& OP INCR(V& a){for(auto& i:a){INCR i;}RE a;} #define DF_OF_ARS_FOR_VE(V)DF_OF_AR_FOR_VE(V,+);DF_OF_AR_FOR_VE(V,-);DF_OF_AR_FOR_VE(V,*);DF_OF_AR_FOR_VE(V,/);DF_OF_AR_FOR_VE(V,%);DF_OF_INCREMENT_FOR_VE(V,++);DF_OF_INCREMENT_FOR_VE(V,--);TE IN V OP*(CO T& scalar,V v){for(auto& t:v){t *= scalar;}RE MO(v);} DF_OF_COUT_FOR_VE(VE);DF_OF_COUT_FOR_VE(LI);DF_OF_ARS_FOR_VE(VE);DF_OF_ARS_FOR_VE(LI);IN VO VariadicResize(CRI SZ){}TE IN VO VariadicResize(CRI SZ,Arg& arg,ARGS&... args){arg.resize(SZ);VariadicResize(SZ,args...);}TE IN auto Get(V& a){RE[&](CRI i = 0)-> CO decldecay_t(a[0])&{RE a[i];};}TE IN VE id(CRI SZ){VE AN(SZ);FOR(i,0,SZ){AN[i]= i;}RE AN;}TE VO Sort(VE& a,CO bool& reversed = false){if(reversed){ST auto comp =[](CO T& t0,CO T& t1){RE t1 < t0;};sort(a.BE(),a.EN(),comp);}else{sort(a.BE(),a.EN());}}TE IN VE IndexSort(CO VE& a,CO bool& reversed = false){auto index = id(a.SZ());if(reversed){sort(index.BE(),index.EN(),[&](CRI i,CRI j){RE a[j]< a[i];});}else{sort(index.BE(),index.EN(),[&](CRI i,CRI j){RE a[i]< a[j];});}RE index;}TE IN U Sum(CO VE& a){U AN{};for(auto& x:a){AN += x;}RE AN;}TE IN U Product(CO VE& a){U AN{};for(auto& x:a){AN *= x;}RE AN;} /* Map (1KB)*/ #define DF_OF_AR_FOR_MAP(MAP,OPR)TE IN MAP& OP OPR ## =(MAP& a,CO pair& v){a[v.first]OPR ## = v.second;RE a;}TE IN MAP& OP OPR ## =(MAP& a0,CO MAP& a1){for(auto&[t,u]:a1){a0[t]OPR ## = u;}RE a0;}TE IN MAP OP OPR(MAP a,CO ARG& arg){RE MO(a OPR ## = arg);} #define DF_OF_ARS_FOR_MAP(MAP)DF_OF_AR_FOR_MAP(MAP,+);DF_OF_AR_FOR_MAP(MAP,-);DF_OF_AR_FOR_MAP(MAP,*);DF_OF_AR_FOR_MAP(MAP,/);DF_OF_AR_FOR_MAP(MAP,%); TE US Map = conditional_t>,unordered_map,conditional_t,map,VO>>; DF_OF_ARS_FOR_MAP(map);DF_OF_ARS_FOR_MAP(unordered_map); /* StdStream (2KB)*/ TE IN IS& VariadicCin(IS& is){RE is;}TE IN IS& VariadicCin(IS& is,Arg& arg,ARGS&... args){RE VariadicCin(is >> arg,args...);}TE IN IS& VariadicSet(IS& is,CRI i){RE is;}TE IN IS& VariadicSet(IS& is,CRI i,Arg& arg,ARGS&... args){RE VariadicSet(is >> arg[i],i,args...);}TE IN IS& VariadicGetline(IS& is,CO char& separator){RE is;}TE IN IS& VariadicGetline(IS& is,CO char& separator,Arg& arg,ARGS&... args){RE VariadicGetline(getline(is,arg,separator),separator,args...);}TE IN OS& VariadicCout(OS& os,Arg&& arg){RE os << forward(arg);}TE IN OS& VariadicCout(OS& os,Arg1&& arg1,Arg2&& arg2,ARGS&&... args){RE VariadicCout(os << forward(arg1)<< " ",forward(arg2),forward(args)...);}TE IN OS& VariadicCoutNonSep(OS& os,Arg&& arg){RE os << forward(arg);}TE IN OS& VariadicCoutNonSep(OS& os,Arg1&& arg1,Arg2&& arg2,ARGS&&... args){RE VariadicCoutNonSep(os << forward(arg1),forward(arg2),forward(args)...);}TE IN OS& CoutArray(OS& os,CRI i_start,CRI i_ulim,ARRAY&& a){for(int i = i_start;i < i_ulim;i++){(i == i_start?os:(os << " "))<< a[i];}RE os;} /* Module (6KB)*/ #define DC_OF_CPOINT(POINT)IN CO U& POINT()CO NE #define DC_OF_POINT(POINT)IN U& POINT()NE #define DF_OF_CPOINT(POINT)TE IN CO U& VirtualPointedSet::POINT()CO NE{RE Point();} #define DF_OF_POINT(POINT)TE IN U& VirtualPointedSet::POINT()NE{RE Point();} TE CL UnderlyingSet{PU:US type = U;};TE CL VirtualPointedSet:VI PU UnderlyingSet{PU:VI CO U& Point()CO NE = 0;VI U& Point()NE = 0;DC_OF_CPOINT(Unit);DC_OF_CPOINT(Zero);DC_OF_CPOINT(One);DC_OF_CPOINT(Infty);DC_OF_POINT(init);DC_OF_POINT(root);};TE CL PointedSet:VI PU VirtualPointedSet{PU:U m_b_U;IN PointedSet(U b_u = U());IN CO U& Point()CO NE;IN U& Point()NE;};TE CL VirtualNSet:VI PU UnderlyingSet{PU:VI U Transfer(CO U& u)= 0;IN U Inverse(CO U& u);};TE CL AbstractNSet:VI PU VirtualNSet{PU:F_U m_f_U;IN AbstractNSet(F_U f_U);IN AbstractNSet& OP=(CO AbstractNSet&)NE;IN U Transfer(CO U& u);};TE CL VirtualMagma:VI PU UnderlyingSet{PU:VI U Product(U u0,CO U& u1)= 0;IN U Sum(U u0,CO U& u1);};TE CL AdditiveMagma:VI PU VirtualMagma{PU:IN U Product(U u0,CO U& u1);};TE CL MultiplicativeMagma:VI PU VirtualMagma{PU:IN U Product(U u0,CO U& u1);};TE CL AbstractMagma:VI PU VirtualMagma{PU:M_U m_m_U;IN AbstractMagma(M_U m_U);IN AbstractMagma& OP=(CO AbstractMagma&)NE;IN U Product(U u0,CO U& u1);}; TE IN PointedSet::PointedSet(U b_U):m_b_U(MO(b_U)){}TE IN CO U& PointedSet::Point()CO NE{RE m_b_U;}TE IN U& PointedSet::Point()NE{RE m_b_U;}DF_OF_CPOINT(Unit);DF_OF_CPOINT(Zero);DF_OF_CPOINT(One);DF_OF_CPOINT(Infty);DF_OF_POINT(init);DF_OF_POINT(root);TE IN AbstractNSet::AbstractNSet(F_U f_U):m_f_U(MO(f_U)){ST_AS(is_invocable_r_v);}TE IN AbstractNSet& AbstractNSet::operator=(CO AbstractNSet&)NE{RE *TH;}TE IN U AbstractNSet::Transfer(CO U& u){RE m_f_U(u);}TE IN U VirtualNSet::Inverse(CO U& u){RE Transfer(u);}TE IN AbstractMagma::AbstractMagma(M_U m_U):m_m_U(MO(m_U)){ST_AS(is_invocable_r_v);}TE IN AbstractMagma& AbstractMagma::OP=(CO AbstractMagma&)NE{RE *TH;}TE IN U AdditiveMagma::Product(U u0,CO U& u1){RE MO(u0 += u1);}TE IN U MultiplicativeMagma::Product(U u0,CO U& u1){RE MO(u0 *= u1);}TE IN U AbstractMagma::Product(U u0,CO U& u1){RE m_m_U(MO(u0),u1);}TE IN U VirtualMagma::Sum(U u0,CO U& u1){RE Product(MO(u0),u1);} TE CL VirtualMonoid:VI PU VirtualMagma,VI PU VirtualPointedSet{};TE CL AdditiveMonoid:VI PU VirtualMonoid,PU AdditiveMagma,PU PointedSet{};TE CL MultiplicativeMonoid:VI PU VirtualMonoid,PU MultiplicativeMagma,PU PointedSet{PU:IN MultiplicativeMonoid(U e_U);};TE CL AbstractMonoid:VI PU VirtualMonoid,PU AbstractMagma,PU PointedSet{PU:IN AbstractMonoid(M_U m_U,U e_U);}; TE IN MultiplicativeMonoid::MultiplicativeMonoid(U e_U):PointedSet(MO(e_U)){}TE IN AbstractMonoid::AbstractMonoid(M_U m_U,U e_U):AbstractMagma(MO(m_U)),PointedSet(MO(e_U)){} TE CL VirtualGroup:VI PU VirtualMonoid,VI PU VirtualPointedSet,VI PU VirtualNSet{};TE CL AdditiveGroup:VI PU VirtualGroup,PU AdditiveMonoid{PU:IN U Transfer(CO U& u);};TE CL AbstractGroup:VI PU VirtualGroup,PU AbstractMonoid,PU AbstractNSet{PU:IN AbstractGroup(M_U m_U,U e_U,I_U i_U);}; TE IN AbstractGroup::AbstractGroup(M_U m_U,U e_U,I_U i_U):AbstractMonoid(MO(m_U),MO(e_U)),AbstractNSet(MO(i_U)){}TE IN U AdditiveGroup::Transfer(CO U& u){RE -u;} TE CL VirtualRSet:VI PU UnderlyingSet{PU:VI U Action(CO R& r,U u)= 0;IN U PW(U u,CO R& r);IN U ScalarProduct(CO R& r,U u);};TE CL RegularRSet:VI PU VirtualRSet,PU MAGMA{PU:IN RegularRSet(MAGMA magma);IN U Action(CO U& r,U u);};TE RegularRSet(MAGMA magma)-> RegularRSet,MAGMA>;TE CL AbstractRSet:VI PU VirtualRSet{PU:O_U m_o_U;IN AbstractRSet(CO R& dummy0,CO U& dummy1,O_U o_U);IN AbstractRSet& OP=(CO AbstractRSet&)NE;IN U Action(CO R& r,U u);};TE CL AbstractModule:PU AbstractRSet,PU GROUP{PU:IN AbstractModule(CO R& dummy,O_U o_U,GROUP M);};TE AbstractModule(CO R& dummy,O_U o_U,GROUP M)-> AbstractModule,O_U,GROUP>;TE CL Module:VI PU VirtualRSet,PU AdditiveGroup{PU:IN U Action(CO R& r,U u);}; TE IN RegularRSet::RegularRSet(MAGMA magma):MAGMA(MO(magma)){}TE IN AbstractRSet::AbstractRSet(CO R& dummy0,CO U& dummy1,O_U o_U):m_o_U(MO(o_U)){ST_AS(is_invocable_r_v);}TE IN AbstractModule::AbstractModule(CO R& dummy,O_U o_U,GROUP M):AbstractRSet(dummy,M.One(),MO(o_U)),GROUP(MO(M)){ST_AS(is_same_v>);}TE IN AbstractRSet& AbstractRSet::OP=(CO AbstractRSet&)NE{RE *TH;}TE IN U RegularRSet::Action(CO U& r,U u){RE TH->Product(r,MO(u));}TE IN U AbstractRSet::Action(CO R& r,U u){RE m_o_U(r,MO(u));}TE IN U Module::Action(CO R& r,U u){RE MO(u *= r);}TE IN U VirtualRSet::PW(U u,CO R& r){RE Action(r,MO(u));}TE IN U VirtualRSet::ScalarProduct(CO R& r,U u){RE Action(r,MO(u));} /* ConstexprModulo (7KB)*/ CEXPR(uint,P,998244353); #define RP Represent #define DeRP Derepresent TE CE INT Residue(INT n)NE{RE MO(n < 0?((((++n)*= -1)%= M)*= -1)+= M - 1:n < INT(M)?n:n %= M);}TE CE INT& ResidueP(INT& n)NE{CE CO uint trunc =(1 << 23)- 1;INT n_u = n >> 23;n &= trunc;INT n_uq =(n_u / 7)/ 17;n_u -= n_uq * 119;n += n_u << 23;RE n < n_uq?n += P - n_uq:n -= n_uq;} TE CL Mod;TE CL COantsForMod{PU:COantsForMod()= delete;ST CE CO uint g_memory_bound = 1e6;ST CE CO uint g_memory_LE = M < g_memory_bound?M:g_memory_bound;ST CE uint g_M_minus = M - 1;ST CE int g_order_minus_1 = M - 2;ST CE int g_order_minus_1_neg = -g_order_minus_1;}; #define SFINAE_FOR_MOD enable_if_t>>* #define DC_OF_CM_FOR_MOD(OPR)CE bool OP OPR(CO Mod& n)CO NE #define DC_OF_AR_FOR_MOD(OPR,EX)CE Mod OP OPR(Mod n)CO EX; #define DF_OF_CM_FOR_MOD(OPR)TE CE bool Mod::OP OPR(CO Mod& n)CO NE{RE m_n OPR n.m_n;} #define DF_OF_AR_FOR_MOD(OPR,EX,LEFT,OPR2)TE CE Mod Mod::OP OPR(Mod n)CO EX{RE MO(LEFT OPR2 ## = *TH);}TE CE Mod OP OPR(T n0,CO Mod& n1)EX{RE MO(Mod(MO(n0))OPR ## = n1);} TE CL Mod{PU:uint m_n;CE Mod()NE;CE Mod(CO Mod& n)NE;CE Mod(Mod&& n)NE;TE CE Mod(T n)NE;CE Mod& OP=(Mod n)NE;CE Mod& OP+=(CO Mod& n)NE;CE Mod& OP-=(CO Mod& n)NE;CE Mod& OP*=(CO Mod& n)NE;IN Mod& OP/=(Mod n);TE CE Mod& OP<<=(INT n);TE CE Mod& OP>>=(INT n);CE Mod& OP++()NE;CE Mod OP++(int)NE;CE Mod& OP--()NE;CE Mod OP--(int)NE;DC_OF_CM_FOR_MOD(==);DC_OF_CM_FOR_MOD(!=);DC_OF_CM_FOR_MOD(<);DC_OF_CM_FOR_MOD(<=);DC_OF_CM_FOR_MOD(>);DC_OF_CM_FOR_MOD(>=);DC_OF_AR_FOR_MOD(+,NE);DC_OF_AR_FOR_MOD(-,NE);DC_OF_AR_FOR_MOD(*,NE);DC_OF_AR_FOR_MOD(/,);TE CE Mod OP^(INT EX)CO;TE CE Mod OP<<(INT n)CO;TE CE Mod OP>>(INT n)CO;CE Mod OP-()CO NE;CE Mod& SignInvert()NE;IN Mod& Invert();TE CE Mod& PW(INT EX);CE VO swap(Mod& n)NE;CE CRUI RP()CO NE;ST CE Mod DeRP(uint n)NE;ST IN CO Mod& Inverse(CRUI n);ST IN CO Mod& Factorial(CRUI n);ST IN CO Mod& FactorialInverse(CRUI n);ST IN Mod Combination(CRUI n,CRUI i);ST IN CO Mod& zero()NE;ST IN CO Mod& one()NE;ST IN CE uint GetModulo()NE;TE CE Mod& PositivePW(INT EX)NE;TE CE Mod& NonNegativePW(INT EX)NE;US COants = COantsForMod;}; US MP = Mod

; TE CE Mod::Mod()NE:m_n(){}TE CE Mod::Mod(CO Mod& n)NE:m_n(n.m_n){}TE CE Mod::Mod(Mod&& n)NE:m_n(MO(n.m_n)){}TE TE CE Mod::Mod(T n)NE:m_n(Residue(MO(n))){}TE CE Mod& Mod::OP=(Mod n)NE{m_n = MO(n.m_n);RE *TH;}TE CE Mod& Mod::OP+=(CO Mod& n)NE{(m_n += n.m_n)< M?m_n:m_n -= M;RE *TH;}TE CE Mod& Mod::OP-=(CO Mod& n)NE{m_n < n.m_n?(m_n += M)-= n.m_n:m_n -= n.m_n;RE *TH;}TE CE Mod& Mod::OP*=(CO Mod& n)NE{m_n = MO(ull(m_n)* n.m_n)% M;RE *TH;}TE <> CE MP& MP::OP*=(CO MP& n)NE{ull m_n_copy = m_n;m_n = MO((m_n_copy *= n.m_n)< P?m_n_copy:ResidueP(m_n_copy));RE *TH;}TE IN Mod& Mod::OP/=(Mod n){RE OP*=(n.Invert());}TE TE CE Mod& Mod::OP<<=(INT n){AS(n >= 0);RE *TH *= Mod(2).NonNegativePW(MO(n));}TE TE CE Mod& Mod::OP>>=(INT n){AS(n >=0);WH(n-- > 0){((m_n & 1)== 0?m_n:m_n += M)>>= 1;}RE *TH;}TE CE Mod& Mod::OP++()NE{m_n < COants::g_M_minus?++m_n:m_n = 0;RE *TH;}TE CE Mod Mod::OP++(int)NE{Mod n{*TH};OP++();RE n;}TE CE Mod& Mod::OP--()NE{m_n == 0?m_n = COants::g_M_minus:--m_n;RE *TH;}TE CE Mod Mod::OP--(int)NE{Mod n{*TH};OP--();RE n;}DF_OF_CM_FOR_MOD(==);DF_OF_CM_FOR_MOD(!=);DF_OF_CM_FOR_MOD(>);DF_OF_CM_FOR_MOD(>=);DF_OF_CM_FOR_MOD(<);DF_OF_CM_FOR_MOD(<=);DF_OF_AR_FOR_MOD(+,NE,n,+);DF_OF_AR_FOR_MOD(-,NE,n.SignInvert(),+);DF_OF_AR_FOR_MOD(*,NE,n,*);DF_OF_AR_FOR_MOD(/,,n.Invert(),*);TE TE CE Mod Mod::OP^(INT EX)CO{RE MO(Mod(*TH).PW(MO(EX)));}TE TE CE Mod Mod::OP<<(INT n)CO{RE MO(Mod(*TH)<<= MO(n));}TE TE CE Mod Mod::OP>>(INT n)CO{RE MO(Mod(*TH)>>= MO(n));}TE CE Mod Mod::OP-()CO NE{RE MO(Mod(*TH).SignInvert());}TE CE Mod& Mod::SignInvert()NE{m_n > 0?m_n = M - m_n:m_n;RE *TH;}TE IN Mod& Mod::Invert(){AS(m_n != 0);uint m_n_neg;RE m_n < COants::g_memory_LE?(m_n = Inverse(m_n).m_n,*TH):((m_n_neg = M - m_n)< COants::g_memory_LE)?(m_n = M - Inverse(m_n_neg).m_n,*TH):NonNegativePW(COants::g_order_minus_1);}TE TE CE Mod& Mod::PositivePW(INT EX)NE{Mod PW{*TH};EX--;WH(EX != 0){(EX & 1)== 1?*TH *= PW:*TH;EX >>= 1;PW *= PW;}RE *TH;}TE TE CE Mod& Mod::NonNegativePW(INT EX)NE{RE EX == 0?(m_n = 1,*TH):PositivePW(MO(EX));}TE TE CE Mod& Mod::PW(INT EX){bool neg = EX < 0;AS(!(neg && m_n == 0));RE neg?PositivePW(ll(MO(EX %= COants::g_M_minus))* COants::g_order_minus_1_neg %COants::g_M_minus):NonNegativePW(MO(EX));}TE CE VO Mod::swap(Mod& n)NE{std::swap(m_n,n.m_n);}TE IN CO Mod& Mod::Inverse(CRUI n){AS(n < M);ST VE> memory ={zero(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory.push_back(DeRP(M - memory[M % LE_curr].m_n * ull(M / LE_curr)% M));LE_curr++;}RE memory[n];}TE IN CO Mod& Mod::Factorial(CRUI n){if(M <= n){RE zero();}ST VE> memory ={one(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory.push_back(memory[LE_curr - 1]* LE_curr);LE_curr++;}RE memory[n];}TE IN CO Mod& Mod::FactorialInverse(CRUI n){ST VE> memory ={one(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory.push_back(memory[LE_curr - 1]* Inverse(LE_curr));LE_curr++;}RE memory[n];}TE IN Mod Mod::Combination(CRUI n,CRUI i){RE i <= n?Factorial(n)* FactorialInverse(i)* FactorialInverse(n - i):zero();}TE CE CRUI Mod::RP()CO NE{RE m_n;}TE CE Mod Mod::DeRP(uint n)NE{Mod n_copy{};n_copy.m_n = MO(n);RE n_copy;}TE IN CO Mod& Mod::zero()NE{ST CE CO Mod z{};RE z;}TE IN CO Mod& Mod::one()NE{ST CE CO Mod o{1};RE o;}TE IN CE uint Mod::GetModulo()NE{RE M;}TE IN Mod Inverse(CO Mod& n){RE MO(Mod(n).Invert());}TE CE Mod PW(Mod n,INT EX){RE MO(n.PW(MO(EX)));}TE CE VO swap(Mod& n0,Mod& n1)NE{n0.swap(n1);}TE IN string to_string(CO Mod& n)NE{RE to_string(n.RP())+ " + " + to_string(M)+ "Z";}TE IN IS& OP>>(IS& is,Mod& n){ll m;is >> m;n = m;RE is;}TE IN OS& OP<<(OS& os,CO Mod& n){RE os << n.RP();} #define DF_OF_HASH_FOR_MOD(MOD)IN size_t hash::OP()(CO MOD& n)CO{ST CO hash h;RE h(n.RP());} TE DC_OF_HASH(Mod); TE DF_OF_HASH_FOR_MOD(Mod); /* Loop (1KB)*/ TE bool NextLoop(CRI SZ,CO VE& lower_bound,CO VE& upper_limit,VE& index){int depth = 0;WH(depth < SZ){if(++index[depth]< upper_limit[depth]){break;}index[depth]= lower_bound[depth];depth++;}RE depth < SZ;}TE bool NextLoop(CO VE& lower_bound,CO VE& upper_limit,VE& index){RE NextLoop(index.SZ(),lower_bound,upper_limit,index);}TE bool NextLoopEq(CRI SZ,CO VE& lower_bound,CO VE& upper_bound,VE& index){int depth = 0;WH(depth < SZ){if(++index[depth]<= upper_bound[depth]){break;}index[depth]= lower_bound[depth];depth++;}RE depth < SZ;}TE bool NextLoopEq(CO VE& lower_bound,CO VE& upper_bound,VE& index){RE NextLoopEq(index.SZ(),lower_bound,upper_bound,index);} /* string (1KB)*/ TE IN char IntToChar(CO INT& i,CO char& c = 'a'){RE c + i;}TE IN INT CharToInt(CO char& i){RE i -(i < 'a'?'A':'a');}TE string ArrayToString(CO VE& A,CO char& c = 'a'){CO int N = A.SZ();string S(N,c);for(int i = 0;i < N;i++){S[i]= IntToChar(A[i],c);}RE S;}TE VE StringToArray(CO string& S){CO int N = S.SZ();VE A(N);for(int i = 0;i < N;i++){A[i]= CharToInt(S[i]);}RE A;} #endif /* AAA 常設ライブラリは以上に挿入する。*/ #define INCLUDE_LIBRARY #include __FILE__ #endif /* INCLUDE_LIBRARY */ #endif /* INCLUDE_SUB */ #endif /* INCLUDE_MAIN */