QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#74050#5439. Meet in the Middlejapan022022AC ✓3610ms69640kbC++2030.1kb2023-01-30 14:14:482023-01-30 14:14:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-30 14:14:50]
  • 评测
  • 测评结果:AC
  • 用时:3610ms
  • 内存:69640kb
  • [2023-01-30 14:14:48]
  • 提交

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 pi = pair<ll, ll>;
using vi = vector<ll>;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

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) {
  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/graph/base.hpp"

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

template <typename T = int, bool directed = false>
struct Graph {
  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; }
  constexpr bool is_directed() { return directed; }

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

  void resize(int n) { N = n; }

  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;
  }

  // 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();
  }

  void read_parent(int off = 1) {
    for (int v = 1; v < N; ++v) {
      INT(p);
      p -= off;
      add(p, v);
    }
    build();
  }

  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];
  }

  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);
    }
  }

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 3 "library/graph/tree.hpp"

// HLD euler tour をとっていろいろ。
// 木以外、非連結でも dfs 順序や親がとれる。
template <typename GT>
struct Tree {
  using Graph_type = GT;
  GT &G;
  using WT = typename GT::cost_type;
  int N;
  bool hld;
  vector<int> LID, RID, head, V, parent;
  vc<int> depth;
  vc<WT> depth_weighted;

  Tree(GT &G, int r = -1, bool hld = 1)
      : G(G),
        N(G.N),
        hld(hld),
        LID(G.N),
        RID(G.N),
        head(G.N, r),
        V(G.N),
        parent(G.N, -1),
        depth(G.N, -1),
        depth_weighted(G.N, 0) {
    assert(G.is_prepared());
    int t1 = 0;
    if (r != -1) {
      dfs_sz(r, -1);
      dfs_hld(r, t1);
    } else {
      for (int r = 0; r < N; ++r) {
        if (parent[r] == -1) {
          head[r] = r;
          dfs_sz(r, -1);
          dfs_hld(r, t1);
        }
      }
    }
  }

  void dfs_sz(int v, int p) {
    auto &sz = RID;
    parent[v] = p;
    depth[v] = (p == -1 ? 0 : depth[p] + 1);
    sz[v] = 1;
    int l = G.indptr[v], r = G.indptr[v + 1];
    auto &csr = G.csr_edges;
    // 使う辺があれば先頭にする
    for (int i = r - 2; i >= l; --i) {
      if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
    }
    int hld_sz = 0;
    for (int i = l; i < r; ++i) {
      auto e = csr[i];
      if (depth[e.to] != -1) continue;
      depth_weighted[e.to] = depth_weighted[v] + e.cost;
      dfs_sz(e.to, v);
      sz[v] += sz[e.to];
      if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
    }
  }

  void dfs_hld(int v, int &times) {
    LID[v] = times++;
    RID[v] += LID[v];
    V[LID[v]] = v;
    bool heavy = true;
    for (auto &&e: G[v]) {
      if (depth[e.to] <= depth[v]) continue;
      head[e.to] = (heavy ? head[v] : e.to);
      heavy = false;
      dfs_hld(e.to, times);
    }
  }

  vc<int> heavy_path_at(int v) {
    vc<int> P = {v};
    while (1) {
      int a = P.back();
      for (auto &&e: G[a]) {
        if (e.to != parent[a] && head[e.to] == v) {
          P.eb(e.to);
          break;
        }
      }
      if (P.back() == a) break;
    }
    return P;
  }

  int e_to_v(int eid) {
    auto e = G.edges[eid];
    return (parent[e.frm] == e.to ? e.frm : e.to);
  }

  int ELID(int v) { return 2 * LID[v] - depth[v]; }
  int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }

  /* k: 0-indexed */
  int LA(int v, int k) {
    assert(k <= depth[v]);
    while (1) {
      int u = head[v];
      if (LID[v] - k >= LID[u]) return V[LID[v] - k];
      k -= LID[v] - LID[u] + 1;
      v = parent[u];
    }
  }

  int LCA(int u, int v) {
    for (;; v = parent[head[v]]) {
      if (LID[u] > LID[v]) swap(u, v);
      if (head[u] == head[v]) return u;
    }
  }

  int lca(int u, int v) { return LCA(u, v); }
  int la(int u, int v) { return LA(u, v); }

  int subtree_size(int v) { return RID[v] - LID[v]; }

  int dist(int a, int b) {
    int c = LCA(a, b);
    return depth[a] + depth[b] - 2 * depth[c];
  }

  WT dist(int a, int b, bool weighted) {
    assert(weighted);
    int c = LCA(a, b);
    return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
  }

  // a is in b
  bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }

  int jump(int a, int b, ll k) {
    if (k == 1) {
      if (a == b) return -1;
      return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
    }
    int c = LCA(a, b);
    int d_ac = depth[a] - depth[c];
    int d_bc = depth[b] - depth[c];
    if (k > d_ac + d_bc) return -1;
    if (k <= d_ac) return LA(a, k);
    return LA(b, d_ac + d_bc - k);
  }

  vc<int> collect_child(int v) {
    vc<int> res;
    for (auto &&e: G[v])
      if (e.to != parent[v]) res.eb(e.to);
    return res;
  }

  vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
    // [始点, 終点] の"閉"区間列。
    vc<pair<int, int>> up, down;
    while (1) {
      if (head[u] == head[v]) break;
      if (LID[u] < LID[v]) {
        down.eb(LID[head[v]], LID[v]);
        v = parent[head[v]];
      } else {
        up.eb(LID[u], LID[head[u]]);
        u = parent[head[u]];
      }
    }
    if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
    elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
    reverse(all(down));
    up.insert(up.end(), all(down));
    return up;
  }

  vc<int> restore_path(int u, int v) {
    vc<int> P;
    for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
      if (a <= b) {
        FOR(i, a, b + 1) P.eb(V[i]);
      } else {
        FOR_R(i, b, a + 1) P.eb(V[i]);
      }
    }
    return P;
  }
};
#line 2 "library/graph/centroid.hpp"

template <typename GT>
vc<int> find_centroids(GT& G) {
  int N = G.N;
  vc<int> par(N, -1);
  vc<int> V(N);
  vc<int> sz(N);
  int l = 0, r = 0;
  V[r++] = 0;
  while (l < r) {
    int v = V[l++];
    for (auto&& e: G[v])
      if (e.to != par[v]) {
        par[e.to] = v;
        V[r++] = e.to;
      }
  }
  FOR_R(i, N) {
    int v = V[i];
    sz[v] += 1;
    int p = par[v];
    if (p != -1) sz[p] += sz[v];
  }

  int M = N / 2;
  auto check = [&](int v) -> bool {
    if (N - sz[v] > M) return false;
    for (auto&& e: G[v]) {
      if (e.to != par[v] && sz[e.to] > M) return false;
    }
    return true;
  };
  vc<int> ANS;
  FOR(v, N) if (check(v)) ANS.eb(v);
  return ANS;
}

template <typename GT>
struct Centroid_Decomposition {
  using edge_type = typename GT::edge_type;
  GT& G;
  int N;
  vc<int> sz;
  vc<int> par;
  vector<int> cdep; // depth in centroid tree
  bool calculated;

  Centroid_Decomposition(GT& G)
      : G(G), N(G.N), sz(G.N), par(G.N), cdep(G.N, -1) {
    calculated = 0;
    build();
  }

private:
  int find(int v) {
    vc<int> V = {v};
    par[v] = -1;
    int p = 0;
    while (p < len(V)) {
      int v = V[p++];
      sz[v] = 0;
      for (auto&& e: G[v]) {
        if (e.to == par[v] || cdep[e.to] != -1) continue;
        par[e.to] = v;
        V.eb(e.to);
      }
    }
    while (len(V)) {
      int v = V.back();
      V.pop_back();
      sz[v] += 1;
      if (p - sz[v] <= p / 2) return v;
      sz[par[v]] += sz[v];
    }
    return -1;
  }
  void build() {
    assert(G.is_prepared());
    assert(!G.is_directed());
    assert(!calculated);
    calculated = 1;

    vc<pair<int, int>> st;
    st.eb(0, 0);
    while (!st.empty()) {
      auto [lv, v] = st.back();
      st.pop_back();
      auto c = find(v);
      cdep[c] = lv;
      for (auto&& e: G[c]) {
        if (cdep[e.to] == -1) { st.eb(lv + 1, e.to); }
      }
    }
  }

public:
  /*
  root を重心とする木において、(v, path data v) の vector
  を、方向ごとに集めて返す ・0 番目:root からのパスすべて(root を含む)
  ・i番目:i 番目の方向
  f: E x edge -> E
  */
  template <typename E, typename F>
  vc<vc<pair<int, E>>> collect(int root, E root_val, F f) {
    vc<vc<pair<int, E>>> res = {{{root, root_val}}};
    for (auto&& e: G[root]) {
      int nxt = e.to;
      if (cdep[nxt] < cdep[root]) continue;
      vc<pair<int, E>> dat;
      int p = 0;
      dat.eb(nxt, f(root_val, e));
      par[nxt] = root;
      while (p < len(dat)) {
        auto [v, val] = dat[p++];
        for (auto&& e: G[v]) {
          if (e.to == par[v]) continue;
          if (cdep[e.to] < cdep[root]) continue;
          par[e.to] = v;
          dat.eb(e.to, f(val, e));
        }
      }
      res.eb(dat);
      res[0].insert(res[0].end(), all(dat));
    }
    return res;
  }

  vc<vc<pair<int, int>>> collect_dist(int root) {
    auto f = [&](int x, auto e) -> int { return x + 1; };
    return collect(root, 0, f);
  }

  // (V, H), V[i] は、H における頂点 i の G における番号
  // 頂点は EulerTour 順に並ぶ、V は sort されているとは限らない
  pair<vc<int>, Graph<typename GT::cost_type, true>> get_subgraph(int root) {
    static vc<int> conv;
    while (len(conv) < N) conv.eb(-1);

    vc<int> V;
    using cost_type = typename GT::cost_type;
    vc<tuple<int, int, cost_type>> edges;

    auto dfs = [&](auto& dfs, int v, int p) -> void {
      conv[v] = len(V);
      V.eb(v);
      for (auto&& e: G[v]) {
        int to = e.to;
        if (to == p) continue;
        if (cdep[to] < cdep[root]) continue;
        dfs(dfs, to, v);
        edges.eb(conv[v], conv[to], e.cost);
      }
    };
    dfs(dfs, root, -1);
    int n = len(V);
    Graph<typename GT::cost_type, true> H(n);
    for (auto&& [a, b, c]: edges) H.add(a, b, c);
    H.build();
    for (auto&& v: V) conv[v] = -1;
    return {V, H};
  }
};
#line 1 "library/graph/compress_tree.hpp"
// (圧縮された木の頂点ラベルたち、グラフ)
template <typename TREE>
pair<vc<int>, typename TREE::Graph_type> compress_tree(TREE& tree, vc<int> V) {
  // 大事な点をリストアップする
  // もともとの根は含まれるようにする
  sort(all(V), [&](auto& x, auto& y) { return tree.LID[x] < tree.LID[y]; });
  int n = len(V);
  FOR(i, n) {
    int j = (i + 1 == n ? 0 : i + 1);
    V.eb(tree.lca(V[i], V[j]));
  }
  V.eb(tree.V[0]);
  sort(all(V), [&](auto& x, auto& y) { return tree.LID[x] < tree.LID[y]; });
  V.erase(unique(all(V)), V.end());
  // 辺を張ってグラフを作る
  n = len(V);
  using GT = typename TREE::Graph_type;
  using WT = typename GT::cost_type;
  GT G(n);
  vc<int> st = {0};
  FOR(i, 1, n) {
    while (1) {
      int p = V[st.back()];
      int v = V[i];
      if (tree.in_subtree(v, p)) break;
      st.pop_back();
    }
    int p = V[st.back()];
    int v = V[i];
    WT d = tree.depth_weighted[v] - tree.depth_weighted[p];
    G.add(st.back(), i, d);
    st.eb(i);
  }
  G.build();
  return {V, G};
}
#line 6 "main.cpp"

