// line 1 "answer.cpp" #if !__INCLUDE_LEVEL__ #include __FILE__ int main() { ll n; input(n); vi from(n-1), to(n-1), cost(n-1, 0); rep(i, n-1) input(from[i], to[i]); --from; --to; Graph g(n, from, to, cost, true); lseg_add_radd seg(n); HeavyLightDecomposition hld(g, seg, false); ll q; input(q); ll ans = 0; rep(q) { ll u,v; input(u,v); --u; --v; hld.apply(u,v,1); ans += hld.prod(u,v).value; } print(ans); } #else // line 2 "/home/seekworser/.cpp_lib/competitive_library/competitive/std/std.hpp" #include #ifndef LOCAL_TEST #pragma GCC target ("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #endif // LOCAL_TEST using namespace std; // 型名の短縮 using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vvi = vector; using vvvi = vector; using vl = vector; using vvl = vector; using vvvl = vector; using vb = vector; using vvb = vector; using vvvb = vector; using vc = vector; using vvc = vector; using vvvc = vector; using vd = vector; using vvd = vector; using vvvd = vector; using vs = vector; using vvs = vector>; using vvvs = vector>>; template vector> vv(int h, int w, T val = T()) { return vector(h, vector(w, val)); } template vector>> vvv(int h1, int h2, int h3, T val = T()) { return vector(h1, vector(h2, vector(h3, val))); } template vector>>> vvvv(int h1, int h2, int h3, int h4, T val = T()) { return vector(h1, vector(h2, vector(h3, vector(h4, val)))); } template using priority_queue_min = priority_queue, greater>; // 定数の定義 constexpr double PI = 3.14159265358979323; constexpr int INF = 100100111; constexpr ll INFL = 3300300300300300491LL; float EPS = 1e-8; double EPSL = 1e-16; template bool eq(const T x, const T y) { return x == y; } template<> bool eq(const double x, const double y) { return abs(x - y) < EPSL; } template<> bool eq(const float x, const float y) { return abs(x - y) < EPS; } template bool neq(const T x, const T y) { return !(eq(x, y)); } template bool ge(const T x, const T y) { return (eq(x, y) || (x > y)); } template bool le(const T x, const T y) { return (eq(x, y) || (x < y)); } template bool gt(const T x, const T y) { return !(le(x, y)); } template bool lt(const T x, const T y) { return !(ge(x, y)); } constexpr int MODINT998244353 = 998244353; constexpr int MODINT1000000007 = 1000000007; // 入出力高速化 struct Nyan { Nyan() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } nyan; // 汎用マクロの定義 #define all(a) (a).begin(), (a).end() #define sz(x) ((ll)(x).size()) #define rep1(n) for(ll dummy_iter = 0LL; dummy_iter < n; ++dummy_iter) // 0 から n-1 まで昇順 #define rep2(i, n) for(ll i = 0LL, i##_counter = 0LL; i##_counter < ll(n); ++(i##_counter), (i) = i##_counter) // 0 から n-1 まで昇順 #define rep3(i, s, t) for(ll i = ll(s), i##_counter = ll(s); i##_counter < ll(t); ++(i##_counter), (i) = (i##_counter)) // s から t まで昇順 #define rep4(i, s, t, step) for(ll i##_counter = step > 0 ? ll(s) : -ll(s), i##_end = step > 0 ? ll(t) : -ll(t), i##_step = abs(step), i = ll(s); i##_counter < i##_end; i##_counter += i##_step, i = step > 0 ? i##_counter : -i##_counter) // s から t まで stepずつ #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define repe(a, v) for(auto& a : (v)) // v の全要素(変更可能) #define smod(n, m) ((((n) % (m)) + (m)) % (m)) // 非負mod #define sdiv(n, m) (((n) - smod(n, m)) / (m)) // 非負div #define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去 void Yes(bool b) { cout << (b ? "Yes\n" : "No\n"); return; }; void YES(bool b) { cout << (b ? "YES\n" : "NO\n"); return; }; template T max(array& a) { return *max_element(all(a)); }; template T min(array& a) { return *min_element(all(a)); }; template T max(vector& a) { return *max_element(all(a)); }; template T min(vector& a) { return *min_element(all(a)); }; template vector vec_slice(const vector& a, int l, int r) { vector rev; rep(i, l, r) rev.push_back(a[i]); return rev; }; template T sum(vector& a, T zero = T(0)) { T rev = zero; rep(i, sz(a)) rev += a[i]; return rev; }; template bool in_range(const T& val, const T& s, const T& t) { return s <= val && val < t; }; template inline vector& operator--(vector& v) { repe(x, v) --x; return v; } template inline vector& operator++(vector& v) { repe(x, v) ++x; return v; } // modでのpow ll powm(ll a, ll n, ll mod=INFL) { ll res = 1; while (n > 0) { if (n & 1) res = (res * a) % mod; if (n > 1) a = (a * a) % mod; n >>= 1; } return res; } // 整数Sqrt ll sqrtll(ll x) { assert(x >= 0); ll rev = sqrt(x); while(rev * rev > x) --rev; while((rev+1) * (rev+1)<=x) ++rev; return rev; } template inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新(更新されたら true を返す) template inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新(更新されたら true を返す) int digit(ll x, int d=10) { int rev=0; while (x > 0) { rev++; x /= d;}; return rev; } // xのd進数桁数 /** * @brief std.hpp * @docs docs/std/std.md */ // line 3 "/home/seekworser/.cpp_lib/competitive_library/competitive/graph/graph.hpp" template struct Graph{ public: struct Edge { int to; Cost cost; Edge() {}; Edge(int _to, Cost _cost) : to(_to), cost(_cost) {}; }; struct AdjacencyListRange{ using iterator = typename std::vector::const_iterator; iterator begi, endi; iterator begin() const { return begi; } iterator end() const { return endi; } int size() const { return (int)distance(begi, endi); } const Edge& operator[](int i) const { return begi[i]; } }; private: public: vector E; vector I; int n; Graph() : n(0) {} Graph(int _n) : n(_n) {} Graph(int _n, const vector& from, vector& to, vector& cost, bool rev = false) : n(_n) { vector buf(n+1, 0); for(int i=0; i<(int)from.size(); i++){ ++buf[from[i]]; if (rev) ++buf[to[i]]; } for(int i=1; i<=_n; i++) buf[i] += buf[i-1]; E.resize(buf[n]); for(int i=(int)from.size()-1; i>=0; i--){ int u = from[i]; int v = to[i]; Cost c = cost[i]; E[--buf[u]] = Edge(v, c); if(rev) E[--buf[v]] = Edge(u, c); } I = move(buf); } AdjacencyListRange operator[](int u) const { return AdjacencyListRange{ E.begin() + I[u], E.begin() + I[u+1] }; } int num_vertices() const { return n; } int size() const { return num_vertices(); } int num_edges() const { return E.size(); } Graph reversed_edges() const { Graph res; int _n = res.n = n; vi buf(n+1, 0); for(auto v : E) ++buf[v.to]; for(int i=1; i<=n; i++) buf[i] += buf[i-1]; res.E.resize(buf[n]); for(int u=0; u ostream& operator<<(ostream& os, Graph g) { bool first = true; rep(i, g.n) repe(e, g[i]) { if (first) first = false; else os << endl; os << i << "->" << e.to << ": " << e.cost; } return os; } /** * @brief graph.hpp * @docs docs/graph/graph.md */ // line 5 "/home/seekworser/.cpp_lib/competitive_library/atcoder/segtree.hpp" // line 2 "/home/seekworser/.cpp_lib/competitive_library/atcoder/internal_bit.hpp" #ifdef _MSC_VER #include #endif namespace atcoder { namespace internal { // @param n `0 <= n` // @return minimum non-negative `x` s.t. `n <= 2**x` int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } // @param n `1 <= n` // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0` constexpr int bsf_constexpr(unsigned int n) { int x = 0; while (!(n & (1 << x))) x++; return x; } // @param n `1 <= n` // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0` int bsf(unsigned int n) { #ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index; #else return __builtin_ctz(n); #endif } } // namespace internal } // namespace atcoder // line 7 "/home/seekworser/.cpp_lib/competitive_library/atcoder/segtree.hpp" namespace atcoder { template struct segtree { public: S (*op)(S, S) = _op; S (*e)() = _e; segtree() : segtree(0) {} explicit segtree(const std::vector& v) : _n(int(v.size())) { log = internal::ceil_pow2(_n); size = 1 << log; d = std::vector(2 * size, e()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } explicit segtree(int n) : segtree(std::vector(n, _e())) {} void set(int p, S x) { assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } void add(int p, S x) { assert(0 <= p && p < _n); (*this).set(p, (*this).get(p) + x); } S get(int p) const { assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r) const { assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size; while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() const { return d[1]; } template int max_right(int l) const { return max_right(l, [](S x) { return f(x); }); } template int max_right(int l, F f) const { assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template int min_left(int r) const { return min_left(r, [](S x) { return f(x); }); } template int min_left(int r, F f) const { assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } int n() const {return (*this)._n;} private: int _n, size, log; std::vector d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; } // namespace atcoder // line 4 "/home/seekworser/.cpp_lib/competitive_library/competitive/data_structure/segtree.hpp" template std::ostream& operator<<(std::ostream& os, const atcoder::segtree seg) { int n = seg.n(); rep(i, n) { os << seg.get(i); if (i != n-1) os << " "; } return os; }; namespace segtree { template T op_max(T x, T y) { return x > y? x : y; } template T op_min(T x, T y) { return x < y? x : y; } template T op_add(T x, T y) { return x + y; } int e_max() { return -INF; } template T e_max() { return -INFL; } int e_min() { return INF; } template T e_min() { return INFL; } template T e_add() { return 0; } } template using seg_add = atcoder::segtree; template using seg_max = atcoder::segtree; template using seg_min = atcoder::segtree; /** * @brief セグメント木(ラッパー) * @docs docs/data_structure/segtree.md */ // line 6 "/home/seekworser/.cpp_lib/competitive_library/atcoder/lazysegtree.hpp" // line 8 "/home/seekworser/.cpp_lib/competitive_library/atcoder/lazysegtree.hpp" namespace atcoder { template struct lazy_segtree { public: S (*op)(S, S) = _op; S (*e)() = _e; S (*mapping)(F, S) = _mapping; F (*composition)(F, F) = _composition; F (*id)() = _id; lazy_segtree() : lazy_segtree(0) {} explicit lazy_segtree(int n) : lazy_segtree(std::vector(n, _e())) {} explicit lazy_segtree(const std::vector& v) : _n(int(v.size())) { log = internal::ceil_pow2(_n); size = 1 << log; d = std::vector(2 * size, e()); lz = std::vector(size, id()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } void add(int p, S x) { assert(0 <= p && p < _n); (*this).set(p, (*this).get(p) + x); } S get(int p) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); return d[p]; } S prod(int l, int r) { assert(0 <= l && l <= r && r <= _n); if (l == r) return e(); l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } S sml = e(), smr = e(); while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } void apply(int p, F f) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = mapping(f, d[p]); for (int i = 1; i <= log; i++) update(p >> i); } void apply(int l, int r, F f) { assert(0 <= l && l <= r && r <= _n); if (l == r) return; l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } template int max_right(int l) { return max_right(l, [](S x) { return g(x); }); } template int max_right(int l, G g) { assert(0 <= l && l <= _n); assert(g(e())); if (l == _n) return _n; l += size; for (int i = log; i >= 1; i--) push(l >> i); S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, d[l]))) { while (l < size) { push(l); l = (2 * l); if (g(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template int min_left(int r) { return min_left(r, [](S x) { return g(x); }); } template int min_left(int r, G g) { assert(0 <= r && r <= _n); assert(g(e())); if (r == 0) return 0; r += size; for (int i = log; i >= 1; i--) push((r - 1) >> i); S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!g(op(d[r], sm))) { while (r < size) { push(r); r = (2 * r + 1); if (g(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } int n() {return (*this)._n;} private: int _n, size, log; std::vector d; std::vector lz; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } void all_apply(int k, F f) { d[k] = mapping(f, d[k]); if (k < size) lz[k] = composition(f, lz[k]); } void push(int k) { all_apply(2 * k, lz[k]); all_apply(2 * k + 1, lz[k]); lz[k] = id(); } }; } // namespace atcoder // line 4 "/home/seekworser/.cpp_lib/competitive_library/competitive/data_structure/lazysegtree.hpp" template std::ostream& operator<<(std::ostream& os, atcoder::lazy_segtree seg) { int n = seg.n(); rep(i, n) { os << seg.get(i); if (i != n-1) os << " "; } return os; }; namespace lsegtree { template struct AddNode { T value; ll size; AddNode() : value(T(0)), size(1) {}; AddNode(T value, ll size) : value(value), size(size) {}; friend ostream& operator<<(std::ostream& os, const AddNode &n) { os << n.value; return os; }; }; int e_max() { return -INF; } template T e_max() { return -INFL; } int e_min() { return INF; } template T e_min() { return INFL; } template AddNode e_add() { return {0, 1}; } template T op_max(T x, T y) { return x > y ? x : y; } template T op_min(T x, T y) { return x < y ? x : y; } template AddNode op_add(AddNode x, AddNode y) { return {x.value + y.value, x.size + y.size}; } template T id_radd(){ return 0; } int id_rupdate(){ return INF; } template T id_rupdate(){ return INFL; } template AddNode mapping_add_radd(T f, AddNode x){ return {x.value + f * x.size, x.size}; } template AddNode mapping_add_rupdate(T f, AddNode x){ AddNode rev = AddNode(x); if(f != id_rupdate()) rev.value = f * rev.size; return rev; } template T mapping_radd(T f, T x){ return f+x; } template T mapping_rupdate(T f, T x){ return (f == id_rupdate() ? x : f); } template T composition_radd(T f, T g){ return f+g; } template T composition_rupdate(T f, T g){ return (f == id_rupdate() ? g : f); } } template using lseg_add_radd = atcoder::lazy_segtree, lsegtree::op_add, lsegtree::e_add, T, lsegtree::mapping_add_radd, lsegtree::composition_radd, lsegtree::id_radd>; template using lseg_min_radd = atcoder::lazy_segtree; template using lseg_max_radd = atcoder::lazy_segtree; template using lseg_add_rupdate = atcoder::lazy_segtree, lsegtree::op_add, lsegtree::e_add, T, lsegtree::mapping_add_rupdate, lsegtree::composition_rupdate, lsegtree::id_rupdate>; template using lseg_min_rupdate = atcoder::lazy_segtree; template using lseg_max_rupdate = atcoder::lazy_segtree; /** * @brief 遅延セグメント木(ラッパー) * @docs docs/data_structure/lazysegtree.md */ // line 6 "/home/seekworser/.cpp_lib/competitive_library/competitive/tree/heavy_light_decomposition.hpp" template struct HeavyLightDecomposition { vi heavy_edge,in,out,head,par,pos; Seg &seg; bool edge; HeavyLightDecomposition(Graph& g, Seg& seg, bool edge = true) : heavy_edge(g.n), in(g.n), out(g.n), head(g.n), par(g.n), pos(g.n), seg(seg), edge(edge) { build(g); } void build(Graph& g) { vi subtree_size(g.n, 0); auto dfs_sz = [&] (auto self, int x, int p) -> int { par[x] = p; subtree_size[x] = 1; repe(e, g[x]) { if (e.to == p) continue; subtree_size[x] += self(self, e.to, x); } int maxs = -INF; heavy_edge[x] = -1; repe(e, g[x]) { if (e.to == p) continue; if (chmax(maxs, subtree_size[e.to])) heavy_edge[x] = e.to; } return subtree_size[x]; }; dfs_sz(dfs_sz, 0, -1); int t = 0; auto dfs_hld = [&] (auto self, int x, int par) -> void { in[x] = t++; pos[in[x]] = x; if (heavy_edge[x] != -1) { head[heavy_edge[x]] = head[x]; self(self, heavy_edge[x], x); } repe(e, g[x]) { if (e.to == par || e.to == heavy_edge[x]) continue; head[e.to] = e.to; self(self, e.to, x); } out[x] = t; }; dfs_hld(dfs_hld, 0, -1); } int lca(int u, int v) { while (head[u] != head[v]) { if (in[u] > in[v]) swap(u, v); v = par[head[v]]; } return in[u] < in[v] ? u : v; } int la(int u, int k) { while (true) { if (u == -1) return -1; if (u == 0 && k > 0) return -1; int v = head[u]; if (in[u] - k >= in[v]) return pos[in[u] - k]; k -= in[u] - in[v] + 1; u = par[head[u]]; } } decltype(seg.e()) prod(int u, int v) { using T = decltype(seg.e()); T l = seg.e(); T r = seg.e(); while (head[u] != head[v]) { if (in[u] > in[v]) swap(u, v), swap(l, r); l = seg.op(seg.prod(in[head[v]], in[v] + 1), l); v = par[head[v]]; } if (in[u] > in[v]) swap(u, v), swap(l, r); // パスクエリの場合はu(uからuの親へのパス)は足さない return seg.op(seg.op(seg.prod(in[u] + edge, in[v] + 1), l) , r); } void apply(int u, int v, decltype(seg.id()) f) { while (head[u] != head[v]) { if (in[u] > in[v]) swap(u, v); seg.apply(in[head[v]], in[v] + 1, f); v = par[head[v]]; } if (in[u] > in[v]) swap(u, v); seg.apply(in[u] + edge, in[v] + 1, f); } int edge_pos(int u, int v) { if (par[u] != v) swap(u, v); assert(par[u] == v); return in[u]; } }; /** * @brief HL分解 (Heavy Light Decomposition) * @docs docs/tree/heavy_light_decomposition.md */ // line 3 "/home/seekworser/.cpp_lib/competitive_library/competitive/std/io.hpp" // 演算子オーバーロード(プロトタイプ宣言) template inline istream& operator>>(istream& is, pair& p); template inline istream& operator>>(istream& is, vector& v); template inline ostream& operator<<(ostream& os, const pair& p); template inline ostream& operator<<(ostream& os, const vector& v); template ostream &operator<<(ostream &os, const map &mp); template ostream &operator<<(ostream &os, const set &st); template ostream &operator<<(ostream &os, const multiset &st); template ostream &operator<<(ostream &os, const unordered_set &st); template ostream &operator<<(ostream &os, queue q); template ostream &operator<<(ostream &os, deque q); template ostream &operator<<(ostream &os, stack st); template ostream &operator<<(ostream &os, priority_queue pq); // 演算子オーバーロード template inline istream& operator>>(istream& is, pair& p) { is >> p.first >> p.second; return is; } template inline istream& operator>>(istream& is, vector& v) { repe(x, v) is >> x; return is; } template inline ostream& operator<<(ostream& os, const pair& p) { os << p.first << " " << p.second; return os; } template inline ostream& operator<<(ostream& os, const vector& v) { rep(i, sz(v)) { os << v.at(i); if (i != sz(v) - 1) os << " "; } return os; } template ostream &operator<<(ostream &os, const map &mp) { for (auto &[key, val] : mp) { os << key << ":" << val << " "; } return os; } template ostream &operator<<(ostream &os, const set &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, const multiset &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, const unordered_set &st) { ll cnt = 0; for (auto &e : st) { os << e << (++cnt != (int)st.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, queue q) { while (q.size()) { os << q.front() << " "; q.pop(); } return os; } template ostream &operator<<(ostream &os, deque q) { while (q.size()) { os << q.front() << " "; q.pop_front(); } return os; } template ostream &operator<<(ostream &os, stack st) { while (st.size()) { os << st.top() << " "; st.pop(); } return os; } template ostream &operator<<(ostream &os, priority_queue pq) { while (pq.size()) { os << pq.top() << " "; pq.pop(); } return os; } template void print_sep_end(string sep, string end, const T& val) { (void)sep; cout << val << end; }; template void print_sep_end(string sep, string end, const T1 &val, const T2 &...remain) { cout << val << sep; print_sep_end(sep, end, remain...); }; template void print(const T &...args) { print_sep_end(" ", "\n", args...); }; template void flush() { cout << flush; }; template void print_and_flush(const T &...args) { print(args...); flush(); }; #define debug(...) debug_func(0, #__VA_ARGS__, __VA_ARGS__) // debug print template void input(T &a) { cin >> a; }; template void input(T1&a, T2 &...b) { cin >> a; input(b...); }; #ifdef LOCAL_TEST template void debug_func(int i, T name) { (void)i; (void)name; cerr << endl; } template void debug_func(int i, const T1 &name, const T2 &a, const T3 &...b) { int scope = 0; for ( ; (scope != 0 || name[i] != ',') && name[i] != '\0'; i++ ) { cerr << name[i]; if (name[i] == '(' || name[i] == '{') scope++; if (name[i] == ')' || name[i] == '}') scope--; } cerr << ":" << a << " "; debug_func(i + 1, name, b...); } #endif #ifndef LOCAL_TEST template void debug_func(const T &...) {} #endif /** * @brief io.hpp * @docs docs/std/io.md */ // line 28 "answer.cpp" #endif