QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749575#8208. Beer CircuitsmaspyTL 3759ms45836kbC++2326.6kb2024-11-15 05:11:082024-11-15 05:11:08

Judging History

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

  • [2024-11-15 05:11:08]
  • 评测
  • 测评结果:TL
  • 用时:3759ms
  • 内存:45836kb
  • [2024-11-15 05:11:08]
  • 提交

answer

#line 1 "/home/maspy/compro/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 u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
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_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (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;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/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__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, 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()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), 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 "/home/maspy/compro/library/graph/base.hpp"

template <typename T>
struct Edge {
  int frm, to;
  T cost;
  int id;
};

template <typename T = int, bool directed = false>
struct Graph {
  static constexpr bool is_directed = directed;
  int N, M;
  using cost_type = T;
  using edge_type = Edge<T>;
  vector<edge_type> edges;
  vector<int> indptr;
  vector<edge_type> csr_edges;
  vc<int> vc_deg, vc_indeg, vc_outdeg;
  bool prepared;

  class OutgoingEdges {
  public:
    OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}

    const edge_type* begin() const {
      if (l == r) { return 0; }
      return &G->csr_edges[l];
    }

    const edge_type* end() const {
      if (l == r) { return 0; }
      return &G->csr_edges[r];
    }

  private:
    const Graph* G;
    int l, r;
  };

  bool is_prepared() { return prepared; }

  Graph() : N(0), M(0), prepared(0) {}
  Graph(int N) : N(N), M(0), prepared(0) {}

  void build(int n) {
    N = n, M = 0;
    prepared = 0;
    edges.clear();
    indptr.clear();
    csr_edges.clear();
    vc_deg.clear();
    vc_indeg.clear();
    vc_outdeg.clear();
  }

  void add(int frm, int to, T cost = 1, int i = -1) {
    assert(!prepared);
    assert(0 <= frm && 0 <= to && to < N);
    if (i == -1) i = M;
    auto e = edge_type({frm, to, cost, i});
    edges.eb(e);
    ++M;
  }

#ifdef FASTIO
  // wt, off
  void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }

  void read_graph(int M, bool wt = false, int off = 1) {
    for (int m = 0; m < M; ++m) {
      INT(a, b);
      a -= off, b -= off;
      if (!wt) {
        add(a, b);
      } else {
        T c;
        read(c);
        add(a, b, c);
      }
    }
    build();
  }
#endif

  void build() {
    assert(!prepared);
    prepared = true;
    indptr.assign(N + 1, 0);
    for (auto&& e: edges) {
      indptr[e.frm + 1]++;
      if (!directed) indptr[e.to + 1]++;
    }
    for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
    auto counter = indptr;
    csr_edges.resize(indptr.back() + 1);
    for (auto&& e: edges) {
      csr_edges[counter[e.frm]++] = e;
      if (!directed)
        csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
    }
  }

  OutgoingEdges operator[](int v) const {
    assert(prepared);
    return {this, indptr[v], indptr[v + 1]};
  }

  vc<int> deg_array() {
    if (vc_deg.empty()) calc_deg();
    return vc_deg;
  }

  pair<vc<int>, vc<int>> deg_array_inout() {
    if (vc_indeg.empty()) calc_deg_inout();
    return {vc_indeg, vc_outdeg};
  }

  int deg(int v) {
    if (vc_deg.empty()) calc_deg();
    return vc_deg[v];
  }

  int in_deg(int v) {
    if (vc_indeg.empty()) calc_deg_inout();
    return vc_indeg[v];
  }

  int out_deg(int v) {
    if (vc_outdeg.empty()) calc_deg_inout();
    return vc_outdeg[v];
  }

#ifdef FASTIO
  void debug() {
    print("Graph");
    if (!prepared) {
      print("frm to cost id");
      for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
    } else {
      print("indptr", indptr);
      print("frm to cost id");
      FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
    }
  }