void solve() {
  LL(N, Q);
  Graph<ll, 0> G1(N), G2(N);
  G1.read_tree(1);
  G2.read_tree(1);
  Tree<decltype(G2)> tree2(G2);

  vvc<pair<int, int>> query_at_A(N);
  FOR(q, Q) {
    LL(a, b);
    --a, --b;
    query_at_A[a].eb(q, b);
  }

  vi ANS(Q);
  Centroid_Decomposition<decltype(G1)> CD(G1);

  vc<bool> IN2(N);
  vc<int> new_idx_1(N, -1);
  vc<int> new_idx_2(N, -1);

  FOR(root, N) {
    auto [V1, H] = CD.get_subgraph(root);
    FOR(i, len(V1)) new_idx_1[V1[i]] = i;
    // (方向, 距離)
    vc<pair<int, ll>> dat(len(V1));
    auto dfs = [&](auto& dfs, int v, int p) -> void {
      for (auto&& e: H[v]) {
        dat[e.to].fi = dat[v].fi;
        dat[e.to].se = dat[v].se + e.cost;
        dfs(dfs, e.to, v);
      }
    };
    for (auto&& e: H[0]) {
      dat[e.to].fi = e.to;
      dat[e.to].se = e.cost;
      dfs(dfs, e.to, 0);
    }
    vc<int> V2;
    auto add_V2 = [&](int v) -> void {
      if (IN2[v]) return;
      IN2[v] = 1;
      V2.eb(v);
    };
    FOR(i, len(V1)) {
      auto a = V1[i];
      add_V2(a);
      for (auto&& [qid, b]: query_at_A[a]) { add_V2(b); }
    }
    // V2 で圧縮木を作る
    auto [V, G] = compress_tree<decltype(tree2)>(tree2, V2);
    FOR(i, len(V)) new_idx_2[V[i]] = i;

    // 全方位をやめる
    // 直径 bfs の変種で
    vc<int> que(G.N);
    auto bfs = [&](int s) -> vi {
      vi dist(G.N, -1);
      if (s == -1) return dist;
      int l = 0, r = 0;
      auto add = [&](int v, ll d) -> void { dist[v] = d, que[r++] = v; };
      add(s, 0);
      while (l < r) {
        int v = que[l++];
        for (auto&& e: G[v]) {
          if (dist[e.to] == -1) add(e.to, dist[v] + e.cost);
        }
      }
      return dist;
    };
    auto find_max2 = [&](vi& dist, int s) -> pair<int, int> {
      if (dist[0] == -1) return {-1, -1};
      // 種類、点、距離
      using T = tuple<int, int, ll>;
      T x = {-1, s, -1}, y = {-1, -1, -1};
      FOR(v, len(dist)) {
        if (v == s) continue;
        int i = new_idx_1[V[v]];
        if (i == -1) continue;
        T p = {dat[i].fi, v, dist[v] + dat[i].se};
        if (get<2>(x) < get<2>(p)) {
          if (get<0>(x) == get<0>(p)) {
            x = p;
          } else {
            swap(x, y);
            x = p;
          }
        }
        elif (get<0>(p) != get<0>(x) && get<2>(y) < get<2>(p)) { y = p; }
      }
      return {get<1>(x), get<1>(y)};
    };

    auto D0 = bfs(0);
    auto [A, B] = find_max2(D0, 0);
    auto DA = bfs(A);
    auto DB = bfs(B);
    auto [C, D] = find_max2(DA, A);
    auto [E, F] = find_max2(DB, B);
    // 適宜 unique してよい
    if (C == A || C == B) C = -1;
    if (D == A || D == B || D == C) D = -1;
    if (E == A || E == B || E == C || E == D) E = -1;
    if (F == A || F == B || F == C || F == D || F == E) F = -1;
    auto DC = bfs(C);
    auto DD = bfs(D);
    auto DE = bfs(E);
    auto DF = bfs(F);

    /*
    print("V1", V1);
    print("V", V);
    print("A", A, B, C, D, E, F);
    */

    auto solve_query = [&](int qid, int b, int dir, ll dist) -> void {
      b = new_idx_2[b];
      auto upd = [&](int A, vi& DA) -> void {
        if (A == -1 || new_idx_1[V[A]] == -1) return;
        auto [dir_A, dist_A] = dat[new_idx_1[V[A]]];
        if (dir != 0 && dir_A != 0 && dir == dir_A) return;
        chmax(ANS[qid], dist + DA[b] + dist_A);
      };
      upd(A, DA);
      upd(B, DB);
      upd(C, DC);
      upd(D, DD);
      upd(E, DE);
      upd(F, DF);
    };

    FOR(i, len(V1)) {
      auto a = V1[i];
      for (auto&& [qid, b]: query_at_A[a]) {
        solve_query(qid, b, dat[i].fi, dat[i].se);
      }
    }

    // reset
    for (auto&& v: V) {
      IN2[v] = 0;
      new_idx_1[v] = new_idx_2[v] = -1;
    }
  }
  for (auto&& x: ANS) print(x);
}

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

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3460kb

input:

3 4
1 2 1
2 3 2
1 2 2
2 3 1
1 1
1 2
2 1
2 2

output:

6
4
5
3

result:

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

Test #2:

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

input:

2 1
1 2 1
1 2 1
1 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

2 1
1 2 1
1 2 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 222ms
memory: 9372kb

input:

10000 50000
8101 5996 108427744
5996 7605 870838849
5996 5599 603303696
8101 3006 339377417
8101 6463 442516687
6463 5560 109174079
5560 4063 127596224
3006 1682 947915262
5996 1986 130416311
6463 5455 279771516
6463 2634 516688796
4063 3034 217886863
7605 5092 742375061
5599 2266 193804402
5092 140...

output:

647838384844
626539793176
514273941704
637066393138
472546379596
645842915960
641537859258
573604504956
644081575470
803875451466
674370549986
734764046916
744862815441
763778393516
553499885160
526743824759
610373719514
689550247042
549161302822
726811438160
653134244120
666761991962
701575393972
6...

result:

ok 50000 numbers

Test #5:

score: 0
Accepted
time: 219ms
memory: 9544kb

input:

10000 50000
5314 8843 137901358
5314 4153 459134340
5314 8667 933926892
4153 6504 330487798
4153 8880 750362377
4153 5990 874275912
4153 546 563436331
5990 6216 902348875
8843 3101 669215553
6216 8138 732343176
8667 8675 581114294
6504 7416 127778711
546 4239 282695908
6504 9455 549237168
5314 8340 ...

output:

464564968641
331633000004
565299667784
484694871646
570451097836
417492802442
372302349684
638725688107
386235986078
355738655551
462027769535
558485994764
524714144289
450157947013
432701214095
494566741391
529031758638
637683369382
415646847933
344894296260
390294136162
527685175763
575151290175
3...

result:

ok 50000 numbers

Test #6:

score: 0
Accepted
time: 197ms
memory: 9732kb

input:

10000 50000
2808 2490 757309564
2808 9601 312271047
2808 4046 119325897
2808 4894 466822371
4894 1507 498399554
2490 5982 84088145
9601 1251 149019541
2808 6681 416590999
2808 6583 357757899
1251 3192 889947539
6583 9762 350572496
6681 22 597479070
5982 8744 263208242
8744 5281 49894126
1507 8806 30...

output:

1501072697023
2058806276380
2017086500812
2044250452467
1543567245539
1695101693278
1765462307870
2576423082091
2302805133490
2090282734929
2375783476943
1954788661090
2056530503168
2453153202726
1978028047409
2106220371212
2210163378358
2015714406862
1555876274751
2122832986951
2102262624814
169085...

result:

ok 50000 numbers

Test #7:

score: 0
Accepted
time: 155ms
memory: 10108kb

input:

10000 50000
4064 7188 81750473
7188 8466 310631946
8466 2276 154981798
2276 7347 162965456
7188 464 806245243
464 2250 849189978
8466 641 734602751
8466 9246 225800419
4064 5267 191524437
2276 5292 192776095
2276 9036 414997994
9246 5470 362146726
2250 473 98496385
4064 7726 700294189
473 9503 42824...

output:

3589143478793
5241855728342
3397106617685
3432843859461
4544481241003
3649934075137
3020107625030
3297847713344
3894730366667
3030559097282
4824131552194
4821302024170
4471510161493
3291683748595
4954639576578
2961243269520
3659899432127
3421183608349
5262802614761
4408705330639
5203984107670
500158...

result:

ok 50000 numbers

Test #8:

score: 0
Accepted
time: 186ms
memory: 9676kb

input:

10000 50000
8676 4714 406191383
8676 5040 603960140
5040 9715 635348098
4714 9483 594267326
9483 5451 409058229
8676 8913 909259106
9715 1399 320185961
9715 4857 180234031
4714 8888 585099487
5040 1244 645347755
5451 7736 479423492
9483 1038 272038574
1399 3970 638817231
8888 3314 55726955
8888 2295...

output:

447424387353
491327570749
614052040822
384218910068
429859933145
356174725430
609432604118
465420084327
472632020898
382647454960
343751681021
441874503695
463199624732
610943875286
563031986601
566780763247
346991783125
601234775562
619765985074
357316826763
495874578271
526431260851
331681020073
4...

result:

ok 50000 numbers

Test #9:

score: 0
Accepted
time: 135ms
memory: 9404kb

input:

10000 50000
30 8765 730632293
8765 4245 897288335
30 4974 965971295
4974 9464 585377707
9464 744 157095406
744 6387 969328235
744 235 905769171
744 912 989443452
744 1341 273641834
744 9933 802952118
4974 8348 248881694
8765 9127 36706230
912 6136 324362270
4974 8517 411159721
8348 1941 672019024
94...

output:

260285187513
334448828465
448073136303
349497881882
360969017248
402078622370
390257279014
308648100196
320994952264
289449337583
393159064851
453034865550
283828471834
446349617896
380894281657
408838602752
363824724502
420964873388
362606539223
391080537186
304570333981
245848347318
310973758007
3...

result:

ok 50000 numbers

Test #10:

score: 0
Accepted
time: 142ms
memory: 9396kb

input:

