QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#616188#9441. Many Common Segment Problemsucup-team3586#AC ✓4807ms49368kbC++2355.9kb2024-10-05 23:19:002024-10-05 23:19:02

Judging History

This is the latest submission verdict.

  • [2024-10-05 23:19:02]
  • Judged
  • Verdict: AC
  • Time: 4807ms
  • Memory: 49368kb
  • [2024-10-05 23:19:00]
  • Submitted

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

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); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(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>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

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

#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) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  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;
    (check(x) ? ok : ng) = 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;
    (check(x) ? ok : ng) = 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"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
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, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

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

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

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#if defined(LOCAL)
#define SHOW(...) \
  SHOW_IMPL(__VA_ARGS__, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) \
  print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#else
#define SHOW(...)
#endif

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __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 3 "main.cpp"

#line 2 "library/random/base.hpp"

u64 RNG_64() {
  static uint64_t x_
      = uint64_t(chrono::duration_cast<chrono::nanoseconds>(
                     chrono::high_resolution_clock::now().time_since_epoch())
                     .count())
        * 10150724397891781847ULL;
  x_ ^= x_ << 7;
  return x_ ^= x_ >> 9;
}

u64 RNG(u64 lim) { return RNG_64() % lim; }

ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
#line 2 "library/nt/factor.hpp"

#line 2 "library/mod/mongomery_modint.hpp"

// odd mod.
// x の代わりに rx を持つ
template <int id, typename U1, typename U2>
struct Mongomery_modint {
  using mint = Mongomery_modint;
  inline static U1 m, r, n2;
  static constexpr int W = numeric_limits<U1>::digits;

  static void set_mod(U1 mod) {
    assert(mod & 1 && mod <= U1(1) << (W - 2));
    m = mod, n2 = -U2(m) % m, r = m;
    FOR(5) r *= 2 - m * r;
    r = -r;
    assert(r * m == U1(-1));
  }
  static U1 reduce(U2 b) { return (b + U2(U1(b) * r) * m) >> W; }

  U1 x;
  Mongomery_modint() : x(0) {}
  Mongomery_modint(U1 x) : x(reduce(U2(x) * n2)){};
  U1 val() const {
    U1 y = reduce(x);
    return y >= m ? y - m : y;
  }
  mint &operator+=(mint y) {
    x = ((x += y.x) >= m ? x - m : x);
    return *this;
  }
  mint &operator-=(mint y) {
    x -= (x >= y.x ? y.x : y.x - m);
    return *this;
  }
  mint &operator*=(mint y) {
    x = reduce(U2(x) * y.x);
    return *this;
  }
  mint operator+(mint y) const { return mint(*this) += y; }
  mint operator-(mint y) const { return mint(*this) -= y; }
  mint operator*(mint y) const { return mint(*this) *= y; }
  bool operator==(mint y) const {
    return (x >= m ? x - m : x) == (y.x >= m ? y.x - m : y.x);
  }
  bool operator!=(mint y) const { return not operator==(y); }
  mint pow(ll n) const {
    assert(n >= 0);
    mint y = 1, z = *this;
    for (; n; n >>= 1, z *= z)
      if (n & 1) y *= z;
    return y;
  }
};

template <int id>
using Mongomery_modint_32 = Mongomery_modint<id, u32, u64>;
template <int id>
using Mongomery_modint_64 = Mongomery_modint<id, u64, u128>;
#line 3 "library/nt/primetest.hpp"

bool primetest(const u64 x) {
  assert(x < u64(1) << 62);
  if (x == 2 or x == 3 or x == 5 or x == 7) return true;
  if (x % 2 == 0 or x % 3 == 0 or x % 5 == 0 or x % 7 == 0) return false;
  if (x < 121) return x > 1;
  const u64 d = (x - 1) >> lowbit(x - 1);

  using mint = Mongomery_modint_64<202311020>;

  mint::set_mod(x);
  const mint one(u64(1)), minus_one(x - 1);
  auto ok = [&](u64 a) -> bool {
    auto y = mint(a).pow(d);
    u64 t = d;
    while (y != one && y != minus_one && t != x - 1) y *= y, t <<= 1;
    if (y != minus_one && t % 2 == 0) return false;
    return true;
  };
  if (x < (u64(1) << 32)) {
    for (u64 a: {2, 7, 61})
      if (!ok(a)) return false;
  } else {
    for (u64 a: {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
      if (!ok(a)) return false;
    }
  }
  return true;
}
#line 5 "library/nt/factor.hpp"

template <typename mint>
ll rho(ll n, ll c) {
  assert(n > 1);
  const mint cc(c);
  auto f = [&](mint x) { return x * x + cc; };
  mint x = 1, y = 2, z = 1, q = 1;
  ll g = 1;
  const ll m = 1LL << (__lg(n) / 5);
  for (ll r = 1; g == 1; r <<= 1) {
    x = y;
    FOR(r) y = f(y);
    for (ll k = 0; k < r && g == 1; k += m) {
      z = y;
      FOR(min(m, r - k)) y = f(y), q *= x - y;
      g = gcd(q.val(), n);
    }
  }
  if (g == n) do {
      z = f(z);
      g = gcd((x - z).val(), n);
    } while (g == 1);
  return g;
}

ll find_prime_factor(ll n) {
  assert(n > 1);
  if (primetest(n)) return n;
  FOR(100) {
    ll m = 0;
    if (n < (1 << 30)) {
      using mint = Mongomery_modint_32<20231025>;
      mint::set_mod(n);
      m = rho<mint>(n, RNG(0, n));
    } else {
      using mint = Mongomery_modint_64<20231025>;
      mint::set_mod(n);
      m = rho<mint>(n, RNG(0, n));
    }
    if (primetest(m)) return m;
    n = m;
  }
  assert(0);
  return -1;
}

// ソートしてくれる
vc<pair<ll, int>> factor(ll n) {
  assert(n >= 1);
  vc<pair<ll, int>> pf;
  FOR(p, 2, 100) {
    if (p * p > n) break;
    if (n % p == 0) {
      ll e = 0;
      do { n /= p, e += 1; } while (n % p == 0);
      pf.eb(p, e);
    }
  }
  while (n > 1) {
    ll p = find_prime_factor(n);
    ll e = 0;
    do { n /= p, e += 1; } while (n % p == 0);
    pf.eb(p, e);
  }
  sort(all(pf));
  return pf;
}

vc<pair<ll, int>> factor_by_lpf(ll n, vc<int>& lpf) {
  vc<pair<ll, int>> res;
  while (n > 1) {
    int p = lpf[n];
    int e = 0;
    while (n % p == 0) {
      n /= p;
      ++e;
    }
    res.eb(p, e);
  }
  return res;
}
#line 2 "library/nt/divisors.hpp"

// sort はしない
vc<ll> divisors_by_pf(const vc<pair<ll, int>>& pf) {
  vi div = {1};
  for (auto&& [p, e]: pf) {
    ll n = len(div);
    ll pp = 1;
    FOR3(i, 1, e + 1) {
      pp *= p;
      FOR(j, n) div.eb(div[j] * pp);
    }
  }
  return div;
}

// sort はしない
vc<ll> divisors(ll N) {
  auto pf = factor(N);
  return divisors_by_pf(pf);
}

// sort はしない
vc<ll> divisors_by_lpf(ll N, vc<int>& lpf) {
  auto pf = factor_by_lpf(N, lpf);
  return divisors_by_pf(pf);
}
#line 2 "library/poly/sum_of_rationals.hpp"

#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::raw(q));
  }
  return dat[n];
}

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

