結果

問題 No.2166 Paint and Fill
ユーザー 👑 p-adicp-adic
提出日時 2023-01-07 01:35:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 62,303 bytes
コンパイル時間 5,540 ms
コンパイル使用メモリ 260,192 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-11-30 22:40:20
合計ジャッジ時間 289,660 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
9,344 KB
testcase_01 TLE -
testcase_02 AC 1,323 ms
9,344 KB
testcase_03 AC 47 ms
9,216 KB
testcase_04 AC 48 ms
9,216 KB
testcase_05 AC 48 ms
9,216 KB
testcase_06 AC 48 ms
9,344 KB
testcase_07 AC 47 ms
9,216 KB
testcase_08 AC 937 ms
9,216 KB
testcase_09 AC 920 ms
9,344 KB
testcase_10 AC 923 ms
9,344 KB
testcase_11 AC 935 ms
9,344 KB
testcase_12 AC 917 ms
9,216 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 RE -
testcase_26 RE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 RE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:52:3405: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
main.cpp:23:12: note: expanded from macro 'MO'
   23 | #define MO move
      |            ^
main.cpp:52:4561: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
main.cpp:23:12: note: expanded from macro 'MO'
   23 | #define MO move
      |            ^
main.cpp:52:1233: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
main.cpp:23:12: note: expanded from macro 'MO'
   23 | #define MO move
      |            ^
main.cpp:52:5366: note: in instantiation of member function 'Mod<2>::Mod' requested here
main.cpp:52:5713: note: in instantiation of member function 'Mod<2>::DeRP' requested here
main.cpp:52:1399: warning: unqualified call to 'std::forward' [-Wunqualified-std-cast-call]
main.cpp:67:461: note: in instantiation of function template specialization 'Mod<998244353>::Mod<int, nullptr>' requested here
main.cpp:42:173: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
   42 | TE <TY INT1,TY INT2> IN INT1& RS(INT1& n,CO INT2& M)NE{RE n >= 0?n %= M:((((++n) *= -1) %= M) *= -1) += M - 1;}TE <TY INT1,TY INT2> IN CE INT1 RS(INT1&& n,CO INT2& M)NE{RE MO(n >= 0?n %= M:((((++n) *= -1) %= M) *= -1) += M - 1);}TE <TY INT1,TY INT2> IN CE INT1 RS(CO INT1& n,CO INT2& M)NE{RE RS(MO(INT1(n)),M);}TE <TY INT1,TY INT2> IN CE INT1 RS_CE(CO INT1& n,CO INT2& M)NE{RE n >= 0?n % M:M - 1 - ((- (n - 1)) % M);}
      |                                                                                                                                                                             ^
      |                                                                                                                                                                             std::
main.cpp:23:12: note: expanded from macro 'MO'
   23 | #define MO move
      |            ^
main.cpp:52:1396: note: in instantiation of function template specialization 'RS<int,

ソースコード

diff #

#pragma GCC optimize ( "O3" )
#pragma GCC target ( "avx" )
#include <bits/stdc++.h>
#define TE template
#define TY typename
#define US using
#define ST static
#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 MO move
#define TH this
#define CRI CO int&
#define CRUI CO uint&
US namespace std;US uint = unsigned int;US ll = long long;
#define TYPE_OF( VAR ) decay_t<decltype( VAR )>
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE 
#define CIN( LL , A ) LL A; cin >> A 
#define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) 
#define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) 
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) 
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) 
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- ) 
#define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) 
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) 
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n";
#define QUIT return 0;

TE <TY INT1,TY INT2> IN INT1& RS(INT1& n,CO INT2& M)NE{RE n >= 0?n %= M:((((++n) *= -1) %= M) *= -1) += M - 1;}TE <TY INT1,TY INT2> IN CE INT1 RS(INT1&& n,CO INT2& M)NE{RE MO(n >= 0?n %= M:((((++n) *= -1) %= M) *= -1) += M - 1);}TE <TY INT1,TY INT2> IN CE INT1 RS(CO INT1& n,CO INT2& M)NE{RE RS(MO(INT1(n)),M);}TE <TY INT1,TY INT2> IN CE INT1 RS_CE(CO INT1& n,CO INT2& M)NE{RE n >= 0?n % M:M - 1 - ((- (n - 1)) % M);}

#define SFINAE_FOR_MOD(DEFAULT) TY T,enable_if_t<is_constructible<uint,decay_t<T> >::value>* DEFAULT
#define DC_OF_CM_FOR_MOD(FUNC) IN bool OP FUNC(CO Mod<M>& n) CO NE
#define DC_OF_AR_FOR_MOD(FUNC,FUNC_CE) IN Mod<M> OP FUNC(CO Mod<M>& n) CO NE;TE <SFINAE_FOR_MOD(= nullptr)> IN Mod<M> OP FUNC(T&& n) CO NE;IN CE Mod<M> FUNC_CE ## _CE(CO Mod<M>& n)NE
#define DF_OF_CM_FOR_MOD(FUNC) TE <uint M> IN bool Mod<M>::OP FUNC(CO Mod<M>& n) CO NE{RE m_n FUNC n.m_n;}
#define DF_OF_AR_FOR_MOD(FUNC,FORMULA,FUNC_CE,FORMULA_CE) TE <uint M> IN Mod<M> Mod<M>::OP FUNC(CO Mod<M>& n) CO NE{RE MO(Mod<M>(*TH) FUNC ## = n);}TE <uint M> TE <SFINAE_FOR_MOD()> IN Mod<M> Mod<M>::OP FUNC(T&& n) CO NE{RE FORMULA;}TE <uint M> IN CE Mod<M> Mod<M>::FUNC_CE ## _CE(CO Mod<M>& n)NE{RE DeRP(FORMULA_CE);}TE <uint M,SFINAE_FOR_MOD(= nullptr)> IN Mod<M> OP FUNC(T&& n0,CO Mod<M>& n1)NE{RE MO(Mod<M>(forward<T>(n0)) FUNC ## = n1);}

US ull = unsigned long long;TE <uint M>CL Mod{PU:uint m_n;PU:IN CE Mod()NE;IN CE Mod(CO Mod<M>& n)NE;IN CE Mod(Mod<M>& n)NE;IN CE Mod(Mod<M>&& n)NE;TE <SFINAE_FOR_MOD(= nullptr)> IN CE Mod(T& n)NE;TE <SFINAE_FOR_MOD(= nullptr)> IN CE Mod(T&& n)NE;IN CE Mod<M>& OP=(CO Mod<M>& n)NE;IN CE Mod<M>& OP+=(CO Mod<M>& n)NE;IN CE Mod<M>& OP-=(CO Mod<M>& n)NE;IN CE Mod<M>& OP*=(CO Mod<M>& n)NE;IN Mod<M>& OP/=(CO Mod<M>& n);IN CE Mod<M>& OP++()NE;IN CE Mod<M> OP++(int)NE;IN CE Mod<M>& OP--()NE;IN 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(+,Add);DC_OF_AR_FOR_MOD(-,Substract);DC_OF_AR_FOR_MOD(*,Multiply);DC_OF_AR_FOR_MOD(/,Devide);IN CE Mod<M> OP-() CO NE;IN CE Mod<M>& SignInvert()NE;IN Mod<M>& Invert();TE <TY T> IN CE Mod<M>& PositivePW(T&& EX)NE;TE <TY T> IN CE Mod<M>& PW(T&& EX);TE <TY T> IN CE Mod<M> NonNegativePW_CE(CO Mod<M>& repetitive_square,T&& EX)NE;IN CE CO uint& RP() CO NE;IN CE VO swap(Mod<M>& n)NE;ST IN CO Mod<M>& Inverse(CO uint& n)NE;ST IN CO Mod<M>& Factorial(CO uint& n)NE;ST IN CO Mod<M>& FactorialInverse(CO uint& n)NE;ST IN CO Mod<M>& zero()NE;ST IN CO Mod<M>& one()NE;ST IN CE Mod<M> DeRP(CO uint& n)NE;PU:ST IN CE uint MNForm(CO uint& n)NE;ST IN CE ull& MNReduction(ull& n)NE;ST IN CE uint MNMU(CO uint& n0,CO uint& n1)NE;ST IN CE uint& Normalise(uint& n)NE;TE <TY T> IN CE Mod<M>& Ref(T&& n)NE;};TE <uint M>CL COantsForMod{PU:ST IN CE int BinaryDigitUpperBound()NE;ST IN CE ull MNBasePW(ull&& EX)NE;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;ST CE CO int g_MN_digit = BinaryDigitUpperBound();ST CE CO ull g_MN_base = ull(1) << g_MN_digit;ST CE CO uint g_MN_base_minus = uint(g_MN_base - 1);ST CE CO uint g_MN_M_neg_inverse = uint((g_MN_base - MNBasePW((ull(1) << (g_MN_digit - 1)) - 1)) & g_MN_base_minus);ST CE CO uint g_MN_base_square = uint((((g_MN_base % M) * (g_MN_base % M)) % M) & g_MN_base_minus);ST CE CO uint g_memory_bound = 1000000;ST CE CO uint g_memory_LE = M < g_memory_bound?M:g_memory_bound;};TE <TY T> IN CE T Square(CO T& t);

