QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670546#9493. 路径计数cmk66685 4020ms51136kbC++2336.7kb2024-10-23 22:12:092024-10-23 22:12:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 22:12:10]
  • 评测
  • 测评结果:85
  • 用时:4020ms
  • 内存:51136kb
  • [2024-10-23 22:12:09]
  • 提交

answer

/*  _              _     _                                             _       __      __      __   
   / \     _   _  | |_  | |__     ___    _ __   _    ___   _ __ ___   | | __  / /_    / /_    / /_  
  / _ \   | | | | | __| | '_ \   / _ \  | '__| (_)  / __| | '_ ` _ \  | |/ / | '_ \  | '_ \  | '_ \ 
 / ___ \  | |_| | | |_  | | | | | (_) | | |     _  | (__  | | | | | | |   <  | (_) | | (_) | | (_) |
/_/   \_\  \__,_|  \__| |_| |_|  \___/  |_|    (_)  \___| |_| |_| |_| |_|\_\  \___/   \___/   \___/ 
[Created Time:       2024-10-23 21:03:31]
[Last Modified Time: 2024-10-23 22:12:01] */
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
#define USE_FastIO
// ------------------------------
// #define DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
	inline void _chk_i() {}
	inline char _gc_nochk() { return getchar(); }
	inline char _gc() { return getchar(); }
	inline void _chk_o() {}
	inline void _pc_nochk(char c) { putchar(c); }
	inline void _pc(char c) { putchar(c); }
	template < int n > inline void _pnc_nochk(const char *c) { for ( int i = 0 ; i < n ; i++ ) putchar(c[i]); }
#else
#ifdef DISABLE_MMAP
	inline constexpr int _READ_SIZE = 1 << 18; inline static char _read_buffer[_READ_SIZE + 40], *_read_ptr = nullptr, *_read_ptr_end = nullptr; static inline bool _eof = false;
	inline void _chk_i() { if ( __builtin_expect(!_eof, true) && __builtin_expect(_read_ptr_end - _read_ptr < 40, false) ) { int sz = _read_ptr_end - _read_ptr; if ( sz ) memcpy(_read_buffer, _read_ptr, sz); char *beg = _read_buffer + sz; _read_ptr = _read_buffer, _read_ptr_end = beg + fread(beg, 1, _READ_SIZE, stdin); if ( __builtin_expect(_read_ptr_end != beg + _READ_SIZE, false) ) _eof = true, *_read_ptr_end = EOF; } }
	inline char _gc_nochk() { return __builtin_expect(_eof && _read_ptr == _read_ptr_end, false) ? EOF : *_read_ptr++; }
	inline char _gc() { _chk_i(); return _gc_nochk(); }
#else
#include<sys/mman.h>
#include<sys/stat.h>
	inline static char *_read_ptr = (char *)mmap(nullptr, [] { struct stat s; return fstat(0, &s), s.st_size; } (), 1, 2, 0, 0);
	inline void _chk_i() {}
	inline char _gc_nochk() { return *_read_ptr++; }
	inline char _gc() { return *_read_ptr++; }
#endif
	inline constexpr int _WRITE_SIZE = 1 << 18; inline static char _write_buffer[_WRITE_SIZE + 40], *_write_ptr = _write_buffer;
	inline void _chk_o() { if ( __builtin_expect(_write_ptr - _write_buffer > _WRITE_SIZE, false) ) fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer; }
	inline void _pc_nochk(char c) { *_write_ptr++ = c; }
	inline void _pc(char c) { *_write_ptr++ = c, _chk_o(); }
	template < int n > inline void _pnc_nochk(const char *c) { memcpy(_write_ptr, c, n), _write_ptr += n; }
	inline struct _auto_flush { inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush;
#endif
#define println println_ // don't use C++23 std::println
	template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
	template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
	template <> inline constexpr bool _is_signed < __int128 > = true;
	template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
	inline bool _isgraph(char c) { return c >= 33; }
	inline bool _isdigit(char c) { return 48 <= c && c <= 57; } // or faster, remove c <= 57
	constexpr struct _table {
#ifndef LOCAL
	int i[65536];
#endif
	char o[40000]; constexpr _table() :
#ifndef LOCAL
	i{},
#endif
	o{} {
#ifndef LOCAL
	for ( int x = 0 ; x < 65536 ; x++ ) i[x] = -1; for ( int x = 0 ; x <= 9 ; x++ ) for ( int y = 0 ; y <= 9 ; y++ ) i[x + y * 256 + 12336] = x * 10 + y;
#endif
	for ( int x = 0 ; x < 10000 ; x++ ) for ( int y = 3, z = x ; ~y ; y-- ) o[x * 4 + y] = z % 10 + 48, z /= 10; } } _table;
	template < class T, int digit > inline constexpr T _pw10 = 10 * _pw10 < T, digit - 1 >;
	template < class T > inline constexpr T _pw10 < T, 0 > = 1;
	inline void read(char &c) { do c = _gc(); while ( !_isgraph(c) ); }
	inline void read_cstr(char *s) { char c = _gc(); while ( !_isgraph(c) ) c = _gc(); while ( _isgraph(c) ) *s++ = c, c = _gc(); *s = 0; }
	inline void read(string &s) { char c = _gc(); s.clear(); while ( !_isgraph(c) ) c = _gc(); while ( _isgraph(c) ) s.push_back(c), c = _gc(); }
	template < class T, bool neg >
#ifndef LOCAL
	__attribute__((no_sanitize("undefined")))
#endif
	inline void _read_int_suf(T &x) { _chk_i(); char c; while
#ifndef LOCAL
	( ~_table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)] ) if constexpr ( neg ) x = x * 100 - _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; else x = x * 100 + _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; if
#endif
	( _isdigit(c = _gc_nochk()) ) if constexpr ( neg ) x = x * 10 - ( c & 15 ); else x = x * 10 + ( c & 15 ); }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ) if ( c == 45 ) { _read_int_suf < T, true >(x = -( _gc_nochk() & 15 )); return; } _read_int_suf < T, false >(x = c & 15); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ); _read_int_suf < T, false >(x = c & 15); }
	inline void write(bool x) { _pc(x | 48); }
	inline void write(char c) { _pc(c); }
	inline void write_cstr(const char *s) { while ( *s ) _pc(*s++); }
	inline void write(const string &s) { for ( char c : s ) _pc(c); }
	template < class T, bool neg, int digit > inline void _write_int_suf(T x) { if constexpr ( digit == 4 ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _write_int_suf < T, neg, digit / 2 >(x / _pw10 < T, digit / 2 >), _write_int_suf < T, neg, digit / 2 >(x % _pw10 < T, digit / 2 >); }
	template < class T, bool neg, int digit > inline void _write_int_pre(T x) { if constexpr ( digit <= 4 ) if ( digit >= 3 && ( neg ? x <= -100 : x >= 100 ) ) if ( digit >= 4 && ( neg ? x <= -1000 : x >= 1000 ) ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _pnc_nochk < 3 >(_table.o + ( neg ? -x : x ) * 4 + 1); else if ( digit >= 2 && ( neg ? x <= -10 : x >= 10 ) ) _pnc_nochk < 2 >(_table.o + ( neg ? -x : x ) * 4 + 2); else _pc_nochk(( neg ? -x : x ) | 48); else { constexpr int cur = 1 << __lg(digit - 1); if ( neg ? x <= -_pw10 < T, cur > : x >= _pw10 < T, cur > ) _write_int_pre < T, neg, digit - cur >(x / _pw10 < T, cur >), _write_int_suf < T, neg, cur >(x % _pw10 < T, cur >); else _write_int_pre < T, neg, cur >(x); } }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void write(T x) { if ( x >= 0 ) _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x); else _pc_nochk(45), _write_int_pre < T, true, numeric_limits < T >::digits10 + 1 >(x); _chk_o(); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void write(T x) { _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x), _chk_o(); }
	template < size_t N, class ...T > inline void _read_tuple(tuple < T... > &x) { read(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _read_tuple < N + 1, T... >(x); }
	template < size_t N, class ...T > inline void _write_tuple(const tuple < T... > &x) { write(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _pc(32), _write_tuple < N + 1, T... >(x); }
	template < class ...T > inline void read(tuple < T... > &x) { _read_tuple < 0, T... >(x); }
	template < class ...T > inline void write(const tuple < T... > &x) { _write_tuple < 0, T... >(x); }
	template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
	template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), _pc(32), write(x.second); }
	template < class T > inline auto read(T &x) -> decltype(x.read(), void()) { x.read(); }
	template < class T > inline auto write(const T &x) -> decltype(x.write(), void()) { x.write(); }
	template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
	template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
	template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
	template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
	template < class T > inline void print(const T &x) { write(x); }
	inline void print_cstr(const char *x) { write_cstr(x); }
	template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { write(x), _pc(32), print(y...); }
	template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_cstr(x), _pc(32), print_cstr(y...); }
	inline void println() { _pc(10); }
	inline void println_cstr() { _pc(10); }
	template < class ...T > inline void println(const T &...x) { print(x...), _pc(10); }
	template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), _pc(10); }
}	using FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;
template < auto P_ > class MontgomeryModInt
{
	using S = decltype(P_); static_assert(is_same_v < S, int > || is_same_v < S, long > || is_same_v < S, long long >);
	static_assert(P_ & 1 && 0 < P_ && P_ < ( (S)1 << ( sizeof(S) * 8 - 2 ) ));
	using U = conditional_t < is_same_v < S, int >, unsigned, unsigned long long >; using D = conditional_t < is_same_v < S, int >, unsigned long long, __uint128_t >;
	inline constexpr static U uinv(U x) { U y = x; for ( int i = is_same_v < S, int > ? 4 : 5 ; i-- ; ) y *= 2 - x * y; return y; }
	constexpr static U P = P_, P2 = P << 1, R = -uinv(P), R2 = -(D)P % P; static_assert(P * R == -1);
	inline constexpr static U reduce(D x) { return ( x + (U)x * R * (D)P ) >> ( sizeof(U) * 8 ); }
	inline constexpr MontgomeryModInt(U x, int) : v(x) {} U v;
public:
	inline constexpr static S mod() { return P; }
	inline constexpr MontgomeryModInt() : v(0) {}
	inline constexpr MontgomeryModInt(const MontgomeryModInt &x) : v(x.v) {}
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > inline constexpr MontgomeryModInt(T x) : v(reduce((D)R2 * ( numeric_limits < T >::is_signed && x < 0 ? ( ( x + P < 0 ) && ( x %= P ), x + P ) : ( ( sizeof(T) > sizeof(U) && x >= (T)1 << sizeof(U) ) && ( x %= P ), x ) ))) {}
	inline constexpr S val()const { U x = reduce(v); return ( x - P ) >> ( sizeof(U) * 8 - 1 ) ? x : x - P; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > explicit inline constexpr operator T()const { return val(); }
	inline constexpr friend bool operator==(const MontgomeryModInt &x, const MontgomeryModInt &y) { return x.val() == y.val(); }
	inline constexpr friend bool operator!=(const MontgomeryModInt &x, const MontgomeryModInt &y) { return x.val() != y.val(); }
	inline constexpr MontgomeryModInt &operator=(const MontgomeryModInt &x) & { v = x.v; return *this; }
	inline constexpr MontgomeryModInt &operator++() & { return *this += 1; }
	inline constexpr MontgomeryModInt operator++(int) & { MontgomeryModInt x = *this; *this += 1; return x; }
	inline constexpr MontgomeryModInt &operator--() & { return *this -= 1; }
	inline constexpr MontgomeryModInt operator--(int) & { MontgomeryModInt x = *this; *this -= 1; return x; }
	inline constexpr MontgomeryModInt operator-()const { return MontgomeryModInt(v ? P2 - v : 0, 0); }
	inline constexpr MontgomeryModInt &operator+=(const MontgomeryModInt &x) & { v += x.v, ( v - P2 ) >> ( sizeof(U) * 8 - 1 ) || ( v -= P2 ); return *this; }
	inline constexpr MontgomeryModInt &operator-=(const MontgomeryModInt &x) & { v -= x.v, v >> ( sizeof(U) * 8 - 1 ) && ( v += P2 ); return *this; }
	inline constexpr MontgomeryModInt &operator*=(const MontgomeryModInt &x) & { v = reduce((D)v * x.v); return *this; }
	inline constexpr MontgomeryModInt &operator/=(const MontgomeryModInt &x) & { return *this *= x.inv(); }
	inline constexpr friend MontgomeryModInt operator+(MontgomeryModInt x, const MontgomeryModInt &y) { return x += y; }
	inline constexpr friend MontgomeryModInt operator-(MontgomeryModInt x, const MontgomeryModInt &y) { return x -= y; }
	inline constexpr friend MontgomeryModInt operator*(MontgomeryModInt x, const MontgomeryModInt &y) { return x *= y; }
	inline constexpr friend MontgomeryModInt operator/(MontgomeryModInt x, const MontgomeryModInt &y) { return x /= y; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > inline constexpr MontgomeryModInt qpow(T y)const { MontgomeryModInt x = *this, z = 1; while ( y ) { if ( y & 1 ) z *= x; if ( y >>= 1 ) x *= x; } return z; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > inline constexpr friend MontgomeryModInt qpow(const MontgomeryModInt &x, T y) { return x.qpow(y); }
	inline constexpr MontgomeryModInt inv()const { return qpow(P - 2); }
	inline constexpr friend MontgomeryModInt inv(const MontgomeryModInt &x) { return x.inv(); }
	inline friend istream &operator>>(istream &is, MontgomeryModInt &x) { S y; is >> y, x = y; return is; }
	inline friend ostream &operator<<(ostream &os, const MontgomeryModInt &x) { return os << x.val(); }
#ifdef USE_FastIO
	inline void read() & { S x; ::read(x), *this = x; }
	inline void write()const { ::write(val()); }
#endif
};	using MI = MontgomeryModInt < 998244353 >; // 1000000007 1145141919810000037
template < class MI > struct VALUES
{
	static vector < MI > inv, fac, ifac;
	inline static void extend(int n)
	{
		if ( __builtin_expect((int)inv.size() > n, true) ) return;
		if ( __builtin_expect(inv.empty(), false) ) inv = { 0, 1 }, fac = ifac = { 1, 1 };
		int m = (int)inv.size(); inv.resize(n + 1), fac.resize(n + 1), ifac.resize(n + 1);
		for ( int i = m ; i != n + 1 ; i++ ) inv[i] = MI::mod() / i * -inv[MI::mod() % i],
								  fac[i] = fac[i - 1] * i, ifac[i] = ifac[i - 1] * inv[i];
	}
};	template < class MI > vector < MI > VALUES < MI >::inv;
	template < class MI > vector < MI > VALUES < MI >::fac;
	template < class MI > vector < MI > VALUES < MI >::ifac;
// int VALUES_INIT = [] { return VALUES < MI >::extend(1000000), 0; } ();
// inline MI  fac(int x) { return x >= 0 ? VALUES < MI >::extend(max(1, x)), VALUES < MI >:: fac[x] : 0; }
// inline MI ifac(int x) { return x >= 0 ? VALUES < MI >::extend(max(1, x)), VALUES < MI >::ifac[x] : 0; }
// inline MI c(int x, int y) { return x >= y && y >= 0 ? fac(x) * ifac(y) * ifac(x - y) : 0; }
template < class IT1, class IT2 > inline void linear_inv(int n, IT1 p, IT2 q)
{
	*q = *p; for ( int i = 1 ; i != n ; i++ ) q[i] = q[i - 1] * p[i]; q[n - 1] = q[n - 1].inv();
	for ( int i = n - 1 ; i ; i-- ) { MI x = q[i]; q[i] *= q[i - 1], q[i - 1] = x * p[i]; }
}
template < class MI > inline pair < bool, MI > cipolla(const MI &s)
{
	if ( !s ) return make_pair(true, 0);
	if ( MI::mod() == 2 ) return make_pair(true, 1);
	if ( s.qpow(( MI::mod() - 1 ) >> 1) != 1 ) return make_pair(false, 0);
	static mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
	uniform_int_distribution < decltype(MI::mod()) > uid(1, MI::mod() - 1);
	MI x, y; do x = uid(rnd), y = x * x - s; while ( y.qpow(( MI::mod() - 1 ) >> 1) == 1 );
	constexpr auto mul = [](pair < MI, MI > &f, const pair < MI, MI > &g, const MI &h) {
		f = make_pair(f.first * g.first  + f.second * g.second * h,
					  f.first * g.second + f.second * g.first);
	}; pair < MI, MI > f(x, 1), g(1, 0); auto z = ( MI::mod() + 1 ) >> 1;
	while ( z ) { if ( z & 1 ) mul(g, f, y); if ( z >>= 1 ) mul(f, f, y); }
	return make_pair(true, min(g.first.val(), MI::mod() - g.first.val()));
}
template < class MI > class Polynomial : public vector < MI >
{
	constexpr static MI G = 3; constexpr static int L = [] { int x = MI::mod() - 1, y = 0; while ( ~x & 1 ) x >>= 1, y++; return y; } ();
	constexpr static array < MI, L + 1 > ivn = [] { array < MI, L + 1 > a{}; for ( int i = 0 ; i != L + 1 ; i++ ) a[i] = MI(1 << i).inv(); return a; } ();
	inline static pair < const Polynomial *, const Polynomial * > get_rt(int n) { static Polynomial rt = { 1 }, irt = { 1 }; if ( rt.size() < n ) { int i = rt.size(); for ( rt.resize(n), irt.resize(n) ; i != n ; i <<= 1 ) { MI w = G.qpow(MI::mod() / ( i << 2 )), iw = w.inv(); for ( int j = 0 ; j != i ; j++ ) rt[j + i] = rt[j] * w, irt[j + i] = irt[j] * iw; } } return make_pair(&rt, &irt); }
	inline constexpr static int get_len(int x) { return x < 3 ? x : 2 << __lg(x - 1); }
	inline void dif(int n) { const Polynomial &rt = *get_rt(n).first; for ( int i = n ; i >>= 1 ; ) for ( int j = 0, k = 0 ; j != n ; j += i << 1, k++ ) for ( int p = j, q = j + i ; p != j + i ; p++, q++ ) { MI x = (*this)[p], y = (*this)[q] * rt[k]; (*this)[p] = x + y, (*this)[q] = x - y; } }
	inline void dit(int n) { const Polynomial &irt = *get_rt(n).second; for ( int i = 1 ; i != n ; i <<= 1 ) for ( int j = 0, k = 0 ; j != n ; j += i << 1, k++ ) for ( int p = j, q = j + i ; p != j + i ; p++, q++ ) { MI x = (*this)[p], y = (*this)[q]; (*this)[p] = x + y, (*this)[q] = ( x - y ) * irt[k]; } MI x = ivn[__lg(n)]; for ( int i = 0 ; i != n ; i++ ) (*this)[i] *= x; }
	inline void dif_rhalf(int n) { const Polynomial &rt = *get_rt(n).first; for ( int i = n, m = 1 ; i >>= 1 ; m <<= 1 ) for ( int j = 0, k = 0 ; j != n ; j += i << 1, k++ ) for ( int p = j, q = j + i ; p != j + i ; p++, q++ ) { MI x = (*this)[p], y = (*this)[q] * rt[m + k]; (*this)[p] = x + y, (*this)[q] = x - y; } }
	inline void dit_rhalf(int n) { const Polynomial &irt = *get_rt(n).second; for ( int i = 1, m = n ; m >>= 1 ; i <<= 1 ) for ( int j = 0, k = 0 ; j != n ; j += i << 1, k++ ) for ( int p = j, q = j + i ; p != j + i ; p++, q++ ) { MI x = (*this)[p], y = (*this)[q]; (*this)[p] = x + y, (*this)[q] = ( x - y ) * irt[m + k]; } MI x = ivn[__lg(n)]; for ( int i = 0 ; i != n ; i++ ) (*this)[i] *= x; }
	inline void dot(const Polynomial &x, int n) { for ( int i = 0 ; i != n ; i++ ) (*this)[i] *= x[i]; }
	inline void deriv(int n, const typename vector < MI >::iterator &x)const { for ( int i = 1 ; i != n ; i++ ) x[i - 1] = (*this)[i] * i; x[n - 1] = 0; }
	inline void integ(int n, const typename vector < MI >::iterator &x)const { VALUES < MI >::extend(n); for ( int i = n - 1 ; i ; i-- ) x[i] = (*this)[i - 1] * VALUES < MI >::inv[i]; x[0] = 0; }
	inline static Polynomial mul_big(Polynomial x, Polynomial y) { int n = x.size() + y.size() - 1, m = get_len(n); x.resize(m), x.dif(m), y.resize(m), y.dif(m), x.dot(y, m), x.dit(m), x.resize(n); return x; }
	inline Polynomial pow_one(int n, int k)const { if ( !k ) { Polynomial x(n); x[0] = 1; return x; } return k == 1 ? modxk(n) : ( modxk(n).ln() * k ).exp(); }
	inline Polynomial pow_non_zero(int n, int k_mod_p, int k_mod_phi_p)const { return (*this)[0] == 1 ? pow_one(n, k_mod_p) : ( *this * (*this)[0].inv() ).pow_one(n, k_mod_p) * (*this)[0].qpow(k_mod_phi_p); }
	inline Polynomial sqrt_non_zero(const MI &t)const { constexpr MI c = -MI(2).inv(); int n = get_len(size()); Polynomial x(size()), y(size()), z(n), u(n), v(n); x[0] = v[0] = t, y[0] = t.inv(); for ( int i = 1, j = 2, k ; i != size() ; j <<= 1 ) { k = j == n ? size() : j, v.dot(v, i), v.dit(i); for ( int l = 0 ; l != i ; l++ ) v[i + l] = v[l] - (*this)[l]; for ( int l = i ; l != k ; l++ ) v[l] -= (*this)[l]; fill(v.begin(), v.begin() + i, 0), v.dif(j), copy(y.begin(), y.begin() + i, u.begin()), u.dif(j), v.dot(u, j), v.dit(j); for ( int l = i ; l != k ; l++ ) x[l] = v[l] * c; if ( j == n ) i = size(); else for ( copy(x.begin(), x.begin() + j, z.begin()), z.dif(j), copy(z.begin(), z.begin() + j, v.begin()), z.dot(u, j), z.dit(j), fill(z.begin(), z.begin() + i, 0), z.dif(j), z.dot(u, j), z.dit(j) ; i != j ; i++ ) y[i] = -z[i]; } return x; }
	struct eval_tree
	{
		int n, m, s; vector < Polynomial > t;
		inline eval_tree(int o, const Polynomial &x) : n(max(2, get_len(o))), m(__lg(n)), s(x.size()), t(m + 1, Polynomial(n << 1)) { Polynomial z(n); for ( int i = 0 ; i != n ; i++ ) { MI w = i < s ? x[i] : 0; t[0][i << 1] = 1 - w, t[0][i << 1 | 1] = -1 - w; } for ( int d = 0, i = 2 ; d != m ; d++, i <<= 1 ) for ( int j = 0 ; j != ( n << 1 ) ; j += i << 1 ) { for ( int k = 0 ; k != i ; k++ ) z[k] = t[d][j + k] * t[d][j + i + k]; if ( d != m - 1 ) copy(z.begin(), z.begin() + i, t[d + 1].begin() + j), z.dit(i), z[0] -= 2, z.dif_rhalf(i), copy(z.begin(), z.begin() + i, t[d + 1].begin() + j + i); else z.dit(i), copy(z.begin(), z.begin() + i, t[d + 1].begin() + j), --t[d + 1][j], ++t[d + 1][i]; } }
		inline Polynomial eval(Polynomial x)const { if ( x.size() > n ) x = x.divmod(t[m]).second; Polynomial y(s), z(n), u = t[m]; x.resize(n << 1), rotate(x.begin(), x.end() - 1, x.end()), x.dif(n << 1), reverse(u.begin(), u.begin() + 1 + n), u = u.modxk(n).inv(); reverse(u.begin(), u.end()), u.resize(n << 1), u.dif(n << 1), u.dot(x, n << 1); for ( int d = m, i = n ; d-- ; i >>= 1 ) for ( int j = 0 ; j != ( n << 1 ) ; j += i << 1 ) { copy(u.begin() + i + j, u.begin() + ( i << 1 ) + j, z.begin()), z.dit_rhalf(i), z.dif(i), copy(z.begin(), z.begin() + i, u.begin() + i + j); for ( int k = 0 ; k != i ; k++ ) { MI w = u[j + k] - u[i + j + k]; u[j + k] = w * t[d][i + j + k], u[i + j + k] = w * t[d][j + k]; } } MI w = ivn[m + 1]; for ( int i = 0 ; i != s ; i++ ) y[i] = ( u[i << 1] - u[i << 1 | 1] ) * w; return y; }
		inline Polynomial inter(const Polynomial &y)const { Polynomial x = t[m], z(n), u(n << 1), v(n << 1); x.erase(x.begin(), x.begin() + n - s), x = eval(x.deriv()), linear_inv(s, x.begin(), v.begin()); for ( int i = 0 ; i != n ; i++ ) u[i << 1] = u[i << 1 | 1] = i < s ? y[i] * v[i] : 0; for ( int d = 0, i = 2 ; d != m ; d++, i <<= 1, swap(u, v) ) for ( int j = 0 ; j != ( n << 1 ) ; j += i << 1 ) { for ( int k = 0 ; k != i ; k++ ) z[k] = t[d][j + k] * u[j + i + k] + u[j + k] * t[d][j + i + k]; if ( d != m - 1 ) copy(z.begin(), z.begin() + i, v.begin() + j), z.dit(i), z.dif_rhalf(i), copy(z.begin(), z.begin() + i, v.begin() + j + i); else z.dit(i), copy(z.begin(), z.begin() + i, v.begin()); } return Polynomial(u.begin() + n - s, u.begin() + n); }
	};
	inline static void shift_poi_non_zero(const Polynomial &y, const MI &k, int m, typename vector < MI >::iterator &z) { int n = y.size(), o = get_len(n + m); Polynomial u(o), v(o), w(n + m), x(n + m); MI p = k - n; VALUES < MI >::extend(max(1, n - 1)); for ( int i = 0 ; i != n ; i++ ) u[i] = ( ( n - i ) & 1 ? y[i] : -y[i] ) * VALUES < MI >::ifac[i] * VALUES < MI >::ifac[n - 1 - i]; u.dif(o); w[0] = 1; for ( int i = 1 ; i != n + m ; i++ ) w[i] = w[i - 1] * ++p; linear_inv(n + m, w.begin(), x.begin()); for ( int i = 0 ; i != n + m - 1 ; i++ ) v[i] = w[i] * x[i + 1]; v.dif(o), u.dot(v, o), u.dit(o); for ( int i = 0 ; i != m ; i++ ) *z++ = u[i + n - 1] * w[i + n] * x[i]; }
	inline void comp_work(Polynomial &x, int o, int m, int n, const MI &w)const { if ( n == 1 ) { x.resize(m + 1), VALUES < MI >::extend(m + m - 1); MI p = VALUES < MI >::ifac[m - 1]; for ( int i = 0 ; i != m + 1 ; i++ ) x[m - i] = p * VALUES < MI >::fac[m - 1 + i] * VALUES < MI >::ifac[i], p *= w; x *= *this, x.erase(x.begin(), x.begin() + m), x.resize(o); return; } Polynomial y(o << 2), z(o << 1), u(o << 1); for ( int i = 0 ; i != m ; i++ ) copy(x.begin() + i * n, x.begin() + i * n + n, y.begin() + ( ( i * n ) << 1 )); y[o << 1] = 1, y.dif(o << 2); for ( int i = 0 ; i != ( o << 2 ) ; i += 2 ) z[i >> 1] = y[i] * y[i + 1]; z.dit(o << 1), --z[0]; for ( int i = 1 ; i != ( m << 1 ) ; i++ ) copy(z.begin() + i * n, z.begin() + i * n + ( n >> 1 ), z.begin() + i * ( n >> 1 )); z.resize(o), comp_work(z, o, m << 1, n >> 1, w); for ( int i = 0 ; i != ( m << 1 ) ; i++ ) copy(z.begin() + i * ( n >> 1 ), z.begin() + i * ( n >> 1 ) + ( n >> 1 ), u.begin() + i * n); u.dif(o << 1), x.resize(o << 2); for ( int i = 0 ; i != ( o << 2 ) ; i += 2 ) x[i] = y[i + 1] * u[i >> 1], x[i + 1] = y[i] * u[i >> 1]; x.dit(o << 2); for ( int i = 0 ; i != m ; i++ ) copy(x.begin() + ( ( ( i + m ) * n ) << 1 ), x.begin() + ( ( ( i + m ) * n ) << 1 ) + n, x.begin() + i * n); x.resize(o); }
public:
	using vector < MI >::vector, vector < MI >::begin, vector < MI >::end;
	inline int size()const { return (int)vector < MI >::size(); }
	inline Polynomial mulxk(int k)const { Polynomial x = *this; x.insert(x.begin(), k, 0); return x; }
	inline Polynomial divxk(int k)const { return Polynomial(begin() + min(k, size()), end()); }
	inline Polynomial modxk(int k)const { return Polynomial(begin(), begin() + min(k, size())); }
	inline void remove0() & { while ( size() && !vector < MI >::back() ) vector < MI >::pop_back(); }
	inline Polynomial mul_xi(const MI &x)const { Polynomial z = *this; if ( size() ) { MI y = 1; for ( int i = 1 ; i != size() ; i++ ) z[i] *= y *= x; } return z; }
	inline MI operator()(const MI &x)const { MI y = vector < MI >::back(); for ( int i = size() - 2 ; ~i ; i-- ) y = y * x + (*this)[i]; return y; }
	inline Polynomial operator-()const { Polynomial x = *this; for ( MI &i : x ) i = -i; return x; }
	inline Polynomial &operator+=(const MI &x) & { if ( !size() ) return *this = Polynomial(1,  x); (*this)[0] += x; return *this; }
	inline Polynomial &operator-=(const MI &x) & { if ( !size() ) return *this = Polynomial(1, -x); (*this)[0] -= x; return *this; }
	inline Polynomial &operator*=(const MI &x) & { for ( MI &i : *this ) i *= x; return *this; }
	inline Polynomial &operator/=(const MI &x) & { return *this *= x.inv(); }
	inline Polynomial &operator+=(const Polynomial &x) & { if ( size() < x.size() ) vector < MI >::resize(x.size()); for ( int i = 0 ; i != x.size() ; i++ ) (*this)[i] += x[i]; return *this; }
	inline Polynomial &operator-=(const Polynomial &x) & { if ( size() < x.size() ) vector < MI >::resize(x.size()); for ( int i = 0 ; i != x.size() ; i++ ) (*this)[i] -= x[i]; return *this; }
	inline Polynomial &operator*=(const Polynomial &x) & { return *this = *this * x; }
	inline friend Polynomial operator+(Polynomial x, const MI &y) { return x += y; }
	inline friend Polynomial operator-(Polynomial x, const MI &y) { return x -= y; }
	inline friend Polynomial operator*(Polynomial x, const MI &y) { return x *= y; }
	inline friend Polynomial operator+(const MI &x, Polynomial y) { return y += x; }
	inline friend Polynomial operator-(const MI &x, Polynomial y) { return -y + x; }
	inline friend Polynomial operator*(const MI &x, Polynomial y) { return y *= x; }
	inline friend Polynomial operator/(Polynomial x, const MI &y) { return x /= y; }
	inline friend Polynomial operator+(Polynomial x, const Polynomial &y) { return x += y; }
	inline friend Polynomial operator-(Polynomial x, const Polynomial &y) { return x -= y; }
	inline friend Polynomial operator*(const Polynomial &x, const Polynomial &y) { if ( min(x.size(), y.size()) > 8 && max(x.size(), y.size()) > 128 ) return mul_big(x, y); Polynomial z(max(0, x.size() + y.size() - 1)); for ( int i = 0 ; i != x.size() ; i++ ) for ( int j = 0 ; j != y.size() ; j++ ) z[i + j] += x[i] * y[j]; return z; }
	inline Polynomial deriv()const { Polynomial x(size()); deriv(size(), x.begin()), x.pop_back(); return x; }
	inline Polynomial integ()const { Polynomial x(size() + 1); integ(size() + 1, x.begin()); return x; }
	inline Polynomial inv()const { int n = get_len(size()); Polynomial x(size()), y(n), z(n); x[0] = (*this)[0].inv(); for ( int i = 1, j = 2, k ; i != size() ; j <<= 1 ) for ( k = j == n ? size() : j, copy(begin(), begin() + k, y.begin()), y.dif(j), copy(x.begin(), x.begin() + i, z.begin()), z.dif(j), y.dot(z, j), y.dit(j), fill(y.begin(), y.begin() + i, 0), y.dif(j), y.dot(z, j), y.dit(j) ; i != k ; i++ ) x[i] = -y[i]; return x; }
	inline Polynomial exp()const { if ( size() == 1 ) return Polynomial(1, 1); int n = get_len(size()); Polynomial x(size()), y(size()), z(n), u(n), v(n); x[0] = y[0] = u[0] = u[1] = 1; for ( int i = 1, j = 2, k ; i != size() ; j <<= 1 ) { k = j == n ? size() : j, deriv(i, z.begin()), z.dif(i), z.dot(u, i), z.dit(i), z[i - 1] = -z[i - 1], x.deriv(i, z.begin() + i); for ( int l = 0 ; l != i - 1 ; l++ ) z[i + l] -= z[l]; fill(z.begin(), z.begin() + i - 1, 0), z.dif(j), copy(y.begin(), y.begin() + i, v.begin()), v.dif(j), z.dot(v, j); z.dit(j), z.integ(j, z.begin()), fill(z.begin(), z.begin() + i, 0); for ( int l = i ; l != k ; l++ ) z[l] -= (*this)[l]; z.dif(j), z.dot(u, j), z.dit(j); for ( int l = i ; l != k ; l++ ) x[l] = -z[l]; if ( j == n ) i = size(); else { copy(x.begin(), x.begin() + j, u.begin()), u.dif(j + j); for ( copy(u.begin(), u.begin() + j, z.begin()), z.dot(v, j), z.dit(j), fill(z.begin(), z.begin() + i, 0), z.dif(j), z.dot(v, j), z.dit(j) ; i != j ; i++ ) y[i] = -z[i]; } } return x; }
	inline Polynomial ln()const { Polynomial x(size()); deriv(size(), x.begin()), x *= inv(), x.resize(size()), x.integ(size(), x.begin()); return x; }
	inline Polynomial pow(int k_chkmn_sz, int k_mod_p, int k_mod_phi_p)const { if ( !k_chkmn_sz ) { Polynomial x(size()); x[0] = 1; return x; } int i = 0; while ( i != size() && !(*this)[i] ) i++; return (long long)i * k_chkmn_sz >= size() ? Polynomial(size()) : i ? divxk(i).pow_non_zero(size() - i * k_chkmn_sz, k_mod_p, k_mod_phi_p).mulxk(i * k_chkmn_sz) : pow_non_zero(size(), k_mod_p, k_mod_phi_p); }
	template < class T > inline Polynomial pow(T x)const { return pow(x < size() ? x : size(), x % MI::mod(), x % ( MI::mod() - 1 )); }
	inline pair < bool, Polynomial > sqrt()const { int i = 0; while ( i != size() && !(*this)[i] ) i++; if ( i == size() ) return make_pair(true, Polynomial(size())); if ( i & 1 ) return make_pair(false, Polynomial()); auto [o, t] = cipolla((*this)[i]); if ( !o ) return make_pair(false, Polynomial()); if ( i ) { Polynomial x(begin() + i, end()); x.insert(x.end(), i >> 1, 0); return make_pair(true, x.sqrt_non_zero(t).mulxk(i >> 1)); } return make_pair(true, sqrt_non_zero(t)); }
	inline Polynomial div(const Polynomial &x)const { if ( x.size() > size() ) return Polynomial(); int n = size() - x.size() + 1; Polynomial y(n), z(n); reverse_copy(begin() + x.size() - 1, end(), y.begin()), reverse_copy(x.begin() + max(0, x.size() - n), x.end(), z.begin()), y = ( y * z.inv() ).modxk(n), reverse(y.begin(), y.end()); return y; }
	inline pair < Polynomial, Polynomial > divmod(const Polynomial &x)const { if ( x.size() > size() ) return make_pair(Polynomial(), *this); Polynomial y = div(x); return make_pair(y, modxk(x.size() - 1) - ( x.modxk(x.size() - 1) * y.modxk(x.size() - 1) ).modxk(x.size() - 1)); }
	inline Polynomial eval(const Polynomial &x)const { return eval_tree(max(size(), x.size()), x).eval(*this); }
	inline static Polynomial inter(const Polynomial &x, const Polynomial &y) { return eval_tree(x.size(), x).inter(y); }
	inline Polynomial chirpz_eval(int m, const MI &x)const { Polynomial y(m); if ( !x ) { y[0] = (*this)(1); if ( m > 1 ) fill(y.begin() + 1, y.end(), (*this)[0]); return y; } int n = size() + m - 1, o = get_len(n); Polynomial u(o), v(n), z = *this; MI w = x.inv(), p = u[0] = 1, q = v[0] = 1; for ( int i = 1 ; i != n ; i++ ) u[i] = u[i - 1] * p, v[i] = v[i - 1] * q, p *= x, q *= w; z.dot(v, size()), reverse(z.begin(), z.end()), z.resize(o), z.dif(o), u.dif(o), z.dot(u, o), z.dit(o), z = Polynomial(z.begin() + size() - 1, z.begin() + size() - 1 + m), z.dot(v, m); return z; }
	inline static Polynomial chirpz_inter(const MI &x, const Polynomial &y) { int n = y.size(), m = get_len(n << 1); if ( n < 2 ) return y; Polynomial u(( n << 1 ) - 1), v(n), z(m), r(n), s(m); MI w = x.inv(), p = u[0] = z[0] = 1, q = v[0] = 1; for ( int i = 1 ; i != n ; i++ ) u[i] = u[i - 1] * p, v[i] = v[i - 1] * q, p *= x, q *= w, z[i] = z[i - 1] * ( 1 - p ); q = z[n - 1] * ( 1 - p * x ); for ( int i = n ; i != ( n << 1 ) - 1 ; i++ ) u[i] = u[i - 1] * p, p *= x; linear_inv(n, z.begin(), r.begin()); for ( int i = 0 ; i != n ; i++ ) z[i] = ( i & 1 ? -y[i] : y[i] ) * r[i] * r[n - 1 - i] * u[n - 1 - i] * v[i] * v[n - 1]; reverse(z.begin(), z.begin() + n), z.dif(m), copy(u.begin(), u.end(), s.begin()), s.dif(m), z.dot(s, m), z.dit(m), z.erase(z.begin(), z.begin() + n - 1), z.dot(v, n), z[n + 1] = 0, z.resize(m), z.dif(m), s[0] = 1; for ( int i = 1 ; i != n ; i++ ) s[i] = ( i & 1 ? -q : q ) * r[i] * r[n - i] * u[i]; fill(s.begin() + n, s.end(), 0), s.dif(m), z.dot(s, m), z.dit(m), z.resize(n), reverse(z.begin(), z.end()); return z; }
	inline Polynomial shift(const MI &k) & { if ( !k ) return *this; int n = size(), m = get_len(n << 1); Polynomial y(m), z(m); VALUES < MI >::extend(max(1, n - 1)); for ( int i = 0 ; i != n ; i++ ) y[i] = (*this)[i] * VALUES < MI >::fac[i]; y.dif(m), z[n - 1] = 1; for ( int i = n - 1 ; i ; i-- ) z[i - 1] = z[i] * k * VALUES < MI >::inv[n - i]; z.dif(m), y.dot(z, m), y.dit(m), y = Polynomial(y.begin() + n - 1, y.begin() + ( n << 1 ) - 1); for ( int i = 0 ; i != n ; i++ ) y[i] *= VALUES < MI >::ifac[i]; return y; }
	inline static Polynomial shift_poi(const Polynomial &y, MI k, int m) { Polynomial x(m); auto z = x.begin(); int p = k.val(), o = MI::mod() - p; if ( o <= m ) shift_poi_non_zero(y, k, o, z), m -= o, k = p = 0; if ( m && p < y.size() ) o = min(y.size(), p + m), copy(y.begin() + p, y.begin() + o, z), z += o - p, m -= o - p, k = y.size(); if ( m ) shift_poi_non_zero(y, k, m, z); return x; }
	inline Polynomial comp(const Polynomial &x)const { int n = get_len(size()); Polynomial y(n); for ( int i = 0 ; i != x.size() ; i++ ) y[i] = -x[i]; comp_work(y, n, 1, n, x[0]), y.resize(size()); return y; }
	inline Polynomial comp_inv()const { constexpr MI c = MI(2).inv(); int n = get_len(size() << 1), m, o, j = 1; const Polynomial &irt = *get_rt(n).second; Polynomial x(n), y(n), u(n << 1), v(n << 1); MI w = (*this)[1].inv(), p = -1; for ( int i = 1 ; i != size() ; i++ ) p *= w, x[i] = (*this)[i] * p; y[0] = 1; for ( int i = size() ; i != 1 ; i = o, j <<= 1 ) { o = ( i + 1 ) >> 1, m = get_len(( i * j ) << 2), fill(u.begin(), u.begin() + m, 0), fill(v.begin(), v.begin() + m, 0); for ( int k = 0 ; k != j ; k++ ) copy(x.begin() + i * k, x.begin() + i * k + i, u.begin() + ( ( i * k ) << 1 )), copy(y.begin() + i * k, y.begin() + i * k + i, v.begin() + ( ( i * k ) << 1 )); u[( i * j ) << 1] = 1, u.dif(m), v.dif(m), x.resize(m >> 1), y.resize(m >> 1); for ( int k = 0 ; k != m ; k += 2 ) x[k >> 1] = u[k] * u[k + 1]; if ( i & 1 ) for ( int k = 0 ; k != m ; k += 2 ) y[k >> 1] = ( u[k + 1] * v[k] + u[k] * v[k + 1] ) * c; else for ( int k = 0 ; k != m ; k += 2 ) y[k >> 1] = ( u[k + 1] * v[k] - u[k] * v[k + 1] ) * irt[k >> 1] * c; x.dit(m >> 1), y.dit(m >> 1); if ( ( ( i * j ) << 2 ) == m ) --x[0]; for ( int k = 1 ; k != ( j << 1 ) ; k++ ) copy(x.begin() + i * k, x.begin() + i * k + o, x.begin() + o * k), copy(y.begin() + i * k, y.begin() + i * k + o, y.begin() + o * k); } y.resize(j * o), reverse(y.begin(), y.end()), m = size(), y.resize(m), VALUES < MI >::extend(m - 1); for ( int i = 1 ; i != m ; i++ ) y[i] *= ( m - 1 ) * VALUES < MI >::inv[i]; reverse(y.begin(), y.end()), y = y.pow_one(m - 1, ( -VALUES < MI >::inv[m - 1] ).val()) * w, y.insert(y.begin(), 0); return y; }
#ifdef USE_FastIO
	inline void read() & { for ( MI &i : *this ) ::read(i); }
	inline void write()const { for ( int i = 0 ; i != size() ; i++ ) { if ( i ) ::write(' '); ::write((*this)[i]); } }
#endif
};	using Poly = Polynomial < MI >;
int _, n, m, p, o; MI a[200009], b[200009], c[200009], d[200009], e[200009], f[200009];
Poly res, qwq;
struct M
{
	Poly a[3][3];
	inline M operator*(const M &o)const
	{
		M z;
		For(i, 0, 2) For(k, 0, 2) if ( a[i][k].size() ) For(j, 0, 2) z.a[i][j] += a[i][k] * o.a[k][j];
		return z;
	}
	inline M &operator*=(const M &o) { return *this = *this * o; }
}	bs;
inline M calc(int l, int r)
{
	if ( l != r ) { int md = ( l + r ) >> 1; return calc(md + 1, r) * calc(l, md); }
	M z; z.a[0][0] = { 1, -c[l] }, z.a[1][0] = { 0, 0, -a[l] * d[l + 1] },
	z.a[0][1] = { 1 }, z.a[0][2] = { f[l] }, z.a[2][2] = { 0, a[l] }; return z;
}
inline pair < Poly, Poly > calc2(int l, int r)
{
	if ( l == r ) return pair(Poly({ 1, b[l] }), Poly({ e[l] }));
	int md = ( l + r ) >> 1; auto [lf, lg] = calc2(l, md); auto [rf, rg] = calc2(md + 1, r);
	return pair(lf * rf, lg.mulxk(r - md) + lf * rg);
}
inline MI slv(Poly f, Poly g, int n)
{
	for ( ; n ; n >>= 1 )
	{
		Poly h = g; for ( int i = 1 ; i < h.size() ; i += 2 ) h[i] = -h[i];
		Poly ff = f * h, gg = g * h; f.clear(), g.clear();
		for ( int i = n & 1 ; i < ff.size() ; i += 2 ) f.emplace_back(ff[i]);
		for ( int i =     0 ; i < gg.size() ; i += 2 ) g.emplace_back(gg[i]);
	}
	return f[0];
}
int main()
{
	read(_, n, m, p);
	For(i, 0, m - 1) read(a[i]);
	For(i, 0, n - 1) read(b[i]);
	For(i, 0, m    ) read(c[i]);
	For(i, 1, m    ) read(d[i]);
	For(i, 0, n    ) read(e[i]);
	For(i, 0, m    ) read(f[i]);
	bs.a[0][0] = { 1 }, bs *= calc(0, m);
	return println(slv(bs.a[0][2] * calc2(0, n).second, bs.a[0][0], n)), 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 61ms
memory: 6688kb

input:

1 5000 5000 998244353
121811167 379924090 361631583 174189813 559424693 889647308 193102812 469875055 32237660 96186933 624360154 404866088 859165067 748410791 926700198 368632735 476560636 798138824 17883437 712872225 448819400 33122704 572152288 627010263 336722521 775918346 465722630 681224329 60...

output:

698779876

result:

ok single line: '698779876'

Test #2:

score: 3
Accepted
time: 64ms
memory: 6564kb

input:

1 4999 4919 998244353
380477138 780960797 787883474 484131625 121182688 933501638 947532778 257948759 108946829 468475856 5564419 677097370 766236309 678789875 533319074 885579006 769287005 710724535 260200529 599758240 380918586 216469888 78561030 325936496 189815268 268769489 232850763 937923688 9...

output:

475720945

result:

ok single line: '475720945'

Test #3:

score: 3
Accepted
time: 65ms
memory: 8552kb

input:

1 4995 4997 998244353
267305461 291432119 107593765 530653184 893921215 15414240 991509792 601027626 313017049 827685069 650321853 385956762 140661695 303322469 142427516 910941336 265371405 731125266 512689773 723594553 552396112 379799950 43662480 666390792 938399292 144960568 817187890 428532063 ...

output:

568578871

result:

ok single line: '568578871'

Subtask #2:

score: 5
Accepted

Test #4:

score: 5
Accepted
time: 3937ms
memory: 46844kb

input:

2 200000 200000 998244353
903563506 433239074 632684755 970178226 831892753 932120646 157832416 517140217 296101978 998244343 850946564 2367119 708278025 376919151 752106478 994362560 806760771 672325565 9 958330492 343658496 153627310 330649130 983441587 829707074 135609242 706388812 325297147 4972...

output:

108905794

result:

ok single line: '108905794'

Test #5:

score: 5
Accepted
time: 3896ms
memory: 42624kb

input:

2 199910 194100 998244353
587911377 573048398 832688590 809066619 524442920 218487661 649170169 8 150333233 204150153 800582862 464558080 291668841 361834956 998244344 998244349 806341682 775965963 459031329 867640103 425129750 7 998244343 274941091 809744915 443910210 859200100 998244350 725497297 ...

output:

597176160

result:

ok single line: '597176160'

Test #6:

score: 5
Accepted
time: 3904ms
memory: 45912kb

input:

2 150810 200000 998244353
288330007 105173193 991831123 698131025 301828280 273289882 387551340 542768677 115972971 425381688 811911805 962095963 566257196 435928108 337873530 109252306 933737641 967531573 29209951 787608009 497111219 315932660 878605444 903737754 260092904 447237039 37123388 594371...

output:

78643368

result:

ok single line: '78643368'

Subtask #3:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 3933ms
memory: 47928kb

input:

3 200000 200000 998244353
493605813 622283646 579332647 528537957 211102509 336893985 106292723 166710741 443808575 180234697 744331593 252016663 693453924 975202110 519712748 174749950 250990381 584528219 619047448 641168296 914918741 785005029 433175528 400547992 845115512 278159630 227330862 6407...

output:

144815343

result:

ok single line: '144815343'

Test #8:

score: 8
Accepted
time: 3928ms
memory: 44444kb

input:

3 200000 199996 998244353
742 699221406 301 364485093 804 294 873 282584633 204 882 889 438104412 349 737559671 152908512 490 206 11 613 175 155 659898955 983 206756334 273919067 843 898 359154783 360 612 201572138 207697004 396 482 136 361 339 831490112 279585283 516749439 318 198386232 69807322 72...

output:

758876599

result:

ok single line: '758876599'

Test #9:

score: 8
Accepted
time: 2933ms
memory: 31420kb

input:

3 1 200000 998244353
734 796 543458399 920002767 990425370 338 107321680 90089647 557777271 434728777 503 709 616 850 448 884 143526194 299065437 45361809 666577969 923 492965257 850 229 769 183867189 675 463141085 791 281 718 763 240353338 711 671313626 203252664 888743426 450 223 446 542052402 565...

output:

53421494

result:

ok single line: '53421494'

Test #10:

score: 8
Accepted
time: 228ms
memory: 17980kb

input:

3 200000 1 998244353
277786488
264242127 2 319061241 5 8 2 1 51038317 673171629 267552091 920379441 5 880796442 618282833 514210179 9 8 67744028 9 1 691195881 92394487 719900388 638641507 5 663287704 4 579997250 985749664 984980853 4 519857232 4 735668111 3 7 360023171 7 7 234677046 359140782 8 5227...

output:

140453572

result:

ok single line: '140453572'

Subtask #4:

score: 8
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 8
Accepted
time: 3942ms
memory: 48152kb

input:

4 200000 200000 998244353
199752876 397435299 166254444 779278347 182416898 901682085 69090988 738092954 712758505 681482091 950425501 897402866 870967623 36849705 515322829 172446310 900429861 34423824 785446470 553333476 938968413 86270822 973639556 431435054 741273084 677434142 222677171 61928101...

output:

65201275

result:

ok single line: '65201275'

Test #12:

score: 8
Accepted
time: 288ms
memory: 19096kb

input:

4 199996 2000 998244353
865 499 31904732 259114092 967550739 255 785 143545371 699 573 216 789 553653892 329548961 451423632 886 741679575 78720133 464611720 972 242 869 294933191 351 788310280 697 861990346 731 734 701 407 401383418 835 189335197 668 758851074 250436747 962105421 562203389 11011899...

output:

85153184

result:

ok single line: '85153184'

Test #13:

score: 8
Accepted
time: 3592ms
memory: 32688kb

input:

4 40000 190000 998244353
953 586890334 906 161 524210942 327745937 100 231 970 63891350 28 370040454 628796638 275 239621470 708518643 995 351 376514813 814869235 66 742 561 483786281 5379525 603 608 274128226 256 844 662 445297819 123782163 920 957935561 621339377 26129412 763585646 451 911 5350051...

output:

99807982

result:

ok single line: '99807982'

Subtask #5:

score: 5
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #14:

score: 5
Accepted
time: 3938ms
memory: 49552kb

input:

5 200000 200000 998244353
357 270 635 81 18806969 807 433 242 242 154 347094190 96 953 893447557 497 265754515 220901127 205 958 488 212420388 457 799989458 726134433 547661079 946786926 891 955400819 664511484 701 155 791 4 845 954462573 536216065 136 54 251 481 584310172 389122260 34 527707943 300...

output:

366841924

result:

ok single line: '366841924'

Test #15:

score: 5
Accepted
time: 3899ms
memory: 44212kb

input:

5 199999 190000 998244353
930048626 861740403 534792638 856 178 908419417 742 685 40557520 132 779489457 792 468990716 153965694 395450527 688 398541680 651 789664707 703746126 579 588989999 936017101 652728925 314526790 297 962 771009949 626 192587923 377598397 654 459 187173523 857466261 567 73215...

output:

755407887

result:

ok single line: '755407887'

Subtask #6:

score: 15
Accepted

Test #16:

score: 15
Accepted
time: 3976ms
memory: 49648kb

input:

6 200000 200000 998244353
401806059 107033001 530043262 862506025 263940497 48524969 232075248 849682830 420464058 64900333 394986647 954304290 957385577 86269798 579307969 896967626 230611640 527078096 39773429 402432856 495204529 272090833 100466767 562115973 196636941 736050044 580541546 81233872...

output:

562220526

result:

ok single line: '562220526'

Test #17:

score: 15
Accepted
time: 3849ms
memory: 43956kb

input:

6 190000 180000 998244353
331419431 585273774 326021268 911984877 504951700 663 667 967180428 535316997 888573230 112066317 286249963 593 994 230 367194808 906865758 946973557 921 1 302880572 377068830 444057418 953 1000 946 906 274661283 90 345429012 719 547222223 806 856 911 970 110923264 26390908...

output:

467130256

result:

ok single line: '467130256'

Subtask #7:

score: 16
Accepted

Dependency #1:

100%
Accepted

Test #18:

score: 16
Accepted
time: 589ms
memory: 23516kb

input:

7 200000 20000 998244353
869285118 18064361 457499026 292378234 45941854 157946840 586178769 392380503 830348035 141601898 591275235 100919004 399285791 115436998 586990272 287976693 795031696 836945332 895793688 432697639 828280269 714678411 137052352 516420393 730089484 911809696 350536206 8175289...

output:

809172057

result:

ok single line: '809172057'

Test #19:

score: 16
Accepted
time: 588ms
memory: 21568kb

input:

7 200000 19810 998244353
828902663 612852451 425506197 233025854 319333441 952074173 717042023 949076193 83452305 763673071 41376007 272593034 356441893 361994505 185035237 266625028 550156798 775373755 727044232 359307823 648601627 384158945 313651668 746883203 321976362 307448064 64684150 4186580 ...

output:

560874322

result:

ok single line: '560874322'

Test #20:

score: 16
Accepted
time: 123ms
memory: 8940kb

input:

7 1000 9996 998244353
233393388 143 900 282 622 588 259300855 18722608 81440606 388097181 802 119 117027019 445 244 220 321165142 193445923 884359675 276 671093341 934763449 844222944 251 190039071 208 521 758 621 722 370522729 731 968984566 656850987 42380471 798 292 324 609 606 400 210 785 816 863...

output:

964458165

result:

ok single line: '964458165'

Test #21:

score: 16
Accepted
time: 408ms
memory: 20588kb

input:

7 200000 9919 998244353
127286538 946789972 892201793 335420070 263695484 170118086 108765927 699100677 678757948 552873985 565640470 952666657 645394702 560901257 95959026 804657734 83330667 185533959 520165719 246753496 769277586 697870667 659358703 318912135 658640680 810790915 492140504 62924551...

output:

269104705

result:

ok single line: '269104705'

Subtask #8:

score: 16
Accepted

Dependency #6:

100%
Accepted

Test #22:

score: 16
Accepted
time: 3961ms
memory: 49752kb

input:

8 200000 200000 998244353
476657058 608590028 176876078 188969399 496243267 200861994 525765121 157833667 112147905 888494665 86463084 3240780 881100059 209383369 616595337 943058640 18341235 731579551 223351112 539615902 3395185 187153519 82693410 67612463 680802074 217978817 9323483 678602864 3453...

output:

474782296

result:

ok single line: '474782296'

Test #23:

score: 16
Accepted
time: 3809ms
memory: 44100kb

input:

8 199997 170000 998244353
505360294 8 975 463 168746690 820247591 120436643 410462769 12959063 167531115 300 621 191294387 22 410 679 782371812 449088425 162807445 835 149638206 858 65 581 12 959 310569501 119222808 476951257 403 646 312711442 530 858755892 671888747 458 412 247 114 230 422058417 22...

output:

763867893

result:

ok single line: '763867893'

Test #24:

score: 16
Accepted
time: 3987ms
memory: 45912kb

input:

8 190000 199996 998244353
749 721817394 27 645 439406479 108090145 550371723 420419950 461 779 412458565 731555989 681 322 304994251 402 74 874226263 674 346 114 126 838 687147645 321419751 420 198508289 341 807392775 960572742 60398571 708697994 880 573 77 521 699 200251635 886 5466957 908 569 96 3...

output:

446047127

result:

ok single line: '446047127'

Test #25:

score: 16
Accepted
time: 3973ms
memory: 48512kb

input:

8 200000 200000 998244353
673 387 272 59 192173777 764 170183158 746432263 207 267 390 400 524 13 968340991 557741817 104800071 932539161 695618609 496396588 645 847701916 398 59229077 279708783 178114129 477 170 819671340 467175001 430861597 292163679 405 189 67855913 794507178 990487692 197409331 ...

output:

927461446

result:

ok single line: '927461446'

Test #26:

score: 16
Accepted
time: 3909ms
memory: 43372kb

input:

8 199999 190000 998244353
190706062 888680627 83397214 6 494083839 9 5 71812818 661044051 2 851345196 4 5 9 1 655271434 10 9 4 9 6 103209989 4 9 976030578 655935000 623342477 1 206077679 7 10 8 6 9 7 298401605 892975523 8 267432364 53188239 70291367 142791981 531492153 5 5 672326478 962867181 7 8679...

output:

170212793

result:

ok single line: '170212793'

Subtask #9:

score: 9
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Test #27:

score: 9
Accepted
time: 4006ms
memory: 51136kb

input:

9 200000 200000 998244353
886612651 387277498 222689570 149684757 801547216 39958935 61994466 279732876 910669986 673110448 242227789 281852762 124220159 702603904 242726522 761430846 261708466 14196264 198147684 71130471 96539799 886809411 454014179 438893638 437708905 533400975 385272485 461115839...

output:

653639881

result:

ok single line: '653639881'

Test #28:

score: 9
Accepted
time: 4018ms
memory: 47324kb

input:

9 199000 199990 998244353
929566148 214291485 906544066 298915999 689760706 271699591 482768561 898907851 81802523 554994538 134064180 501518029 641765774 423311402 134116703 391491198 791826482 649073874 696499611 279773162 697654068 669577487 356335067 571197676 194446272 321902950 667228720 31535...

output:

790075420

result:

ok single line: '790075420'

Test #29:

score: 9
Accepted
time: 4001ms
memory: 48452kb

input:

9 199997 199992 998244353
131543484 131291289 593343835 383688404 614251659 28042347 794277226 944988995 90198501 227326291 300776651 558115109 476201534 78151684 536357291 264046767 946044015 398569226 176484997 28421208 648281543 235639450 776266080 616245182 623867397 523564530 864964454 40378887...

output:

483850208

result:

ok single line: '483850208'

Test #30:

score: 9
Accepted
time: 4020ms
memory: 47228kb

input:

9 200000 200000 998244353
745599216 859346500 634928637 690647766 10273176 338563878 7698219 743763863 718373315 189069600 879813230 122401277 976417985 98413473 210957679 595554610 710895015 273465866 711019517 695658890 236226376 740332195 711573064 388099079 794053021 135899585 924688794 41508470...

output:

503071975

result:

ok single line: '503071975'

Test #31:

score: 9
Accepted
time: 4007ms
memory: 50984kb

input:

9 200000 200000 998244353
998244284 998243397 998243865 998244160 998243619 998244095 998243530 998244257 998243534 998243564 998243583 998244164 998244147 998244000 998243730 998243737 998243628 998243528 998243829 998244222 998243852 998244137 998243563 998244120 998244207 998243409 998243839 9982...

output:

359574540

result:

ok single line: '359574540'

Subtask #10:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #32:

score: 0
Wrong Answer
time: 1815ms
memory: 28616kb

input:

10 100000 100000 856853193
287061150 779504426 21691247 494814415 381655016 536089292 240188530 458291018 332927950 428352746 351529999 258956585 651084688 268523951 338285674 719419445 165275422 367200319 35308342 563282834 763880581 117326555 284413760 207571906 703023023 622478929 212959189 34094...

output:

756256154

result:

wrong answer 1st lines differ - expected: '304611769', found: '756256154'