template <typename mint>
mint fact_inv(int n) {
  static vector<mint> dat = {1, 1};
  if (n < 0) 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 constexpr (dense) return C_dense<mint>(n, k);
  if constexpr (!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 {
  static constexpr u32 umod = u32(mod);
  static_assert(umod < u32(1) << 31);
  u32 val;

  static modint raw(u32 v) {
    modint x;
    x.val = v;
    return x;
  }
  constexpr modint() : val(0) {}
  constexpr modint(u32 x) : val(x % umod) {}
  constexpr modint(u64 x) : val(x % umod) {}
  constexpr modint(u128 x) : val(x % umod) {}
  constexpr modint(int x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(ll x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(i128 x) : val((x %= mod) < 0 ? x + mod : x){};
  bool operator<(const modint &other) const { return val < other.val; }
  modint &operator+=(const modint &p) {
    if ((val += p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator-=(const modint &p) {
    if ((val += umod - p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator*=(const modint &p) {
    val = u64(val) * p.val % umod;
    return *this;
  }
  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }
  modint operator-() const { return modint::raw(val ? mod - val : u32(0)); }
  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;
  }
  static constexpr int get_mod() { return mod; }
  // (n, r), r は 1 の 2^n 乗根
  static constexpr pair<int, int> ntt_info() {
    if (mod == 120586241) return {20, 74066978};
    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 == 943718401) return {22, 663003469};
    if (mod == 998244353) return {23, 31};
    if (mod == 1004535809) return {21, 836905998};
    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; }
};

#ifdef FASTIO
template <int mod>
void rd(modint<mod> &x) {
  fastio::rd(x.val);
  x.val %= mod;
  // assert(0 <= x.val && x.val < mod);
}
template <int mod>
void wt(modint<mod> x) {
  fastio::wt(x.val);
}
#endif

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

// long でも大丈夫
// (val * x - 1) が mod の倍数になるようにする
// 特に mod=0 なら x=0 が満たす
ll mod_inv(ll val, ll mod) {
  if (mod == 0) return 0;
  mod = abs(mod);
  val %= mod;
  if (val < 0) val += mod;
  ll 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);
  }
  if (u < 0) u += mod;
  return u;
}
#line 2 "library/mod/crt3.hpp"

constexpr u32 mod_pow_constexpr(u64 a, u64 n, u32 mod) {
  a %= mod;
  u64 res = 1;
  FOR(32) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod, n /= 2;
  }
  return res;
}

template <typename T, u32 p0, u32 p1>
T CRT2(u64 a0, u64 a1) {
  static_assert(p0 < p1);
  static constexpr u64 x0_1 = mod_pow_constexpr(p0, p1 - 2, p1);
  u64 c = (a1 - a0 + p1) * x0_1 % p1;
  return a0 + c * p0;
}

template <typename T, u32 p0, u32 p1, u32 p2>
T CRT3(u64 a0, u64 a1, u64 a2) {
  static_assert(p0 < p1 && p1 < p2);
  static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
  static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
  static constexpr u64 p01 = u64(p0) * p1;
  u64 c = (a1 - a0 + p1) * x1 % p1;
  u64 ans_1 = a0 + c * p0;
  c = (a2 - ans_1 % p2 + p2) * x2 % p2;
  return T(ans_1) + T(c) * T(p01);
}

template <typename T, u32 p0, u32 p1, u32 p2, u32 p3, u32 p4>
T CRT5(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4) {
  static_assert(p0 < p1 && p1 < p2 && p2 < p3 && p3 < p4);
  static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
  static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
  static constexpr u64 x3
      = mod_pow_constexpr(u64(p0) * p1 % p3 * p2 % p3, p3 - 2, p3);
  static constexpr u64 x4
      = mod_pow_constexpr(u64(p0) * p1 % p4 * p2 % p4 * p3 % p4, p4 - 2, p4);
  static constexpr u64 p01 = u64(p0) * p1;
  static constexpr u64 p23 = u64(p2) * p3;
  u64 c = (a1 - a0 + p1) * x1 % p1;
  u64 ans_1 = a0 + c * p0;
  c = (a2 - ans_1 % p2 + p2) * x2 % p2;
  u128 ans_2 = ans_1 + c * static_cast<u128>(p01);
  c = static_cast<u64>(a3 - ans_2 % p3 + p3) * x3 % p3;
  u128 ans_3 = ans_2 + static_cast<u128>(c * p2) * p01;
  c = static_cast<u64>(a4 - ans_3 % p4 + p4) * x4 % p4;
  return T(ans_3) + T(c) * T(p01) * T(p23);
}
#line 2 "library/poly/convolution_naive.hpp"

template <class T, typename enable_if<!has_mod<T>::value>::type* = nullptr>
vc<T> convolution_naive(const vc<T>& a, const vc<T>& b) {
  int n = int(a.size()), m = int(b.size());
  if (n > m) return convolution_naive<T>(b, a);
  if (n == 0) return {};
  vector<T> ans(n + m - 1);
  FOR(i, n) FOR(j, m) ans[i + j] += a[i] * b[j];
  return ans;
}

template <class T, typename enable_if<has_mod<T>::value>::type* = nullptr>
vc<T> convolution_naive(const vc<T>& a, const vc<T>& b) {
  int n = int(a.size()), m = int(b.size());
  if (n > m) return convolution_naive<T>(b, a);
  if (n == 0) return {};
  vc<T> ans(n + m - 1);
  if (n <= 16 && (T::get_mod() < (1 << 30))) {
    for (int k = 0; k < n + m - 1; ++k) {
      int s = max(0, k - m + 1);
      int t = min(n, k + 1);
      u64 sm = 0;
      for (int i = s; i < t; ++i) { sm += u64(a[i].val) * (b[k - i].val); }
      ans[k] = sm;
    }
  } else {
    for (int k = 0; k < n + m - 1; ++k) {
      int s = max(0, k - m + 1);
      int t = min(n, k + 1);
      u128 sm = 0;
      for (int i = s; i < t; ++i) { sm += u64(a[i].val) * (b[k - i].val); }
      ans[k] = T::raw(sm % T::get_mod());
    }
  }
  return ans;
}
#line 2 "library/poly/convolution_karatsuba.hpp"

// 任意の環でできる
template <typename T>
vc<T> convolution_karatsuba(const vc<T>& f, const vc<T>& g) {
  const int thresh = 30;
  if (min(len(f), len(g)) <= thresh) return convolution_naive(f, g);
  int n = max(len(f), len(g));
  int m = ceil(n, 2);
  vc<T> f1, f2, g1, g2;
  if (len(f) < m) f1 = f;
  if (len(f) >= m) f1 = {f.begin(), f.begin() + m};
  if (len(f) >= m) f2 = {f.begin() + m, f.end()};
  if (len(g) < m) g1 = g;
  if (len(g) >= m) g1 = {g.begin(), g.begin() + m};
  if (len(g) >= m) g2 = {g.begin() + m, g.end()};
  vc<T> a = convolution_karatsuba(f1, g1);
  vc<T> b = convolution_karatsuba(f2, g2);
  FOR(i, len(f2)) f1[i] += f2[i];
  FOR(i, len(g2)) g1[i] += g2[i];
  vc<T> c = convolution_karatsuba(f1, g1);
  vc<T> F(len(f) + len(g) - 1);
  assert(2 * m + len(b) <= len(F));
  FOR(i, len(a)) F[i] += a[i], c[i] -= a[i];
  FOR(i, len(b)) F[2 * m + i] += b[i], c[i] -= b[i];
  if (c.back() == T(0)) c.pop_back();
  FOR(i, len(c)) if (c[i] != T(0)) F[m + i] += c[i];
  return F;
}
#line 2 "library/poly/ntt.hpp"

template <class mint>
void ntt(vector<mint>& a, bool inverse) {
  assert(mint::can_ntt());
  const int rank2 = mint::ntt_info().fi;
  const int mod = mint::get_mod();
  static array<mint, 30> root, iroot;
  static array<mint, 30> rate2, irate2;
  static array<mint, 30> rate3, irate3;

  assert(rank2 != -1 && len(a) <= (1 << max(0, rank2)));

  static bool prepared = 0;
  if (!prepared) {
    prepared = 1;
    root[rank2] = mint::ntt_info().se;
    iroot[rank2] = mint(1) / root[rank2];
    FOR_R(i, rank2) {
      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];
    }
    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];
    }
  }

  int n = int(a.size());
  int h = topbit(n);
  assert(n == 1 << h);
  if (!inverse) {
    int len = 0;
    while (len < h) {
      if (h - len == 1) {
        int p = 1 << (h - len - 1);
        mint rot = 1;
        FOR(s, 1 << len) {
          int offset = s << (h - len);
          FOR(i, p) {
            auto l = a[i + offset];
            auto r = a[i + offset + p] * rot;
            a[i + offset] = l + r;
            a[i + offset + p] = l - r;
          }
          rot *= rate2[topbit(~s & -~s)];
        }
        len++;
      } else {
        int p = 1 << (h - len - 2);
        mint rot = 1, imag = 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++) {
            u64 mod2 = u64(mod) * mod;
            u64 a0 = a[i + offset].val;
            u64 a1 = u64(a[i + offset + p].val) * rot.val;
            u64 a2 = u64(a[i + offset + 2 * p].val) * rot2.val;
            u64 a3 = u64(a[i + offset + 3 * p].val) * rot3.val;
            u64 a1na3imag = (a1 + mod2 - a3) % mod * imag.val;
            u64 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);
          }
          rot *= rate3[topbit(~s & -~s)];
        }
        len += 2;
      }
    }
  } else {
    mint coef = mint(1) / mint(len(a));
    FOR(i, len(a)) a[i] *= coef;
    int len = h;
    while (len) {
      if (len == 1) {
        int p = 1 << (h - len);
        mint irot = 1;
        FOR(s, 1 << (len - 1)) {
          int offset = s << (h - len + 1);
          FOR(i, p) {
            u64 l = a[i + offset].val;
            u64 r = a[i + offset + p].val;
            a[i + offset] = l + r;
            a[i + offset + p] = (mod + l - r) * irot.val;
          }
          irot *= irate2[topbit(~s & -~s)];
        }
        len--;
      } else {
        int p = 1 << (h - len);
        mint irot = 1, iimag = iroot[2];
        FOR(s, (1 << (len - 2))) {
          mint irot2 = irot * irot;
          mint irot3 = irot2 * irot;
          int offset = s << (h - len + 2);
          for (int i = 0; i < p; i++) {
            u64 a0 = a[i + offset + 0 * p].val;
            u64 a1 = a[i + offset + 1 * p].val;
            u64 a2 = a[i + offset + 2 * p].val;
            u64 a3 = a[i + offset + 3 * p].val;
            u64 x = (mod + a2 - a3) * iimag.val % mod;
            a[i + offset] = a0 + a1 + a2 + a3;
            a[i + offset + 1 * p] = (a0 + mod - a1 + x) * irot.val;
            a[i + offset + 2 * p] = (a0 + a1 + 2 * mod - a2 - a3) * irot2.val;
            a[i + offset + 3 * p] = (a0 + 2 * mod - a1 - x) * irot3.val;
          }
          irot *= irate3[topbit(~s & -~s)];
        }
        len -= 2;
      }
    }
  }
}
#line 1 "library/poly/fft.hpp"
namespace CFFT {
using real = double;

struct C {
  real x, y;

  C() : x(0), y(0) {}

  C(real x, real y) : x(x), y(y) {}
  inline C operator+(const C& c) const { return C(x + c.x, y + c.y); }
  inline C operator-(const C& c) const { return C(x - c.x, y - c.y); }
  inline C operator*(const C& c) const {
    return C(x * c.x - y * c.y, x * c.y + y * c.x);
  }

  inline C conj() const { return C(x, -y); }
};

const real PI = acosl(-1);
int base = 1;
vector<C> rts = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};

void ensure_base(int nbase) {
  if (nbase <= base) return;
  rev.resize(1 << nbase);
  rts.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  while (base < nbase) {
    real angle = PI * 2.0 / (1 << (base + 1));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      rts[i << 1] = rts[i];
      real angle_i = angle * (2 * i + 1 - (1 << base));
      rts[(i << 1) + 1] = C(cos(angle_i), sin(angle_i));
    }
    ++base;
  }
}

void fft(vector<C>& a, int n) {
  assert((n & (n - 1)) == 0);
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) { swap(a[i], a[rev[i] >> shift]); }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        C z = a[i + j + k] * rts[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}
} // namespace CFFT
#line 9 "library/poly/convolution.hpp"

template <class mint>
vector<mint> convolution_ntt(vector<mint> a, vector<mint> b) {
  if (a.empty() || b.empty()) return {};
  int n = int(a.size()), m = int(b.size());
  int sz = 1;
  while (sz < n + m - 1) sz *= 2;

  // sz = 2^k のときの高速化。分割統治的なやつで損しまくるので。
  if ((n + m - 3) <= sz / 2) {
    auto a_last = a.back(), b_last = b.back();
    a.pop_back(), b.pop_back();
    auto c = convolution(a, b);
    c.resize(n + m - 1);
    c[n + m - 2] = a_last * b_last;
    FOR(i, len(a)) c[i + len(b)] += a[i] * b_last;
    FOR(i, len(b)) c[i + len(a)] += b[i] * a_last;
    return c;
  }

  a.resize(sz), b.resize(sz);
  bool same = a == b;
  ntt(a, 0);
  if (same) {
    b = a;
  } else {
    ntt(b, 0);
  }
  FOR(i, sz) a[i] *= b[i];
  ntt(a, 1);
  a.resize(n + m - 1);
  return a;
}

template <typename mint>
vector<mint> convolution_garner(const vector<mint>& a, const vector<mint>& b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  static constexpr int p0 = 167772161;
  static constexpr int p1 = 469762049;
  static constexpr int p2 = 754974721;
  using mint0 = modint<p0>;
  using mint1 = modint<p1>;
  using mint2 = modint<p2>;
  vc<mint0> a0(n), b0(m);
  vc<mint1> a1(n), b1(m);
  vc<mint2> a2(n), b2(m);
  FOR(i, n) a0[i] = a[i].val, a1[i] = a[i].val, a2[i] = a[i].val;
  FOR(i, m) b0[i] = b[i].val, b1[i] = b[i].val, b2[i] = b[i].val;
  auto c0 = convolution_ntt<mint0>(a0, b0);
  auto c1 = convolution_ntt<mint1>(a1, b1);
  auto c2 = convolution_ntt<mint2>(a2, b2);
  vc<mint> c(len(c0));
  FOR(i, n + m - 1) {
    c[i] = CRT3<mint, p0, p1, p2>(c0[i].val, c1[i].val, c2[i].val);
  }
  return c;
}