TE <uint M> IN CE int COantsForMod<M>::BinaryDigitUpperBound()NE{int AN = 0;uint PW = 1;WH(M > PW){AN++;PW <<= 1;}assert(AN < 32);RE AN;}TE <uint M> IN CE ull COantsForMod<M>::MNBasePW(ull&& EX)NE{ull prod = 1;ull PW = M;WH(EX != 0){(EX & 1) == 1?(prod *= PW) &= g_MN_base_minus:prod;EX >>= 1;(PW *= PW) &= g_MN_base_minus;}RE prod;}TE <uint M> IN CE uint Mod<M>::MNForm(CO uint& n)NE{ull n_copy = n;RE uint(MO(MNReduction(n_copy *= COantsForMod<M>::g_MN_base_square)));}TE <uint M> IN CE ull& Mod<M>::MNReduction(ull& n)NE{ull n_sub = n & COantsForMod<M>::g_MN_base_minus;RE ((n += ((n_sub *= COantsForMod<M>::g_MN_M_neg_inverse) &= COantsForMod<M>::g_MN_base_minus) *= M) >>= COantsForMod<M>::g_MN_digit) < M?n:n -= M;}TE <uint M> IN CE uint Mod<M>::MNMU(CO uint& n0,CO uint& n1)NE{ull n0_copy = n0;RE uint(MO(MNReduction(MNReduction(n0_copy *= n1) *= COantsForMod<M>::g_MN_base_square)));}TE <uint M> IN CE uint& Mod<M>::Normalise(uint& n)NE{RE n >= M?n -= M:n;}TE <uint M> TE <TY T> IN CE Mod<M>& Mod<M>::Ref(T&& n)NE{RE *TH;}TE <uint M> IN CE Mod<M>::Mod()NE:m_n(){}TE <uint M> IN CE Mod<M>::Mod(CO Mod<M>& n)NE:m_n(n.m_n){}TE <uint M> IN CE Mod<M>::Mod(Mod<M>& n)NE:m_n(n.m_n){}TE <uint M> IN CE Mod<M>::Mod(Mod<M>&& n)NE:m_n(MO(n.m_n)){}TE <uint M> TE <SFINAE_FOR_MOD()> IN CE Mod<M>::Mod(T& n)NE:m_n(RS(decay_t<T>(n),M)){}TE <uint M> TE <SFINAE_FOR_MOD()> IN CE Mod<M>::Mod(T&& n)NE:m_n(RS(forward<T>(n),M)){}TE <uint M> IN CE Mod<M>& Mod<M>::OP=(CO Mod<M>& n)NE{RE Ref(m_n = n.m_n);}TE <uint M> IN CE Mod<M>& Mod<M>::OP+=(CO Mod<M>& n)NE{RE Ref(Normalise(m_n += n.m_n));}TE <uint M> IN CE Mod<M>& Mod<M>::OP-=(CO Mod<M>& n)NE{RE Ref(Normalise(m_n += M - n.m_n));}TE <uint M> IN CE Mod<M>& Mod<M>::OP*=(CO Mod<M>& n)NE{RE Ref(m_n = MNMU(m_n,n.m_n));}TE <uint M> IN Mod<M>& Mod<M>::OP/=(CO Mod<M>& n){RE OP*=(Mod<M>(n).Invert());}TE <uint M> IN CE Mod<M>& Mod<M>::OP++()NE{RE Ref(m_n < COantsForMod<M>::g_M_minus?++m_n:m_n = 0);}TE <uint M> IN CE Mod<M> Mod<M>::OP++(int)NE{Mod<M> n{*TH};OP++();RE n;}TE <uint M> IN CE Mod<M>& Mod<M>::OP--()NE{RE Ref(m_n == 0?m_n = COantsForMod<M>::g_M_minus:--m_n);}TE <uint M> IN 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(+,Mod<M>(forward<T>(n)) += *TH,Add,uint(RS_CE(ull(m_n) + n.m_n,M)));DF_OF_AR_FOR_MOD(-,Mod<M>(forward<T>(n)).SignInvert() += *TH,Substract,uint(RS_CE(ull(m_n) + (M - n.m_n),M)));DF_OF_AR_FOR_MOD(*,Mod<M>(forward<T>(n)) *= *TH,Multiply,uint(RS_CE(ull(m_n) * n.m_n,M)));DF_OF_AR_FOR_MOD(/,Mod<M>(forward<T>(n)).Invert() *= *TH,Devide,Multiply_CE(Inverse_CE(n)).m_n);TE <uint M> IN CE Mod<M> Mod<M>::OP-() CO NE{RE MO(Mod<M>(*TH).SignInvert());}TE <uint M> IN 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(){assert(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 <> IN Mod<2>& Mod<2>::Invert(){assert(m_n > 0);RE *TH;}TE <uint M> TE <TY T> IN CE Mod<M>& Mod<M>::PositivePW(T&& EX)NE{ull prod = COantsForMod<M>::g_MN_base;ull PW = MNForm(m_n);WH(EX != 0){(EX & 1) == 1?MNReduction(prod *= PW):prod;EX >>= 1;MNReduction(PW *= PW);}RE Ref(m_n = uint(MO(MNReduction(prod))));}TE <> TE <TY T> IN CE Mod<2>& Mod<2>::PositivePW(T&& EX)NE{RE *TH;}TE <uint M> TE <TY T> IN CE Mod<M>& Mod<M>::PW(T&& EX){bool neg = EX < 0;assert(!(neg && m_n == 0));neg?EX *= COantsForMod<M>::g_M_minus_2_neg:EX;RE m_n == 0?*TH:(EX %= COantsForMod<M>::g_M_minus) == 0?Ref(m_n = 1):PositivePW(forward<T>(EX));}TE <uint M> TE <TY T> IN CE Mod<M> Mod<M>::NonNegativePW_CE(CO Mod<M>& repetitive_square,T&& EX)NE{Mod<M> repetitive_square_next{Multiply_CE(repetitive_square,repetitive_square)};Mod<M> one_CE{DeRP(1)};RE MO(EX == 0?one_CE:Multiply_CE(MO((EX & 1) == 1?repetitive_square:one_CE),NonNegativePW_CE(repetitive_square_next,EX >> 1)));}TE <uint M> IN CO Mod<M>& Mod<M>::Inverse(CO uint& n)NE{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 - MNMU(memory[M % LE_curr].m_n,M / LE_curr);LE_curr++;}RE memory[n];}TE <uint M> IN CO Mod<M>& Mod<M>::Factorial(CO uint& n)NE{ST Mod<M> memory[COantsForMod<M>::g_memory_LE] ={one(),one()};ST uint LE_curr = 2;ST ull val_curr = COantsForMod<M>::g_MN_base;ull val_copy;WH(LE_curr <= n){memory[LE_curr].m_n = uint(MO(MNReduction(val_copy = MNReduction(val_curr *= MNForm(LE_curr)))));LE_curr++;}RE memory[n];}TE <uint M> IN CO Mod<M>& Mod<M>::FactorialInverse(CO uint& n)NE{ST Mod<M> memory[COantsForMod<M>::g_memory_LE] ={one(),one()};ST uint LE_curr = 2;ST ull val_curr = COantsForMod<M>::g_MN_base;ull val_copy;WH(LE_curr <= n){memory[LE_curr].m_n = uint(MO(MNReduction(val_copy = MNReduction(val_curr *= MNForm(Inverse(LE_curr).m_n)))));LE_curr++;}RE memory[n];}TE <uint M> IN CE CO uint& Mod<M>::RP() CO NE{RE m_n;}TE <uint M> IN 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>::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{DeRP(1)};RE o;}TE <uint M> IN 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 Mod<M> Inverse(CO Mod<M>& n){RE MO(Mod<M>(n).Invert());}TE <uint M> IN CE Mod<M> Inverse_COrexpr(CO uint& n)NE{RE Mod<M>::NonNegativePW_CE(Mod<M>::DeRP(RS_CE(n,M)),M - 2);}TE <uint M,TY T> IN CE Mod<M> PW(CO Mod<M>& n,CO T& EX){RE MO(Mod<M>(n).PW(T(EX)));}TE <TY T> IN CE Mod<2> PW(CO Mod<2>& n,CO T& EX){RE EX == 0?Mod<2>::DeRP(1):n;}TE <> IN CE Mod<2> Square<Mod<2> >(CO Mod<2>& t){RE t;}TE <uint M> IN 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()) + " + MZ";}TE<uint M,CL Traits> IN basic_ostream<char,Traits>& OP<<(basic_ostream<char,Traits>& os,CO Mod<M>& n){RE os << n.RP();}

