QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107884#6324. Expanded HullmaspyAC ✓3656ms9472kbC++2338.4kb2023-05-23 03:30:522023-05-23 03:30:56

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-23 03:30:56]
  • 评测
  • 测评结果:AC
  • 用时:3656ms
  • 内存:9472kb
  • [2023-05-23 03:30:52]
  • 提交

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 {
  static_assert(mod < (1 << 30));
  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/alg/monoid/mul.hpp"

template <class T>
struct Monoid_Mul {
  using value_type = T;
  using X = T;
  static constexpr X op(const X &x, const X &y) noexcept { return x * y; }
  static constexpr X inverse(const X &x) noexcept { return X(1) / x; }
  static constexpr X unit() { return X(1); }
  static constexpr bool commute = true;
};
#line 1 "library/ds/sliding_window_aggregation.hpp"
template <class Monoid>
struct Sliding_Window_Aggregation {
  using X = typename Monoid::value_type;
  using value_type = X;
  int sz = 0;
  vc<X> dat;
  vc<X> cum_l;
  X cum_r;

  Sliding_Window_Aggregation()
      : cum_l({Monoid::unit()}), cum_r(Monoid::unit()) {}

  int size() { return sz; }

  void push(X x) {
    ++sz;
    cum_r = Monoid::op(cum_r, x);
    dat.eb(x);
  }

  void pop() {
    --sz;
    cum_l.pop_back();
    if (len(cum_l) == 0) {
      cum_l = {Monoid::unit()};
      cum_r = Monoid::unit();
      while (len(dat) > 1) {
        cum_l.eb(Monoid::op(dat.back(), cum_l.back()));
        dat.pop_back();
      }
      dat.pop_back();
    }
  }

  X lprod() { return cum_l.back(); }
  X rprod() { return cum_r; }

  X prod() { return Monoid::op(cum_l.back(), cum_r); }

  void debug() {
    print("swag");
    print("dat", dat);
    print("cum_l", cum_l);
    print("cum_r", cum_r);
  }
};

// 定数倍は目に見えて遅くなるので、queue でよいときは使わない
template <class Monoid>
struct SWAG_deque {
  using X = typename Monoid::value_type;
  using value_type = X;
  int sz;
  vc<X> dat_l, dat_r;
  vc<X> cum_l, cum_r;

  SWAG_deque() : sz(0), cum_l({Monoid::unit()}), cum_r({Monoid::unit()}) {}

  int size() { return sz; }

  void push_back(X x) {
    ++sz;
    dat_r.eb(x);
    cum_r.eb(Monoid::op(cum_r.back(), x));
  }

  void push_front(X x) {
    ++sz;
    dat_l.eb(x);
    cum_l.eb(Monoid::op(x, cum_l.back()));
  }

  void push(X x) { push_back(x); }

  void clear() {
    sz = 0;
    dat_l.clear(), dat_r.clear();
    cum_l = {Monoid::unit()}, cum_r = {Monoid::unit()};
  }

  void pop_front() {
    if (sz == 1) return clear();
    if (dat_l.empty()) rebuild();
    --sz;
    dat_l.pop_back();
    cum_l.pop_back();
  }

  void pop_back() {
    if (sz == 1) return clear();
    if (dat_r.empty()) rebuild();
    --sz;
    dat_r.pop_back();
    cum_r.pop_back();
  }

  void pop() { pop_front(); }

  X lprod() { return cum_l.back(); }
  X rprod() { return cum_r.back(); }
  X prod() { return Monoid::op(cum_l.back(), cum_r.back()); }
  X prod_all() { return prod(); }

  void debug() {
    print("swag");
    print("dat_l", dat_l);
    print("dat_r", dat_r);
    print("cum_l", cum_l);
    print("cum_r", cum_r);
  }

private:
  void rebuild() {
    vc<X> X;
    FOR_R(i, len(dat_l)) X.eb(dat_l[i]);
    X.insert(X.end(), all(dat_r));
    clear();
    int m = len(X) / 2;
    FOR_R(i, m) push_front(X[i]);
    FOR(i, m, len(X)) push_back(X[i]);
    assert(sz == len(X));
  }
};
#line 2 "library/mod/mod_inv.hpp"
// long でも大丈夫
ll mod_inv(ll val, ll 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 1 "library/poly/convolution_naive.hpp"
template <class T>
vector<T> convolution_naive(const vector<T>& a, const vector<T>& b) {
  int n = int(a.size()), m = int(b.size());
  vector<T> ans(n + m - 1);
  if (n < m) {
    FOR(j, m) FOR(i, n) ans[i + j] += a[i] * b[j];
  } else {
    FOR(i, n) FOR(j, m) ans[i + j] += a[i] * b[j];
  }
  return ans;
}
#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;

  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 7 "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 const long long nttprimes[] = {754974721, 167772161, 469762049};
  using mint0 = modint<754974721>;
  using mint1 = modint<167772161>;
  using mint2 = modint<469762049>;
  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);
  static const long long m01 = 1LL * nttprimes[0] * nttprimes[1];
  static const long long m0_inv_m1 = mint1(nttprimes[0]).inverse().val;
  static const long long m01_inv_m2 = mint2(m01).inverse().val;
  const int mod = mint::get_mod();
  auto garner = [&](mint0 x0, mint1 x1, mint2 x2) -> mint {
    int r0 = x0.val, r1 = x1.val, r2 = x2.val;
    int v1 = (m0_inv_m1 * (r1 + nttprimes[1] - r0)) % nttprimes[1];
    auto v2 = (mint2(r2) - r0 - mint2(nttprimes[0]) * v1) * mint2(m01_inv_m2);
    return mint(r0 + 1LL * nttprimes[0] * v1 + m01 % mod * v2.val);
  };
  vc<mint> c(len(c0));
  FOR(i, len(c)) c[i] = garner(c0[i], c1[i], c2[i]);
  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++) {
    int x = (i < (int)a.size() ? a[i] : 0);
    int 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) <= 60) 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, n) 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_naive(a, b);
    return convolution_ntt(a, b);
  }
  if (min(n, m) <= 200) return convolution_naive(a, b);
  return convolution_garner(a, b);
}
#line 5 "library/poly/lagrange_interpolate_iota.hpp"