template <typename R>
vc<double> convolution_fft(const vc<R>& a, const vc<R>& b) {
  using C = CFFT::C;
  int need = (int)a.size() + (int)b.size() - 1;
  int nbase = 1;
  while ((1 << nbase) < need) nbase++;
  CFFT::ensure_base(nbase);
  int sz = 1 << nbase;
  vector<C> fa(sz);
  for (int i = 0; i < sz; i++) {
    double x = (i < (int)a.size() ? a[i] : 0);
    double y = (i < (int)b.size() ? b[i] : 0);
    fa[i] = C(x, y);
  }
  CFFT::fft(fa, sz);
  C r(0, -0.25 / (sz >> 1)), s(0, 1), t(0.5, 0);
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    C z = (fa[j] * fa[j] - (fa[i] * fa[i]).conj()) * r;
    fa[j] = (fa[i] * fa[i] - (fa[j] * fa[j]).conj()) * r;
    fa[i] = z;
  }
  for (int i = 0; i < (sz >> 1); i++) {
    C A0 = (fa[i] + fa[i + (sz >> 1)]) * t;
    C A1 = (fa[i] - fa[i + (sz >> 1)]) * t * CFFT::rts[(sz >> 1) + i];
    fa[i] = A0 + A1 * s;
  }
  CFFT::fft(fa, sz >> 1);
  vector<double> ret(need);
  for (int i = 0; i < need; i++) {
    ret[i] = (i & 1 ? fa[i >> 1].y : fa[i >> 1].x);
  }
  return ret;
}

vector<ll> convolution(const vector<ll>& a, const vector<ll>& b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  if (min(n, m) <= 2500) return convolution_naive(a, b);
  ll abs_sum_a = 0, abs_sum_b = 0;
  ll LIM = 1e15;
  FOR(i, n) abs_sum_a = min(LIM, abs_sum_a + abs(a[i]));
  FOR(i, m) abs_sum_b = min(LIM, abs_sum_b + abs(b[i]));
  if (i128(abs_sum_a) * abs_sum_b < 1e15) {
    vc<double> c = convolution_fft<ll>(a, b);
    vc<ll> res(len(c));
    FOR(i, len(c)) res[i] = ll(floor(c[i] + .5));
    return res;
  }

  static constexpr unsigned long long MOD1 = 754974721; // 2^24
  static constexpr unsigned long long MOD2 = 167772161; // 2^25
  static constexpr unsigned long long MOD3 = 469762049; // 2^26
  static constexpr unsigned long long M2M3 = MOD2 * MOD3;
  static constexpr unsigned long long M1M3 = MOD1 * MOD3;
  static constexpr unsigned long long M1M2 = MOD1 * MOD2;
  static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3;

  static const unsigned long long i1 = mod_inv(MOD2 * MOD3, MOD1);
  static const unsigned long long i2 = mod_inv(MOD1 * MOD3, MOD2);
  static const unsigned long long i3 = mod_inv(MOD1 * MOD2, MOD3);

  using mint1 = modint<MOD1>;
  using mint2 = modint<MOD2>;
  using mint3 = modint<MOD3>;

  vc<mint1> a1(n), b1(m);
  vc<mint2> a2(n), b2(m);
  vc<mint3> a3(n), b3(m);
  FOR(i, n) a1[i] = a[i], a2[i] = a[i], a3[i] = a[i];
  FOR(i, m) b1[i] = b[i], b2[i] = b[i], b3[i] = b[i];

  auto c1 = convolution_ntt<mint1>(a1, b1);
  auto c2 = convolution_ntt<mint2>(a2, b2);
  auto c3 = convolution_ntt<mint3>(a3, b3);

  vc<ll> c(n + m - 1);
  FOR(i, n + m - 1) {
    u64 x = 0;
    x += (c1[i].val * i1) % MOD1 * M2M3;
    x += (c2[i].val * i2) % MOD2 * M1M3;
    x += (c3[i].val * i3) % MOD3 * M1M2;
    ll diff = c1[i].val - ((long long)(x) % (long long)(MOD1));
    if (diff < 0) diff += MOD1;
    static constexpr unsigned long long offset[5]
        = {0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3};
    x -= offset[diff % 5];
    c[i] = x;
  }
  return c;
}

template <typename mint>
vc<mint> convolution(const vc<mint>& a, const vc<mint>& b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  if (mint::can_ntt()) {
    if (min(n, m) <= 50) return convolution_karatsuba<mint>(a, b);
    return convolution_ntt(a, b);
  }
  if (min(n, m) <= 200) return convolution_karatsuba<mint>(a, b);
  return convolution_garner(a, b);
}
#line 2 "library/poly/ntt_doubling.hpp"

#line 4 "library/poly/ntt_doubling.hpp"

// 2^k 次多項式の長さ 2^k が与えられるので 2^k+1 にする
template <typename mint, bool transposed = false>
void ntt_doubling(vector<mint>& a) {
  static array<mint, 30> root;
  static bool prepared = 0;
  if (!prepared) {
    prepared = 1;
    const int rank2 = mint::ntt_info().fi;
    root[rank2] = mint::ntt_info().se;
    FOR_R(i, rank2) { root[i] = root[i + 1] * root[i + 1]; }
  }

  if constexpr (!transposed) {
    const int M = (int)a.size();
    auto b = a;
    ntt(b, 1);
    mint r = 1, zeta = root[topbit(2 * M)];
    FOR(i, M) b[i] *= r, r *= zeta;
    ntt(b, 0);
    copy(begin(b), end(b), back_inserter(a));
  } else {
    const int M = len(a) / 2;
    vc<mint> tmp = {a.begin(), a.begin() + M};
    a = {a.begin() + M, a.end()};
    transposed_ntt(a, 0);
    mint r = 1, zeta = root[topbit(2 * M)];
    FOR(i, M) a[i] *= r, r *= zeta;
    transposed_ntt(a, 1);
    FOR(i, M) a[i] += tmp[i];
  }
}
#line 5 "library/poly/sum_of_rationals.hpp"

// 有理式の和を計算する。分割統治 O(Nlog^2N)。N は次数の和。
template <typename mint>
pair<vc<mint>, vc<mint>> sum_of_rationals(vc<pair<vc<mint>, vc<mint>>> dat) {
  if (len(dat) == 0) {
    vc<mint> f = {0}, g = {1};
    return {f, g};
  }
  using P = pair<vc<mint>, vc<mint>>;
  auto add = [&](P& a, P& b) -> P {
    int na = len(a.fi) - 1, da = len(a.se) - 1;
    int nb = len(b.fi) - 1, db = len(b.se) - 1;
    int n = max(na + db, da + nb);
    vc<mint> num(n + 1);
    {
      auto f = convolution(a.fi, b.se);
      FOR(i, len(f)) num[i] += f[i];
    }
    {
      auto f = convolution(a.se, b.fi);
      FOR(i, len(f)) num[i] += f[i];
    }
    auto den = convolution(a.se, b.se);
    return {num, den};
  };

  while (len(dat) > 1) {
    int n = len(dat);
    FOR(i, 1, n, 2) { dat[i - 1] = add(dat[i - 1], dat[i]); }
    FOR(i, ceil(n, 2)) dat[i] = dat[2 * i];
    dat.resize(ceil(n, 2));
  }
  return dat[0];
}

// sum wt[i]/(1-A[i]x)
template <typename mint>
pair<vc<mint>, vc<mint>> sum_of_rationals_1(vc<mint> A, vc<mint> wt) {
  using poly = vc<mint>;
  int n = 1;
  while (n < len(A)) n *= 2;
  int k = topbit(n);
  vc<mint> F(n), G(n);
  FOR(i, len(A)) F[i] = -A[i], G[i] = wt[i];

  FOR(d, k) {
    int b = 1 << d;
    for (int L = 0; L < n; L += 2 * b) {
      poly f1 = {F.begin() + L, F.begin() + L + b};
      poly f2 = {F.begin() + L + b, F.begin() + L + 2 * b};
      poly g1 = {G.begin() + L, G.begin() + L + b};
      poly g2 = {G.begin() + L + b, G.begin() + L + 2 * b};
      ntt_doubling(f1), ntt_doubling(f2);
      ntt_doubling(g1), ntt_doubling(g2);
      FOR(i, b) f1[i] += 1, f2[i] += 1;
      FOR(i, b, 2 * b) f1[i] -= 1, f2[i] -= 1;
      FOR(i, 2 * b) F[L + i] = f1[i] * f2[i] - 1;
      FOR(i, 2 * b) G[L + i] = g1[i] * f2[i] + g2[i] * f1[i];
    }
  }
  ntt(F, 1), ntt(G, 1);
  F.eb(1);
  reverse(all(F)), reverse(all(G));
  F.resize(len(A) + 1);
  G.resize(len(A));
  return {G, F};
}
#line 2 "library/poly/fps_div.hpp"

#line 2 "library/poly/count_terms.hpp"
template<typename mint>
int count_terms(const vc<mint>& f){
  int t = 0;
  FOR(i, len(f)) if(f[i] != mint(0)) ++t;
  return t;
}
#line 4 "library/poly/fps_inv.hpp"

template <typename mint>
vc<mint> fps_inv_sparse(const vc<mint>& f) {
  int N = len(f);
  vc<pair<int, mint>> dat;
  FOR(i, 1, N) if (f[i] != mint(0)) dat.eb(i, f[i]);
  vc<mint> g(N);
  mint g0 = mint(1) / f[0];
  g[0] = g0;
  FOR(n, 1, N) {
    mint rhs = 0;
    for (auto&& [k, fk]: dat) {
      if (k > n) break;
      rhs -= fk * g[n - k];
    }
    g[n] = rhs * g0;
  }
  return g;
}

template <typename mint>
vc<mint> fps_inv_dense_ntt(const vc<mint>& F) {
  vc<mint> G = {mint(1) / F[0]};
  ll N = len(F), n = 1;
  G.reserve(N);
  while (n < N) {
    vc<mint> f(2 * n), g(2 * n);
    FOR(i, min(N, 2 * n)) f[i] = F[i];
    FOR(i, n) g[i] = G[i];
    ntt(f, false), ntt(g, false);
    FOR(i, 2 * n) f[i] *= g[i];
    ntt(f, true);
    FOR(i, n) f[i] = 0;
    ntt(f, false);
    FOR(i, 2 * n) f[i] *= g[i];
    ntt(f, true);
    FOR(i, n, min(N, 2 * n)) G.eb(-f[i]);
    n *= 2;
  }
  return G;
}

