結果

問題 No.3291 K-step Navigation
コンテスト
ユーザー miscalc
提出日時 2026-09-16 21:43:08
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 63,534 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,585 ms
コンパイル使用メモリ 411,388 KB
実行使用メモリ 10,032 KB
最終ジャッジ日時 2026-09-16 21:43:21
合計ジャッジ時間 12,133 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#define SINGLE_TESTCASE 

#define FAST_IO 

#define INF 4'000'000'000'000'000'037LL
#define EPS 1e-11

// https://github.com/miscalculation53/library/tree/wip/template/template_all.hpp

// https://github.com/miscalculation53/library/tree/wip/template/template_all_but_modint.hpp

// https://github.com/miscalculation53/library/tree/wip/template/template_types.hpp

#include <bits/stdc++.h>
using namespace std;

using ld = decltype(EPS);

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
using tllll = tuple<ll, ll, ll, ll>;

#define vc vector
template <class T>
using vvc = vc<vc<T>>;
template <class T>
using vvvc = vc<vc<vc<T>>>;

using vb = vc<bool>;
using vl = vc<ll>;
using vpll = vc<pll>;
using vtlll = vc<tlll>;
using vtllll = vc<tllll>;
using vstr = vc<string>;
using vvb = vvc<bool>;
using vvl = vvc<ll>;

template <class T>
using pql = priority_queue<T, vc<T>, greater<T>>;
template <class T>
using pqg = priority_queue<T>;

using i128 = __int128_t;
using u128 = __uint128_t;
i128 stoi128(const string &s)
{
  const bool neg = s.front() == '-';
  u128 res = 0;
  for (int i = neg; i < (int)s.size(); i++)
    res = 10 * res + s[i] - '0';
  if (neg)
    return -i128(res - 1) - 1;
  return i128(res);
}
string i128tos(i128 x)
{
  if (x == 0) return "0";
  string sign = "", res = "";
  u128 ux;
  if (x < 0)
    ux = u128(-(x + 1)) + 1, sign = "-";
  else
    ux = x;
  while (ux > 0)
  {
    res += '0' + ux % 10;
    ux /= 10;
  }
  reverse(res.begin(), res.end());
  return sign + res;
}
istream &operator>>(istream &is, i128 &a)
{
  string s;
  is >> s;
  a = stoi128(s);
  return is;
}
ostream &operator<<(ostream &os, const i128 &a)
{
  os << i128tos(a);
  return os;
}

#define cauto const auto
// https://github.com/miscalculation53/library/tree/wip/template/template_rep.hpp

#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0, nnnnn = ll(n); i < nnnnn; i++)
#define rep2(i,l,r) for (ll i = ll(l), rrrrr = ll(r); i < rrrrr; i++)
#define rep3(i,l,r,d) for (ll i = ll(l), rrrrr = ll(r), ddddd = ll(d); ddddd > 0 ? i < rrrrr : i > rrrrr; i += d)
#define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define repi1(i,n) for (int i = 0, nnnnn = int(n); i < nnnnn; i++)
#define repi2(i,l,r) for (int i = int(l), rrrrr = int(r); i < rrrrr; i++)
#define repi3(i,l,r,d) for (int i = int(l), rrrrr = int(r), ddddd = int(d); ddddd > 0 ? i < rrrrr : i > rrrrr; i += d)
#define repi(...) overload4(__VA_ARGS__, repi3, repi2, repi1)(__VA_ARGS__)

#define fe(...) for (auto __VA_ARGS__)
#define fec(...) for (cauto &__VA_ARGS__)
#define fem(...) for (auto &__VA_ARGS__)
// https://github.com/miscalculation53/library/tree/wip/template/template_math.hpp

// https://github.com/miscalculation53/library/tree/wip/utils/is_integral_ext.hpp

template <class T>
constexpr bool is_integral_ext = is_integral_v<T> || is_same_v<T, i128> || is_same_v<T, u128>;

template <class T>
constexpr bool is_signed_ext = is_signed_v<T> || is_same_v<T, i128>;

template <class T>
constexpr bool is_unsigned_ext = is_unsigned_v<T> || is_same_v<T, u128>;
// https://github.com/miscalculation53/library/tree/wip/utils/default_infty.hpp

namespace default_infty_detail
{
  template <class T, class = void>
  struct has_infty : false_type {};

  template <class T>
  struct has_infty<T, void_t<decltype(T::infty())>> : true_type {};

  template <class T>
  inline constexpr bool unsupported = false;
}

template <class T, class U>
inline bool chmin(T &a, U b) { return a > b ? a = b, true : false; }

template <class T = ll, class U, class V, typename = enable_if_t<is_integral_ext<U> && is_integral_ext<V>>>
inline constexpr T divfloor(U a, V b) { return T(a) / T(b) - (T(a) % T(b) && (T(a) ^ T(b)) < 0); }
template <class T = ll, class U, class V, typename = enable_if_t<is_integral_ext<U> && is_integral_ext<V>>>
inline constexpr T safemod(U a, V b) { return T(a) - T(b) * divfloor<T>(a, b); }

// https://github.com/miscalculation53/library/tree/wip/template/template_vector.hpp

#define ALL(a) (a).begin(), (a).end()
template <class T = ll, class V>
inline T SZ(const V &x) { return x.size(); }
#define eb emplace_back

#define LMD(x,fx) ([&](const auto &x) { return fx; })
#define GEN_VEC(n,i,fi) (gen_vec(n, LMD(i, fi)))

template <class T, size_t d, size_t i = 0, class V>
auto dvec(const V (&sz)[d], const T &init)
{
  if constexpr (i < d)
    return vc(sz[i], dvec<T, d, i + 1>(sz, init));
  else
    return init;
}

// https://github.com/miscalculation53/library/tree/wip/template/template_algo.hpp

// https://github.com/miscalculation53/library/tree/wip/utils/resolved_infty.hpp

// https://github.com/miscalculation53/library/tree/wip/utils/resolved_value.hpp

template <class V>
auto SUM(const V &v)
{
  typename V::value_type s{};
  fec(vi : v) s += vi;
  return s;
}

template <class T>
vvc<T> top(const vvc<T> &a)
{
  if (a.empty())
    return {};
  const int n = a.size(), m = a[0].size();
  vvc<T> b(m, vc<T>(n));
  repi(i, n)
  {
    assert(SZ<int>(a[i]) == m);
    repi(j, m) b[j][i] = a[i][j];
  }
  return b;
}
vstr top(const vstr &a)
{
  vvc<char> a_(a.size());
  repi(i, SZ<int>(a)) a_[i] = {ALL(a[i])};
  vvc<char> b_ = top(a_);
  vstr b(b_.size());
  repi(i, SZ<int>(b)) b[i] = {ALL(b_[i])};
  return b;
}

template <class T, class = void>
struct has_e0 : false_type {};
template <class T>
struct has_e0<T, void_t<decltype(T::e0())>> : true_type {};
template <class T>
inline constexpr bool has_e0_v = has_e0<T>::value;

template <class T>
struct MonoidAdd
{
  using S = T;
};
template <class T, auto infty = nullptr>
struct MonoidMin
{
  using S = T;
};
template <class T, auto infty = nullptr>
struct MonoidMax
{
  using S = T;
};

namespace internal
{
  template <class M, class I, class = void>
  struct HasMonoidPow : false_type
  {
  };
  template <class M, class I>
  struct HasMonoidPow<M, I, void_t<decltype(M::pow(declval<const typename M::S &>(), declval<I>()))>> : true_type
  {
  };
}

constexpr array<pll, 4> DRULgrid = {{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}};
constexpr array<pll, 4> DRULplane = {{{0, -1}, {1, 0}, {0, 1}, {-1, 0}}};
// https://github.com/miscalculation53/library/tree/wip/template/template_binsearch.hpp

template <class T>
struct is_random_access_iterator
{
  static constexpr bool value = is_same_v<
    typename iterator_traits<T>::iterator_category,
    random_access_iterator_tag
  >;
};
template <class T>
constexpr bool is_random_access_iterator_v = is_random_access_iterator<T>::value;

#define DEFAULT_COMP ranges::less

namespace internal
{
};

// https://github.com/miscalculation53/library/tree/wip/template/template_bit.hpp

template <class T>
inline constexpr ull MASK(T k) { return (1ULL << k) - 1ULL; }

inline constexpr ll bit_width(ll x) { return std::bit_width((ull)x); }

inline constexpr ll bit_floor(ll x) { return std::bit_floor((ull)x); }

inline constexpr ll bit_ceil(ll x) { return std::bit_ceil((ull)x); }
inline constexpr ll countr_zero(ll x) { assert(x != 0); return std::countr_zero((ull)x); }
inline constexpr ll popcount(ll x) { return std::popcount((ull)x); }
inline constexpr bool has_single_bit(ll x) { return std::has_single_bit((ull)x); }

inline constexpr ull lsb_pos(ull x) { assert(x != 0); return countr_zero(x); }
inline constexpr ull msb_pos(ull x) { assert(x != 0); return bit_width(x) - 1; }
inline constexpr ull lsb_mask(ull x) { assert(x != 0); return x & -x; }
inline constexpr ull msb_mask(ull x) { assert(x != 0); return bit_floor(x); }

inline constexpr bool btest(ull x, uint k) { return (x >> k) & 1; }
inline constexpr bool bsubset(ull x, ull y) { return (x & y) == x; }
inline constexpr bool bsupset(ull x, ull y) { return (x & y) == y; }
inline constexpr ull bsetminus(ull x, ull y) { return x & ~y; }
// https://github.com/miscalculation53/library/tree/wip/template/template_inout.hpp