// Input: f(0), ..., f(n-1) and c. Return: f(c)
template <typename T, typename enable_if<has_mod<T>::value>::type * = nullptr>
T lagrange_interpolate_iota(vc<T> &f, T c) {
  int n = len(f);
  if (int(c.val) < n) return f[c.val];
  auto a = f;
  FOR(i, n) {
    a[i] = a[i] * fact_inv<T>(i) * fact_inv<T>(n - 1 - i);
    if ((n - 1 - i) & 1) a[i] = -a[i];
  }
  vc<T> lp(n + 1), rp(n + 1);
  lp[0] = rp[n] = 1;
  FOR(i, n) lp[i + 1] = lp[i] * (c - i);
  FOR_R(i, n) rp[i] = rp[i + 1] * (c - i);
  T ANS = 0;
  FOR(i, n) ANS += a[i] * lp[i] * rp[i + 1];
  return ANS;
}

// mod じゃない場合。かなり低次の多項式を想定している。O(n^2)
// Input: f(0), ..., f(n-1) and c. Return: f(c)
template <typename T, typename enable_if<!has_mod<T>::value>::type * = nullptr>
T lagrange_interpolate_iota(vc<T> &f, T c) {
  const int LIM = 10;
  int n = len(f);
  assert(n < LIM);

  // (-1)^{i-j} binom(i,j)
  static vvc<int> C;
  if (C.empty()) {
    C.assign(LIM, vc<int>(LIM));
    C[0][0] = 1;
    FOR(n, 1, LIM) FOR(k, n + 1) {
      C[n][k] += C[n - 1][k];
      if (k) C[n][k] += C[n - 1][k - 1];
    }
    FOR(n, LIM) FOR(k, n + 1) if ((n + k) % 2) C[n][k] = -C[n][k];
  }
  // f(x) = sum a_i binom(x,i)
  vc<T> a(n);
  FOR(i, n) FOR(j, i + 1) { a[i] += f[j] * C[i][j]; }

  T res = 0;
  T b = 1;
  FOR(i, n) {
    res += a[i] * b;
    b = b * (c - i) / (1 + i);
  }
  return res;
}