template <typename mint>
vc<mint> fps_inv_dense(const vc<mint>& F) {
  if (mint::can_ntt()) return fps_inv_dense_ntt(F);
  const int N = len(F);
  vc<mint> R = {mint(1) / F[0]};
  vc<mint> p;
  int m = 1;
  while (m < N) {
    p = convolution(R, R);
    p.resize(m + m);
    vc<mint> f = {F.begin(), F.begin() + min(m + m, N)};
    p = convolution(p, f);
    R.resize(m + m);
    FOR(i, m + m) R[i] = R[i] + R[i] - p[i];
    m += m;
  }
  R.resize(N);
  return R;
}

template <typename mint>
vc<mint> fps_inv(const vc<mint>& f) {
  assert(f[0] != mint(0));
  int n = count_terms(f);
  int t = (mint::can_ntt() ? 160 : 820);
  return (n <= t ? fps_inv_sparse<mint>(f) : fps_inv_dense<mint>(f));
}
#line 5 "library/poly/fps_div.hpp"

// f/g. f の長さで出力される.
template <typename mint, bool SPARSE = false>
vc<mint> fps_div(vc<mint> f, vc<mint> g) {
  if (SPARSE || count_terms(g) < 200) return fps_div_sparse(f, g);
  int n = len(f);
  g.resize(n);
  g = fps_inv<mint>(g);
  f = convolution(f, g);
  f.resize(n);
  return f;
}

// f/g ただし g は sparse
template <typename mint>
vc<mint> fps_div_sparse(vc<mint> f, vc<mint>& g) {
  if (g[0] != mint(1)) {
    mint cf = g[0].inverse();
    for (auto&& x: f) x *= cf;
    for (auto&& x: g) x *= cf;
  }

  vc<pair<int, mint>> dat;
  FOR(i, 1, len(g)) if (g[i] != mint(0)) dat.eb(i, -g[i]);
  FOR(i, len(f)) {
    for (auto&& [j, x]: dat) {
      if (i >= j) f[i] += x * f[i - j];
    }
  }
  return f;
}
#line 2 "library/poly/middle_product.hpp"

#line 5 "library/poly/middle_product.hpp"

// n, m 次多項式 (n>=m) a, b → n-m 次多項式 c
// c[i] = sum_j b[j]a[i+j]
template <typename mint>
vc<mint> middle_product(vc<mint>& a, vc<mint>& b) {
  assert(len(a) >= len(b));
  if (b.empty()) return vc<mint>(len(a) - len(b) + 1);
  if (min(len(b), len(a) - len(b) + 1) <= 60) {
    return middle_product_naive(a, b);
  }
  if (!(mint::can_ntt())) {
    return middle_product_garner(a, b);
  } else {
    int n = 1 << __lg(2 * len(a) - 1);
    vc<mint> fa(n), fb(n);
    copy(a.begin(), a.end(), fa.begin());
    copy(b.rbegin(), b.rend(), fb.begin());
    ntt(fa, 0), ntt(fb, 0);
    FOR(i, n) fa[i] *= fb[i];
    ntt(fa, 1);
    fa.resize(len(a));
    fa.erase(fa.begin(), fa.begin() + len(b) - 1);
    return fa;
  }
}

template <typename mint>
vc<mint> middle_product_garner(vc<mint>& a, vc<mint> b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  static constexpr int p0 = 167772161;
  static constexpr int p1 = 469762049;
  static constexpr int p2 = 754974721;
  using mint0 = modint<p0>;
  using mint1 = modint<p1>;
  using mint2 = modint<p2>;
  vc<mint0> a0(n), b0(m);
  vc<mint1> a1(n), b1(m);
  vc<mint2> a2(n), b2(m);
  FOR(i, n) a0[i] = a[i].val, a1[i] = a[i].val, a2[i] = a[i].val;
  FOR(i, m) b0[i] = b[i].val, b1[i] = b[i].val, b2[i] = b[i].val;
  auto c0 = middle_product<mint0>(a0, b0);
  auto c1 = middle_product<mint1>(a1, b1);
  auto c2 = middle_product<mint2>(a2, b2);
  vc<mint> c(len(c0));
  FOR(i, n - m + 1) {
    c[i] = CRT3<mint, p0, p1, p2>(c0[i].val, c1[i].val, c2[i].val);
  }
  return c;
}

template <typename mint>
vc<mint> middle_product_naive(vc<mint>& a, vc<mint>& b) {
  vc<mint> res(len(a) - len(b) + 1);
  FOR(i, len(res)) FOR(j, len(b)) res[i] += b[j] * a[i + j];
  return res;
}
#line 2 "library/poly/transposed_ntt.hpp"

template <class mint>
void transposed_ntt(vector<mint>& a, bool inverse) {
  assert(mint::can_ntt());
  const int rank2 = mint::ntt_info().fi;
  const int mod = mint::get_mod();
  static array<mint, 30> root, iroot;
  static array<mint, 30> rate2, irate2;
  static array<mint, 30> rate3, irate3;

  assert(rank2 != -1 && len(a) <= (1 << max(0, rank2)));

  static bool prepared = 0;
  if (!prepared) {
    prepared = 1;
    root[rank2] = mint::ntt_info().se;
    iroot[rank2] = mint(1) / root[rank2];
    FOR_R(i, rank2) {
      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];
    }
    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];
    }
  }

  int n = int(a.size());
  int h = topbit(n);
  assert(n == 1 << h);
  if (!inverse) {
    int len = h;
    while (len > 0) {
      if (len == 1) {
        int p = 1 << (h - len);
        mint rot = 1;
        FOR(s, 1 << (len - 1)) {
          int offset = s << (h - len + 1);
          FOR(i, p) {
            u64 l = a[i + offset].val;
            u64 r = a[i + offset + p].val;
            a[i + offset] = l + r;
            a[i + offset + p] = (mod + l - r) * rot.val;
          }
          rot *= rate2[topbit(~s & -~s)];
        }
        len--;
      } else {
        int p = 1 << (h - len);
        mint rot = 1, imag = root[2];
        FOR(s, (1 << (len - 2))) {
          int offset = s << (h - len + 2);
          mint rot2 = rot * rot;
          mint rot3 = rot2 * rot;
          for (int i = 0; i < p; i++) {
            u64 a0 = a[i + offset + 0 * p].val;
            u64 a1 = a[i + offset + 1 * p].val;
            u64 a2 = a[i + offset + 2 * p].val;
            u64 a3 = a[i + offset + 3 * p].val;
            u64 x = (mod + a2 - a3) * imag.val % mod;
            a[i + offset] = a0 + a1 + a2 + a3;
            a[i + offset + 1 * p] = (a0 + mod - a1 + x) * rot.val;
            a[i + offset + 2 * p] = (a0 + a1 + 2 * mod - a2 - a3) * rot2.val;
            a[i + offset + 3 * p] = (a0 + 2 * mod - a1 - x) * rot3.val;
          }
          rot *= rate3[topbit(~s & -~s)];
        }
        len -= 2;
      }
    }
  } else {
    mint coef = mint(1) / mint(len(a));
    FOR(i, len(a)) a[i] *= coef;
    int len = 0;
    while (len < h) {
      if (len == h - 1) {
        int p = 1 << (h - len - 1);
        mint irot = 1;
        FOR(s, 1 << len) {
          int offset = s << (h - len);
          FOR(i, p) {
            auto l = a[i + offset];
            auto r = a[i + offset + p] * irot;
            a[i + offset] = l + r;
            a[i + offset + p] = l - r;
          }
          irot *= irate2[topbit(~s & -~s)];
        }
        len++;
      } else {
        int p = 1 << (h - len - 2);
        mint irot = 1, iimag = iroot[2];
        for (int s = 0; s < (1 << len); s++) {
          mint irot2 = irot * irot;
          mint irot3 = irot2 * irot;
          int offset = s << (h - len);
          for (int i = 0; i < p; i++) {
            u64 mod2 = u64(mod) * mod;
            u64 a0 = a[i + offset].val;
            u64 a1 = u64(a[i + offset + p].val) * irot.val;
            u64 a2 = u64(a[i + offset + 2 * p].val) * irot2.val;
            u64 a3 = u64(a[i + offset + 3 * p].val) * irot3.val;
            u64 a1na3imag = (a1 + mod2 - a3) % mod * iimag.val;
            u64 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);
          }
          irot *= irate3[topbit(~s & -~s)];
        }
        len += 2;
      }
    }
  }
}
#line 11 "main.cpp"

template <typename mint>
vc<mint> multipoint_evaluation(vc<mint> f, vc<mint> point) {
  using poly = vc<mint>;
  int n = 1, k = 0;
  while (n < len(point)) n *= 2, ++k;
  vv(mint, F, k + 1, 2 * n);
  FOR(i, len(point)) F[0][2 * i] = -point[i];

  FOR(d, k) {
    int b = 1 << d;
    for (int L = 0; L < 2 * n; L += 4 * b) {
      poly f1 = {F[d].begin() + L, F[d].begin() + L + b};
      poly f2 = {F[d].begin() + L + 2 * b, F[d].begin() + L + 3 * b};
      ntt_doubling(f1), ntt_doubling(f2);
      FOR(i, b) f1[i] += 1, f2[i] += 1;
      FOR(i, b, 2 * b) f1[i] -= 1, f2[i] -= 1;
      copy(all(f1), F[d].begin() + L);
      copy(all(f2), F[d].begin() + L + 2 * b);
      FOR(i, 2 * b) { F[d + 1][L + i] = f1[i] * f2[i] - 1; }
    }
  }
  vc<mint> P = {F[k].begin(), F[k].begin() + n};
  ntt(P, 1), P.eb(1), reverse(all(P)), P.resize(len(f)), P = fps_inv<mint>(P);
  f.resize(n + len(P) - 1), f = middle_product<mint>(f, P), reverse(all(f));
  transposed_ntt(f, 1);
  vc<mint>& G = f;
  FOR_R(d, k) {
    vc<mint> nxt_G(n);
    int b = 1 << d;
    for (int L = 0; L < n; L += 2 * b) {
      vc<mint> g1(2 * b), g2(2 * b);
      FOR(i, 2 * b) { g1[i] = G[L + i] * F[d][2 * L + 2 * b + i]; }
      FOR(i, 2 * b) { g2[i] = G[L + i] * F[d][2 * L + i]; }
      ntt_doubling<mint, true>(g1), ntt_doubling<mint, true>(g2);
      FOR(i, b) { nxt_G[L + i] = g1[i], nxt_G[L + b + i] = g2[i]; }
    }
    swap(G, nxt_G);
  }
  G.resize(len(point));
  return G;
}