#include <immintrin.h>
#define SFINAE_FOR_MA(DEFAULT) TY Arg,enable_if_t<is_constructible<T,Arg>::value>* DEFAULT

TE <TY T>CL TTMA;TE <TY T>CL TOMA{PU:T m_M0;T m_M1;PU:IN CE TOMA(CO T& M0 = T(),CO T& M1 = T())NE;IN CE TOMA(T&& M0,T&& M1)NE;IN CE TOMA(CO TOMA<T>& mat)NE;IN CE TOMA(TOMA<T>&& mat)NE;IN CE TOMA<T>& OP=(CO TOMA<T>& mat)NE;IN CE TOMA<T>& OP=(TOMA<T>&& mat)NE;IN CE TOMA<T>& OP+=(CO TOMA<T>& mat)NE;IN CE TOMA<T>& OP-=(CO TOMA<T>& mat)NE;IN CE TOMA<T>& OP*=(CO TTMA<T>& mat)NE;IN CE TOMA<T>& OP*=(CO T& scalar)NE;TE <SFINAE_FOR_MA(= nullptr)> IN CE TOMA<T>& OP*=(CO Arg& scalar)NE;IN TOMA<T>& OP/=(CO T& scalar);TE <SFINAE_FOR_MA(= nullptr)> IN CE TOMA<T>& OP/=(CO Arg& scalar);IN TOMA<T>& OP%=(CO T& scalar);TE <SFINAE_FOR_MA(= nullptr)> IN CE TOMA<T>& OP%=(CO Arg& scalar);IN CE CO T& GetEntry(CRUI y) CO NE;IN CE T& RefEntry(CRUI y)NE;};

#define VECTORISATION_FOR_TTMA_FOR_MOD(MODULO) TE <> IN TTMA<Mod<MODULO> >& TTMA<Mod<MODULO> >::OP+=(CO TTMA<Mod<MODULO> >& mat)NE{uint TH_copy[4] ={m_M00.m_n,m_M01.m_n,m_M10.m_n,m_M11.m_n};uint mat_copy[4] ={mat.m_M00.m_n,mat.m_M01.m_n,mat.m_M10.m_n,mat.m_M11.m_n};_mm_store_si128((__m128i*)TH_copy,_mm_load_si128((__m128i *)TH_copy) + _mm_load_si128((__m128i *)mat_copy));FOR(i,0,4){Mod<MODULO>::Normalise(TH_copy[i]);}m_M00.m_n = TH_copy[0];m_M01.m_n = TH_copy[1];m_M10.m_n = TH_copy[2];m_M11.m_n = TH_copy[3];RE *TH;}TE <> IN TTMA<Mod<MODULO> >& TTMA<Mod<MODULO> >::OP-=(CO TTMA<Mod<MODULO> >& mat)NE{ST CO uint MODULO_copy[4] ={MODULO,MODULO,MODULO,MODULO};ST CO __m128i v_MODULO = _mm_load_si128((__m128i *)MODULO_copy);uint TH_copy[4] ={m_M00.m_n,m_M01.m_n,m_M10.m_n,m_M11.m_n};uint mat_copy[4] ={mat.m_M00.m_n,mat.m_M01.m_n,mat.m_M10.m_n,mat.m_M11.m_n};_mm_store_si128((__m128i*)TH_copy,(_mm_load_si128((__m128i *)TH_copy) + v_MODULO) - _mm_load_si128((__m128i *)mat_copy));FOR(i,0,4){Mod<MODULO>::Normalise(TH_copy[i]);}m_M00.m_n = TH_copy[0];m_M01.m_n = TH_copy[1];m_M10.m_n = TH_copy[2];m_M11.m_n = TH_copy[3];RE *TH;}

TE <TY T>CL TTMA{PU:T m_M00;T m_M01;T m_M10;T m_M11;PU:IN CE TTMA(CO T& M00,CO T& M01,CO T& M10,CO T& M11)NE;IN CE TTMA(T&& M00,T&& M01,T&& M10,T&& M11)NE;IN CE TTMA(CO T& n = T())NE;TE <SFINAE_FOR_MA(= nullptr)> IN CE TTMA(CO Arg& n)NE;IN CE TTMA(CO TTMA<T>& mat)NE;IN CE TTMA(TTMA<T>&& mat)NE;IN CE TTMA<T>& OP=(CO TTMA<T>& mat)NE;IN CE TTMA<T>& OP=(TTMA<T>&& mat)NE;IN TTMA<T>& OP+=(CO TTMA<T>& mat)NE;IN TTMA<T>& OP-=(CO TTMA<T>& mat)NE;IN CE TTMA<T>& OP*=(CO TTMA<T>& mat)NE;IN CE TTMA<T>& OP*=(CO T& scalar)NE;TE <SFINAE_FOR_MA(= nullptr)> IN CE TTMA<T>& OP*=(CO Arg& scalar)NE;IN TTMA<T>& OP/=(CO TTMA<T>& mat);IN TTMA<T>& OP/=(CO T& scalar);TE <SFINAE_FOR_MA(= nullptr)> IN CE TTMA<T>& OP/=(CO Arg& scalar);IN TTMA<T>& OP%=(CO T& scalar);TE <SFINAE_FOR_MA(= nullptr)> IN CE TTMA<T>& OP%=(CO Arg& scalar);IN TTMA<T>& Invert();IN CE TTMA<T> OP*(CO TTMA<T>& mat) CO NE;IN CE TOMA<T> OP*(CO TOMA<T>& mat) CO NE;IN TTMA<T> OP/(CO TTMA<T>& mat) CO;IN CE TTMA<T> Square() CO NE;IN CE CO T& GetEntry(CRUI y,CRUI x) CO NE;IN CE T& RefEntry(CRUI y,CRUI x)NE;};TE <TY T,SFINAE_FOR_MA(= nullptr)> IN CE TTMA<T> OP*(CO Arg& scalar,CO TTMA<T>& mat)NE;TE <TY T,SFINAE_FOR_MA(= nullptr)> IN CE TTMA<T> OP*(CO TTMA<T>& mat,CO T& scalar)NE;TE <TY T,SFINAE_FOR_MA(= nullptr)> IN TTMA<T> OP/(CO TTMA<T>& mat,CO Arg& scalar);TE <TY T,SFINAE_FOR_MA(= nullptr)> IN TTMA<T> OP%(CO TTMA<T>& mat,CO Arg& scalar);