// Input: f(0), ..., f(n-1) and c, m
// Return: f(c), f(c+1), ..., f(c+m-1)
// Complexity: M(n, n + m)
template <typename mint>
vc<mint> lagrange_interpolate_iota(vc<mint> &f, mint c, int m) {
  if (m <= 60) {
    vc<mint> ANS(m);
    FOR(i, m) ANS[i] = lagrange_interpolate_iota(f, c + mint(i));
    return ANS;
  }
  ll n = len(f);
  auto a = f;
  FOR(i, n) {
    a[i] = a[i] * fact_inv<mint>(i) * fact_inv<mint>(n - 1 - i);
    if ((n - 1 - i) & 1) a[i] = -a[i];
  }
  // x = c, c+1, ... に対して a0/x + a1/(x-1) + ... を求めておく
  vc<mint> b(n + m - 1);
  FOR(i, n + m - 1) b[i] = mint(1) / (c + mint(i - n + 1));
  a = convolution(a, b);

  Sliding_Window_Aggregation<Monoid_Mul<mint>> swag;
  vc<mint> ANS(m);
  ll L = 0, R = 0;
  FOR(i, m) {
    while (L < i) { swag.pop(), ++L; }
    while (R - L < n) { swag.push(c + mint((R++) - n + 1)); }
    auto coef = swag.prod();
    if (coef == 0) {
      ANS[i] = f[(c + i).val];
    } else {
      ANS[i] = a[i + n - 1] * coef;
    }
  }
  return ANS;
}
#line 5 "main.cpp"

using mint = modint998;

void solve() {
  LL(N, K);

  using T = array<int, 3>;
  vc<T> point(N);
  FOR(i, N) FOR(j, 3) read(point[i][j]);

  // ax+by+cz+d>=0
  using T4 = tuple<int, int, int, ll>;
  auto eval = [&](T4 f, T p) -> ll {
    auto [a, b, c, d] = f;
    return a * p[0] + b * p[1] + c * p[2] + d;
  };

  vc<T4> plane;

  FOR(k, N) FOR(j, k) FOR(i, j) {
    T A, B;
    FOR(p, 3) A[p] = point[j][p] - point[i][p];
    FOR(p, 3) B[p] = point[k][p] - point[i][p];
    T C;
    C[0] = A[1] * B[2] - A[2] * B[1];
    C[1] = A[2] * B[0] - A[0] * B[2];
    C[2] = A[0] * B[1] - A[1] * B[0];
    ll a = C[0], b = C[1], c = C[2];
    if (a == 0 && b == 0 && c == 0) continue;
    ll d = a * point[i][0] + b * point[i][1] + c * point[i][2];
    d = -d;
    T4 f = {a, b, c, d};
    vi F(N);
    FOR(i, N) { F[i] = eval(f, point[i]); };
    assert(F[i] == 0 && F[j] == 0 && F[k] == 0);
    if (MIN(F) < 0) {
      f = {-a, -b, -c, -d};
      for (auto&& x: F) x = -x;
    }
    if (MIN(F) >= 0) { plane.eb(f); }
  }

  for (auto&& [a, b, c, d]: plane) {
    ll g = 0;
    g = gcd(g, a);
    g = gcd(g, b);
    g = gcd(g, c);
    g = gcd(g, d);
    a /= g, b /= g, c /= g, d /= g;
  }
  UNIQUE(plane);
  assert(len(plane) <= 1000);

  auto solve = [&](ll k) -> mint {
    ll lo = -200, hi = 200;
    lo *= k, hi *= k;
    ll ANS = 0;
    FOR(x, lo, hi + 1) FOR(y, lo, hi + 1) {
      // a(x/k)+b(y/k)+c(z/k)+d>=0 が必要
      // ax+by+cz+dk>=0 が必要
      ll mi = lo, ma = hi;
      for (auto&& [a, b, c, d]: plane) {
        if (mi > ma) break;
        // cz>=rhs
        ll rhs = a * x + b * y + d * k;
        rhs = -rhs;
        if (c == 0) {
          if (rhs <= 0) continue;
          mi = hi, ma = lo;
          continue;
        }
        if (c > 0) {
          chmax(mi, ceil(rhs, c));
        } else {
          // -cz<=-rhs
          chmin(ma, floor(-rhs, -c));
        }
      }
      if (mi <= ma) ANS += ma - mi + 1;
    }
    return ANS;
  };

  vc<mint> f(4);
  /*
  FOR(i, 4) f[i] = solve(1 + i);
  mint ANS = lagrange_interpolate_iota<mint>(f, K - 1);
  */
  FOR(i, 4) f[i] = solve(i);
  mint ANS = lagrange_interpolate_iota<mint>(f, K);
  print(ANS);
}