using mint = modint998;
#define vi vector<int>
#define pb push_back
const int mod=998244353,G=3,GI=(mod+1)/3;
int qpow(int a,int b){
	int c=1;for(;b;b>>=1){
		if(b&1)c=1ll*a*c%mod;
		a=1ll*a*a%mod;
	}
	return c;
}
int L,lb[1<<20];
void init(int n){
	L=1;while(L<=n)L<<=1;
	for(int i=0;i<L;i++)lb[i]=(lb[i>>1]>>1)|((i&1)?(L>>1):0);
}
void NTT(vi &a,int fl){
	for(int i=0;i<L;i++)if(i>lb[i])swap(a[i],a[lb[i]]);
	for(int o=1;o<L;o<<=1){
		int Wn=qpow(fl?G:GI,(mod-1)/(o<<1));
		for(int i=0;i<L;i+=(o<<1))for(int j=0,w=1;j<o;j++,w=1ll*w*Wn%mod){
			int x=a[i+j],y=1ll*w*a[i+j+o]%mod;
			a[i+j]=(x+y)%mod,a[i+j+o]=(x-y)%mod;
		}
	}
	if(!fl){
		int I=qpow(L,mod-2);
		for(int i=0;i<L;i++)a[i]=1ll*a[i]*I%mod;
	}
}
vi mul(vi a,vi b){
	int n=(int)a.size()+(int)b.size()-1;init(n);
	a.resize(L),b.resize(L),NTT(a,1),NTT(b,1);
	for(int i=0;i<L;i++)a[i]=1ll*a[i]*b[i]%mod;
	NTT(a,0);a.resize(n);
	return a;
}
mint s[101000],ans;
int n,m,al[101000],ar[101000],p2[101000],s2[101000],bi[101000],A,AL;
int ht[100100];
#define pi pair<int,int>
#define fi first
#define se second
vector<pi>g[400100];
void up(int p,int l,int r,int x,int y,pi z){
    if(x<=l&&r<=y){
        g[p].push_back(z);
        return;
    }
    int mid=(l+r)>>1;
    if(x<=mid)up(p<<1,l,mid,x,y,z);
    if(y>mid)up(p<<1|1,mid+1,r,x,y,z);
}
vector<mint> Fuc(vector<pi>a){
    if(a.size()==1)return {mint(a[0].se),mint(a[0].fi)};
    int n=a.size();
    vector<pi>a_;
    while(a.size()>n/2)a_.pb(a.back()),a.pop_back();
    return convolution(Fuc(a_),Fuc(a));
}
void solu(int p,int l,int r){
    if(l<r){int mid=(l+r)>>1;solu(p<<1,l,mid),solu(p<<1|1,mid+1,r);}
    if(g[p].empty())return;
    vector<mint>A=Fuc(g[p]),B;
    for(int i=l;i<=r;i++)B.push_back(mint(i));
    auto dd=multipoint_evaluation(A,B);
    for(int i=l;i<=r;i++){
        mint e=0;
        s[i]=s[i]*dd[i-l];
    }
}
void Sol(int Z){
    for(int i=1;i<=m;i++)s[i]=1,s2[i]=0,ht[i]=1;
    for(int i=1;i<=m*4;i++)g[i].clear();
    int K=0;
    for(int i=1;i<=n;i++){
        if(al[i]!=-1&&ar[i]!=-1)s2[al[i]]++,s2[ar[i]+1]--;
        else if(al[i]==-1&&ar[i]==-1)K++;
        else if(al[i]==-1){
            if(ar[i])up(1,1,m,1,ar[i],{1,bi[i]});
            ht[ar[i]+1]=1ll*ht[ar[i]+1]*bi[i]%mod;
            /*for(int j=1;j<=m;j++){
                if(j<=ar[i])
                s[j]=1ll*s[j]*(bi[i]+j)%mod;
                else s[j]=1ll*s[j]*bi[i]%mod;
            }*/
        }
        else{
            /*for(int j=1;j<=m;j++){
                if(j>=al[i])s[j]=1ll*s[j]*(bi[i]+m-j+1)%mod;
                else s[j]=1ll*s[j]*bi[i]%mod;
            }*/
           if(al[i]<=m)up(1,1,m,al[i],m,{mod-1,bi[i]+m+1});
           ht[1]=1ll*ht[1]*bi[i]%mod;
           ht[al[i]]=1ll*ht[al[i]]*qpow(bi[i],mod-2)%mod;
        }
    }
    int pz=1;
    for(int i=1;i<=m;i++)pz=1ll*pz*ht[i]%mod,
    s2[i]+=s2[i-1],s[i]=s[i]*p2[s2[i]]*qpow(1ll*i*(m-i+1)%mod+A,K)*pz;
    solu(1,1,m);
    for(int i=1;i<=m;i++)ans+=s[i]*Z;
}
int main(){
    p2[0]=1;
    scanf("%d%d",&n,&m),p2[0]=1;
    A=(1ll*m*(m+1)/2)%mod,AL=1;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&al[i],&ar[i]),p2[i]=2*p2[i-1]%mod;
        if(ar[i]==-1&&al[i]==-1)bi[i]=A;
        else if(al[i]==-1)bi[i]=ar[i];
        else if(ar[i]==-1)bi[i]=m-al[i]+1;
        else bi[i]=1;
        AL=1ll*AL*bi[i]%mod;
    }
    Sol(1),m--;
    for(int i=1;i<=n;i++)if(ar[i]!=-1)ar[i]--;
    Sol(mod-1);
    ans+=mod-AL;
    print(ans);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7988kb

input:

3 3
1 -1
2 2
2 3

output:

18

result:

ok "18"

Test #2:

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

input:

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

output:

15

result:

ok "15"

Test #3:

score: 0
Accepted
time: 2ms
memory: 9988kb

input:

10 13
4 -1
-1 -1
7 11
-1 -1
-1 -1
-1 -1
11 -1
3 8
-1 9
-1 -1

output:

841024210

result:

ok "841024210"

Test #4:

score: 0
Accepted
time: 7ms
memory: 8164kb

input:

46508 20888
9935 17879
803 14990
5348 5434
2630 15632
6302 16990
4875 20297
15220 17881
10385 16908
7395 13312
4794 5956
1867 13086
5261 14262
506 19423
18148 20403
1083 6648
13858 18123
4036 14289
7743 11040
15055 20527
1576 8846
10614 12995
2111 16084
6669 14966
1704 16041
8030 16085
6939 9047
281...

output:

622373905

result:

ok "622373905"

Test #5:

score: 0
Accepted
time: 9ms
memory: 9884kb

input:

71468 8417
1491 3032
3940 4632
4208 6407
419 5971
3498 5578
1905 3096
1962 3199
1291 2756
694 8294
2090 4946
7008 7851
2751 2882
2706 6889
108 5225
136 7934
2980 7661
4680 4716
1442 6931
610 2433
2029 7632
7493 8090
3186 5781
381 884
3605 6949
2658 4522
3990 5039
581 1842
2834 7073
969 7024
2753 637...

output:

624258105

result:

ok "624258105"

Test #6:

score: 0
Accepted
time: 7ms
memory: 8216kb

input:

33867 68520
14011 22082
27837 41559
2144 15734
12979 31839
886 12147
24281 49957
9826 65576
1722 19415
14491 47918
50636 58028
17563 41887
16942 39177
24530 40332
1552 34825
14639 29619
3990 12925
47753 51870
40028 53008
2544 30228
8858 41307
21578 60354
50609 60612
20338 21716
40758 41397
26456 648...

output:

222682065

result:

ok "222682065"

Test #7:

score: 0
Accepted
time: 10ms
memory: 8052kb

input:

75153 39190
26291 36182
5293 32997
7346 9934
2591 35269
19354 29051
22682 33232
2834 11921
15097 26586
21097 22576
16043 37502
6017 38992
13072 36070
31124 38395
11041 29593
3057 25268
20445 29246
32902 33740
22225 23893
21068 35059
13229 23256
33091 34091
28800 38407
21094 23905
6683 32400
3521 341...

output:

644912633

result:

ok "644912633"

Test #8:

score: 0
Accepted
time: 7ms
memory: 8256kb

input:

38983 51827
23950 48250
8451 21390
34709 41670
8577 19224
28009 38802
8116 46250
33417 41876
6012 27827
20506 28824
32508 36718
9519 42347
16217 47490
27201 43904
28345 36254
18056 51005
32416 48961
3944 44653
35051 46634
7354 28377
184 18868
5637 41072
17151 32335
46925 51578
38617 43416
28959 4596...

output:

66873446

result:

ok "66873446"

Test #9:

score: 0
Accepted
time: 2ms
memory: 9860kb

input:

7679 44174
248 9943
15956 26442
2725 33239
10294 16406
1756 43460
17823 36584
4116 8280
1378 8294
2284 6085
14532 29528
131 29456
8000 15758
7967 36529
18153 22142
24272 42715
5906 43341
15538 30632
30706 39656
578 37881
4671 42928
12276 35991
11872 39136
27705 33517
21108 27545
2303 27196
38175 400...

output:

346752121

result:

ok "346752121"

Test #10:

score: 0
Accepted
time: 11ms
memory: 10124kb

input:

64986 73724
3612 17490
57957 71291
9395 47466
16850 17666
34093 69220
9241 43326
3408 50034
25 43682
15457 38280
11293 12231
23016 60834
15987 24580
7089 70748
46238 49344
56579 71985
19218 59431
56899 64041
15137 38936
9921 34761
11644 28437
22451 55339
33303 61478
4834 11432
9944 49814
20282 35353...

output:

773636281

result:

ok "773636281"

Test #11:

score: 0
Accepted
time: 15ms
memory: 10040kb

input:

100000 100000
31015 42574
31826 52090
83087 85955
23220 37841
56013 70940
34751 70547
62376 76457
31649 91712
18505 47662
85040 98454
13121 30466
1256 3470
3980 85011
57880 71144
32147 38601
31379 50646
72392 87906
48476 76451
40774 58685
64093 68937
32329 80656
8177 25150
15432 60258
22018 69969
48...

output:

941648147

result:

ok "941648147"

Test #12:

score: 0
Accepted
time: 15ms
memory: 7884kb

input:

100000 100000
21014 66363
7456 75478
5229 68612
15284 54049
29655 88817
65818 66444
33870 76176
29544 90569
62304 90461
83356 99748
24455 94172
57249 66657
44630 50799
65039 67617
4906 38962
7679 51541
59316 74310
28441 76551
19291 98970
7367 65494
62031 78933
21758 59135
46144 98556
21049 55166
573...

output:

526465770

result:

ok "526465770"

Test #13:

score: 0
Accepted
time: 15ms
memory: 10308kb

input:

100000 100000
28862 53149
9949 69392
28285 43896
10353 80816
34142 87078
63124 67907
41674 71792
48558 72019
7933 14947
74512 93023
31561 85833
15508 33590
49247 51145
14356 99398
22644 66661
7140 85438
66105 67726
5276 71801
42804 71017
79393 96156
1822 11277
23399 70023
93290 99802
28361 43488
245...

output:

491623414

result:

ok "491623414"

Test #14:

score: 0
Accepted
time: 15ms
memory: 10304kb

input:

100000 100000
14799 99589
42148 79991
40478 73277
20849 87949
45939 72422
41866 46646
4066 26608
33598 57285
17116 42252
32284 66953
77926 88983
5776 86665
28968 39697
18131 25212
27377 42980
29537 93995
18671 55017
7758 76277
17700 62026
24191 54409
41589 55516
72711 73804
31813 37554
24757 72146
1...