TE <TY T> IN CE TOMA<T>::TOMA(CO T& M0,CO T& M1)NE:m_M0(M0),m_M1(M1){}TE <TY T> IN CE TOMA<T>::TOMA(T&& M0,T&& M1)NE:m_M0(MO(M0)),m_M1(MO(M1)){}TE <TY T> IN CE TOMA<T>::TOMA(CO TOMA<T>& mat)NE:m_M0(mat.m_M0),m_M1(mat.m_M1){}TE <TY T> IN CE TOMA<T>::TOMA(TOMA<T>&& mat)NE:m_M0(MO(mat.m_M0)),m_M1(MO(mat.m_M1)){}TE <TY T> IN CE TOMA<T>& TOMA<T>::OP=(CO TOMA<T>& mat)NE{if(&mat != TH){m_M0 = mat.m_M0;m_M1 = mat.m_M1;}RE *TH;}TE <TY T> IN CE TOMA<T>& TOMA<T>::OP=(TOMA<T>&& mat)NE{m_M0 = MO(mat.m_M0);m_M1 = MO(mat.m_M1);RE *TH;}TE <TY T> IN CE TOMA<T>& TOMA<T>::OP+=(CO TOMA<T>& mat)NE{m_M0 += mat.m_M0;m_M1 += mat.m_M1;RE *TH;}TE <TY T> IN CE TOMA<T>& TOMA<T>::OP-=(CO TOMA<T>& mat)NE{m_M0 -= mat.m_M0;m_M1 -= mat.m_M1;RE *TH;}TE <TY T> IN CE TOMA<T>& TOMA<T>::OP*=(CO TTMA<T>& mat)NE{RE OP=(mat * *TH);}TE <TY T> IN CE TOMA<T>& TOMA<T>::OP*=(CO T& scalar)NE{m_M0 *= scalar;m_M1 *= scalar;RE *TH;}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TOMA<T>& TOMA<T>::OP*=(CO Arg& scalar)NE{RE OP*=(T(scalar));}TE <TY T> IN TOMA<T>& TOMA<T>::OP/=(CO T& scalar){m_M0 /= scalar;m_M1 /= scalar;RE *TH;}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TOMA<T>& TOMA<T>::OP/=(CO Arg& scalar){RE OP/=(T(scalar));}TE <TY T> IN TOMA<T>& TOMA<T>::OP%=(CO T& scalar){m_M0 %= scalar;m_M1 %= scalar;RE *TH;}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TOMA<T>& TOMA<T>::OP%=(CO Arg& scalar){RE OP%=(T(scalar));}TE <TY T> IN CE CO T& TOMA<T>::GetEntry(CRUI y) CO NE{RE y == 0?m_M0:m_M1;}TE <TY T> IN CE T& TOMA<T>::RefEntry(CRUI y)NE{RE y == 0?m_M0:m_M1;}

TE <TY T> IN CE TTMA<T>::TTMA(CO T& M00,CO T& M01,CO T& M10,CO T& M11) NE:m_M00(M00),m_M01(M01),m_M10(M10),m_M11(M11){}TE <TY T> IN CE TTMA<T>::TTMA(T&& M00,T&& M01,T&& M10,T&& M11) NE:m_M00(MO(M00)),m_M01(MO(M01)),m_M10(MO(M10)),m_M11(MO(M11)){}TE <TY T> IN CE TTMA<T>::TTMA(CO T& n) NE:m_M00(n),m_M01(),m_M10(),m_M11(n){}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TTMA<T>::TTMA(CO Arg& n) NE:TTMA(T(n)){}TE <TY T> IN CE TTMA<T>::TTMA(CO TTMA<T>& mat) NE:m_M00(mat.m_M00),m_M01(mat.m_M01),m_M10(mat.m_M10),m_M11(mat.m_M11){}TE <TY T> IN CE TTMA<T>::TTMA(TTMA<T>&& mat) NE:m_M00(MO(mat.m_M00)),m_M01(MO(mat.m_M01)),m_M10(MO(mat.m_M10)),m_M11(MO(mat.m_M11)){}TE <TY T> IN CE TTMA<T>& TTMA<T>::OP=(CO TTMA<T>& mat) NE{if(&mat != TH){m_M00 = mat.m_M00;m_M01 = mat.m_M01;m_M10 = mat.m_M10;m_M11 = mat.m_M11;}RE *TH;}TE <TY T> IN CE TTMA<T>& TTMA<T>::OP=(TTMA<T>&& mat) NE{m_M00 = MO(mat.m_M00);m_M01 = MO(mat.m_M01);m_M10 = MO(mat.m_M10);m_M11 = MO(mat.m_M11);RE *TH;}TE <TY T> IN TTMA<T>& TTMA<T>::OP+=(CO TTMA<T>& mat) NE{m_M00 += mat.m_M00;m_M01 += mat.m_M01;m_M10 += mat.m_M10;m_M11 += mat.m_M11;RE *TH;}TE <TY T> IN TTMA<T>& TTMA<T>::OP-=(CO TTMA<T>& mat) NE{m_M00 -= mat.m_M00;m_M01 -= mat.m_M01;m_M10 -= mat.m_M10;m_M11 -= mat.m_M11;RE *TH;}TE <TY T> IN CE TTMA<T>& TTMA<T>::OP*=(CO TTMA<T>& mat) NE{RE OP=(*TH * mat);}TE <TY T> IN CE TTMA<T>& TTMA<T>::OP*=(CO T& scalar) NE{m_M00 *= scalar;m_M01 *= scalar;m_M10 *= scalar;m_M11 *= scalar;RE *TH;}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TTMA<T>& TTMA<T>::OP*=(CO Arg& scalar) NE{RE OP*=(T(scalar));}TE <TY T> IN TTMA<T>& TTMA<T>::OP/=(CO TTMA<T>& mat){RE OP=(*TH / mat);}TE <TY T> IN TTMA<T>& TTMA<T>::OP/=(CO T& scalar){RE OP*=(T(1) / scalar);}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TTMA<T>& TTMA<T>::OP/=(CO Arg& scalar){RE OP/=(T(scalar));}TE <TY T> IN TTMA<T>& TTMA<T>::OP%=(CO T& scalar){m_M00 %= scalar;m_M01 %= scalar;m_M10 %= scalar;m_M11 %= scalar;RE *TH;}TE <TY T> TE <SFINAE_FOR_MA()> IN CE TTMA<T>& TTMA<T>::OP%=(CO Arg& scalar){RE OP%=(T(scalar));}TE <TY T> IN TTMA<T>& TTMA<T>::Invert(){CO T det_inv{T(1) / (m_M00 * m_M11 - m_M01 * m_M10)};swap(m_M00,m_M11);m_M01 = T() - m_M01;m_M11 = T() - m_M10;RE OP*=(det_inv);}TE <TY T> IN CE TTMA<T> TTMA<T>::OP*(CO TTMA<T>& mat) CO NE{RE TTMA<T>(m_M00 * mat.m_M00 + m_M01 * mat.m_M10,m_M00 * mat.m_M01 + m_M01 * mat.m_M11,m_M10 * mat.m_M00 + m_M11 * mat.m_M10,m_M10 * mat.m_M01 + m_M11 * mat.m_M11);}TE <TY T> IN CE TOMA<T> TTMA<T>::OP*(CO TOMA<T>& mat) CO NE{RE TOMA<T>(m_M00 * mat.m_M0 + m_M01 * mat.m_M1,m_M10 * mat.m_M0 + m_M11 * mat.m_M1);}TE <TY T> IN TTMA<T> TTMA<T>::OP/(CO TTMA<T>& mat) CO{CO T det_inv{T(1) / (mat.m_M00 * mat.m_M11 - mat.m_M01 * mat.m_M10)};RE TTMA<T>((m_M00 * mat.m_M11 - m_M01 * mat.m_M10) * det_inv,(m_M01 * mat.m_M00 - m_M00 * mat.m_M01) * det_inv,(m_M10 * mat.m_M11 - m_M11 * mat.m_M10) * det_inv,(m_M11 * mat.m_M00 - m_M10 * mat.m_M01) * det_inv);}TE <TY T> IN CE TTMA<T> TTMA<T>::Square() CO NE{RE TTMA<T>(m_M00 * m_M00 + m_M01 * m_M10,(m_M00 + m_M11) * m_M01,m_M10 * (m_M00 + m_M11),m_M10 * m_M01 + m_M11 * m_M11);}TE <TY T> IN CE CO T& TTMA<T>::GetEntry(CRUI y,CRUI x) CO NE{RE y == 0?x == 0?m_M00:m_M01:x == 0?m_M10:m_M11;}TE <TY T> IN CE T& TTMA<T>::RefEntry(CRUI y,CRUI x) NE{RE y == 0?x == 0?m_M00:m_M01:x == 0?m_M10:m_M11;}TE <TY T> IN TTMA<T> OP+(CO TTMA<T>& mat1,CO TTMA<T>& mat2) NE{RE MO(TTMA<T>(mat1) += mat2);}TE <TY T> IN TTMA<T> OP-(CO TTMA<T>& mat1,CO TTMA<T>& mat2) NE{RE MO(TTMA<T>(mat1) -= mat2);}TE <TY T> IN CE TTMA<T> OP*(CO T& scalar,CO TTMA<T>& mat) NE{RE MO(TTMA<T>(mat) *= scalar);}TE <TY T,SFINAE_FOR_MA()> IN CE TTMA<T> OP*(CO Arg& scalar,CO TTMA<T>& mat) NE{RE T(scalar) * mat;}TE <TY T> IN CE TTMA<T> OP*(CO TTMA<T>& mat,CO T& scalar) NE{RE MO(TTMA<T>(mat) *= scalar);}TE <TY T,SFINAE_FOR_MA()> IN CE TTMA<T> OP*(CO TTMA<T>& mat,CO Arg& scalar) NE{RE mat * T(scalar);}TE <TY T> IN TTMA<T> OP/(CO TTMA<T>& mat,CO T& scalar){RE MO(TTMA<T>(mat) /= scalar);}TE <TY T,SFINAE_FOR_MA()> IN TTMA<T> OP/(CO TTMA<T>& mat,CO Arg& scalar){RE mat / T(scalar);}TE <TY T> IN TTMA<T> OP%(CO TTMA<T>& mat,CO T& scalar){RE MO(TTMA<T>(mat) %= scalar);}TE <TY T,SFINAE_FOR_MA()> IN TTMA<T> OP%(CO TTMA<T>& mat,CO Arg& scalar){RE mat % T(scalar);}TE <TY T> IN CE TTMA<T> Square(CO TTMA<T>& mat) NE{RE mat.Square();}