// https://github.com/miscalculation53/library/tree/wip/template/template_dump.hpp

// https://github.com/miscalculation53/library/tree/wip/template/template_dump_map.hpp

#define CPP_DUMP_DEFINE_DATA(...) 
#define dump(...) 
#define local(...) 
#define oj(...) __VA_ARGS__
#define local_oj(a,b) (b)

namespace fastio {
template <class T>
struct unsigned_integer
{
  using type = make_unsigned_t<T>;
};
template <>
struct unsigned_integer<i128>
{
  using type = u128;
};
template <>
struct unsigned_integer<u128>
{
  using type = u128;
};
template <class T>
using unsigned_integer_t = typename unsigned_integer<T>::type;

static constexpr uint32_t SIZ = 1 << 17;
char ibuf[SIZ];
char obuf[SIZ];
char out[100];

uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SIZ - pir + pil, stdin);
  pil = 0;
  if (pir < SIZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd1(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (c <= ' ');
}

void rd1(string &x) {
  x.clear();
  while (true) {
    if (pil == pir) load();
    while (pil < pir && ibuf[pil] <= ' ') ++pil;
    if (pil < pir) break;
  }
  while (true) {
    uint32_t p = pil;
    while (pil < pir && ibuf[pil] > ' ') ++pil;
    x.append(ibuf + p, pil - p);
    if (pil < pir) {
      ++pil;
      return;
    }
    load();
  }
}

template <typename T>
void rd1_real(T &x) {
  string s;
  rd1(s);

  if constexpr (!is_same_v<T, long double>)
  {
    auto [p, ec] = from_chars(s.data(), s.data() + s.size(), x);
    if (ec == errc{} && p == s.data() + s.size()) return;
  }

  if constexpr (is_same_v<T, long double>)
    x = stold(s);
  else
    x = stod(s);
}

template <bool check_buffer = true, typename T>
void rd1_integer(T &x) {
  using U = unsigned_integer_t<T>;
  bool minus = false;
  U val = 0;
  if constexpr (check_buffer)
    if (pil + 100 > pir) load();
  uint32_t p = pil;
  while (ibuf[p] < '-') ++p;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (ibuf[p] == '-') minus = true, ++p;
  }
  while ('0' <= ibuf[p]) val = val * 10 + (ibuf[p++] & 15);
  pil = p;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>)
  {
    if (minus)
    {
      const U min_abs = U(numeric_limits<T>::max()) + 1;
      x = val == min_abs ? numeric_limits<T>::lowest() : -T(val);
    }
    else x = T(val);
  }
  else
    x = T(val);
}

void rd1(int &x) { rd1_integer(x); }
void rd1(ll &x) { rd1_integer(x); }
void rd1(i128 &x) { rd1_integer(x); }
void rd1(uint &x) { rd1_integer(x); }
void rd1(ull &x) { rd1_integer(x); }
void rd1(u128 &x) { rd1_integer(x); }
void rd1(double &x) { rd1_real(x); }
void rd1(long double &x) { rd1_real(x); }

template <class T, class U>
void rd1(pair<T, U> &p) {
  return rd1(p.first), rd1(p.second);
}

template <class T>
void rd1(vc<T> &x) {
  for (auto &d: x) rd1(d);
}

template <class... T>
void read(T &...x) {
  if constexpr (sizeof...(T) <= SIZ / 100 &&
                ((!is_same_v<T, char> &&
                  (is_integral_v<T> || is_same_v<T, i128> || is_same_v<T, u128>)) && ...)) {
    if (pil + 100 * sizeof...(T) > pir) load();
    (rd1_integer<false>(x), ...);
  }
  else
    (rd1(x), ...);
}

void wt1(const char c) {
  if (por == SIZ) flush();
  obuf[por++] = c;
}
void wt1(string_view s) {
  while (!s.empty()) {
    if (por == SIZ) flush();
    size_t n = min<size_t>(s.size(), SIZ - por);
    memcpy(obuf + por, s.data(), n);
    por += n;
    s.remove_prefix(n);
  }
}