output:

394684748

result:

ok "394684748"

Test #15:

score: 0
Accepted
time: 12ms
memory: 8256kb

input:

100000 100000
55015 73375
3596 29679
19231 76062
82350 90597
19070 96441
66671 80639
47379 62902
38990 66802
37706 64205
4989 34650
20110 59898
6647 99705
41498 42886
7404 33540
36363 42005
37631 75016
68188 82917
21072 43390
36562 68641
21837 95043
65523 85407
21441 41841
4913 98767
29560 94781
196...

output:

962695745

result:

ok "962695745"

Test #16:

score: 0
Accepted
time: 15ms
memory: 8264kb

input:

100000 100000
48836 52965
22215 37796
26537 29092
90657 98341
2131 7342
17641 64091
46683 79182
1165 35743
10331 23332
2889 41333
56769 75505
63440 94599
40276 80762
14501 68386
3239 8420
3295 69001
42668 83714
43199 90350
39921 65865
16402 19637
48565 85097
44750 83786
59138 84536
61461 96164
65218...

output:

269046725

result:

ok "269046725"

Test #17:

score: 0
Accepted
time: 11ms
memory: 9920kb

input:

100000 100000
1089 99857
8077 43835
37678 60147
2950 63548
84341 95606
4257 36034
15407 30716
27902 71808
18112 93015
608 75716
53770 66511
54636 89625
41858 47390
45083 76588
1172 53992
19357 42200
37722 52861
61126 92664
48696 88494
48676 89136
33660 90563
9778 25918
53528 97743
7510 96964
5597 33...

output:

86816533

result:

ok "86816533"

Test #18:

score: 0
Accepted
time: 14ms
memory: 10200kb

input:

100000 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 10000...

output:

538261387

result:

ok "538261387"

Test #19:

score: 0
Accepted
time: 13ms
memory: 10236kb

input:

1744 831
2 -1
430 692
-1 661
-1 145
282 330
-1 -1
27 -1
-1 579
232 538
-1 -1
318 508
315 -1
-1 -1
715 -1
524 -1
-1 555
-1 172
445 -1
-1 -1
-1 -1
79 -1
-1 -1
-1 -1
-1 231
-1 695
-1 654
63 -1
206 -1
-1 44
352 787
7 351
591 686
781 -1
313 -1
-1 154
576 -1
185 239
555 611
-1 721
-1 550
102 204
19 -1
436...

output:

603361949

result:

ok "603361949"

Test #20:

score: 0
Accepted
time: 4ms
memory: 10000kb

input:

645 233
-1 -1
33 227
-1 137
57 -1
51 -1
21 -1
44 108
41 123
-1 140
72 -1
-1 88
6 -1
21 56
-1 182
-1 160
-1 168
102 127
134 -1
-1 -1
-1 -1
181 -1
17 165
54 190
-1 97
187 -1
-1 147
78 -1
10 52
-1 169
75 -1
63 157
-1 100
21 155
-1 -1
-1 208
155 -1
38 196
-1 161
-1 231
-1 109
-1 206
-1 -1
-1 104
-1 -1
9...

output:

167490773

result:

ok "167490773"

Test #21:

score: 0
Accepted
time: 5ms
memory: 8172kb

input:

282 279
-1 131
-1 -1
113 115
35 256
9 268
-1 105
261 -1
-1 -1
89 -1
18 -1
65 182
-1 -1
-1 -1
167 191
-1 194
-1 -1
-1 -1
-1 -1
-1 105
32 51
-1 211
111 133
-1 -1
-1 -1
29 276
-1 35
29 276
-1 -1
54 -1
79 -1
-1 -1
142 164
82 -1
51 -1
-1 -1
262 -1
6 119
-1 -1
209 -1
-1 184
-1 -1
-1 -1
-1 -1
67 124
-1 124...

output:

269738573

result:

ok "269738573"

Test #22:

score: 0
Accepted
time: 23ms
memory: 8568kb

input:

2000 2000
904 -1
119 -1
-1 -1
175 722
-1 1469
692 1062
49 425
-1 783
1825 -1
-1 1133
733 1325
1946 -1
127 1559
694 1287
-1 -1
583 -1
-1 -1
1423 1626
12 -1
-1 -1
613 1547
-1 1057
368 1509
574 1515
1405 -1
971 -1
560 1370
430 1802
-1 1934
-1 795
-1 117
-1 -1
1367 1878
-1 1468
1118 1723
-1 -1
-1 647
-1...

output:

417815992

result:

ok "417815992"

Test #23:

score: 0
Accepted
time: 26ms
memory: 8288kb

input:

2000 2000
-1 -1
32 -1
327 -1
1220 1869
-1 1444
200 1066
1522 -1
1049 -1
1541 -1
1630 -1
-1 267
-1 482
-1 -1
-1 -1
1005 1847
131 303
24 1933
568 1176
772 -1
-1 -1
-1 -1
1920 -1
1676 -1
1697 1847
-1 -1
-1 -1
-1 973
1357 -1
886 1735
974 -1
-1 1943
-1 456
912 1531
916 -1
820 964
-1 -1
-1 96
404 1575
-1 ...

output:

946305065

result:

ok "946305065"

Test #24:

score: 0
Accepted
time: 23ms
memory: 10316kb

input:

2000 2000
842 1676
820 1103
155 -1
691 -1
763 1757
540 1818
-1 -1
-1 -1
-1 -1
813 -1
942 -1
-1 -1
939 -1
1600 -1
67 1656
-1 1365
691 -1
1245 -1
330 866
399 1774
1761 -1
831 1310
-1 1639
48 1572
-1 -1
-1 395
-1 47
-1 520
680 993
-1 -1
885 1449
117 757
924 -1
-1 -1
-1 1053
1752 1893
-1 907
-1 882
940 ...

output:

504771084

result:

ok "504771084"

Test #25:

score: 0
Accepted
time: 23ms
memory: 8424kb

input:

2000 2000
1846 -1
-1 354
363 1151
678 -1
-1 -1
606 1154
154 1931
633 857
1557 -1
124 1798
934 -1
-1 -1
-1 -1
1334 -1
-1 -1
-1 633
571 -1
834 944
1107 1545
390 1566
296 561
160 1589
745 -1
611 1142
287 779
-1 1546
1766 1807
-1 -1
-1 -1
541 -1
-1 -1
-1 562
1705 -1
1496 -1
-1 291
143 1934
-1 -1
342 -1
...

output:

164655804

result:

ok "164655804"

Test #26:

score: 0
Accepted
time: 19ms
memory: 8416kb

input:

2000 2000
1304 -1
1697 -1
-1 116
-1 -1
432 467
-1 225
-1 1135
-1 -1
56 -1
1949 -1
174 -1
-1 1742
-1 -1
1730 1947
-1 1008
-1 1404
1092 1267
-1 -1
-1 -1
-1 883
1602 -1
-1 -1
1124 1810
502 -1
-1 1557
396 -1
400 729
-1 -1
-1 -1
-1 1705
286 1719
277 -1
-1 -1
421 -1
-1 -1
574 1285
1265 1668
-1 794
-1 -1
5...

output:

433544803

result:

ok "433544803"

Test #27:

score: 0
Accepted
time: 2ms
memory: 8140kb

input:

2000 2000
651 1106
707 924
638 968
1080 1581
97 1257
261 1531
1160 1733
26 1571
743 1741
86 1283
1245 1536
393 511
793 1051
881 1755
1437 1613
15 795
337 1343
1723 1823
1059 1875
476 1927
524 1109
1870 1983
916 1750
363 1115
18 779
306 371
47 115
216 951
128 407
229 1986
1253 1683
397 1909
1785 1891...

output:

275736124

result:

ok "275736124"

Test #28:

score: 0
Accepted
time: 2ms
memory: 8148kb

input:

2000 2000
488 525
1086 1118
1812 1888
86 1836
459 491
782 1449
238 436
125 598
403 941
341 1296
358 1985
57 568
423 652
874 1862
324 1597
985 1746
22 753
251 642
172 378
487 1486
810 1564
874 1789
380 1097
215 1625
744 1532
1589 1952
9 1764
4 330
559 562
940 1836
364 386
91 1562
1191 1806
484 1823
5...

output:

647106319

result:

ok "647106319"

Test #29:

score: 0
Accepted
time: 24ms
memory: 8392kb

input:

2000 2000
-1 -1
-1 -1
-1 107
-1 -1
-1 -1
618 -1
-1 1936
42 -1
-1 456
-1 443
31 -1
-1 -1
750 -1
-1 -1
-1 141
-1 47
-1 515
-1 606
-1 -1
-1 -1
-1 40
581 -1
-1 482
-1 -1
790 -1
-1 -1
-1 557
-1 -1
-1 1308
1238 -1
-1 53
-1 -1
-1 -1
1956 -1
217 -1
-1 1972
-1 -1
1070 -1
-1 -1
-1 82
706 -1
-1 16
-1 -1
12 -1
...

output:

178213118

result:

ok "178213118"

Test #30:

score: 0
Accepted
time: 27ms
memory: 8676kb

input:

2000 2000
-1 -1
844 -1
-1 1719
-1 1682
1041 -1
1549 -1
-1 -1
-1 459
1404 -1
1862 -1
-1 1275
344 -1
1003 -1
-1 -1
-1 -1
1738 -1
804 -1
1481 -1
-1 1096
-1 -1
-1 -1
191 -1
-1 432
-1 -1
-1 -1
1538 -1
1525 -1
-1 -1
-1 946
-1 -1
-1 1292
1973 -1
1343 -1
-1 769
1129 -1
1722 -1
-1 -1
-1 -1
1295 -1
-1 741
-1 ...

output:

326294367

result:

ok "326294367"

Test #31:

score: 0
Accepted
time: 30ms
memory: 8444kb

input:

2000 2000
1019 -1
707 -1
551 -1
1755 -1
1231 -1
513 -1
1042 -1
-1 460
1557 -1
-1 899
-1 1083
-1 1262
-1 444
1811 -1
1831 -1
671 -1
105 -1
-1 1299
-1 1559
1491 -1
980 -1
1054 -1
-1 300
-1 934
1660 -1
-1 186
355 -1
1463 -1
-1 653
-1 678
-1 1569
1342 -1
-1 884
-1 126
1777 -1
-1 971
-1 13
-1 569
1072 -1...

output:

751548938

result:

ok "751548938"

Test #32:

score: 0
Accepted
time: 28ms
memory: 8384kb

input:

2000 2000
1539 -1
1305 -1
1660 -1
1742 -1
-1 1535
184 -1
211 -1
1908 -1
531 -1
1548 -1
1676 -1
1346 -1
-1 893
156 -1
1790 -1
170 -1
283 -1
1573 -1
-1 35
-1 838
1741 -1
1289 -1
-1 1650
-1 1410
1163 -1
1189 -1
1592 -1
-1 180
1829 -1
-1 574
1000 -1
-1 342
1928 -1
1498 -1
1572 -1
1138 -1
-1 1970
-1 1856...

