QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103114#2068. Fast as RysermaspyAC ✓1144ms52332kbC++2024.6kb2023-05-04 15:01:402023-05-04 15:01:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-04 15:01:44]
  • 评测
  • 测评结果:AC
  • 用时:1144ms
  • 内存:52332kb
  • [2023-05-04 15:01:40]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  assert(!que.empty());
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  assert(!que.empty());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.write(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};

struct has_read_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.read(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <typename T,
            typename enable_if<has_read<T>::value>::type * = nullptr>
  inline bool read_single(T &x) {
    x.read();
    return true;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <size_t N = 0, typename T>
  void read_single_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
      auto &x = std::get<N>(t);
      read_single(x);
      read_single_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool read_single(tuple<T...> &tpl) {
    read_single_tuple(tpl);
    return true;
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <typename T,
            typename enable_if<has_write<T>::value>::type * = nullptr>
  inline void write(T x) {
    x.write();
  }
  template <class T>
  void write(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <size_t N = 0, typename T>
  void write_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
      if constexpr (N > 0) { write(' '); }
      const auto x = std::get<N>(t);
      write(x);
      write_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool write(tuple<T...> tpl) {
    write_tuple(tpl);
    return true;
  }
  template <class T, size_t S>
  void write(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if (val < 0) {
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if (negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "library/mod/modint_common.hpp"

struct has_mod_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.get_mod(), std::true_type{});
  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_mod : public decltype(has_mod_impl::check<T>(std::declval<T>())) {};


template <typename mint>
mint inv(int n) {
  static const int mod = mint::get_mod();
  static vector<mint> dat = {0, 1};
  assert(0 <= n);
  if (n >= mod) n %= mod;
  while (len(dat) <= n) {
    int k = len(dat);
    int q = (mod + k - 1) / k;
    dat.eb(dat[k * q - mod] * mint(q));
  }
  return dat[n];
}

template <typename mint>
mint fact(int n) {
  static const int mod = mint::get_mod();
  assert(0 <= n);
  if (n >= mod) return 0;
  static vector<mint> dat = {1, 1};
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint(len(dat)));
  return dat[n];
}

template <typename mint>
mint fact_inv(int n) {
  static const int mod = mint::get_mod();
  assert(-1 <= n && n < mod);
  static vector<mint> dat = {1, 1};
  if (n == -1) return mint(0);
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * inv<mint>(len(dat)));
  return dat[n];
}

template <class mint, class... Ts>
mint fact_invs(Ts... xs) {
  return (mint(1) * ... * fact_inv<mint>(xs));
}

template <typename mint, class Head, class... Tail>
mint multinomial(Head &&head, Tail &&... tail) {
  return fact<mint>(head) * fact_invs<mint>(std::forward<Tail>(tail)...);
}

template <typename mint>
mint C_dense(int n, int k) {
  static vvc<mint> C;
  static int H = 0, W = 0;
  auto calc = [&](int i, int j) -> mint {
    if (i == 0) return (j == 0 ? mint(1) : mint(0));
    return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
  };
  if (W <= k) {
    FOR(i, H) {
      C[i].resize(k + 1);
      FOR(j, W, k + 1) { C[i][j] = calc(i, j); }
    }
    W = k + 1;
  }
  if (H <= n) {
    C.resize(n + 1);
    FOR(i, H, n + 1) {
      C[i].resize(W);
      FOR(j, W) { C[i][j] = calc(i, j); }
    }
    H = n + 1;
  }
  return C[n][k];
}

template <typename mint, bool large = false, bool dense = false>
mint C(ll n, ll k) {
  assert(n >= 0);
  if (k < 0 || n < k) return 0;
  if (dense) return C_dense<mint>(n, k);
  if (!large) return multinomial<mint>(n, k, n - k);
  k = min(k, n - k);
  mint x(1);
  FOR(i, k) x *= mint(n - i);
  return x * fact_inv<mint>(k);
}

template <typename mint, bool large = false>
mint C_inv(ll n, ll k) {
  assert(n >= 0);
  assert(0 <= k && k <= n);
  if (!large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k);
  return mint(1) / C<mint, 1>(n, k);
}

// [x^d] (1-x) ^ {-n} の計算
template <typename mint, bool large = false, bool dense = false>
mint C_negative(ll n, ll d) {
  assert(n >= 0);
  if (d < 0) return mint(0);
  if (n == 0) { return (d == 0 ? mint(1) : mint(0)); }
  return C<mint, large, dense>(n + d - 1, d);
}
#line 3 "library/mod/modint.hpp"

template <int mod>
struct modint {
  int val;
  constexpr modint(const ll val = 0) noexcept
      : val(val >= 0 ? val % mod : (mod - (-val) % mod) % mod) {}
  bool operator<(const modint &other) const {
    return val < other.val;
  } // To use std::map
  modint &operator+=(const modint &p) {
    if ((val += p.val) >= mod) val -= mod;
    return *this;
  }
  modint &operator-=(const modint &p) {
    if ((val += mod - p.val) >= mod) val -= mod;
    return *this;
  }
  modint &operator*=(const modint &p) {
    val = (int)(1LL * val * p.val % mod);
    return *this;
  }
  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }
  modint operator-() const { return modint(-val); }
  modint operator+(const modint &p) const { return modint(*this) += p; }
  modint operator-(const modint &p) const { return modint(*this) -= p; }
  modint operator*(const modint &p) const { return modint(*this) *= p; }
  modint operator/(const modint &p) const { return modint(*this) /= p; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  modint inverse() const {
    int a = val, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b), swap(u -= t * v, v);
    }
    return modint(u);
  }
  modint pow(ll n) const {
    assert(n >= 0);
    modint ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
#ifdef FASTIO
  void write() { fastio::printer.write(val); }
  void read() { fastio::scanner.read(val); }
#endif
  static constexpr int get_mod() { return mod; }
  // (n, r), r は 1 の 2^n 乗根
  static constexpr pair<int, int> ntt_info() {
    if (mod == 167772161) return {25, 17};
    if (mod == 469762049) return {26, 30};
    if (mod == 754974721) return {24, 362};
    if (mod == 880803841) return {23, 211};
    if (mod == 998244353) return {23, 31};
    if (mod == 1045430273) return {20, 363};
    if (mod == 1051721729) return {20, 330};
    if (mod == 1053818881) return {20, 2789};
    return {-1, -1};
  }
  static constexpr bool can_ntt() { return ntt_info().fi != -1; }
};

using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
#line 2 "library/nt/primetable.hpp"

template <typename T = long long>
vc<T> primetable(int LIM) {
  ++LIM;
  const int S = 32768;
  static int done = 2;
  static vc<T> primes = {2}, sieve(S + 1);

  if (done < LIM) {
    done = LIM;

    primes = {2}, sieve.assign(S + 1, 0);
    const int R = LIM / 2;
    primes.reserve(int(LIM / log(LIM) * 1.1));
    vc<pair<int, int>> cp;
    for (int i = 3; i <= S; i += 2) {
      if (!sieve[i]) {
        cp.eb(i, i * i / 2);
        for (int j = i * i; j <= S; j += 2 * i) sieve[j] = 1;
      }
    }
    for (int L = 1; L <= R; L += S) {
      array<bool, S> block{};
      for (auto& [p, idx]: cp)
        for (int i = idx; i < S + L; idx = (i += p)) block[i - L] = 1;
      FOR(i, min(S, R - L)) if (!block[i]) primes.eb((L + i) * 2 + 1);
    }
  }
  int k = LB(primes, LIM + 1);
  return {primes.begin(), primes.begin() + k};
}
#line 3 "library/mod/powertable.hpp"

// a^0, ..., a^N
template <typename mint>
vc<mint> powertable_1(mint a, ll N) {
  // table of a^i
  vc<mint> f(N + 1, 1);
  FOR(i, N) f[i + 1] = a * f[i];
  return f;
}

// 0^e, ..., N^e
template <typename mint>
vc<mint> powertable_2(ll e, ll N) {
  auto primes = primetable(N);
  vc<mint> f(N + 1, 1);
  f[0] = mint(0).pow(e);
  for (auto&& p: primes) {
    if (p > N) break;
    mint xp = mint(p).pow(e);
    ll pp = p;
    while (pp <= N) {
      ll i = pp;
      while (i <= N) {
        f[i] *= xp;
        i += pp;
      }
      pp *= p;
    }
  }
  return f;
}
#line 1 "library/enumerate/bits.hpp"
template <typename F>
void enumerate_bits_32(u32 s, F f) {
  while (s) {
    int i = __builtin_ctz(s);
    f(i);
    s ^= 1 << i;
  }
}

template <typename F>
void enumerate_bits_64(u64 s, F f) {
  while (s) {
    int i = __builtin_ctzll(s);
    f(i);
    s ^= u64(1) << i;
  }
}

template <typename BS, typename F>
void enumerate_bits_bitset(BS& b, int L, int R, F f) {
  int p = (b[L] ? L : b._Find_next(L));
  while (p < R) {
    f(p);
    p = b._Find_next(p);
  }
}
#line 2 "library/setfunc/ranked_zeta.hpp"

template <typename T, int LIM = 20>
vc<array<T, LIM + 1>> ranked_zeta(const vc<T>& f) {
  int n = topbit(len(f));
  assert(n <= LIM);
  assert(len(f) == 1 << n);
  vc<array<T, LIM + 1>> Rf(1 << n);
  for (int s = 0; s < (1 << n); ++s) Rf[s][popcnt(s)] = f[s];
  for (int i = 0; i < n; ++i) {
    int w = 1 << i;
    for (int p = 0; p < (1 << n); p += 2 * w) {
      for (int s = p; s < p + w; ++s) {
        int t = s | 1 << i;
        for (int d = 0; d <= n; ++d) Rf[t][d] += Rf[s][d];
      }
    }
  }
  return Rf;
}

template <typename T, int LIM = 20>
vc<T> ranked_mobius(vc<array<T, LIM + 1>>& Rf) {
  int n = topbit(len(Rf));
  assert(len(Rf) == 1 << n);
  for (int i = 0; i < n; ++i) {
    int w = 1 << i;
    for (int p = 0; p < (1 << n); p += 2 * w) {
      for (int s = p; s < p + w; ++s) {
        int t = s | 1 << i;
        for (int d = 0; d <= n; ++d) Rf[t][d] -= Rf[s][d];
      }
    }
  }
  vc<T> f(1 << n);
  for (int s = 0; s < (1 << n); ++s) f[s] = Rf[s][popcnt(s)];
  return f;
}
#line 2 "library/setfunc/subset_convolution.hpp"

template <typename T, int LIM = 20>
vc<T> subset_convolution(const vc<T>& A, const vc<T>& B) {
  if (A == B) return subset_convolution_square(A);
  auto RA = ranked_zeta<T, LIM>(A);
  auto RB = ranked_zeta<T, LIM>(B);
  int n = topbit(len(RA));
  FOR(s, len(RA)) {
    auto &f = RA[s], g = RB[s];
    FOR_R(d, n + 1) {
      T x = 0;
      FOR(i, d + 1) x += f[i] * g[d - i];
      f[d] = x;
    }
  }
  return ranked_mobius<T, LIM>(RA);
}

template <typename T, int LIM = 20>
vc<T> subset_convolution_square(const vc<T>& A) {
  auto RA = ranked_zeta<T, LIM>(A);
  int n = topbit(len(RA));
  FOR(s, len(RA)) {
    auto& f = RA[s];
    FOR_R(d, n + 1) {
      T x = 0;
      FOR(i, d + 1) x += f[i] * f[d - i];
      f[d] = x;
    }
  }
  return ranked_mobius<T, LIM>(RA);
}
#line 2 "library/setfunc/sps_exp.hpp"

// sum_i f_i/i! s^i, s^i is subset-convolution
template <typename mint, int LIM>
vc<mint> sps_exp(int N, vc<mint>& s) {
  assert(len(s) == (1 << N) && s[0] == mint(0));
  vc<mint> dp(1 << N);
  dp[0] = mint(1);
  FOR(i, N) {
    vc<mint> a = {s.begin() + (1 << i), s.begin() + (2 << i)};
    vc<mint> b = {dp.begin(), dp.begin() + (1 << i)};
    a = subset_convolution<mint, LIM>(a, b);
    copy(all(a), dp.begin() + (1 << i));
  }
  return dp;
}
#line 7 "main.cpp"

using mint = modint107;

void solve() {
  LL(N, M, c);
  N = 36;
  auto POW = powertable_1<mint>(c, 100);

  vc<u64> nbd(N);
  FOR(M) {
    INT(a, b);
    --a, --b;
    nbd[a] |= u64(1) << b;
    nbd[b] |= u64(1) << a;
  }

  ll n = N / 2;

  vc<mint> path(1 << n), cyc(1 << n);

  FOR(i, N / 2) {
    int A = 2 * i + 0, B = 2 * i + 1;
    vv(mint, dp, 1 << i, 2 * i + 2);
    vv(mint, dp1, 1 << i, 2 * i + 2);
    dp[0][A] = 1;
    u64 mask = (u64(1) << (i + i)) - 1;
    FOR(s, 1 << i) {
      FOR(v, 2 * i + 2) {
        if (dp[s][v] == mint(0)) continue;
        if (nbd[v] >> B & 1) cyc[s | 1 << i] += dp[s][v];
        dp1[s][B] += dp[s][v];
        enumerate_bits_64(nbd[v] & mask, [&](int x) -> void {
          int t = s | 1 << (x / 2);
          if (s == t) return;
          int y = x ^ 1;
          // v -> x -> y
          dp[t][y] += dp[s][v];
        });
      }
      FOR(v, 2 * i + 2) {
        if (dp1[s][v] == mint(0)) continue;
        path[s | 1 << i] += dp1[s][v];
        enumerate_bits_64(nbd[v] & mask, [&](int x) -> void {
          int t = s | 1 << (x / 2);
          if (s == t) return;
          int y = x ^ 1;
          // v -> x -> y
          dp1[t][y] += dp1[s][v];
        });
      }
    }
  }
  vc<mint> f(1 << n);
  FOR(s, 1, 1 << n) {
    int k = popcnt(s);
    f[s] += path[s] * POW[k - 1];
    f[s] += cyc[s] * POW[k];
  }

  f = sps_exp<mint, 18>(n, f);
  print(f.back());
}

signed main() {
  solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 197ms
memory: 52196kb

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: 201ms
memory: 52280kb

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: 376ms
memory: 52124kb

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: 1112ms
memory: 52140kb

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: 977ms
memory: 52288kb

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: 829ms
memory: 52220kb

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: 653ms
memory: 52248kb

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: 1132ms
memory: 52264kb

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: 314ms
memory: 52224kb

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: 1120ms
memory: 52284kb

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: 194ms
memory: 52256kb

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: 1144ms
memory: 52236kb

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: 981ms
memory: 52224kb

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: 256ms
memory: 52180kb

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: 1132ms
memory: 52196kb

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: 746ms
memory: 52248kb

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: 664ms
memory: 52284kb

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: 211ms
memory: 52300kb

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: 1020ms
memory: 52160kb

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: 659ms
memory: 52216kb

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: 224ms
memory: 52184kb

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: 948ms
memory: 52240kb

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: 196ms
memory: 52172kb

input:

36 0 73190723

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 1093ms
memory: 52184kb

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: 193ms
memory: 52320kb

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: 663ms
memory: 52140kb

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: 430ms
memory: 52100kb

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: 743ms
memory: 52288kb

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: 874ms
memory: 52176kb

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: 793ms
memory: 52220kb

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: 223ms
memory: 52296kb

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: 214ms
memory: 52268kb

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: 279ms
memory: 52292kb

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: 880ms
memory: 52316kb

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: 406ms
memory: 52264kb

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: 419ms
memory: 52284kb

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: 221ms
memory: 52244kb

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: 636ms
memory: 52316kb

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: 879ms
memory: 52288kb

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: 400ms
memory: 52288kb

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: 520ms
memory: 52196kb

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: 816ms
memory: 52192kb

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: 871ms
memory: 52220kb

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: 279ms
memory: 52208kb

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: 871ms
memory: 52128kb

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: 187ms
memory: 52296kb

input:

35 0 387237811

output:

1

result:

ok single line: '1'

Test #47:

score: 0
Accepted
time: 811ms
memory: 52320kb

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: 182ms
memory: 52140kb

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: 192ms
memory: 52128kb

input:

1 0 240889969

output:

1

result:

ok single line: '1'

Test #50:

score: 0
Accepted
time: 201ms
memory: 52172kb

input:

2 0 734305586

output:

1

result:

ok single line: '1'

Test #51:

score: 0
Accepted
time: 190ms
memory: 52332kb

input:

2 1 907431552
2 1

output:

907431553

result:

ok single line: '907431553'