10000 50000
2152 8278 350040498
2152 3058 895649234
3058 2264 151370300
8278 6118 576488088
8278 7313 464941095
3058 6966 884173172
6966 9779 786319677
9779 9796 943877064
6118 929 517473780
6118 2651 550491074
7313 662 313307192
7313 8043 506406589
7313 1698 864683116
6118 5060 766592488
6966 1903 ...

output:

652477746679
597325264627
539318490039
597048004752
421646977029
649309274459
506349020540
429554460108
462828559625
593933122751
543584884281
652286846854
654020863570
717938057245
431237695994
601883634488
731084254857
588856926225
399175030875
575410680840
526320427336
494819850806
529049784844
5...

result:

ok 50000 numbers

Test #11:

score: 0
Accepted
time: 180ms
memory: 9280kb

input:

10000 50000
7747 7582 379514112
7582 4607 188977429
7582 5317 187026200
7747 8600 712822661
8600 4262 212978273
7747 827 649275004
827 8014 76935591
7747 6641 753086484
7582 8582 206016126
8014 8460 708095438
8014 9211 377732689
8582 4450 416298437
827 9208 699971259
9208 6823 416992550
8582 186 770...

output:

746737735180
498470031337
630778245801
714337715073
566315588400
809241414480
668680437815
575990359534
612421079786
631355089285
534254563162
566879359756
667087033615
650377712872
669587743650
611030906118
593248384501
735077133684
585253655611
595113935966
519628983099
603281284099
529926712130
5...

result:

ok 50000 numbers

Test #12:

score: 0
Accepted
time: 184ms
memory: 9468kb

input:

10000 50000
3472 122 628742395
3472 3867 379635964
3867 1902 749838600
3867 7438 305533780
122 6633 278565996
122 1661 208291710
7438 3819 677928429
1902 7425 657683150
1661 5239 676247552
1902 2756 448261111
7438 7365 97063037
3819 6763 371040229
6633 8865 356148629
6763 5581 863369674
6633 1551 46...

output:

608697605604
482134269787
577721966634
628074778968
445000575297
484814952220
511586460160
374153126368
469519128844
602443844531
619658782918
385417337773
345965815878
620132139546
609655051154
537845187251
622122602447
436588599524
531403283302
587074749895
441226010189
421564270566
406700017163
5...

result:

ok 50000 numbers

Test #13:

score: 0
Accepted
time: 196ms
memory: 9456kb

input:

10000 50000
1160 9231 559787863
9231 4770 299521320
9231 9192 876373929
4770 3107 498755345
1160 5830 724175215
3107 9464 281278611
5830 3611 15139105
4770 7601 642740087
9464 910 538577221
9464 8134 554493711
7601 5225 259081456
9192 4493 741155925
5225 7756 789054604
5225 9044 160953940
7601 6104 ...

output:

44163199908
36544889589
45890256673
36776414195
37333219129
39650732470
43389306319
38148496085
42684423989
37470526473
42398992970
40710607327
42271798904
40981602830
42083787825
41411720865
39511748870
39133821656
42107800923
40131700757
38159799832
39161288828
43514631246
38415055107
37202416831
...

result:

ok 50000 numbers

Test #14:

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

input:

10000 50000
4350 9200 67344024
4350 3516 652031480
9200 9124 852386373
3516 3291 174252855
9124 6162 531615996
3516 3512 591430394
9124 1486 34243545
9200 6098 389999654
6162 3831 371706900
3512 4570 438513693
6162 312 142582166
3512 2336 718583156
4570 7409 610288335
2336 7420 1537001
7420 7842 827...

output:

1281632463885
1210271183079
1237017380491
895833426340
1283280064455
942224768023
892689065199
798697911014
751216197267
758455784557
1141824774281
820909870575
1014030803803
957938689064
1219651503682
771983156874
1178424399518
788435609430
1077287342681
1093062283731
946704599027
893784573061
1275...

result:

ok 50000 numbers

Test #15:

score: 0
Accepted
time: 151ms
memory: 9916kb

input:

10000 50000
9863 2086 776561351
2086 3631 126823773
9863 3392 474209454
3631 9001 149307847
9001 9522 263109666
3392 5761 187746709
9001 3767 870963783
3631 3788 726791
9522 4896 223271095
5761 1160 858678197
5761 543 58975325
3767 9995 875487770
1160 7361 101433507
4896 8325 954009430
8325 3351 894...

output:

3639977233620
3530907756332
2675379129344
4448022048643
2573190330483
4499414931784
3266309481456
3096703943537
2626858162069
3705044120135
3214988142418
3607045075418
2855013843207
4100248201012
2944552371007
3467914981358
4012578656847
4011860831951
5010047454262
4258401519515
4612650790910
498761...

result:

ok 50000 numbers

Test #16:

score: 0
Accepted
time: 171ms
memory: 9528kb

input:

10000 50000
4049 3217 948325921
4049 5052 335875847
5052 1077 805501667
1077 5617 791326096
3217 6795 341938001
1077 1687 296345105
6795 4846 592548551
5052 605 480047794
1687 1641 278347154
5617 4357 204297995
605 314 916793543
605 2278 379707422
2278 1593 345641808
1687 8644 903411591
1593 4760 76...

output:

22692370014
26671995767
23223650964
25037938894
24746389474
23697688458
23151041959
23816855885
23838338206
24834553266
26196330065
24533366219
26308807100
27248674922
25552842773
26570165114
22870797629
23557706389
26691697989
25265417363
24630757806
26415052596
25655335960
24347193370
26001962880
...

result:

ok 50000 numbers

Test #17:

score: 0
Accepted
time: 127ms
memory: 9420kb

input:

10000 50000
6523 4998 683131495
4998 935 871371995
6523 9691 163318078
9691 8916 578451344
9691 9874 961103371
8916 685 208189809
685 8871 368173207
8916 6734 382636596
685 5383 69823504
8871 5902 340803834
4998 587 182084912
935 8296 327702300
5383 4787 216764061
5383 2603 471182122
587 7372 923681...

output:

24346279878
24159724129
19056689759
21329886740
23717511632
21152471010
22089148390
19124036591
20347315967
22739779159
21892965420
21733073800
20715327790
19193604096
20429859569
23181805930
23345539065
21847491691
20610795206
20970932375
20066420900
25367510483
25843830881
20702116769
20515076455
...

result:

ok 50000 numbers

Test #18:

score: 0
Accepted
time: 146ms
memory: 9264kb

input:

10000 50000
8136 1635 842124659
8136 2446 96949099
1635 3483 867846492
1635 7944 589014022
2446 207 229225727
7944 1395 875428514
7944 312 711917988
3483 4069 668199427
4069 2891 305479784
4069 4426 368431680
3483 1607 247762956
1395 7960 213299897
1607 6273 261862409
207 8056 602952
7960 2331 89834...

output:

221805361345
344330244834
301417460297
196121116177
222185764926
269532557170
198254727612
342514611011
271623778301
249627562926
352800786311
318085376117
259654080926
283228181375
306204031853
331174503459
236933657251
189132469039
318214396178
200056424582
246470661905
244719493308
274008065442
3...

result:

ok 50000 numbers

Test #19:

score: 0
Accepted
time: 179ms
memory: 9292kb

input:

10000 50000
334 352 60206968
352 305 837992380
305 8581 842844833
334 8942 264051201
352 6003 382159029
8942 5537 30427164
8581 5969 913354403
6003 905 682266733
5969 1403 303476090
5969 7464 32917776
6003 2070 859897901
2070 3467 234241345
3467 8698 320427414
8581 7873 37110524
1403 8517 185370301
...

output:

581969194691
514453676470
390553242144
398767185182
396307411698
584378802405
654841477333
639529239848
655418442247
730832203542
400197481561
640310612327
591358565895
582685012783
649766947177
653842132618
655829106256
632258804246
648019844537
634680579467
592078061031
629280869021
403624822082
6...

result:

ok 50000 numbers

Test #20:

score: 0
Accepted
time: 214ms
memory: 9320kb

input:

10000 50000
2912 1663 153488050
1663 350 727308826
350 5343 783761508
5343 4104 46303186
4104 4018 493469519
4018 7659 338930839
7659 7533 245268135
7533 7193 290715498
7193 1634 377621959
1634 4211 94097273
4211 8929 767914581
8929 9758 539944169
9758 5342 960382115
5342 9418 972428758
9418 7598 33...

output:

1190970395145
1233073741726
1371353640922
1331841332961
1378285681669
1293803818492
1686098601566
1618705136059
1050063891251
1662210882776
1448886276816
1832119288597
1763213206091
1156731099316
1524816455948
1335795776622
1633864615670
1516179736541
1415679696558
1438625445786
1615887718882
189147...

result:

ok 50000 numbers

Test #21:

score: 0
Accepted
time: 212ms
memory: 9604kb

input:

10000 50000
1582 4135 838497045
4135 3442 702336909
3442 375 533282097
375 7146 882775805
7146 7807 86813140
7807 2263 859334122
2263 4883 392374535
4883 764 848075477
764 8723 793741265
8723 7925 470473887
7925 9112 861905098
9112 9330 805905723
9330 1010 229417453
1010 1029 642466213
1029 9335 709...

output:

1127922564814
1281785466573
973255728311
1332854046538
1161797930892
807045830722
1425252079799
1039233881246
980497481096
1216098061633
1476646339263
1533948111753
1212122907197
1332660079468
955677153525
1259815716640
1086329148065
909766639115
1338471739010
939166362772
1340194437028
104118973954...

result:

ok 50000 numbers

Test #22:

score: 0
Accepted
time: 183ms
memory: 9808kb

input:

10000 50000
4451 9061 799400506
9061 1178 240231790
1178 5175 327625710
5175 2065 504597872
2065 7467 395771348
7467 4338 90256163
4338 7909 39263862
7909 6047 959079033
6047 4521 939635800
4521 1781 570412122
1781 7114 41842045
7114 9567 538188744
9567 6660 479347504
6660 5084 475415876
5084 7759 2...

output:

2612835250496
2316736477624
2309048258185
2157172758992
2377745518491
2409756133919
2272336592611
2053957710271
2157940052734
2055432584295
2389859879140
2584767884856
2084451671595
2691085170630
2552358316415
2117293003432
2601352641000
2038665655976
2262026232194
2883248280386
1930369024422
263238...

result:

ok 50000 numbers

Test #23:

score: 0
Accepted
time: 162ms
memory: 10352kb

input:

10000 50000
2406 3956 170266249
3956 4278 617152977
4278 9621 802573824
9621 7235 499787802
7235 7940 556199678
7940 5712 268451785
5712 8272 380260179
8272 9454 312873112
9454 37 928734978
37 8494 918251253
8494 2702 909777424
2702 2897 511382005
2897 2473 650541982
2473 8739 540826760
8739 1318 57...

output:

3688449984397
3506033630019
3926985837670
4985948471880
5772244887821
5602256960659
4730388411655
5141144647115
3882620480043
5244011267795
6180288345261
4561619240491
4424170939376
4452089542635
5272350745707
5067654692782
4316283105320
6103750854868
4951431868818
4953378642955
4369957992172
502862...

result:

ok 50000 numbers

Test #24:

score: 0
Accepted
time: 223ms
memory: 9620kb

input:

10000 50000
9430 4862 90250453
4862 5092 294400353
5092 2612 484501098
2612 8881 932929771
8881 7630 665290950
7630 6880 197581047
6880 6106 295913729
6106 3182 888334009
3182 2764 687623650
2764 7330 955188014
7330 5888 105599141
5888 5128 827517314
5128 9673 626535422
9673 9500 218347441
9500 4501...

output:

1442822272365
1249968437919
1368459443408
925425673049
1371626107255
1501244260337
1123727805409
1434888268789
1537663432781
1199117283837
1547928613605
899524679128
1495714480795
1196591493368
981733389269
1184663866396
937249971220
1217636880799
1567605094467
1392243948541
1496701724063
9117555121...

result:

ok 50000 numbers

Test #25:

score: 0
Accepted
time: 133ms
memory: 9596kb

input:

10000 50000
1967 9497 461820510
9497 1178 319298273
1178 7445 145202113
7445 3034 902583404
3034 7501 928151869
7501 2487 459727120
2487 1927 411855531
1927 4807 105006725
4807 1992 299690675
1992 4558 246562304
4558 115 348147838
115 2218 732412173
2218 6098 36029103
6098 8912 215264673
8912 5974 7...

output:

1452728960259
1069309140104
1088859970692
1601829914205
1600074448672
918801493758
1556713604025
1468991923254
1032000884525
1120479986989
1584995341955
1225820113142
1115386685568
1125849996370
1624310125094
1042043642274
1642673371715
921569447932
1114209021067
1175110907921
1674220487453
13608173...

result:

ok 50000 numbers

Test #26:

score: 0
Accepted
time: 151ms
memory: 9460kb

input:

10000 50000
3687 1957 195328472
1957 9618 819445162
9618 5708 301381464
5708 7804 803748477
7804 5784 159651491
5784 9477 191830173
9477 2828 651065074
2828 3288 442904132
3288 2676 145220818
2676 9753 442305164
9753 9303 898437452
9303 6960 700689716
6960 6964 284360517
6964 5387 355920548
5387 392...

output:

998503404363
1604845265983
1423320672434
1230166630000
1629093161212
1665524577805
1017436418144
1379079551940
1215814978854
1525080888607
1336110438270
1391978947901
1224078797078
1337273479620
903411009592
1032160619737
1450865947593
1270702155713
1123901183324
945302264234
1621388543791
137770393...

result:

ok 50000 numbers

Test #27:

score: 0
Accepted
time: 184ms
memory: 9720kb

input:

10000 50000
4619 4672 632374577
4672 1485 151596478
1485 7570 520803323
7570 5035 589315332
5035 6454 972688563
6454 3178 4455903
3178 7452 655255761
7452 8817 290358997
8817 7446 894564176
7446 2400 391187907
2400 8212 447745441
8212 1041 225735660
1041 6146 3273699
6146 2076 501450580
2076 7017 60...

output:

1466430398410
1374962852333
1167346426504
1568616290332
1583434370235
1567260274522
1342605268196
1110985837416
1424545379723
1198723544468
1440457693462
1113663184800
1717040026662
1319981119405
1547625088972
1818262100762
1438147538696
1732361643736
1514518231328
1800320095828
1235395372966
167798...

result:

ok 50000 numbers

Test #28:

score: 0
Accepted
time: 228ms
memory: 9656kb

input:

10000 50000
3815 2108 109828605
2108 8246 871433724
8246 1773 499617397
1773 4982 529444916
4982 5565 125348820
5565 4927 295865627
4927 3617 274708402
3617 4621 934061476
4621 5864 71331083
5864 7163 41553354
7163 1864 139708757
1864 4821 408177604
4821 406 762686163
406 3802 554564727
3802 6097 45...

output:

4179645608801
3621222799118
5069122128753
3107489850826
3725609402691
4197146513097
3863763537601
4425810625162
5271230619388
3622077291893
5587359863687
3216144157381
4585048602299
4823522488441
4961364199893
3633725603053
4304942220163
5515944410576
4837662880499
3818831769794
3063292200970
371425...

result:

ok 50000 numbers

Test #29:

score: 0
Accepted
time: 258ms
memory: 9964kb

input:

10000 50000
1026 9411 807865599
9411 8477 114914385
8477 4630 117894471
4630 2583 431079789
2583 7986 776448300
7986 218 457926255
218 8900 397346917
8900 8767 218388952
8767 5843 913534371
5843 3742 618503504
3742 3319 492252659
3319 2455 830110630
2455 5201 394003558
5201 2347 119358741
2347 3095 ...

output:

4150620273258
4900011741668
4510937083926
4507537640062
4335426504350
3076847988438
3179824212142
4281208959293
4022540671475
3575917949129
4047096988755
4242394553346
3429528629662
2907131856245
3234879589233
2830253794403
3038747350850
3062740673985
3527280377144
3688356427678
2849861354167
286902...

result:

ok 50000 numbers

Test #30:

score: 0
Accepted
time: 204ms
memory: 9668kb

input:

10000 50000
5676 3304 360678401
3304 9671 208651942
9671 5808 291461144
5808 7195 332714662
7195 6117 132580484
6117 2475 325019586
2475 2202 665209625
2202 9459 357492236
9459 4541 490896443
4541 102 755262166
102 480 549829265
480 2980 957076360
2980 7927 880096760
7927 6507 829376947
6507 5875 48...

output:

4053816166902
5274942110119
6621667205076
5262572259524
6375870430343
5009263574832
4550206351153
5992896905952
6725177648919
5751273937319
5957109474664
5698292166429
4651310779201
5295950230806
5540686673728
5227296374669
5403703339688
6532799126832
5515803622733
4945763113888
6142127823783
456305...

result:

ok 50000 numbers

Test #31:

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

input:

10000 50000
7860 6916 58715396
6916 2107 452132603
2107 6027 909738217
6027 7833 384092639
7833 3186 343488475
3186 1684 632304406
1684 7566 933072332
7566 7672 791562817
7672 3011 628067027
3011 2000 892020828
2000 4650 757148974
4650 2781 379009386
2781 1925 776255370
1925 284 394170961
284 2519 7...

output:

8345802882466
7752125506031
5325552875372
7910967128590
9162073099026
8347819055596
7069087140904
6103598414251
7578942323087
8020606113849
9166504332696
8058152029875
7865849019734
7591333908187
7235306321669
7779837515745
7381576408027
7874688500313
8398331609483
8448934115503
6855357808040
724080...

result:

ok 50000 numbers

Test #32:

score: 0
Accepted
time: 203ms
memory: 9764kb

input:

10000 50000
3912 5768 611528198
5768 1279 400645967
1279 6160 378272187
6160 4799 285727512
4799 6833 699620659
6833 8750 204430442
8750 5144 200935040
5144 3528 780922997
3528 6561 60204907
6561 4926 28779490
4926 341 814725580
341 9028 505975116
9028 1101 407572764
1101 3028 958964975
3028 2587 81...

output:

3006556003155
2986675768895
3602898535206
3072106966530
2875433482745
3736109673979
4361090734417
3107949394516
2694549139780
3794436600420
3540637515996
3983471110773
4619052142947
2935033637289
4509082043952
4293885199026
2894169597463
4892779588617
5046352712895
2768312011109
4296372655827
401366...

result:

ok 50000 numbers

Test #33:

score: 0
Accepted
time: 137ms
memory: 9808kb

input:

10000 50000
5558 6828 899499784
6828 3450 939093924
3450 8591 701581964
8591 6110 187362385
6110 2720 55752843
2720 9172 366491070
9172 300 468797747
300 8280 214993577
8280 7196 492342787
7196 2183 460505448
2183 3765 872302186
3765 6107 632940846
6107 5739 893665966
5739 8632 228791692
8632 4011 4...

output:

2576945793968
4438226525762
4481355559359
3498409719144
3124280127226
3476509741524
3231958189445
2583145100783
3829513290883
4116510653072
4744987131523
2774262210980
4705754804913
4044614358257
4714733484071
3448030816040
3741061531555
3680907163383
4158506190573
4066157026108
4497257277372
277552...

result:

ok 50000 numbers

Test #34:

score: 0
Accepted
time: 197ms
memory: 9764kb

input:

10000 50000
3417 812 452312587
812 3679 32831481
3679 9424 170115933
9424 6506 238740362
6506 6627 706852322
6627 3203 233584402
3203 76 591436263
76 71 354096861
71 5392 774737563
5392 3048 597264110
3048 8906 79621896
8906 7876 759906576
7876 3329 379759168
3329 3319 793585706
3319 1919 150456534
...

output:

2793290563406
5100059649817
2755446460025
4472173766552
4616870733077
5095866481572
3132176265250
5053455434636
3693212335776
2965942366995
2956246263851
3427979821834
3169235318775
3742819981252
2670186975658
4444948825358
4670233814666
3805960388458
3025495857934
3501882130036
4108392137023
355064...

result:

ok 50000 numbers

Test #35:

score: 0
Accepted
time: 215ms
memory: 9932kb

input:

10000 50000
2235 3798 5125389
3798 4755 276312142
4755 942 493425711
942 2995 140375235
2995 6796 62984506
6796 549 395645030
549 4531 154266266
4531 1655 788167441
1655 3957 911908148
3957 4983 734022772
4983 3258 137198502
3258 1803 886872306
1803 7978 716109267
7978 9466 503603912
9466 3342 74121...

output:

4477866840130
4540331690816
3047500903303
4674396108007
4614023873482
4101285169455
3408066895970
3869869436784
4400024412461
3421748946225
4741022300319
3672879059157
2954920604473
3100739068002
3778903004363
3997267428937
4226662837584
3387981902161
3936843525627
3540296299447
3019118401753
443717...

result:

ok 50000 numbers

Test #36:

score: 0
Accepted
time: 123ms
memory: 9468kb

input:

10000 50000
2764 6267 177718153
2764 1936 879305164
2764 7194 230541546
2764 9209 619817871
6267 2149 725275415
6267 111 159807033
6267 7130 44970417
6267 4659 93642751
6267 9431 504556475
1936 7507 785795089
1936 2403 497197404
1936 4466 848003581
1936 1558 30618082
1936 4936 8359765
7194 2173 7559...

output:

360898072889
448018777875
433650570003
396592849441
460140813406
514992199226
407565858989
525944471386
536655383679
428284999570
372997724781
313299387258
314137667834
447318998795
484169750325
501935831308
278211059357
510196051629
522719636432
491015742173
282002929685
447940167347
536371112593
3...

result:

ok 50000 numbers

Test #37:

score: 0
Accepted
time: 115ms
memory: 9704kb

input:

10000 50000
4735 9641 126231518
4735 9090 52871837
4735 8455 132176419
4735 1 975950055
4735 2806 32560235
9641 3672 282445549
9641 2295 184073701
9641 3676 81070231
9641 8325 936282433
9641 2250 138338991
9641 5576 624163134
9090 3999 184353680
9090 5648 740636288
9090 2702 304151324
9090 3611 4557...

output:

26654787218
25849489215
22982877830
27532741512
29167792048
30269889742
29686868840
28261359820
25831438942
24838367437
23893582091
24129511369
25753470260
25671566804
26069663171
22283968484
25384736488
24555880969
25677851302
24726988284
30353420340
30735659672
28509398049
24051209701
27071897083
...

result:

ok 50000 numbers