output:

186475814

result:

ok "186475814"

Test #33:

score: 0
Accepted
time: 15ms
memory: 8292kb

input:

2000 2000
-1 1009
-1 1594
-1 1522
-1 311
-1 1679
-1 679
-1 103
-1 78
-1 797
-1 1530
-1 829
-1 1813
-1 383
-1 930
-1 712
-1 988
-1 1023
-1 1257
-1 1162
-1 17
-1 966
-1 1815
-1 680
-1 1315
-1 1348
-1 171
-1 200
-1 779
-1 1320
-1 1506
-1 937
-1 779
-1 161
-1 1640
-1 1999
-1 761
-1 871
-1 1934
-1 1228
-...

output:

63681103

result:

ok "63681103"

Test #34:

score: 0
Accepted
time: 21ms
memory: 8400kb

input:

2000 2000
-1 1505
-1 857
-1 54
-1 194
-1 368
-1 1154
-1 629
-1 175
-1 1287
-1 770
-1 1243
-1 1451
-1 507
-1 1328
-1 102
-1 75
-1 1357
-1 415
-1 499
-1 1736
-1 1214
-1 1702
-1 1521
-1 717
-1 863
-1 1534
-1 1349
-1 606
-1 1466
-1 1314
-1 1526
-1 1024
-1 579
-1 1788
-1 155
-1 615
-1 517
-1 569
-1 744
-...

output:

630266191

result:

ok "630266191"

Test #35:

score: 0
Accepted
time: 22ms
memory: 10388kb

input:

2000 2000
1047 -1
384 -1
1758 -1
1389 -1
740 -1
816 -1
203 -1
489 -1
569 -1
1276 -1
1531 -1
154 -1
1999 -1
379 -1
329 -1
203 -1
1452 -1
161 -1
1384 -1
559 -1
79 -1
208 -1
92 -1
1125 -1
1616 -1
384 -1
1082 -1
204 -1
1811 -1
1105 -1
58 -1
613 -1
1619 -1
1243 -1
1392 -1
1631 -1
653 -1
1373 -1
632 -1
15...

output:

114835083

result:

ok "114835083"

Test #36:

score: 0
Accepted
time: 23ms
memory: 8380kb

input:

2000 2000
1513 -1
3 -1
640 -1
1744 -1
1998 -1
960 -1
1676 -1
608 -1
56 -1
1794 -1
334 -1
999 -1
1739 -1
106 -1
711 -1
1579 -1
641 -1
1257 -1
544 -1
797 -1
479 -1
374 -1
1358 -1
1643 -1
1278 -1
714 -1
302 -1
1520 -1
1916 -1
67 -1
1581 -1
898 -1
778 -1
767 -1
1651 -1
76 -1
1235 -1
742 -1
1523 -1
370 -...

output:

429309272

result:

ok "429309272"

Test #37:

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

input:

2000 2000
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1...

output:

708459481

result:

ok "708459481"

Test #38:

score: 0
Accepted
time: 2824ms
memory: 38676kb

input:

39371 73505
-1 67150
-1 57770
42317 -1
-1 -1
65127 -1
48039 57936
16817 -1
46051 52105
-1 44100
33469 43807
-1 66673
-1 -1
83 68755
-1 65324
11453 31180
-1 2443
35823 -1
-1 -1
-1 -1
8433 24104
37008 55794
21490 -1
-1 23813
59037 -1
-1 43665
-1 -1
25001 42758
18631 -1
29828 -1
-1 -1
-1 -1
43963 -1
37...

output:

417807573

result:

ok "417807573"

Test #39:

score: 0
Accepted
time: 1609ms
memory: 20412kb

input:

516 68842
17469 -1
23357 -1
8760 46430
7432 -1
-1 48636
19607 -1
41983 -1
-1 17512
47499 -1
11213 38541
21538 -1
32032 68432
-1 35755
-1 54811
37739 63152
-1 21436
585 5674
-1 -1
-1 -1
-1 -1
51261 51348
-1 28993
3606 22514
-1 64998
20340 48659
35722 65937
-1 -1
-1 64396
-1 -1
-1 -1
1482 50269
28310 ...

output:

944392637

result:

ok "944392637"

Test #40:

score: 0
Accepted
time: 1212ms
memory: 22260kb

input:

11928 51104
7727 -1
12632 13001
-1 -1
-1 -1
6272 50896
23549 -1
-1 -1
-1 43881
27531 48840
-1 45956
-1 41853
27809 33690
-1 16089
27024 39291
-1 -1
5238 -1
36436 -1
-1 22559
40105 -1
20976 37615
-1 -1
-1 6246
17537 47844
8564 9869
-1 2246
24489 -1
-1 -1
10003 17239
-1 -1
-1 -1
3415 25065
3283 25074
...

output:

760980906

result:

ok "760980906"

Test #41:

score: 0
Accepted
time: 1606ms
memory: 28584kb

input:

87869 56606
24516 39428
26004 -1
-1 48577
-1 17564
-1 -1
33985 -1
55338 -1
-1 51915
20824 -1
-1 17939
7402 45187
31118 -1
8297 20482
32329 36079
10683 36084
-1 5542
30020 -1
12935 13532
-1 25603
15811 -1
-1 6534
38966 -1
-1 -1
13907 -1
23761 45077
-1 14130
35441 51955
-1 -1
-1 -1
21280 -1
7405 32321...

output:

876373628

result:

ok "876373628"

Test #42:

score: 0
Accepted
time: 644ms
memory: 14204kb

input:

40641 26318
7109 13581
25097 -1
23267 -1
1102 13576
12052 -1
12801 18315
-1 9329
-1 -1
4332 -1
10112 20954
666 -1
14616 -1
-1 25123
-1 14856
-1 -1
-1 4259
4865 -1
-1 -1
253 -1
9566 -1
7063 -1
-1 -1
5486 -1
1559 -1
9327 22486
9521 13718
862 13292
4843 7815
14881 16553
25182 -1
-1 -1
-1 -1
10534 -1
11...

output:

603095629

result:

ok "603095629"

Test #43:

score: 0
Accepted
time: 2885ms
memory: 30872kb

input:

100000 100000
80910 85031
-1 46621
61333 99990
89041 -1
-1 46204
48529 79326
-1 -1
2747 55365
-1 -1
-1 5862
3891 54076
-1 90774
50016 -1
-1 13462
41283 -1
7290 8385
961 78037
61802 -1
-1 20292
72341 -1
-1 -1
98901 -1
32950 -1
61160 -1
-1 -1
84609 -1
60542 -1
54713 -1
35383 88820
58869 -1
14739 -1
49...

output:

875564287

result:

ok "875564287"

Test #44:

score: 0
Accepted
time: 3190ms
memory: 44240kb

input:

100000 100000
-1 -1
-1 -1
58262 66732
58914 61320
67630 69377
11169 40789
52235 76000
-1 38693
-1 -1
-1 51837
-1 -1
-1 -1
-1 20873
-1 86015
61867 -1
-1 79893
-1 43481
32490 -1
-1 -1
-1 -1
-1 34584
15429 52880
-1 96933
5109 -1
373 -1
-1 -1
73425 -1
31557 -1
-1 24025
75347 -1
-1 -1
-1 -1
14028 -1
3929...

output:

711299685

result:

ok "711299685"

Test #45:

score: 0
Accepted
time: 2942ms
memory: 32880kb

input:

100000 100000
75183 78136
35617 -1
-1 18706
57048 -1
-1 -1
-1 27906
31253 -1
86063 -1
-1 53125
20587 -1
-1 -1
88024 -1
-1 92960
16945 83958
-1 47260
48746 -1
-1 -1
30210 -1
54460 75100
8786 -1
-1 -1
-1 -1
68101 -1
12156 93667
-1 -1
44107 73979
54642 70186
-1 -1
-1 95729
-1 20306
42929 -1
28087 -1
-1...

output:

51364591

result:

ok "51364591"

Test #46:

score: 0
Accepted
time: 3188ms
memory: 41756kb

input:

100000 100000
-1 29231
27579 -1
-1 -1
-1 56749
-1 -1
-1 -1
-1 -1
42070 -1
-1 15181
-1 5211
72963 -1
-1 -1
72323 -1
-1 50903
-1 97727
-1 -1
-1 -1
-1 17913
-1 83302
-1 27183
-1 -1
-1 88000
19902 -1
78405 -1
61740 -1
36441 37528
24828 95216
-1 -1
-1 99257
82763 -1
85843 -1
7610 26057
-1 -1
54130 -1
532...

output:

749999568

result:

ok "749999568"

Test #47:

score: 0
Accepted
time: 3195ms
memory: 42064kb

input:

100000 100000
-1 -1
-1 -1
71455 87994
-1 -1
-1 70805
-1 6368
39972 68521
-1 46049
21208 91408
68 39582
-1 36681
63072 -1
76257 -1
-1 -1
-1 -1
-1 -1
-1 9393
-1 63750
-1 99364
-1 1479
-1 13423
-1 3420
10066 -1
-1 -1
-1 -1
-1 -1
-1 -1
58639 -1
-1 18319
-1 80225
25804 -1
-1 -1
68756 -1
-1 -1
16180 -1
40...

output:

930185694

result:

ok "930185694"

Test #48:

score: 0
Accepted
time: 12ms
memory: 10244kb

input:

100000 100000
56199 91291
40437 82521
19552 81440
12739 83409
53402 77939
42064 63128
4342 65251
38574 74433
4013 13097
3550 70914
52773 56209
32166 76985
95408 97749
57359 84113
66381 70787
39433 68501
12977 13199
8762 22385
1055 18446
36373 92518
925 39093
23947 59419
44418 92857
22872 80638
47058...

output:

49931541

result:

ok "49931541"

Test #49:

score: 0
Accepted
time: 15ms
memory: 8204kb

input:

100000 100000
50106 86783
60571 70716
47204 54138
55639 62784
36078 84941
6279 21915
4868 83374
28166 58000
1682 67802
9121 23778
59200 84282
28024 78232
38001 46997
24442 72617
18579 29514
46860 80122
26555 91391
80518 97471
7833 38804
72763 96909
7043 60172
35749 96351
68580 75643
18826 83843
1136...

output:

658828321

result:

ok "658828321"

Test #50:

score: 0
Accepted
time: 3125ms
memory: 33096kb

input:

100000 100000
52142 -1
-1 -1
-1 -1
-1 30266
-1 -1
35323 -1
79660 -1
13258 -1
34358 -1
36621 -1
26780 -1
-1 -1
50361 -1
-1 -1
65478 -1
-1 -1
-1 -1
11658 -1
-1 -1
-1 -1
-1 76128
-1 19735
4957 -1
-1 -1
-1 -1
-1 313
34883 -1
79739 -1
40675 -1
-1 -1
-1 86093
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -...