#endif

  vc<int> new_idx;
  vc<bool> used_e;

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  // {G, es}
  // sum(deg(v)) の計算量になっていて、
  // 新しいグラフの n+m より大きい可能性があるので注意
  Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
    if (len(new_idx) != N) new_idx.assign(N, -1);
    int n = len(V);
    FOR(i, n) new_idx[V[i]] = i;
    Graph<T, directed> G(n);
    vc<int> history;
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (len(used_e) <= e.id) used_e.resize(e.id + 1);
        if (used_e[e.id]) continue;
        int a = e.frm, b = e.to;
        if (new_idx[a] != -1 && new_idx[b] != -1) {
          history.eb(e.id);
          used_e[e.id] = 1;
          int eid = (keep_eid ? e.id : -1);
          G.add(new_idx[a], new_idx[b], e.cost, eid);
        }
      }
    }
    FOR(i, n) new_idx[V[i]] = -1;
    for (auto&& eid: history) used_e[eid] = 0;
    G.build();
    return G;
  }

  Graph<T, true> to_directed_tree(int root = -1) {
    if (root == -1) root = 0;
    assert(!is_directed && prepared && M == N - 1);
    Graph<T, true> G1(N);
    vc<int> par(N, -1);
    auto dfs = [&](auto& dfs, int v) -> void {
      for (auto& e: (*this)[v]) {
        if (e.to == par[v]) continue;
        par[e.to] = v, dfs(dfs, e.to);
      }
    };
    dfs(dfs, root);
    for (auto& e: edges) {
      int a = e.frm, b = e.to;
      if (par[a] == b) swap(a, b);
      assert(par[b] == a);
      G1.add(a, b, e.cost);
    }
    G1.build();
    return G1;
  }

private:
  void calc_deg() {
    assert(vc_deg.empty());
    vc_deg.resize(N);
    for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
  }

  void calc_deg_inout() {
    assert(vc_indeg.empty());
    vc_indeg.resize(N);
    vc_outdeg.resize(N);
    for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
  }
};
#line 2 "/home/maspy/compro/library/geo/base.hpp"
template <typename T>
struct Point {
  T x, y;

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

  template <typename A, typename B>
  Point(A x, B y) : x(x), y(y) {}

  template <typename A, typename B>
  Point(pair<A, B> p) : x(p.fi), y(p.se) {}

  Point operator+=(const Point p) {
    x += p.x, y += p.y;
    return *this;
  }
  Point operator-=(const Point p) {
    x -= p.x, y -= p.y;
    return *this;
  }
  Point operator+(Point p) const { return {x + p.x, y + p.y}; }
  Point operator-(Point p) const { return {x - p.x, y - p.y}; }
  bool operator==(Point p) const { return x == p.x && y == p.y; }
  bool operator!=(Point p) const { return x != p.x || y != p.y; }
  Point operator-() const { return {-x, -y}; }
  Point operator*(T t) const { return {x * t, y * t}; }
  Point operator/(T t) const { return {x / t, y / t}; }

  bool operator<(Point p) const {
    if (x != p.x) return x < p.x;
    return y < p.y;
  }
  T dot(const Point& other) const { return x * other.x + y * other.y; }
  T det(const Point& other) const { return x * other.y - y * other.x; }

  double norm() { return sqrtl(x * x + y * y); }
  double angle() { return atan2(y, x); }

  Point rotate(double theta) {
    static_assert(!is_integral<T>::value);
    double c = cos(theta), s = sin(theta);
    return Point{c * x - s * y, s * x + c * y};
  }
  Point rot90(bool ccw) { return (ccw ? Point{-y, x} : Point{y, -x}); }
};

#ifdef FASTIO
template <typename T>
void rd(Point<T>& p) {
  fastio::rd(p.x), fastio::rd(p.y);
}
template <typename T>
void wt(Point<T>& p) {
  fastio::wt(p.x);
  fastio::wt(' ');
  fastio::wt(p.y);
}
#endif

// A -> B -> C と進むときに、左に曲がるならば +1、右に曲がるならば -1
template <typename T>
int ccw(Point<T> A, Point<T> B, Point<T> C) {
  T x = (B - A).det(C - A);
  if (x > 0) return 1;
  if (x < 0) return -1;
  return 0;
}

template <typename REAL, typename T, typename U>
REAL dist(Point<T> A, Point<U> B) {
  REAL dx = REAL(A.x) - REAL(B.x);
  REAL dy = REAL(A.y) - REAL(B.y);
  return sqrt(dx * dx + dy * dy);
}