Test #38:

score: 0
Accepted
time: 146ms
memory: 9772kb

input:

10000 50000
4276 5034 664679475
4276 5140 671148910
5034 1837 888587100
5034 7593 627049535
5034 8454 899653567
5140 8092 845275552
5140 4926 323176986
5140 2640 513208111
1837 7139 73041095
1837 2963 195915597
1837 8246 751128864
7593 3407 670446882
7593 201 305430302
7593 4777 44653283
8454 7835 3...

output:

1447107869872
1265469647776
1307193095162
848288250978
863631986020
1599161614228
1456362239612
1455582375147
1256744804550
1346437461977
1378527263747
910696040472
1181055362003
1358649022878
1386224525929
988154311637
939044401855
827972558485
1518711765983
1067975153835
1575946901538
936047441056...

result:

ok 50000 numbers

Test #39:

score: 0
Accepted
time: 112ms
memory: 10096kb

input:

10000 50000
5990 2599 758417031
5990 9188 844715584
5990 2582 85189269
2599 7893 983181718
2599 1532 61714194
2599 5352 113138260
2599 8209 607504462
9188 68 945345992
9188 3781 209799757
9188 1629 403235307
9188 2904 173061890
2582 5221 156540084
2582 2612 870224316
2582 9968 635412138
2582 4257 62...

output:

2653237866591
2488224739435
3094956389261
4434597731695
4229904115133
4195636080287
3736047460883
4033998994260
3906121002347
3881225741752
3187720411313
4747370699182
4790572853590
4064118984674
4496076103565
3903827217157
4085352809248
3291624395034
4662954030834
2915847830192
2489026419691
416507...

result:

ok 50000 numbers

Test #40:

score: 0
Accepted
time: 92ms
memory: 9452kb

input:

10000 50000
3176 606 1897692
3176 4666 462992657
3176 2191 281791438
3176 5204 194089710
3176 2438 928807526
3176 1562 381000967
3176 995 41575042
3176 6478 82516576
606 8238 491782611
606 4471 460811913
606 2443 594994915
606 2912 492890182
606 3630 435018330
606 1417 80946802
606 4873 914480252
60...

output:

11824711248
13306672501
11865441165
12401067358
13979191789
11416993215
13257098530
12818301110
11931719667
12306403599
12492951754
12954182558
12498264508
12186564191
13357715637
12634669171
10978510796
13162263198
12915455391
13720633868
11111780080
10866051416
11301390513
12309873179
12668930419
...

result:

ok 50000 numbers

Test #41:

score: 0
Accepted
time: 63ms
memory: 9512kb

input:

10000 50000
5134 9386 950411057
5134 9105 636559330
5134 8263 333169415
5134 2084 550221894
5134 6883 795900858
9386 5829 648863675
9386 4921 885711030
9386 9232 659878648
9386 9183 218475865
9386 3201 518388519
9386 6811 721960645
9105 2990 978983384
9105 4268 999812343
9105 1712 966672953
9105 992...

output:

10445450762
11133373527
8889431706
8831357513
8391596779
9286294269
10013934204
10451900592
9175572562
9543057146
9893146788
10595734939
10237447692
8374337878
9448084976
8917421132
8203095179
8101393281
9821416297
8844788917
9327518007
9575595542
9543794145
8225258887
8562917185
8483311576
94134540...

result:

ok 50000 numbers

Test #42:

score: 0
Accepted
time: 128ms
memory: 9188kb

input:

10000 50000
588 3021 339115910
588 5589 254836404
3021 5070 234804288
3021 8033 906354077
3021 2733 662994190
5589 1426 916726382
5589 4459 465005802
5589 4000 797049232
5070 4223 355234527
5070 1860 725708229
5070 4653 848926375
8033 9695 465076586
8033 9935 564606357
8033 2691 412207616
2733 8602 ...

output:

80297111067
99611652277
102234234942
97828205780
109151058991
81664867586
111925159451
126616820519
106662017101
109885061443
112484916802
98972223350
120159963864
118707891431
104868535230
109916318731
129954297579
136240763984
100605757004
81113208737
115198227199
112981940207
77820702879
11585709...

result:

ok 50000 numbers

Test #43:

score: 0
Accepted
time: 115ms
memory: 9108kb

input:

10000 50000
5060 1314 582596571
5060 4120 578146181
5060 7338 136439161
1314 3572 557453557
1314 5664 825054818
1314 8335 744397602
1314 3536 604109087
4120 2952 934219816
4120 1965 491993189
4120 643 783284835
4120 3296 975892105
7338 21 801426685
7338 6367 274624563
7338 934 297933767
7338 5534 22...

output:

414772460288
237702806427
234212430166
345856998591
357453889734
306565218137
236225455034
338688147181
236029360222
261970517140
240162710031
237387928354
248870347104
246247511946
238984591287
230016646107
331252294270
320992099621
274643501743
306309017447
247401997168
230776688043
240590387422
2...

result:

ok 50000 numbers

Test #44:

score: 0
Accepted
time: 32ms
memory: 9112kb

input:

10000 50000
3585 8403 687043359
3585 1429 484002582
3585 4146 109249826
3585 8601 226605473
3585 5864 114286922
3585 7326 594876691
3585 9104 44905665
3585 6522 10655166
3585 1569 115954420
3585 5065 967559596
3585 6645 431881422
3585 2892 440993011
3585 2100 638353703
3585 7583 801638733
3585 3464 ...

output:

238774636669
208958010185
285056127507
344392778955
326551225861
339127645438
197162846928
281318176485
223014828629
377415389369
371221938289
354603983294
292680862689
235725444252
237877638296
230591788638
366884260278
344829443225
289171185737
286642671826
275787585207
295348740679
353518043754
3...

result:

ok 50000 numbers

Test #45:

score: 0
Accepted
time: 37ms
memory: 9000kb

input:

10000 50000
4912 946 239856161
4912 3697 727483243
4912 2777 432559603
4912 1839 983016154
4912 304 470419106
4912 5921 461970023
4912 7708 167544180
4912 6149 294982642
4912 9380 103381900
4912 3080 399285554
4912 7538 784425323
4912 9764 713182933
4912 9982 269671098
4912 5638 511656939
4912 3188 ...

output:

26391067214
23501883113
25653062021
20370328114
24301722803
21393520836
23994198279
21127899601
22824998986
25130093650
21875019199
21000013337
20965175587
20946146132
22761830404
18639982391
22269500019
23797737934
26156093929
25411001529
23439341876
21286955417
21621620036
22460872088
24562928370
...

result:

ok 50000 numbers

Test #46:

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

input:

10000 50000
899 6771 937893155
899 5531 675996607
899 6132 901093572
899 8128 179618323
899 9991 826551290
899 8895 329063355
899 9646 435406888
899 334 434085927
899 7851 535519780
899 2785 831011512
899 3826 842001929
899 5476 840148663
899 5550 755764300
899 2810 76450953
899 3130 306404365
899 8...

output:

1574445864922
1972778828458
1591699814167
1194494465440
1693285511606
1737656725784
1552861248093
1554447836381
1496763123669
1134627939314
1469701361028
1719977313037
1188207774895
1106284377295
1227759293519
1854665665862
1202997027025
1458268514935
1134551402927
1679382207034
1851927226115
206876...

result:

ok 50000 numbers

Test #47:

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

input:

10000 50000
9241 3043 490705958
9241 3823 64701460
9241 9161 224403350
9241 2497 81253196
9241 354 477650769
9241 1921 491123983
9241 7069 703269595
9241 8667 573189211
9241 6330 967657660
9241 2320 967770174
9241 7477 49321639
9241 8544 262081689
9241 7525 241857502
9241 2271 641244967
9241 8386 19...

output:

3125852400335
2941865441525
2946397315488
3001592501400
3691585440836
3810768201212
4921736048428
3216403951540
4811045848926
3876530715191
4834248082194
3954101310601
2983413779279
3138617964890
2622438808225
4440862976974
4962594717857
3266929933479
2866674294655
3110018142853
4298083805694
320933...

result:

ok 50000 numbers

Test #48:

score: 0
Accepted
time: 34ms
memory: 9104kb

input:

10000 50000
6024 8289 483710248
6024 4206 308182121
6024 9710 692937319
6024 3139 837663877
6024 6137 833782953
6024 6517 358217315
6024 6545 266099599
6024 8403 152483983
6024 6367 104828244
6024 11 104528836
6024 9060 106898245
6024 6198 389047419
6024 2984 578207600
6024 9857 911071684
6024 1477 ...

output:

7696947150
5974661747
7020959894
7099817526
7567371599
6807787969
7563147808
7076353987
6385017930
6425297669
7559982078
5844012428
7172932326
8054544176
7493528393
7557545533
6449953846
6746334578
6546732553
7262603607
6587596826
7308038744
8380947411
5977502148
7008566613
7485379754
6742703114
808...

result:

ok 50000 numbers

Test #49:

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

input:

10000 50000
8279 53 36523050
8279 6457 551662782
8279 8046 16247096
8279 1985 34266046
8279 2440 44690945
8279 6639 520277942
8279 7394 533962306
8279 8444 996619971
8279 2844 682190316
8279 4960 536254794
8279 1582 164474851
8279 3344 516013149
8279 2765 64300802
8279 5859 475865698
8279 9253 22842...

output:

3271130848
2514805796
2767461658
2927623316
3107690185
3031425659
3098823068
3617127456
2598752590
2753530204
3563856996
3238773617
2523120802
2854124457
3594429563
3086023127
2974348198
3153988315
3223941821
3449139282
2422286813
3194952240
3567014728
2648580076
2977655686
2926210899
3689891579
247...

result:

ok 50000 numbers

Test #50:

score: 0
Accepted
time: 31ms
memory: 9024kb

input:

10000 50000
8157 4203 734560044
8157 1747 500176147
8157 3898 44589578
8157 1303 790676727
8157 2676 400823128
8157 3212 92403978
8157 4984 801825014
8157 4877 430690552
8157 1873 819360901
8157 2999 673013456
8157 9392 371794561
8157 1199 642978879
8157 1629 695618197
8157 3796 185883904
8157 9033 ...

output:

124963144729
181246360658
150728927083
183928936405
133360594008
149036880819
200915530666
140781121412
208565015795
149552352362
185253633723
172903245089
187853819974
176399520096
118494914029
106232398677
184057235235
106485275500
164599640965
199547242576
134351930598
179640742048
127332878210
1...

result:

ok 50000 numbers

Test #51:

score: 0
Accepted
time: 36ms
memory: 9180kb

input:

10000 50000
1571 6744 287372847
1571 6638 888881000
1571 7705 808090843
1571 3872 692311600
1571 8065 756955312
1571 5195 399688798
1571 6823 924463529
1571 811 715018028
1571 5364 956531485
1571 4155 809772118
1571 3056 429371167
1571 9051 64911905
1571 5146 181711399
1571 8113 750677918
1571 7813 ...

output:

504418500854
519926168686
678017729895
489122566913
573088979604
555916864456
575899537700
457597363247
674597453596
453112697992
407336944789
565744097015
445902623065
481298424363
533377882199
640490376733
439380832452
509391863193
468535968880
453445452838
452805572074
560374766055
596835632847
4...