IN CEXPR(ll,P,998244353);US MP = Mod<P>;TE <TY T> IN CE CO uint LimitOfPWForFFT{};TE <TY T> IN CE CO uint BorderForFFT{};TE <TY T> IN CO T (&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<T>];TE <TY T> IN CO T (&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<T>];TE <> IN CE CO uint LimitOfPWForFFT<MP> = 24;TE <> IN CE CO uint BorderForFFT<MP> = 4;TE <> IN CO MP (&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<MP>]{ST CO MP PRT[ LimitOfPWForFFT<MP> ] ={MP(1),MP(998244352),MP(911660635),MP(625715529),MP(373294451),MP(827987769),MP(280333251),MP(581015842),MP(628092333),MP(300892551),MP(586046298),MP(615001099),MP(318017948),MP(64341522),MP(106061068),MP(304605202),MP(631920086),MP(857779016),MP(841431251),MP(805775211),MP(390359979),MP(923521),MP(961),MP(31)};RE PRT;}TE <> IN CO MP (&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT<MP>]{ST CO MP PRT[ LimitOfPWForFFT<MP> ] ={MP(1),MP(998244352),MP(86583718),MP(488723995),MP(369330050),MP(543653592),MP(382946991),MP(844956623),MP(91420391),MP(433414612),MP(288894979),MP(260490556),MP(857007890),MP(736054570),MP(474649464),MP(948509906),MP(114942468),MP(962405921),MP(667573957),MP(46809892),MP(304321983),MP(30429817),MP(293967900),MP(128805723)};RE PRT;}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;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++;}uint two_PW_curr = 1;uint two_PW_curr_2 = 2;CO T& zeta_0 = PRT[0];T zeta,diff;CO T* p_zeta_i;uint bit_num_copy,i,j,j_butterfly,j_lim;WH(two_PW_curr < two_PW){bit_num = 0;i = 0;WH(i < two_PW){zeta = zeta_0;p_zeta_i = &zeta_0 + 2;bit_num_copy = bit_num;WH(bit_num_copy != 0){if(bit_num_copy % 2 == 1){zeta *= *p_zeta_i;}bit_num_copy /= 2;p_zeta_i++;}j = i;j_lim = i + two_PW_curr;WH(j < j_lim){j_butterfly = j + two_PW_curr;T& f_j = f[j + N_input_start];T& f_j_butterfly = f[j_butterfly + N_input_start];diff = f_j - f_j_butterfly;f_j += f_j_butterfly;f_j_butterfly = zeta * diff;j++;}bit_num++;i += two_PW_curr_2;}swap(two_PW_curr,two_PW_curr_2);two_PW_curr_2 *= 4;}CO uint LE_fixed = N_output_lim + N_input_start;WH(f.SZ() > LE_fixed){f.pop_back();}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_constructible<T,decay_t<Arg> >::value>* DEFAULT
#define DF_BODY_OF_PARTIAL_SPECIALISATION_OF_MU_OF_PO(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 DF_OF_PARTIAL_SPECIALISATION_OF_MU_OF_PO(TYPE) DF_BODY_OF_PARTIAL_SPECIALISATION_OF_MU_OF_PO(TYPE,CO PO<TYPE>&,TH == &f?TH_copy:f);DF_BODY_OF_PARTIAL_SPECIALISATION_OF_MU_OF_PO(TYPE,PO<TYPE>&&,MO(f));