// ax+by+c
template <typename T>
struct Line {
  T a, b, c;

  Line(T a, T b, T c) : a(a), b(b), c(c) {}
  Line(Point<T> A, Point<T> B) { a = A.y - B.y, b = B.x - A.x, c = A.x * B.y - A.y * B.x; }
  Line(T x1, T y1, T x2, T y2) : Line(Point<T>(x1, y1), Point<T>(x2, y2)) {}

  template <typename U>
  U eval(Point<U> P) {
    return a * P.x + b * P.y + c;
  }

  template <typename U>
  T eval(U x, U y) {
    return a * x + b * y + c;
  }

  // 同じ直線が同じ a,b,c で表現されるようにする
  void normalize() {
    static_assert(is_same_v<T, int> || is_same_v<T, long long>);
    T g = gcd(gcd(abs(a), abs(b)), abs(c));
    a /= g, b /= g, c /= g;
    if (b < 0) { a = -a, b = -b, c = -c; }
    if (b == 0 && a < 0) { a = -a, b = -b, c = -c; }
  }

  bool is_parallel(Line other) { return a * other.b - b * other.a == 0; }
  bool is_orthogonal(Line other) { return a * other.a + b * other.b == 0; }
};

template <typename T>
struct Segment {
  Point<T> A, B;

  Segment(Point<T> A, Point<T> B) : A(A), B(B) {}
  Segment(T x1, T y1, T x2, T y2) : Segment(Point<T>(x1, y1), Point<T>(x2, y2)) {}

  bool contain(Point<T> C) {
    T det = (C - A).det(B - A);
    if (det != 0) return 0;
    return (C - A).dot(B - A) >= 0 && (C - B).dot(A - B) >= 0;
  }

  Line<T> to_Line() { return Line(A, B); }
};

template <typename REAL>
struct Circle {
  Point<REAL> O;
  REAL r;
  Circle(Point<REAL> O, REAL r) : O(O), r(r) {}
  Circle(REAL x, REAL y, REAL r) : O(x, y), r(r) {}
  template <typename T>
  bool contain(Point<T> p) {
    REAL dx = p.x - O.x, dy = p.y - O.y;
    return dx * dx + dy * dy <= r * r;
  }
};
#line 2 "/home/maspy/compro/library/ds/hashmap.hpp"

// u64 -> Val
template <typename Val>
struct HashMap {
  // n は入れたいものの個数で ok
  HashMap(u32 n = 0) { build(n); }
  void build(u32 n) {
    u32 k = 8;
    while (k < n * 2) k *= 2;
    cap = k / 2, mask = k - 1;
    key.resize(k), val.resize(k), used.assign(k, 0);
  }

  // size を保ったまま. size=0 にするときは build すること.
  void clear() {
    used.assign(len(used), 0);
    cap = (mask + 1) / 2;
  }
  int size() { return len(used) / 2 - cap; }

  int index(const u64& k) {
    int i = 0;
    for (i = hash(k); used[i] && key[i] != k; i = (i + 1) & mask) {}
    return i;
  }

  Val& operator[](const u64& k) {
    if (cap == 0) extend();
    int i = index(k);
    if (!used[i]) { used[i] = 1, key[i] = k, val[i] = Val{}, --cap; }
    return val[i];
  }

  Val get(const u64& k, Val default_value) {
    int i = index(k);
    return (used[i] ? val[i] : default_value);
  }

  bool count(const u64& k) {
    int i = index(k);
    return used[i] && key[i] == k;
  }

  // f(key, val)
  template <typename F>
  void enumerate_all(F f) {
    FOR(i, len(used)) if (used[i]) f(key[i], val[i]);
  }

private:
  u32 cap, mask;
  vc<u64> key;
  vc<Val> val;
  vc<bool> used;

  u64 hash(u64 x) {
    static const u64 FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
    x += FIXED_RANDOM;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return (x ^ (x >> 31)) & mask;
  }

