// #pragma GCC optimize ( "O3" ) // #pragma GCC optimize( "unroll-loops" ) // #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include using namespace std; using uint = unsigned int; using ll = long long; #define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) ) #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr 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 GETLINE( A ) string A; getline( cin , A ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #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 QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n"; #define RETURN( ANSWER ) COUT( ANSWER ); QUIT #define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << "\n"; QUIT #define POWER( ANSWER , ARGUMENT , EXPONENT ) \ TYPE_OF( ARGUMENT ) ANSWER{ 1 }; \ { \ TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO ) \ TYPE_OF( ARGUMENT ) ANSWER{ 1 }; \ { \ TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( MODULO + ( ( ARGUMENT ) % MODULO ) ) % MODULO; \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % MODULO; \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % MODULO; \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_I , LENGTH , MODULO ) \ static ll ANSWER[LENGTH]; \ static ll ANSWER_INV[LENGTH]; \ static ll INVERSE[LENGTH]; \ { \ ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL; \ FOREQ( i , 1 , MAX_I ){ \ ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= MODULO; \ } \ ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ FOREQ( i , 2 , MAX_I ){ \ ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = MODULO - ( ( ( MODULO / i ) * INVERSE[MODULO % i] ) % MODULO ) ) %= MODULO; \ } \ } \ // 通常の二分探索(単調関数-目的値が一意実数解を持つ場合にそれを超えない最大の整数を返す) #define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ ll ANSWER = MAXIMUM; \ { \ ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM; \ ll VARIABLE_FOR_BINARY_SEARCH_U = ANSWER; \ ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){ \ VARIABLE_FOR_BINARY_SEARCH_L = ANSWER; \ } else { \ ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \ } \ while( VARIABLE_FOR_BINARY_SEARCH_L != ANSWER ){ \ VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){ \ break; \ } else { \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH > 0 ){ \ VARIABLE_FOR_BINARY_SEARCH_L = ANSWER; \ } else { \ VARIABLE_FOR_BINARY_SEARCH_U = ANSWER; \ } \ ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \ } \ } \ } \ \ // 二進法の二分探索(単調関数-目的値が一意実数解を持つ場合にそれを超えない最大の整数を返す) #define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ ll ANSWER = MINIMUM; \ { \ ll VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 = 1; \ ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( MAXIMUM ) - ANSWER; \ while( VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 <= VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ){ \ VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 *= 2; \ } \ VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 /= 2; \ ll VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER; \ while( VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 != 0 ){ \ ANSWER = VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 + VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2; \ VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){ \ VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER; \ break; \ } else if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH > 0 ){ \ VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER; \ } \ VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 /= 2; \ } \ ANSWER = VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2; \ } \ \ template inline T Absolute( const T& a ){ return a > 0 ? a : -a; } template inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); } #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& #define CRL CO ll& US ull = unsigned long long;IN CEXPR(uint,P,998244353);TE IN CE INT& RS(INT& n)NE{RE n < 0?((((++n)*= -1)%= M)*= -1)+= M - 1:n %= M;}TE IN CE uint& RS(uint& n)NE{RE n %= M;}TE IN CE ull& RS(ull& n)NE{RE n %= M;}TE IN 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;}TE <> IN CE ull& RS(ull& n)NE{CE CO ull Pull = P;CE CO ull Pull2 = (Pull - 1)* (Pull - 1);RE RSP(n > Pull2?n -= Pull2:n);}TE IN CE INT RS(INT&& n)NE{RE MO(RS(n));}TE IN CE INT RS(CO INT& n)NE{RE RS(INT(n));} #define SFINAE_FOR_MOD(DEFAULT)TY T,enable_if_t >::value>* DEFAULT #define DC_OF_CM_FOR_MOD(FUNC)IN bool OP FUNC(CO Mod& n)CO NE #define DC_OF_AR_FOR_MOD(FUNC)IN Mod OP FUNC(CO Mod& n)CO NE;TE IN Mod OP FUNC(T&& n)CO NE; #define DF_OF_CM_FOR_MOD(FUNC)TE IN bool Mod::OP FUNC(CO Mod& n)CO NE{RE m_n FUNC n.m_n;} #define DF_OF_AR_FOR_MOD(FUNC,FORMULA)TE IN Mod Mod::OP FUNC(CO Mod& n)CO NE{RE MO(Mod(*TH)FUNC ## = n);}TE TE IN Mod Mod::OP FUNC(T&& n)CO NE{RE FORMULA;}TE IN Mod OP FUNC(T&& n0,CO Mod& n1)NE{RE MO(Mod(forward(n0))FUNC ## = n1);} TE CL Mod{PU:uint m_n;IN CE Mod()NE;IN CE Mod(CO Mod& n)NE;IN CE Mod(Mod& n)NE;IN CE Mod(Mod&& n)NE;TE IN CE Mod(CO T& n)NE;TE IN CE Mod(T& n)NE;TE IN CE Mod(T&& n)NE;IN CE Mod& OP=(CO Mod& n)NE;IN CE Mod& OP=(Mod&& n)NE;IN CE Mod& OP+=(CO Mod& n)NE;IN CE Mod& OP-=(CO Mod& n)NE;IN CE Mod& OP*=(CO Mod& n)NE;IN Mod& OP/=(CO Mod& n);IN CE Mod& OP<<=(int n)NE;IN CE Mod& OP>>=(int n)NE;IN CE Mod& OP++()NE;IN CE Mod OP++(int)NE;IN CE Mod& OP--()NE;IN CE Mod OP--(int)NE;DC_OF_CM_FOR_MOD(==);DC_OF_CM_FOR_MOD(!=);DC_OF_CM_FOR_MOD(<);DC_OF_CM_FOR_MOD(<=);DC_OF_CM_FOR_MOD(>);DC_OF_CM_FOR_MOD(>=);DC_OF_AR_FOR_MOD(+);DC_OF_AR_FOR_MOD(-);DC_OF_AR_FOR_MOD(*);DC_OF_AR_FOR_MOD(/);IN CE Mod OP<<(int n)CO NE;IN CE Mod OP>>(int n)CO NE;IN CE Mod OP-()CO NE;IN CE Mod& SignInvert()NE;IN CE Mod& Double()NE;IN CE Mod& Halve()NE;IN Mod& Invert();TE IN CE Mod& PositivePW(T&& EX)NE;TE IN CE Mod& NonNegativePW(T&& EX)NE;TE IN CE Mod& PW(T&& EX);IN CE VO swap(Mod& n)NE;IN CE CO uint& RP()CO NE;ST IN CE Mod DeRP(CO uint& n)NE;ST IN CE uint& Normalise(uint& n)NE;ST IN CO Mod& Inverse(CO uint& n)NE;ST IN CO Mod& Factorial(CO uint& n)NE;ST IN CO Mod& FactorialInverse(CO uint& n)NE;ST IN CO Mod& zero()NE;ST IN CO Mod& one()NE;TE IN CE Mod& Ref(T&& n)NE;}; #define SFINAE_FOR_MN(DEFAULT)TY T,enable_if_t,decay_t >::value>* DEFAULT #define DC_OF_AR_FOR_MN(FUNC)IN MN OP FUNC(CO MN& n)CO NE;TE IN MN OP FUNC(T&& n)CO NE; #define DF_OF_CM_FOR_MN(FUNC)TE IN bool MN::OP FUNC(CO MN& n)CO NE{RE m_n FUNC n.m_n;} #define DF_OF_AR_FOR_MN(FUNC,FORMULA)TE IN MN MN::OP FUNC(CO MN& n)CO NE{RE MO(MN(*TH)FUNC ## = n);}TE TE IN MN MN::OP FUNC(T&& n)CO NE{RE FORMULA;}TE IN MN OP FUNC(T&& n0,CO MN& n1)NE{RE MO(MN(forward(n0))FUNC ## = n1);} TE CL MN :PU Mod{PU:IN CE MN()NE;IN CE MN(CO MN& n)NE;IN CE MN(MN& n)NE;IN CE MN(MN&& n)NE;TE IN CE MN(CO T& n)NE;TE IN CE MN(T&& n)NE;IN CE MN& OP=(CO MN& n)NE;IN CE MN& OP=(MN&& n)NE;IN CE MN& OP+=(CO MN& n)NE;IN CE MN& OP-=(CO MN& n)NE;IN CE MN& OP*=(CO MN& n)NE;IN MN& OP/=(CO MN& n);IN CE MN& OP<<=(int n)NE;IN CE MN& OP>>=(int n)NE;IN CE MN& OP++()NE;IN CE MN OP++(int)NE;IN CE MN& OP--()NE;IN CE MN OP--(int)NE;DC_OF_AR_FOR_MN(+);DC_OF_AR_FOR_MN(-);DC_OF_AR_FOR_MN(*);DC_OF_AR_FOR_MN(/);IN CE MN OP<<(int n)CO NE;IN CE MN OP>>(int n)CO NE;IN CE MN OP-()CO NE;IN CE MN& SignInvert()NE;IN CE MN& Double()NE;IN CE MN& Halve()NE;IN CE MN& Invert();TE IN CE MN& PositivePW(T&& EX)NE;TE IN CE MN& NonNegativePW(T&& EX)NE;TE IN CE MN& PW(T&& EX);IN CE uint RP()CO NE;IN CE Mod Reduce()CO NE;ST IN CE MN DeRP(CO uint& n)NE;ST IN CO MN& Formise(CO uint& n)NE;ST IN CO MN& Inverse(CO uint& n)NE;ST IN CO MN& Factorial(CO uint& n)NE;ST IN CO MN& FactorialInverse(CO uint& n)NE;ST IN CO MN& zero()NE;ST IN CO MN& one()NE;ST IN CE uint Form(CO uint& n)NE;ST IN CE ull& Reduction(ull& n)NE;ST IN CE ull& ReducedMU(ull& n,CO uint& m)NE;ST IN CE uint MU(CO uint& n0,CO uint& n1)NE;ST IN CE uint BaseSquareTruncation(uint& n)NE;TE IN CE MN& Ref(T&& n)NE;};TE IN CE MN Twice(CO MN& n)NE;TE IN CE MN Half(CO MN& n)NE;TE IN CE MN Inverse(CO MN& n);TE IN CE MN PW(CO MN& n,CO T& EX);TE IN CE MN<2> PW(CO MN<2>& n,CO T& p);TE IN CE T Square(CO T& t);TE <> IN CE MN<2> Square >(CO MN<2>& t);TE IN CE VO swap(MN& n0,MN& n1)NE;TE IN string to_string(CO MN& n)NE;TE IN basic_ostream& OP<<(basic_ostream& os,CO MN& n); TE CL COantsForMod{PU:COantsForMod()= delete;ST CE CO bool g_even = ((M & 1)== 0);ST CE CO uint g_memory_bound = 1000000;ST CE CO uint g_memory_LE = M < g_memory_bound?M:g_memory_bound;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 = 32;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_digit_half = (g_MN_digit + 1)>> 1;ST CE CO uint g_MN_base_sqrt_minus = (1 << g_MN_digit_half)- 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_mod = uint(g_MN_base % M);ST CE CO uint g_MN_base_square_mod = uint(((g_MN_base % M)* (g_MN_base % M))% M);};TE IN CE ull COantsForMod::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;} #include #define SET_VE_32_128_FOR_SIMD(UINT,VE_NAME,SCALAR0,SCALAR1,SCALAR2,SCALAR3)CE CO UINT VE_NAME ## _copy[4] ={SCALAR0,SCALAR1,SCALAR2,SCALAR3};ST CO __m128i v_ ## VE_NAME = _mm_load_si128((__m128i*)VE_NAME ##_copy) #define SET_VE_64_128_FOR_SIMD(UINT,VE_NAME,SCALAR0,SCALAR1)CE CO UINT VE_NAME ## _copy[2] ={SCALAR0,SCALAR1};ST CO __m128i v_ ## VE_NAME = _mm_load_si128((__m128i*)VE_NAME ##_copy) #define SET_VE_64_256_FOR_SIMD(ULL,VE_NAME,SCALAR0,SCALAR1,SCALAR2,SCALAR3)CE CO ULL VE_NAME ## _copy[4] ={SCALAR0,SCALAR1,SCALAR2,SCALAR3};ST CO __m256i v_ ## VE_NAME = _mm256_load_si256((__m256i*)VE_NAME ##_copy) #define SET_CO_VE_32_128_FOR_SIMD(UINT,VE_NAME,SCALAR)SET_VE_32_128_FOR_SIMD(UINT,VE_NAME,SCALAR,SCALAR,SCALAR,SCALAR) #define SET_CO_VE_64_128_FOR_SIMD(ULL,VE_NAME,SCALAR)SET_VE_64_128_FOR_SIMD(ULL,VE_NAME,SCALAR,SCALAR) #define SET_CO_VE_64_256_FOR_SIMD(ULL,VE_NAME,SCALAR)SET_VE_64_256_FOR_SIMD(ULL,VE_NAME,SCALAR,SCALAR,SCALAR,SCALAR) TE CL COantsForSIMDForMod{PU:COantsForSIMDForMod()= delete;ST IN CO __m128i& v_M()NE;ST IN CO __m128i& v_Mull()NE;ST IN CO __m128i& v_M_minus()NE;ST IN CO __m128i& v_M_neg_inverse()NE;ST IN CO __m128i& v_digitull()NE;};TE IN CO __m128i& COantsForSIMDForMod::v_M()NE{SET_CO_VE_32_128_FOR_SIMD(uint,M,M);RE v_M;}TE IN CO __m128i& COantsForSIMDForMod::v_Mull()NE{SET_CO_VE_64_128_FOR_SIMD(ull,Mull,M);RE v_Mull;}TE IN CO __m128i& COantsForSIMDForMod::v_M_minus()NE{SET_CO_VE_32_128_FOR_SIMD(uint,M_minus,M - 1);RE v_M_minus;}TE IN CO __m128i& COantsForSIMDForMod::v_M_neg_inverse()NE{SET_CO_VE_32_128_FOR_SIMD(uint,M_neg_inverse,COantsForMod::g_MN_M_neg_inverse);RE v_M_neg_inverse;}TE IN CO __m128i& COantsForSIMDForMod::v_digitull()NE{SET_CO_VE_64_128_FOR_SIMD(ull,digitull,COantsForMod::g_MN_digit);RE v_digitull;}TE IN __m128i& SIMD_RS_32_128(__m128i& v)NE{CO __m128i& v_M = COantsForSIMDForMod::v_M();RE v -= v_M * _mm_cmpgt_epi32(v,v_M);}TE IN __m128i& SIMD_RS_64_128(__m128i& v)NE{ull v_copy[2];_mm_store_si128((__m128i*)v_copy,v);for(uint i = 0;i < 2;i++){ull& v_copy_i = v_copy[i];v_copy_i = (v_copy_i < M?0:M);}RE v -= _mm_load_si128((__m128i*)v_copy);}TE IN __m256i& SIMD_RS_64_256(__m256i& v)NE{ull v_copy[4];_mm256_store_si256((__m256i*)v_copy,v);for(uint i = 0;i < 4;i++){ull& v_copy_i = v_copy[i];v_copy_i = (v_copy_i < M?0:M);}RE v -= _mm256_load_si256((__m256i*)v_copy);}IN CE int SIMD_Shuffle(CRI a0,CRI a1,CRI a2,CRI a3)NE{RE (a0 << (0 << 1))+ (a1 << (1 << 1))+ (a2 << (2 << 1))+ (a3 << (3 << 1));}TE IN VO SIMD_Addition_32_64(CO Mod& a0,CO Mod& a1,CO Mod& b0,CO Mod& b1,Mod& c0,Mod& c1)NE{uint a_copy[4] ={a0.m_n,a1.m_n,0,0};uint b_copy[4] ={b0.m_n,b1.m_n,0,0};__m128i v_a = _mm_load_si128((__m128i*)a_copy);v_a += _mm_load_si128((__m128i*)b_copy);ST CO __m128i& v_M_minus = COantsForSIMDForMod::v_M_minus();ST CO __m128i& v_M = COantsForSIMDForMod::v_M();v_a += _mm_cmpgt_epi32(v_a,v_M_minus)& v_M;_mm_store_si128((__m128i*)a_copy,v_a);c0.m_n = MO(a_copy[0]);c1.m_n = MO(a_copy[1]);RE;}TE IN VO SIMD_Addition_32_128(CO Mod& a0,CO Mod& a1,CO Mod& a2,CO Mod& a3,CO Mod& b0,CO Mod& b1,CO Mod& b2,CO Mod& b3,Mod& c0,Mod& c1,Mod& c2,Mod& c3)NE{uint a_copy[4] ={a0.m_n,a1.m_n,a2.m_n,a3.m_n};uint b_copy[4] ={b0.m_n,b1.m_n,b2.m_n,b3.m_n};__m128i v_a = _mm_load_si128((__m128i*)a_copy)+ _mm_load_si128((__m128i*)b_copy);_mm_store_si128((__m128i*)a_copy,v_a);for(uint i = 0;i < 4;i++){b_copy[i] = a_copy[i] < M?0:M;}v_a -= _mm_load_si128((__m128i*)b_copy);_mm_store_si128((__m128i*)a_copy,v_a);c0.m_n = MO(a_copy[0]);c1.m_n = MO(a_copy[1]);c2.m_n = MO(a_copy[2]);c3.m_n = MO(a_copy[3]);RE;}TE IN VO SIMD_Substracition_32_64(CO Mod& a0,CO Mod& a1,CO Mod& b0,CO Mod& b1,Mod& c0,Mod& c1)NE{uint a_copy[4] ={a0.m_n,a1.m_n,0,0};uint b_copy[4] ={b0.m_n,b1.m_n,0,0};__m128i v_a = _mm_load_si128((__m128i*)a_copy);__m128i v_b = _mm_load_si128((__m128i*)b_copy);_mm_store_si128((__m128i*)a_copy,v_a);for(uint i = 0;i < 2;i++){b_copy[i] = a_copy[i] < b_copy[i]?M:0;}(v_a += _mm_load_si128((__m128i*)b_copy))-= v_b;_mm_store_si128((__m128i*)a_copy,v_a);c0.m_n = MO(a_copy[0]);c1.m_n = MO(a_copy[1]);RE;}TE IN VO SIMD_Subtraction_32_128(CO Mod& a0,CO Mod& a1,CO Mod& a2,CO Mod& a3,CO Mod& b0,CO Mod& b1,CO Mod& b2,CO Mod& b3,Mod& c0,Mod& c1,Mod& c2,Mod& c3)NE{uint a_copy[4] ={a0.m_n,a1.m_n,a2.m_n,a3.m_n};uint b_copy[4] ={b0.m_n,b1.m_n,b2.m_n,b3.m_n};__m128i v_a = _mm_load_si128((__m128i*)a_copy);__m128i v_b = _mm_load_si128((__m128i*)b_copy);_mm_store_si128((__m128i*)a_copy,v_a);for(uint i = 0;i < 4;i++){b_copy[i] = a_copy[i] < b_copy[i]?M:0;}(v_a += _mm_load_si128((__m128i*)b_copy))-= v_b;_mm_store_si128((__m128i*)a_copy,v_a);c0.m_n = MO(a_copy[0]);c1.m_n = MO(a_copy[1]);c2.m_n = MO(a_copy[2]);c3.m_n = MO(a_copy[3]);RE;} US MP = Mod

