結果

問題 No.2683 Two Sheets
ユーザー 👑 p-adicp-adic
提出日時 2024-03-22 12:16:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 57,214 bytes
コンパイル時間 11,639 ms
コンパイル使用メモリ 346,468 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2024-11-15 05:46:56
合計ジャッジ時間 14,066 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 106 ms
7,768 KB
testcase_03 AC 106 ms
9,824 KB
testcase_04 AC 109 ms
7,732 KB
testcase_05 AC 109 ms
7,856 KB
testcase_06 AC 110 ms
9,936 KB
testcase_07 AC 107 ms
9,940 KB
testcase_08 AC 107 ms
7,732 KB
testcase_09 AC 106 ms
9,748 KB
testcase_10 AC 106 ms
7,728 KB
testcase_11 AC 108 ms
7,860 KB
testcase_12 AC 109 ms
7,860 KB
testcase_13 AC 112 ms
7,856 KB
testcase_14 AC 108 ms
7,980 KB
testcase_15 AC 110 ms
7,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef INCLUDE_MODE
  #define INCLUDE_MODE
  // #define REACTIVE
  // #define USE_GETLINE
#endif

#ifdef INCLUDE_MAIN

IN VO Solve()
{
  CIN( int , H , W , A , B );
  RETURN( GridStampCoveringEpxpectation<MP>( H , W , A , B , 2 ) );
}
REPEAT_MAIN(1);

#else // INCLUDE_MAIN

#ifdef INCLUDE_SUB

// COMPAREに使用。圧縮時は削除する。
ll Naive( ll N , ll M , ll K )
{
  ll answer = N + M + K;
  return answer;
}

// COMPAREに使用。圧縮時は削除する。
ll Answer( ll N , ll M , ll K )
{
  // START_WATCH;
  ll answer = N + M + K;

  // // TLに準じる乱択や全探索。デフォルトの猶予は100.0[ms]。
  // CEXPR( double , TL , 2000.0 );
  // while( CHECK_WATCH( TL ) ){

  // }
  return answer;
}

// 圧縮時は中身だけ削除する。
IN VO Experiment()
{
  // CEXPR( int , bound , 10 );
  // FOREQ( N , 0 , bound ){
  //   FOREQ( M , 0 , bound ){
  //     FOREQ( K , 0 , bound ){
  //   	COUT( N , M , K , ":" , Naive( N , M , K ) );
  //     }
  //   }
  //   // cout << Naive( N ) << ",\n"[N==bound];
  // }
}

// 圧縮時は中身だけ削除する。
IN VO SmallTest()
{
  // CEXPR( int , bound , 10 );
  // FOREQ( N , 0 , bound ){
  //   FOREQ( M , 0 , bound ){
  //     FOREQ( K , 0 , bound ){
  //   	COMPARE( N , M , K );
  //     }
  //   }
  // }
}

// 圧縮時は中身だけ削除する。
IN VO RandomTest()
{
  // CEXPR( int , bound_N , 1e5 ); CIN_ASSERT( N , 1 , bound_N );
  // CEXPR( ll , bound_M , 1e18 ); CIN_ASSERT( M , 1 , bound_M );
  // CEXPR( ll , bound_K , 1e9 ); CIN_ASSERT( K , 1 , bound_K );
  // COMPARE( N , M , N );
}

#define INCLUDE_MAIN
#include __FILE__

#else // INCLUDE_SUB

#ifdef INCLUDE_LIBRARY

/*

C-x 3 C-x o C-x C-fによるファイル操作用

BFS (5KB)
c:/Users/user/Documents/Programming/Mathematics/Geometry/Graph/BreadthFirstSearch/compress.txt

CoordinateCompress (3KB)
c:/Users/user/Documents/Programming/Mathematics/SetTheory/DirectProduct/CoordinateCompress/compress.txt

DFSOnTree (11KB)
c:/Users/user/Documents/Programming/Mathematics/Geometry/Graph/DepthFirstSearch/Tree/a.hpp

Divisor (4KB)
c:/Users/user/Documents/Programming/Mathematics/Arithmetic/Prime/Divisor/compress.txt

IntervalAddBIT (9KB)
c:/Users/user/Documents/Programming/Mathematics/SetTheory/DirectProduct/AffineSpace/BIT/IntervalAdd/compress.txt

Polynomial (21KB)
c:/Users/user/Documents/Programming/Mathematics/Polynomial/compress.txt

UnionFind (3KB)
c:/Users/user/Documents/Programming/Mathematics/Geometry/Graph/UnionFindForest/compress.txt

*/

// VVV 常設でないライブラリは以下に挿入する。

#define PO Polynomial
#define TRPO TruncatedPolynomial