  void extend() {
    vc<pair<u64, Val>> dat;
    dat.reserve(len(used) / 2 - cap);
    FOR(i, len(used)) {
      if (used[i]) dat.eb(key[i], val[i]);
    }
    build(2 * len(dat));
    for (auto& [a, b]: dat) (*this)[a] = b;
  }
};
#line 2 "/home/maspy/compro/library/ds/to_small_key.hpp"

// [30,10,20,30] -> [0,1,2,0] etc.
struct To_Small_Key {
  int kind = 0;
  HashMap<int> MP;
  To_Small_Key(u32 n = 0) : MP(n) {}
  void reserve(u32 n) { MP.build(n); }
  int size() { return MP.size(); }
  int query(u64 x, bool set_if_not_exist) {
    int ans = MP.get(x, -1);
    if (ans == -1 && set_if_not_exist) MP[x] = ans = kind++;
    return ans;
  }
};
#line 7 "main.cpp"

/*
次数 6 の点が出たら終わってよい
距離 d 以下でそういうのがないとする
(d,d) grid をとると各セルの中は少ない
距離 2d 以下は全列挙できる
*/

void solve() {
  LL(N, K);
  using P = Point<ll>;
  VEC(P, A, N);
  ll D = 0;

  pi ANS = {infty<ll>, infty<ll>};
  ll cnt = 0;
  while (1) {
    D = (D == 0 ? 1 : D + D);
    vvc<int> IDS(N);
    To_Small_Key S;
    vc<int> box(N);
    FOR(i, N) {
      ll x = 1 + A[i].x / D;
      ll y = 1 + A[i].y / D;
      int k = S.query(x << 32 | y, 1);
      box[i] = k;
      IDS[k].eb(i);
    }
    vc<tuple<ll, int, int>> dat;
    FOR(i, N) {
      ll x = 1 + A[i].x / D;
      ll y = 1 + A[i].y / D;
      FOR(a, -1, 2) {
        FOR(b, -1, 2) {
          int k = S.query((x + a) << 32 | (y + b), 0);
          if (k == -1) continue;
          for (auto& j: IDS[k]) {
            if (i >= j) continue;
            P p = A[i] - A[j];
            if (p.dot(p) <= D * D) dat.eb(p.dot(p), i, j);
          }
        }
      }
    }
    sort(all(dat));

    int M = len(dat);
    vvc<int> G(N);

    vc<int> dist(N, infty<int>);
    vc<int> que(N);
    vi way(N);

    FOR(i, M) {
      auto [c, s, t] = dat[i];
      if (ANS.fi < c) break;
      int ql = 0, qr = 0;
      auto upd = [&](int v, int d) -> void {
        if (d >= K) return;
        if (chmin(dist[v], d)) que[qr++] = v;
      };
      upd(s, 0);
      way[s] = 1;
      while (ql < qr) {
        int v = que[ql++];
        for (auto& w: G[v]) {
          upd(w, dist[v] + 1);
          if (dist[w] == dist[v] + 1) way[w] += way[v];
        }
      }
      G[s].eb(t), G[t].eb(s);
      if (dist[t] < infty<int>) {
        pi k = {c, dist[t] + 1};
        if (chmin(ANS, k)) cnt = 0;
        if (ANS == k) cnt += way[t];
      }
      FOR(i, qr) {
        int v = que[i];
        dist[v] = infty<int>, way[v] = 0;
      }
    }
    if (ANS.fi < infty<ll>) {
      print(ANS.fi);
      print(ANS.se);
      print(cnt * 2 * ANS.se);
      return;
    }
  }
}

signed main() { solve(); }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
0 0
2 2
1000000000 1000000000

output:

2000000000000000000
3
6

result:

ok 3 number(s): "2000000000000000000 3 6"

Test #2:

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

input:

8 5
5 5
5 7
7 7
3 7
2 5
8 5
3 4
7 4

output:

5
5
20

result:

ok 3 number(s): "5 5 20"

Test #3:

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

input:

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

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #4:

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

input:

10 5
4 9
3 8
4 8
3 0
1 4
2 0
10 1
9 10
0 10
3 5

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #5:

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

input:

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

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #6:

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

input:

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

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #7:

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

input:

10 5
6 6
9 10
8 3
1 0
3 0
1 1
5 9
4 1
4 6
8 6

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #8:

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