template <typename T>
void wt1_integer(T x) {
  if (por > SIZ - 100) flush();
  using U = unsigned_integer_t<T>;
  U ux;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>)
  {
    if (x < 0)
      obuf[por++] = '-', ux = U(0) - U(x);
    else
      ux = U(x);
  }
  else
    ux = x;
  int outi;
  for (outi = 96; ux >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[ux % 10000], 4);
    ux /= 10000;
  }
  if (ux >= 1000) {
    memcpy(obuf + por, pre.num[ux], 4);
    por += 4;
  } else if (ux >= 100) {
    memcpy(obuf + por, pre.num[ux] + 1, 3);
    por += 3;
  } else if (ux >= 10) {
    int q = (ux * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (ux - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = ux | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt1_real(T x) {

  if constexpr (!is_same_v<T, long double>)
  {
    auto [p, ec] = to_chars(out, out + sizeof(out), x, chars_format::fixed, 15);
    if (ec == errc{}) {
      wt1(string_view(out, p));
      return;
    }
  }

  ostringstream oss;
  oss << fixed << setprecision(15) << x;
  wt1(oss.str());
}

void wt1(int x) { wt1_integer(x); }
void wt1(i128 x) { wt1_integer(x); }
void wt1(u128 x) { wt1_integer(x); }
void wt1(double x) { wt1_real(x); }
void wt1(long double x) { wt1_real(x); }

template <class... T>
void write(T &&...x) {
  (wt1(std::forward<T>(x)), ...);
}

template <class... T>
void print(T &&...x) {
  if constexpr (sizeof...(T))
  {
    int i = 0;
    ((i++ ? wt1(' ') : void(), wt1(std::forward<T>(x))), ...);
  }
  wt1('\n');
}

} 

struct Dummy {
  Dummy() { atexit(fastio::flush); }
} dummy;

namespace internal
{

template <class... Ts>
void READnodump(Ts &...a) { fastio::read(a...); }

template <class... T>
void READVECnodump(int n, vc<T> &...v)
{
  (v.resize(n), ...);
  READnodump(v...);
}

}; 

#define READ(...) internal::READnodump(__VA_ARGS__); dump(__VA_ARGS__)

#define IN(T,...) T __VA_ARGS__; READ(__VA_ARGS__)

#define CHAR(...) IN(char, __VA_ARGS__)
#define INT(...) IN(int, __VA_ARGS__)
#define LL(...) IN(ll, __VA_ARGS__)
#define STR(...) IN(string, __VA_ARGS__)
#define ARR(T,n,...) array<T, n> __VA_ARGS__; READ(__VA_ARGS__)

#define READVEC(...) internal::READVECnodump(__VA_ARGS__); dump(__VA_ARGS__)
#define READVEC2(...) internal::READVEC2nodump(__VA_ARGS__); dump(__VA_ARGS__)

#define VEC(T,n,...) vc<T> __VA_ARGS__; READVEC(n, __VA_ARGS__)
#define VEC2(T,n,m,...) vvc<T> __VA_ARGS__; READVEC2(n, m, __VA_ARGS__)

#define READJAG(...) internal::READJAGnodump(__VA_ARGS__); dump(__VA_ARGS__)

#define JAG(T,n,...) vvc<T> __VA_ARGS__; READJAG(n, __VA_ARGS__)

#define ENDL '\n'

#define WRITE fastio::write
#define PRINT fastio::print

#define PRINTEXIT(...) do { PRINT(__VA_ARGS__); exit(0); } while (false)
#define PRINTRETURN(...) do { PRINT(__VA_ARGS__); return; } while (false)

#define PRINTVEXIT(...) do { PRINTV(__VA_ARGS__); exit(0); } while (false)
#define PRINTVRETURN(...) do { PRINTV(__VA_ARGS__); return; } while (false)

template <class T, class U, class P>
pair<T, U> &operator+=(pair<T, U> &a, const P &b)
{
  a.first += b.first;
  a.second += b.second;
  return a;
}

namespace internal
{

}; 

template <class T, class Add>
void offset(vc<T> &v, const Add &add) { for (auto &vi : v) vi += add; }

namespace internal
{

};

#define UNZIP(vt,...) auto [__VA_ARGS__] = unzip(vt)
#define ZIP(vt,...) auto vt = zip(tuple{__VA_ARGS__})

// https://github.com/miscalculation53/library/tree/wip/template/template_random.hpp

mt19937_64 mt;

bool randbool(double p)
{
  assert(0 <= p && p <= 1);
  return bernoulli_distribution(p)(mt);
}

namespace internal
{
}; 

// https://github.com/miscalculation53/library/tree/wip/math/modint/template_modint.hpp

// https://github.com/miscalculation53/library/tree/wip/math/modint/modint.hpp

// https://github.com/miscalculation53/library/tree/wip/math/modint/modint_internal_static.hpp

// https://github.com/miscalculation53/library/tree/wip/utils/larger_int.hpp

namespace larger_int_detail
{
}

template <class T>
struct larger_int
{
private:
  static constexpr bool check();
  static_assert(check());

public:
  using type = T;
};

#define LARGER_INT(T,U) template <> struct larger_int<T> { using type = U; };

LARGER_INT(signed char, short)
LARGER_INT(short, int)
LARGER_INT(int, long long)
LARGER_INT(long, __int128_t)
LARGER_INT(long long, __int128_t)

LARGER_INT(unsigned char, unsigned short)
LARGER_INT(unsigned short, unsigned int)
LARGER_INT(unsigned int, unsigned long long)
LARGER_INT(unsigned long, __uint128_t)
LARGER_INT(unsigned long long, __uint128_t)

#undef LARGER_INT

template <class T>
struct Rational;

template <class T>
struct larger_int<Rational<T>>
{
  using type = Rational<typename larger_int<T>::type>;
};

template <class T>
using larger_int_t = typename larger_int<T>::type;
// https://github.com/miscalculation53/library/tree/wip/math/modint/modint_internal_isprime.hpp

namespace internal
{

template <class T>
constexpr ll powmod_constexpr(ll x, ll n, T m)
{
  if (m == 1)
    return 0;
  using U = make_unsigned_t<T>;
  using L = larger_int_t<U>;

  U r = 1, y = safemod(x, m);
  while (n)
  {
    if (n & 1)
      r = L(r) * y % m;
    y = L(y) * y % m;
    n >>= 1;
  }
  return r;
}

template <class T>
constexpr bool isprime_constexpr(T n)
{
  if constexpr (sizeof(T) > 4)
  {
    if (n <= INT_MAX)
      return isprime_constexpr<int>(n);
  }

  if (n <= 1)
    return false;
  if (n == 2 || n == 7 || n == 61)
    return true;
  if (n % 2 == 0)
    return false;

  ll d = n - 1;
  while (d % 2 == 0)
    d /= 2;

  using U = make_unsigned_t<T>;
  using L = larger_int_t<U>;

  auto miller_rabin = [&](const auto &bases) constexpr
  {
    for (ll a : bases)
    {
      ll t = d, y = powmod_constexpr(a, t, n);
      while (t != n - 1 && y != 1 && y != n - 1)
      {
        y = L(y) * y % n;
        t <<= 1;
      }
      if (y != n - 1 && t % 2 == 0)
        return false;
    }
    return true;
  };

  if constexpr(sizeof(T) <= 4)
  {
    constexpr ll bases[3] = {2, 7, 61};
    return miller_rabin(bases);
  }
  else
  {
    constexpr ll bases[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    return miller_rabin(bases);
  }
}

template <auto n>
constexpr bool isprime = isprime_constexpr(n);

};

namespace internal
{

template <auto M>
struct policy_static
{
  using mod_type = decltype(M);
  using value_type = make_unsigned_t<mod_type>;
  using calc_type = larger_int_t<value_type>;

  static constexpr bool is_prime = isprime_constexpr(M);

  static constexpr mod_type mod() { return M; }
  static constexpr value_type umod() { return M; }

  static constexpr value_type init(value_type v) { return v; }
  static constexpr mod_type val(value_type v) { return v; }
  static constexpr value_type mul(value_type a, value_type b)
  {
    return (value_type)((calc_type(a) * b) % M);
  }
};

};
// https://github.com/miscalculation53/library/tree/wip/math/modint/modint_internal_barrett32.hpp

namespace internal
{

struct barrett32
{
  uint m;
  ull im;
  explicit barrett32(uint m) : m(m), im((ull)(-1) / m + 1) {}
  uint umod() const { return m; }
  uint mul(uint a, uint b) const
  {
    ull z = a;
    z *= b;
    ull x = ull((u128(z) * im) >> 64);
    ull y = x * m;
    return uint(z - y + (z < y ? m : 0));
  }
};

template <int id>
struct policy_barrett32
{
  using value_type = uint;
  using calc_type = ull;
  using mod_type = int;
  
  static constexpr bool is_prime = false;
  static inline barrett32 reducer{998244353};
  static void set_mod(mod_type m) { reducer = barrett32(m); }
  static mod_type mod() { return reducer.umod(); }
  static value_type umod() { return reducer.umod(); }
  static value_type init(value_type v) { return v; }
  static mod_type val(value_type v) { return v; }
  static value_type mul(value_type a, value_type b) { return reducer.mul(a, b); }
};

};
// https://github.com/miscalculation53/library/tree/wip/math/modint/modint_internal_montgomery64.hpp

namespace internal
{

inline constexpr ull inv64(ull a)
{
  ull x = a;
  while (a * x != 1) x *= 2 - a * x;
  return x;
}

struct montgomery64odd
{
  ull m, im, sq;
  explicit montgomery64odd(ull m) : m(m), im(inv64(m)), sq(-u128(m) % m) {}
  ull umod() const { return m; }
  ull reduce(u128 x) const
  {
    auto t = (x + u128(m) * (-im * ull(x))) >> 64;
    if (t >= m) t -= m;
    return (ull)t;
  }
  ull inv_reduce(i128 v) const { return reduce(u128(v % m + m) * sq); }
};

struct montgomery64
{
  ull m, mx, imx, d, q;
  uint b;
  explicit montgomery64(ull m) : m(m)
  {
    b = countr_zero(m), mx = m >> b; 
    imx = inv64(mx);
    d = powmod_constexpr((mx + 1) / 2, b, mx); 
    u128 sq = -u128(mx) % mx; 
    q = (1 + (((sq - 1) * d) << b)) % m;
  }
  ull umod() const { return m; }
  ull reduce(u128 x) const
  {
    if (b == 0)
    {
      auto t = (x + u128(mx) * (-imx * ull(x))) >> 64;
      if (t >= m) t -= m;
      return (ull)t;
    }
    ull p = x & MASK(b); 
    x = (x >> b) + p * d;
    ull y = p << (64 - b);
    auto t = (x + u128(mx) * (imx * (y - ull(x)))) >> (64 - b);
    if (t >= m) { t -= m; if (t >= m) t -= m; }
    return (ull)t;
  }
  ull inv_reduce(i128 v) const { return reduce(u128(v % m + m) * q); }
};

template <int id>
struct policy_montgomery64_odd
{
  using value_type = ull;
  using calc_type = u128;
  using mod_type = ll;

  static constexpr bool is_prime = false;
  static inline montgomery64odd reducer{(1LL << 61) - 1};
  static void set_mod(mod_type m) { reducer = montgomery64odd(m); }
  static mod_type mod() { return reducer.umod(); }
  static value_type umod() { return reducer.umod(); }
  static value_type init(value_type v) { return reducer.inv_reduce(v); }
  static mod_type val(value_type v) { return reducer.reduce(v); }
  static value_type mul(value_type a, value_type b) { return reducer.reduce((calc_type)a * b); }
};

template <int id>
struct policy_montgomery64
{
  using value_type = ull;
  using calc_type = u128;
  using mod_type = ll;

  static constexpr bool is_prime = false;
  static inline montgomery64 reducer{(1LL << 61) - 1};
  static mod_type mod() { return reducer.umod(); }
  static value_type umod() { return reducer.umod(); }
  static value_type init(value_type v) { return reducer.inv_reduce(v); }
  static mod_type val(value_type v) { return reducer.reduce(v); }
};

};
// https://github.com/miscalculation53/library/tree/wip/math/extgcd.hpp

template <class T = ll>
constexpr tuple<T, T, T> extgcd(T a, T b)
{
  if (a == 0 && b == 0)
    return {0, 0, 0};
  
  T x1 = 1, y1 = 0, z1 = a;
  T x2 = 0, y2 = 1, z2 = b;
  while (z2 != 0)
  {
    
    T q = z1 / z2;
    tie(x1, x2) = make_pair(x2, x1 - q * x2);
    tie(y1, y2) = make_pair(y2, y1 - q * y2);
    tie(z1, z2) = make_pair(z2, z1 - q * z2);
  }
  if (z1 < 0)
    x1 = -x1, y1 = -y1, z1 = -z1;
  return {z1, x1, y1};
}

namespace internal
{

  template <class Policy>
  struct modint_impl
  {
    using V = typename Policy::value_type;
    using M = typename Policy::mod_type;
    using mint = modint_impl;

  private:
    V _v;

  public:
    static constexpr M mod() { return Policy::mod(); }

    template <class T = Policy>
    static auto set_mod(M m) -> decltype(T::set_mod(m)) { return T::set_mod(m); }

    static mint raw(V v)
    {
      mint x;
      x._v = v;
      return x;
    }

    modint_impl() : _v(0) {}

    template <class T, typename = enable_if_t<is_integral_ext<T>>>
    modint_impl(T v)
    {
      V rem;
      if constexpr (is_signed_ext<T>)
      {
        using S = make_signed_t<V>;
        S x = v % S(Policy::umod());
        if (x < 0)
          x += Policy::umod();
        rem = x;
      }
      else
        rem = V(v % Policy::umod());
      _v = Policy::init(rem);
    };

    M val() const { return Policy::val(_v); }

    mint &operator+=(const mint &rhs)
    {
      _v += rhs._v;
      if (_v >= Policy::umod())
        _v -= Policy::umod();
      return *this;
    }
    mint &operator-=(const mint &rhs)
    {
      _v -= rhs._v;
      if (_v >= Policy::umod())
        _v += Policy::umod();
      return *this;
    }
    mint &operator*=(const mint &rhs)
    {
      _v = Policy::mul(_v, rhs._v);
      return *this;
    }
    mint &operator/=(const mint &rhs)
    {
      return *this *= rhs.inv();
    }

    mint operator-() const { return mint() - *this; }

    template <class T>
    mint pow(T n) const
    {
      assert(n >= 0);
      mint x = *this, r = 1;
      while (n)
      {
        if (n & 1)
          r *= x;
        x *= x;
        n >>= 1;
      }
      return r;
    }
    mint inv() const
    {
      if constexpr (Policy::is_prime)
      {
        return pow(mod() - 2);
      }
      else
      {
        auto [g, x, y] = extgcd<M>(val(), mod());
        assert(g == 1);
        return mint(x);
      }
    }

    friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
    friend bool operator==(const mint &lhs, const mint &rhs) { return lhs._v == rhs._v; }
    friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs._v != rhs._v; }
    friend M safe_hash_key(const mint &x) { return x.val(); }
  
    friend void rd1(mint &x)
    {
      long long a;
      fastio::rd1(a);
      x = a;
    }
    friend void wt1(const mint &x)
    {
      fastio::wt1(x.val());
    }

  };

};

template <int mod>
using static_modint32 = internal::modint_impl<internal::policy_static<mod>>;
template <int id>
using dynamic_modint32 = internal::modint_impl<internal::policy_barrett32<id>>;
template <ll mod>
using static_modint64 = internal::modint_impl<internal::policy_static<mod>>;
template <int id>
using dynamic_modint64_odd = internal::modint_impl<internal::policy_montgomery64_odd<id>>;
template <int id>
using dynamic_modint64 = internal::modint_impl<internal::policy_montgomery64<id>>;

using modint998244353 = static_modint32<998244353>;
using modint1000000007 = static_modint32<1000000007>;
using modint = dynamic_modint32<-1>;
using modint61 = static_modint64<(1LL << 61) - 1>;
using modint64 = dynamic_modint64<-1>;

template <class T>
struct is_modint : std::false_type
{
};
template <class Policy>
struct is_modint<internal::modint_impl<Policy>> : std::true_type
{
};
template <class T>
inline constexpr bool is_modint_v = is_modint<T>::value;

template <class T>
struct is_static_modint : false_type {};
template <int m>
struct is_static_modint<static_modint32<m>> : true_type {};
template <ll m>
struct is_static_modint<static_modint64<m>> : true_type {};
template <class T>
inline constexpr bool is_static_modint_v = is_static_modint<T>::value;

template <class T>
struct is_dynamic_modint : false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint32<id>> : true_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint64_odd<id>> : true_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint64<id>> : true_type {};
template <class T>
inline constexpr bool is_dynamic_modint_v = is_dynamic_modint<T>::value;

template <typename, typename = void>
struct has_mod : std::false_type
{
};
template <typename T>
struct has_mod<T, std::void_t<decltype(T::mod())>> : std::true_type
{
};

template <class mint>
struct modint_less
{
};

template <class mint>
struct modint_hash
{
};
// https://github.com/miscalculation53/library/tree/wip/math/modint/power_table.hpp

template <class mint>
struct PowerTable
{
private:
  decltype(mint::mod()) mod;
  mint base;
  vc<mint> pw;

public:

  void reserve(int n)
  {
    if (mod != mint::mod())
    {
      mod = mint::mod();
      pw = {1};
    }
    int i = pw.size();
    if (n < i)
      return;
    pw.resize(n + 1);
    for (; i <= n; i++)
      pw[i] = pw[i - 1] * base;
  }

};
// https://github.com/miscalculation53/library/tree/wip/math/modint/binomial.hpp

template <class T>
struct Binomial
{
private:
  inline static decltype(T::mod()) mod;
  
public:
  inline static vc<T> fac_, finv_, inv_;
  static void reserve(int n)
  {
    if constexpr (is_dynamic_modint_v<T>)
    {
      if (mod != T::mod())
      {
        mod = T::mod();
        fac_ = {1, 1}, finv_ = {1, 1}, inv_ = {0, 1};
      }
    }
    else
    {
      if (fac_.empty())
        fac_ = {1, 1}, finv_ = {1, 1}, inv_ = {0, 1};
    }
    if (n < SZ(fac_))
      return;
    chmin(n, T::mod() - 1);
    int si = fac_.size();
    fac_.resize(n + 1), finv_.resize(n + 1), inv_.resize(n + 1);
    repi(i, si, n + 1)
    {
      fac_[i] = fac_[i - 1] * T::raw(i);
      inv_[i] = -inv_[T::mod() % i] * T::raw(T::mod() / i);
      finv_[i] = finv_[i - 1] * inv_[i];
    }
  }
  static T inv(int n)
  {
    n %= T::mod();
    if (n < 0)
      n += T::mod();
    assert(n != 0);
    reserve(n);
    return inv_[n];
  }

};
// https://github.com/miscalculation53/library/tree/wip/math/modint/stom.hpp

// https://github.com/miscalculation53/library/tree/wip/math/modint/to_rational.hpp

// https://github.com/miscalculation53/library/tree/wip/math/svp2d.hpp

namespace cpp_dump
{
  template <class T>
  struct rat_value
  {
    T p, q;

    friend ostream &operator<<(ostream &os, const rat_value &x)
    {
      os << x.p;
      if (x.q != 1)
        os << '/' << x.q;
      return os;
    }
  };

  struct mint_to_rat_fn
  {
  };

  template <class T>
  struct rat_object
  {
    T value;
  };

  template <class T>
  inline constexpr bool rat_is_map = false;
  template <class... Args>
  inline constexpr bool rat_is_map<std::map<Args...>> = true;
  template <class... Args>
  inline constexpr bool rat_is_map<std::multimap<Args...>> = true;
  template <class... Args>
  inline constexpr bool rat_is_map<std::unordered_map<Args...>> = true;
  template <class... Args>
  inline constexpr bool rat_is_map<std::unordered_multimap<Args...>> = true;

  struct rat_closure : std::ranges::range_adaptor_closure<rat_closure>
  {

  };

  constexpr rat_closure rat()
  {
    return rat_closure{};
  }
}

using mint = static_modint32<846862693>;

using bi = Binomial<mint>;

void init()
{
  oj(mt.seed(random_device()()));
}

// https://github.com/miscalculation53/library/tree/wip/graph/graph.hpp

// https://github.com/miscalculation53/library/tree/wip/ds/csr.hpp

template <class T, bool is_erasable = false>
struct CSR
{
protected:
  int n, m;
  
  vc<int> start;
  vc<T> elist;
  vc<int> len;

  template <class Iter>
  struct RowBase
  {
    using iterator = Iter;
    using reference = typename iterator_traits<iterator>::reference;

  private:
    iterator begi, endi;

  public:
    inline iterator begin() const { return begi; }
    template <class I = ll>
    inline I size() const { return endi - begi; }
    inline bool empty() const { return size() == 0; }

  };
  using Row = RowBase<typename vc<T>::iterator>;
  using ConstRow = RowBase<typename vc<T>::const_iterator>;

public:
  
  template <class I = ll>
  I size() const { return n; }

  vc<T> &get_elist() { return elist; }
  const vc<T> &get_elist() const { return elist; }
};

template <class Cost = void>
struct Edge
{
  int from, to;
  Cost cost;
  int index;
  CPP_DUMP_DEFINE_DATA(from, to, cost, index);
  
};

template <>
struct Edge<void>
{
  int from, to, index;
  static constexpr ll cost = 1;
  CPP_DUMP_DEFINE_DATA(from, to, cost, index);
  Edge() : from(-1), to(-1), index(-1) {}
  Edge(int s, int t, int i = -1) : from(s), to(t), index(i) {}
  operator int() const { return to; }
  bool operator<(const Edge &) const { return false; }
  Edge rev() const { return Edge(to, from, index); }
};

template <bool is_directed, class Cost = void, bool is_erasable = false>
struct Graph
{
  using E = Edge<Cost>;

protected:
  template <class C, bool unweighted = is_void_v<C>>
  struct InternalEdge
  {
    int to, index;
    C cost;
  };
  template <class C>
  struct InternalEdge<C, true>
  {
    int to, index;
    static constexpr ll cost = 1;
  };
  using GE = conditional_t<is_erasable, E, InternalEdge<Cost>>;
  using Weight = decay_t<decltype(E::cost)>;

  int n = 0, m = 0, era = 0;
  CSR<GE, is_erasable> g;
  vc<int> eid_to_elist_id;

  static E make_edge(int from, int to, const Weight &cost, int index)
  {
    if constexpr (is_void_v<Cost>)
      return E(from, to, index);
    else
      return E(from, to, cost, index);
  }

  struct OutEdgeRow;
  struct OutEdgeIter
  {
    using iterator_category = input_iterator_tag;
    using value_type = E;
    using difference_type = ptrdiff_t;
    using pointer = const E *;
    using reference = const E &;

  private:
    friend struct OutEdgeRow;
    int from = -1;
    typename vc<GE>::const_iterator it;
    mutable E e;

  public:
    OutEdgeIter() = default;
    reference operator*() const
    {
      if constexpr (is_erasable)
        return *it;
      else
      {
        e = make_edge(from, it->to, it->cost, it->index);
        return e;
      }
    }
  };

  struct OutEdgeRow
  {
  private:
    const Graph *g;
    int from, l, r;

    OutEdgeIter iter(int pos) const
    {
      return {from, g->g.get_elist().begin() + pos};
    }

  public:
    OutEdgeIter begin() const { return iter(l); }
    template <class I = ll>
    I size() const { return r - l; }
    bool empty() const { return l == r; }
  };

public:

  template <class I = ll>
  I size() const { return n; }
  
private:
};

template <bool is_directed, bool is_erasable = false, class I>
Graph(int, const vc<pair<I, I>> &) -> Graph<is_directed, void, is_erasable>;
template <bool is_directed, bool is_erasable = false, class I, class Cost>
Graph(int, const vc<tuple<I, I, Cost>> &) -> Graph<is_directed, Cost, is_erasable>;
template <bool is_directed, bool is_erasable = false, class I, class Cost>
Graph(int, const vc<pair<I, I>> &, const Cost &) -> Graph<is_directed, Cost, is_erasable>;
template <bool is_directed, bool is_erasable = false, class Cost>
Graph(int, const vc<Edge<Cost>> &) -> Graph<is_directed, Cost, is_erasable>;

template <class Cost = void, bool is_erasable = false>
using GraphDirected = Graph<true, Cost, is_erasable>;
template <class Cost = void, bool is_erasable = false>
using GraphUndirected = Graph<false, Cost, is_erasable>;

// https://github.com/miscalculation53/library/tree/wip/math/fps/bmbm.hpp

// https://github.com/miscalculation53/library/tree/wip/math/fps/berlekamp_massey.hpp

// https://github.com/miscalculation53/library/tree/wip/algebra/algebra_basic_ops.hpp

// https://github.com/miscalculation53/library/tree/wip/algebra/algebra_base.hpp

template <class S_, auto op_, auto e_>
struct Monoid
{
  using S = S_;
  static constexpr auto op = op_;
  static constexpr auto e = e_;
};

template <class S_, auto op_, auto e_, auto inv_>
struct Group
{
  using S = S_;
  static constexpr auto op = op_;
  static constexpr auto e = e_;
  static constexpr auto inv = inv_;
};

template <class S_, auto add_, auto e0_, auto mul_, auto e1_>
struct SemiRing
{
  using S = S_;
  static constexpr auto add = add_;
  static constexpr auto e0 = e0_;
  static constexpr auto mul = mul_;
  static constexpr auto e1 = e1_;
};

template <class S_, auto add_, auto e0_, auto minus_, auto mul_, auto e1_>
struct Ring
{
  using S = S_;
  static constexpr auto add = add_;
  static constexpr auto e0 = e0_;
  static constexpr auto minus = minus_;
  static constexpr auto mul = mul_;
  static constexpr auto e1 = e1_;
};

template <class S_, auto add_, auto e0_, auto minus_, auto mul_, auto e1_, auto inv_>
struct Field
{
  using S = S_;
  static constexpr auto add = add_;
  static constexpr auto e0 = e0_;
  static constexpr auto minus = minus_;
  static constexpr auto mul = mul_;
  static constexpr auto e1 = e1_;
  static constexpr auto inv = inv_;
};

template <class M>
struct OppositeMonoid
{
  using S = typename M::S;
  static constexpr auto e = M::e;
};
template <class G>
struct OppositeGroup
{
  using S = typename G::S;
  static constexpr auto e = G::e;
  static constexpr auto inv = G::inv;
};
template <class M>
struct NormalAndOppositeMonoid
{
  struct S
  {
    typename M::S normal;
    typename M::S opposite;
  };
};
template <class G>
struct NormalAndOppositeGroup
{
  struct S
  {
    typename G::S normal;
    typename G::S opposite;
  };
  static constexpr S inv(const S &a) { return {G::inv(a.normal), G::inv(a.opposite)}; }
};

template <class SR>
using MonoidOfSemiRingAdd = Monoid<typename SR::S, SR::add, SR::e0>;
template <class SR>
using MonoidOfSemiRingMul = Monoid<typename SR::S, SR::mul, SR::e1>;
template <class R>
using GroupOfRingAdd = Group<typename R::S, R::add, R::e0, R::minus>;
template <class K>
using GroupOfFieldMul = Group<typename K::S, K::mul, K::e1, K::inv>;

template <class Madd, class Mmul>
struct SemiRingFromMonoidMonoid
{
  static_assert(is_same_v<typename Madd::S, typename Mmul::S>, "Madd::S and Mmul::S must be identical");
  using S = typename Madd::S;
  static constexpr auto add = Madd::op;
  static constexpr auto e0 = Madd::e;
  static constexpr auto mul = Mmul::op;
  static constexpr auto e1 = Mmul::e;
};

template <class Gadd, class Mmul>
struct RingFromGroupMonoid
{
  static_assert(is_same_v<typename Gadd::S, typename Mmul::S>, "Gadd::S and Mmul::S must be identical");
  using S = typename Gadd::S;
  static constexpr auto add = Gadd::op;
  static constexpr auto e0 = Gadd::e;
  static constexpr auto minus = Gadd::inv;
  static constexpr auto mul = Mmul::op;
  static constexpr auto e1 = Mmul::e;
};

template <class Gadd, class Gmul>
struct FieldFromGroupGroup
{
  static_assert(is_same_v<typename Gadd::S, typename Gmul::S>, "Gadd::S and Gmul::S must be identical");
  using S = typename Gadd::S;
  static constexpr auto add = Gadd::op;
  static constexpr auto e0 = Gadd::e;
  static constexpr auto minus = Gadd::inv;
  static constexpr auto mul = Gmul::op;
  static constexpr auto e1 = Gmul::e;
  static constexpr auto inv = Gmul::inv;
};

template <class T, class = void>
struct has_e1 : false_type {};
template <class T>
struct has_e1<T, void_t<decltype(T::e1())>> : true_type {};
template <class T>
inline constexpr bool has_e1_v = has_e1<T>::value;

template <class T>
struct MonoidMul
{
  using S = T;
  static constexpr S op(S a, S b) { return a * b; }
  static constexpr S e()
  {
    if constexpr (has_e1_v<S>)
      return S::e1();
    else
      return 1;
  }
};

template <class T>
struct GroupAddSub
{
  using S = T;
  static constexpr S op(S a, S b) { return a + b; }
  static constexpr S e()
  {
    if constexpr (has_e0_v<S>)
      return S::e0();
    else
      return S{};
  }
  static constexpr S inv(S a) { return -a; }
};
template <class T>
struct GroupMulDiv
{
  using S = T;
  static constexpr S op(S a, S b) { return a * b; }
  static constexpr S e()
  {
    if constexpr (has_e1_v<S>)
      return S::e1();
    else
      return S(1);
  }
  static constexpr S inv(S a) { return e() / a; }
};

template <class T, auto infty = nullptr>
using SemiRingMinPlus = SemiRingFromMonoidMonoid<MonoidMin<T, infty>, MonoidAdd<T>>;
template <class T, auto infty = nullptr>
using SemiRingMaxPlus = SemiRingFromMonoidMonoid<MonoidMax<T, infty>, MonoidAdd<T>>;
template <class T>
using RingAddSubMul = RingFromGroupMonoid<GroupAddSub<T>, MonoidMul<T>>;
template <class T>
using FieldAddSubMulDiv = FieldFromGroupGroup<GroupAddSub<T>, GroupMulDiv<T>>;
// https://github.com/miscalculation53/library/tree/wip/math/dot_product.hpp

// https://github.com/miscalculation53/library/tree/wip/math/modint/internal_mod32.hpp

namespace internal
{

template <class S>
struct ordinary_mod32 : false_type {};
template <int mod>
struct ordinary_mod32<static_modint32<mod>> : true_type {};
template <int id>
struct ordinary_mod32<dynamic_modint32<id>> : true_type {};

template <class G>
struct ordinary_mod32_add_group : false_type {};
template <class S>
struct ordinary_mod32_add_group<GroupAddSub<S>> : ordinary_mod32<S> {};
template <class S>
struct ordinary_mod32_add_group<Group<S, GroupAddSub<S>::op, GroupAddSub<S>::e, GroupAddSub<S>::inv>>
    : ordinary_mod32<S> {};

template <class F>
struct ordinary_mod32_field : false_type {};
template <class S>
struct ordinary_mod32_field<FieldAddSubMulDiv<S>> : ordinary_mod32<S> {};
}

namespace internal
{
template <class S>
using dot_product_mod32_value = ordinary_mod32<S>;

template <class SR>
struct dot_product_mod32 : false_type {};
template <class S>
struct dot_product_mod32<FieldAddSubMulDiv<S>> : dot_product_mod32_value<S> {};
template <class S>
struct dot_product_mod32<RingAddSubMul<S>> : dot_product_mod32_value<S> {};
template <class S>
struct dot_product_mod32<SemiRingFromMonoidMonoid<MonoidAdd<S>, MonoidMul<S>>>
    : dot_product_mod32_value<S> {};

template <int block, class S, class It1, class It2>
S dot_product_mod32_impl(int n, It1 a, It2 b)
{
  const ull mod = S::mod();
  ull sum = 0;
  for (; n >= block; n -= block)
  {
    repi(j, block) sum += ull((a++)->val()) * (b++)->val();
    sum %= mod;
  }
  repi(j, n) sum += ull((a++)->val()) * (b++)->val();
  return S::raw(sum % mod);
}
} 

template <class SR, class It1, class It2>
typename SR::S dot_product(int n, It1 a, It2 b)
{
  using S = typename SR::S;
  assert(n >= 0);
  if constexpr (internal::dot_product_mod32<SR>::value)
  {
    
    if (S::mod() <= (1 << 30))
      return internal::dot_product_mod32_impl<16, S>(n, a, b);
    return internal::dot_product_mod32_impl<4, S>(n, a, b);
  }
  else
  {
    S sum = SR::e0();
    repi(i, n) sum = SR::add(sum, SR::mul(*a++, *b++));
    return sum;
  }
}

template <class F>
struct BerlekampMassey
{
  using S = typename F::S;
  vc<S> a, b, c, tmp;
  int pos = -1;
  S inv_x = F::e0();

  void append(S value)
  {
    const int i = a.size(), d = c.size();
    a.eb(value);
    S y = F::add(value, F::minus(dot_product<F>(d, c.begin(), a.rbegin() + 1)));
    if (y == F::e0())
      return;
    
    if (c.empty())
    {
      c.assign(i + 1, F::e0());
      pos = i;
      inv_x = F::inv(y);
      return;
    }

    S z = F::mul(y, inv_x);
    int d2 = i - pos + b.size();
    if (d2 > d)
    {
      tmp = c;
      c.resize(d2, F::e0());
    }
    c[i - 1 - pos] = F::add(c[i - 1 - pos], z);
    const S minus_z = F::minus(z);
    repi(j, b.size()) c[i - pos + j] = F::add(c[i - pos + j], F::mul(minus_z, b[j]));
    if (d2 > d)
      pos = i, inv_x = F::inv(y), swap(tmp, b);
  }

  vc<S> coefficients() const
  {
    vc<S> res;
    res.reserve(c.size() + 1);
    res.eb(F::minus(F::e1()));
    res.insert(res.end(), c.begin(), c.end());
    return res;
  }
};

template <class F>
vc<typename F::S> berlekamp_massey(const vc<typename F::S> &a)
{
  BerlekampMassey<F> bm;
  bm.a.reserve(a.size());
  for (const auto &x : a) bm.append(x);
  return bm.coefficients();
}
// https://github.com/miscalculation53/library/tree/wip/math/fps/bostan_mori.hpp

// https://github.com/miscalculation53/library/tree/wip/bit/bit_reverse.hpp

uint32_t bit_reverse32(uint32_t x)
{
  x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1);
  x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2);
  x = ((x & 0x0F0F0F0F) << 4) | ((x & 0xF0F0F0F0) >> 4);
  x = ((x & 0x00FF00FF) << 8) | ((x & 0xFF00FF00) >> 8);
  return (x << 16) | (x >> 16);
}