TE <TY T>CL PO{PU:VE<T> m_f;uint m_SZ;PU:IN PO();IN PO(CO T& t);IN PO(T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN PO(CO Arg& n);IN PO(CO PO<T>& f);IN PO(PO<T>&& f);IN PO(CRUI i,CO T& t);IN PO(CRUI i,T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN PO(CRUI i,CO Arg& n);IN PO(CO VE<T>& f);IN PO(VE<T>&& f);IN PO<T>& OP=(CO T& t);IN PO<T>& OP=(T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN PO<T>& OP=(CO Arg& n);IN PO<T>& OP=(CO PO<T>& f);IN PO<T>& OP=(PO<T>&& f);IN PO<T>& OP=(CO VE<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);PO<T>& OP/=(CO T& t);IN PO<T>& OP/=(CO PO<T>& f);PO<T>& OP%=(CO T& t);PO<T>& OP%=(CO PO<T>& f);IN PO<T> OP-() CO;PO<T>& OP<<=(CO T& t);IN CO VE<T>& GetCoefficient() CO NE;IN CRUI SZ() CO 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> TransposeQuotient(CO PO<T>& f0,CRUI f0_transpose_SZ,CO PO<T>& f1_transpose_inverse,CRUI f1_SZ);ST PO<T> Transpose(CO PO<T>& f,CRUI f_transpose_SZ);ST IN CO PO<T>& zero();ST IN CO T& CO_zero();ST IN CO T& CO_one();ST IN CO T& CO_minus_one();};

#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>::CO_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>::CO_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;FFT<T>(f0,N_INPUT_START_0,N_INPUT_LIM_0,two_PW,EX);DC_OF_F1;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;true;i--){MU_FORMULA;if(i == I_START){break;}}CO uint N_output_start_shifted = N_OUTPUT_START_SHIFTED;CO uint N_output_lim_shifted = N_output_lim_fixed - N_input_start_0_start_1;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 >::CO_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) CRUI N = f.GetTruncation();uint PW;uint PW_2 = 1;TRPO< TYPE > f_exp{PW_2,PO< TYPE >::CO_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_PARTIAL_SPECIALISATION_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;TE <> CE CO uint FFT_MU_border_1_2< TYPE > = BORDER_1_2;TE <> CE CO uint FFT_MU_border_1_2_EX< TYPE > = BORDER_1_2_EX;TE <> CE CO uint FFT_MU_border_1_2_inv< TYPE > = BORDER_1_2_INV;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));}

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,CO T& t);IN TRPO(CRUI N,CO PO<T>& f);IN TRPO(CRUI N,PO<T>&& f);IN TRPO(CRUI N,CRUI i,CO T& t);IN TRPO(CRUI N,CRUI i,T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN TRPO(CRUI N,CRUI i,CO Arg& t);IN TRPO(CRUI N,VE<T>&& f);IN TRPO<T>& OP=(CO TRPO<T>& f);IN TRPO<T>& OP=(TRPO<T>&& f);IN TRPO<T>& OP=(CO T& t);IN TRPO<T>& OP=(T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN TRPO<T>& OP=(CO Arg& n);IN TRPO<T>& OP=(CO PO<T>& f);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>& FFT_MU(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> IN CE CO uint FFT_MU_border_0{};TE <TY T> IN CE CO uint FFT_MU_border_1{};TE <TY T> IN CE CO uint FFT_MU_border_1_2{};TE <TY T> IN CE CO uint FFT_MU_border_1_2_EX{};TE <TY T> IN CE CO uint FFT_MU_border_1_2_inv{};

TE <TY T> IN TRPO<T>::TRPO(CRUI N):PO<T>(),m_N(N){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CO TRPO<T>& f):PO<T>(f),m_N(f.m_N){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(TRPO<T>&& f):PO<T>(MO(f)),m_N(MO(f.m_N)){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CO T& t):PO<T>(t),m_N(N){PO<T>::m_f.reserve(m_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];}PO<T>::m_f.reserve(m_N);}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){PO<T>::m_f.reserve(m_N);}else{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,CRUI i,CO T& t):PO<T>(),m_N(N){if(i < m_N?t != PO<T>::CO_zero():false){PO<T>::OP[](i) = t;}PO<T>::m_f.reserve(m_N);}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>::CO_zero():false){PO<T>::OP[](i) = MO(t);}PO<T>::m_f.reserve(m_N);}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(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){PO<T>::m_f.reserve(m_N);}else{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]);}PO<T>::m_f.reserve(m_N);}}
TE <TY T> IN TRPO<T>& TRPO<T>::OP=(CO TRPO<T>& f){PO<T>::OP=(f);m_N = f.m_N;PO<T>::m_f.reserve(m_N);RE *TH;}
TE <TY T> IN TRPO<T>& TRPO<T>::OP=(TRPO<T>&& f){PO<T>::OP=(MO(f));m_N = MO(f.m_N);PO<T>::m_f.reserve(m_N);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=(T&& t){PO<T>::OP=(MO(t));RE *TH;}
TE <TY T> TE <SFINAE_FOR_PO()> IN TRPO<T>& TRPO<T>::OP=(CO Arg& n){PO<T>::OP=(T(n));RE *TH;}
TE <TY T> IN TRPO<T>& TRPO<T>::OP=(CO PO<T>& f){RE OP=(TRPO<T>(m_N,f));}
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 TRPO<T>::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):TRPO<T>::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 TRPO<T>::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):TRPO<T>::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_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,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>::FFT_MU(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,VE<T>&& f1 = MO(f.PO<T>::m_f),N_input_start_1,N_input_max_1 + 1,f0,f0.resize(product_LE),0,f0[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 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_0,N_input_max_1,N_input_start_1),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,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(m_N);}else{PO<T>::m_f.reserve(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] = i * f.PO<T>::m_f[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){RE Integral<T>(Differential<T>(f) /= f);}TE <TY T> IN TRPO<T> PW(CO TRPO<T>& f,CO T& t){RE Exp(Log(f) *= t);}DF_OF_PARTIAL_SPECIALISATION_OF_MU_OF_TR_PO(MP,17,512,1024,10,997269505);

TE <TY T> IN PO<T>::PO():m_f(),m_SZ(0){}TE <TY T> IN PO<T>::PO(CO T& t):PO(){if(t != CO_zero()){OP[](0) = t;}}TE <TY T> IN PO<T>::PO(T&& t):PO(){if(t != CO_zero()){OP[](0) = MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>::PO(CO Arg& n):PO(T(n)){}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(MO(f.m_SZ)){}TE <TY T> IN PO<T>::PO(CRUI i,CO T& t):PO(){if(t != CO_zero()){OP[](i) = t;}}TE <TY T> IN PO<T>::PO(CRUI i,T&& t):PO(){if(t != CO_zero()){OP[](i) = MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>::PO(CRUI i,CO Arg& n):PO(i,T(n)){}TE <TY T> IN PO<T>::PO(CO VE<T>& f):m_f(f),m_SZ(m_f.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>::OP=(CO T& t){m_f.clear();m_SZ = 0;OP[](0) = t;RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(T&& t){m_f.clear();m_SZ = 0;OP[](0) = MO(t);RE *TH;}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>& PO<T>::OP=(CO Arg& n){RE OP=(T(n));}TE <TY T> IN PO<T>& PO<T>::OP=(CO PO<T>& f){m_f = f.m_f;m_SZ = f.m_SZ;RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(PO<T>&& f){m_f = MO(f.m_f);m_SZ = MO(f.m_SZ);RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(CO VE<T>& f){m_f = 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>CO T& PO<T>::OP[](CRUI i) CO{if(m_SZ <= i){RE CO_zero();}RE m_f[i];}TE <TY T> IN T& PO<T>::OP[](CRUI i){if(m_SZ <= i){CO T& z = CO_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,CO_one()) - t))[0]);}TE <TY T>PO<T>& PO<T>::OP+=(CO PO<T>& f){for(uint i = 0;i < f.m_SZ;i++){OP[](i) += f.m_f[i];}RE *TH;}TE <TY T>PO<T>& PO<T>::OP-=(CO PO<T>& f){for(uint i = 0;i < f.m_SZ;i++){OP[](i) -= f.m_f[i];}RE *TH;}DF_OF_PARTIAL_SPECIALISATION_OF_MU_OF_PO(MP);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?i - m_SZ + 1:0;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 OP=(MO(product));}TE <TY T> IN PO<T>& PO<T>::OP*=(PO<T>&& f){RE OP*=(f);};TE <TY T>PO<T>& PO<T>::OP/=(CO T& t){if(t == CO_one()){RE *TH;}CO T t_inv{CO_one() / t};for(uint i = 0;i < m_SZ;i++){OP[](i) *= t_inv;}RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP/=(CO PO<T>& f){RE m_SZ < f.m_SZ?*TH:OP=(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 f0;}assert(f1.m_SZ > 0);CO uint f0_transpose_SZ = f0.m_SZ - f1.m_SZ + 1;CO uint f1_transpose_SZ = f0_transpose_SZ < f1.m_SZ?f0_transpose_SZ:f1.m_SZ;RE TransposeQuotient(f0,f0_transpose_SZ,Inverse(TRPO<T>(f0_transpose_SZ,Transpose(f1,f1_transpose_SZ))),f1.m_SZ);}TE <TY T>PO<T> PO<T>::TransposeQuotient(CO PO<T>& f0,CRUI f0_transpose_SZ,CO PO<T>& f1_transpose_inverse,CRUI f1_SZ){TRPO<T> f0_transpose{f0_transpose_SZ,Transpose(f0,f0_transpose_SZ)};f0_transpose *= f1_transpose_inverse;for(uint d0 = (f0_transpose_SZ + 1) / 2;d0 < f0_transpose_SZ;d0++){::swap(f0_transpose.PO<T>::m_f[d0],f0_transpose.PO<T>::m_f[ f0_transpose_SZ - 1 - d0 ]);}RE f0_transpose;}TE <TY T>PO<T> PO<T>::Transpose(CO PO<T>& f,CRUI f_transpose_SZ){VE<T> f_transpose(f_transpose_SZ);for(uint d = 0;d < f_transpose_SZ;d++){f_transpose[d] = f.m_f[f.m_SZ - 1 - d];}RE PO<T>(MO(f_transpose));}TE <TY T>PO<T>& PO<T>::OP%=(CO T& t){if(t == CO_one()){RE OP=(zero());}for(uint i = 0;i < m_SZ;i++){m_f[i] %= t;}RE *TH;}TE <TY T>PO<T>& PO<T>::OP%=(CO PO<T>& f){if(m_SZ >= f.m_SZ){OP-=((*TH / f) * f);ReMORedundantZero();}RE *TH;}TE <TY T> IN PO<T> PO<T>::OP-() CO{RE MO(PO<T>() -= *TH);}TE <TY T >PO<T>& PO<T>::OP<<=(CO T& t){if(m_SZ > 0){for(uint d = 0;d < m_SZ;d++){m_f[d] *= T::Factorial(d);}TRPO<T> exp_t_transpose{m_SZ * 2};T PW_t = CO_one();for(uint d = 0;d < m_SZ;d++){exp_t_transpose[m_SZ - 1 - d] = PW_t * T::FactorialInverse(d);PW_t *= t;}exp_t_transpose *= *TH;for(uint d = 0;d < m_SZ;d++){m_f[d] = exp_t_transpose.PO<T>::m_f[d + m_SZ - 1] * T::FactorialInverse(d);}}RE *TH;}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>::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 = CO_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 T& PO<T>::CO_zero(){ST CO T z{0};RE z;}TE <TY T> IN CO T& PO<T>::CO_one(){ST CO T o{1};RE o;}TE <TY T> IN CO T& PO<T>::CO_minus_one(){ST CO T m{-1};RE m;}TE <TY T>bool OP==(CO PO<T>& f0,CO T& t1){CRUI SZ = f0.SZ();CO T& zero = PO<T>::CO_zero();for(uint i = 1;i < SZ;i++){if(f0[i] != zero){RE false;}}RE f0[0] == t1;}TE <TY T>bool OP==(CO PO<T>& f0,CO PO<T>& f1){CRUI SZ0 = f0.SZ();CRUI SZ1 = f1.SZ();CRUI SZ = SZ0 < SZ1?SZ1:SZ0;for(uint i = 0;i < SZ;i++){if(f0[i] != f1[i]){RE false;}}RE true;}TE <TY T,TY P> IN bool OP!=(CO PO<T>& f0,CO P& f1){RE !(f0 == f1);}TE <TY T,TY P> IN PO<T> OP+(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) += f1);}TE <TY T,TY P> IN PO<T> OP-(CO PO<T>& f){RE PO<T>::zero() - f;}TE <TY T,TY P> IN PO<T> OP-(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) -= f1);}TE <TY T,TY P> IN PO<T> OP*(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) *= f1);}TE <TY T> IN PO<T> OP/(CO PO<T>& f0,CO T& t1){RE MO(PO<T>(f0) /= t1);}TE <TY T> IN PO<T> OP/(CO PO<T>& f0,CO PO<T>& f1){RE PO<T>::Quotient(f0,f1);}TE <TY T,TY P> IN PO<T> OP%(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) %= f1);}TE <TY T> PO<T> OP<<(CO PO<T>& f,CO T& t){RE MO(PO<T>(f) <<= t);};TE <TY T,TE <TY...> TY V>T& Prod(V<T>& f){if(f.empty()){f.push_back(T(1));}if(f.SZ() == 1){RE f.front();}auto IT = f.BE(),EN = f.EN();WH(IT != EN){T& t = *IT;IT++;if(IT != EN){t *= *IT;IT = f.erase(IT);}}RE Prod(f);}