TE <TY T,int EX_lim>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 <TY T,int EX_lim> CE PW3PW_CE<T,EX_lim>::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 <TY T,int EX_lim> CE CO T& PW3PW_CE<T,EX_lim>::OP[](CRI i)CO{AS(i < EX_lim);RE m_val[i];}TE <TY T,int EX_lim> CE CO T(&PW3PW_CE<T,EX_lim>::Get()CO)[EX_lim]{RE m_val;}
#define PS_FOR_FFT(MOD,LE,BORDER,PR,IPR,MINT)ST_AS((MINT<MOD>::DeRP(PR)*= MINT<MOD>::DeRP(IPR))== MINT<MOD>::DeRP(1));TE <> CE CO uint LimitOfPWForFFT<MINT<MOD> > = LE - 1;TE <> CE CO uint BorderForFFT<MINT<MOD> > = BORDER;TE <> IN CO MINT<MOD>(&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<MINT<MOD> >]{ST CE PW3PW_CE<MINT<MOD>,LimitOfPWForFFT<MINT<MOD> > > PRT{PR};ST_AS(PRT.m_val[0]== MINT<MOD>::DeRP(1));RE PRT.Get();}TE <> IN CO MINT<MOD>(&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<MINT<MOD> >]{ST CE PW3PW_CE<MINT<MOD>,LimitOfPWForFFT<MINT<MOD> > > IPRT{IPR};ST_AS(IPRT.m_val[0]== MINT<MOD>::DeRP(1)&&(MINT<MOD>::DeRP(PR)*= MINT<MOD>::DeRP(IPR))== MINT<MOD>::DeRP(1));RE IPRT.Get();}
TE <TY T> CE CO uint LimitOfPWForFFT{};TE <TY T> CE CO uint BorderForFFT{};TE <TY T> IN CO T(&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<T>];TE <TY T> IN CO T(&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<T>];
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 <TY T> VO CooleyTukey(VE<T>& 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<T>]){CO uint LE = two_PW + N_input_start + N_output_start;f.reserve(LE);WH(f.SZ()< LE){f.push_back(0);}ST VE<uint> bit_reverse[32]={VE<uint>(1)};ST uint e_next = 1;ST uint two_PW_next = 1;ST uint two_PW_next2 = 2;ST VE<uint>* p_bit_reverse_prev = bit_reverse;ST VE<uint>* p_bit_reverse_curr = p_bit_reverse_prev + 1;WH(e_next <= EX){*p_bit_reverse_curr = VE<uint>(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<uint>& 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 <TY T> IN VO FFT(VE<T>& f,CRUI N_input_start,CRUI N_input_lim,CRUI two_PW,CRUI EX){CooleyTukey<T>(f,N_input_start,N_input_lim,0,two_PW,two_PW,EX,PrimitiveRootOfTwoForFFT<T>());}TE <TY T> IN VO FFT(VE<T>& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CRUI EX){CooleyTukey<T>(f,N_input_start,N_input_lim,N_output_start,N_output_lim,two_PW,EX,PrimitiveRootOfTwoForFFT<T>());}TE <TY T> IN VO IFFT(VE<T>& f,CRUI N_input_start,CRUI N_input_lim,CRUI two_PW,CO T& two_PW_inv,CRUI EX){CooleyTukey<T>(f,N_input_start,N_input_lim,0,two_PW,two_PW,EX,InversePrimitiveRootOfTwoForFFT<T>());CO uint SZ = two_PW + N_input_start;for(uint i = N_input_start;i < SZ;i++){f[i]*= two_PW_inv;}}TE <TY T> IN VO IFFT(VE<T>& 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<T>(f,N_input_start,N_input_lim,N_output_start,N_output_lim,two_PW,EX,InversePrimitiveRootOfTwoForFFT<T>());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 SFINAE_FOR_PO(DEFAULT)TY Arg,enable_if_t<is_COructible_v<T,decay_t<Arg>>>* DEFAULT
#define DC_OF_AR_FOR_PO(FUNC)IN PO<T> OP FUNC(PO<T> f)CO;IN PO<T> OP FUNC(T t)CO
#define DF_OF_AR_FOR_PO(FUNC,DEF)TE <TY T> IN PO<T> PO<T>::OP FUNC(PO<T> f)CO{RE MO(DEF);};TE <TY T> IN PO<T> PO<T>::OP FUNC(T t)CO{RE *TH FUNC PO<T>(MO(t));}
TE <TY T>CL TRPO;TE <TY T>CL PO{PU:VE<T> m_f;uint m_SZ;IN PO();IN PO(CO PO<T>& f);IN PO(PO<T>&& f);IN PO(TRPO<T> f);IN PO(VE<T> f);IN PO(T t);TE <SFINAE_FOR_PO(= nullptr)> IN PO(Arg n);IN PO(CRUI i,T t);TE <SFINAE_FOR_PO(= nullptr)> IN PO(CRUI i,Arg n);TE <SFINAE_FOR_PO(= nullptr)> IN PO<T>& OP=(Arg n);IN PO<T>& OP=(PO<T> f);IN PO<T>& OP=(VE<T> f);IN CO T& OP[](CRUI i)CO;IN T& OP[](CRUI i);IN T OP()(CO T& t)CO;PO<T>& OP+=(CO PO<T>& f);PO<T>& OP-=(CO PO<T>& f);PO<T>& OP*=(CO PO<T>& f);PO<T>& OP*=(PO<T>&& f);IN PO<T>& OP/=(CO PO<T>& f);PO<T>& OP/=(CO T& t);PO<T>& OP%=(CO PO<T>& f);PO<T>& OP%=(CO T& t);bool OP==(CO PO<T>& f)CO;bool OP==(CO T& t)CO;TE <TY P> IN bool OP!=(CO P& f)CO;DC_OF_AR_FOR_PO(+);IN PO<T> OP-()CO;DC_OF_AR_FOR_PO(-);DC_OF_AR_FOR_PO(*);IN PO<T> OP/(CO PO<T>& f)CO;IN PO<T> OP/(CO T& t)CO;IN PO<T> OP%(CO PO<T>& f)CO;IN PO<T> OP%(CO T& t)CO;IN CO VE<T>& GetCoefficient()CO NE;IN CRUI SZ()CO NE;IN VO reSZ(CRUI deg_plus)NE;IN VO swap(PO<T>& f);IN VO swap(VE<T>& f);VO ReMORedundantZero();IN string Display()CO NE;ST PO<T> Quotient(CO PO<T>& f0,CO PO<T>& f1);ST PO<T> TP(CO PO<T>& f,CRUI f_TP_SZ);ST IN CO PO<T>& zero();ST IN CO PO<T>& one();ST IN CO T& c_zero();ST IN CO T& c_one();ST IN CO T& c_minus_one();IN PO<T>& SignInvert();};

#define DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(TYPE,ARG,RHS)TE <> PO<TYPE>& PO<TYPE>::OP*=(ARG f){if(m_SZ != 0){VE<TYPE> v{};v.swap(m_f);TRPO<TYPE> TH_copy{m_SZ + f.m_SZ - 1,MO(v)};TH_copy *= RHS;m_f = MO(TH_copy.PO<TYPE>::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<T>(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<T>::m_SZ < N_OUTPUT_LIM){for(uint i = PO<T>::m_SZ;i < N_OUTPUT_LIM;i++){PO<T>::m_f.push_back(0);}PO<T>::m_SZ = N_OUTPUT_LIM;}
#define SET_VE_FOR_AN_OF_TR_MU_CO_FOR_TR_PO(N_OUTPUT_LIM)VE<T> 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<T>::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<T>::m_f[j]* f.PO<T>::m_f[i - j];}PO<T>::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<T>::m_f[j]* f.PO<T>::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<T>::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<T>::m_SZ == 0);uint N_output_max = PO<T>::m_SZ + f.PO<T>::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<T>::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<T>::m_f,PO<T>::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<T>::m_SZ,N_input_start_1);
#define SET_N_INPUT_RANGE SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(PO<T>::m_f,PO<T>::m_SZ,N_input_max_0);SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(f,f.PO<T>::m_SZ < m_N?f.PO<T>::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<T> 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<T>;CO T& zero = PO<T>::c_zero();bool searching = true;if(PO<T>::m_SZ < border_0 && f.PO<T>::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<T>;CO T& zero = PO<T>::c_zero();bool searching = true;if(PO<T>::m_SZ < border_0 && f.PO<T>::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<T>;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<T>;uint EX = FFT_MU_border_1_2_EX<T>;T two_PW_inv{FFT_MU_border_1_2_inv<T>};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<T>(f0,N_INPUT_START_0,N_INPUT_LIM_0,two_PW,EX);FFT<T>(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;uint N_output_start_shifted = N_OUTPUT_START_SHIFTED;if(N_output_start_shifted > N_output_lim_shifted){N_output_start_shifted = N_output_lim_shifted; }IFFT<T>(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)assert(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;static_assert(FFT_MU_border_0< TYPE > <= FFT_MU_border_1< TYPE >);TE <> CE CO uint FFT_MU_border_1_2< TYPE > = BORDER_1_2;static_assert(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;static_assert(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;static_assert((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 > 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 > 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<MOD>,17,512,1024,10,BORDER_1_2_INV);DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(MINT<MOD>,CO PO<MINT<MOD> >&,TH == &f?TH_copy:f);DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(MINT<MOD>,PO<MINT<MOD> >&&,MO(f));

TE <TY T>CL TRPO :PU PO<T>{PU:uint m_N;PU:IN TRPO(CRUI N = 0);IN TRPO(CO TRPO<T>& f);IN TRPO(TRPO<T>&& f);IN TRPO(CRUI N,T t);IN TRPO(CRUI N,CO PO<T>& f);IN TRPO(CRUI N,PO<T>&& f);IN TRPO(CRUI N,VE<T>&& f);IN TRPO(CRUI N,CRUI i,T t);TE <SFINAE_FOR_PO(= nullptr)> IN TRPO(CRUI N,CRUI i,CO Arg& t);IN TRPO<T>& OP=(TRPO<T> f);TE <SFINAE_FOR_PO(= nullptr)> IN TRPO<T>& OP=(Arg n);IN TRPO<T>& OP=(PO<T> f);IN TRPO<T>& OP+=(CO T& t);IN TRPO<T>& OP+=(CO PO<T>& f);IN TRPO<T>& OP+=(CO TRPO<T>& f);TRPO<T>& TRPlus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO<T>& OP-=(CO T& t);IN TRPO<T>& OP-=(CO PO<T>& f);IN TRPO<T>& OP-=(CO TRPO<T>& f);TRPO<T>& TRMinus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO<T>& OP*=(CO T& t);TRPO<T>& OP*=(CO PO<T>& f);IN TRPO<T>& OP*=(PO<T>&& f);TRPO<T>& FFT_MU(CO PO<T>& f);TRPO<T>& TRMU(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim);TRPO<T>& FFT_TRMU(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim);TRPO<T>& FFT_TRMU(PO<T>&& f,CRUI N_output_start,CRUI N_output_lim);TRPO<T> TRMU_CO(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim)CO;TRPO<T> FFT_TRMU_CO(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim)CO;TRPO<T> FFT_TRMU_CO(PO<T>&& f,CRUI N_output_start,CRUI N_output_lim)CO;IN TRPO<T>& OP/=(CO T& t);IN TRPO<T>& OP/=(CO TRPO<T>& t);IN TRPO<T>& OP%=(CO T& t);IN TRPO<T> OP-()CO;IN VO SetTruncation(CRUI N)NE;IN CRUI GetTruncation()CO NE;IN TRPO<T>& TruncateInitial(CRUI N)NE;IN TRPO<T>& TruncateFinal(CRUI N)NE;};TE <TY T> CE CO uint FFT_MU_border_0 = 17;TE <TY T> CE CO uint FFT_MU_border_1{};TE <TY T> CE CO uint FFT_MU_border_1_2{};TE <TY T> CE CO uint FFT_MU_border_1_2_EX{};TE <TY T> CE CO uint FFT_MU_border_1_2_inv{};

TE <TY T> IN TRPO<T>::TRPO(CRUI N):PO<T>(),m_N(N){}TE <TY T> IN TRPO<T>::TRPO(CO TRPO<T>& f):PO<T>(f),m_N(f.m_N){}TE <TY T> IN TRPO<T>::TRPO(TRPO<T>&& f):PO<T>(MO(f.m_f)),m_N(f.m_N){}TE <TY T> IN TRPO<T>::TRPO(CRUI N,T t):PO<T>(MO(t)),m_N(N){}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CO PO<T>& f):PO<T>(),m_N(N){PO<T>::m_SZ = f.PO<T>::m_SZ < m_N?f.PO<T>::m_SZ:m_N;PO<T>::m_f = VE<T>(PO<T>::m_SZ);for(uint i = 0;i < PO<T>::m_SZ;i++){PO<T>::m_f[i]= f.PO<T>::m_f[i];}}TE <TY T> IN TRPO<T>::TRPO(CRUI N,PO<T>&& f):PO<T>(),m_N(N){if(f.PO<T>::m_SZ < m_N * 2){PO<T>::OP=(MO(f));if(f.PO<T>::m_SZ > m_N){TruncateFinal(m_N);}}else{PO<T>::m_f = VE<T>(m_N);for(uint i = 0;i < m_N;i++){PO<T>::m_f[i]= MO(f.PO<T>::m_f[i]);}PO<T>::m_SZ = m_N;}}TE <TY T> IN TRPO<T>::TRPO(CRUI N,VE<T>&& f):PO<T>(),m_N(N){CO uint f_SZ = f.SZ();if(f_SZ < m_N * 2){PO<T>::OP=(MO(f));if(f_SZ > m_N){TruncateFinal(m_N);}}else{PO<T>::m_f = VE<T>(m_N);for(uint i = 0;i < m_N;i++){PO<T>::m_f[i]= MO(f[i]);}}}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CRUI i,T t):PO<T>(),m_N(N){if(i < m_N?t != PO<T>::c_zero():false){PO<T>::OP[](i)= MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN TRPO<T>::TRPO(CRUI N,CRUI i,CO Arg& n):TRPO(N,i,T(n)){}TE <TY T> IN TRPO<T>& TRPO<T>::OP=(TRPO<T> f){PO<T>::OP=(MO(f.m_f));m_N = f.m_N;RE *TH;}TE <TY T> TE <SFINAE_FOR_PO()> IN TRPO<T>& TRPO<T>::OP=(Arg n){PO<T>::OP=(MO(n));RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP=(PO<T> f){RE OP=(TRPO<T>(m_N,MO(f)));}TE <TY T> IN TRPO<T>& TRPO<T>::OP+=(CO T& t){PO<T>::OP+=(t);RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP+=(CO PO<T>& f){RE TRPlus(f,0,f.m_SZ);}TE <TY T> IN TRPO<T>& TRPO<T>::OP+=(CO TRPO<T>& f){RE m_N == 0?OP=(f):TRPlus(f,0,f.PO<T>::m_SZ);}TE <TY T>TRPO<T>& TRPO<T>::TRPlus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO<T>::m_SZ?N_input_lim:f.PO<T>::m_SZ:m_N < f.PO<T>::m_SZ?m_N:f.PO<T>::m_SZ;if(PO<T>::m_SZ < SZ){PO<T>::m_f.reserve(SZ);for(uint i = N_input_start;i < PO<T>::m_SZ;i++){PO<T>::m_f[i]+= f.PO<T>::m_f[i];}for(uint i = PO<T>::m_SZ;i < SZ;i++){PO<T>::m_f.push_back(f.PO<T>::m_f[i]);}PO<T>::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO<T>::m_f[i]+= f.PO<T>::m_f[i];}}RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP-=(CO T& t){PO<T>::OP-=(t);RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP-=(CO PO<T>& f){RE TRMinus(f,0,f.m_SZ);}TE <TY T> IN TRPO<T>& TRPO<T>::OP-=(CO TRPO<T>& f){RE m_N == 0?OP=(-f):TRMinus(f,0,f.PO<T>::m_SZ);}TE <TY T>TRPO<T>& TRPO<T>::TRMinus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO<T>::m_SZ?N_input_lim:f.PO<T>::m_SZ:m_N < f.PO<T>::m_SZ?m_N:f.PO<T>::m_SZ;if(PO<T>::m_SZ < SZ){PO<T>::m_f.reserve(SZ);for(uint i = N_input_start;i < PO<T>::m_SZ;i++){PO<T>::m_f[i]-= f.PO<T>::m_f[i];}for(uint i = PO<T>::m_SZ;i < SZ;i++){PO<T>::m_f.push_back(- f.PO<T>::m_f[i]);}PO<T>::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO<T>::m_f[i]-= f.PO<T>::m_f[i];}}RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP*=(CO T& t){PO<T>::OP*=(t);RE *TH;}TE <TY T>TRPO<T>& TRPO<T>::OP*=(CO PO<T>& f){DF_OF_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO<T>::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<T>::m_f[j],0,);}TE <TY T> IN TRPO<T>& TRPO<T>::OP*=(PO<T>&& f){RE OP*=(f);}TE <TY T>TRPO<T>& TRPO<T>::FFT_MU(CO PO<T>& f){DF_OF_FFT_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO<T>::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<T>::m_f[j],0,0,,VE<T>& f0 = PO<T>::m_f,N_input_start_0,N_input_max_0 + 1,SET_SHIFTED_VE_FOR_MU(f1,f.PO<T>::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<T>(m_N,MO(f1))));}TE <TY T>TRPO<T>& TRPO<T>::TRMU(CO PO<T>& 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<T>::m_f[j],N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE <TY T>TRPO<T>& TRPO<T>::FFT_TRMU(CO PO<T>& 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<T>::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<T>& f0 = PO<T>::m_f,N_input_start_0,N_input_max_0 + 1,SET_SHIFTED_VE_FOR_MU(f1,f.PO<T>::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<T>(m_N,MO(f1))));}TE <TY T>TRPO<T>& TRPO<T>::FFT_TRMU(PO<T>&& 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<T>::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<T>& f0 = PO<T>::m_f,N_input_start_0,N_input_max_0 + 1,VE<T>&& f1 = MO(f.PO<T>::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<T>::m_SZ = f0.SZ();SetTruncation(m_N););}TE <TY T>TRPO<T> TRPO<T>::TRMU_CO(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim)CO{DF_OF_MU_FOR_TR_PO(,RE TRPO<T>(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<T>(m_N,MO(AN)),TR_MU_CO,PO<T>::OP[](j),N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE <TY T>TRPO<T> TRPO<T>::FFT_TRMU_CO(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim)CO{DF_OF_FFT_MU_FOR_TR_PO(,RE TRPO<T>(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<T>(m_N,MO(AN)),RE TRPO<T>(m_N,MO(f0)),TR_MU_CO,PO<T>::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<T>::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<T> f1 = f.PO<T>::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 <TY T>TRPO<T> TRPO<T>::FFT_TRMU_CO(PO<T>&& f,CRUI N_output_start,CRUI N_output_lim)CO{DF_OF_FFT_MU_FOR_TR_PO(,RE TRPO<T>(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<T>(m_N,MO(AN)),RE TRPO<T>(m_N,MO(f0)),TR_MU_CO,PO<T>::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<T>::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<T>&& f1 = MO(f.PO<T>::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 <TY T> IN TRPO<T>& TRPO<T>::OP/=(CO T& t){PO<T>::OP/=(t);RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP/=(CO TRPO<T>& f){RE OP*=(Inverse(m_N <= f.m_N?f:TRPO<T>(m_N,f)));}TE <TY T> IN TRPO<T>& TRPO<T>::OP%=(CO T& t){PO<T>::OP%=(t);RE *TH;}TE <TY T> IN TRPO<T> TRPO<T>::OP-()CO{RE MO(TRPO<T>(m_N)-= *TH);}TE <TY T> IN VO TRPO<T>::SetTruncation(CRUI N)NE{if(N < m_N){TruncateFinal(N);}m_N = N;}TE <TY T> IN CRUI TRPO<T>::GetTruncation()CO NE{RE m_N;}TE <TY T> IN TRPO<T>& TRPO<T>::TruncateInitial(CRUI N)NE{CRUI SZ = N < PO<T>::m_SZ?N:PO<T>::m_SZ;for(uint i = 0;i < SZ;i++){PO<T>::m_f[i]= 0;}RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::TruncateFinal(CRUI N)NE{WH(PO<T>::m_SZ > N){PO<T>::m_f.pop_back();PO<T>::m_SZ--;}RE *TH;}TE <TY T,TY P> IN TRPO<T> OP+(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0)+= f1);}TE <TY T,TY P> IN TRPO<T> OP-(CO TRPO<T>& f){RE MO(TRPO<T>(f.GetTurncation())-= f);}TE <TY T,TY P> IN TRPO<T> OP-(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0)-= f1);}TE <TY T,TY P> IN TRPO<T> OP*(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0)*= f1);}TE <TY T,TY P> IN TRPO<T> OP/(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0)/= f1);}TE <TY T> IN TRPO<T> OP%(CO TRPO<T>& f0,CO T& t1){RE MO(TRPO<T>(f0)%= t1);}TE <TY T>TRPO<T> Differential(CRUI n,CO TRPO<T>& f){if(f.PO<T>::m_SZ < n){RE TRPO<T>(f.m_N - n,PO<T>::zero());}VE<T> df(f.PO<T>::m_SZ - n);T coef = T::Factorial(n);uint i = n;WH(i < f.PO<T>::m_SZ){df[i - n]= f[i]* coef;i++;(coef *= i)/=(i - n);}RE TRPO<T>(f.m_N - n,MO(df));}TE <TY T>TRPO<T> TRDifferential(CO TRPO<T>& f,CRUI N_output_start_plus_one){assert(f.m_N > 0);TRPO<T> f_dif{f.m_N - 1};if(N_output_start_plus_one < f.PO<T>::m_SZ){CO uint SZ = f.PO<T>::m_SZ - 1;f_dif.PO<T>::m_f = VE<T>(SZ);for(uint i = N_output_start_plus_one;i < f.PO<T>::m_SZ;i++){f_dif.PO<T>::m_f[i-1]= f.PO<T>::m_f[i]* i;}f_dif.PO<T>::m_SZ = SZ;}RE f_dif;}TE <TY T> IN TRPO<T> Differential(CO TRPO<T>& f){RE TRDifferential<T>(f,1);}TE <TY T>TRPO<T> TRIntegral(CO TRPO<T>& f,CRUI N_output_start){TRPO<T> f_int{f.m_N + 1};if(N_output_start <= f.PO<T>::m_SZ){CO uint SZ = f.PO<T>::m_SZ + 1;f_int.PO<T>::m_f = VE<T>(SZ);for(uint i = N_output_start;i <= f.PO<T>::m_SZ;i++){f_int.PO<T>::m_f[i]= f.PO<T>::m_f[i - 1]/ T(i);}f_int.PO<T>::m_SZ = SZ;}RE f_int;}TE <TY T> IN TRPO<T> Integral(CO TRPO<T>& f){RE TRIntegral<T>(f,1);}TE <TY T>TRPO<T> Inverse(CO TRPO<T>& 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 <TY T>TRPO<T> Exp(CO TRPO<T>& 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 <TY T> IN TRPO<T> Log(CO TRPO<T>& f){assert(f[0]== PO<T>::c_one());RE Integral<T>(Differential<T>(f)/= f);}
DF_OF_PS_OF_MU_OF_PO_PROTH_MOD(P,997269505,Mod);

// ファイル容量が厳しい場合は以下を削除する。(プロス素数以外を法とする畳み込み)
DF_OF_PS_OF_MU_OF_PO_PROTH_MOD(167772161,167608321,Mod);DF_OF_PS_OF_MU_OF_PO_PROTH_MOD(469762049,469303297,Mod);DF_OF_PS_OF_MU_OF_PO_PROTH_MOD(754974721,754237441,Mod);
#define DF_BODY_OF_PS_OF_MU_OF_PO_ARBITRARY_MOD(TYPE,ARG,MINT)TE <> PO<TYPE>& PO<TYPE>::OP*=(ARG f){if(m_SZ != 0){if(f.m_SZ == 0){m_f.clear();m_SZ = 0;}else{CE uint P0 = 167772161;CE uint P1 = 469762049;CE uint P2 = P;US M0 = MINT<P0>;US M1 = MINT<P1>;US M2 = MINT<P2>;VE<M0> v0{};VE<M1> v1{};VE<M2> v2{};v0.reserve(m_SZ);v1.reserve(m_SZ);v2.reserve(m_SZ);for(uint d = 0;d < m_SZ;d++){CO uint& f_d = m_f[d].RP();v0.push_back(f_d);v1.push_back(f_d);v2.push_back(f_d);}VE<M0> w0{};VE<M1> w1{};VE<M2> w2{};w0.reserve(f.m_SZ);w1.reserve(f.m_SZ);w2.reserve(f.m_SZ);for(uint d = 0;d < f.m_SZ;d++){CO uint& f_d = f.m_f[d].RP();w0.push_back(f_d);w1.push_back(f_d);w2.push_back(f_d);}m_SZ += f.m_SZ - 1;TRPO<M0> TH_copy0{m_SZ,MO(v0)};TRPO<M1> TH_copy1{m_SZ,MO(v1)};TRPO<M2> TH_copy2{m_SZ,MO(v2)};TRPO<M0> f_copy0{f.m_SZ,MO(w0)};TRPO<M1> f_copy1{f.m_SZ,MO(w1)};TRPO<M2> f_copy2{f.m_SZ,MO(w2)};TH_copy0 *= f_copy0;TH_copy1 *= f_copy1;TH_copy2 *= f_copy2;m_f.clear();m_f.reserve(m_SZ);CE TYPE P0_mod_M = TYPE(P0);CE TYPE P01_mod_M = TYPE(P1)*= P0_mod_M;CE M1 P0_mod_P1_inv = M1::DeRP(104391568);CE M2 P0_mod_P2 = M2::DeRP(P0);CE M2 P01_mod_P2_inv = M2::DeRP(575867115);ST_AS((M1::DeRP(P0)*= P0_mod_P1_inv)== M1::DeRP(1));ST_AS((M2::DeRP(P0)*= M2::DeRP(P1)*= P01_mod_P2_inv)== M2::DeRP(1));for(uint d = 0;d < m_SZ;d++){CO uint& c0 = TH_copy0[d].RP();CO uint& c1 =((TH_copy1[d]-= c0)*= P0_mod_P1_inv).RP();CO uint& c2 =((TH_copy2[d]-= P0_mod_P2 * c1 + c0)*= P01_mod_P2_inv).RP();m_f.push_back(P01_mod_M * c2 + P0_mod_M * c1 + c0);}ReMORedundantZero();}}RE *TH;}
#define DF_OF_PS_OF_MU_OF_PO_ARBITRARY_MOD(MOD,MINT)DF_BODY_OF_PS_OF_MU_OF_PO_ARBITRARY_MOD(MINT<MOD>,CO PO<MINT<MOD> >&,MINT);DF_BODY_OF_PS_OF_MU_OF_PO_ARBITRARY_MOD(MINT<MOD>,PO<MINT<MOD> >&&,MINT);
DF_OF_PS_OF_MU_OF_PO_ARBITRARY_MOD(1000000007,Mod);
// ここまで。

TE <TY T> IN PO<T>::PO():m_f(),m_SZ(0){}TE <TY T> IN PO<T>::PO(CO PO<T>& f):m_f(f.m_f),m_SZ(f.m_SZ){}TE <TY T> IN PO<T>::PO(PO<T>&& f):m_f(MO(f.m_f)),m_SZ(f.m_SZ){}TE <TY T> IN PO<T>::PO(TRPO<T> f):m_f(MO(f.m_f)),m_SZ(f.m_SZ){}TE <TY T> IN PO<T>::PO(VE<T> f):m_f(MO(f)),m_SZ(m_f.SZ()){}TE <TY T> IN PO<T>::PO(T t):PO(){if(t != c_zero()){OP[](0)= MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>::PO(Arg n):PO(T(MO(n))){}TE <TY T> IN PO<T>::PO(CRUI i,T t):PO(){if(t != c_zero()){OP[](i)= MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>::PO(CRUI i,Arg n):PO(i,T(MO(n))){}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>& PO<T>::OP=(Arg n){m_f.clear();m_SZ = 0;OP[](0)= MO(n);RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(PO<T> f){m_f = MO(f.m_f);m_SZ = f.m_SZ;RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(VE<T> f){m_f = MO(f);m_SZ = m_f.SZ();RE *TH;}TE <TY T> IN CO T& PO<T>::OP[](CRUI i)CO{RE m_SZ <= i?c_zero():m_f[i];}TE <TY T> IN T& PO<T>::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 <TY T> IN T PO<T>::OP()(CO T& t)CO{RE MO((*TH %(PO<T>(1,c_one())- t))[0]);}TE <TY T>PO<T>& PO<T>::OP+=(CO PO<T>& 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 <TY T>PO<T>& PO<T>::OP-=(CO PO<T>& 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 <TY T>PO<T>& PO<T>::OP*=(CO PO<T>& 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<T> 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 <TY T> IN PO<T>& PO<T>::OP*=(PO<T>&& f){RE *TH *= f;};TE <TY T>PO<T>& PO<T>::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 <TY T>PO<T> PO<T>::TP(CO PO<T>& f,CRUI f_TP_SZ){VE<T> 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<T>(MO(f_TP));}TE <TY T>PO<T>& PO<T>::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 <TY T>bool PO<T>::OP==(CO PO<T>& 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 <TY T>bool PO<T>::OP==(CO T& t)CO{CRUI SZ_max = SZ();CO T& zero = PO<T>::c_zero();for(uint i = 1;i < SZ_max;i++){if(m_f[i]!= zero){RE false;}}RE OP[](0)== t;}TE <TY T> TE<TY P> IN bool PO<T>::OP!=(CO P& f)CO{RE !(*TH == f);}DF_OF_AR_FOR_PO(+,f += *TH);TE <TY T> IN PO<T>& PO<T>::SignInvert(){ReMORedundantZero();for(auto& fi:m_f){fi = -fi;}RE *TH;}TE <TY T> IN PO<T> PO<T>::OP-()CO{RE MO(PO<T>(*TH).SignInvert());}DF_OF_AR_FOR_PO(-,f.SignInvert()+= *TH);DF_OF_AR_FOR_PO(*,f *= *TH);TE <TY T> IN PO<T> PO<T>::OP/(CO T& t)CO{RE MO(PO<T>(*TH)/= t);}TE <TY T> IN PO<T> PO<T>::OP%(CO T& t)CO{RE MO(PO<T>(*TH)%= t);}TE <TY T> IN CO VE<T>& PO<T>::GetCoefficient()CO NE{RE m_f;}TE <TY T> IN CRUI PO<T>::SZ()CO NE{RE m_SZ;}TE <TY T> IN VO PO<T>::reSZ(CRUI deg_plus)NE{m_f.reSZ(m_SZ = deg_plus);}TE <TY T> IN VO PO<T>::swap(PO<T>& f){m_f.swap(f.m_f);swap(m_SZ,f.m_SZ);}TE <TY T> IN VO PO<T>::swap(VE<T>& f){m_f.swap(f);m_SZ = m_f.SZ();}TE <TY T>VO PO<T>::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 <TY T>string PO<T>::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 <TY T> IN CO PO<T>& PO<T>::zero(){ST CO PO<T> z{};RE z;}TE <TY T> IN CO PO<T>& PO<T>::one(){ST CO PO<T> o{c_one()};RE o;}TE <TY T> IN CO T& PO<T>::c_zero(){ST CO T z{0};RE z;}TE <TY T> IN CO T& PO<T>::c_one(){ST CO T o{1};RE o;}TE <TY T> IN CO T& PO<T>::c_minus_one(){ST CO T m{-1};RE m;}TE <TY T>PO<T> Differential(CRUI n,CO PO<T>& f){CRUI SZ = f.SZ();if(SZ < n){RE PO<T>::zero();}VE<T> 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<T>(MO(df));}
TE <TY T> IN PO<T>& PO<T>::OP/=(CO PO<T>& f){RE m_SZ < f.m_SZ?*TH:*TH = Quotient(*TH,f);}TE <TY T>PO<T> PO<T>::Quotient(CO PO<T>& f0,CO PO<T>& f1){if(f0.m_SZ < f1.m_SZ){RE PO<T>::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<T> f1_TP_inverse = Inverse(TRPO<T>(f0_TP_SZ,TP(f1,f1_TP_SZ)));TRPO<T> 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 <TY T>PO<T>& PO<T>::OP%=(CO PO<T>& f){if(m_SZ >= f.m_SZ){*TH -=(*TH / f)* f;ReMORedundantZero();}RE *TH;}TE <TY T> IN PO<T> PO<T>::OP/(CO PO<T>& f)CO{RE PO<T>::Quotient(*TH,f);}TE <TY T> IN PO<T> PO<T>::OP%(CO PO<T>& f)CO{RE MO(PO<T>(*TH)%= f);}

// 冪乗
TE <TY T>PO<T> PW(PO<T> f,uint e){PO<T> AN = Polynomial<T>::one();WH(e > 0){(e & 1)== 0?AN:AN *= f;f *= f;e >>= 1;}RE AN;}

// 累積和
TE <TY T,int LE>CL BernulliNumberCalculator{PU:T m_val[LE];IN BernulliNumberCalculator(CO bool& negative = true);IN CO T& OP[](CRI i)CO;};
TE <TY T,int LE> IN BernulliNumberCalculator<T,LE>::BernulliNumberCalculator(CO bool& negative):m_val(){TRPO<T> f{LE};for(int i = 0;i < LE;i++){f[i] = T::FactorialInverse(i + 1);}f = Inverse(f);for(int i = 0;i < LE;i++){m_val[i] = MO(f[i] *= T::Factorial(i));}if(!negative && LE > 1){m_val[1] *= -1;}}TE <TY T,int LE> IN CO T& BernulliNumberCalculator<T,LE>::OP[](CRI i)CO{assert(i < LE);RE m_val[i];}

TE <TY T,uint deg_max>PO<T> CumulativeSum(PO<T> f,CO bool& EXial = false){CO uint f_SZ = f.SZ();if(f_SZ == 0){RE f;}CO uint deg = f_SZ - 1;assert(deg <= deg_max);CO T f0 = f[0];CO uint deg_half =(deg + 1)/ 2;if(!EXial){for(uint d = 1;d <= deg;d++){f[d]*= T::Factorial(d);}}for(uint d = 0;d < deg_half;d++){swap(f[d],f[deg - d]);}f.reSZ(deg);TRPO<T> f_transpose{f_SZ,MO(f)};ST CO BernulliNumberCalculator<T,deg_max+1> B{false};ST PO<T> g{};ST uint g_SZ = 0;WH(deg >= g_SZ){g[g_SZ]= B[g_SZ]* T::FactorialInverse(g_SZ);g_SZ++;}f_transpose *= g;f_transpose.SetTruncation(f_SZ + 1);CO uint f_SZ_half =(f_SZ + 1)/ 2;for(uint d = 0;d < f_SZ_half;d++){swap(f_transpose[d],f_transpose[f_SZ - d]);}if(!EXial){for(uint d = 1;d<= f_SZ;d++){f_transpose[d]*= T::FactorialInverse(d);}}f_transpose[1]+= f_transpose[0]= f0;RE f_transpose;}

// H×Wの白色グリッドでX×Yの領域を一様ランダムにN回選び黒色に塗り潰す時の黒色マスの個数の期待値を
// https://yukicoder.me/problems/no/2457/editorial
// をもとにO(min(XY,N^2)log_2 N)で計算。
template <typename T> inline T GridStampCoveringEpxpectation( const int& H ,  const int& W ,  const int& X ,  const int& Y , const ull& N );

template <typename T>
T GridBigStampCoveringEpxpectation( const uint& H ,  const uint& W , const uint& X ,  const uint& Y , const uint& N )
{

  const T S = T( H - X + 1 ) * ( W - Y + 1 );
  const T& one = Polynomial<T>::c_one();
  const T two = one + one;
  T answer{};
  Polynomial<T> power = Power( Polynomial<T>{ { one , - one / S } } , N );

  for( uint i = 1 ; i <= N ; i++ ){

    auto cs = CumulativeSum<T,(1<<16)-1>( Polynomial<T>( i , two ) );
    auto factor = [&]( const uint& h , const uint& k ){
      return cs( T( h < 2 * k ? h - k : k - 1 ) ) + ( h < 2 * k ? T( h - k + 1 ).Power( i ) *= T( 2 * k - h ) : T( k ).Power( i ) *= T( h - 2 * k + 2 ) );
    };
    answer -= factor( H , X ) * factor( W , Y ) * power[i];

  }

  return answer;
  
}

template <typename T>
T GridSmallStampCoveringEpxpectation( const int& H ,  const int& W ,  const int& X ,  const int& Y , const ull& N )
{
  
  const int H_minus = H - X;
  const int W_minus = W - Y;
  const T S_inv = 1 / ( T( H_minus + 1 ) * ( W_minus + 1 ) );
  T answer = T( H ) * W;

  for( int i = 0 ; i < H ; i++ ){

    T u{};

    for( int j = 0 ; j < W ; j++ ){

      T t = ( 1 - ( max( min( i , H_minus ) - max( i - X , -1 ) , 0 ) * max( min( j , W_minus ) - max( j - Y , -1 ) , 0 ) ) * S_inv ).Power( N );

      if( Y <= j && j < W_minus ){

	u += t * ( W - 2 * Y );
	j = W_minus - 1;

      } else {

	u += t;

      }
      
    }

    if( X <= i && i < H_minus ){

      answer -= u * ( H - 2 * X );
      i = H_minus - 1;

    } else {

      answer -= u;

    }

  }

  return answer;

}

template <typename T> inline T GridStampCoveringEpxpectation( const int& H ,  const int& W ,  const int& X ,  const int& Y , const ull& N ) { assert( 1 <= X && X <= H && 1 <= Y && Y <= W ); return ull( N ) * N <= ull( X ) * Y ? GridBigStampCoveringEpxpectation<T>( uint( H ) , uint( W ) , uint( X ) , uint( Y ) , uint( N ) ) : GridSmallStampCoveringEpxpectation<T>( H , W , X , Y , N ); }

// AAA 常設でないライブラリは以上に挿入する。

#define INCLUDE_SUB
#include __FILE__

#else // INCLUDE_LIBRARY

#ifdef DEBUG
  #define _GLIBCXX_DEBUG
  #define REPEAT_MAIN( BOUND ) START_MAIN; signal( SIGABRT , &AlertAbort ); AutoCheck( exec_mode , use_getline ); CEXPR( int , bound_test_case_num , BOUND ); int test_case_num = 1; if( exec_mode == solve_mode ){ if CE( bound_test_case_num > 1 ){ CERR( "テストケースの個数を入力してください。" ); SET_ASSERT( test_case_num , 1 , bound_test_case_num ); } } else { if( exec_mode == experiment_mode ){ Experiment(); } else if( exec_mode == small_test_mode ){ SmallTest(); } else if( exec_mode == random_test_mode ){ CERR( "ランダムテストを行う回数を指定してください。" ); SET_LL( test_case_num ); REPEAT( test_case_num ){ RandomTest(); } } RE 0; } FINISH_MAIN
  #define DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE2 )
  #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " , ( MIN ) , ( ( MIN ) <= A ? "<=" : ">" ) , A , ( A <= ( MAX ) ? "<=" : ">" ) , ( MAX ) ); AS( ( MIN ) <= A && A <= ( MAX ) )
  #define SET_ASSERT( A , MIN , MAX ) if( exec_mode == solve_mode ){ SET_LL( A ); ASSERT( A , MIN , MAX ); } else if( exec_mode == random_test_mode ){ CERR( #A , " = " , ( A = GetRand( MIN , MAX ) ) ); } else { AS( false ); }
  #define SOLVE_ONLY ST_AS( __FUNCTION__[0] == 'S' )
  #define CERR( ... ) VariadicCout( cerr , __VA_ARGS__ ) << endl
  #define COUT( ... ) VariadicCout( cout << "出力: " , __VA_ARGS__ ) << endl
  #define CERR_A( A , N ) OUTPUT_ARRAY( cerr , A , N ) << endl
  #define COUT_A( A , N ) cout << "出力: "; OUTPUT_ARRAY( cout , A , N ) << endl
  #define CERR_ITR( A ) OUTPUT_ITR( cerr , A ) << endl
  #define COUT_ITR( A ) cout << "出力: "; OUTPUT_ITR( cout , A ) << endl
#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 DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE1 )
  #define ASSERT( A , MIN , MAX ) AS( ( MIN ) <= A && A <= ( MAX ) )
  #define SET_ASSERT( A , MIN , MAX ) SET_LL( A ); ASSERT( A , MIN , MAX )
  #define SOLVE_ONLY 
  #define CERR( ... ) 
  #define COUT( ... ) VariadicCout( cout , __VA_ARGS__ ) << ENDL
  #define CERR_A( A , N ) 
  #define COUT_A( A , N ) OUTPUT_ARRAY( cout , A , N ) << ENDL
  #define CERR_ITR( A ) 
  #define COUT_ITR( A ) OUTPUT_ITR( cout , A ) << ENDL
#endif
#ifdef REACTIVE
  #define ENDL endl
#else
  #define ENDL "\n"
#endif
#ifdef USE_GETLINE
  #define SET_LL( A ) { GETLINE( A ## _str ); A = stoll( A ## _str ); }
  #define GETLINE_SEPARATE( SEPARATOR , ... ) SOLVE_ONLY; string __VA_ARGS__; VariadicGetline( cin , SEPARATOR , __VA_ARGS__ )
  #define GETLINE( ... ) SOLVE_ONLY; GETLINE_SEPARATE( '\n' , __VA_ARGS__ )
#else
  #define SET_LL( A ) cin >> A
  #define CIN( LL , ... ) SOLVE_ONLY; LL __VA_ARGS__; VariadicCin( cin , __VA_ARGS__ )
  #define SET_A( A , N ) SOLVE_ONLY; FOR( VARIABLE_FOR_SET_A , 0 , N ){ cin >> A[VARIABLE_FOR_SET_A]; }
  #define CIN_A( LL , A , N ) VE<LL> A( N ); SET_A( A , N );
#endif
#include <bits/stdc++.h>
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 FINISH_MAIN REPEAT( test_case_num ){ if CE( bound_test_case_num > 1 ){ CERR( "testcase " , VARIABLE_FOR_REPEAT_test_case_num , ":" ); } Solve(); CERR( "" ); } }
#define START_WATCH chrono::system_clock::time_point watch = chrono::system_clock::now()
#define CURRENT_TIME static_cast<double>( chrono::duration_cast<chrono::microseconds>( chrono::system_clock::now() - watch ).count() / 1000.0 )
#define CHECK_WATCH( TL_MS ) ( CURRENT_TIME < TL_MS - 100.0 )
#define CEXPR( LL , BOUND , VALUE ) CE LL BOUND = VALUE
#define SET_A_ASSERT( A , N , MIN , MAX ) FOR( VARIABLE_FOR_SET_A , 0 , N ){ SET_ASSERT( A[VARIABLE_FOR_SET_A] , MIN , MAX ); }
#define CIN_ASSERT( A , MIN , MAX ) decldecay_t( MAX ) A; SET_ASSERT( A , MIN , MAX )
#define CIN_A_ASSERT( A , N , MIN , MAX ) vector<decldecay_t( MAX )> A( N ); SET_A_ASSERT( A , N , 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 AUTO_ITR( ARRAY ) auto itr_ ## ARRAY = ARRAY .BE() , end_ ## ARRAY = ARRAY .EN()
#define FOR_ITR( ARRAY ) for( AUTO_ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ )
#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 )
#define OUTPUT_ARRAY( OS , A , N ) FOR( VARIABLE_FOR_OUTPUT_ARRAY , 0 , N ){ OS << A[VARIABLE_FOR_OUTPUT_ARRAY] << (VARIABLE_FOR_OUTPUT_ARRAY==N-1?"":" "); } OS
#define OUTPUT_ITR( OS , A ) { auto ITERATOR_FOR_OUTPUT_ITR = A.BE() , EN_FOR_OUTPUT_ITR = A.EN(); bool VARIABLE_FOR_OUTPUT_ITR = ITERATOR_FOR_COUT_ITR != END_FOR_COUT_ITR; WH( VARIABLE_FOR_OUTPUT_ITR ){ OS << *ITERATOR_FOR_COUT_ITR; ( VARIABLE_FOR_OUTPUT_ITR = ++ITERATOR_FOR_COUT_ITR != END_FOR_COUT_ITR ) ? OS : OS << " "; } } OS
#define RETURN( ... ) SOLVE_ONLY; COUT( __VA_ARGS__ ); RE
#define COMPARE( ... ) auto naive = Naive( __VA_ARGS__ ); auto answer = Answer( __VA_ARGS__ ); bool match = naive == answer; COUT( "(" , #__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 ST_AS static_assert
#define reMO_CO remove_const
#define is_COructible_v is_constructible_v
#define rBE rbegin
#define reSZ resize

// 型のエイリアス
#define decldecay_t(VAR)decay_t<decltype(VAR)>
TE <TY F,TY...Args> US ret_t = decltype(declval<F>()(declval<Args>()...));
TE <TY T> 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 <TY INT> US T2 = pair<INT,INT>;
TE <TY INT> US T3 = tuple<INT,INT,INT>;
TE <TY INT> US T4 = tuple<INT,INT,INT,INT>;
US path = pair<int,ll>;

// 入出力用
#define DF_OF_COUT_FOR_VE(V)TE <CL Traits,TY Arg> IN basic_ostream<char,Traits>& OP<<(basic_ostream<char,Traits>& os,CO V<Arg>& arg){auto BE = arg.BE(),EN = arg.EN();auto IT = BE;WH(IT != EN){(IT == BE?os:os << " ")<< *IT;IT++;}RE os;}
TE <CL Traits> IN basic_istream<char,Traits>& VariadicCin(basic_istream<char,Traits>& is){RE is;}
TE <CL Traits,TY Arg,TY... ARGS> IN basic_istream<char,Traits>& VariadicCin(basic_istream<char,Traits>& is,Arg& arg,ARGS&... args){RE VariadicCin(is >> arg,args...);}
TE <CL Traits> IN basic_istream<char,Traits>& VariadicGetline(basic_istream<char,Traits>& is,CO char& separator){RE is;}
TE <CL Traits,TY Arg,TY... ARGS> IN basic_istream<char,Traits>& VariadicGetline(basic_istream<char,Traits>& is,CO char& separator,Arg& arg,ARGS&... args){RE VariadicGetline(getline(is,arg,separator),separator,args...);}
DF_OF_COUT_FOR_VE(VE);
DF_OF_COUT_FOR_VE(LI);
DF_OF_COUT_FOR_VE(set);
DF_OF_COUT_FOR_VE(unordered_set);
TE <CL Traits,TY Arg1,TY Arg2> IN basic_ostream<char,Traits>& OP<<(basic_ostream<char,Traits>& os,CO pair<Arg1,Arg2>& arg){RE os << arg.first << " " << arg.second;}
TE <CL Traits,TY Arg> IN basic_ostream<char,Traits>& VariadicCout(basic_ostream<char,Traits>& os,CO Arg& arg){RE os << arg;}
TE <CL Traits,TY Arg1,TY Arg2,TY... ARGS> IN basic_ostream<char,Traits>& VariadicCout(basic_ostream<char,Traits>& os,CO Arg1& arg1,CO Arg2& arg2,CO ARGS&... args){RE VariadicCout(os << arg1 << " ",arg2,args...);}

// デバッグ用
#ifdef DEBUG
  IN VO AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); }
  VO AutoCheck( int& exec_mode , CO bool& use_getline );
  IN VO Solve();
  IN VO Experiment();
  IN VO SmallTest();
  IN VO RandomTest();
  ll GetRand( CRL Rand_min , CRL Rand_max );
  IN VO BreakPoint( CRI LINE ) {}
  int exec_mode;
  CEXPR( int , solve_mode , 0 );
  CEXPR( int , sample_debug_mode , 1 );
  CEXPR( int , submission_debug_mode , 2 );
  CEXPR( int , library_search_mode , 3 );
  CEXPR( int , experiment_mode , 4 );
  CEXPR( int , small_test_mode , 5 );
  CEXPR( int , random_test_mode , 6 );
  #ifdef USE_GETLINE
    CEXPR( bool , use_getline , true );
  #else
    CEXPR( bool , use_getline , false );
  #endif
#else
  ll GetRand( CRL Rand_min , CRL Rand_max ) { ll answer = time( NULL ); RE answer * rand() % ( Rand_max + 1 - Rand_min ) + Rand_min; }
#endif

// VVV 常設ライブラリは以下に挿入する。
// ConstexprModulo (7KB)
// c:/Users/user/Documents/Programming/Mathematics/Arithmetic/Mod/ConstexprModulo/compress.txt
#define RP Represent
#define DeRP Derepresent
CEXPR(uint,P,998244353);
TE <uint M,TY INT> CE INT RS(INT n)NE{RE MO(n < 0?((((++n)*= -1)%= M)*= -1)+= M - 1:n < INT(M)?n:n %= M);}TE <TY INT> CE INT& RSP(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;}
#define DC_OF_CM_FOR_MOD(OPR)CE bool OP OPR(CO Mod<M>& n)CO NE
#define DC_OF_AR_FOR_MOD(OPR,EX)CE Mod<M> OP OPR(Mod<M> n)CO EX;
#define DF_OF_CM_FOR_MOD(OPR)TE <uint M> CE bool Mod<M>::OP OPR(CO Mod<M>& n)CO NE{RE m_n OPR n.m_n;}
#define DF_OF_AR_FOR_MOD(OPR,EX,LEFT,OPR2)TE <uint M> CE Mod<M> Mod<M>::OP OPR(Mod<M> n)CO EX{RE MO(LEFT OPR2 ## = *TH);}TE <uint M,TY T> CE Mod<M> OP OPR(T n0,CO Mod<M>& n1)EX{RE MO(Mod<M>(MO(n0))OPR ## = n1);}
TE <uint M>CL Mod{PU:uint m_n;CE Mod()NE;CE Mod(CO Mod<M>& n)NE;CE Mod(Mod<M>&& n)NE;TE <TY T> CE Mod(T n)NE;CE Mod<M>& OP=(Mod<M> n)NE;CE Mod<M>& OP+=(CO Mod<M>& n)NE;CE Mod<M>& OP-=(CO Mod<M>& n)NE;CE Mod<M>& OP*=(CO Mod<M>& n)NE;IN Mod<M>& OP/=(Mod<M> n);TE <TY INT> CE Mod<M>& OP<<=(INT n);TE <TY INT> CE Mod<M>& OP>>=(INT n);CE Mod<M>& OP++()NE;CE Mod<M> OP++(int)NE;CE Mod<M>& OP--()NE;CE Mod<M> 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 <TY INT> CE Mod<M> OP^(INT EX)CO;TE <TY INT> CE Mod<M> OP<<(INT n)CO;TE <TY INT> CE Mod<M> OP>>(INT n)CO;CE Mod<M> OP-()CO NE;CE Mod<M>& SignInvert()NE;IN Mod<M>& Invert();TE <TY INT> CE Mod<M>& PW(INT EX);CE VO swap(Mod<M>& n)NE;CE CO uint& RP()CO NE;ST CE Mod<M> DeRP(CO uint& n)NE;ST IN CO Mod<M>& Inverse(CO uint& n);ST IN CO Mod<M>& Factorial(CO uint& n);ST IN CO Mod<M>& FactorialInverse(CO uint& n);ST IN Mod<M> Combination(CO uint& n,CO uint& i);ST IN CO Mod<M>& zero()NE;ST IN CO Mod<M>& one()NE;TE <TY INT> CE Mod<M>& PositivePW(INT EX)NE;TE <TY INT> CE Mod<M>& NonNegativePW(INT EX)NE;TE <TY T> CE Mod<M>& Ref(T&& n)NE;ST CE uint& Normalise(uint& n)NE;};
US MP = Mod<P>;
TE <uint M> CL Mod;TE <uint M>CL COantsForMod{PU:COantsForMod()= delete;ST CE CO uint g_memory_bound =
#ifdef DEBUG
1e3;
#else
1e6;
#endif
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 uint g_M_minus_2 = M - 2;ST CE uint g_M_minus_2_neg = 2 - M;};
TE <uint M> CE Mod<M>::Mod()NE:m_n(){}TE <uint M> CE Mod<M>::Mod(CO Mod<M>& n)NE:m_n(n.m_n){}TE <uint M> CE Mod<M>::Mod(Mod<M>&& n)NE:m_n(MO(n.m_n)){}TE <uint M> TE <TY T> CE Mod<M>::Mod(T n)NE:m_n(RS<M>(MO(n))){ST_AS(is_COructible_v<uint,decay_t<T> >);}TE <uint M> CE Mod<M>& Mod<M>::OP=(Mod<M> n)NE{RE Ref(m_n = MO(n.m_n));}TE <uint M> CE Mod<M>& Mod<M>::OP+=(CO Mod<M>& n)NE{RE Ref(Normalise(m_n += n.m_n));}TE <uint M> CE Mod<M>& Mod<M>::OP-=(CO Mod<M>& n)NE{RE Ref(m_n < n.m_n?(m_n += M)-= n.m_n:m_n -= n.m_n);}TE <uint M> CE Mod<M>& Mod<M>::OP*=(CO Mod<M>& n)NE{RE Ref(m_n = RS<M>(ull(m_n)* n.m_n));}TE <> CE MP& MP::OP*=(CO MP& n)NE{ull m_n_copy = m_n;RE Ref(m_n = MO((m_n_copy *= n.m_n)< P?m_n_copy:RSP(m_n_copy)));}TE <uint M> IN Mod<M>& Mod<M>::OP/=(Mod<M> n){RE OP*=(n.Invert());}TE <uint M> TE <TY INT> CE Mod<M>& Mod<M>::OP<<=(INT n){AS(n >= 0);RE *TH *= Mod<M>(2).NonNegativePW(MO(n));}TE <uint M> TE <TY INT> CE Mod<M>& Mod<M>::OP>>=(INT n){AS(n >=0);WH(n-- > 0){((m_n & 1)== 0?m_n:m_n += M)>>= 1;}RE *TH;}TE <uint M> CE Mod<M>& Mod<M>::OP++()NE{RE Ref(m_n < COantsForMod<M>::g_M_minus?++m_n:m_n = 0);}TE <uint M> CE Mod<M> Mod<M>::OP++(int)NE{Mod<M> n{*TH};OP++();RE n;}TE <uint M> CE Mod<M>& Mod<M>::OP--()NE{RE Ref(m_n == 0?m_n = COantsForMod<M>::g_M_minus:--m_n);}TE <uint M> CE Mod<M> Mod<M>::OP--(int)NE{Mod<M> 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 <uint M> TE <TY INT> CE Mod<M> Mod<M>::OP^(INT EX)CO{RE MO(Mod<M>(*TH).PW(MO(EX)));}TE <uint M> TE <TY INT> CE Mod<M> Mod<M>::OP<<(INT n)CO{RE MO(Mod<M>(*TH)<<= MO(n));}TE <uint M> TE <TY INT> CE Mod<M> Mod<M>::OP>>(INT n)CO{RE MO(Mod<M>(*TH)>>= MO(n));}TE <uint M> CE Mod<M> Mod<M>::OP-()CO NE{RE MO(Mod<M>(*TH).SignInvert());}TE <uint M> CE Mod<M>& Mod<M>::SignInvert()NE{RE Ref(m_n > 0?m_n = M - m_n:m_n);}TE <uint M> IN Mod<M>& Mod<M>::Invert(){AS(m_n != 0);uint m_n_neg;RE m_n < COantsForMod<M>::g_memory_LE?Ref(m_n = Inverse(m_n).m_n):((m_n_neg = M - m_n)< COantsForMod<M>::g_memory_LE)?Ref(m_n = M - Inverse(m_n_neg).m_n):PositivePW(uint(COantsForMod<M>::g_M_minus_2));}TE <uint M> TE <TY INT> CE Mod<M>& Mod<M>::PositivePW(INT EX)NE{Mod<M> PW{*TH};EX--;WH(EX != 0){(EX & 1)== 1?*TH *= PW:*TH;EX >>= 1;PW *= PW;}RE *TH;}TE <uint M> TE <TY INT> CE Mod<M>& Mod<M>::NonNegativePW(INT EX)NE{RE EX == 0?Ref(m_n = 1):Ref(PositivePW(MO(EX)));}TE <uint M> TE <TY INT> CE Mod<M>& Mod<M>::PW(INT EX){bool neg = EX < 0;AS(!(neg && m_n == 0));RE neg?PositivePW(MO(EX *= COantsForMod<M>::g_M_minus_2_neg)):NonNegativePW(MO(EX));}TE <uint M> CE VO Mod<M>::swap(Mod<M>& n)NE{std::swap(m_n,n.m_n);}TE <uint M> IN CO Mod<M>& Mod<M>::Inverse(CO uint& n){AS(n < COantsForMod<M>::g_memory_LE);ST Mod<M> memory[COantsForMod<M>::g_memory_LE]={zero(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory[LE_curr].m_n = M - memory[M % LE_curr].m_n * ull(M / LE_curr)% M;LE_curr++;}RE memory[n];}TE <uint M> IN CO Mod<M>& Mod<M>::Factorial(CO uint& n){AS(n < COantsForMod<M>::g_memory_LE);ST Mod<M> memory[COantsForMod<M>::g_memory_LE]={one(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){(memory[LE_curr]= memory[LE_curr - 1])*= LE_curr;LE_curr++;}RE memory[n];}TE <uint M> IN CO Mod<M>& Mod<M>::FactorialInverse(CO uint& n){ST Mod<M> memory[COantsForMod<M>::g_memory_LE]={one(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){(memory[LE_curr]= memory[LE_curr - 1])*= Inverse(LE_curr);LE_curr++;}RE memory[n];}TE <uint M> IN Mod<M> Mod<M>::Combination(CO uint& n,CO uint& i){RE i <= n?Factorial(n)* FactorialInverse(i)* FactorialInverse(n - i):zero();}TE <uint M> CE CO uint& Mod<M>::RP()CO NE{RE m_n;}TE <uint M> CE Mod<M> Mod<M>::DeRP(CO uint& n)NE{Mod<M> n_copy{};n_copy.m_n = n;RE n_copy;}TE <uint M> IN CO Mod<M>& Mod<M>::zero()NE{ST CE CO Mod<M> z{};RE z;}TE <uint M> IN CO Mod<M>& Mod<M>::one()NE{ST CE CO Mod<M> o{1};RE o;}TE <uint M> TE <TY T> CE Mod<M>& Mod<M>::Ref(T&& n)NE{RE *TH;}TE <uint M> CE uint& Mod<M>::Normalise(uint& n)NE{RE n < M?n:n -= M;}TE <uint M> IN Mod<M> Inverse(CO Mod<M>& n){RE MO(Mod<M>(n).Invert());}TE <uint M> CE Mod<M> Inverse_CE(Mod<M> n)NE{RE MO(n.NonNegativePW(M - 2));}TE <uint M,TY INT> CE Mod<M> PW(Mod<M> n,INT EX){RE MO(n.PW(MO(EX)));}TE <uint M> CE VO swap(Mod<M>& n0,Mod<M>& n1)NE{n0.swap(n1);}TE <uint M> IN string to_string(CO Mod<M>& n)NE{RE to_string(n.RP())+ " + " + to_string(M)+ "Z";}TE <uint M,CL Traits> IN basic_istream<char,Traits>& OP>>(basic_istream<char,Traits>& is,Mod<M>& n){ll m;is >> m;n = m;RE is;}TE <uint M,CL Traits> IN basic_ostream<char,Traits>& OP<<(basic_ostream<char,Traits>& os,CO Mod<M>& n){RE os << n.RP();}
// AAA 常設ライブラリは以上に挿入する。

#define INCLUDE_LIBRARY
#include __FILE__

#endif // INCLUDE_LIBRARY

#endif // INCLUDE_SUB

#endif // INCLUDE_MAIN
0