int bitrev(int pw2, int i)
{
  assert(pw2 > 0 && has_single_bit((uint)pw2));
  assert(0 <= i && i < pw2);
  if (pw2 == 1)
    return 0;
  return bit_reverse32(i) >> (32 - countr_zero((uint)pw2));
}
// https://github.com/miscalculation53/library/tree/wip/math/fps/fps.hpp

// https://github.com/miscalculation53/library/tree/wip/math/convolution/convolution.hpp

// https://github.com/miscalculation53/library/tree/wip/math/crt.hpp

template <class mint, class U1, class U2, size_t n>
constexpr pair<mint, mint> crt_mod_constexpr(const array<U1, n> &rs, const array<U2, n> &ms)
{
  using T = larger_int_t<U2>;
  assert(rs.size() == ms.size());
  mint r = 0, m = 1;
  array<T, n> rr{}, mm;
  fill(ALL(mm), 1);
  repi(i, n)
  {
    assert(ms[i] >= U2(1));
    assert(U1(0) <= rs[i] && U2(rs[i]) < ms[i]);
    auto [g, im, _] = extgcd<T>(mm[i], ms[i]);
    assert(g == 1);
    T t = safemod((rs[i] - rr[i]) * im, ms[i]);
    r += t * m, m *= ms[i];
    repi(j, i + 1, n)
    {
      rr[j] += t * mm[j] % ms[j];
      if (rr[j] >= ms[j])
        rr[j] -= ms[j];
      mm[j] *= ms[i], mm[j] %= ms[j];
    }
  }
  return {r, m};
}