output:

208320674

result:

ok "208320674"

Test #51:

score: 0
Accepted
time: 3119ms
memory: 35128kb

input:

100000 100000
53906 -1
-1 -1
-1 90057
-1 -1
-1 67689
-1 -1
-1 80045
-1 -1
-1 -1
1418 -1
65159 -1
-1 32307
-1 -1
-1 23951
-1 -1
-1 -1
-1 -1
-1 64225
-1 19711
80412 -1
-1 -1
-1 -1
-1 -1
-1 60840
-1 71629
-1 93515
35923 -1
-1 -1
51987 -1
-1 -1
65197 -1
12027 -1
-1 -1
-1 -1
-1 75962
83550 -1
-1 -1
-1 12...

output:

383054357

result:

ok "383054357"

Test #52:

score: 0
Accepted
time: 3634ms
memory: 48880kb

input:

100000 100000
63575 -1
-1 7400
79813 -1
98399 -1
13873 -1
14572 -1
19061 -1
70999 -1
77559 -1
65265 -1
4346 -1
-1 74813
-1 7985
-1 35710
35861 -1
79524 -1
30778 -1
67501 -1
-1 22305
-1 44157
-1 62332
-1 5628
-1 18973
27455 -1
-1 48414
66056 -1
24981 -1
68294 -1
21015 -1
-1 46011
-1 5575
4417 -1
6624...

output:

503409689

result:

ok "503409689"

Test #53:

score: 0
Accepted
time: 3620ms
memory: 46772kb

input:

100000 100000
-1 33901
-1 66021
62619 -1
84968 -1
5973 -1
221 -1
74746 -1
-1 8218
66325 -1
81801 -1
-1 19236
93697 -1
10390 -1
-1 37512
-1 28713
57237 -1
84838 -1
18557 -1
57091 -1
74599 -1
46617 -1
-1 64742
-1 3585
23920 -1
96818 -1
91194 -1
-1 34039
-1 76341
63222 -1
-1 4070
52549 -1
52320 -1
2529...

output:

542286132

result:

ok "542286132"

Test #54:

score: 0
Accepted
time: 3620ms
memory: 49368kb

input:

100000 100000
-1 74707
-1 79497
80831 -1
-1 13660
-1 2355
-1 3193
93434 -1
46852 -1
-1 71434
56165 -1
72138 -1
-1 60877
53744 -1
-1 29414
-1 79316
-1 34371
-1 83159
70157 -1
-1 10459
44011 -1
-1 89285
2721 -1
-1 81322
64654 -1
-1 55226
-1 88643
55364 -1
-1 29667
-1 88510
-1 68812
-1 95576
-1 36116
-...

output:

915309845

result:

ok "915309845"

Test #55:

score: 0
Accepted
time: 3335ms
memory: 35808kb

input:

100000 100000
-1 30060
20079 -1
-1 23063
21687 -1
-1 69283
-1 60835
42463 -1
69629 -1
-1 74776
36689 -1
89922 -1
-1 8379
214 -1
3715 -1
77111 -1
28023 -1
-1 12596
98730 -1
-1 1776
52953 -1
50069 -1
-1 51070
-1 83557
-1 4535
-1 50618
16148 -1
70826 -1
50838 -1
-1 59590
-1 88742
24648 -1
55639 -1
2375...

output:

923853144

result:

ok "923853144"

Test #56:

score: 0
Accepted
time: 2680ms
memory: 43748kb

input:

100000 100000
-1 99984
-1 99213
145 -1
-1 99053
318 -1
-1 99009
-1 99565
-1 99220
-1 99334
-1 99870
-1 99547
342 -1
621 -1
568 -1
526 -1
26 -1
916 -1
565 -1
526 -1
-1 99107
-1 99362
462 -1
-1 99471
-1 99151
-1 99022
487 -1
-1 99020
458 -1
907 -1
676 -1
927 -1
-1 99216
253 -1
589 -1
-1 99880
-1 99874...

output:

128192368

result:

ok "128192368"

Test #57:

score: 0
Accepted
time: 2380ms
memory: 47980kb

input:

100000 100000
-1 32146
-1 6895
-1 43504
-1 94964
-1 5082
-1 69541
-1 58879
-1 9425
-1 9722
-1 19108
-1 77933
-1 30806
-1 10667
-1 90570
-1 77965
-1 65368
-1 82544
-1 78636
-1 91380
-1 50002
-1 66292
-1 23842
-1 38060
-1 90192
-1 4081
-1 94755
-1 57313
-1 55556
-1 20864
-1 51424
-1 17220
-1 51489
-1 ...

output:

461531218

result:

ok "461531218"

Test #58:

score: 0
Accepted
time: 2068ms
memory: 35288kb

input:

100000 100000
-1 24112
-1 29415
-1 59008
-1 59525
-1 72057
-1 32796
-1 53056
-1 39914
-1 60183
-1 29066
-1 30319
-1 22292
-1 75168
-1 30075
-1 730
-1 57883
-1 71736
-1 22823
-1 33880
-1 27859
-1 42291
-1 80947
-1 25413
-1 38888
-1 50895
-1 51239
-1 40782
-1 48036
-1 20833
-1 6017
-1 11031
-1 13706
-...

output:

685855997

result:

ok "685855997"

Test #59:

score: 0
Accepted
time: 2556ms
memory: 43284kb

input:

100000 100000
-1 99946
-1 99374
-1 99695
-1 99908
-1 99425
-1 99298
-1 99444
-1 99478
-1 99074
-1 99338
-1 99540
-1 99466
-1 99773
-1 99256
-1 99117
-1 99903
-1 99889
-1 99727
-1 99067
-1 99458
-1 99391
-1 99324
-1 99169
-1 99185
-1 99213
-1 99811
-1 99974
-1 99273
-1 99299
-1 99296
-1 99418
-1 9934...

output:

741344412

result:

ok "741344412"

Test #60:

score: 0
Accepted
time: 2375ms
memory: 45620kb

input:

100000 100000
88122 -1
22419 -1
72915 -1
16790 -1
82911 -1
68163 -1
97964 -1
99368 -1
62160 -1
81235 -1
27503 -1
57865 -1
5780 -1
32671 -1
91062 -1
96378 -1
36135 -1
88493 -1
26161 -1
50422 -1
20914 -1
84193 -1
33641 -1
73209 -1
65369 -1
87331 -1
31318 -1
62567 -1
68644 -1
31605 -1
82937 -1
22518 -1...

output:

274568803

result:

ok "274568803"

Test #61:

score: 0
Accepted
time: 2098ms
memory: 35052kb

input:

100000 100000
65732 -1
11100 -1
71587 -1
75320 -1
9952 -1
47148 -1
20555 -1
64361 -1
43541 -1
4169 -1
95423 -1
83066 -1
71053 -1
68728 -1
14445 -1
34486 -1
67223 -1
94492 -1
15553 -1
22406 -1
35564 -1
40226 -1
72709 -1
93475 -1
38314 -1
18136 -1
47848 -1
6843 -1
14004 -1
68815 -1
81926 -1
88686 -1
4...

output:

110203772

result:

ok "110203772"

Test #62:

score: 0
Accepted
time: 2590ms
memory: 43780kb

input:

100000 100000
138 -1
533 -1
344 -1
58 -1
284 -1
760 -1
235 -1
908 -1
285 -1
402 -1
516 -1
780 -1
412 -1
128 -1
869 -1
95 -1
375 -1
577 -1
444 -1
474 -1
714 -1
538 -1
196 -1
58 -1
628 -1
764 -1
389 -1
209 -1
673 -1
352 -1
921 -1
725 -1
781 -1
108 -1
560 -1
158 -1
7 -1
310 -1
433 -1
214 -1
824 -1
103 ...

output:

399221708

result:

ok "399221708"

Test #63:

score: 0
Accepted
time: 25ms
memory: 8256kb

input:

100000 100000
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -...

output:

682834676

result:

ok "682834676"

Test #64:

score: 0
Accepted
time: 77ms
memory: 13488kb

input:

100000 100000
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-...

output:

538261387

result:

ok "538261387"

Test #65:

score: 0
Accepted
time: 481ms
memory: 33568kb

input:

100000 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100...

output:

168783817

result:

ok "168783817"

Test #66:

score: 0
Accepted
time: 2722ms
memory: 36292kb

input:

100000 100000
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 9999...

output:

911213386

result:

ok "911213386"

Test #67:

score: 0
Accepted
time: 1522ms
memory: 28528kb

input:

100000 100000
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 6553...

output:

958020328

result:

ok "958020328"

Test #68:

score: 0
Accepted
time: 1544ms
memory: 33836kb

input:

100000 100000
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 6553...

output:

376123473

result:

ok "376123473"

Test #69:

score: 0
Accepted
time: 1605ms
memory: 29688kb

input:

100000 100000
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 6553...

output:

558998334

result:

ok "558998334"

Test #70:

score: 0
Accepted
time: 3705ms
memory: 37440kb

input:

100000 100000
53486 -1
39997 88519
84325 -1
37606 -1
66183 79560
-1 10303
-1 53157
8761 -1
12793 67803
33675 -1
12761 47448
-1 93895
49265 67228
7378 -1
-1 57452
67968 76339
47096 -1
49571 62188
31863 91277
35138 -1
73437 94561
46238 60564
-1 62721
15721 38820
39037 43534
85549 -1
76266 -1
70417 892...

output:

234032781

result:

ok "234032781"

Test #71:

score: 0
Accepted
time: 503ms
memory: 35408kb

input:

100000 100000
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1...

output:

168783817

result:

ok "168783817"

Test #72:

score: 0
Accepted
time: 2859ms
memory: 35032kb

input:

100000 100000
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2...

output:

911213386

result:

ok "911213386"

Test #73:

score: 0
Accepted
time: 103ms
memory: 13264kb

input:

100000 100000
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000...

output:

538261387

result:

ok "538261387"

Test #74:

score: 0
Accepted
time: 1619ms
memory: 32836kb

input:

100000 100000
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -...

output:

958020328

result:

ok "958020328"

Test #75:

score: 0
Accepted
time: 1725ms
memory: 31948kb

input:

100000 100000
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -...

output:

376123473

result:

ok "376123473"

Test #76:

score: 0
Accepted
time: 1751ms
memory: 29964kb

input:

100000 100000
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -...

output:

558998334

result:

ok "558998334"

Test #77:

score: 0
Accepted
time: 4807ms
memory: 43480kb

input:

100000 100000
-1 67653
29813 -1
8485 85934
12402 23734
-1 84172
7904 30261
71842 -1
-1 58480
7175 84465
65363 95224
20337 81386
-1 91396
741 51360
-1 52196
3940 86117
1982 9289
18819 65495
4767 -1
24735 99523
34668 60575
6755 83029
80722 87776
55520 79079
32800 39607
45123 50000
33895 38990
31019 -1...

output:

367637584

result:

ok "367637584"

Extra Test:

score: 0
Extra Test Passed