signed main() {
  solve();
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 49ms
memory: 3556kb

input:

4 2
0 0 0
1 0 0
0 1 0
0 0 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 47ms
memory: 3544kb

input:

4 10000
0 0 0
1 0 0
0 1 0
0 0 1

output:

59878050

result:

ok 1 number(s): "59878050"

Test #3:

score: 0
Accepted
time: 86ms
memory: 3492kb

input:

8 314159265358979
5 -3 -3
-5 -3 -3
0 5 -3
0 0 10
4 2 6
-4 2 6
0 -5 6
0 0 -5

output:

152811018

result:

ok 1 number(s): "152811018"

Test #4:

score: 0
Accepted
time: 47ms
memory: 3648kb

input:

100 1
0 0 77
0 0 -195
0 0 -194
0 0 -112
0 0 -192
0 0 62
0 0 73
0 0 188
0 0 -150
0 0 -26
0 0 -164
0 0 -142
0 0 -90
200 1 0
0 0 50
0 0 111
0 0 -133
0 0 91
0 0 -70
0 0 46
0 0 175
-200 -67 0
0 0 128
0 0 170
0 0 76
0 0 -28
0 0 47
0 0 -196
0 0 45
0 0 -136
0 0 96
0 0 24
0 0 -29
0 0 -141
0 0 -84
0 0 -99
0 0...

output:

882531

result:

ok 1 number(s): "882531"

Test #5:

score: 0
Accepted
time: 70ms
memory: 3612kb

input:

82 333333333
98 99 168
-106 -105 -172
113 114 193
-13 -12 -17
-115 -114 -187
71 72 123
-70 -69 -112
95 96 163
-85 -84 -137
-28 -27 -42
-31 -30 -47
-200 -67 0
-121 -120 -197
-52 -51 -82
-112 -111 -182
110 111 188
44 45 78
86 87 148
104 105 178
-73 -72 -117
47 48 83
62 63 108
-103 -102 -167
56 57 98
1...

output:

767480931

result:

ok 1 number(s): "767480931"

Test #6:

score: 0
Accepted
time: 562ms
memory: 3348kb

input:

100 1
-63 -39 51
-36 -104 70
9 -77 34
115 -153 19
-161 141 10
157 -149 -4
-82 -92 87
14 114 -64
-176 -68 122
-7 -179 93
-182 200 -9
173 97 -135
0 -1 200
-83 -189 136
117 69 -93
-3 -113 58
183 -179 -2
-52 -184 118
-107 89 9
-24 -48 36
-111 87 12
-143 -173 158
-176 -78 127
-96 162 -33
147 -111 -18
-92...

output:

9771107

result:

ok 1 number(s): "9771107"

Test #7:

score: 0
Accepted
time: 192ms
memory: 9472kb

input:

100 1159111449
82 82 90
181 181 -85
70 70 -20
1 1 0
190 190 56
-83 -83 40
-89 -89 39
136 136 146
-195 -195 47
50 50 -99
-101 -101 -161
162 162 146
23 23 152
181 181 -91
-73 -73 -5
-105 -105 6
155 155 -136
152 152 -190
-33 -33 -137
55 55 41
3 3 -199
-168 -168 -177
-111 -111 115
171 171 8
131 131 123
...

output:

681451260

result:

ok 1 number(s): "681451260"

Test #8:

score: 0
Accepted
time: 64ms
memory: 3568kb

input:

8 1
200 200 200
-200 -200 -200
200 -200 -200
-200 200 200
-200 200 -200
200 200 -200
200 -200 200
-200 -200 200

output:

64481201

result:

ok 1 number(s): "64481201"

Test #9:

score: 0
Accepted
time: 68ms
memory: 3540kb

input:

8 10
200 200 200
-200 200 200
-200 -200 200
200 200 -200
-200 -200 -200
200 -200 -200
-200 200 -200
200 -200 200

output:

160373409

result:

ok 1 number(s): "160373409"

Test #10:

score: 0
Accepted
time: 68ms
memory: 3444kb

input:

8 1234567890123
-200 -200 200
-200 200 200
-200 200 -200
-200 -200 -200
200 -200 200
200 -200 -200
200 200 200
200 200 -200

output:

868669244

result:

ok 1 number(s): "868669244"

Test #11:

score: 0
Accepted
time: 238ms
memory: 3400kb

input:

24 1
200 200 140
200 -140 200
140 200 -200
-140 -200 200
-200 200 140
-200 200 -140
-200 140 200
200 140 -200
200 -140 -200
200 200 -140
-200 -200 140
-200 -140 -200
-200 -200 -140
-200 140 -200
-140 200 200
140 -200 200
200 -200 -140
-200 -140 200
200 140 200
200 -200 140
140 -200 -200
140 200 200
...

output:

64178641

result:

ok 1 number(s): "64178641"

Test #12:

score: 0
Accepted
time: 237ms
memory: 3568kb

input:

24 10
-200 140 -200
200 -140 200
200 140 200
-200 -140 -200
140 -200 -200
200 200 140
-200 -200 -140
-200 200 140
200 -140 -200
-200 -200 140
-140 200 -200
140 -200 200
200 -200 -140
-200 -140 200
-140 -200 -200
-200 200 -140
200 -200 140
200 200 -140
140 200 -200
-140 200 200
-140 -200 200
200 140 ...

output:

869176162

result:

ok 1 number(s): "869176162"

Test #13:

score: 0
Accepted
time: 239ms
memory: 3596kb

input:

24 1234567890123
-200 -140 -200
140 -200 -200
140 200 -200
200 -140 200
-200 -140 200
200 140 200
-140 200 -200
-200 -200 -140
200 200 140
-200 140 -200
-140 200 200
-140 -200 -200
200 -200 140
-200 -200 140
200 -140 -200
140 -200 200
200 140 -200
200 200 -140
200 -200 -140
-140 -200 200
-200 140 20...

output:

908630290

result:

ok 1 number(s): "908630290"

Test #14:

score: 0
Accepted
time: 2506ms
memory: 3504kb

input:

100 1
11 200 0
-197 36 0
-199 17 0
-76 -185 0
136 -147 0
-194 -50 0
140 143 0
0 0 -200
-5 200 0
-180 -88 0
-21 199 0
-99 -174 0
-186 74 0
116 -163 0
153 128 0
118 -161 0
-68 188 0
-200 -1 0
-194 47 0
-196 -40 0
-185 76 0
196 41 0
146 137 0
99 174 0
-124 -157 0
121 -159 0
-200 9 0
-59 191 0
-83 182 0...

output:

16722291

result:

ok 1 number(s): "16722291"

Test #15:

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

input:

100 3
-87 180 0
-163 116 0
-185 -76 0
-200 0 0
200 13 0
189 66 0
-128 -153 0
-192 57 0
44 195 0
167 110 0
-116 -163 0
47 194 0
-86 -181 0
92 -178 0
-53 -193 0
66 189 0
-92 -178 0
-176 96 0
191 -60 0
197 32 0
-78 -184 0
-14 -200 0
-179 -89 0
109 168 0
177 -94 0
176 -95 0
94 -176 0
70 187 0
128 153 0
...

output:

450766066

result:

ok 1 number(s): "450766066"

Test #16:

score: 0
Accepted
time: 2495ms
memory: 3588kb

input:

100 784433716
-103 172 0
-154 128 0
129 -153 0
84 -181 0
-7 200 0
138 -145 0
-97 -175 0
196 -38 0
-148 -135 0
-197 -37 0
141 142 0
128 -154 0
-164 114 0
106 -169 0
-151 131 0
-122 -158 0
170 105 0
61 -191 0
-192 -58 0
197 -33 0
-170 -105 0
109 -167 0
-181 85 0
166 111 0
-44 -195 0
0 0 -200
49 -194 0...

output:

631042395

result:

ok 1 number(s): "631042395"

Test #17:

score: 0
Accepted
time: 437ms
memory: 3444kb

input:

20 1
94 -145 -152
38 -114 138
186 -113 -75
154 -91 -178
191 173 -24
174 23 -128
126 -60 -17
-5 182 -3
-20 -71 157
197 51 68
41 117 -190
184 32 -152
21 -112 158
-14 110 172
24 -9 31
-13 -93 -192
-108 104 179
17 86 -76
107 -72 53
99 -19 60

output:

16547736

result:

ok 1 number(s): "16547736"

Test #18:

score: 0
Accepted
time: 1241ms
memory: 3500kb

input:

93 1
-64 -152 107
92 128 -174
170 56 177
137 -113 -41
-37 -24 -185
185 162 -187
182 35 79
-71 73 -114
126 -117 -44
-160 121 103
-98 163 59
141 77 130
-96 -114 45
130 152 -190
164 -71 188
-65 2 -86
80 16 -24
-104 -118 -131
123 -165 -195
118 26 164
-169 145 1
-147 -129 -106
-137 -85 -192
107 182 111
-...

output:

41981036

result:

ok 1 number(s): "41981036"

Test #19:

score: 0
Accepted
time: 906ms
memory: 3528kb

input:

62 1
-8 164 -123
-146 11 -34
176 151 -132
-26 -81 39
71 174 -83
-111 29 90
85 153 28
156 -174 0
144 -115 -124
-96 -31 -65
162 128 -118
-9 152 -149
-191 -87 -107
-161 84 200
181 -4 -59
-116 -70 71
-68 -141 108
4 -2 -13
96 155 -188
8 144 -39
-90 -20 -66
-69 -197 -156
136 -36 -14
13 -150 -82
71 91 -119...

output:

30784242

result:

ok 1 number(s): "30784242"

Test #20:

score: 0
Accepted
time: 657ms
memory: 3404kb

input:

45 1
104 177 -54
112 168 192
3 -135 51
-149 35 -105
156 -97 25
161 22 -106
113 -120 -75
71 144 144
-188 -36 110
137 63 -137
43 -81 169
183 184 178
-65 183 -148
185 -15 -196
-164 -154 10
67 -178 188
-81 17 -126
164 97 -87
157 156 104
19 33 146
172 169 121
33 146 -141
166 -20 9
158 116 163
-144 -177 -...

output:

34262460

result:

ok 1 number(s): "34262460"

Test #21:

score: 0
Accepted
time: 492ms
memory: 3572kb

input:

26 1
-19 77 -129
71 57 106
-30 35 54
68 86 109
107 -88 -14
-159 149 178
-39 161 88
-176 -24 -15
171 -89 -90
97 -88 69
188 9 -14
-184 65 -176
77 -145 -98
-5 14 -99
94 158 -192
93 138 175
-142 -68 -29
66 -14 -49
196 130 -14
-40 -13 138
169 41 54
149 46 -122
-3 -156 140
-4 17 26
-90 106 146
-107 -114 26

output:

22630372

result:

ok 1 number(s): "22630372"

Test #22:

score: 0
Accepted
time: 1064ms
memory: 3412kb

input:

83 1
150 77 20
-184 -196 23
-128 189 119
194 177 110
-125 -76 -165
11 165 -108
-34 28 100
78 30 23
83 -60 61
20 -15 101
-199 43 -23
95 -18 197
45 -150 104
-53 -10 -53
184 101 -11
-15 125 136
127 -180 29
-14 -33 -150
-73 15 -97
123 62 25
-110 44 -75
99 -58 -32
-57 -85 95
91 -90 12
105 -11 106
172 -18...

output:

44429135

result:

ok 1 number(s): "44429135"

Test #23:

score: 0
Accepted
time: 781ms
memory: 3512kb

input:

37 1
86 -96 195
-92 -11 -166
40 -58 145
-132 -123 64
-196 39 -52
-199 36 -59
41 119 171
131 170 146
-70 12 160
-48 193 -152
57 33 97
-75 -48 -104
-17 36 170
-20 133 9
171 100 44
119 110 -105
-44 -111 -172
43 154 -96
181 80 157
-180 98 -103
-90 -130 -110
-84 173 41
189 -139 55
-144 107 -142
-114 -179...

output:

28728439

result:

ok 1 number(s): "28728439"

Test #24:

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

input:

58 1
-45 174 -64
128 -186 -75
-82 -108 23
-88 -5 17
149 191 -18
122 133 150
-47 -64 100
-2 113 -82
-157 -94 55
194 -56 -61
-117 -83 109
-83 43 -26
107 -24 17
141 -35 -12
53 199 188
68 -145 113
15 -73 -188
164 -56 -171
-46 149 43
2 -153 29
25 -104 35
57 -16 60
-143 -127 -13
78 -143 42
148 -139 187
-1...

output:

37363387

result:

ok 1 number(s): "37363387"

Test #25:

score: 0
Accepted
time: 622ms
memory: 3588kb

input:

42 1
105 -190 -22
174 49 89
-42 163 -189
-61 62 81
190 134 20
-147 -43 117
-95 -104 133
-103 -19 47
159 48 -79
26 -97 -58
-192 138 -118
1 18 14
151 79 -21
-188 -135 -132
151 -164 -3
196 2 11
-62 46 98
135 -29 182
-85 102 -170
-161 -85 105
2 -49 101
-132 40 -133
73 58 79
13 -78 134
-5 -196 186
26 85 ...

output:

33396223

result:

ok 1 number(s): "33396223"

Test #26:

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

input:

50 1
-102 -104 -195
95 81 -157
-119 17 -123
16 -122 -169
147 78 152
48 80 125
-45 -150 -22
111 -85 124
14 -35 -34
-195 9 -128
197 -4 -64
24 -118 100
195 -82 102
50 -132 -104
-100 -95 142
-44 56 176
170 -177 -154
73 109 -158
-143 -184 -178
-160 -1 155
115 -143 107
-98 33 -157
190 -21 62
107 -48 -41
-...

output:

33656374

result:

ok 1 number(s): "33656374"

Test #27:

score: 0
Accepted
time: 606ms
memory: 3488kb

input:

34 1
-166 -133 -99
-128 133 0
-81 193 24
46 18 143
144 94 -167
-9 146 17
-73 52 15
116 132 14
1 -179 139
-194 169 -183
-63 191 10
-90 -50 -121
-96 -170 -197
181 149 182
-180 90 -30
194 -114 -17
-109 146 104
150 -109 -143
56 166 -142
130 123 -8
-50 178 -108
-27 -161 -107
-199 -42 139
78 22 -104
-11 -...

output:

35731863

result:

ok 1 number(s): "35731863"

Test #28:

score: 0
Accepted
time: 740ms
memory: 3384kb

input:

57 1
-93 -132 -143
-33 159 -194
-123 25 -143
-140 -85 74
69 -191 140
57 74 -179
-145 84 177
-73 -191 175
141 149 -134
-36 22 -130
-87 67 133
6 -59 -41
82 -34 -137
-10 -4 4
-194 -185 -143
-60 57 -104
-193 4 -118
-52 -179 33
-85 -87 -38
-126 -100 -79
161 161 -186
24 -126 91
152 -22 -24
-24 -32 138
-19...

output:

42104731

result:

ok 1 number(s): "42104731"

Test #29:

score: 0
Accepted
time: 79ms
memory: 3500kb

input:

5 1
25 -2 20
100 129 -140
-37 133 -181
7 -92 -114
22 116 -82

output:

951995

result:

ok 1 number(s): "951995"

Test #30:

score: 0
Accepted
time: 89ms
memory: 3416kb

input:

5 147
-64 98 50
-143 10 -118
131 -79 62
-59 138 -149
-142 -7 196

output:

884272932

result:

ok 1 number(s): "884272932"

Test #31:

score: 0
Accepted
time: 79ms
memory: 3444kb

input:

5 271828182845
60 -181 -110
-75 196 -71
55 9 -58
-74 -48 -76
91 -177 128

output:

846002797

result:

ok 1 number(s): "846002797"

Test #32:

score: 0
Accepted
time: 3571ms
memory: 3568kb

input:

100 1
193 -53 0
96 -132 115
-97 154 -82
173 75 67
-44 91 173
-63 51 -183
-142 99 101
18 -199 -5
-35 181 77
-44 -63 184
-66 -123 -143
138 140 40
0 82 -182
-100 -172 20
142 139 -24
-187 1 -71
131 -145 45
114 84 -141
186 1 -74
132 -7 -150
57 102 -162
-131 -88 123
-92 31 175
162 114 25
152 -54 -119
-10 ...

output:

29842680

result:

ok 1 number(s): "29842680"

Test #33:

score: 0
Accepted
time: 3618ms
memory: 3556kb

input:

100 2
-68 44 183
-15 -129 152
-132 143 48
-187 25 -65
116 -88 -138
157 46 -115
77 18 -184
24 53 191
-135 143 -36
161 -96 71
-48 178 78
-3 -59 191
133 -58 -137
-17 -1 -199
25 -197 -23
47 -91 172
6 155 -126
38 107 -164
187 69 -17
23 189 -62
111 -150 74
5 136 -147
-112 7 -166
-61 67 -178
157 -119 -33
-...

output:

237639433

result:

ok 1 number(s): "237639433"

Test #34:

score: 0
Accepted
time: 3379ms
memory: 3420kb

input:

100 36
164 -35 109
-181 -61 60
141 61 -128
-117 138 86
65 -74 174
-125 72 139
-183 -60 -53
-171 6 104
144 117 74
-166 -20 -110
-159 -113 -46
-159 -90 -81
79 -65 172
-43 -95 -171
76 91 161
-178 29 86
-130 13 -151
186 26 -70
-165 -105 42
-108 5 -168
-176 -84 -43
77 -79 -167
-171 90 52
39 132 -145
-82 ...

output:

133126869

result:

ok 1 number(s): "133126869"

Test #35:

score: 0
Accepted
time: 3475ms
memory: 3460kb

input:

100 899000570
-33 195 29
41 -174 89
173 -52 86
107 149 -79
-194 48 -7
179 86 26
125 -85 -130
-162 110 -41
37 -191 -47
-64 -166 93
88 88 -157
179 67 59
-146 119 -66
-89 168 -63
-73 147 -114
-146 -116 -72
-129 140 -60
160 -96 -70
-93 15 176
38 71 -183
-166 106 -37
31 110 -164
-105 106 133
83 -76 166
-...

output:

642235468

result:

ok 1 number(s): "642235468"

Test #36:

score: 0
Accepted
time: 3656ms
memory: 3572kb

input:

100 527256954420915
-100 110 -134
-60 -147 -122
-18 -146 -135
-114 103 128
-38 0 196
157 106 63
79 150 -106
-8 -174 99
-196 -8 40
76 -162 89
47 152 -122
83 -102 150
-36 -79 -180
-75 120 -141
23 -196 -32
-144 114 79
-190 -61 -13
156 101 74
-133 -19 -148
-32 -89 176
-157 108 -61
162 -96 69
175 -48 83
...

output:

828026607

result:

ok 1 number(s): "828026607"

Test #37:

score: 0
Accepted
time: 1417ms
memory: 3568kb

input:

100 2
-113 -117 -33
5 -174 -192
-153 23 -105
-92 178 -100
-43 -70 -94
-29 111 35
3 -164 155
-75 163 117
145 -140 102
-199 150 8
2 -63 -56
-137 -185 -56
165 -41 -88
-20 -94 -178
-47 -60 184
159 17 -148
-108 186 169
3 -51 81
-2 -45 -150
-61 -102 119
-198 -187 124
34 -179 -123
149 -132 -123
177 -147 -5...

output:

354649638

result:

ok 1 number(s): "354649638"

Test #38:

score: 0
Accepted
time: 1121ms
memory: 3416kb

input:

100 5
65 -152 -103
-195 110 10
-145 -6 106
105 -20 29
-198 128 57
-89 79 -110
8 159 -6
194 132 -107
-111 88 -54
-74 -171 183
-119 -166 127
-188 33 -151
140 19 -38
-47 193 170
57 -132 16
-105 96 107
-105 -163 -15
55 -165 113
158 -111 -170
51 -92 195
185 93 110
145 149 92
47 -119 149
118 -196 65
-172 ...

output:

580842281

result:

ok 1 number(s): "580842281"

Test #39:

score: 0
Accepted
time: 1035ms
memory: 3416kb

input:

100 145361171
112 53 144
61 -115 159
-148 163 22
23 -70 91
-116 -39 142
-7 -132 35
-167 162 -103
47 -169 -18
-180 -103 -116
-163 -62 70
54 79 145
76 -190 -118
10 -39 -179
69 187 78
31 139 -106
126 38 -125
-80 -101 95
151 -32 -9
-100 167 -44
-84 -82 132
59 -188 -106
45 68 165
150 26 -28
137 164 -91
-...

output:

139549314

result:

ok 1 number(s): "139549314"

Test #40:

score: 0
Accepted
time: 1221ms
memory: 3348kb

input:

100 52502708246019
12 97 -77
195 163 71
160 64 110
-50 -139 99
-142 -28 -151
-91 89 -60
69 92 100
-195 31 -26
-78 -4 -110
20 12 153
148 -153 -158
144 -37 -3
188 57 164
13 -64 -39
160 177 -67
-6 -126 -189
44 -14 75
-23 96 122
133 179 -83
-161 -181 -111
156 100 -59
165 15 -29
-18 74 180
-46 126 101
63...

output:

722223460

result:

ok 1 number(s): "722223460"