template <class T>
T convolution_point_get(const vc<T> &a, const vc<T> &b, int p)
{
  const int n = a.size(), m = b.size();
  if constexpr (internal::dot_product_mod32_value<T>::value)
  {
    if (p < 0 || ll(p) >= ll(n) + m - 1 || n == 0 || m == 0) return T(0);
    const int l = max(0, p - m + 1), r = min(n, p + 1);
    return dot_product<RingAddSubMul<T>>(r - l, a.begin() + l, b.rbegin() + (m - 1 - p + l));
  }
  T res = 0;
  repi(i, max(0, p - m + 1), min(n, p + 1)) res += a[i] * b[p - i];
  return res;
}

namespace internal
{

constexpr int primitive_root_constexpr(int m)
{
  if (m == 2)
    return 1;
  if (m == 167772161)
    return 3;
  if (m == 469762049)
    return 3;
  if (m == 754974721)
    return 11;
  if (m == 998244353)
    return 3;
  if (m == 1107296257)
    return 10;
  if (m == 1711276033)
    return 29;
  if (m == 1811939329)
    return 13;
  if (m == 2013265921)
    return 31;
  if (m == 2113929217)
    return 5;
  int divs[20] = {};
  divs[0] = 2;
  int cnt = 1;
  int x = (m - 1) / 2;
  while (x % 2 == 0)
    x /= 2;
  for (int i = 3; (long long)(i)*i <= x; i += 2)
  {
    if (x % i == 0)
    {
      divs[cnt++] = i;
      while (x % i == 0)
      {
        x /= i;
      }
    }
  }
  if (x > 1)
  {
    divs[cnt++] = x;
  }
  for (int g = 2;; g++)
  {
    bool ok = true;
    for (int i = 0; i < cnt; i++)
    {
      if (powmod_constexpr(g, (m - 1) / divs[i], m) == 1)
      {
        ok = false;
        break;
      }
    }
    if (ok)
      return g;
  }
}
template <int m>
constexpr int primitive_root_for_convolution = primitive_root_constexpr(m);

template <class mint, int g = internal::primitive_root_for_convolution<mint::mod()>>
struct fft_info
{
  static constexpr int rank2 = countr_zero(mint::mod() - 1);
  std::array<mint, std::max(3, rank2 + 1)> root;  
  std::array<mint, std::max(3, rank2 + 1)> iroot; 