input:

10 5
8 4
0 3
2 3
10 0
3 6
0 4
8 3
8 8
0 2
0 1

output:

4
3
12

result:

ok 3 number(s): "4 3 12"

Test #9:

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

input:

10 5
6 6
5 8
3 6
0 0
2 8
6 8
10 7
1 7
5 7
6 7

output:

1
4
8

result:

ok 3 number(s): "1 4 8"

Test #10:

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

input:

10 5
1 8
7 8
8 6
6 0
9 6
8 10
9 0
5 9
4 2
8 2

output:

8
3
6

result:

ok 3 number(s): "8 3 6"

Test #11:

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

input:

10 5
10 9
1 2
1 9
8 7
8 2
7 2
1 8
9 8
9 7
3 1

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #12:

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

input:

10 5
0 10
6 6
10 8
9 7
0 9
8 3
5 0
7 10
3 2
3 4

output:

13
3
6

result:

ok 3 number(s): "13 3 6"

Test #13:

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

input:

10 5
9 4
5 0
5 4
0 3
6 0
6 6
3 7
2 3
0 1
5 9

output:

8
3
6

result:

ok 3 number(s): "8 3 6"

Test #14:

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

input:

10 5
7 10
6 5
9 3
6 3
4 5
6 4
2 2
7 0
7 4
5 3

output:

2
3
18

result:

ok 3 number(s): "2 3 18"

Test #15:

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

input:

10 5
2 0
5 9
3 3
7 3
5 5
3 0
4 9
0 1
8 2
2 2

output:

5
3
12

result:

ok 3 number(s): "5 3 12"

Test #16:

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

input:

10 5
0 1
3 2
4 10
5 3
1 7
9 0
6 6
0 0
8 0
4 1

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #17:

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

input:

10 5
2 7
1 7
9 10
7 10
0 9
8 7
5 6
8 10
5 2
0 0

output:

4
3
6

result:

ok 3 number(s): "4 3 6"

Test #18:

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

input:

10 5
0 4
3 7
3 3
4 3
10 8
3 5
9 9
9 8
2 10
0 8

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #19:

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

input:

10 5
6 6
9 1
8 6
3 3
6 3
1 1
6 7
5 0
2 7
4 1

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #20:

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

input:

10 5
4 8
3 1
1 5
4 10
0 8
8 5
6 6
6 2
10 0
2 8

output:

8
3
6

result:

ok 3 number(s): "8 3 6"

Test #21:

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

input:

10 5
6 9
5 9
3 5
2 3
1 4
6 7
0 9
2 5
3 7
1 6

output:

4
3
12

result:

ok 3 number(s): "4 3 12"

Test #22:

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

input:

10 5
2 10
9 5
7 7
6 2
7 2
5 9
3 8
7 10
6 0
1 1

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #23:

score: 0
Accepted
time: 1171ms
memory: 42096kb

input:

199692 3
500136792 500000000
499931604 500118465
499931604 499881535
500557553 499600008
500352365 499718473
500352365 499481543
500978314 499200016
500773126 499318481
500773126 499081551
501399075 498800024
501193887 498918489
501193887 498681559
501819836 498400032
501614648 498518497
501614648 4...

output:

56136071569
3
399384

result:

ok 3 number(s): "56136071569 3 399384"

Test #24:

score: 0
Accepted
time: 988ms
memory: 37652kb

input:

198916 4
500024820 500000000
500000000 500024820
499975180 500000000
500000000 499975180
500110708 499936963
500085888 499961783
500061068 499936963
500085888 499912143
500196596 499873926
500171776 499898746
500146956 499873926
500171776 499849106
500282484 499810889
500257664 499835709
500232844 4...

output:

1232064800
4
397832

result:

ok 3 number(s): "1232064800 4 397832"

Test #25:

score: 0
Accepted
time: 1225ms
memory: 39576kb

input:

200000 5
500243124 500000000
500075129 500231225
499803309 500142905
499803309 499857095
500075129 499768775
500748155 499046283
500580160 499277508
500308340 499189188
500308340 498903378
500580160 498815058
501253186 498092566
501085191 498323791
500813371 498235471
500813371 497949661
501085191 4...