US MPN = PO<MP>;
US MPNK = PO<MPN>;

VECTORISATION_FOR_TTMA_FOR_MOD( P );

// 前計算はO(fold^4)で、実行時間はclangで
// fold = 24 = 2^4+2^3の時は13[ms]程度、
// fold = 28 = 2^4+2^3+2^2の時は20[ms]程度、
// fold = 32 = 2^5の時は31[ms]程度、
// fold = 36 = 2^5+2^2の時は44[ms]程度、
// fold = 40 = 2^5+2^3の時は63[ms]程度、
// fold = 45 = 2^5+2^3+2^2の時は92[ms]程度、
// fold = 46 = 2^5+2^3+2^2+2^1の時は100[ms]程度
// fold = 47 = 2^5+2^3+2^2+2^1+2^0の時は105[ms]程度、
// fold = 48 = 2^5+2^4の時は116[ms]程度、
// fold = 64 = 2^6の時は300[ms]程度、
// fold = 80 = 2^6+2^4の時は650[ms]程度、
// fold = 96 = 2^6+2^5の時は1260[ms]程度、
// fold = 128 = 2^7の時は3700[ms]程度かかる。
// 各クエリの乗算回数は愚直代入版で(8K/fold)+10fold+4fold^2程度なので
// foldは(2(Kの上限))^{1/3}~58.48より大きくなると全体の実行速度が落ちる。
// 恐らく32付近で最小化されている気がする。
inline CEXPR( int , fold , 32 );
inline CEXPR( int , deg_max , fold + 1 );
inline CEXPR( int , deg_lim , deg_max + 1 );

class fold_power
{
public:
  MP m_val[deg_lim];
  CE fold_power() : m_val() { MP fold1{ MP::DeRP( fold ) }; MP power{ MP::DeRP( 1 ) }; FOREQ( deg , 0 , deg_max ){ m_val[deg] = power; power *= fold1; } }
};

#define SET_CEXPR( NUM )				\
  CE MP c ## NUM { MP::DeRP( NUM ) };	\
  