  std::array<mint, std::max(1, rank2 - 2 + 1)> rate2;
  std::array<mint, std::max(1, rank2 - 2 + 1)> irate2;

  std::array<mint, std::max(1, rank2 - 3 + 1)> rate3;
  std::array<mint, std::max(1, rank2 - 3 + 1)> irate3;

  fft_info()
  {
    root[rank2] = mint(g).pow((mint::mod() - 1) >> rank2);
    iroot[rank2] = root[rank2].inv();
    for (int i = rank2 - 1; i >= 0; i--)
    {
      root[i] = root[i + 1] * root[i + 1];
      iroot[i] = iroot[i + 1] * iroot[i + 1];
    }

    {
      mint prod = 1, iprod = 1;
      for (int i = 0; i <= rank2 - 2; i++)
      {
        rate2[i] = root[i + 2] * prod;
        irate2[i] = iroot[i + 2] * iprod;
        prod *= iroot[i + 2];
        iprod *= root[i + 2];
      }
    }
    {
      mint prod = 1, iprod = 1;
      for (int i = 0; i <= rank2 - 3; i++)
      {
        rate3[i] = root[i + 3] * prod;
        irate3[i] = iroot[i + 3] * iprod;
        prod *= iroot[i + 3];
        iprod *= root[i + 3];
      }
    }
  }
};

}  

template <class mint>
bool ntt_ok(int n)
{
  if (n <= 0)
    return false;
  if constexpr (is_static_modint_v<mint>)
  {
    if constexpr (!internal::isprime<mint::mod()>)
      return false;
    static constexpr int rank2 = countr_zero(mint::mod() - 1);
    return n <= (1 << rank2);
  }
  else
    return false;
}

template <int id>
void ntt(vc<dynamic_modint32<id>> &) { assert(false); }

template <auto mod>
void ntt(vc<internal::modint_impl<internal::policy_static<mod>>> &a)
{
  using mint = internal::modint_impl<internal::policy_static<mod>>;
  int n = int(a.size());
  assert(n > 0);
  int h = countr_zero((unsigned int)n);
  assert(n == (1 << h));
  assert(ntt_ok<mint>(n));

  static const internal::fft_info<mint> info;

  int len = 0; 
  while (len < h)
  {
    if (h - len == 1)
    {
      int p = 1 << (h - len - 1);
      mint rot = 1;
      for (int s = 0; s < (1 << len); s++)
      {
        int offset = s << (h - len);
        for (int i = 0; i < p; i++)
        {
          auto l = a[i + offset];
          auto r = a[i + offset + p] * rot;
          a[i + offset] = l + r;
          a[i + offset + p] = l - r;
        }
        if (s + 1 != (1 << len))
          rot *= info.rate2[countr_zero(~(unsigned int)(s))];
      }
      len++;
    }
    else
    {
      
      int p = 1 << (h - len - 2);
      mint rot = 1, imag = info.root[2];
      for (int s = 0; s < (1 << len); s++)
      {
        mint rot2 = rot * rot;
        mint rot3 = rot2 * rot;
        int offset = s << (h - len);
        for (int i = 0; i < p; i++)
        {
          auto mod2 = 1ULL * mint::mod() * mint::mod();
          auto a0 = 1ULL * a[i + offset].val();
          auto a1 = 1ULL * a[i + offset + p].val() * rot.val();
          auto a2 = 1ULL * a[i + offset + 2 * p].val() * rot2.val();
          auto a3 = 1ULL * a[i + offset + 3 * p].val() * rot3.val();
          auto a1na3imag =
              1ULL * mint(a1 + mod2 - a3).val() * imag.val();
          auto na2 = mod2 - a2;
          a[i + offset] = a0 + a2 + a1 + a3;
          a[i + offset + 1 * p] = a0 + a2 + (2 * mod2 - (a1 + a3));
          a[i + offset + 2 * p] = a0 + na2 + a1na3imag;
          a[i + offset + 3 * p] = a0 + na2 + (mod2 - a1na3imag);
        }
        if (s + 1 != (1 << len))
          rot *= info.rate3[countr_zero(~(unsigned int)(s))];
      }
      len += 2;
    }
  }
}