result:

ok 50000 numbers

Test #52:

score: 0
Accepted
time: 149ms
memory: 9244kb

input:

10000 50000
3166 8459 923744508
3166 2424 221883796
3166 2737 60424275
3166 2147 194135700
3166 2964 796680447
3166 9964 10317331
3166 8723 696057237
3166 5420 408657716
3166 3992 33329648
3166 7317 30394623
3166 1928 975690308
3166 4184 217210265
3166 8876 587282291
3166 6187 776242356
3166 9246 81...

output:

325581385038
282622739344
334954017591
278454192026
300051850510
267101196171
336644206249
323808563638
331856308145
299515862009
285222470482
317965680439
350124122626
239583106516
219810541998
223277904115
323403063606
238907956683
263494469650
247431610864
298302098899
270597002947
266803548271
2...

result:

ok 50000 numbers

Test #53:

score: 0
Accepted
time: 178ms
memory: 9160kb

input:

10000 50000
9772 558 33767671
9772 4228 662504265
9772 8775 684112784
9772 7483 964888157
9772 4812 186347107
9772 8661 492834300
9772 5542 260667392
9772 988 125693568
9772 3999 157255971
9772 4796 430511656
9772 9517 656978541
9772 1934 354988516
9772 9959 987710294
9772 4970 122620783
9772 634 37...

output:

215928475651
150627162218
179529821952
161729424471
139999775339
150770149346
197379394735
164673815016
195892380687
173971337047
139275818196
229065017504
216132507294
213995421333
154108346832
150025354337
237189547371
196427517213
214939950766
150829420432
199872527003
147854363462
149582119345
1...

result:

ok 50000 numbers

Test #54:

score: 0
Accepted
time: 129ms
memory: 9440kb

input:

10000 50000
3680 7688 277248332
3680 1142 690846747
3680 8319 735490761
3680 6196 321020341
3680 9547 758473143
3680 9639 615472815
3680 4561 104803380
3680 237 557831449
3680 4004 294014633
3680 3646 488088262
3680 5963 929168463
3680 4054 841081718
3680 1447 552504308
3680 121 863122742
3680 7277 ...

output:

1324682465547
1687524437246
1686880558864
1371209238826
1601131240553
1119410156261
1073274090017
1264721199858
1260092310581
1466284798654
1230050777952
1407573106543
1279044937749
1651227022319
975442297464
1208919081546
1098563840827
1316930578565
1550582781122
1648305325514
977569823765
12461248...

result:

ok 50000 numbers

Test #55:

score: 0
Accepted
time: 107ms
memory: 10184kb

input:

10000 50000
7206 7146 225761697
7206 7754 454348012
7206 5677 637125634
7206 3301 677152524
7206 3019 920533771
7206 850 883335523
7206 7669 684098152
7206 8768 989969329
7206 5204 430773295
7206 2561 400440676
7206 438 351101488
7206 697 472399112
7206 7892 117298322
7206 874 453881598
7206 922 968...

output:

4001046006032
4258976116322
2844638548210
4967754235790
3378819833196
4681240881531
4038719341581
3107433975601
3912408002537
2749122423392
4166869349079
3107272808313
2644422821396
2943703753796
3629783905006
4831704396544
3894138787385
3466283555308
4421520552911
2771036472346
2917862734937
329705...

result:

ok 50000 numbers

Test #56:

score: 0
Accepted
time: 153ms
memory: 9196kb

input:

10000 50000
2580 6021 614466550
2580 4583 777657789
2580 3161 833727803
2580 2834 328252004
2580 1331 787627103
2580 3930 151198230
2580 6087 823201436
2580 8312 272364105
2580 770 567531957
2580 7614 752984578
2580 5108 478067218
2580 6941 663525018
2580 8201 682092335
2580 9026 339607749
2580 8996...

output:

224360729593
260892934055
220222546817
211674710221
285449665945
171628380116
229805733596
281299348871
269714675885
283144153682
198636422257
264040060770
262329564714
281814046797
258416536638
218077933331
193687323870
273949525319
209853625801
263583130390
216138052998
288796094453
253231267229
2...

result:

ok 50000 numbers

Test #57:

score: 0
Accepted
time: 93ms
memory: 9228kb

input:

10000 50000
3855 4266 562979915
3855 4589 100967567
3855 9098 885105780
3855 9252 539159996
3855 3861 94911923
3855 2405 419060938
3855 551 257272017
3855 7922 704501985
3855 2314 999257915
3855 8002 810561184
3855 2706 605032948
3855 9883 149618220
3855 2363 246886349
3855 3305 785142412
3855 9412 ...

output:

110895109384
105968771434
132235892029
89620816409
149673057506
145996354474
88575451816
96400801535
151595633108
91729941144
145891269549
102478250980
123701453840
142941338347
87494932578
115209130985
104806034861
148562132560
91902185778
114921648878
114146357059
103865421330
148685272330
1197895...

result:

ok 50000 numbers

Test #58:

score: 0
Accepted
time: 118ms
memory: 9036kb

input:

10000 50000
3769 6230 101427872
3769 5747 569501536
3769 6886 786740653
3769 4621 895292179
3769 4733 962005255
3769 7098 981890941
3769 2778 246632197
3769 314 546705273
3769 2658 136016576
3769 3806 17880893
3769 4170 731998678
3769 603 780935615
3769 6090 956904555
3769 9307 375901267
3769 6499 9...

output:

177882493998
194269842635
196682406657
215677216969
250467834428
192287251591
238717654159
241138530154
178044593472
207691007131
207531829827
254319955136
162351521910
242239618680
237750791610
215832988923
201472667867
247554897625
211686353269
231419814477
209263955151
197514960498
209191437074
2...

result:

ok 50000 numbers

Test #59:

score: 0
Accepted
time: 176ms
memory: 9324kb

input:

10000 50000
8811 3603 49941237
8811 5172 892811313
8811 2350 983342822
8811 7286 956457067
8811 430 829098586
8811 7511 104529457
8811 8218 680702777
8811 8931 978843153
8811 7813 567742534
8811 5183 75457499
8811 2232 858964408
8811 3495 972061521
8811 4702 521698569
8811 6584 821435931
8811 7012 2...

output:

965160661378
1047133751987
822562361171
875216829685
788251250010
852026495899
784335087031
814403602998
1090338743025
687137545225
751591383596
808915178746
708362988191
753712594156
813436368080
902661284442
944207836795
895421347659
782383664527
868239536855
961529232863
883881379836
928477309023...

result:

ok 50000 numbers

Test #60:

score: 0
Accepted
time: 176ms
memory: 9400kb

input:

10000 50000
211 23 390795006
23 130 951303855
211 83 421151186
23 210 189548305
130 38 390171179
210 106 936721214
130 158 915422479
106 243 978720111
210 290 374304038
243 80 223182104
158 352 581264506
352 60 787395660
158 322 75409533
80 11 792962911
83 215 867831888
11 263 305651916
243 332 7652...

output:

589641854146
836187321493
786328170047
740403092099
792139989921
620231879193
743589551484
566537152636
520876310491
659752633316
796950478628
834697647469
654776567086
653593833943
586244050665
629727516677
703433301582
751037402092
643126244987
730857318651
658337211357
660061714604
595812666518
8...

result:

ok 50000 numbers

Test #61:

score: 0
Accepted
time: 148ms
memory: 9712kb

input:

10000 50000
96 77 633866734
96 24 187335885
96 48 767640261
96 32 387826610
96 103 104938516
96 9 315731918
96 49 436443004
77 58 745327599
24 39 888949190
48 73 298420037
32 13 195591391
103 43 620115200
9 26 997352995
49 33 744089143
58 72 48597725
39 76 388938251
73 68 764220686
13 92 747959308
4...

output:

468286008262
371043410735
376882517605
419186537247
490268831044
377307115887
388772485629
465738095323
385089304909
468552312053
464393068075
388315162892
431003839040
465841636295
474727086222
456401912341
468767810720
411142539457
466904135997
381198946360
401085893124
484840259366
377297796552
3...

result:

ok 50000 numbers

Test #62:

score: 0
Accepted
time: 124ms
memory: 9532kb

input:

10000 50000
44 3 390878984
44 21 610378448
44 42 219037365
3 9 876160801
3 29 788839484
3 39 832298121
3 43 881360353
21 34 200638360
21 30 614553871
21 19 83825164
21 5 641236604
42 2 935971737
42 46 453805706
42 20 630763756
42 10 959937520
9 26 405099757
9 28 406427801
9 31 738784324
9 11 9023899...

output:

1541016104216
1616982779051
1750828015371
1642028638692
1009017246584
1126211185631
1366972251611
1507201707702
1078701061931
1727608467615
1112757161213
1279131921068
1145657525241
1815514325390
1742171167681
1307680185188
1048288940844
981546872463
1451770299936
1587500252231
1722746145834
1163524...

result:

ok 50000 numbers

Test #63:

score: 0
Accepted
time: 121ms
memory: 9940kb

input:

10000 50000
93 110 70604560
93 103 649600422
93 146 584541041
93 66 129505817
93 94 906776501
93 111 516612865
93 52 257525432
93 101 906290704
93 148 186678387
93 159 740081378
93 176 750435237
93 49 910928701
93 161 466181551
93 215 640645530
93 190 707187391
93 113 161122276
93 153 483662897
93 6...

output:

4470822017858
3608786932765
3838498529134
3480064254968
3617450399604
3762760854321
5247258049412
3534311337354
4677413908922
3422906001766
4061758488701
4263051817474
3227233090140
3726471865075
4439104363743
3223217552495
5129723825290
3448961524507
5244342097711
3501234824416
3076151939247
312096...

result:

ok 50000 numbers

Test #64:

score: 0
Accepted
time: 164ms
memory: 9324kb

input:

10000 50000
286 208 181486056
208 131 536565458
131 264 530802762
264 247 296672632
247 14 252325548
14 39 285812135
39 100 539809100
100 119 4449811
119 102 30246643
102 68 798706852
68 16 716973402
16 225 882801017
225 216 117143497
216 57 203235888
57 295 94548993
295 105 489368420
105 36 7231788...

output:

482569328915
564804799622
550190577621
473896319938
412924729149
474968106622
525455570340
477725170612
645559744181
489377674323
503468148680
551621055948
490014553008
545131730789
562342104750
618891079678
486432279866
486104194861
564667207700
504697484622
662322820271
626953740862
415147265782
4...

result:

ok 50000 numbers

Test #65:

score: 0
Accepted
time: 100ms
memory: 9740kb

input:

10000 50000
35 32 559540132
35 11 685717096
35 31 533526584
35 38 655144827
35 20 63053943
35 26 265550477
35 12 428150568
35 16 355059274
32 13 832496335
32 33 1235687
32 5 944934226
32 15 475871333
32 37 588595167
32 18 870454550
32 19 760978700
32 21 952642144
32 6 852766015
11 1 453097408
11 41 ...

output:

370335576423
476537835533
359471672305
477037362370
476998733698
391037894089
479044000003
479518271897
356813598766
357133476660
414990965774
370264963605
361043652821
476289532308
407397405069
406752062631
479544227139
431012701320
365558819492
478301493645
356999280624
516601948339
407128055275
3...

result:

ok 50000 numbers

Test #66:

score: 0
Accepted
time: 114ms
memory: 9160kb

input:

10000 50000
342 723 620404401
342 287 51551092
342 516 441982813
342 640 662818471
342 569 254430075
342 216 149955884
342 463 442993851
342 130 851038804
342 538 373857693
723 694 332101891
287 279 78741627
516 57 695017546
640 263 874896076
569 161 798438997
216 490 88650918
463 609 42802567
130 5...

output:

261050407377
245423585194
240040308045
251229505281
275665240707
255605576876
274987798498
343486392480
219216742602
253255225235
257468082524
266904133150
265198298604
254682578254
314563731512
300415149586
260335237326
242276767989
211954974132
305659801823
257462473564
192573616154
229074159622
2...

result:

ok 50000 numbers

Test #67:

score: 0
Accepted
time: 163ms
memory: 9380kb

input:

10000 50000
250 94 97734933
250 358 240801207
250 4 787722216
250 31 669113232
250 311 451048847
250 91 438430595
250 48 945947336
250 324 162739315
250 372 358925347
250 398 565443538
94 253 97541901
358 421 212717123
4 327 374369034
31 47 460017792
311 156 806470465
91 412 789430398
48 260 8837857...

output:

1243653176418
1154934267330
1122241158371
1054304565831
1076341383403
1444405964531
877970226969
1289979708352
1057528686920
1049835245030
1090589199732
1127515401241
958512357464
967452781727
1076167055049
1026536869606
1358444742932
1185662804277
1099314980354
1159263179881
1555733931994
897230082...

result:

ok 50000 numbers

Test #68:

score: 0
Accepted
time: 157ms
memory: 9380kb

input:

10000 50000
855 87 93904
87 803 147
803 741 83721
741 89 74098
89 558 93362
558 659 60420
659 95 73000
95 76 56097
76 796 53596
796 320 96186
320 642 17170
642 16 13666
16 413 40939
413 70 48208
70 618 86214
618 151 15458
151 464 85475
464 393 45316
393 279 36841
279 766 87378
766 354 71689
354 390 ...

output:

938071085710
920245375923
1054804887637
897507376907
965134567938
662940937079
743438919176
913962399335
883851937238
727758826587
701373211466
853398946109
951037560573
665499073349
931066896749
853606626993
853128665519
636254823723
1053926042333
884481901149
884573464233
737781118717
943596120691...

result:

ok 50000 numbers

Test #69:

score: 0
Accepted
time: 162ms
memory: 9432kb

input:

10000 50000
321 132 64232
321 423 533375
321 135 391170
321 427 530111
321 413 644246
132 69 172031
132 148 609869
132 300 72437
132 326 143589
132 256 190959
132 448 829453
423 68 542606
423 185 400818
423 246 415092
423 412 402777
423 5 583932
423 149 479279
135 491 270378
135 250 322589
135 481 3...

output:

404580974908
315684425841
267383711726
246569101667
263880485424
279724855388
232822183790
292074728452
315993948961
308003128420
284755591745
263964961827
317207981454
265698262275
294950811503
294609967551
291189579028
260516997843
266597502627
287488713740
250958496921
248929317041
286873591406
2...

result:

ok 50000 numbers

Test #70:

score: 0
Accepted
time: 131ms
memory: 9616kb

input:

10000 50000
427 419 8172385
419 225 2352916
225 428 3286933
428 171 3281026
171 232 3972157
232 258 464720
258 260 1074039
260 248 3709097
248 212 5860188
212 143 5413083
143 210 9450465
210 370 3144029
370 384 7340033
384 82 7160594
82 393 5807384
393 103 1145039
103 310 223762
310 168 7184282
168 ...

output:

300716064457
263746653484
309381702106
208038164796
264282149331
276824554406
265706397204
270991324461
261787739876
333095161436
219978233990
269417488594
207626784443
254702993572
257831832959
263574423285
285313804874
262840585062
264022453659
212857256779
254731481877
265973823124
321639784841
2...

result:

ok 50000 numbers

Test #71:

score: 0
Accepted
time: 124ms
memory: 9520kb

input:

10000 50000
221 287 58898116
287 66 39866883
66 4 50849513
4 312 29128250
312 235 45483986
235 313 67396496
313 296 71970744
296 322 11714283
322 101 71780336
101 90 7685340
90 39 33981277
39 61 11522100
61 113 85902629
113 6 68853213
6 185 19614630
185 317 10798822
317 286 99345835
286 323 41883871...

output:

494534664979
355858109036
478647453213
426123160535
468852239511
300792262653
477746847976
477721530847
430713812346
462548735353
325848745761
304783930246
471067496887
342017254866
322047372900
305900036685
368397627798
340236891882
467579786202
373181848244
387365191443
336442539885
314945870223
3...

result:

ok 50000 numbers

Test #72:

score: 0
Accepted
time: 151ms
memory: 9148kb

input:

10000 50000
44 54 822598084
44 18 210549215
44 73 994793843
44 30 83767256
44 53 957980873
54 24 856129873
54 26 917279013
54 67 569758048
54 75 160630524
54 76 778892930
54 23 386232264
18 34 387747758
18 5 665578303
18 58 963417254
18 37 288922568
18 69 388115855
18 64 767299626
73 57 444421060
73...

output:

270341665845
283828564772
283524756613
297403120538
172142468029
199357307228
204458392675
191446344777
215960366569
204372847455
204552533726
202443562526
207757774604
207616187357
282293192441
204395042882
202071891131
221358843115
234432787998
222268418441
199590595300
283188885459
286193363756
2...

result:

ok 50000 numbers

Test #73:

score: 0
Accepted
time: 145ms
memory: 9704kb

input:

10000 50000
99 122 597892528
99 38 307310100
99 70 400320923
99 228 318199083
99 286 998973890
99 325 766239532
99 231 829247168
99 178 376522190
99 65 284383151
99 120 813777797
99 94 277560373
99 366 855819559
99 19 198398148
99 313 963558354
99 167 451805980
99 6 725959948
99 278 677448468
99 131...

output:

554036772646
631538056251
684316510559
726913724378
631538195510
630310089217
617785238655
648578961555
663060866220
543081232914
675579578908
563314723206
657345861173
873997674484
659831327932
630202395172
631090335213
872633658338
631576939533
621097038260
798294279341
627633807414
631100641587
6...

result:

ok 50000 numbers

Test #74:

score: 0
Accepted
time: 129ms
memory: 9060kb

input:

10000 50000
2 104 542572706
2 98 747994510
2 180 560987118
2 210 297216259
2 226 279850936
2 4 455470692
2 88 467872151
2 36 764714746
2 240 706713025
2 254 266731593
2 72 102486737
2 43 850275188
2 148 223883211
2 221 184226015
2 70 990315612
2 111 969702422
2 146 558393189
2 211 766061037
2 236 41...

output:

134963797837
142515130539
141020444151
149177163763
151210757568
168684134969
134402783610
145597746962
142771870858
150304729804
149226048977
138570966712
132675048474
135344544945
154101028561
135188767074
148419208362
173548750092
130443544210
162485880989
158448443815
140882211054
120159555333
1...

result:

ok 50000 numbers

Test #75:

score: 0
Accepted
time: 152ms
memory: 9292kb

input:

10000 50000
945 305 959405331
945 436 797903772
436 273 585092426
273 793 845781379
305 170 588071487
793 215 976663713
273 44 711451821
215 859 511382678
215 919 82073458
305 631 685640280
631 683 943359549
631 369 351408127
170 534 654814085
44 483 354551261
919 884 671816124
170 623 207286993
369...

output:

386722187343
286348996118
541592585564
334433773061
436500081350
365293012451
420996786243
356415124780
357443396767
288443816342
323808284083
460196712780
360879547204
287772882290
388292232665
353327661103
328787517128
454780728636
353628286964
289085636551
458086148253
288141448051
286353634222
4...

result:

ok 50000 numbers

Test #76:

score: 0
Accepted
time: 3600ms
memory: 67532kb

input:

100000 500000
23248 76544 800459710
76544 34936 626830548
23248 67140 271833671
23248 30258 753101110
76544 19775 66610645
23248 59631 599390178
76544 52631 312020252
76544 38988 861581256
38988 96970 877780107
23248 92275 991057953
67140 79925 121756349
52631 8493 236423180
59631 78522 945105461
79...

output:

6245627757539
4992982221714
6191697260508
4867803356840
7309759154083
7004194856977
5545534305447
6177318197562
6926386832311
7077711020159
4043400569395
6532265272943
5274385346646
6140773706784
5494250529466
6225338874969
4810860044649
5860677671512
4011199141437
6841676526644
6879048327747
653383...

result:

ok 500000 numbers

Test #77:

score: 0
Accepted
time: 3590ms
memory: 65484kb

input:

100000 500000
34514 73827 32969987
73827 46381 85892521
34514 81124 550393052
46381 95116 126520896
73827 87339 820688267
46381 18023 130764123
95116 43904 43915665
87339 4751 231260224
18023 7718 477247663
4751 27969 128750603
18023 90398 173941674
7718 25867 262062874
4751 11814 231213135
43904 47...

output:

49965422247
48601890677
49313514594
53431106979
53434202457
49698775616
45923992100
53266177736
53268385751
46936839361
52569922868
50855722121
56036975609
55497773103
49368267919
51260567098
51892132514
46663500730
48049163448
52018223903
50558783410
49703839435
53404408114
49192016351
56035205349
...

result:

ok 500000 numbers

Test #78:

score: 0
Accepted
time: 3610ms
memory: 67828kb

input:

100000 500000
26096 43836 143794311
43836 28627 535370694
28627 72619 35993727
72619 15469 793591901
15469 92738 630053442
92738 53699 97216072
53699 31583 759774783
31583 64395 425463071
64395 61883 730137593
61883 52951 816872310
52951 50206 852925671
50206 50401 296920163
50401 56207 665843098
56...

output:

21368463569514
35416404026240
30972645177722
33442928736924
25733976266882
23798828702659
37410570997782
31713336808997
21883620437716
20234754936849
30072696403634
27188548930047
28503735323212
32588075660304
30213680704904
33847128541647
31375139046161
27535181572135
29463690638237
21244936676068
...

result:

ok 500000 numbers

Test #79:

score: 0
Accepted
time: 3521ms
memory: 69640kb

input:

100000 500000
40981 48673 429022710
48673 28249 248832919
28249 73547 64778901
73547 97176 819935593
97176 49924 396631606
49924 28358 770640042
28358 28047 345120809
28047 87738 344522640
87738 63031 777714968
63031 2115 803507219
2115 59645 10281378
59645 21873 822549659
21873 52725 979982890
5272...

output:

70638705282798
76323963281889
73079995654706
67186799417867
76559942910907
70836740001063
85276957229472
82355538404797
72912377148347
74442479490800
81911033413367
75184225656784
77105096805823
77050701474171
72521988401663
76497795027185
73007338242199
65651486857279
83356800836762
61837892694755
...

result:

ok 500000 numbers

Test #80:

score: 0
Accepted
time: 2205ms
memory: 64868kb

input:

100000 500000
93426 14362 934960334
93426 78209 599135159
93426 12772 256577201
93426 11475 339852998
93426 64958 580116850
14362 42767 219247196
14362 41041 14833512
14362 51971 896204777
14362 17307 648310723
14362 84591 570510771
14362 54580 337593368
78209 20156 21196282
78209 23648 291782684
78...

output:

23346739101
22413147920
20834670722
22631938061
22221254891
20834633096
21254370364
21650944671
18877481529
19938219021
23064600840
21602523393
23134614880
22589308392
22744208336
22088617880
18946990899
21885530944
22030146056
21049448306
20409632986
23806846401
20923751588
21343580066
20819647609
...

result:

ok 500000 numbers

Test #81:

score: 0
Accepted
time: 363ms
memory: 64168kb

input:

100000 500000
33204 25284 51624740
33204 60757 642003654
33204 71281 758700135
33204 40723 309765983
33204 20976 733795629
33204 12086 989944499
33204 29891 886754801
33204 7320 326719235
33204 82977 370691700
33204 41761 530122266
33204 41233 64006936
33204 84945 817288386
33204 97901 806486894
332...

output:

2728706521
2882455585
3084222970
2502957333
2715789937
2938307328
3290112136
3405707982
2727245615
3265339580
2937860569
3552694886
2799622498
3023788426
3444938863
2793206558
2990061639
3008303512
2832510592
3102565155
2780358177
2629733570
3294327235
3726670981
3174925281
2457034707
3204101594
308...

result:

ok 500000 numbers

Test #82:

score: 0
Accepted
time: 1824ms
memory: 63236kb

input:

100000 500000
84315 87586 898397534
84315 15456 105660752
84315 28277 409456986
84315 90043 552120745
84315 12291 394564024
84315 45814 952539093
84315 35503 875366589
84315 2749 447084323
84315 49098 745946142
84315 30423 445645524
84315 2799 226982614
84315 25959 442094097
84315 49293 172595770
84...

output:

1281337877645
1062719835259
932578301381
1344231918119
1308590616542
878581479242
1393736500159
1154181783825
1323608718415
879909225509
1067641220325
1046325000476
1378023045063
1233315234065
909984612606
1214962966959
1399842167071
1354180116343
899410320872
1080739749339
1180066507626
13097477919...

result:

ok 500000 numbers

Test #83:

score: 0
Accepted
time: 2570ms
memory: 63824kb

input:

100000 500000
583 448 481555229
448 2022 179389261
2022 2354 434676908
2354 161 552350333
161 1196 248443955
1196 1303 999412260
1303 2145 883072167
2145 2494 955993073
2494 1329 92688416
1329 355 909637211
355 2386 529213680
2386 2807 308477908
2807 67 519741942
67 2052 735314750
2052 459 679616563...

output:

6589843731779
6869143831138
6134716025889
7753075398542
7577524147526
6983470838270
7226274038430
6467747157805
7705176875227
8142313086916
8767833094107
6548245565406
7235457026023
8515061575563
5952801428222
7812453602597
7990440189428
8208393100414
7670324129577
8580497326633
7263822654146
717494...

result:

ok 500000 numbers

Test #84:

score: 0
Accepted
time: 2955ms
memory: 64012kb

input:

100000 500000
3732 1778 5514
1778 2240 5013
2240 3635 1567
3635 1090 2267
1090 3160 1992
3160 2403 6768
2403 1169 9711
1169 4989 8821
4989 4347 1249
4347 4913 7619
4913 968 7960
968 1964 834
1964 2379 9215
2379 1462 5290
1462 2398 3778
2398 5244 8186
5244 622 2885
622 1970 1240
1970 5376 119
5376 31...

output:

4683517194310
3106746316388
5273372896450
3936594245102
3852386303435
3537757796907
3572565146610
3537182643061
4351144987931
4239289095527
4313962792810
3845817711541
3169560509511
5012019890213
5241054943392
4683897632118
5285833492264
5001229009462
3445404532265
4572042558674
5088499982627
311089...

result:

ok 500000 numbers

Test #85:

score: 0
Accepted
time: 1932ms
memory: 66352kb

input:

100000 500000
4451 4057 74083
4451 1865 53455
4451 1910 404
1865 1071 52116
1865 3512 8757
1071 2897 41357
2897 218 51006
2897 1727 34623
2897 1734 84287
218 4797 76805
4797 527 90692
527 1862 10735
4797 720 99065
527 4474 90022
1862 2341 50960
4474 3534 39251
4474 1530 36641
1530 2082 57825
1530 39...

output:

7657046699705
3866513392335
4475055067945
5059648344131
3970081812967
4355958258009
4475005704352
7131379798634
4052742623059
4289318972062
6006356785834
7383727726271
6755820747599
7383453420386
4152817864210
3856264187416
7382922157992
6395617651827
7383184497118
3897266216825
3973503171715
527947...

result:

ok 500000 numbers

Test #86:

score: 0
Accepted
time: 2475ms
memory: 67928kb

input:

100000 500000
1691 2348 441434
2348 5743 392326
5743 627 881435
1691 4458 470810
627 4562 581498
627 508 37282
4458 2176 151813
4458 3341 604942
3341 3301 906802
2176 5128 221861
2176 3966 972871
5128 4590 579844
3966 2187 116092
2187 1884 870823
4590 4664 863390
4664 415 209191
2187 1777 63349
1884...

output:

7830651055669
8856079531373
8284838884766
7710732794466
8829564783388
7493895665113
7985566582918
8824002856218
8835000461688
6595253523788
5492255947234
6590228169725
8824670940452
5219472034516
9030612101415
8818576328617
9256113405657
8826743686392
9329706643362
6610794136377
6176764501355
901510...

result:

ok 500000 numbers

Test #87:

score: 0
Accepted
time: 2477ms
memory: 66436kb

input:

100000 500000
320 360 9465757
360 53 3640055
53 91 560971
91 184 7162361
184 31 8302308
31 57 5642330
57 95 8090566
95 121 5659053
121 148 3141692
148 107 3756030
107 516 9340524
516 212 7984367
212 419 3325460
419 5 2859139
5 398 3688053
398 245 6637113
245 429 4746638
429 64 1010396
64 480 7481101...

output:

3001213584831
3288309062876
3049748507393
3775982664527
2338356177529
3063633563716
3153492006294
3079059387668
3844456350224
3440497485560
3049840624455
3176405035704
3027414438171
3139970942924
3138727611650
3010234915647
3195930227968
3005920442784
3188860322646
3005997579765
3689721331488
304912...

result:

ok 500000 numbers

Test #88:

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

input:

100000 500000
248 523 66740320
523 448 66155835
448 416 73273404
416 319 3184885
319 195 70749000
195 304 76781857
304 219 19145786
219 288 91801140
288 391 99681684
391 73 73374549
73 550 27074619
550 115 21289483
115 128 54608713
128 273 58346806
273 443 60952609
443 394 94991683
394 122 89085380
...

output:

3574022756804
3570615091375
4478808414066
3555982521916
4463476185090
3605996577127
4432106013006
3893548051239
3862993798074
4260368582664
4828013900231
3554562497393
3563008888496
3575302898281
3785851389418
3776060260708
3591184539846
5500715735932
3319397576202
3783306937107
4941736052884
382010...

result:

ok 500000 numbers

Test #89:

score: 0
Accepted
time: 2296ms
memory: 67888kb

input:

100000 500000
1547 2182 491396871
2182 1005 150469262
1005 1961 759150025
1961 1201 848257889
1201 1462 728478499
1462 1288 242945783
1288 745 882438614
745 138 728282831
138 1380 374749026
1380 1240 249724340
1240 1033 469972082
1033 566 751775571
566 124 650832025
124 2055 300789518
2055 1285 9573...

output:

4143836723175
4319482702517
4220343634651
4315690747746
4368308938192
4167037495916
4138478356845
4237052311675
4163601575323
4204946236570
4289647589459
4211841987498
5683794888763
4068010017353
7038517898394
4806204613008
4382984224541
4350814717903
4340624217382
4239506426040
4244037680704
417894...

result:

ok 500000 numbers

Test #90:

score: 0
Accepted
time: 2621ms
memory: 65524kb

input:

100000 500000
7 239 108469593
7 54 99693654
7 223 873343385
7 204 46174590
7 81 79899548
7 448 318676908
7 337 708957756
7 785 837799613
7 234 456209530
239 574 503772260
54 473 569658345
223 45 786028331
204 790 681272141
81 511 665489335
448 79 911193470
337 178 885784143
785 411 947151506
234 724...

output:

3735032189338
2539376307259
3135087823667
2628961197236
2606540251597
2618104477210
2616377871238
2564357939434
3230281445615
2601342556361
3135475438637
2723192077778
2557185330438
3579694369669
3473257682023
2668105240265
2647641245987
3135374516900
2642428365812
2619214101458
2861849842371
270523...

result:

ok 500000 numbers

Test #91:

score: 0
Accepted
time: 2241ms
memory: 65320kb

input:

100000 500000
690 1249 523053069
690 858 10847965
690 37 39560556
690 545 69207445
690 455 733209568
690 1752 22645839
690 499 866301891
690 1822 415276666
1249 1656 69741937
1249 58 896143800
1249 1437 934180855
1249 913 26765744
1249 804 616115977
1249 1807 910841122
1249 145 516571193
1249 318 84...

output:

3474759454916
3590667493155
3736505985605
3635210857045
4091452547733
3426378404308
3816562876175
3516385056195
3723026410659
3490821989007
5630498814550
4227042443801
3802121101047
3502545395014
3499630028484
3603064266437
3457532273027
4733878197796
3681186356936
3586089094667
3500708708214
351703...

result:

ok 500000 numbers

Test #92:

score: 0
Accepted
time: 2194ms
memory: 67416kb

input:

100000 500000
2780 719 739708309
719 3748 301354142
719 4573 695653142
3748 6572 560059942
3748 2828 868776871
4573 3881 77863223
4573 583 531423324
6572 3665 419404547
6572 6272 556773075
2828 1864 78810411
2828 1164 865780429
3881 4703 913166710
3881 4270 567132415
583 3736 201074877
583 6331 1033...

output:

3990191143311
4861352183600
3961036908180
3980476414435
4063653395112
3960571455121
3959015905027
3953609703731
3991349793174
3978207525064
3949752765590
3932871253924
3972553049773
3963775311043
3980662901929
3951289485157
3622212558361
3957487114361
3934617253091
3977751298911
3958172549071
395457...

result:

ok 500000 numbers

Test #93:

score: 0
Accepted
time: 2729ms
memory: 65888kb

input:

100000 500000
132 300 920401466
300 80 935115337
80 122 914151038
122 308 876430264
308 186 398223114
186 283 680790206
283 103 285804286
103 218 363299873
218 14 414291124
14 39 622707629
39 173 516206957
173 182 823442045
182 292 378799404
292 206 437500792
206 257 482697954
257 158 992972830
158 ...

output:

7954672418645
7504705757140
5894029682838
5476396270774
5570807601925
7240191395647
7927607780494
8348114107114
6449893142099
8189612090098
5866424828695
8344381657294
7168755834047
4951748719674
5095841967964
8056887150959
7699703216874
7970745695343
8034151944511
8045319760846
8118294744953
805342...

result:

ok 500000 numbers