int main()
{
  UNTIE;
  CEXPR( int , bound_T , 100000 );
  CIN_ASSERT( T , 1 , bound_T );
  // 本体のO((fold^2+max{K})T)部分を定数倍改善するための前計算
  SET_CEXPR( 0 );
  SET_CEXPR( 1 );
  SET_CEXPR( 2 );
  CE const MP c2_neg{ MP::DeRP( P - 2 ) };
  CE const MP c2_inv{ Mod<P>::DeRP( ( P + 1 ) / 2 ) };
  CE MP c2_inv_neg{ Mod<P>::DeRP( ( P - 1 ) / 2 ) };
  CE MP c1_neg{ Mod<P>::DeRP( P - 1 ) };
  CE TOMA<MP> v{ MP::DeRP( 1 ) , MP::DeRP( 0 ) };
  const MPN& zero = MPN::zero();
  MPN one{ 0 , c1 };
  MPN one_neg{ 0 , c1_neg };
  MPN two_neg{ 0 , c2_neg };
  MPN two_inv{ 0 , c2_inv };
  MPN two_inv_neg{ 0 , c2_inv_neg };
  MPN N_plus_half{ move( MPN( 1 , c1 ) += c2_inv ) };
  MPN N_2{ 1 , c2 };
  MPNK quad_zero{ 0 , zero };
  MPNK quad_one{ 0 , one };
  MPNK quad_one_neg{ 0 , one_neg };
  MPNK quad_two_neg{ 0 , two_neg };
  MPNK quad_two_inv_neg{ 0 , two_inv_neg };
  MPNK quad_N_plus_half{ 0 , N_plus_half };
  MPNK quad_N_2{ 0 , N_2 };
  MPNK K_shift{ 1 , one };
  MPNK K_shift_2_neg{ 1 , two_neg };
  MPNK K_shift_N_plus_half{ 1 , N_plus_half };
  MPNK K2_shift_half_neg{ 2 , two_inv_neg };
  TTMA<MPNK> MNk_shift
  { K_shift_2_neg + N_2 , K2_shift_half_neg + K_shift_N_plus_half ,
      MPNK( quad_one ) , MPNK( quad_zero ) };
  LI<TTMA<MPNK> > M = {};
  CEXPR( int , fold_minus , fold - 1 );
  REPEAT( fold_minus ){
    M.push_front( MNk_shift );
    K_shift_N_plus_half.m_f[0] += N_plus_half;
    K2_shift_half_neg.m_f[0] += ( K2_shift_half_neg.m_f[1] += one_neg ) + two_inv;
    MNk_shift.m_M00.m_f[0]+= two_neg;
    MNk_shift.m_M01 = K2_shift_half_neg + K_shift_N_plus_half;
  }
  M.push_front( move( MNk_shift ) );
  VE<MPN> comb[deg_lim] = {};
  comb[0].push_back( one );
  FOREQ( deg , 1 , deg_max ){
    MPN* p_comb_deg_minus_right = &( comb[deg - 1][0] );
    MPN* p_comb_deg_minus_left = p_comb_deg_minus_right++;
    VE<MPN>& comb_deg = comb[deg];
    comb_deg = VE<MPN>( deg + 1 ,  zero );
    comb_deg[0] = comb_deg[deg] = one;
    uint deg_half = ( deg + 1 ) / 2;
    FOR( ddeg , 1 , deg_half ){
      comb_deg[ddeg] = comb_deg[deg - ddeg] = *p_comb_deg_minus_left + *p_comb_deg_minus_right;
      p_comb_deg_minus_left++;
      p_comb_deg_minus_right++;
    }
    if( deg % 2 == 0 ){
      comb_deg[deg_half] = *p_comb_deg_minus_left + *p_comb_deg_minus_left;
    }
  }
  CE fold_power fp{};
  MPN fp1[deg_lim];
  FOREQ( deg , 0 , deg_max ){
    fp1[deg] = MPN( 0 , fp.m_val[deg] );
  }
  VE<VE<MPN> > comb_fp{};
  comb_fp.reserve( deg_lim );
  comb_fp.push_back( VE<MPN>() );
  FOR( ddeg , 1 , deg_lim ){
    VE<MPN>& comb_ddeg = comb[ddeg];
    comb_fp.push_back( VE<MPN>() );
    VE<MPN>& comb_fp_ddeg = comb_fp[ddeg];
    comb_fp_ddeg.reserve( ddeg );
    comb_fp_ddeg.push_back( fp1[ddeg] );
    FOR( dddeg , 1 , ddeg ){
      comb_fp_ddeg.push_back( comb_ddeg[dddeg] * fp1[ddeg - dddeg] );
    }
  }
  TTMA<MPNK> prod[deg_lim];
  TTMA<MPNK>& prod_curr = prod[deg_max];
  prod_curr = Prod( M );
  MPNK* p_prod_curr[4] = { &( prod_curr.m_M00 ) , &( prod_curr.m_M01 ) , &( prod_curr.m_M10 ) , &( prod_curr.m_M11 ) };
  FOR( deg , 0 , deg_max ){
    prod[deg] = prod_curr;
    FOR( i , 0 , 4 ){
      MPNK& prod_curr_i = *( p_prod_curr[i] );
      const uint& size = prod_curr_i.size();
      FOR( ddeg , 1 , size ){
	VE<MPN>& comb_fp_ddeg = comb_fp[ddeg];
	MPN& prod_curr_i_ddeg = prod_curr_i.m_f[ddeg];
	FOR( dddeg , 0 , ddeg ){
	  prod_curr_i.m_f[dddeg] += prod_curr_i_ddeg * comb_fp_ddeg[dddeg];
	}
      }
    }
  }
  // 本体O((fold^2+max(K))T)の計算時間はT=1000で92[ms]
  VE<uint> coef[deg_lim][4] = {};
  map<uint,uint> coef_LI{};
  FOREQ( deg , 0 , deg_max ){
    TTMA<MPNK>& diff_deg = prod[deg];
    MPN* p_diff_deg[4] = { &( diff_deg.m_M00[0] ) , &( diff_deg.m_M01[0] ) , &( diff_deg.m_M10[0] ) , &( diff_deg.m_M11[0] ) };
    VE<uint> ( &coef_deg )[4] = coef[deg];
    FOR( i , 0 , 4 ){
      MPN& diff_deg_i = *( p_diff_deg[i] );
      const uint& size = diff_deg_i.size();
      VE<uint>& coef_deg_i = coef_deg[i];
      coef_deg_i.reserve( size );
      FOR( d , 0 , size ){
	const uint& diff_deg_i_d = diff_deg_i[d].RP(); 
	coef_deg_i.push_back( diff_deg_i_d );
	if( diff_deg_i_d > 0 ){
	  coef_LI[diff_deg_i_d];
	}
      }
    }
    TTMA<MPNK>* p_prod_curr = &( prod[deg_max] );
    TTMA<MPNK>* p_prod_prev = p_prod_curr--;
    FOREQ( ddeg_trans , deg + 1 , deg_max ){
      *p_prod_prev -= *p_prod_curr;
      p_prod_prev->m_M00.ReMORedundantZero();
      p_prod_prev->m_M01.ReMORedundantZero();
      p_prod_prev->m_M10.ReMORedundantZero();
      p_prod_prev->m_M11.ReMORedundantZero();
      p_prod_curr--;
      p_prod_prev--;
    }
  }
  uint coef_size = 0;
  VE<MP> coef_array{};
  coef_array.reserve( coef_LI.size() );
  FOR_ITR( coef_LI , itr , end ){
    itr->second = coef_size++;
    coef_array.push_back( MP::DeRP( itr->first ) );
  }
  VE<uint> TheAtsu_coef[deg_lim][4] = {};
  VE<uint> TheAtsu_degree[deg_lim][4] = {};
  FOREQ( deg , 0 , deg_max ){
    VE<uint> ( &coef_deg )[4] = coef[deg];
    VE<uint> ( &TheAtsu_coef_deg )[4] = TheAtsu_coef[deg];
    VE<uint> ( &TheAtsu_degree_deg )[4] = TheAtsu_degree[deg];
    FOR( i , 0 , 4 ){
      VE<uint>& coef_deg_i = coef_deg[i];
      VE<uint>& TheAtsu_coef_deg_i = TheAtsu_coef_deg[i];
      VE<uint>& TheAtsu_degree_deg_i = TheAtsu_degree_deg[i];
      uint size = coef_deg_i.size();
      TheAtsu_coef_deg_i.reserve( size );
      TheAtsu_degree_deg_i.reserve( size );
      FOR( d , 0 , size ){
	uint& coef_deg_i_d = coef_deg_i[d];
	if( coef_deg_i_d != 0 ){
	  TheAtsu_coef_deg_i.push_back( coef_LI[coef_deg_i_d] );
	  TheAtsu_degree_deg_i.push_back( d );
	}
      }
    }
  }
  // ここから本体
  CEXPR( ll , bound_N , 1000000000000000000 );
  CEXPR( ll , bound_K1 , bound_T );
  CEXPR( ll , bound_K2 , bound_N );
  const ll& bound_K = T > 5 ? bound_K1 : bound_K2;
  REPEAT( T ){
    CIN_ASSERT( Nt , 1 , bound_N );
    CIN_ASSERT( Kt , 0 , uint( min( Nt * 2 , bound_K ) ) );
    if( Kt >= P ){
      COUT( 0 );
    } else {
      MP Ntd[fold + 1];
      MP Nt1 = MP( Nt );
      MP Nt_power = Ntd[0] = c1;
      FOREQ( d , 1 , fold ){
	Ntd[d] = ( Nt_power *= Nt1 );
      }
      TTMA<MP> diff[deg_lim] = {};
      TTMA<MP>& MNk = diff[0];
      FOREQ( deg , 0 , deg_max ){
	TTMA<MP> &diff_deg = diff[deg];
	MP* p_diff_deg[4] = { &( diff_deg.m_M00 ) , &( diff_deg.m_M01 ) , &( diff_deg.m_M10 ) , &( diff_deg.m_M11 ) };
	VE<uint> ( &TheAtsu_coef_deg )[4] = TheAtsu_coef[deg];
	VE<uint> ( &TheAtsu_degree_deg )[4] = TheAtsu_degree[deg];
	FOR( i , 0 , 4 ){
	  MP& diff_deg_i = *p_diff_deg[i];
	  VE<uint>& TheAtsu_coef_deg_i = TheAtsu_coef_deg[i];
	  VE<uint>& TheAtsu_degree_deg_i = TheAtsu_degree_deg[i];
	  uint size = TheAtsu_coef_deg_i.size();
	  FOR( d , 0 , size ){
	    diff_deg_i += Ntd[TheAtsu_degree_deg_i[d]] * coef_array[TheAtsu_coef_deg_i[d]];
	  }
	}
      }
      TOMA<MP> vt{ v };
      uint Kt_div = uint( Kt / fold );
      REPEAT( Kt_div ){
	TTMA<MP>* p_M_diff = &MNk;
	TTMA<MP>* p_M = p_M_diff++;
	vt *= MNk;
	FOR( deg , 0 , deg_max ){
	  *p_M += *p_M_diff;
	  p_M++;
	  p_M_diff++;
	}
      }
      uint k_start = Kt_div * fold;
      MP k_start_1{ MP::DeRP( k_start ) };
      MP Nt1_minus_k_start_1{ Nt1 + MP::DeRP( P - k_start ) };
      MNk = TTMA<MP>
	( Nt1_minus_k_start_1 + Nt1_minus_k_start_1 , ( k_start % 2 == 0 ? k_start == 0 ? c0 : MP::DeRP( k_start / 2 ) * ( Nt1 + Nt1 + MP::DeRP( P - k_start + 1 ) ) :  k_start_1 * ( Nt1 + MP::DeRP( ( P - k_start + 1 ) / 2 ) ) ) ,
	  c1 , c0 );
      FOR( k , k_start , Kt ){
	vt *= MNk;
	MNk.m_M00 += c2_neg;
	MNk.m_M01 += Nt1 + MP::DeRP( P - k );
      }
      COUT( vt.m_M0 );
    }
  }
  return 0;
}
0