template <auto mod>
void intt(vc<internal::modint_impl<internal::policy_static<mod>>> &a)
{
  using mint = internal::modint_impl<internal::policy_static<mod>>;
  int n = int(a.size());
  assert(n > 0);
  int h = countr_zero((unsigned int)n);
  assert(n == (1 << h));
  assert(ntt_ok<mint>(n));

  static const internal::fft_info<mint> info;

  int len = h; 
  while (len)
  {
    if (len == 1)
    {
      int p = 1 << (h - len);
      mint irot = 1;
      for (int s = 0; s < (1 << (len - 1)); s++)
      {
        int offset = s << (h - len + 1);
        for (int i = 0; i < p; i++)
        {
          auto l = a[i + offset];
          auto r = a[i + offset + p];
          a[i + offset] = l + r;
          a[i + offset + p] =
              ((unsigned long long)mint::mod() + l.val() - (uint)r.val()) *
              irot.val();
          ;
        }
        if (s + 1 != (1 << (len - 1)))
          irot *= info.irate2[countr_zero(~(unsigned int)(s))];
      }
      len--;
    }
    else
    {
      
      int p = 1 << (h - len);
      mint irot = 1, iimag = info.iroot[2];
      for (int s = 0; s < (1 << (len - 2)); s++)
      {
        mint irot2 = irot * irot;
        mint irot3 = irot2 * irot;
        int offset = s << (h - len + 2);
        for (int i = 0; i < p; i++)
        {
          auto a0 = 1ULL * a[i + offset + 0 * p].val();
          auto a1 = 1ULL * a[i + offset + 1 * p].val();
          auto a2 = 1ULL * a[i + offset + 2 * p].val();
          auto a3 = 1ULL * a[i + offset + 3 * p].val();

          auto a2na3iimag =
              1ULL *
              mint((mint::mod() + a2 - a3) * iimag.val()).val();

          a[i + offset] = a0 + a1 + a2 + a3;
          a[i + offset + 1 * p] =
              (a0 + (mint::mod() - a1) + a2na3iimag) * irot.val();
          a[i + offset + 2 * p] =
              (a0 + a1 + (mint::mod() - a2) + (mint::mod() - a3)) *
              irot2.val();
          a[i + offset + 3 * p] =
              (a0 + (mint::mod() - a1) + (mint::mod() - a2na3iimag)) *
              irot3.val();
        }
        if (s + 1 != (1 << (len - 2)))
          irot *= info.irate3[countr_zero(~(unsigned int)(s))];
      }
      len -= 2;
    }
  }
}

namespace internal
{

template <class mint>
vc<mint> convolution_naive(const vc<mint> &a, const vc<mint> &b)
{
  const int n = a.size(), m = b.size();
  const int cnta = n - count(ALL(a), 0), cntb = m - count(ALL(b), 0);
  vc<mint> c(n + m - 1);
  if constexpr (dot_product_mod32_value<mint>::value)
  {
    
    if (min(n, m) >= 16 && ll(cnta) * 2 >= n && ll(cntb) * 2 >= m)
    {
      repi(p, n + m - 1) c[p] = convolution_point_get(a, b, p);
      return c;
    }
  }
  if ((ll)m * cnta > (ll)n * cntb)
  {
    repi(j, m)
    {
      if (b[j] == 0)
        continue;
      repi(i, n) c[i + j] += a[i] * b[j];
    }
  }
  else
  {
    repi(i, n)
    {
      if (a[i] == 0)
        continue;
      repi(j, m) c[i + j] += a[i] * b[j];
    }
  }
  return c;
}

template <class mint>
vc<mint> convolution_ntt(vc<mint> a, vc<mint> b)
{
  const int n = a.size(), m = b.size();
  const int z = bit_ceil(n + m - 1);
  if (a == b)
  {
    a.resize(z);
    ntt(a);
    repi(i, z) a[i] *= a[i];
  }
  else
  {
    a.resize(z), b.resize(z);
    ntt(a), ntt(b);
    repi(i, z) a[i] *= b[i];
  }
  intt(a);
  mint iz = mint(z).inv();
  fem(ai : a) ai *= iz;
  a.resize(n + m - 1);
  return a;
}

template <size_t j, int mod, class T, size_t k>
void convolution_crt_helper(const vc<T> &a, const vc<T> &b, vc<array<T, k>> &cs)
{
  using mint = static_modint32<mod>;
  const int n = a.size(), m = b.size();
  auto c = convolution_ntt(vc<mint>(ALL(a)), vc<mint>(ALL(b)));
  repi(i, n + m - 1) cs[i][j] = c[i].val();
}

template <class mint, int... ms, class T>
vc<mint> convolution_crt_mod(const vc<T> &a, const vc<T> &b)
{
  const int n = a.size(), m = b.size();

  constexpr size_t k = sizeof...(ms);
  vc<array<T, k>> cs(n + m - 1);
  constexpr array<int, k> ms_arr = {ms...};
  [&]<size_t... Is>(index_sequence<Is...>)
  {
    (convolution_crt_helper<Is, ms_arr[Is], T, k>(a, b, cs), ...);
  }(make_index_sequence<k>{});

  vc<mint> c(n + m - 1);
  repi(i, n + m - 1) c[i] = crt_mod_constexpr<mint>(cs[i], ms_arr).first;
  return c;
}

}  

template <class mint, typename = std::enable_if_t<!std::is_integral<mint>::value>>
vc<mint> convolution(const vc<mint> &a, const vc<mint> &b)
{
  const int n = a.size(), m = b.size();
  const int cnta = n - count(ALL(a), 0), cntb = m - count(ALL(b), 0);
  if (n == 0 || m == 0)
    return {};
  if (ntt_ok<mint>(n + m - 1))
  {
    if (min(cnta, cntb) <= 60)
      return internal::convolution_naive(a, b);
    return internal::convolution_ntt(a, b);
  }
  else
  {
    if (min(cnta, cntb) <= 300)
      return internal::convolution_naive(a, b);
    assert(ntt_ok<static_modint32<469762049>>(n + m - 1) && "|a| + |b| - 1 <= 2^26");
    vc<ll> a_(n), b_(m);
    repi(i, n) a_[i] = a[i].val();
    repi(j, m) b_[j] = b[j].val();
    return internal::convolution_crt_mod<mint, 469762049, 1811939329, 2013265921>(a_, b_);
  }
}

template <int mod = 998244353, class T, typename = enable_if_t<is_integral<T>::value>>
vc<T> convolution(const vc<T> &a, const vc<T> &b)
{
  using mint = static_modint32<mod>;
  auto c = convolution(vc<mint>(ALL(a)), vc<mint>(ALL(b)));
  vc<T> c_(c.size());
  repi(i, c.size()) c_[i] = c[i].val();
  return c_;
}
// https://github.com/miscalculation53/library/tree/wip/math/modint/sqrt_mod.hpp

// https://github.com/miscalculation53/library/tree/wip/math/prime/large/primality_test.hpp

namespace internal
{

template <class mint, class Array>
bool is_prime_impl(ll n, const Array &bases)
{
  if (n <= 1)
    return false;
  if (n == 2 || n == 7 || n == 61)
    return true;
  if (n % 2 == 0)
    return false;
  ll d = (n - 1) >> countr_zero(n - 1);
  mint::set_mod(n);
  for (ll a : bases)
  {
    ll t = d;
    mint y = mint(a).pow(t);
    while (t != n - 1 && y != 1 && y != n - 1)
    {
      y *= y;
      t <<= 1;
    }
    if (y != n - 1 && t % 2 == 0)
      return false;
  }
  return true;
}

}; 

bool is_prime(ll n)
{
  static constexpr array<ll, 3> bases32 = {2, 7, 61};
  static constexpr array<ll, 7> bases64 = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
  if (n <= INT_MAX)
  {
    using mint = dynamic_modint32<INT_MIN>;
    return internal::is_prime_impl<mint>(n, bases32);
  }
  else
  {
    using mint = dynamic_modint64_odd<INT_MIN>;
    return internal::is_prime_impl<mint>(n, bases64);
  }
}

template <class mint>
struct FormalPowerSeries : vc<mint>
{
  using F = FormalPowerSeries;
  using vc<mint>::vc;
  using vc<mint>::operator=;
  using vc<mint>::size;
  using vc<mint>::empty;
  using vc<mint>::back;
  using vc<mint>::pop_back;
  using vc<mint>::begin;
  using vc<mint>::resize;
  using vc<mint>::front;

  FormalPowerSeries(const vc<mint> &f) : vc<mint>(f) {}