;US MNP = MN

;TE IN CE uint MN::Form(CO uint& n)NE{ull n_copy = n;RE uint(MO(Reduction(n_copy *= COantsForMod::g_MN_base_square_mod)));}TE IN CE ull& MN::Reduction(ull& n)NE{ull n_sub = n & COantsForMod::g_MN_base_minus;RE ((n += ((n_sub *= COantsForMod::g_MN_M_neg_inverse)&= COantsForMod::g_MN_base_minus)*= M)>>= COantsForMod::g_MN_digit)< M?n:n -= M;}TE IN CE ull& MN::ReducedMU(ull& n,CO uint& m)NE{RE Reduction(n *= m);}TE IN CE uint MN::MU(CO uint& n0,CO uint& n1)NE{ull n0_copy = n0;RE uint(MO(ReducedMU(ReducedMU(n0_copy,n1),COantsForMod::g_MN_base_square_mod)));}TE IN CE uint MN::BaseSquareTruncation(uint& n)NE{CO uint n_u = n >> COantsForMod::g_MN_digit_half;n &= COantsForMod::g_MN_base_sqrt_minus;RE n_u;}TE IN CE MN::MN()NE:Mod(){static_assert(! COantsForMod::g_even);}TE IN CE MN::MN(CO MN& n)NE:Mod(n){}TE IN CE MN::MN(MN& n)NE:Mod(n){}TE IN CE MN::MN(MN&& n)NE:Mod(MO(n)){}TE TE IN CE MN::MN(CO T& n)NE:Mod(n){static_assert(! COantsForMod::g_even);Mod::m_n = Form(Mod::m_n);}TE TE IN CE MN::MN(T&& n)NE:Mod(forward(n)){static_assert(! COantsForMod::g_even);Mod::m_n = Form(Mod::m_n);}TE IN CE MN& MN::OP=(CO MN& n)NE{RE Ref(Mod::OP=(n));}TE IN CE MN& MN::OP=(MN&& n)NE{RE Ref(Mod::OP=(MO(n)));}TE IN CE MN& MN::OP+=(CO MN& n)NE{RE Ref(Mod::OP+=(n));}TE IN CE MN& MN::OP-=(CO MN& n)NE{RE Ref(Mod::OP-=(n));}TE IN CE MN& MN::OP*=(CO MN& n)NE{ull m_n_copy = Mod::m_n;RE Ref(Mod::m_n = MO(ReducedMU(m_n_copy,n.m_n)));}TE IN MN& MN::OP/=(CO MN& n){RE OP*=(MN(n).Invert());}TE IN CE MN& MN::OP<<=(int n)NE{RE Ref(Mod::OP<<=(n));}TE IN CE MN& MN::OP>>=(int n)NE{RE Ref(Mod::OP>>=(n));}TE IN CE MN& MN::OP++()NE{RE Ref(Mod::Normalise(Mod::m_n += COantsForMod::g_MN_base_mod));}TE IN CE MN MN::OP++(int)NE{MN n{*TH};OP++();RE n;}TE IN CE MN& MN::OP--()NE{RE Ref(Mod::m_n < COantsForMod::g_MN_base_mod?((Mod::m_n += M)-= COantsForMod::g_MN_base_mod):Mod::m_n -= COantsForMod::g_MN_base_mod);}TE IN CE MN MN::OP--(int)NE{MN n{*TH};OP--();RE n;}DF_OF_AR_FOR_MN(+,MN(forward(n))+= *TH);DF_OF_AR_FOR_MN(-,MN(forward(n)).SignInvert()+= *TH);DF_OF_AR_FOR_MN(*,MN(forward(n))*= *TH);DF_OF_AR_FOR_MN(/,MN(forward(n)).Invert()*= *TH);TE IN CE MN MN::OP<<(int n)CO NE{RE MO(MN(*TH)<<= n);}TE IN CE MN MN::OP>>(int n)CO NE{RE MO(MN(*TH)>>= n);}TE IN CE MN MN::OP-()CO NE{RE MO(MN(*TH).SignInvert());}TE IN CE MN& MN::SignInvert()NE{RE Ref(Mod::m_n > 0?Mod::m_n = M - Mod::m_n:Mod::m_n);}TE IN CE MN& MN::Double()NE{RE Ref(Mod::Double());}TE IN CE MN& MN::Halve()NE{RE Ref(Mod::Halve());}TE IN CE MN& MN::Invert(){assert(Mod::m_n > 0);RE PositivePW(uint(COantsForMod::g_M_minus_2));}TE TE IN CE MN& MN::PositivePW(T&& EX)NE{MN PW{*TH};(--EX)%= COantsForMod::g_M_minus_2;WH(EX != 0){(EX & 1)== 1?OP*=(PW):*TH;EX >>= 1;PW *= PW;}RE *TH;}TE TE IN CE MN& MN::NonNegativePW(T&& EX)NE{RE EX == 0?Ref(Mod::m_n = 1):PositivePW(forward(EX));}TE TE IN CE MN& MN::PW(T&& EX){bool neg = EX < 0;assert(!(neg && Mod::m_n == 0));RE neg?PositivePW(forward(EX *= COantsForMod::g_M_minus_2_neg)):NonNegativePW(forward(EX));}TE IN CE uint MN::RP()CO NE{ull m_n_copy = Mod::m_n;RE MO(Reduction(m_n_copy));}TE IN CE Mod MN::Reduce()CO NE{ull m_n_copy = Mod::m_n;RE Mod::DeRP(MO(Reduction(m_n_copy)));}TE IN CE MN MN::DeRP(CO uint& n)NE{RE MN(Mod::DeRP(n));}TE IN CO MN& MN::Formise(CO uint& n)NE{ST MN memory[COantsForMod::g_memory_LE] ={zero(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory[LE_curr] = DeRP(LE_curr);LE_curr++;}RE memory[n];}TE IN CO MN& MN::Inverse(CO uint& n)NE{ST MN memory[COantsForMod::g_memory_LE] ={zero(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory[LE_curr] = MN(Mod::Inverse(LE_curr));LE_curr++;}RE memory[n];}TE IN CO MN& MN::Factorial(CO uint& n)NE{ST MN memory[COantsForMod::g_memory_LE] ={one(),one()};ST uint LE_curr = 2;ST MN val_curr{one()};MN val_last{one()};WH(LE_curr <= n){memory[LE_curr++] = val_curr *= ++val_last;}RE memory[n];}TE IN CO MN& MN::FactorialInverse(CO uint& n)NE{ST MN memory[COantsForMod::g_memory_LE] ={one(),one()};ST uint LE_curr = 2;ST MN val_curr{one()};MN val_last{one()};WH(LE_curr <= n){memory[LE_curr] = val_curr *= Inverse(LE_curr);LE_curr++;}RE memory[n];}TE IN CO MN& MN::zero()NE{ST CE CO MN z{};RE z;}TE IN CO MN& MN::one()NE{ST CE CO MN o{DeRP(1)};RE o;}TE TE IN CE MN& MN::Ref(T&& n)NE{RE *TH;}TE IN CE MN Twice(CO MN& n)NE{RE MO(MN(n).Double());}TE IN CE MN Half(CO MN& n)NE{RE MO(MN(n).Halve());}TE IN CE MN Inverse(CO MN& n){RE MO(MN(n).Invert());}TE IN CE MN PW(CO MN& n,CO T& EX){RE MO(MN(n).PW(T(EX)));}TE IN CE VO swap(MN& n0,MN& n1)NE{n0.swap(n1);}TE IN string to_string(CO MN& n)NE{RE to_string(n.RP())+ " + MZ";}TE IN basic_ostream& OP<<(basic_ostream& os,CO MN& n){RE os << n.RP();} TE IN CE Mod::Mod()NE:m_n(){}TE IN CE Mod::Mod(CO Mod& n)NE:m_n(n.m_n){}TE IN CE Mod::Mod(Mod& n)NE:m_n(n.m_n){}TE IN CE Mod::Mod(Mod&& n)NE:m_n(MO(n.m_n)){}TE TE IN CE Mod::Mod(CO T& n)NE:m_n(RS(n)){}TE TE IN CE Mod::Mod(T& n)NE:m_n(RS(decay_t(n))){}TE TE IN CE Mod::Mod(T&& n)NE:m_n(RS(forward(n))){}TE IN CE Mod& Mod::OP=(CO Mod& n)NE{RE Ref(m_n = n.m_n);}TE IN CE Mod& Mod::OP=(Mod&& n)NE{RE Ref(m_n = MO(n.m_n));}TE IN CE Mod& Mod::OP+=(CO Mod& n)NE{RE Ref(Normalise(m_n += n.m_n));}TE IN CE Mod& Mod::OP-=(CO Mod& n)NE{RE Ref(m_n < n.m_n?(m_n += M)-= n.m_n:m_n -= n.m_n);}TE IN CE Mod& Mod::OP*=(CO Mod& n)NE{RE Ref(m_n = COantsForMod::g_even?RS(ull(m_n)* n.m_n):MN::MU(m_n,n.m_n));}TE <> IN 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 IN Mod& Mod::OP/=(CO Mod& n){RE OP*=(Mod(n).Invert());}TE IN CE Mod& Mod::OP<<=(int n)NE{WH(n-- > 0){Normalise(m_n <<= 1);}RE *TH;}TE IN CE Mod& Mod::OP>>=(int n)NE{WH(n-- > 0){((m_n & 1)== 0?m_n:m_n += M)>>= 1;}RE *TH;}TE IN CE Mod& Mod::OP++()NE{RE Ref(m_n < COantsForMod::g_M_minus?++m_n:m_n = 0);}TE IN CE Mod Mod::OP++(int)NE{Mod n{*TH};OP++();RE n;}TE IN CE Mod& Mod::OP--()NE{RE Ref(m_n == 0?m_n = COantsForMod::g_M_minus:--m_n);}TE IN CE Mod Mod::OP--(int)NE{Mod n{*TH};OP--();RE n;}DF_OF_CM_FOR_MOD(==);DF_OF_CM_FOR_MOD(!=);DF_OF_CM_FOR_MOD(>);DF_OF_CM_FOR_MOD(>=);DF_OF_CM_FOR_MOD(<);DF_OF_CM_FOR_MOD(<=);DF_OF_AR_FOR_MOD(+,Mod(forward(n))+= *TH);DF_OF_AR_FOR_MOD(-,Mod(forward(n)).SignInvert()+= *TH);DF_OF_AR_FOR_MOD(*,Mod(forward(n))*= *TH);DF_OF_AR_FOR_MOD(/,Mod(forward(n)).Invert()*= *TH);TE IN CE Mod Mod::OP<<(int n)CO NE{RE MO(Mod(*TH)<<= n);}TE IN CE Mod Mod::OP>>(int n)CO NE{RE MO(Mod(*TH)>>= n);}TE IN CE Mod Mod::OP-()CO NE{RE MO(Mod(*TH).SignInvert());}TE IN CE Mod& Mod::SignInvert()NE{RE Ref(m_n > 0?m_n = M - m_n:m_n);}TE IN CE Mod& Mod::Double()NE{RE Ref(Normalise(m_n <<= 1));}TE IN CE Mod& Mod::Halve()NE{RE Ref(((m_n & 1)== 0?m_n:m_n += M)>>= 1);}TE IN Mod& Mod::Invert(){assert(m_n > 0);uint m_n_neg;RE m_n < COantsForMod::g_memory_LE?Ref(m_n = Inverse(m_n).m_n):(m_n_neg = M - m_n < COantsForMod::g_memory_LE)?Ref(m_n = M - Inverse(m_n_neg).m_n):PositivePW(uint(COantsForMod::g_M_minus_2));}TE <> IN Mod<2>& Mod<2>::Invert(){assert(m_n > 0);RE *TH;}TE TE IN CE Mod& Mod::PositivePW(T&& EX)NE{Mod PW{*TH};EX--;WH(EX != 0){(EX & 1)== 1?OP*=(PW):*TH;EX >>= 1;PW *= PW;}RE *TH;}TE <> TE IN CE Mod<2>& Mod<2>::PositivePW(T&& EX)NE{RE *TH;}TE TE IN CE Mod& Mod::NonNegativePW(T&& EX)NE{RE EX == 0?Ref(m_n = 1):Ref(PositivePW(forward(EX)));}TE TE IN CE Mod& Mod::PW(T&& EX){bool neg = EX < 0;assert(!(neg && m_n == 0));neg?EX *= COantsForMod::g_M_minus_2_neg:EX;RE m_n == 0?*TH:(EX %= COantsForMod::g_M_minus)== 0?Ref(m_n = 1):PositivePW(forward(EX));}TE IN CO Mod& Mod::Inverse(CO uint& n)NE{ST Mod memory[COantsForMod::g_memory_LE] ={zero(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory[LE_curr].m_n = M - MN::MU(memory[M % LE_curr].m_n,M / LE_curr);LE_curr++;}RE memory[n];}TE IN CO Mod& Mod::Factorial(CO uint& n)NE{ST Mod memory[COantsForMod::g_memory_LE] ={one(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory[LE_curr] = MN::Factorial(LE_curr).Reduce();LE_curr++;}RE memory[n];}TE IN CO Mod& Mod::FactorialInverse(CO uint& n)NE{ST Mod memory[COantsForMod::g_memory_LE] ={one(),one()};ST uint LE_curr = 2;WH(LE_curr <= n){memory[LE_curr] = MN::FactorialInverse(LE_curr).Reduce();LE_curr++;}RE memory[n];}TE IN CE VO Mod::swap(Mod& n)NE{std::swap(m_n,n.m_n);}TE IN CE CO uint& Mod::RP()CO NE{RE m_n;}TE IN CE Mod Mod::DeRP(CO uint& n)NE{Mod n_copy{};n_copy.m_n = n;RE n_copy;}TE IN CE uint& Mod::Normalise(uint& n)NE{RE n < M?n:n -= M;}TE IN CO Mod& Mod::zero()NE{ST CE CO Mod z{};RE z;}TE IN CO Mod& Mod::one()NE{ST CE CO Mod o{DeRP(1)};RE o;}TE TE IN CE Mod& Mod::Ref(T&& n)NE{RE *TH;}TE IN CE Mod Twice(CO Mod& n)NE{RE MO(Mod(n).Double());}TE IN CE Mod Half(CO Mod& n)NE{RE MO(Mod(n).Halve());}TE IN Mod Inverse(CO Mod& n){RE MO(Mod(n).Invert());}TE IN CE Mod Inverse_COrexpr(CO uint& n)NE{RE MO(Mod::DeRP(RS(n)).NonNegativePW(M - 2));}TE IN CE Mod PW(CO Mod& n,CO T& EX){RE MO(Mod(n).PW(T(EX)));}TE IN CE VO swap(Mod& n0,Mod& n1)NE{n0.swap(n1);}TE IN string to_string(CO Mod& n)NE{RE to_string(n.RP())+ " + MZ";}TE IN basic_ostream& OP<<(basic_ostream& os,CO Mod& n){RE os << n.RP();} #define SFINAE_FOR_PO(DEFAULT) TY Arg,enable_if_t >::value>* DEFAULT TE CL PO{PU:VE m_f;uint m_SZ;IN PO();IN PO(CO T& t);IN PO(T&& t);TE IN PO(CO Arg& n);IN PO(CO PO& f);IN PO(PO&& f);IN PO(CRUI i,CO T& t);IN PO(CRUI i,T&& t);TE IN PO(CRUI i,CO Arg& n);IN PO(CO VE& f);IN PO(VE&& f);IN PO& OP=(CO T& t);IN PO& OP=(T&& t);TE IN PO& OP=(CO Arg& n);IN PO& OP=(CO PO& f);IN PO& OP=(PO&& f);IN PO& OP=(CO VE& f);IN PO& OP=(VE&& f);IN CO T& OP[](CRUI i) CO;IN T& OP[](CRUI i);IN T OP()(CO T& t) CO;PO& OP+=(CO PO& f);PO& OP-=(CO PO& f);PO& OP*=(CO PO& f);PO& OP*=(PO&& f);PO& OP/=(CO T& t);IN PO& OP/=(CO PO& f);PO& OP%=(CO T& t);PO& OP%=(CO PO& f);IN PO OP-() CO;PO& OP<<=(CO T& t);IN CO VE& GetCoefficient() CO NE;IN CRUI SZ() CO NE;IN VO swap(PO& f);IN VO swap(VE& f);VO ReMORedundantZero();IN string Display() CO NE;ST PO Quotient(CO PO& f0,CO PO& f1);ST PO TPQuotient(CO PO& f0,CRUI f0_TP_SZ,CO PO& f1_TP_inverse,CRUI f1_SZ);ST PO TP(CO PO& f,CRUI f_TP_SZ);ST IN CO PO& zero();ST IN CO T& CO_zero();ST IN CO T& CO_one();ST IN CO T& CO_minus_one();}; TE IN PO::PO():m_f(),m_SZ(0){}TE IN PO::PO(CO T& t):PO(){if(t != CO_zero()){OP[](0) = t;}}TE IN PO::PO(T&& t):PO(){if(t != CO_zero()){OP[](0) = MO(t);}}TE TE IN PO::PO(CO Arg& n):PO(T(n)){}TE IN PO::PO(CO PO& f):m_f(f.m_f),m_SZ(f.m_SZ){}TE IN PO::PO(PO&& f):m_f(MO(f.m_f)),m_SZ(MO(f.m_SZ)){}TE IN PO::PO(CRUI i,CO T& t):PO(){if(t != CO_zero()){OP[](i) = t;}}TE IN PO::PO(CRUI i,T&& t):PO(){if(t != CO_zero()){OP[](i) = MO(t);}}TE TE IN PO::PO(CRUI i,CO Arg& n):PO(i,T(n)){}TE IN PO::PO(CO VE& f):m_f(f),m_SZ(m_f.SZ()){}TE IN PO::PO(VE&& f):m_f(MO(f)),m_SZ(m_f.SZ()){}TE IN PO& PO::OP=(CO T& t){m_f.clear();m_SZ = 0;OP[](0) = t;RE *TH;}TE IN PO& PO::OP=(T&& t){m_f.clear();m_SZ = 0;OP[](0) = MO(t);RE *TH;}TE TE IN PO& PO::OP=(CO Arg& n){RE OP=(T(n));}TE IN PO& PO::OP=(CO PO& f){m_f = f.m_f;m_SZ = f.m_SZ;RE *TH;}TE IN PO& PO::OP=(PO&& f){m_f = MO(f.m_f);m_SZ = MO(f.m_SZ);RE *TH;}TE IN PO& PO::OP=(CO VE& f){m_f = f;m_SZ = f.m_SZ;RE *TH;}TE IN PO& PO::OP=(VE&& f){m_f = MO(f);m_SZ = m_f.SZ();RE *TH;}TE CO T& PO::OP[](CRUI i) CO{if(m_SZ <= i){RE CO_zero();}RE m_f[i];}TE IN T& PO::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 IN T PO::OP()(CO T& t) CO{RE MO((*TH % (PO(1,CO_one()) - t))[0]);}TE PO& PO::OP+=(CO PO& f){if(m_SZ < f.m_SZ){m_f.reserve(f.m_SZ);for(uint i = 0;i < m_SZ;i++){m_f[i] += f.m_f[i];}for(uint i = m_SZ;i < f.m_SZ;i++){m_f.push_back(f.m_f[i]);}m_SZ = f.m_SZ;}else{for(uint i = 0;i < f.m_SZ;i++){m_f[i] += f.m_f[i];}}RE *TH;}TE PO& PO::OP-=(CO PO& f){if(m_SZ < f.m_SZ){m_f.reserve(f.m_SZ);for(uint i = 0;i < m_SZ;i++){m_f[i] -= f.m_f[i];}for(uint i = m_SZ;i < f.m_SZ;i++){m_f.push_back(- f.m_f[i]);}m_SZ = f.m_SZ;}else{for(uint i = 0;i < f.m_SZ;i++){m_f[i] -= f.m_f[i];}}RE *TH;}TE PO& PO::OP*=(CO PO& f){if(m_SZ == 0){RE *TH;}if(f.m_SZ == 0){m_f.clear();m_SZ = 0;RE *TH;}CO uint SZ = m_SZ + f.m_SZ - 1;PO product{};for(uint i = 0;i < SZ;i++){T& product_i = product[i];CO uint j_min = m_SZ > i?0:i - m_SZ + 1;CO uint j_lim = i < f.m_SZ?i + 1:f.m_SZ;for(uint j = j_min;j < j_lim;j++){product_i += m_f[i - j] * f.m_f[j];}}RE OP=(MO(product));}TE IN PO& PO::OP*=(PO&& f){RE OP*=(f);};TE PO& PO::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 PO PO::TP(CO PO& f,CRUI f_TP_SZ){VE f_TP(f_TP_SZ);for(uint d = 0;d < f_TP_SZ;d++){f_TP[d] = f.m_f[f.m_SZ - 1 - d];}RE PO(MO(f_TP));}TE PO& PO::OP%=(CO T& t){if(t == CO_one()){RE OP=(zero());}for(uint i = 0;i < m_SZ;i++){m_f[i] %= t;}RE *TH;}TE IN PO PO::OP-() CO{RE MO(PO() -= *TH);}TE IN CO VE& PO::GetCoefficient() CO NE{RE m_f;}TE IN CRUI PO::SZ() CO NE{RE m_SZ;}TE IN VO PO::swap(PO& f){m_f.swap(f.m_f);swap(m_SZ,f.m_SZ);}TE IN VO PO::swap(VE& f){m_f.swap(f);m_SZ = m_f.SZ();}TE VO PO::ReMORedundantZero(){CO T& z = CO_zero();WH(m_SZ > 0?m_f[m_SZ - 1] == z:false){m_f.pop_back();m_SZ--;}RE;}TE string PO::Display() CO NE{string s = "(";if(m_SZ > 0){s += to_string(m_f[0]);for(uint i = 1;i < m_SZ;i++){s += "," + to_string(m_f[i]);}}s += ")";RE s;}TE IN CO PO& PO::zero(){ST CO PO z{};RE z;}TE IN CO T& PO::CO_zero(){ST CO T z{0};RE z;}TE IN CO T& PO::CO_one(){ST CO T o{1};RE o;}TE IN CO T& PO::CO_minus_one(){ST CO T m{-1};RE m;}TE bool OP==(CO PO& f0,CO T& t1){CRUI SZ = f0.SZ();CO T& zero = PO::CO_zero();for(uint i = 1;i < SZ;i++){if(f0[i] != zero){RE false;}}RE f0[0] == t1;}TE bool OP==(CO PO& f0,CO PO& 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 IN bool OP!=(CO PO& f0,CO P& f1){RE !(f0 == f1);}TE IN PO OP+(CO PO& f0,CO P& f1){RE MO(PO(f0) += f1);}TE IN PO OP-(CO PO& f){RE PO::zero() - f;}TE IN PO OP-(CO PO& f0,CO P& f1){RE MO(PO(f0) -= f1);}TE IN PO OP*(CO PO& f0,CO P& f1){RE MO(PO(f0) *= f1);}TE IN PO OP/(CO PO& f0,CO T& t1){RE MO(PO(f0) /= t1);}TE TY V>T& Prod(V& 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);} TE CL PW_CE{PU:T m_val[EX_lim];IN CE PW_CE(CO T& t,CO T& init = T(1));};TE IN CE PW_CE::PW_CE(CO T& t,CO T& init):m_val() {T PW{init};for( uint EX = 0;EX < EX_lim;EX++){m_val[EX] = PW;PW *= t;}} TE IN CE CO uint LimitOfPWForFFT{};TE IN CE CO uint BorderForFFT{};TE IN CO T (&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT];TE IN CO T (&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT];TE <> IN CE CO uint LimitOfPWForFFT = 24;TE <> IN CE CO uint LimitOfPWForFFT = LimitOfPWForFFT;TE <> IN CE CO uint BorderForFFT = 4;TE <> IN CE CO uint BorderForFFT = BorderForFFT;TE <> IN CO MP (&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT]{ST CO PW_CE > PRT{31};RE PRT.m_val;}TE <> IN CO MP (&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT]{ST CO PW_CE > IPRT{128805723};RE IPRT.m_val;}TE <> IN CO MNP (&PrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT]{ST CO PW_CE > PRT{31};RE PRT.m_val;}TE <> IN CO MNP (&InversePrimitiveRootOfTwoForFFT()NE)[LimitOfPWForFFT]{ST CO PW_CE > IPRT{128805723};RE IPRT.m_val;}TE VO CooleyTukey(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CRUI EX,CO T (&PRT)[LimitOfPWForFFT]){CO uint LE = two_PW + N_input_start;f.reserve(LE);WH(f.SZ() < LE){f.push_back(0);}ST VE bit_reverse[32] ={VE(1)};ST uint e_next = 1;ST uint two_PW_next = 1;ST uint two_PW_next2 = 2;ST VE* p_bit_reverse_prev = bit_reverse;ST VE* p_bit_reverse_curr = p_bit_reverse_prev + 1;WH(e_next <= EX){*p_bit_reverse_curr = VE(two_PW_next2);uint* p_bit_reverse_curr_i = &((*p_bit_reverse_curr)[0]);uint* p_bit_reverse_curr_i_plus = p_bit_reverse_curr_i + two_PW_next;uint* p_bit_reverse_prev_i = &((*p_bit_reverse_prev)[0]);for(uint i = 0;i < two_PW_next;i++){(*(p_bit_reverse_curr_i_plus++) = *(p_bit_reverse_curr_i++) = *(p_bit_reverse_prev_i++) * 2) += 1;}e_next++;swap(two_PW_next,two_PW_next2);two_PW_next2 *= 4;p_bit_reverse_prev++;p_bit_reverse_curr++;}CO VE& bit_reverse_EX = bit_reverse[EX];uint bit_num = 0;CO uint* p_bit_num_reverse = &(bit_reverse_EX[bit_num]);WH(bit_num < two_PW){if(*p_bit_num_reverse < bit_num){swap(f[*p_bit_num_reverse + N_input_start],f[bit_num + N_input_start]);}bit_num++;p_bit_num_reverse++;}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 IN VO FFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI two_PW,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,0,two_PW,two_PW,EX,PrimitiveRootOfTwoForFFT());}TE IN VO FFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,N_output_start,N_output_lim,two_PW,EX,PrimitiveRootOfTwoForFFT());}TE IN VO IFFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI two_PW,CO T& two_PW_inv,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,0,two_PW,two_PW,EX,InversePrimitiveRootOfTwoForFFT());CO uint SZ = two_PW + N_input_start;for(uint i = N_input_start;i < SZ;i++){f[i] *= two_PW_inv;}}TE IN VO IFFT(VE& f,CRUI N_input_start,CRUI N_input_lim,CRUI N_output_start,CRUI N_output_lim,CRUI two_PW,CO T& two_PW_inv,CRUI EX){CooleyTukey(f,N_input_start,N_input_lim,N_output_start,N_output_lim,two_PW,EX,InversePrimitiveRootOfTwoForFFT());CO uint SZ = N_output_lim + N_input_start;for(uint i = N_output_start + N_input_start;i < SZ;i++){f[i] *= two_PW_inv;}} #define DF_BODY_OF_PARTIAL_SPECIALISATION_OF_PO(TYPE,ARG,RHS) TE <> PO& PO::OP*=(ARG f){if(m_SZ != 0){VE v{};v.swap(m_f);TRPO TH_copy{m_SZ + f.m_SZ - 1,MO(v)};TH_copy *= RHS;m_f = MO(TH_copy.PO::m_f);m_SZ = m_f.SZ();}RE *TH;} #define DF_OF_PARTIAL_SPECIALISATION_OF_PO(TYPE) DF_BODY_OF_PARTIAL_SPECIALISATION_OF_PO(TYPE,CO PO&,TH == &f?TH_copy:f);DF_BODY_OF_PARTIAL_SPECIALISATION_OF_PO(TYPE,PO&&,MO(f)); #define RE_ZERO_FOR_MU_FOR_TR_PO_IF(CONDITION) if(CONDITION){RE OP=(zero);} #define RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(CONDITION) if(CONDITION){RE TRPO(m_N);} #define RE_ZERO_FOR__FOR_TR_PO_IF(MU,CONDITION) RE_ZERO_FOR_ ## MU ## _FOR_TR_PO_IF(CONDITION) #define SET_VE_FOR_AN_OF_MU_FOR_TR_PO(N_OUTPUT_LIM) if(PO::m_SZ < N_OUTPUT_LIM){for(uint i = PO::m_SZ;i < N_OUTPUT_LIM;i++){PO::m_f.push_back(0);}PO::m_SZ = N_OUTPUT_LIM;} #define SET_VE_FOR_AN_OF_TR_MU_CO_FOR_TR_PO(N_OUTPUT_LIM) VE AN(N_OUTPUT_LIM) #define SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_OUTPUT_LIM) SET_VE_FOR_AN_OF_ ## MU ## _FOR_TR_PO(N_OUTPUT_LIM) #define SET_SUM_OF_MU_FOR_TR_PO PO::m_f[i] = sum #define SET_SUM_OF_TR_MU_CO_FOR_TR_PO AN[i] = sum #define SET_SUM_OF__FOR_TR_PO(MU) SET_SUM_OF_ ## MU ## _FOR_TR_PO #define SET_N_INPUT_START_FOR_MU_FOR_TR_PO(F,SZ,N_INPUT_START_NUM) uint N_INPUT_START_NUM{};for(uint i = 0;i < SZ && searching;i++){if(F[i] != zero){N_INPUT_START_NUM = i;searching = false;}} #define SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(F,SZ,N_INPUT_MAX_NUM) uint N_INPUT_MAX_NUM{};searching = true;for(uint i = (SZ) - 1;searching;i--){if(F[i] != zero){N_INPUT_MAX_NUM = i;searching = false;}} #define CN_FOR_MU_FOR_TR_PO(J_MIN) CO uint j_max = i < N_input_max_0_start_1?i - N_input_start_1:N_input_max_0;T sum{zero};for(uint j = J_MIN;j <= j_max;j++){sum += PO::m_f[j] * f.PO::m_f[i - j];}PO::m_f[i] = sum; #define CN_FOR_TR_MU_CO_FOR_TR_PO(J_MIN) CO uint j_max = i < N_input_max_0_start_1?i - N_input_start_1:N_input_max_0;T& m_fi = AN[i];for(uint j = J_MIN;j <= j_max;j++){m_fi += PO::m_f[j] * f.PO::m_f[i - j];} #define CN_FOR__FOR_TR_PO(MU,J_MIN) CN_FOR_ ## MU ## _FOR_TR_PO(J_MIN) #define ZEROIFICATION_FOR_MU_FOR_TR_PO for(uint i = 0;i < N_input_start_0_start_1;i++){PO::m_f[i] = 0;} #define ZEROIFICATION_FOR_TR_MU_CO_FOR_TR_PO CRUI N_output_start_fixed = N_output_start < N_input_start_0_start_1?N_output_start:N_input_start_0_start_1;for(uint i = 0;i < N_output_start_fixed;i++){AN[i] = 0;} #define ZEROIFICATION_FOR__FOR_TR_PO(MU) ZEROIFICATION_FOR_ ## MU ## _FOR_TR_PO #define DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START) RE_ZERO_FOR__FOR_TR_PO_IF(MU,PO::m_SZ == 0);uint N_output_max = PO::m_SZ + f.PO::m_SZ - 2;if(N_output_max >= m_N){N_output_max = m_N - 1;}CO uint N_output_lim = N_output_max + 1;SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_output_lim);for(uint i = N_output_max;searching;i--){T sum{zero};for(uint j = 0;j <= i;j++){sum += ACCESS_ENTRY * f.PO::OP[](i - j);}SET_SUM_OF__FOR_TR_PO(MU);searching = i > N_OUTPUT_START;} #define DF_1_OF__FOR_TR_PO(MU) SET_N_INPUT_START_FOR_MU_FOR_TR_PO(PO::m_f,PO::m_SZ,N_input_start_0);RE_ZERO_FOR__FOR_TR_PO_IF(MU,searching);searching = true;SET_N_INPUT_START_FOR_MU_FOR_TR_PO(f,f.PO::m_SZ,N_input_start_1); #define SET_N_INPUT_RANGE SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(PO::m_f,PO::m_SZ,N_input_max_0);SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(f,f.PO::m_SZ < m_N?f.PO::m_SZ:m_N,N_input_max_1);CO uint N_input_max_0_max_1 = N_input_max_0 + N_input_max_1;CO uint N_input_start_0_start_1 = N_input_start_0 + N_input_start_1;uint N_output_lim_fixed = N_input_max_0_max_1 < m_N?N_input_max_0_max_1 + 1:m_N; #define DF_3_OF__FOR_TR_PO(MU) CO uint N_input_start_0_max_1 = N_input_start_0 + N_input_max_1;CO uint N_input_max_0_start_1 = N_input_max_0 + N_input_start_1;CO uint N_output_max_fixed = N_output_lim_fixed - 1;SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_output_lim_fixed);for(uint i = N_output_max_fixed;i > N_input_start_0_max_1;i--){CN_FOR__FOR_TR_PO(MU,i - N_input_max_1);}searching = true;for(uint i = N_input_start_0_max_1 < N_output_max_fixed?N_input_start_0_max_1:N_output_max_fixed;searching;i--){CN_FOR__FOR_TR_PO(MU,N_input_start_0);searching = i > N_input_start_0_start_1;}ZEROIFICATION_FOR__FOR_TR_PO(MU); #define SET_SHIFTED_VE_FOR_MU(V,F,I_START,I_MAX,I_SHIFT) VE V(product_LE);for(uint i = I_START;i <= I_MAX;i++){V[I_SHIFT + i] = F[i];} #define DF_OF_MU_FOR_TR_PO(RE_LINE_0,RE_LINE_1,RE_LINE_2,RE_LINE_3,RE_LINE_4,MU,ACCESS_ENTRY,N_OUTPUT_START,FIX_N_OUTPUT_LIM) CE CRUI border_0 = FFT_MU_border_0;CO T& zero = PO::CO_zero();bool searching = true;if(PO::m_SZ < border_0 && f.PO::m_SZ < border_0){RE_LINE_0;DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START);RE_LINE_1;}DF_1_OF__FOR_TR_PO(MU);RE_LINE_2;SET_N_INPUT_RANGE;FIX_N_OUTPUT_LIM;RE_LINE_3;DF_3_OF__FOR_TR_PO(MU);RE_LINE_4; #define DF_OF_FFT_MU_FOR_TR_PO(RE_LINE_0,RE_LINE_1,RE_LINE_2,RE_LINE_3,RE_LINE_4,RE_LINE_5,MU,ACCESS_ENTRY,N_OUTPUT_START,N_OUTPUT_START_SHIFTED,FIX_N_OUTPUT_LIM,DC_OF_F0,N_INPUT_START_0,N_INPUT_LIM_0,DC_OF_F1,N_INPUT_START_1,N_INPUT_LIM_1,VE_FOR_IFFT,RESZ_VE_FOR_IFFT,I_START,MU_FORMULA,SET_AN) CE CRUI border_0 = FFT_MU_border_0;CO T& zero = PO::CO_zero();bool searching = true;if(PO::m_SZ < border_0 && f.PO::m_SZ < border_0){RE_LINE_0;DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START);RE_LINE_1;}DF_1_OF__FOR_TR_PO(MU);RE_LINE_2;SET_N_INPUT_RANGE;FIX_N_OUTPUT_LIM;RE_LINE_3;CO uint N_input_TR_deg_0_deg_1 = N_input_max_0 - N_input_start_0 + N_input_max_1 - N_input_start_1;CE CRUI border_1 = FFT_MU_border_1;if(N_input_TR_deg_0_deg_1 < border_1){DF_3_OF__FOR_TR_PO(MU);RE_LINE_4;}uint two_PW = FFT_MU_border_1_2;uint EX = FFT_MU_border_1_2_EX;T two_PW_inv{FFT_MU_border_1_2_inv};WH(N_input_TR_deg_0_deg_1 >= two_PW){two_PW *= 2;two_PW_inv /= 2;EX++;}CO uint product_LE = N_input_start_0_start_1 + two_PW;DC_OF_F0;FFT(f0,N_INPUT_START_0,N_INPUT_LIM_0,two_PW,EX);DC_OF_F1;FFT(f1,N_INPUT_START_1,N_INPUT_LIM_1,two_PW,EX);RESZ_VE_FOR_IFFT;for(uint i = I_START + two_PW - 1;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(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 CL TRPO :PU PO{PU:uint m_N;IN TRPO(CRUI N = 0);IN TRPO(CO TRPO& f);IN TRPO(TRPO&& f);IN TRPO(CRUI N,CO T& t);IN TRPO(CRUI N,CO PO& f);IN TRPO(CRUI N,PO&& f);IN TRPO(CRUI N,CRUI i,CO T& t);IN TRPO(CRUI N,CRUI i,T&& t);TE IN TRPO(CRUI N,CRUI i,CO Arg& t);IN TRPO(CRUI N,VE&& f);IN TRPO& OP=(CO TRPO& f);IN TRPO& OP=(TRPO&& f);IN TRPO& OP=(CO T& t);IN TRPO& OP=(T&& t);TE IN TRPO& OP=(CO Arg& n);IN TRPO& OP=(CO PO& f);IN TRPO& OP=(PO&& f);IN TRPO& OP+=(CO T& t);IN TRPO& OP+=(CO PO& f);IN TRPO& OP+=(CO TRPO& f);TRPO& TRPlus(CO PO& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO& OP-=(CO T& t);IN TRPO& OP-=(CO PO& f);IN TRPO& OP-=(CO TRPO& f);TRPO& TRMinus(CO PO& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO& OP*=(CO T& t);TRPO& OP*=(CO PO& f);IN TRPO& OP*=(PO&& f);TRPO& FFT_MU(CO PO& f);TRPO& FFT_MU(PO&& f);TRPO& TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim);TRPO& FFT_TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim);TRPO& FFT_TRMU(PO&& f,CRUI N_output_start,CRUI N_output_lim);TRPO TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim) CO;TRPO FFT_TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim) CO;TRPO FFT_TRMU_CO(PO&& f,CRUI N_output_start,CRUI N_output_lim) CO;IN TRPO& OP/=(CO T& t);IN TRPO& OP/=(CO TRPO& t);IN TRPO& OP%=(CO T& t);IN TRPO OP-() CO;IN VO SetTruncation(CRUI N)NE;IN CRUI GetTruncation() CO NE;IN TRPO& TruncateInitial(CRUI N)NE;IN TRPO& TruncateFinal(CRUI N)NE;};TE IN CE CO uint FFT_MU_border_0{};TE IN CE CO uint FFT_MU_border_1{};TE IN CE CO uint FFT_MU_border_1_2{};TE IN CE CO uint FFT_MU_border_1_2_EX{};TE IN CE CO uint FFT_MU_border_1_2_inv{}; TE IN TRPO::TRPO(CRUI N):PO(),m_N(N){PO::m_f.reserve(m_N);}TE IN TRPO::TRPO(CO TRPO& f):PO(f),m_N(f.m_N){PO::m_f.reserve(m_N);}TE IN TRPO::TRPO(TRPO&& f):PO(MO(f)),m_N(MO(f.m_N)){PO::m_f.reserve(m_N);}TE IN TRPO::TRPO(CRUI N,CO T& t):PO(t),m_N(N){PO::m_f.reserve(m_N);}TE IN TRPO::TRPO(CRUI N,CO PO& f):PO(),m_N(N){PO::m_SZ = f.PO::m_SZ < m_N?f.PO::m_SZ:m_N;PO::m_f = VE(PO::m_SZ);for(uint i = 0;i < PO::m_SZ;i++){PO::m_f[i] = f.PO::m_f[i];}PO::m_f.reserve(m_N);}TE IN TRPO::TRPO(CRUI N,PO&& f):PO(),m_N(N){if(f.PO::m_SZ < m_N * 2){PO::OP=(MO(f));if(f.PO::m_SZ < m_N){PO::m_f.reserve(m_N);}else{TruncateFinal(m_N);}}else{PO::m_f = VE(m_N);for(uint i = 0;i < m_N;i++){PO::m_f[i] = MO(f.PO::m_f[i]);}PO::m_SZ = m_N;}}TE IN TRPO::TRPO(CRUI N,CRUI i,CO T& t):PO(),m_N(N){if(i < m_N?t != PO::CO_zero():false){PO::OP[](i) = t;}PO::m_f.reserve(m_N);}TE IN TRPO::TRPO(CRUI N,CRUI i,T&& t):PO(),m_N(N){if(i < m_N?t != PO::CO_zero():false){PO::OP[](i) = MO(t);}PO::m_f.reserve(m_N);}TE TE IN TRPO::TRPO(CRUI N,CRUI i,CO Arg& n):TRPO(N,i,T(n)){}TE IN TRPO::TRPO(CRUI N,VE&& f):PO(),m_N(N){CO uint f_SZ = f.SZ();if(f_SZ < m_N * 2){PO::OP=(MO(f));if(f_SZ < m_N){PO::m_f.reserve(m_N);}else{TruncateFinal(m_N);}}else{PO::m_f = VE(m_N);for(uint i = 0;i < m_N;i++){PO::m_f[i] = MO(f[i]);}PO::m_f.reserve(m_N);}}TE IN TRPO& TRPO::OP=(CO TRPO& f){PO::OP=(f);m_N = f.m_N;PO::m_f.reserve(m_N);RE *TH;}TE IN TRPO& TRPO::OP=(TRPO&& f){PO::OP=(MO(f));m_N = MO(f.m_N);PO::m_f.reserve(m_N);RE *TH;}TE IN TRPO& TRPO::OP=(CO T& t){PO::OP=(t);RE *TH;}TE IN TRPO& TRPO::OP=(T&& t){PO::OP=(MO(t));RE *TH;}TE TE IN TRPO& TRPO::OP=(CO Arg& n){PO::OP=(T(n));RE *TH;}TE IN TRPO& TRPO::OP=(CO PO& f){RE OP=(TRPO(m_N,f));}TE IN TRPO& TRPO::OP=(PO&& f){RE OP=(TRPO(m_N,MO(f)));}TE IN TRPO& TRPO::OP+=(CO T& t){PO::OP+=(t);RE *TH;}TE IN TRPO& TRPO::OP+=(CO PO& f){RE TRPO::TRPlus(f,0,f.m_SZ);}TE IN TRPO& TRPO::OP+=(CO TRPO& f){RE m_N == 0?OP=(f):TRPO::TRPlus(f,0,f.PO::m_SZ);}TE TRPO& TRPO::TRPlus(CO PO& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO::m_SZ?N_input_lim:f.PO::m_SZ:m_N < f.PO::m_SZ?m_N:f.PO::m_SZ;if(PO::m_SZ < SZ){PO::m_f.reserve(SZ);for(uint i = N_input_start;i < PO::m_SZ;i++){PO::m_f[i] += f.PO::m_f[i];}for(uint i = PO::m_SZ;i < SZ;i++){PO::m_f.push_back(f.PO::m_f[i]);}PO::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO::m_f[i] += f.PO::m_f[i];}}RE *TH;}TE IN TRPO& TRPO::OP-=(CO T& t){PO::OP-=(t);RE *TH;}TE IN TRPO& TRPO::OP-=(CO PO& f){RE TRPO::TRMinus(f,0,f.m_SZ);}TE IN TRPO& TRPO::OP-=(CO TRPO& f){RE m_N == 0?OP=(-f):TRPO::TRMinus(f,0,f.PO::m_SZ);}TE TRPO& TRPO::TRMinus(CO PO& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO::m_SZ?N_input_lim:f.PO::m_SZ:m_N < f.PO::m_SZ?m_N:f.PO::m_SZ;if(PO::m_SZ < SZ){PO::m_f.reserve(SZ);for(uint i = N_input_start;i < PO::m_SZ;i++){PO::m_f[i] -= f.PO::m_f[i];}for(uint i = PO::m_SZ;i < SZ;i++){PO::m_f.push_back(- f.PO::m_f[i]);}PO::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO::m_f[i] -= f.PO::m_f[i];}}RE *TH;}TE IN TRPO& TRPO::OP*=(CO T& t){PO::OP*=(t);RE *TH;}TE TRPO& TRPO::OP*=(CO PO& f){DF_OF_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO::m_SZ == 0),,RE_ZERO_FOR_MU_FOR_TR_PO_IF(searching),RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= m_N),RE *TH,MU,PO::m_f,0,);}TE IN TRPO& TRPO::OP*=(PO&& f){RE OP*=(f);}TE TRPO& TRPO::FFT_MU(CO PO& f){DF_OF_FFT_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO::m_SZ == 0),RE *TH,RE_ZERO_FOR_MU_FOR_TR_PO_IF(searching),RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f[j],0,0,,VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,SET_SHIFTED_VE_FOR_MU(f1,f.PO::m_f,N_input_start_1,N_input_max_1,N_input_start_0),N_input_start_0_start_1,N_input_start_0 + N_input_max_1 + 1,f1,,N_input_start_0,f1[N_input_start_1 + i] *= f0[i],OP=(TRPO(m_N,MO(f1))));}TE TRPO& TRPO::FFT_MU(PO&& f){DF_OF_FFT_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO::m_SZ == 0),RE *TH,RE_ZERO_FOR_MU_FOR_TR_PO_IF(searching),RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f[j],0,0,,VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,VE&& f1 = MO(f.PO::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::m_SZ = f0.SZ();SetTruncation(m_N););}TE TRPO& TRPO::TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,MU,PO::m_f[j],N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE TRPO& TRPO::FFT_TRMU(CO PO& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_FFT_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f[j],N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,SET_SHIFTED_VE_FOR_MU(f1,f.PO::m_f,N_input_start_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(m_N,MO(f1))));}TE TRPO& TRPO::FFT_TRMU(PO&& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_FFT_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,RE *TH,MU,PO::m_f,N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},VE& f0 = PO::m_f,N_input_start_0,N_input_max_0 + 1,VE&& f1 = MO(f.PO::m_f),N_input_start_1,N_input_max_1 + 1,f0,f0.reserve(product_LE),0,f1[N_input_start_0_start_1 + i] = f0[N_input_start_0 + i] * f1[N_input_start_1 + i],for(uint i = N_input_start_0;i < N_input_start_0_start_1;i++){f0[i] = 0;}PO::m_SZ = f0.SZ();SetTruncation(m_N););}TE TRPO TRPO::TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim) CO{DF_OF_MU_FOR_TR_PO(,RE TRPO(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO(m_N,MO(AN)),TR_MU_CO,PO::OP[](j),N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE TRPO TRPO::FFT_TRMU_CO(CO PO& f,CRUI N_output_start,CRUI N_output_lim) CO{DF_OF_FFT_MU_FOR_TR_PO(,RE TRPO(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO(m_N,MO(AN)),RE TRPO(m_N,MO(f0)),TR_MU_CO,PO::OP[](j),N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},SET_SHIFTED_VE_FOR_MU(f0,PO::m_f,N_input_start_0,N_input_max_0,N_input_start_1),N_input_start_0_start_1,N_input_start_1 + N_input_max_0 + 1,VE f1 = f.PO::m_f,N_input_start_1,N_input_max_1 + 1,f0,,N_input_start_1,f0[N_input_start_0 + i] *= f1[i],);}TE TRPO TRPO::FFT_TRMU_CO(PO&& f,CRUI N_output_start,CRUI N_output_lim) CO{DF_OF_FFT_MU_FOR_TR_PO(,RE TRPO(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO(m_N,MO(AN)),RE TRPO(m_N,MO(f0)),TR_MU_CO,PO::OP[](j),N_output_start,N_output_start < N_input_start_0_start_1?0:N_output_start - N_input_start_0_start_1,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;},SET_SHIFTED_VE_FOR_MU(f0,PO::m_f,N_input_start_0,N_input_max_0,N_input_start_1),N_input_start_0_start_1,N_input_start_1 + N_input_max_0 + 1,VE&& f1 = MO(f.PO::m_f),N_input_start_1,N_input_max_1 + 1,f0,,N_input_start_1,f0[N_input_start_0 + i] *= f1[i],);}TE IN TRPO& TRPO::OP/=(CO T& t){PO::OP/=(t);RE *TH;}TE IN TRPO& TRPO::OP/=(CO TRPO& f){RE OP*=(Inverse(m_N > f.m_N?f:TRPO(m_N,f)));}TE IN TRPO& TRPO::OP%=(CO T& t){PO::OP%=(t);RE *TH;}TE IN TRPO TRPO::OP-() CO{RE MO(TRPO(m_N) -= *TH);}TE IN VO TRPO::SetTruncation(CRUI N)NE{if(N < m_N){TruncateFinal(m_N);}else{PO::m_f.reserve(N);}m_N = N;}TE IN CRUI TRPO::GetTruncation() CO NE{RE m_N;}TE IN TRPO& TRPO::TruncateInitial(CRUI N)NE{CRUI SZ = N < PO::m_SZ?N:PO::m_SZ;for(uint i = 0;i < SZ;i++){PO::m_f[i] = 0;}RE *TH;}TE IN TRPO& TRPO::TruncateFinal(CRUI N)NE{WH(PO::m_SZ > N){PO::m_f.pop_back();PO::m_SZ--;}RE *TH;}TE IN TRPO OP+(CO TRPO& f0,CO P& f1){RE MO(TRPO(f0) += f1);}TE IN TRPO OP-(CO TRPO& f){RE MO(TRPO(f.GetTurncation()) -= f);}TE IN TRPO OP-(CO TRPO& f0,CO P& f1){RE MO(TRPO(f0) -= f1);}TE IN TRPO OP*(CO TRPO& f0,CO P& f1){RE MO(TRPO(f0) *= f1);}TE IN TRPO OP/(CO TRPO& f0,CO P& f1){RE MO(TRPO(f0) /= f1);}TE IN TRPO OP%(CO TRPO& f0,CO T& t1){RE MO(TRPO(f0) %= t1);}TE TRPO Differential(CRUI n,CO TRPO& f){if(f.PO::m_SZ < n){RE TRPO(f.m_N - n,PO::zero());}VE df(f.PO::m_SZ - n);T coef = T::Factorial(n);uint i = n;WH(i < f.PO::m_SZ){df[i - n] = f[i] * coef;i++;(coef *= i) /= (i - n);}RE TRPO(f.m_N - n,MO(df));}TE TRPO TRDifferential(CO TRPO& f,CRUI N_output_start_plus_one){assert(f.m_N > 0);TRPO f_dif{f.m_N - 1};if(N_output_start_plus_one < f.PO::m_SZ){CO uint SZ = f.PO::m_SZ - 1;f_dif.PO::m_f = VE(SZ);for(uint i = N_output_start_plus_one;i < f.PO::m_SZ;i++){f_dif.PO::m_f[i-1] = i * f.PO::m_f[i];}f_dif.PO::m_SZ = SZ;}RE f_dif;}TE IN TRPO Differential(CO TRPO& f){RE TRDifferential(f,1);}TE TRPO TRIntegral(CO TRPO& f,CRUI N_output_start){TRPO f_int{f.m_N + 1};if(N_output_start <= f.PO::m_SZ){CO uint SZ = f.PO::m_SZ + 1;f_int.PO::m_f = VE(SZ);for(uint i = N_output_start;i <= f.PO::m_SZ;i++){f_int.PO::m_f[i] = f.PO::m_f[i - 1] / T(i);}f_int.PO::m_SZ = SZ;}RE f_int;}TE IN TRPO Integral(CO TRPO& f){RE TRIntegral(f,1);}TE TRPO Inverse(CO TRPO& f){DF_OF_INVERSE_FOR_TR_PO(T,f_inv.TRMinus(f_inv.TRMU_CO(f,PW,PW_2).TRMU(f_inv,PW,PW_2),PW,PW_2));}TE TRPO Exp(CO TRPO& f){DF_OF_EXP_FOR_TR_PO(T,f_exp.TRMinus((TRIntegral(Differential(f_exp).TRMU_CO(Inverse(f_exp),PW - 1,PW_2),PW).TRMinus(f,PW,PW_2)).TRMU(f_exp,PW),PW,PW_2));}TE IN TRPO Log(CO TRPO& f){RE Integral(Differential(f) /= f);}TE IN TRPO PW(CO TRPO& f,CO T& t){RE Exp(Log(f) *= t);} TE IN PO& PO::OP/=(CO PO& f){RE m_SZ < f.m_SZ?*TH:OP=(Quotient(*TH,f));}TE PO& PO::OP%=(CO PO& f){if(m_SZ >= f.m_SZ){OP-=((*TH / f) * f);ReMORedundantZero();}RE *TH;}TE PO PO::Quotient(CO PO& f0,CO PO& f1){if(f0.m_SZ < f1.m_SZ){RE f0;}assert(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;RE TPQuotient(f0,f0_TP_SZ,Inverse(TRPO(f0_TP_SZ,TP(f1,f1_TP_SZ))),f1.m_SZ);}TE PO PO::TPQuotient(CO PO& f0,CRUI f0_TP_SZ,CO PO& f1_TP_inverse,CRUI f1_SZ){TRPO f0_TP{f0_TP_SZ,TP(f0,f0_TP_SZ)};f0_TP *= f1_TP_inverse;for(uint d0 = (f0_TP_SZ + 1) / 2;d0 < f0_TP_SZ;d0++){::swap(f0_TP.PO::m_f[d0],f0_TP.PO::m_f[ f0_TP_SZ - 1 - d0 ]);}RE f0_TP;}TE PO& PO::OP<<=(CO T& t){if(m_SZ > 0){for(uint d = 0;d < m_SZ;d++){m_f[d] *= T::Factorial(d);}TRPO exp_t_TP{m_SZ * 2};T PW_t = CO_one();for(uint d = 0;d < m_SZ;d++){exp_t_TP[m_SZ - 1 - d] = PW_t * T::FactorialInverse(d);PW_t *= t;}exp_t_TP *= *TH;for(uint d = 0;d < m_SZ;d++){m_f[d] = exp_t_TP.PO::m_f[d + m_SZ - 1] * T::FactorialInverse(d);}}RE *TH;}TE IN PO OP/(CO PO& f0,CO PO& f1){RE PO::Quotient(f0,f1);}TE IN PO OP%(CO PO& f0,CO P& f1){RE MO(PO(f0) %= f1);}TE PO OP<<(CO PO& f,CO T& t){RE MO(PO(f) <<= t);}DF_OF_PARTIAL_SPECIALISATION_OF_MU_OF_TR_PO(MP,17,512,1024,10,997269505);DF_OF_PARTIAL_SPECIALISATION_OF_MU_OF_TR_PO(MNP,17,512,1024,10,997269505);DF_OF_PARTIAL_SPECIALISATION_OF_PO(MP); #include using namespace atcoder; uint K = 1; uint K2 = 2; // PO mul( PO f0 , PO f1 ) // { // PO ans = f0 * f1; // while( ans.m_SZ > K ){ // ans.m_SZ--; // ans.m_f[ans.m_SZ - K] += ans.m_f[ans.m_SZ]; // ans.m_f.pop_back(); // } // return ans; // } // inline constexpr MNP one{ 1 }; // inline PO e(){ return PO( 0 , one ); } vector mul( vector f0 , vector f1 ) { vector ans = convolution( f0 , f1 ); int size = ans.size(); while( size > K ){ size--; ans[size - K] += ans[size]; ans.pop_back(); } return ans; } inline vector e(){ return vector( 1 , 1 ); } ATT int main() { UNTIE; CIN( int , N ); CIN( int , M ); cin >> K; K2 = ( K << 1 ); // segtree,mul,e> a{ N }; // FOR( i , 0 , N ){ // CIN( uint , Ai ); // a.set( i , e() + PO( Ai , 1 ) ); // } vector > v{}; REPEAT( N ){ CIN( uint , Ai ); vector f( Ai + 1 ); f[0]++; f[Ai]++; v.push_back( move( f ) ); } segtree,mul,e> a{ v }; int k_lim = N - M + 1; FOR( k , 0 , k_lim ){ ll answer = a.prod( k , k + M )[0]; COUT( answer > 0 ? --answer : 998244352 ); } QUIT; }