QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321294#2068. Fast as RyserhashiryoAC ✓923ms42316kbC++1728.7kb2024-02-04 13:08:552024-02-04 13:08:55

Judging History

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

  • [2024-02-04 13:08:55]
  • 评测
  • 测评结果:AC
  • 用时:923ms
  • 内存:42316kb
  • [2024-02-04 13:08:55]
  • 提交

answer

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// clang-format off
std::ostream&operator<<(std::ostream&os,std::int8_t x){return os<<(int)x;}
std::ostream&operator<<(std::ostream&os,std::uint8_t x){return os<<(int)x;}
std::ostream&operator<<(std::ostream&os,const __int128_t &v){if(!v)os<<"0";__int128_t tmp=v<0?(os<<"-",-v):v;std::string s;while(tmp)s+='0'+(tmp%10),tmp/=10;return std::reverse(s.begin(),s.end()),os<<s;}
std::ostream&operator<<(std::ostream&os,const __uint128_t &v){if(!v)os<<"0";__uint128_t tmp=v;std::string s;while(tmp)s+='0'+(tmp%10),tmp/=10;return std::reverse(s.begin(),s.end()),os<<s;}
#define checkpoint() (void(0))
#define debug(...) (void(0))
#define debugArray(x,n) (void(0))
#define debugMatrix(x,h,w) (void(0))
// clang-format on
#include <type_traits>
template <class Int> constexpr inline Int mod_inv(Int a, Int mod) {
 static_assert(std::is_signed_v<Int>);
 Int x= 1, y= 0, b= mod;
 for (Int q= 0, z= 0; b;) z= x, x= y, y= z - y * (q= a / b), z= a, a= b, b= z - b * q;
 return assert(a == 1), x < 0 ? mod - (-x) % mod : x % mod;
}
namespace math_internal {
using namespace std;
using u8= unsigned char;
using u32= unsigned;
using i64= long long;
using u64= unsigned long long;
using u128= __uint128_t;
#define CE constexpr
#define IL inline
#define NORM \
 if (n >= mod) n-= mod; \
 return n
#define PLUS(U, M) \
 CE IL U plus(U l, U r) const { return l+= r, l < (M) ? l : l - (M); }
#define DIFF(U, C, M) \
 CE IL U diff(U l, U r) const { return l-= r, l >> C ? l + (M) : l; }
#define SGN(U) \
 static CE IL U set(U n) { return n; } \
 static CE IL U get(U n) { return n; } \
 static CE IL U norm(U n) { return n; }
template <class u_t, class du_t, u8 B, u8 A> struct MP_Mo {
 u_t mod;
 CE MP_Mo(): mod(0), iv(0), r2(0) {}
 CE MP_Mo(u_t m): mod(m), iv(inv(m)), r2(-du_t(mod) % mod) {}
 CE IL u_t mul(u_t l, u_t r) const { return reduce(du_t(l) * r); }
 PLUS(u_t, mod << 1)
 DIFF(u_t, A, mod << 1)
 CE IL u_t set(u_t n) const { return mul(n, r2); }
 CE IL u_t get(u_t n) const {
  n= reduce(n);
  NORM;
 }
 CE IL u_t norm(u_t n) const { NORM; }
private:
 u_t iv, r2;
 static CE u_t inv(u_t n, int e= 6, u_t x= 1) { return e ? inv(n, e - 1, x * (2 - x * n)) : x; }
 CE IL u_t reduce(const du_t &w) const { return u_t(w >> B) + mod - ((du_t(u_t(w) * iv) * mod) >> B); }
};
struct MP_Na {
 u32 mod;
 CE MP_Na(): mod(0){};
 CE MP_Na(u32 m): mod(m) {}
 CE IL u32 mul(u32 l, u32 r) const { return u64(l) * r % mod; }
 PLUS(u32, mod) DIFF(u32, 31, mod) SGN(u32)
};
struct MP_Br {  // mod < 2^31
 u32 mod;
 CE MP_Br(): mod(0), s(0), x(0) {}
 CE MP_Br(u32 m): mod(m), s(95 - __builtin_clz(m - 1)), x(((u128(1) << s) + m - 1) / m) {}
 CE IL u32 mul(u32 l, u32 r) const { return rem(u64(l) * r); }
 PLUS(u32, mod) DIFF(u32, 31, mod) SGN(u32) private: u8 s;
 u64 x;
 CE IL u64 quo(u64 n) const { return (u128(x) * n) >> s; }
 CE IL u32 rem(u64 n) const { return n - quo(n) * mod; }
};
struct MP_Br2 {  // 2^20 < mod <= 2^41
 u64 mod;
 CE MP_Br2(): mod(0), x(0) {}
 CE MP_Br2(u64 m): mod(m), x((u128(1) << 84) / m) {}
 CE IL u64 mul(u64 l, u64 r) const { return rem(u128(l) * r); }
 PLUS(u64, mod << 1)
 DIFF(u64, 63, mod << 1)
 static CE IL u64 set(u64 n) { return n; }
 CE IL u64 get(u64 n) const { NORM; }
 CE IL u64 norm(u64 n) const { NORM; }
private:
 u64 x;
 CE IL u128 quo(const u128 &n) const { return (n * x) >> 84; }
 CE IL u64 rem(const u128 &n) const { return n - quo(n) * mod; }
};
struct MP_D2B1 {
 u8 s;
 u64 mod, d, v;
 CE MP_D2B1(): s(0), mod(0), d(0), v(0) {}
 CE MP_D2B1(u64 m): s(__builtin_clzll(m)), mod(m), d(m << s), v(u128(-1) / d) {}
 CE IL u64 mul(u64 l, u64 r) const { return rem((u128(l) * r) << s) >> s; }
 PLUS(u64, mod) DIFF(u64, 63, mod) SGN(u64) private: CE IL u64 rem(const u128 &u) const {
  u128 q= (u >> 64) * v + u;
  u64 r= u64(u) - (q >> 64) * d - d;
  if (r > u64(q)) r+= d;
  if (r >= d) r-= d;
  return r;
 }
};
template <class u_t, class MP> CE u_t pow(u_t x, u64 k, const MP &md) {
 for (u_t ret= md.set(1);; x= md.mul(x, x))
  if (k & 1 ? ret= md.mul(ret, x) : 0; !(k>>= 1)) return ret;
}
#undef NORM
#undef PLUS
#undef DIFF
#undef SGN
#undef CE
}
namespace math_internal {
struct m_b {};
struct s_b: m_b {};
}
template <class mod_t> constexpr bool is_modint_v= std::is_base_of_v<math_internal::m_b, mod_t>;
template <class mod_t> constexpr bool is_staticmodint_v= std::is_base_of_v<math_internal::s_b, mod_t>;
namespace math_internal {
#define CE constexpr
template <class MP, u64 MOD> struct SB: s_b {
protected:
 static CE MP md= MP(MOD);
};
template <class Int, class U, class B> struct MInt: public B {
 using Uint= U;
 static CE inline auto mod() { return B::md.mod; }
 CE MInt(): x(0) {}
 template <class T, typename= enable_if_t<is_modint_v<T> && !is_same_v<T, MInt>>> CE MInt(T v): x(B::md.set(v.val() % B::md.mod)) {}
 CE MInt(__int128_t n): x(B::md.set((n < 0 ? ((n= (-n) % B::md.mod) ? B::md.mod - n : n) : n % B::md.mod))) {}
 CE MInt operator-() const { return MInt() - *this; }
#define FUNC(name, op) \
 CE MInt name const { \
  MInt ret; \
  return ret.x= op, ret; \
 }
 FUNC(operator+(const MInt & r), B::md.plus(x, r.x))
 FUNC(operator-(const MInt & r), B::md.diff(x, r.x))
 FUNC(operator*(const MInt & r), B::md.mul(x, r.x))
 FUNC(pow(u64 k), math_internal::pow(x, k, B::md))
#undef FUNC
 CE MInt operator/(const MInt& r) const { return *this * r.inv(); }
 CE MInt& operator+=(const MInt& r) { return *this= *this + r; }
 CE MInt& operator-=(const MInt& r) { return *this= *this - r; }
 CE MInt& operator*=(const MInt& r) { return *this= *this * r; }
 CE MInt& operator/=(const MInt& r) { return *this= *this / r; }
 CE bool operator==(const MInt& r) const { return B::md.norm(x) == B::md.norm(r.x); }
 CE bool operator!=(const MInt& r) const { return !(*this == r); }
 CE bool operator<(const MInt& r) const { return B::md.norm(x) < B::md.norm(r.x); }
 CE inline MInt inv() const { return mod_inv<Int>(val(), B::md.mod); }
 CE inline Uint val() const { return B::md.get(x); }
 friend ostream& operator<<(ostream& os, const MInt& r) { return os << r.val(); }
 friend istream& operator>>(istream& is, MInt& r) {
  i64 v;
  return is >> v, r= MInt(v), is;
 }
private:
 Uint x;
};
template <u64 MOD> using ModInt= conditional_t < (MOD < (1 << 30)) & MOD, MInt<int, u32, SB<MP_Mo<u32, u64, 32, 31>, MOD>>, conditional_t < (MOD < (1ull << 62)) & MOD, MInt<i64, u64, SB<MP_Mo<u64, u128, 64, 63>, MOD>>, conditional_t<MOD<(1u << 31), MInt<int, u32, SB<MP_Na, MOD>>, conditional_t<MOD<(1ull << 32), MInt<i64, u32, SB<MP_Na, MOD>>, conditional_t<MOD <= (1ull << 41), MInt<i64, u64, SB<MP_Br2, MOD>>, MInt<i64, u64, SB<MP_D2B1, MOD>>>>>>>;
#undef CE
}
using math_internal::ModInt;
namespace sps {
namespace sps_internal {
using namespace std;
#define ZETA(s, l) \
 if constexpr (!t) A[s + l]+= A[s]; \
 else if constexpr (t == 1) A[s + l]-= A[s]; \
 else if constexpr (t == 2) A[s]+= A[s + l]; \
 else A[s]-= A[s + l]
template <int t, class T> void rec(T A[], int l) {
 if (l > 127) {
  l>>= 1, rec<t>(A, l), rec<t>(A + l, l);
  for (int s= 0; s < l; ++s) ZETA(s, l);
 } else
  for (int k= 1; k < l; k<<= 1)
   for (int i= 0; i < l; i+= k + k)
    for (int j= 0; j < k; ++j) ZETA(i + j, k);
}
#undef ZETA
/* subset_zeta:   f -> g s.t. g[S] = sum_{T subseteq S} f[T]  O(n 2^n) */
template <class T> void subset_zeta(vector<T>& f) { rec<0>(f.data(), f.size()); }
/* supset_zeta:   f -> g s.t. g[S] = sum_{S subseteq T} f[T]  O(n 2^n) */
template <class T> void subset_mobius(vector<T>& f) { rec<1>(f.data(), f.size()); }
/* subset_mobius: f -> g s.t. f[S] = sum_{T subseteq S} g[T]  O(n 2^n) */
template <class T> void supset_zeta(vector<T>& f) { rec<2>(f.data(), f.size()); }
/* supset_mobius: f -> g s.t. f[S] = sum_{S subseteq T} g[T]  O(n 2^n) */
template <class T> void supset_mobius(vector<T>& f) { rec<3>(f.data(), f.size()); }
/* h[S] = sum_{U | T == S} f[U]g[T]  O(n 2^n) */
template <class T> vector<T> or_convolve(vector<T> f, vector<T> g) {
 subset_zeta(f), subset_zeta(g);
 for (int s= f.size(); s--;) f[s]*= g[s];
 return subset_mobius(f), f;
}
/* h[S] = sum_{U & T == S} f[U]g[T]  O(n 2^n) */
template <class T> vector<T> and_convolve(vector<T> f, vector<T> g) {
 supset_zeta(f), supset_zeta(g);
 for (int s= f.size(); s--;) f[s]*= g[s];
 return supset_mobius(f), f;
}
template <int t, class T> void rec_r(T A[], int l, int n, int c= 0) {
 if (l >= (n << 4)) {
  l>>= 1, rec_r<t>(A, l, n, c), rec_r<t>(A + l, l, n, c + 1);
  for (int s= l / n; s--;)
   if constexpr (!t)
    for (int d= 0, e= __builtin_popcount(s) + c + 1; d < e; ++d) A[s * n + d + l]+= A[s * n + d];
   else
    for (int d= __builtin_popcount(s) + c + 1; d < n; ++d) A[s * n + d + l]-= A[s * n + d];
 } else
  for (int k= 1, m= l / n; k < m; k<<= 1)
   for (int i= 0; i < m; i+= k + k)
    for (int j= 0; j < k; ++j)
     if constexpr (!t)
      for (int u= i + j, s= u + k, d= 0, e= __builtin_popcount(s) + c; d < e; ++d) A[s * n + d]+= A[u * n + d];
     else
      for (int u= i + j, s= u + k, d= __builtin_popcount(s) + c; d < n; ++d) A[s * n + d]-= A[u * n + d];
}
template <class T> void rnk_zeta(const T f[], T F[], int n) {
 for (int s= 1 << n; s--;) F[s * (n + 1) + __builtin_popcount(s)]= f[s];
 rec_r<0>(F, (n + 1) << n, n + 1);
}
template <class T> void rnk_mobius(T F[], T f[], int n) {
 rec_r<1>(F, (n + 1) << n, n + 1);
 for (int s= 1 << n; s--;) f[s]= F[s * (n + 1) + __builtin_popcount(s)];
}
template <class T> void cnv_(T A[], const T B[], int n) {
 for (int s= 1 << (n - 1); s--;) {
  T t, *a= A + s * n;
  const T* b= B + s * n;
  for (int c= __builtin_popcount(s), d= min(2 * c, n - 1), e; d >= c; a[d--]= t)
   for (t= 0, e= d - c; e <= c; ++e) t+= a[e] * b[d - e];
 }
}
template <class T> void cnv_na(const T f[], const T g[], T h[], int N) {
 for (int s= N, t; s--;)
  for (h[t= s]= f[s] * g[0]; t; --t&= s) h[s]+= f[s ^ t] * g[t];
}
// fg, O(n^2 2^n)
template <class T> vector<T> convolve(const vector<T>& f, const vector<T>& g) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1))), assert(N == (int)g.size());
 vector<T> h(N);
 if (n < 11) return cnv_na(f.data(), g.data(), h.data(), N), h;
 vector<T> F((n + 1) << n), G((n + 1) << n);
 return rnk_zeta(f.data(), F.data(), n), rnk_zeta(g.data(), G.data(), n), cnv_(F.data(), G.data(), n + 1), rnk_mobius(F.data(), h.data(), n), h;
}
template <class T> void div_na(T f[], const T g[], int N) {
 for (int s= 1; s < N; ++s)
  for (int t= s; t; --t&= s) f[s]-= f[s ^ t] * g[t];
}
// 1/f, "f[empty] = 1" is required, O(n^2 2^n)
template <class T> vector<T> inv(const vector<T>& f) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1))), assert(f[0] == 1);
 vector<T> h(N);
 if (n < 11) return h[0]= 1, div_na(h.data(), f.data(), N), h;
 vector<T> F((n + 1) << n), G((n + 1) << n);
 rnk_zeta(f.data(), G.data(), n);
 for (int s= N; s--;) {
  T *a= F.data() + s * (n + 1), *b= G.data() + s * (n + 1);
  a[0]= 1;
  for (int d= 0, c= __builtin_popcount(s); d++ < n;)
   for (int e= max(0, d - c); e < d; ++e) a[d]-= a[e] * b[d - e];
 }
 return rnk_mobius(F.data(), h.data(), n), h;
}
// f/g, "f[empty] = 1" is required, O(n^2 2^n)
template <class T> vector<T> div(vector<T> f, const vector<T>& g) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1))), assert(N == (int)g.size()), assert(g[0] == 1);
 if (n < 12) return div_na(f.data(), g.data(), N), f;
 vector<T> F((n + 1) << n), G((n + 1) << n);
 rnk_zeta(f.data(), F.data(), n), rnk_zeta(g.data(), G.data(), n);
 for (int s= N; s--;) {
  T *a= F.data() + s * (n + 1), *b= G.data() + s * (n + 1);
  for (int d= 0, c= __builtin_popcount(s); d++ < n;)
   for (int e= max(0, d - c); e < d; ++e) a[d]-= a[e] * b[d - e];
 }
 return rnk_mobius(F.data(), f.data(), n), f;
}
template <class T, class P> void oncnv_(const T f[], T h[], const P& phi, int n) {
 vector<T> F((n + 1) << n), G((n + 1) << n);
 rnk_zeta(f, F.data(), n), fill_n(G.data(), 1 << n, h[0]);
 T* a= G.data() + (1 << n);
 for (int l= 1 << n; l>>= 1;) phi(l, a[l]= h[0] * f[l]), h[l]= a[l];
 for (int d= 2, s; d <= n; ++d) {
  for (rec<0>(a, 1 << n), a+= (s= 1 << n); s--;)
   if (int c= __builtin_popcount(s); c <= d && d <= 2 * c)
    for (int e= d; e--;) a[s]+= G[e << n | s] * F[s * (n + 1) + d - e];
  for (rec<1>(a, 1 << n), s= 1 << n; s--;)
   if (__builtin_popcount(s) == d) phi(s, a[s]), h[s]= a[s];
   else a[s]= 0;
 }
}
// h[S] = phi(S, sum_{T subsetneq S} h[T]f[S/T] )   O(n^2 2^n)
template <class T, class P> vector<T> semi_relaxed_convolve(const vector<T>& f, T init, const P& phi) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1)));
 vector<T> h(N);
 if (h[0]= init; n < 12) {
  for (int s= 1, t; s < N; phi(s, h[s]), ++s)
   for (t= s; t; --t&= s) h[s]+= h[s ^ t] * f[t];
 } else oncnv_(f.data(), h.data(), phi, n);
 return h;
}
// h[S] = phi(S, 1/2 sum_{empty neq T subseteq S} h[T]h[S/T] )   O(n^2 2^n)
template <class T, class P> vector<T> self_relaxed_convolve(const P& phi, int n) {
 const int e= min(n, 12);
 int i= 0, l= 1;
 vector<T> f(1 << n);
 for (int u= 1; i < e; l<<= 1, ++i)
  for (int s= 0; s < l; phi(u, f[u]), ++s, ++u)
   for (int t= s; t; --t&= s) f[u]+= f[u ^ t] * f[t];
 for (; i < n; l<<= 1, ++i)
  phi(l, f[l]), oncnv_(
                    f.data(), f.data() + l, [&](int s, T& x) { phi(s | l, x); }, i);
 return f;
}
// exp(f) , "f[empty] = 0" is required,  O(n^2 2^n)
template <class T> vector<T> exp(const vector<T>& f) {
 const int N= f.size(), n= __builtin_ctz(N), e= min(N, 1 << 11);
 assert(!(N & (N - 1))), assert(f[0] == 0);
 vector<T> h(N);
 int i= 0, l= 1;
 for (h[0]= 1; l < e; l<<= 1, ++i) cnv_na(h.data(), f.data() + l, h.data() + l, l);
 for (; l < N; l<<= 1, ++i) {
  vector<T> F((i + 1) << i), G((i + 1) << i);
  rnk_zeta(h.data(), F.data(), i), rnk_zeta(f.data() + l, G.data(), i), cnv_(F.data(), G.data(), i + 1), rnk_mobius(F.data(), h.data() + l, i);
 }
 return h;
}
// log(f) , "f[empty] = 1" is required,  O(n^2 2^n)
template <class T> vector<T> log(const vector<T>& f) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1))), assert(f[0] == 1);
 vector<T> h(N);
 int i= n - 1, l= N >> 1;
 if (i > 11) {
  vector<T> G(n << (n - 1));
  rnk_zeta(f.data(), G.data(), n - 1);
  for (; i > 11; l>>= 1, --i) {
   vector<T> F((i + 1) << i);
   rnk_zeta(f.data() + l, F.data(), i);
   for (int s= l; s--;) {
    T *a= F.data() + s * (i + 1), *b= G.data() + s * n;
    for (int d= 0, c= __builtin_popcount(s); d++ < i;)
     for (int e= max(0, d - c); e < d; ++e) a[d]-= a[e] * b[d - e];
   }
   rnk_mobius(F.data(), h.data() + l, i);
  }
 }
 for (; l; l>>= 1) copy_n(f.data() + l, l, h.data() + l), div_na(h.data() + l, f.data(), l);
 return h;
}
// F(f) =  sum_i F_i f^i/i! , "f[empty] = 0" is required, O(n^2 2^n)
template <class T> vector<T> egf_comp(const vector<T>& F, const vector<T>& f) {
 const int N= f.size(), n= __builtin_ctz(N), e= min(N, 1 << 11);
 assert(!(N & (N - 1))), assert(f[0] == 0);
 vector<T> h(N);
 T* b= h.data() + N;
 for (int i= n - F.size(); i++ < n;) h[N - (1 << i)]= F[n - i];
 int i= 0, l= 1;
 for (; l < e; l<<= 1, ++i)
  for (int j= N >> 1; j >= l; j>>= 1) cnv_na(b - j, f.data() + l, b - j - j + l, l);
 if (l < N) {
  vector<T> A(n << (n - 1)), B(n << (n - 1));
  for (; l < N; l<<= 1, ++i) {
   fill_n(B.data(), (i + 1) << i, 0), rnk_zeta(f.data() + l, B.data(), i);
   for (int j= N >> 1; j >= l; j>>= 1) fill_n(A.data(), (i + 1) << i, 0), rnk_zeta(b - j, A.data(), i), cnv_(A.data(), B.data(), i + 1), rnk_mobius(A.data(), b - j - j + l, i);
  }
 }
 return h;
}
// P(f) = sum_{i=0}^m P_i f^i ,  O(n^2 2^n)
template <class T> vector<T> poly_comp(vector<T> P, vector<T> f) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1)));
 vector<T> F(n + 1);
 for (int j= 0, e= P.size();; ++j, --e) {
  for (int i= e; i--;) (F[j]*= f[0])+= P[i];
  if (j == n || e <= 1) break;
  for (int i= 1; i < e; ++i) P[i - 1]= P[i] * i;
 }
 return f[0]= 0, egf_comp(F, f);
}
template <class T> vector<T> _egfT(const T* b, T* h, int M, int n) {
 T *a, *d;
 vector<T> c(n + 1);
 int l= M;
 if (int i= __builtin_ctz(M); i > 10) {
  vector<T> F((i + 1) << i), G((i + 1) << i);
  for (int m, s; i > 10; fill_n(F.data(), (i + 1) << i, 0), rnk_zeta(h, F.data(), i), cnv_(F.data(), G.data(), i + 1), rnk_mobius(F.data(), h, i), b-= (l>>= 1), --i)
   for (fill_n(G.data(), (i + 1) << i, 0), rnk_zeta(b, G.data(), i), m= M; m > l; m>>= 1)
    for (a= h + (m - l), fill_n(F.data(), (i + 1) << i, 0), rnk_zeta(a + m - l, F.data(), i), cnv_(F.data(), G.data(), i + 1), rec_r<1>(F.data(), (i + 1) << i, i + 1), s= l; s--;) a[s]+= F[s * (i + 1) + __builtin_popcount(s)];
 }
 for (; l; cnv_na(h, b, h, l), b-= (l>>= 1))
  for (int m= M, s, t; m > l; m>>= 1)
   for (a= h + (m - l), d= a + (m - l), s= l; s--;)
    for (a[t= s]+= d[s] * b[0]; t; --t&= s) a[s]+= d[s ^ t] * b[t];
 for (int i= 0; i <= n; ++i) c[i]= h[(1 << (n - i)) - 1];
 return c;
}
// [X^{[n]}] f^k/k! for k=0,1,...,n , O(n^2 2^n)
template <class T> vector<T> egf_T(vector<T> f) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1)));
 if (n == 0) return {1};
 if (n == 1) return {0, f[1]};
 return _egfT(f.data() + (N >> 2), f.data() + (N >> 1), N >> 2, n);
}
// [X^{[n]}] f^k/k! g for k=0,1,...,n , O(n^2 2^n)
template <class T> vector<T> egf_T(const vector<T>& f, vector<T> g) {
 const int N= f.size(), n= __builtin_ctz(N);
 assert(!(N & (N - 1)));
 if (n == 0) return {g[1]};
 return _egfT(f.data() + (N >> 1), g.data(), N >> 1, n);
}
}
using sps_internal::subset_zeta, sps_internal::subset_mobius, sps_internal::supset_zeta, sps_internal::supset_mobius, sps_internal::or_convolve, sps_internal::and_convolve, sps_internal::convolve, sps_internal::semi_relaxed_convolve, sps_internal::self_relaxed_convolve, sps_internal::inv, sps_internal::div, sps_internal::exp, sps_internal::log, sps_internal::egf_comp, sps_internal::poly_comp, sps_internal::egf_T;
}
template <class Int= int> class UndirectedGraphSetPowerSeries {
 template <class T> using Sps= std::vector<T>;
 template <class T> using Poly= std::vector<T>;
 const int n, N, m, o;
 std::vector<Int> adj;
 std::vector<int> es;
 template <class T> static inline T pow(T x, int k) {
  for (T ret(1);; x*= x)
   if (k& 1 ? ret*= x : 0; !(k>>= 1)) return ret;
 }
 template <class F> inline void bfs(int s, const F& f) const {
  for (int t= s, u, j; t;)
   for (f(u= 1 << __builtin_ctz(t)); u;) j= __builtin_ctz(u), t^= 1 << j, u^= 1 << j, u|= es[j] & t;
 }
 template <class T, class G> static inline void transform_articulation(Sps<T>& f, const G& g) {
  const int M= f.size() / 2;
  Sps<T> tmp(M);
  for (int I= M; I; I>>= 1) {
   for (int t= 0; t < M; t+= I)
    for (int u= I, t2= t << 1; u--;) tmp[t | u]= f[t2 | I | u];
   tmp= g(tmp);
   for (int t= 0; t < M; t+= I)
    for (int u= I, t2= t << 1; u--;) f[t2 | I | u]= tmp[t | u];
  }
 }
 template <class T, bool b> inline void transform_bridge(Sps<T>& f) const {
  const int M= N / 2;
  Sps<T> tmp(M), tmp2;
  for (int i= n, I= M; --i; I>>= 1) {
   for (int t= 0; t < M; t+= I)
    for (int u= I, t2= t << 1; u--;) tmp[t | u]= f[t2 | I | u];
   tmp2.assign(M, 0);
   for (int t= 0; t < M; t+= I)
    for (int j= i, J= I, t2= t << 1; J>>= 1, j--;)
     for (int s= J, J2= J * 2; s < I; s+= J2)
      for (int u= s + J; u-- > s;) {
       if constexpr (b) tmp2[t | u]+= f[t2 | u] * adj[i * m + j];
       else tmp2[t | u]-= f[t2 | u] * adj[i * m + j];
      }
   tmp= sps::convolve(tmp, sps::exp(tmp2));
   for (int t= 0; t < M; t+= I)
    for (int u= I, t2= t << 1; u--;) f[t2 | I | u]= tmp[t | u];
  }
 }
 template <class T> inline std::vector<T> cyc() const {
  std::vector<T> cyc(1 << o);
  for (int i= 0; i < o; ++i) {
   int a= i + i, b= a + 1, K= a + 2, I= 1 << i;
   std::vector<T> dp0(K << i);
   dp0[a]= 1;
   for (int s= 0; s < I; ++s) {
    T* dp0s= dp0.data() + (s * K);
    for (int u= s | I, S= u, j, j0, j1; S; S^= 1 << j) {
     j= __builtin_ctz(S), j0= j + j, j1= j0 + 1;
     const Int *A0= adj.data() + (j0 * m), *A1= A0 + m;
     T dp0s0= dp0s[j0], dp0s1= dp0s[j1];
     cyc[u]+= dp0s0 * A0[b] + dp0s1 * A1[b];
     for (int U= I - 1 - s, k, k0, k1; U; U^= 1 << k) {
      k= __builtin_ctz(U), k0= k + k, k1= k0 + 1;
      dp0s[(K << k) + k0]+= dp0s0 * A0[k1] + dp0s1 * A1[k1], dp0s[(K << k) + k1]+= dp0s0 * A0[k0] + dp0s1 * A1[k0];
     }
    }
   }
  }
  return cyc;
 }
 template <class T> inline std::pair<std::vector<T>, std::vector<T>> cyc_pth() const {
  std::vector<T> cyc(1 << o), pth(1 << o);
  for (int i= 0; i < o; ++i) {
   int a= i + i, b= a + 1, K= a + 2, I= 1 << i;
   std::vector<T> dp0(K << i), dp1(K << i);
   dp0[a]= 1;
   for (int s= 0; s < I; ++s) {
    T *dp0s= dp0.data() + (s * K), *dp1s= dp1.data() + (s * K);
    for (int j= 0; j < K; ++j) dp1s[b]+= dp0s[j];
    for (int u= s | I, S= u, j, j0, j1; S; S^= 1 << j) {
     j= __builtin_ctz(S), j0= j + j, j1= j0 + 1;
     const Int *A0= adj.data() + (j0 * m), *A1= A0 + m;
     T dp0s0= dp0s[j0], dp0s1= dp0s[j1], dp1s0= dp1s[j0], dp1s1= dp1s[j1];
     cyc[u]+= dp0s0 * A0[b] + dp0s1 * A1[b], pth[u]+= dp1s0 + dp1s1;
     for (int U= I - 1 - s, k, k0, k1; U; U^= 1 << k) {
      k= __builtin_ctz(U), k0= k + k, k1= k0 + 1;
      dp0s[(K << k) + k0]+= dp0s0 * A0[k1] + dp0s1 * A1[k1], dp0s[(K << k) + k1]+= dp0s0 * A0[k0] + dp0s1 * A1[k0];
      dp1s[(K << k) + k0]+= dp1s0 * A0[k1] + dp1s1 * A1[k1], dp1s[(K << k) + k1]+= dp1s0 * A0[k0] + dp1s1 * A1[k0];
     }
    }
   }
  }
  return {cyc, pth};
 }
public:
 UndirectedGraphSetPowerSeries(int n): n(n), N(1 << n), m(n + (n & 1)), o(m / 2), adj(m * m), es(n) {}
 UndirectedGraphSetPowerSeries(const std::vector<std::vector<Int>>& g): n(g.size()), N(1 << n), m(n + (n & 1)), o(m / 2), adj(m * m), es(n) {
  for (int i= n; i--;)
   for (int j= i; j--;) assert(g[i][j] == g[j][i]);
  for (int i= n; i--;)
   for (int j= n; j--;) adj[i * m + j]= g[i][j];
  for (int i= n; i--;)
   for (int j= n; j--;) es[i]|= !(!(adj[i * m + j])) << j;
 }
 void add_edge(int u, int v, int cnt= 1) {
  adj[u * m + v]= (adj[v * m + u]+= cnt), es[u]|= (1 << v), es[v]|= (1 << u);
  if (!(adj[u * m + v])) es[u]^= (1 << v), es[v]^= (1 << u);
 }
 const auto operator[](int u) const { return adj.begin() + (u * m); }
 template <class T> static inline Sps<T> only_connected(const Sps<T>& f) { return sps::log(f); }
 template <class T> static inline Sps<T> disjoint_union(const Sps<T>& f) { return sps::exp(f); }
 template <class T> static inline Sps<T> only_biconnected(Sps<T> f) { return transform_articulation(f, sps::log<T>), f; }
 template <class T> static inline Sps<T> articulation_union(Sps<T> f) { return transform_articulation(f, sps::exp<T>), f; }
 template <class T> inline Sps<T> only_2edge_connected(Sps<T> f) const { return transform_bridge<T, false>(f), f; }
 template <class T> inline Sps<T> bridge_union(Sps<T> f) const { return transform_bridge<T, true>(f), f; }
 inline Sps<Int> edge_num() const {
  Sps<Int> ret(N, 0);
  for (int i= n; i--;)
   for (int j= i; j--;) ret[(1 << i) | (1 << j)]= adj[i * m + j];
  return sps::subset_zeta(ret), ret;
 }
 inline Sps<int> connected_component_num() const {
  Sps<int> ret(N, 0);
  for (int s= N; s--;) bfs(s, [&](int) { ret[s]++; });
  return ret;
 }
 inline Sps<Int> cycle_space_rank() const {
  Sps<Int> e= edge_num(), ret(N, 0);
  Sps<int> k= connected_component_num();
  for (int s= N; s--;) ret[s]= e[s] + k[s] - __builtin_popcount(s);
  return ret;
 }
 inline Sps<Int> odd_deg_num() const {
  Sps<Int> ret(N, 0);
  for (int i= n, I= N; I>>= 1, i--;)
   for (int t= 0, I2= I << 1; t < N; t+= I2)
    for (int u= I, cnt, v, j; u--; ret[t | I | u]+= cnt & 1)
     for (cnt= 0, v= t | u; v; v^= 1 << j) cnt+= adj[i * m + (j= __builtin_ctz(v))];
  return ret;
 }
 inline Sps<Int> selfloop_num() const {
  Sps<Int> ret(N, 0);
  for (int i= 0, I= 1; i < n; ++i, I<<= 1)
   for (int u= I; u--;) ret[I | u]= ret[u] + adj[i * m + i];
  return ret;
 }
 template <class T> static inline Sps<T> space_size(const Sps<int>& rank) {
  Sps<T> ret(rank.size());
  for (int s= rank.size(); s--;) ret[s]= pow<T>(2, rank[s]);
  return ret;
 }
 template <class T> inline Sps<T> graph() const { return space_size<T>(edge_num()); }
 template <class T> inline Sps<T> cycle_space_size() const { return space_size<T>(cycle_space_rank()); }
 template <class T> inline Sps<T> connected_graph() const { return sps::log(graph<T>()); }
 template <class T> inline Sps<T> eulerian_graph() const { return sps::log(cycle_space_size<T>()); }
 template <class T> inline Sps<T> connected_biparate_graph() const {
  Sps<T> tmp= graph<T>(), ret(N, 1);
  for (int s= N; s--;) ret[s]/= tmp[s];
  ret= sps::convolve(ret, ret);
  for (int s= N; s--;) ret[s]*= tmp[s];
  ret= sps::log(ret);
  for (int s= N; s--;) ret[s]/= 2;
  return ret;
 }
 template <class T> inline Sps<T> tree() const {
  Sps<int> e= edge_num();
  Sps<T> ret= {0, 1};
  ret.reserve(N);
  for (int I= 2; I < N; I<<= 1) {
   Sps<T> g(ret);
   for (int s= I; --s;) g[s]*= e[s | I] - e[s] - e[I];
   g= sps::exp(g), std::copy(g.begin(), g.end(), std::back_inserter(ret));
  }
  return ret;
 }
 template <class T> inline Sps<T> forest() const { return sps::exp(tree<T>()); }
 template <class T> inline Sps<T> cycle_graph() const {
  T dp[N][n - 1];
  Sps<T> ret(N, 0);
  for (int i= n, I= N; I>>= 1, --i;) {
   for (int s= I; --s;) std::fill_n(dp[s], i, 0);
   for (int j= i; j--;) dp[1 << j][j]= adj[i * m + j];
   for (int s= 1; s < I; ++s)
    for (int t= s, j, u, r, k; t; ret[s | I]+= dp[s][j] * adj[j * m + i])
     for (t^= 1 << (j= __builtin_ctz(t)), u= r= s ^ (1 << j); u; dp[s][j]+= dp[r][k] * adj[k * m + j]) u^= 1 << (k= __builtin_ctz(u));
  }
  for (int i= n; i--;)
   for (int j= i; j--;) ret[(1 << i) | (1 << j)]-= adj[i * m + j];
  for (int s= N; --s;) ret[s]/= 2;
  return ret;
 }
 template <class T> inline Sps<T> biconnected_graph() const {
  Sps<T> ret= connected_graph<T>();
  return transform_articulation(ret, sps::log<T>), ret;
 }
 template <class T> inline Sps<T> two_edge_connected_graph() const {
  Sps<T> ret= connected_graph<T>();
  return transform_bridge<T, false>(ret), ret;
 }
 template <class T> inline Sps<T> cactus_graph() const {
  auto ret= cycle_graph<T>();
  for (int i= n; i--;)
   for (int j= i; j--;) ret[(1 << i) | (1 << j)]+= adj[i * m + j];
  return transform_articulation(ret, sps::exp<T>), ret;
 }
 template <class T> inline Sps<T> acyclic_orientations() const {
  auto k= connected_component_num();
  Sps<T> g(N, 0);
  for (int s= N; --s;)
   if (k[s] == __builtin_popcount(s)) g[s]= k[s] & 1 ? -1 : 1;
  return g[0]= 1, sps::inv(g);
 }
 template <class T> inline std::vector<T> colorings_using_exactly_k_colors_num() const {
  if (n == 0) return {0};  // impossible in any number of ways
  auto k= connected_component_num();
  std::vector<T> indep(N, 0);
  for (int s= N; --s;) indep[s]= k[s] == __builtin_popcount(s);
  return sps::egf_T(indep);
 }
 template <class T> inline Poly<T> chromatic_polynomial() const {
  auto e= colorings_using_exactly_k_colors_num<T>();
  if (e.back() == 0) return {0};
  Poly<T> ret(n + 1, 0);
  T tmp[n]= {1};
  for (int i= 1, j; i < n; ++i)
   for (j= i; j--; tmp[j]*= -i) ret[j + 1]+= tmp[j] * e[i], tmp[j + 1]+= tmp[j];
  for (int j= n; j--;) ret[j + 1]+= tmp[j];
  return ret;
 }
 template <class T> inline T tutte_polynomial(T x, T y) const {
  int sum[N], s, t, lim= 2, i, j;
  T fum[10'000]= {0, 1};
  std::vector<T> g= {0}, h;
  for (g.reserve(N), h.reserve(N), i= 0; i < n; h= sps::exp(h), std::copy(h.begin(), h.end(), std::back_inserter(g)), ++i) {
   for (sum[0]= j= 0; j < i; j++)
    for (s= t= 1 << j; s--;) sum[s | t]= sum[s] + adj[i * m + j];
   for (h.resize(s= 1 << i); s--; h[s]= g[s] * fum[sum[s]])
    for (; lim <= sum[s]; lim++) fum[lim]= fum[lim - 1] * y + 1;
  }
  for (x-= 1, t= ~0, j= 0, i= n; i--;) j+= adj[i * m + i];
  for (bfs((s= N) - 1, [&](int u) { t^= u; }); --s&= t;) g[s]*= x;
  return sps::exp(g)[N - 1] * pow(y, j);
 }
 template <class T> inline T perfect_matching() const { return sps::exp(cyc<T>()).back(); }
 template <class T> inline T all_matching() const {
  auto [cyc, pth]= cyc_pth<T>();
  for (int s= cyc.size(); s--;) cyc[s]+= pth[s];
  return sps::exp(cyc).back();
 }
 template <class T> std::vector<T> k_mathcing() const {
  auto [cyc, pth]= cyc_pth<T>();
  auto ret= sps::egf_T(pth, sps::exp(cyc));
  return std::reverse(ret.begin(), ret.end()), ret;
 }
};
using namespace std;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 using Mint= ModInt<int(1e9) + 7>;
 int n, m;
 Mint c;
 cin >> n >> m >> c;
 UndirectedGraphSetPowerSeries g(n);
 for (int i= 0, u, v; i < m; ++i) cin >> u >> v, g.add_edge(--u, --v);
 auto k_mch= g.k_mathcing<Mint>();
 Mint pw= 1, ans= 0;
 for (int i= 0, e= k_mch.size(); i < e; ++i) ans+= pw * k_mch[i], pw*= c;
 cout << ans << '\n';
 return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

input:

6 10 100
3 6
1 3
2 4
3 4
4 6
1 2
4 5
2 3
1 4
3 5

output:

2171001

result:

ok single line: '2171001'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

8 11 818466928
6 7
3 6
6 5
7 3
6 2
8 1
1 7
4 3
5 1
6 1
6 4

output:

425176360

result:

ok single line: '425176360'

Test #3:

score: 0
Accepted
time: 909ms
memory: 42136kb

input:

36 123 272968155
33 35
17 5
12 1
36 32
1 11
9 28
24 36
13 17
19 17
35 8
7 19
31 24
31 34
27 18
9 17
35 17
6 17
31 12
12 19
25 18
36 16
24 23
26 34
7 23
25 14
18 34
10 23
32 33
12 28
18 14
35 23
19 33
22 27
14 27
14 15
22 6
1 20
31 17
27 31
15 4
35 4
5 33
26 36
27 2
20 23
2 12
36 13
28 13
4 7
21 24
2...

output:

951479337

result:

ok single line: '951479337'

Test #4:

score: 0
Accepted
time: 902ms
memory: 42188kb

input:

36 465 876331013
34 32
4 12
12 28
12 35
10 11
13 32
21 26
27 31
30 17
32 26
2 5
5 25
35 28
13 18
19 7
4 27
32 35
12 2
17 19
29 34
9 25
17 8
6 5
26 30
26 36
11 7
13 29
1 2
9 3
22 8
8 34
24 17
11 23
4 14
21 13
19 24
22 25
11 19
12 19
21 6
21 12
19 15
34 17
16 27
14 30
33 36
16 35
10 26
19 21
18 24
32 ...

output:

139355408

result:

ok single line: '139355408'

Test #5:

score: 0
Accepted
time: 901ms
memory: 42168kb

input:

36 362 721856249
26 4
33 21
23 15
3 31
23 12
35 17
30 9
3 26
18 2
27 13
10 14
7 36
17 25
14 11
17 4
8 12
1 24
30 1
33 15
22 1
32 31
30 32
29 5
27 12
25 32
9 5
16 18
20 8
33 31
16 6
36 22
11 1
15 28
3 32
10 28
17 24
9 16
22 29
29 7
5 15
18 27
36 26
16 36
9 28
35 27
12 24
13 1
14 1
25 36
14 35
30 2
30...

output:

409886964

result:

ok single line: '409886964'

Test #6:

score: 0
Accepted
time: 894ms
memory: 42176kb

input:

36 284 3732174
34 9
7 11
8 5
17 14
31 36
5 1
21 5
25 26
25 2
28 29
9 17
35 26
35 28
14 19
25 13
34 5
27 19
23 20
19 7
12 36
7 13
33 28
9 28
36 2
27 8
11 34
20 22
1 12
17 1
25 23
4 24
23 24
12 27
11 22
14 31
30 32
27 16
20 26
4 30
22 12
18 28
15 16
21 19
7 8
34 17
33 3
23 34
5 14
14 33
26 21
14 11
12...

output:

825811598

result:

ok single line: '825811598'

Test #7:

score: 0
Accepted
time: 923ms
memory: 42288kb

input:

36 211 812897109
14 36
23 29
29 25
33 14
26 6
14 4
6 11
21 10
35 26
24 18
27 35
23 34
36 23
36 30
28 7
7 5
36 5
8 18
36 20
23 11
27 22
33 11
25 7
31 18
10 24
26 11
9 25
19 28
21 16
7 14
33 36
24 35
3 22
15 6
14 15
7 30
9 6
35 25
21 11
19 12
19 24
29 31
34 33
7 34
23 9
22 9
12 31
17 1
28 8
23 26
35 2...

output:

466059363

result:

ok single line: '466059363'

Test #8:

score: 0
Accepted
time: 909ms
memory: 42156kb

input:

36 538 952519816
5 34
16 15
34 21
16 18
14 17
13 12
4 25
4 18
6 32
18 23
27 36
8 9
35 26
3 6
29 2
29 16
19 36
12 36
30 12
5 26
24 34
20 3
6 33
8 31
25 11
27 19
11 6
26 22
15 30
18 32
36 4
19 29
28 27
29 4
6 8
34 26
9 11
2 23
21 33
30 27
23 11
7 22
15 9
13 6
3 5
23 30
17 6
16 6
6 4
22 30
31 3
2 36
19...

output:

183842696

result:

ok single line: '183842696'

Test #9:

score: 0
Accepted
time: 901ms
memory: 42148kb

input:

36 109 722377035
5 33
11 27
10 1
11 22
13 6
26 25
5 30
33 1
25 3
32 3
22 16
17 34
13 4
30 21
10 32
18 23
3 35
7 8
17 4
18 1
1 26
28 13
28 33
30 36
7 5
17 25
13 19
27 18
18 21
10 7
18 7
5 34
36 24
6 11
2 31
9 26
27 13
27 6
9 21
24 15
12 8
34 27
7 1
6 15
20 10
3 23
5 25
27 22
15 23
8 10
21 4
14 16
12 ...

output:

602614473

result:

ok single line: '602614473'

Test #10:

score: 0
Accepted
time: 911ms
memory: 42116kb

input:

36 474 597422891
13 10
15 18
34 24
13 25
1 9
36 15
35 10
19 25
16 9
22 10
35 3
31 7
18 33
23 30
34 1
30 12
18 29
24 23
27 31
29 13
9 23
12 4
16 30
36 31
13 27
23 31
8 14
5 18
35 22
10 17
8 32
32 19
29 24
3 8
35 17
28 8
21 19
28 5
5 17
31 35
18 34
35 24
7 14
27 32
16 11
21 3
33 13
23 2
30 6
22 18
26 ...

output:

534178430

result:

ok single line: '534178430'

Test #11:

score: 0
Accepted
time: 898ms
memory: 42100kb

input:

36 46 195215736
6 13
10 12
14 22
13 31
3 13
18 28
24 33
3 23
5 36
19 24
12 31
9 35
20 31
23 12
36 10
4 8
1 30
31 4
34 3
30 32
34 7
14 16
30 4
5 8
15 30
33 27
5 20
25 14
35 23
3 10
36 1
3 27
35 15
15 1
16 25
19 28
12 19
29 36
29 3
4 23
3 4
8 17
17 13
21 22
5 23
9 7

output:

984244248

result:

ok single line: '984244248'

Test #12:

score: 0
Accepted
time: 899ms
memory: 42316kb

input:

36 592 469136264
19 32
6 22
6 12
10 14
11 24
15 28
32 13
31 23
15 9
11 29
22 24
28 32
20 14
21 32
27 25
7 35
18 15
23 19
10 4
33 12
3 6
11 1
23 6
31 16
34 6
1 6
34 12
5 13
12 23
22 8
26 7
25 23
36 17
35 26
22 21
17 14
15 10
27 4
2 32
15 19
18 8
23 34
21 31
36 18
6 25
29 32
13 16
26 4
35 6
9 8
26 30
...

output:

334985208

result:

ok single line: '334985208'

Test #13:

score: 0
Accepted
time: 896ms
memory: 42316kb

input:

36 362 433466696
15 30
23 18
22 29
35 13
25 15
4 17
35 34
3 32
4 3
15 10
19 4
31 1
8 35
30 31
2 28
31 4
15 27
24 14
16 23
32 24
13 3
7 30
18 33
19 6
22 35
27 20
24 12
19 2
30 22
30 1
5 16
10 18
13 9
18 35
18 16
25 4
29 27
22 4
6 35
23 3
12 4
23 15
33 31
27 24
8 32
15 19
13 15
17 28
15 26
21 5
16 33
...

output:

491766799

result:

ok single line: '491766799'

Test #14:

score: 0
Accepted
time: 898ms
memory: 42288kb

input:

36 102 417246257
35 27
33 25
10 23
25 4
20 31
35 6
33 36
9 32
34 3
2 26
23 8
25 15
29 2
30 29
6 30
27 24
4 32
10 18
16 3
9 3
33 29
26 8
22 36
28 19
25 5
29 34
14 5
29 36
15 31
7 8
2 12
10 26
36 13
24 23
5 6
12 22
27 18
3 5
22 3
30 2
15 24
9 6
1 13
4 13
19 18
27 11
13 8
14 24
17 10
12 18
24 31
25 23
...

output:

599285973

result:

ok single line: '599285973'

Test #15:

score: 0
Accepted
time: 892ms
memory: 42316kb

input:

36 503 478252988
23 3
14 13
16 23
17 2
31 4
29 25
18 23
6 18
13 32
2 8
3 36
34 20
11 33
2 15
11 20
28 33
16 10
5 29
29 12
15 36
23 15
22 27
3 1
27 21
5 13
11 22
28 8
20 12
1 31
12 6
27 11
12 8
24 13
23 11
9 6
25 35
23 2
19 12
35 36
17 25
23 21
7 9
33 31
27 17
16 8
4 8
24 21
18 8
5 6
5 1
21 29
22 18
...

output:

195560486

result:

ok single line: '195560486'

Test #16:

score: 0
Accepted
time: 896ms
memory: 42136kb

input:

36 250 950666826
27 26
4 15
36 7
11 36
1 5
26 13
11 5
27 8
30 1
22 1
24 6
8 15
32 36
2 24
33 34
36 25
4 27
4 6
18 21
3 27
2 7
5 7
25 20
22 30
12 33
35 21
27 13
2 23
33 1
8 17
21 9
8 31
13 24
17 31
30 9
24 9
22 9
30 28
8 1
15 9
2 15
18 29
22 10
10 32
24 29
32 31
14 30
31 25
17 11
26 25
17 7
25 2
24 1...

output:

512893447

result:

ok single line: '512893447'

Test #17:

score: 0
Accepted
time: 889ms
memory: 42176kb

input:

36 224 815243647
24 13
3 24
32 22
9 1
30 36
33 12
32 18
22 36
29 6
16 10
19 31
36 18
25 35
1 6
20 22
33 25
16 31
6 34
36 15
32 17
11 36
32 23
35 21
27 31
1 19
20 1
31 7
33 5
20 23
23 28
36 23
34 25
27 24
17 26
14 5
16 19
4 3
20 21
2 23
6 15
3 15
11 9
29 21
1 27
10 13
26 2
21 31
28 10
20 28
21 4
33 3...

output:

75822342

result:

ok single line: '75822342'

Test #18:

score: 0
Accepted
time: 902ms
memory: 42124kb

input:

36 20 72725288
25 31
34 5
29 15
28 14
4 34
35 12
10 34
18 17
33 6
36 17
24 3
27 24
31 30
19 10
15 26
22 14
34 32
2 28
31 5
1 28

output:

10405385

result:

ok single line: '10405385'

Test #19:

score: 0
Accepted
time: 894ms
memory: 42120kb

input:

36 375 731733295
36 28
26 30
3 7
16 20
28 2
25 12
20 30
23 6
9 8
24 5
7 29
25 22
25 17
3 22
20 5
13 24
19 9
34 30
31 7
2 34
23 19
23 7
19 34
24 7
26 16
14 34
9 22
30 22
3 8
36 33
36 32
4 15
9 7
13 6
19 13
33 31
17 34
28 25
34 15
4 29
17 35
25 31
13 25
5 28
35 34
36 23
21 20
25 32
21 29
14 12
3 16
9 ...

output:

71633307

result:

ok single line: '71633307'

Test #20:

score: 0
Accepted
time: 901ms
memory: 42292kb

input:

36 207 50817522
3 21
26 27
15 29
22 26
19 6
19 26
32 7
1 10
27 1
29 18
4 36
32 25
9 2
24 15
25 36
23 26
8 13
6 10
26 24
31 13
11 27
16 17
30 11
19 32
32 17
29 35
5 11
12 6
18 19
20 22
29 5
32 21
9 20
5 28
12 16
14 21
35 19
21 2
24 35
32 5
23 17
6 4
4 18
35 3
10 35
3 36
17 31
15 34
19 34
31 24
16 22
...

output:

865260163

result:

ok single line: '865260163'

Test #21:

score: 0
Accepted
time: 902ms
memory: 42188kb

input:

36 79 616823516
1 34
15 14
28 23
18 35
14 36
4 19
10 36
14 12
12 3
27 34
6 5
24 2
15 9
34 32
15 16
26 23
12 29
18 33
26 24
8 24
24 1
5 13
19 27
26 10
36 3
25 33
27 14
29 4
5 10
19 30
31 23
3 17
19 1
3 14
21 16
31 11
2 35
28 7
8 9
35 11
2 10
31 20
4 23
27 4
6 30
5 7
25 36
4 6
24 28
25 22
24 34
34 11
...

output:

750998004

result:

ok single line: '750998004'

Test #22:

score: 0
Accepted
time: 902ms
memory: 42248kb

input:

36 348 986386993
20 24
26 22
3 11
19 32
19 11
32 24
12 22
22 1
13 26
2 20
14 1
17 23
26 35
6 21
29 5
28 17
35 1
23 24
26 14
23 11
26 31
13 23
14 25
13 34
31 17
2 22
36 32
35 9
26 36
13 5
10 13
6 32
6 15
7 17
35 31
16 23
18 9
35 2
23 10
34 2
34 30
28 34
15 19
27 19
2 9
4 26
7 18
18 23
2 21
35 3
35 29...

output:

682561439

result:

ok single line: '682561439'

Test #23:

score: 0
Accepted
time: 892ms
memory: 42312kb

input:

36 0 73190723

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 909ms
memory: 42180kb

input:

36 630 67695848
6 13
35 30
14 31
8 29
30 26
26 1
11 33
13 30
20 7
35 20
18 34
27 30
14 23
1 27
21 27
26 14
13 14
25 4
11 3
17 28
20 33
2 5
31 28
18 10
21 29
31 26
29 28
19 31
17 33
28 33
3 23
28 20
10 8
25 9
8 7
26 5
7 33
17 36
34 13
12 35
6 19
9 19
6 2
15 1
24 4
4 1
36 15
3 17
21 17
18 9
18 27
11 2...

output:

396183330

result:

ok single line: '396183330'

Test #25:

score: 0
Accepted
time: 900ms
memory: 42104kb

input:

36 15 361262017
3 10
30 33
11 3
15 12
12 17
36 20
15 20
23 22
36 35
20 5
17 26
34 27
1 34
27 9
21 5

output:

622932610

result:

ok single line: '622932610'

Test #26:

score: 0
Accepted
time: 884ms
memory: 42172kb

input:

35 269 282064549
6 4
25 31
30 26
9 14
31 26
14 31
17 24
3 34
1 11
14 34
30 3
27 3
11 3
23 25
32 4
12 8
18 29
33 28
3 21
27 33
30 13
32 18
1 28
31 20
9 8
7 23
13 6
35 6
17 31
14 33
10 16
18 17
34 10
30 4
9 21
12 33
24 20
20 23
26 10
11 30
11 27
11 8
14 1
25 16
2 3
25 3
24 3
20 2
4 27
1 27
32 2
15 25
...

output:

251519103

result:

ok single line: '251519103'

Test #27:

score: 0
Accepted
time: 908ms
memory: 42248kb

input:

35 150 743933078
20 12
3 26
35 13
29 22
27 8
24 6
30 13
35 2
35 19
13 17
7 10
1 12
20 23
26 4
31 7
17 23
13 21
31 14
27 19
31 29
34 2
29 33
6 14
11 25
16 21
8 2
10 1
28 10
26 19
32 13
27 14
24 14
26 10
34 10
12 8
28 24
25 19
30 23
20 29
3 15
12 5
30 6
16 27
5 29
15 9
1 9
17 1
14 34
30 25
10 2
6 29
3...

output:

645624710

result:

ok single line: '645624710'

Test #28:

score: 0
Accepted
time: 886ms
memory: 42136kb

input:

35 322 83215822
23 5
13 5
18 23
20 8
5 32
16 6
23 26
5 33
28 15
28 24
28 34
34 4
21 23
17 1
1 16
16 7
27 28
6 30
1 5
2 24
15 21
21 35
29 8
20 4
24 21
6 13
34 35
27 8
22 20
9 6
29 26
4 7
11 15
33 27
32 20
21 34
11 12
32 8
5 29
30 17
23 35
34 30
12 16
4 26
20 15
22 6
32 6
21 29
33 1
10 1
3 11
14 17
29...

output:

568055158

result:

ok single line: '568055158'

Test #29:

score: 0
Accepted
time: 891ms
memory: 42124kb

input:

35 468 489443848
24 3
4 22
26 32
20 15
35 16
30 18
33 32
1 15
19 29
6 26
17 16
4 28
33 21
6 13
26 14
21 24
27 6
26 10
15 8
7 15
5 7
3 12
11 9
27 4
12 29
15 35
13 16
17 26
35 25
25 1
4 10
2 17
15 30
9 15
12 24
5 23
1 34
9 13
31 29
34 31
23 13
30 28
9 18
30 2
11 13
11 33
25 34
18 17
9 33
13 30
17 31
3...

output:

713518423

result:

ok single line: '713518423'

Test #30:

score: 0
Accepted
time: 892ms
memory: 42124kb

input:

35 366 799296863
30 11
21 9
19 26
28 5
2 34
18 31
35 6
7 6
3 2
30 4
8 12
6 4
8 34
34 31
31 26
24 29
23 14
34 23
4 21
6 22
9 31
34 14
16 6
7 12
26 28
16 20
3 13
23 24
24 3
8 35
23 9
16 19
28 23
29 8
21 26
1 17
2 35
16 2
14 11
1 33
26 13
12 25
16 5
10 13
27 15
4 18
14 10
27 6
10 5
28 16
15 6
30 18
18 ...

output:

526316962

result:

ok single line: '526316962'

Test #31:

score: 0
Accepted
time: 899ms
memory: 42172kb

input:

35 70 240439625
15 4
9 32
6 7
29 30
3 29
11 4
35 3
35 13
28 16
14 24
28 3
13 11
28 32
22 27
19 16
35 8
20 12
23 1
9 21
25 20
26 8
2 14
7 17
4 2
32 7
22 26
12 32
6 22
28 18
12 1
27 9
19 33
22 19
2 30
15 29
14 11
22 17
29 22
25 14
35 7
11 18
28 33
4 31
11 5
8 16
20 29
18 6
10 1
6 26
4 16
24 4
22 14
16...

output:

253768058

result:

ok single line: '253768058'

Test #32:

score: 0
Accepted
time: 895ms
memory: 42248kb

input:

35 37 405284183
9 18
19 15
35 30
21 3
16 21
2 15
8 27
12 24
16 14
24 35
14 10
5 3
3 24
20 4
13 7
7 30
5 17
34 30
31 4
21 33
13 28
34 27
32 13
10 6
22 1
19 20
28 34
8 18
25 14
17 27
8 33
25 26
29 14
26 8
9 6
11 12
22 3

output:

372934214

result:

ok single line: '372934214'

Test #33:

score: 0
Accepted
time: 890ms
memory: 42168kb

input:

35 76 719205944
17 1
13 25
11 34
8 24
32 16
24 33
9 21
17 21
21 3
28 17
6 32
15 29
28 13
21 8
9 20
16 19
4 6
35 14
14 11
35 9
30 18
18 23
24 19
22 17
33 14
31 1
30 4
4 8
10 14
21 33
1 18
34 12
18 27
18 6
15 20
14 18
30 12
14 17
30 23
5 27
8 3
15 28
2 29
24 21
3 30
26 21
22 32
10 7
21 10
35 12
11 27
...

output:

842468939

result:

ok single line: '842468939'

Test #34:

score: 0
Accepted
time: 905ms
memory: 42108kb

input:

35 569 429963741
34 31
2 7
17 25
24 21
29 21
4 9
1 9
28 23
10 26
1 32
7 5
11 16
9 3
25 10
21 35
25 19
6 2
25 24
18 13
10 11
12 14
27 22
19 20
8 5
3 10
17 2
32 26
23 5
30 35
33 20
33 22
3 17
9 21
29 23
32 27
27 34
3 28
23 18
20 2
12 29
9 18
21 16
12 9
6 7
31 13
1 33
28 34
30 11
7 24
27 20
32 16
9 11
...

output:

258844910

result:

ok single line: '258844910'

Test #35:

score: 0
Accepted
time: 902ms
memory: 42120kb

input:

35 146 200801667
6 12
4 11
21 2
26 2
23 32
14 34
8 10
15 18
11 24
30 18
7 14
26 12
22 23
16 12
24 18
11 13
2 5
1 16
21 28
33 14
4 28
11 7
25 12
19 3
21 30
19 23
26 30
34 30
15 9
5 23
2 22
25 5
32 33
10 11
30 23
9 26
9 21
17 11
19 7
23 29
4 16
6 1
6 21
3 7
14 27
25 32
18 31
8 13
26 11
4 20
20 34
5 7
...

output:

919806627

result:

ok single line: '919806627'

Test #36:

score: 0
Accepted
time: 903ms
memory: 42104kb

input:

35 147 617735967
7 12
34 12
22 7
17 23
10 5
7 35
7 16
19 32
15 23
23 27
16 15
15 21
18 13
18 16
35 12
5 17
1 23
1 24
13 11
21 30
17 20
12 14
9 35
34 13
30 33
10 21
34 26
30 23
4 9
19 34
9 23
11 23
35 28
8 6
30 24
20 2
7 13
32 33
17 18
35 3
21 20
26 4
34 17
30 26
12 15
12 1
17 21
17 30
28 5
20 1
25 1...

output:

426225410

result:

ok single line: '426225410'

Test #37:

score: 0
Accepted
time: 893ms
memory: 42288kb

input:

35 90 623211325
35 15
3 26
17 7
2 34
14 3
1 35
23 30
15 28
13 26
1 32
10 14
5 2
31 9
32 27
24 29
23 25
16 13
32 21
33 17
22 1
23 32
6 9
22 12
33 20
12 21
16 17
34 31
1 18
33 26
3 20
34 17
7 33
15 20
5 4
25 20
23 2
4 25
11 3
30 10
4 7
12 24
29 5
35 34
21 14
29 7
7 11
26 9
8 33
9 10
30 11
4 6
17 24
35...

output:

331767880

result:

ok single line: '331767880'

Test #38:

score: 0
Accepted
time: 900ms
memory: 42156kb

input:

35 253 829669609
30 3
27 28
26 12
9 23
22 30
34 3
17 12
35 7
16 18
4 22
14 25
35 19
4 5
13 6
33 1
25 1
33 28
27 29
14 32
30 7
7 6
28 24
16 32
20 16
35 27
5 14
7 25
22 13
28 11
32 15
30 16
34 8
27 5
21 25
8 16
13 4
15 8
32 13
8 28
35 28
16 10
17 24
22 33
28 31
1 8
31 10
16 21
5 19
4 18
3 15
21 24
16 ...

output:

46207147

result:

ok single line: '46207147'

Test #39:

score: 0
Accepted
time: 888ms
memory: 42168kb

input:

35 570 918909015
24 1
30 18
22 31
23 8
34 30
20 26
34 3
3 8
27 14
10 7
26 13
5 7
1 11
18 8
18 21
19 6
14 11
20 35
33 13
28 13
11 28
24 11
4 5
19 31
12 33
23 1
30 4
23 15
9 17
15 7
6 28
8 7
16 11
24 22
4 26
34 28
8 2
5 31
23 20
17 23
6 5
31 16
12 8
3 5
8 13
18 20
27 3
21 19
24 20
32 3
21 25
25 3
18 1...

output:

469807921

result:

ok single line: '469807921'

Test #40:

score: 0
Accepted
time: 908ms
memory: 42176kb

input:

35 129 775293489
5 25
22 26
31 32
23 4
32 8
1 29
26 2
4 11
2 12
2 24
29 21
22 34
34 12
31 3
9 15
17 4
21 19
8 26
15 17
4 25
28 14
3 7
30 18
23 31
15 30
17 31
8 23
33 9
18 15
26 6
23 5
28 3
16 18
21 33
28 27
3 23
34 33
33 35
21 6
32 35
8 16
32 16
23 22
20 31
26 15
18 24
34 10
35 6
5 27
11 26
24 7
29 ...

output:

919339893

result:

ok single line: '919339893'

Test #41:

score: 0
Accepted
time: 898ms
memory: 42136kb

input:

35 185 95250686
18 26
29 25
1 34
28 1
21 33
4 3
27 5
18 22
35 13
3 21
33 25
10 31
20 5
27 28
33 7
10 19
32 33
18 8
34 28
16 14
12 16
23 14
1 5
10 20
33 31
34 29
6 10
2 1
22 21
5 17
31 2
13 5
19 35
11 10
28 30
30 12
4 13
30 9
30 27
21 35
1 8
29 28
35 17
14 29
21 8
23 2
1 25
32 2
31 9
8 6
14 3
30 2
9 ...

output:

795926433

result:

ok single line: '795926433'

Test #42:

score: 0
Accepted
time: 905ms
memory: 42120kb

input:

35 389 720957282
8 26
25 5
21 15
12 23
3 10
19 4
26 15
13 12
9 13
33 13
13 29
28 7
22 15
13 26
18 8
32 21
4 14
30 8
5 26
29 32
28 16
5 4
10 12
32 28
27 25
15 27
35 2
17 25
16 4
11 7
22 8
12 9
5 10
28 14
11 4
26 22
12 24
11 22
25 22
28 29
31 22
13 28
4 33
1 6
6 34
20 21
18 30
29 15
6 4
27 13
29 3
11 ...

output:

637398048

result:

ok single line: '637398048'

Test #43:

score: 0
Accepted
time: 903ms
memory: 42188kb

input:

35 462 243446510
29 35
17 34
1 25
35 19
1 32
29 18
14 7
12 21
7 29
31 26
1 19
5 34
11 3
23 20
3 7
27 32
6 5
30 25
19 7
17 18
2 32
31 14
12 25
12 9
25 21
22 9
19 2
30 34
26 24
3 14
28 22
7 34
11 17
5 15
26 28
28 2
13 27
15 33
2 27
25 19
24 32
15 24
13 24
24 28
29 26
4 3
27 10
4 27
25 5
35 31
27 29
8 ...

output:

69874215

result:

ok single line: '69874215'

Test #44:

score: 0
Accepted
time: 896ms
memory: 42108kb

input:

35 113 645348377
26 23
4 22
30 6
31 12
33 12
25 7
34 17
10 32
14 21
6 12
22 23
3 9
8 7
22 30
1 4
5 25
14 30
4 2
1 22
13 22
18 35
22 24
25 19
19 2
26 25
29 7
10 5
11 14
22 11
27 18
31 17
33 1
17 16
9 1
28 21
8 17
4 3
15 28
4 17
10 14
21 4
33 32
11 10
3 22
21 25
3 6
9 16
5 34
5 29
14 4
15 31
10 4
35 2...

output:

707600894

result:

ok single line: '707600894'

Test #45:

score: 0
Accepted
time: 899ms
memory: 42104kb

input:

35 580 53683173
15 8
1 29
16 3
14 15
22 15
19 6
10 20
19 35
23 9
34 16
17 11
16 33
35 26
29 20
35 13
12 3
19 14
34 21
22 25
8 5
2 31
34 5
30 19
3 15
11 27
21 31
33 1
33 35
13 10
10 19
20 12
26 14
8 29
31 15
30 1
18 1
7 22
14 28
25 7
1 28
29 15
6 32
10 2
28 7
7 26
32 29
24 25
12 10
2 22
12 29
5 27
18...

output:

948550415

result:

ok single line: '948550415'

Test #46:

score: 0
Accepted
time: 908ms
memory: 42248kb

input:

35 0 387237811

output:

1

result:

ok single line: '1'

Test #47:

score: 0
Accepted
time: 898ms
memory: 42316kb

input:

35 595 294244417
32 23
1 29
29 7
14 2
18 17
9 6
3 6
21 34
5 14
33 5
34 6
8 19
6 10
18 6
21 25
6 24
29 18
19 5
23 7
12 33
29 24
24 35
11 33
5 20
33 22
28 26
13 14
21 7
1 30
8 6
11 5
3 33
23 24
1 32
21 33
17 28
3 23
22 9
29 15
20 23
30 27
5 2
12 15
13 25
4 35
34 10
5 18
30 33
29 21
5 24
15 32
27 32
21...

output:

381017452

result:

ok single line: '381017452'

Test #48:

score: 0
Accepted
time: 893ms
memory: 42100kb

input:

35 18 520325436
33 25
26 31
25 14
21 14
12 10
29 17
32 8
10 2
19 3
4 23
9 14
26 10
27 11
11 16
16 6
22 35
27 25
29 21

output:

866869480

result:

ok single line: '866869480'

Test #49:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

1 0 240889969

output:

1

result:

ok single line: '1'

Test #50:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

2 0 734305586

output:

1

result:

ok single line: '1'

Test #51:

score: 0
Accepted
time: 1ms
memory: 3548kb

input:

2 1 907431552
2 1

output:

907431553

result:

ok single line: '907431553'