  int sz() const { return size(); }
  void shrink()
  {
    while (!empty() && back() == 0)
      pop_back();
  }
  mint get(int i) const { return 0 <= i && i < sz() ? (*this)[i] : 0; }
  F pre(int len) const
  {
    assert(len >= 0);
    return F(begin(), begin() + min(sz(), len));
  }
  F rev(int d = -1) const
  {
    F res(*this);
    if (d >= 0)
      res.resize(d);
    reverse(ALL(res));
    return res;
  }
  int cnt_nz() const { return count_if(ALL(*this), LMD(x, x != 0)); }
  vc<pair<int, mint>> nz() const
  {
    vc<pair<int, mint>> res;
    repi(i, sz()) if ((*this)[i] != 0) res.eb(i, (*this)[i]);
    return res;
  }

  F operator-() const
  {
    F res(*this);
    fem(a : res) a = -a;
    return res;
  }
  F &operator*=(const mint &k)
  {
    fem(a : *this) a *= k;
    return *this;
  }
  F operator*(const mint &k) const { return F(*this) *= k; }
  friend F operator*(const mint &k, const F &f) { return f * k; }
  F &operator-=(const F &g)
  {
    const int n = size(), m = g.size();
    resize(max(n, m));
    repi(i, m)(*this)[i] -= g[i];
    return *this;
  }
  F operator-(const F &g) const { return F(*this) -= g; }
  F operator*(const F &g) const { return convolution(*this, g); }

  F div_sparse_destructive(const F &g, int d = -1)
  {
    assert(g.get(0) != 0);
    if (d < 0)
      d = max(sz(), g.sz());
    mint iv = g.front().inv();
    auto gnz = g.nz();
    resize(d);
    repi(i, d)
    {
      fec([j, b] : gnz)
      {
        if (j == 0)
          continue;
        if (j > i)
          break;
        (*this)[i] -= (*this)[i - j] * b;
      }
      (*this)[i] *= iv;
    }
    return pre(d);
  }
  F div_sparse(const F &g, int d = -1) const { return F(*this).div_sparse_destructive(g, d); }

  F inv(int d = -1) const
  {
    assert(get(0) != 0);
    if (d < 0)
      d = sz();
    if (cnt_nz() <= 200)
      return F{1}.div_sparse(*this, d);
    F f, g2, g{front().inv()};
    for (int m = 1; m < d; m *= 2)
    {
      if (ntt_ok<mint>(2 * m))
      {
        f = pre(2 * m), g2 = F(g);
        f.resize(2 * m), ntt(f);
        g2.resize(2 * m), ntt(g2);
        repi(i, 2 * m) f[i] *= g2[i];
        intt(f);
        f >>= m;
        f.resize(2 * m), ntt(f);
        repi(i, 2 * m) f[i] *= g2[i];
        intt(f);
        mint iz = mint(2 * m).inv();
        iz *= -iz;
        repi(i, m) f[i] *= iz;
        g.insert(g.end(), f.begin(), f.begin() + m);
      }
      else
        g = (g * mint(2) - g * g * pre(2 * m)).pre(2 * m);
    }
    return g.pre(d);
  }

  F div_poly(const F &g) const
  {
    const int k = sz() - g.sz() + 1;
    if (k <= 0)
      return {};
    return (rev().pre(k) * g.rev().inv(k)).pre(k).rev();
  }
  pair<F, F> divmod(const F &g) const
  {
    F q = div_poly(g);
    const int l = sz() - q.sz();
    F r = pre(l) - (q.pre(l) * g.pre(l)).pre(l);
    r.shrink();
    return {q, r};
  }

  F operator>>(int k) const
  {
    F res(max(0, sz() - k));
    repi(i, sz() - k) res[i] = (*this)[i + k];
    return res;
  }
  F &operator>>=(int k) { return *this = *this >> k; }

};

template <class mint>
mint bostan_mori(const FormalPowerSeries<mint> &p, const FormalPowerSeries<mint> &q, ll k)
{
  using F = FormalPowerSeries<mint>;
  assert(k >= 0);
  static const internal::fft_info<mint> info;
  auto [r, u] = p.divmod(q);
  mint res = k < r.sz() ? r[(int)k] : 0;
  const int d = SZ(q) - 1;
  if (d == 0)
    return res;
  if (ntt_ok<mint>(2 * d + 1))
  {
    const int z = bit_ceil(2 * d + 1);
    const mint i2 = mint(2).inv();
    const mint iz = mint(z / 2).inv();
    const mint root = info.root[bit_width(z / 2)];
    const mint iroot = info.iroot[bit_width(z / 2)];
    vc<mint> ipw(z / 2);
    {
      mint itmp = 1;
      repi(i, z / 2)
      {
        ipw[bitrev(z / 2, i)] = itmp;
        itmp *= iroot;
      }
    }
    F v = q;
    u.resize(z / 2), v.resize(z / 2);
    F u2 = u, v2 = v;
    ntt(u), ntt(v);
    while (k > 0)
    {
      {
        mint tmp = 1;
        repi(i, z / 2)
        {
          u2[i] = u2[i] * tmp;
          v2[i] = v2[i] * tmp;
          tmp *= root;
        }
      }
      ntt(u2), ntt(v2);
      if (k & 1)
      {
        repi(i, z / 4)
        {
          const mint x = v[2 * i], y = v[2 * i + 1];
          u[i] = (u[2 * i] * y - u[2 * i + 1] * x) * ipw[i] * i2;
          v[i] = x * y;
        }
        repi(i, z / 4)
        {
          const mint x = v2[2 * i], y = v2[2 * i + 1];
          u[i + z / 4] = (u2[2 * i] * y - u2[2 * i + 1] * x) * ipw[i + z / 4] * i2;
          v[i + z / 4] = x * y;
        }
      }
      else
      {
        repi(i, z / 4)
        {
          const mint x = v[2 * i], y = v[2 * i + 1];
          u[i] = (u[2 * i] * y + u[2 * i + 1] * x) * i2;
          v[i] = x * y;
        }
        repi(i, z / 4)
        {
          const mint x = v2[2 * i], y = v2[2 * i + 1];
          u[i + z / 4] = (u2[2 * i] * y + u2[2 * i + 1] * x) * i2;
          v[i + z / 4] = x * y;
        }
      }
      u2 = u, v2 = v;
      intt(u2), intt(v2);
      repi(i, z / 2) u2[i] *= iz, v2[i] *= iz;
      k >>= 1;
    }
    return res + u2[0] / v2[0];
  }
  else
  {
    F v = q;
    u.resize(d + 1), v.resize(d + 1);
    while (k > 0)
    {
      F w = v;
      repi(i, 1, d + 1, 2) w[i] = -w[i];
      F u2 = u * w, v2 = v * w;
      repi(i, d + 1)
      {
        if (2 * i + (k & 1) < SZ(u2))
          u[i] = u2[2 * i + (k & 1)];
        if (2 * i < SZ(v2))
          v[i] = v2[2 * i];
      }
      k >>= 1;
    }
    return res + u[0] / v[0];
  }
}

template <class mint>
pair<FormalPowerSeries<mint>, FormalPowerSeries<mint>> linear_recurrence_gf(const vc<mint> &a, const vc<mint> &c)
{
  using F = FormalPowerSeries<mint>;
  const int d = SZ(c) - 1;
  assert(d >= 0);
  assert(SZ(a) >= d);
  F q = -F(c);
  q[0] = 1;
  F p = (F(a) * q).pre(d);
  return {p, q};
}

template <class mint>
mint bmbm(const vc<mint> &a, ll k, bool show_coefs = true)
{
  auto c = berlekamp_massey<FieldAddSubMulDiv<mint>>(a);
  if (show_coefs)
    dump(c | cp::index() | cp::rat());
  auto [p, q] = linear_recurrence_gf(a, c);
  if (show_coefs)
    dump(p | cp::index() | cp::rat(), q | cp::index() | cp::rat());
  return bostan_mori(p, q, k);
}

void main2()
{
  
  LL(N, M, K, S, T);
  S--, T--;
  VEC(pll, M, UV);
  offset(UV, pll{-1, -1});

  const ll LIM = 5 * N + 1;
  auto dp = dvec({2LL, N}, mint(0)), ndp = dp;
  dp[0][S] = 1;
  vc<mint> vec(LIM);
  vec[0] = dp[0][T] + dp[1][T];
  rep(t, 1, LIM)
  {
    rep(i, 2) rep(j, N) ndp[i][j] = 0;
    fec([ u, v ] : UV)
    {
      ndp[0][u] += dp[0][v];
      ndp[0][v] += dp[0][u];
      ndp[1][u] += dp[0][v];
      ndp[1][v] += dp[0][u];
    }
     
    mint sm = SUM(dp[0]);
    rep(v, N) ndp[1][v] += sm - dp[0][v];

    swap(dp, ndp);
    vec[t] = dp[0][T] + dp[1][T];
  }

  mint ans = bmbm(vec, K);
  PRINT(ans != 0 ? "Yes" : "No");
}

void test()
{

}

// https://github.com/miscalculation53/library/tree/wip/template/template_main.hpp

template <auto init, auto main2, auto test>
struct Main
{
  Main()
  {
    cauto CERR = [](string val, string color)
    {
      string s = "\033[" + color + "m" + val + "\033[m";
      
    };
  
    CERR("\n[FAST_IO]\n\n", "32");
    
    cout << fixed << setprecision(20);
  
    init();
    
    CERR("\n[SINGLE_TESTCASE]\n\n", "36");
    main2();
  }
};
Main<init, main2, test> main_dummy;
int main() {}
0