output:

81687356100
5
400000

result:

ok 3 number(s): "81687356100 5 400000"

Test #26:

score: 0
Accepted
time: 1131ms
memory: 37104kb

input:

198744 6
500157690 500000000
500078845 500136563
499921155 500136563
499842310 500000000
499921155 499863437
500078845 499863437
500935173 499831340
500856328 499967903
500698638 499967903
500619793 499831340
500698638 499694777
500856328 499694777
501712656 499662680
501633811 499799243
501476121 4...

output:

24866136100
6
397488

result:

ok 3 number(s): "24866136100 6 397488"

Test #27:

score: 0
Accepted
time: 1147ms
memory: 41200kb

input:

199927 7
500278028 500000000
500173347 500217371
499938133 500271057
499749505 500120632
499749505 499879368
499938133 499728943
500173347 499782629
501459060 499512861
501354379 499730232
501119165 499783918
500930537 499633493
500930537 499392229
501119165 499241804
501354379 499295490
502640092 4...

output:

58208317696
7
399854

result:

ok 3 number(s): "58208317696 7 399854"

Test #28:

score: 0
Accepted
time: 1160ms
memory: 37164kb

input:

199712 8
500197494 500000000
500139649 500139649
500000000 500197494
499860351 500139649
499802506 500000000
499860351 499860351
500000000 499802506
500139649 499860351
501140007 499757547
501082162 499897196
500942513 499955041
500802864 499897196
500745019 499757547
500802864 499617898
500942513 4...

output:

22847887226
8
399424

result:

ok 3 number(s): "22847887226 8 399424"

Test #29:

score: 0
Accepted
time: 1191ms
memory: 40020kb

input:

199809 9
500517211 500000000
500396206 500332456
500089812 500509353
499741395 500447918
499513981 500176896
499513981 499823104
499741395 499552082
500089812 499490647
500396206 499667544
502059676 498439198
501938671 498771654
501632277 498948551
501283860 498887116
501056446 498616094
501056446 4...

output:

125170051880
9
399618

result:

ok 3 number(s): "125170051880 9 399618"

Test #30:

score: 0
Accepted
time: 1172ms
memory: 39580kb

input:

198810 10
500213830 500000000
500172992 500125686
500066077 500203364
499933923 500203364
499827008 500125686
499786170 500000000
499827008 499874314
499933923 499796636
500066077 499796636
500172992 499874314
500868929 499372119
500828091 499497805
500721176 499575483
500589022 499575483
500482107 ...

output:

17464712840
10
397620

result:

ok 3 number(s): "17464712840 10 397620"

Test #31:

score: 0
Accepted
time: 1139ms
memory: 39948kb

input:

197516 11
500355273 500000000
500298874 500192075
500147585 500323167
499949440 500351656
499767346 500268497
499659118 500100092
499659118 499899908
499767346 499731503
499949440 499648344
500147585 499676833
500298874 499807925
501503078 499016166
501446679 499208241
501295390 499339333
501097245 ...

output:

40073652826
11
395032

result:

ok 3 number(s): "40073652826 11 395032"

Test #32:

score: 0
Accepted
time: 1123ms
memory: 36152kb

input:

199692 12
500287748 500000000
500249197 500143874
500143874 500249197
500000000 500287748
499856126 500249197
499750803 500143874
499712252 500000000
499750803 499856126
499856126 499750803
500000000 499712252
500143874 499750803
500249197 499856126
501616606 499602368
501578055 499746242
501472732 ...

output:

22185907477
12
399384

result:

ok 3 number(s): "22185907477 12 399384"

Test #33:

score: 0
Accepted
time: 1074ms
memory: 41320kb

input:

199888 13
500214891 500000000
500190276 500099864
500122072 500176851
500025902 500213324
499923799 500200926
499839152 500142499
499791354 500051426
499791354 499948574
499839152 499857501
499923799 499799074
500025902 499786676
500122072 499823149
500190276 499900136
500400819 498896581
500376204 ...

output:

10578948629
13
399776

result:

ok 3 number(s): "10578948629 13 399776"

Test #34:

score: 0
Accepted
time: 1143ms
memory: 41276kb

input:

198254 14
500466462 500000000
500420268 500202390
500290834 500364695
500103797 500454767
499896203 500454767
499709166 500364695
499579732 500202390
499533538 500000000
499579732 499797610
499709166 499635305
499896203 499545233
500103797 499545233
500290834 499635305
500420268 499797610
501174191 ...

output:

43096073381
14
396508

result:

ok 3 number(s): "43096073381 14 396508"

Test #35:

score: 0
Accepted
time: 1155ms
memory: 41068kb

input:

198375 15
500469143 500000000
500428583 500190817
500313918 500348641
500144973 500446181
499950962 500466573
499765429 500406289
499620456 500275755
499541109 500097540
499541109 499902460
499620456 499724245
499765429 499593711
499950962 499533427
500144973 499553819
500313918 499651359
500428583 ...

output:

38056654745
15
396750

result:

ok 3 number(s): "38056654745 15 396750"

Test #36:

score: 0
Accepted
time: 1125ms
memory: 39548kb

input:

197136 16
500209439 500000000
500193496 500080148
500148095 500148095
500080148 500193496
500000000 500209439
499919852 500193496
499851905 500148095
499806504 500080148
499790561 500000000
499806504 499919852
499851905 499851905
499919852 499806504
500000000 499790561
500080148 499806504
500148095 ...

output:

6678045610
16
394272

result:

ok 3 number(s): "6678045610 16 394272"

Test #37:

score: 0
Accepted
time: 999ms
memory: 40144kb

input:

198288 17
500145782 500000000
500135938 500052662
500107734 500098213
500064980 500130499
500013451 500145160
499960105 500140217
499912147 500116336
499876054 500076744
499856700 500026787
499856700 499973213
499876054 499923256
499912147 499883664
499960105 499859783
500013451 499854840
500064980 ...

output:

2870359217
17
396576

result:

ok 3 number(s): "2870359217 17 396576"

Test #38:

score: 0
Accepted
time: 1127ms
memory: 36416kb

input:

198450 18
500408063 500000000
500383453 500139565
500312594 500262297
500204031 500353392
500070859 500401863
499929141 500401863
499795969 500353392
499687406 500262297
499616547 500139565
499591937 500000000
499616547 499860435
499687406 499737703
499795969 499646608
499929141 499598137
500070859 ...

output:

20084223994
18
396900

result:

ok 3 number(s): "20084223994 18 396900"

Test #39:

score: 0
Accepted
time: 1054ms
memory: 39492kb

input:

197676 19
500266376 500000000
500251943 500086492
500210208 500163612
500145694 500223001
500065391 500258225
499978003 500265467
499892998 500243940
499819588 500195979
499765729 500126781
499737257 500043844
499737257 499956156
499765729 499873219
499819588 499804021
499892998 499756060
499978003 ...

output:

7689304625
19
395352

result:

ok 3 number(s): "7689304625 19 395352"

Test #40:

score: 0
Accepted
time: 1159ms
memory: 37256kb

input:

200000 20
500471804 500000000
500448712 500145795
500381697 500277319
500277319 500381697
500145795 500448712
500000000 500471804
499854205 500448712
499722681 500381697
499618303 500277319
499551288 500145795
499528196 500000000
499551288 499854205
499618303 499722681
499722681 499618303
499854205 ...

output:

21789572801
20
400000

result:

ok 3 number(s): "21789572801 20 400000"

Test #41:

score: 0
Accepted
time: 1077ms
memory: 40152kb

input:

196830 30
500478309 500000000
500467856 500099446
500436957 500194545
500386960 500281142
500320051 500355452
500239154 500414227
500147805 500454898
500049996 500475688
499950004 500475688
499852195 500454898
499760846 500414227
499679949 500355452
499613040 500281142
499563043 500194545
499532144 ...

output:

9998825234
30
393660

result:

ok 3 number(s): "9998825234 30 393660"

Test #42:

score: 0
Accepted
time: 1006ms
memory: 42028kb

input:

199980 30
187518 500000000
187501 500001125
184276 500015254
183803 500016275
175109 500027870
174262 500028610
161604 500035667
160529 500035999
146095 500037298
144978 500037163
131264 500032479
130298 500031901
119674 500022044
119027 500021124
113332 500007797
113114 500006693
113332 499992203
1...

output:

210044785
30
120

result:

ok 3 number(s): "210044785 30 120"

Test #43:

score: 0
Accepted
time: 999ms
memory: 45836kb

input:

199976 28
175020 500000000
175004 500001050
171554 500015188
171084 500016127
161841 500027367
161010 500028010
147805 500034126
146778 500034345
132227 500034126
131207 500033877
118191 500027367
117380 500026700
108478 500015188
108037 500014235
105012 500000000
105028 499998950
108478 499984812
1...

output:

211796356
28
399952

result:

ok 3 number(s): "211796356 28 399952"

Test #44:

score: 0
Accepted
time: 1050ms
memory: 42472kb

input:

199992 26
162506 500000000
162491 500000975
158783 500015104
158317 500015960
148468 500026748
147657 500027290
133923 500032264
132953 500032367
118480 500030389
117574 500030030
105678 500021552
105042 500020813
98448 500007778
98229 500006828
98448 499992222
98696 499991279
105678 499978448
10633...

output:

213392061
26
399984

result:

ok 3 number(s): "213392061 26 399984"

Test #45:

score: 0
Accepted
time: 857ms
memory: 14132kb

input:

49729 30
500000000 500000000
500753821 498954062
501507642 497908124
502261463 496862186
503015284 495816248
503769105 494770310
504522926 493724372
505276747 492678434
506030568 491632496
506784389 490586558
507538210 489540620
508292031 488494682
509045852 487448744
509799673 486402806
510553494 4...

output:

1662232399885
4
394272

result:

ok 3 number(s): "1662232399885 4 394272"

Test #46:

score: 0
Accepted
time: 1814ms
memory: 22152kb

input:

99856 30
500000000 500000000
500777497 499969354
501554994 499938708
502332491 499908062
503109988 499877416
503887485 499846770
504664982 499816124
505442479 499785478
506219976 499754832
506997473 499724186
507774970 499693540
508552467 499662894
509329964 499632248
510107461 499601602
510884958 4...

output:

605440762325
4
793800

result:

ok 3 number(s): "605440762325 4 793800"

Test #47:

score: 0
Accepted
time: 3759ms
memory: 44360kb

input:

199809 30
500000000 500000000
500139442 499563552
500278884 499127104
500418326 498690656
500557768 498254208
500697210 497817760
500836652 497381312
500976094 496944864
501115536 496508416
501254978 496071968
501394420 495635520
501533862 495199072
501673304 494762624
501812746 494326176
501952188 ...

output:

209930928068
4
1591328

result:

ok 3 number(s): "209930928068 4 1591328"

Test #48:

score: 0
Accepted
time: 3757ms
memory: 40828kb

input:

199809 30
500000000 500000000
500184735 499643289
500369470 499286578
500554205 498929867
500738940 498573156
500923675 498216445
501108410 497859734
501293145 497503023
501477880 497146312
501662615 496789601
501847350 496432890
502032085 496076179
502216820 495719468
502401555 495362757
502586290 ...

output:

161369757746
4
1591328

result:

ok 3 number(s): "161369757746 4 1591328"

Test #49:

score: 0
Accepted
time: 2026ms
memory: 14108kb

input:

49729 30
500000000 500000000
500430450 500105515
500773132 499824464
501203582 499929979
501546264 499648928
501976714 499754443
502319396 499473392
502749846 499578907
503092528 499297856
503522978 499403371
503865660 499122320
504296110 499227835
504638792 498946784
505069242 499052299
505411924 4...

output:

196420617725
3
591408

result:

ok 3 number(s): "196420617725 3 591408"

Test #50:

score: -100
Time Limit Exceeded

input:

99856 30
500000000 500000000
500527456 500187113
500993620 499877416
501521076 500064529
501987240 499754832
502514696 499941945
502980860 499632248
503508316 499819361
503974480 499509664
504501936 499696777
504968100 499387080
505495556 499574193
505961720 499264496
506489176 499451609
506955340 4...

output:


result: