// Library reference: https://github.com/Luke256/cp-template // meow (^・ω・^) #include #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define rep(i, n) for (ll i = 0; i < (n); ++i) #define ALL(x) x.begin(), x.end() #define BACK(x) x.rbegin(), x.rend() #define MOD1 1000000007 #define MOD1_BASE 131 #define MOD2 998244353 #define INF (LLONG_MAX / 2) #define FLOAT_ANS fixed << setprecision(20) #define TORAD(x) (x * acosl(-1) / 180.0) #define TODEG(x) (x * 180.0 / acosl(-1)) using namespace std; using ll = long long; using LL = __int128_t; using ull = unsigned long long; using ld = long double; template concept ArrayLike = requires(const T& x, size_t i, size_t j) { { ranges::size(x) } -> convertible_to; { x[i] == x[j] } -> convertible_to; }; template concept ArrayLikeT = ArrayLike && is_same_v, U>; template using p_que = priority_queue, greater>; struct Condition { bool state; constexpr Condition(bool v) noexcept : state(v) {} constexpr explicit operator bool() const { return state; } template constexpr Condition then(F&& func) const noexcept(is_nothrow_invocable_v) { if (state) { invoke(forward(func)); } return *this; } template constexpr Condition otherwise(F&& func) const noexcept(is_nothrow_invocable_v) { if (!state) { invoke(forward(func)); } return *this; } }; template Condition chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template Condition chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } inline auto range(size_t n) { return views::iota(0u, n); } template void RotateVec2(vector>& v) { ll h = v.size(); ll w = v[0].size(); vector> t(w, vector(h)); rep(i, h) { rep(j, w) { t[j][h - i - 1] = v[i][j]; } } v = t; } template bool InRange(T x, T mn, T mx) { return (mn <= x && x <= mx); } template vector& merged(vector& a, vector& b) { vector res; merge(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; } inline ll popcount(ll x) { ll res = 0; while (x) { res += x % 2; x >>= 1; } return res; } inline ll isqrt(ll n) { if (n <= 0) return 0; ll x = sqrt(n); while ((x + 1) * (x + 1) <= n) x++; while (x * x > n) x--; return x; } template ostream& operator<<(ostream& stream, const pair& p); template ostream& operator<<(ostream& stream, const vector& a); template ostream& operator<<(ostream& stream, const deque& a); template ostream& operator<<(ostream& stream, const set& a); template ostream& operator<<(ostream& stream, const map& a); template istream& operator>>(istream& stream, pair& a); template istream& operator>>(istream& stream, vector& a); template concept EmplaceBackSink = requires(C& c, U&& x) { c.emplace_back(forward(x)); }; template concept EmplaceSink = requires(C& c, U&& x) { c.emplace(forward(x)); }; template concept PushBackSink = requires(C& c, U&& x) { c.push_back(forward(x)); }; template concept PushSink = requires(C& c, U&& x) { c.push(forward(x)); }; template concept InsertSink = requires(C& c, U&& x) { c.insert(forward(x)); }; template concept Sink = EmplaceBackSink || EmplaceSink || PushBackSink || PushSink || InsertSink; template concept Readable = requires(istream& is, T& x) { is >> x; }; template requires Sink constexpr C& put(C& c, U&& x) { if constexpr (EmplaceBackSink) c.emplace_back(forward(x)); else if constexpr (EmplaceSink) c.emplace(forward(x)); else if constexpr (PushBackSink) c.push_back(forward(x)); else if constexpr (PushSink) c.push(forward(x)); else c.insert(forward(x)); return c; } template requires Sink C& operator<<(C& c, U&& x) { return put(c, forward(x)); } template requires Sink> void operator<<=(C& c, R&& r) { for (auto&& x : r) c << std::forward(x); } template ostream& operator<<(ostream& stream, const pair& p) { stream << "( " << p.first << ", " << p.second << " )"; return stream; } template ostream& operator<<(ostream& stream, const vector& a) { stream << "{ "; for (const T& i : a) stream << i << " "; stream << "}"; return stream; } template ostream& operator<<(ostream& stream, const deque& a) { stream << "{ "; for (const T& i : a) stream << i << " "; stream << "}"; return stream; } template ostream& operator<<(ostream& stream, const set& a) { stream << "{ "; for (const T& i : a) stream << i << " "; stream << "}"; return stream; } template ostream& operator<<(ostream& stream, const map& a) { stream << "{ "; for (const auto& [k, v] : a) stream << "{ " << k << " : " << v << " } "; stream << "}"; return stream; } template istream& operator>>(istream& stream, pair& a) { stream >> a.first >> a.second; return stream; } template istream& operator>>(istream& stream, vector& a) { for (auto& i : a) stream >> i; return stream; } template struct PredictedInput { tuple args; template requires Readable && constructible_from operator T() && { T x = apply( [](auto&&... args) -> T { return T(forward(args)...); }, move(args)); cin >> x; return x; } }; template auto in(Args&&... args) { return PredictedInput...>{{forward(args)...}}; } template T in() { T x; cin >> x; return x; } template auto in() { tuple x; apply( [](auto&... xs) { (cin >> ... >> xs); }, x); return x; } template vector ZAlgorithm(const T& x) { const size_t n = ranges::size(x); if (n == 0) return {}; vector z(n); z[0] = n; size_t l = 0, r = 0; for (size_t i = 1; i < n; ++i) { if (i < r) z[i] = min(r - i, z[i - l]); while (i + z[i] < n && x[z[i]] == x[i + z[i]]) ++z[i]; if (i + z[i] > r) l = i, r = i + z[i]; } return z; } template struct AhoCorasick { struct Node { unordered_map next; size_t fail = 0; bool matches = false; }; vector nodes; AhoCorasick(initializer_list patterns) requires same_as : AhoCorasick(views::all(patterns)) {} AhoCorasick(initializer_list> patterns) requires(!same_as) : AhoCorasick(views::all(patterns)) {} template AhoCorasick(R&& patterns) : nodes(1) { for (const auto& pattern : patterns) { size_t node = 0; for (const T& ch : [&] { if constexpr (same_as && convertible_to) return string_view(pattern); else return views::all(pattern); }()) { const auto [it, inserted] = nodes[node].next.try_emplace(ch, nodes.size()); node = it->second; if (inserted) nodes.emplace_back(); } nodes[node].matches = true; } queue q; for (const auto& [ch, node] : nodes[0].next) { nodes[node].matches |= nodes[0].matches; q.push(node); } while (!q.empty()) { const size_t node = q.front(); q.pop(); for (const auto& [ch, next] : nodes[node].next) { const size_t fail = step(nodes[node].fail, ch); nodes[next].fail = fail; nodes[next].matches |= nodes[fail].matches; q.push(next); } } } bool match(string_view text) const requires same_as { return match(ranges::subrange(text.begin(), text.end())); } template requires(!same_as || !convertible_to) bool match(R&& text) const { if (nodes[0].matches) return true; size_t node = 0; for (const T& ch : text) { node = step(node, ch); if (nodes[node].matches) return true; } return false; } size_t step(size_t node, const T& ch) const { while (true) { const auto it = nodes[node].next.find(ch); if (it != nodes[node].next.end()) return it->second; if (!node) return 0; node = nodes[node].fail; } } }; template AhoCorasick(initializer_list>) -> AhoCorasick; template requires convertible_to, string_view> AhoCorasick(R&&) -> AhoCorasick; template requires(!convertible_to, string_view>) AhoCorasick(R&&) -> AhoCorasick>>; struct UnionFind { vector tree; UnionFind(ll x) : tree(x, -1) {} ll root(ll x) { if (tree[x] < 0) return x; return tree[x] = root(tree[x]); } bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return -tree[root(x)]; } void unite(ll x, ll y) { x = root(x), y = root(y); if (x == y) return; if (size(x) < size(y)) swap(x, y); tree[x] += tree[y]; tree[y] = x; } }; template struct SegTree { using MergeFunc = Monoid (*)(Monoid, Monoid); using ApplyFunc = Monoid (*)(Monoid, Action); ull n; vector tree; Monoid e; MergeFunc merge; ApplyFunc apply; SegTree(ull n_, MergeFunc mf, Monoid e_, ApplyFunc af) : e(e_), merge(mf), apply(af) { ull s = 1; while (s < n_) s <<= 1; n = s; tree.assign(n * 2, e); } Monoid query(ull l, ull r) { return query(l, r, 0, 0, n); } void update(ull idx, Action x) { idx += n - 1; tree[idx] = apply(tree[idx], x); while (idx) { idx = (idx - 1) / 2; tree[idx] = merge(tree[idx * 2 + 1], tree[idx * 2 + 2]); } } Monoid get(ull i) { return query(i, i + 1); } private: Monoid query(ull ql, ull qr, ull pos, ull rl, ull rr) { if (qr <= rl || rr <= ql) return e; if (ql <= rl && rr <= qr) return tree[pos]; return merge(query(ql, qr, pos * 2 + 1, rl, (rl + rr) >> 1), query(ql, qr, pos * 2 + 2, (rl + rr) >> 1, rr)); } }; template struct LazySegTree { static_assert(std::is_convertible_v>, "merge must work as Monoid(Monoid, Monoid)"); static_assert(std::is_convertible_v>, "mapping must work as Monoid(Monoid, Action)"); static_assert(std::is_convertible_v>, "composition must work as Action(Action, Action)"); ull n; vector tree; vector lazy; Monoid e; Action id; LazySegTree(ull n_, Monoid e_, Action id_, const vector& initial_values = {}) : e(e_), id(id_) { ull s = 1; while (s < n_) s <<= 1; n = s; tree.assign(n * 2, e); lazy.assign(n * 2, id); for (ull i = 0; i < initial_values.size(); i++) { tree[i + n - 1] = initial_values[i]; } for (ull i = n - 2; i < n - 1; i--) { tree[i] = merge(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } Monoid query(ull l, ull r) { return query(l, r, 0, 0, n); } void update(ull idx, Action x) { update(idx, idx + 1, x); } void update(ull l, ull r, Action x) { update(l, r, 0, 0, n, x); } Monoid get(ull i) { return query(i, i + 1); } void clear() { fill(tree.begin(), tree.end(), e); fill(lazy.begin(), lazy.end(), id); } void flush() { for (int i = 0; i < n * 2; i++) { fetch(i); } } const Monoid& operator[](ull idx) { return tree[idx + n - 1]; } private: void fetch(ull pos) { if (lazy[pos] == id) return; if (pos < n - 1) { lazy[(pos << 1) + 1] = comp(lazy[(pos << 1) + 1], lazy[pos]); lazy[(pos << 1) + 2] = comp(lazy[(pos << 1) + 2], lazy[pos]); } tree[pos] = apply(tree[pos], lazy[pos]); lazy[pos] = id; } Monoid query(ull ql, ull qr, ull pos, ull rl, ull rr) { if (rr <= ql || qr <= rl) return e; fetch(pos); if (ql <= rl && rr <= qr) return tree[pos]; return merge(query(ql, qr, (pos << 1) + 1, rl, (rl + rr) >> 1), query(ql, qr, (pos << 1) + 2, (rl + rr) >> 1, rr)); } void update(ull ql, ull qr, ull pos, ull rl, ull rr, Action x) { fetch(pos); if (rr <= ql || qr <= rl) return; if (ql <= rl && rr <= qr) { lazy[pos] = comp(lazy[pos], x); fetch(pos); return; } update(ql, qr, (pos << 1) + 1, rl, (rl + rr) >> 1, x); update(ql, qr, (pos << 1) + 2, (rl + rr) >> 1, rr, x); tree[pos] = merge(tree[(pos << 1) + 1], tree[(pos << 1) + 2]); } }; template class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(((x % Modulus) + Modulus) % Modulus) {} constexpr u64& value() noexcept { return a; } constexpr const u64& value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint& operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint& operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint& operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint& operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr modint pow(u64 exp) noexcept { modint res = 1, rhs = *this; while (exp) { if (exp & 1) { res *= rhs; } rhs *= rhs; exp >>= 1; } return res; } constexpr modint& operator=(u64 x) { a = x % Modulus; return *this; } constexpr bool operator==(const modint x) const { return a == x.a; } friend istream& operator>>(istream& stream, modint& a) { u64 x; stream >> x; a = ((x % Modulus) + Modulus) % Modulus; return stream; } friend ostream& operator<<(ostream& stream, const modint a) { stream << a.a; return stream; } }; inline ll fastpow(ll a, ll n) { ll res = 1; while (n > 0) { if (n & 1) res *= a; a *= a; n >>= 1; } return res; } inline ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = (res * (a % mod)) % mod; a = ((a % mod) * (a % mod)) % mod; n >>= 1; } return res; } inline void FFT998(vector>& a, bool invert = false) { size_t n = a.size(); for (size_t i = 1, j = 0; i < n; i++) { size_t bit = n >> 1; for (; j & bit; bit >>= 1) j ^= bit; j ^= bit; if (i < j) swap(a[i], a[j]); } for (size_t len = 2; len <= n; len <<= 1) { modint wlen = modpow(3, (MOD2 - 1) / len, MOD2); if (invert) wlen = wlen.pow(MOD2 - 2); for (size_t i = 0; i < n; i += len) { modint w = 1; for (size_t j = 0; j < len / 2; j++) { modint u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen; } } } if (invert) { modint n_inv = modpow(n, MOD2 - 2, MOD2); for (modint& x : a) x *= n_inv; } } inline vector> Convolution998(vector> a, vector> b) { size_t n = 1; size_t m = a.size() + b.size() - 1; while (n < m) n <<= 1; a.resize(n); b.resize(n); FFT998(a); FFT998(b); for (size_t i = 0; i < n; i++) a[i] *= b[i]; FFT998(a, true); a.resize(m); return a; } namespace Geometry2D { template struct Vector2D { T x, y; Vector2D() : x(0), y(0) {} Vector2D(T x_, T y_) : x(x_), y(y_) {} long double length() const { return sqrt((long double)x * x + y * y); }; T lengthp() const { return x * x + y * y; }; bool inrange(const Vector2D a, const Vector2D b) const { return (InRange(x, a.x, b.x) and InRange(y, a.y, b.y)); } Vector2D yx() const { return Vector2D{y, x}; } Vector2D rotated90() const { return Vector2D{-y, x}; } Vector2D normalized() const { return *this / length(); } T cross(const Vector2D a) const { return x * a.y - y * a.x; } Vector2D operator-(const Vector2D a) const { return Vector2D(*this) -= a; } Vector2D operator+(const Vector2D a) const { return Vector2D(*this) += a; } T operator*(const Vector2D a) const { return x * a.x + y * a.y; } Vector2D operator*(const T a) const { return Vector2D(*this) *= a; } Vector2D operator/(const T a) const { return Vector2D(*this) /= a; } Vector2D& operator+=(const Vector2D a) { x += a.x; y += a.y; return *this; } Vector2D& operator-=(const Vector2D a) { x -= a.x; y -= a.y; return *this; } Vector2D& operator-=(const T a) { x -= a; y -= a; return *this; } Vector2D& operator*=(const T a) { x *= a; y *= a; return *this; } Vector2D& operator/=(const T a) { x /= a; y /= a; return *this; } bool operator==(const Vector2D a) const { return (x == a.x and y == a.y); } bool operator!=(const Vector2D a) const { return not(x == a.x and y == a.y); } bool operator>(const Vector2D a) const { return a < *this; } bool operator<(const Vector2D a) const { return make_pair(x, y) < make_pair(a.x, a.y); } friend ostream& operator<<(ostream& stream, const Vector2D& x) { stream << "(" << x.x << ", " << x.y << ")"; return stream; } friend istream& operator>>(istream& stream, Vector2D& x) { stream >> x.x >> x.y; return stream; } }; using Scalar = long double; using Vec2 = Vector2D; constexpr Scalar EPS = 1e-12L; inline bool InRange(Scalar x, Scalar a, Scalar b) { return min(a, b) - EPS <= x and x <= max(a, b) + EPS; } inline int Sign(Scalar x) { if (x > EPS) return 1; if (x < -EPS) return -1; return 0; } struct Line { Vec2 p1, p2, d; Line(Vec2 p1, Vec2 p2) : p1(p1), p2(p2), d(p2 - p1) {} bool onSegment(const Vec2& p) const { return Sign(d.cross(p - p1)) == 0 and InRange(p.x, p1.x, p2.x) and InRange(p.y, p1.y, p2.y); } bool segIntersects(const Line& line) const { int a = Sign(d.cross(line.p1 - p1)); int b = Sign(d.cross(line.p2 - p1)); int c = Sign(line.d.cross(p1 - line.p1)); int d = Sign(line.d.cross(p2 - line.p1)); return (a * b < 0 and c * d < 0) or (a == 0 and onSegment(line.p1)) or (b == 0 and onSegment(line.p2)) or (c == 0 and line.onSegment(p1)) or (d == 0 and line.onSegment(p2)); } bool lineIntersects(const Line& line) const { return Sign(d.cross(line.d)) != 0 or Sign(d.cross(line.p1 - p1)) == 0; } Vec2 intersectsAt(const Line& line) const { if (!lineIntersects(line) or Sign(d.cross(line.d)) == 0) return Vec2{}; return p1 + d * (line.p1 - p1).cross(line.d) / d.cross(line.d); } Vec2 projected(const Vec2& p) const { return Sign(d.lengthp()) ? p1 + d * ((p - p1) * d) / d.lengthp() : p1; } Scalar lineDistance(const Vec2& p) const { return (p - projected(p)).length(); } Scalar lineDistance(const Line& l) const { return lineIntersects(l) ? 0 : lineDistance(l.p1); } Scalar segDistance(const Vec2& p) const { Scalar t = (p - p1) * d / d.lengthp(); if (t <= 0) return (p - p1).length(); else if (t >= 1) return (p - p2).length(); else return (p1 + d * t - p).length(); } Scalar segDistance(const Line& l) const { return segIntersects(l) ? 0 : min({segDistance(l.p1), segDistance(l.p2), l.segDistance(p1), l.segDistance(p2)}); } }; struct Polygon { vector points; size_t n; Polygon(const vector& points) : points(points), n(points.size()) {} const Vec2& vertex(size_t idx) const { return points[idx % n]; } Vec2& vertex(size_t idx) { return points[idx % n]; } Scalar Area() const { Scalar area = 0; for (size_t i = 0; i < n; i++) { area += vertex(i).cross(vertex(i + 1)); } return area * Sign(area) / 2; } bool IsConvex() const { for (size_t i = 0; i < n; i++) if ((vertex(i) - vertex(i + 1)).cross(vertex(i + 1) - vertex(i + 2)) < 0) return false; return true; } bool Contains(const Vec2& p) { Scalar acc = 0; for (size_t i = 0; i < n; i++) { Vec2 a = vertex(i) - p; Vec2 b = vertex(i + 1) - p; if (Sign(a.cross(b)) == 0 and (a * b) <= EPS) return true; acc += atan2(a.cross(b), a * b); } return abs(acc) > acosl(-1L); } bool OnBoundary(const Vec2& p) const { for (size_t i = 0; i < n; i++) { if (Line(vertex(i), vertex(i + 1)).onSegment(p)) return true; } return false; } Scalar Diameter() const { if (n == 2) return (points[0] - points[1]).length(); Scalar res = 0; size_t i = 0, j = 1; while (i <= n) { res = max(res, (vertex(i) - vertex(j)).length()); if (Sign((vertex(i + 1) - vertex(i)).cross(vertex(j + 1) - vertex(j))) > 0) j++; else i++; } return res; } pair ConvexCut(const Line& line) const { vector left, right; for (size_t i = 0; i < n; i++) { const Vec2& a = vertex(i); const Vec2& b = vertex(i + 1); int sa = Sign(line.d.cross(a - line.p1)); int sb = Sign(line.d.cross(b - line.p1)); if (sa >= 0) left.push_back(a); if (sa <= 0) right.push_back(a); if (sa * sb < 0) left.push_back(line.intersectsAt(Line(a, b))), right.push_back(line.intersectsAt(Line(a, b))); } return {Polygon(left), Polygon(right)}; } }; inline Polygon ConvexHull(vector points) { if (points.size() < 3) return Polygon{{}}; sort(points.begin(), points.end(), [](Vec2 a, Vec2 b) { if (Sign(a.y - b.y)) return Sign(a.y - b.y) < 0; return Sign(a.x - b.x) < 0; }); points.erase(unique(ALL(points)), points.end()); auto half = [](auto begin, auto end) { vector p(begin, begin + 2); for (auto itr = begin + 2; itr != end; itr++) { while (p.size() >= 2 and Sign((*itr - p.back()).cross(p[p.size() - 2] - p.back())) < 0) p.pop_back(); p.push_back(*itr); } p.pop_back(); return p; }; auto lower = half(points.begin(), points.end()), upper = half(points.rbegin(), points.rend()); lower.insert(lower.end(), upper.begin(), upper.end()); return Polygon{lower}; } } template struct Grid { vector data; vector shape; Grid() {} Grid(ull h, ull w, T x = T()) : data(h * w, x), shape({h, w}) {} Grid(initializer_list shape_, T x = T()) : data(accumulate(shape_.begin(), shape_.end(), 1, multiplies()), x), shape(shape_) {} T& operator[](ull i) { return data.data()[i]; } template ()))> T& operator[](const Container& idx) { ull i = 0; for (ull j = 0; j < shape.size(); ++j) { i = i * shape.data()[j] + idx[j]; } return data.data()[i]; } template T& operator[](initializer_list idx) { ull i = 0; auto it = idx.begin(); for (ull j = 0; j < shape.size(); ++j, ++it) { i = i * shape.data()[j] + *it; } return data.data()[i]; } template T& operator[](const Geometry2D::Vector2D& idx) { return data.data()[idx.x * shape.data()[1] + idx.y]; } template T& operator()(Args... args) { ull idxs[] = {static_cast(args)...}; ull i = 0; for (ull j = 0; j < sizeof...(Args); ++j) { i = i * shape.data()[j] + idxs[j]; } return data[i]; } friend istream& operator>>(istream& stream, Grid& grid) { for (auto& i : grid.data) stream >> i; return stream; } }; #define __DEBUGGER_OUTPUT cerr namespace Debugger { class TableManager { struct Table { std::vector columns; std::vector> rows; }; std::map tables; static TableManager& getInstance() { static TableManager instance; return instance; } public: static void addRow(int line, const std::vector& header, const std::vector& row) { auto& table = getInstance().tables[line]; if (table.columns.empty()) { table.columns = header; } table.rows.push_back(row); } static void flush() { auto& instance = getInstance(); for (const auto& [line, table] : instance.tables) { vector colWidths(table.columns.size(), 0); size_t width = 0; for (size_t i = 0; i < table.columns.size(); ++i) colWidths[i] = table.columns[i].size(); for (const auto& row : table.rows) for (size_t i = 0; i < row.size(); ++i) colWidths[i] = std::max(colWidths[i], row[i].size()); for (size_t i = 0; i < colWidths.size(); ++i) width += colWidths[i] + 2; __DEBUGGER_OUTPUT << std::left << "[DEBUG TABLE] L" << line << "\n"; for (size_t i = 0; i < table.columns.size(); ++i) { __DEBUGGER_OUTPUT << '+' << std::string(colWidths[i] + 2, '-') << (i + 1 < table.columns.size() ? "" : "+\n"); } for (size_t i = 0; i < table.columns.size(); ++i) { __DEBUGGER_OUTPUT << "| " << std::setw(colWidths[i]) << table.columns[i] << (i + 1 < table.columns.size() ? " " : " |\n"); } for (size_t i = 0; i < table.columns.size(); ++i) { __DEBUGGER_OUTPUT << '+' << std::string(colWidths[i] + 2, '-') << (i + 1 < table.columns.size() ? "" : "+\n"); } for (const auto& row : table.rows) { __DEBUGGER_OUTPUT << "| "; for (size_t i = 0; i < row.size(); ++i) __DEBUGGER_OUTPUT << std::setw(colWidths[i]) << row[i] << (i + 1 < row.size() ? " | " : " |\n"); } for (size_t i = 0; i < table.columns.size(); ++i) { __DEBUGGER_OUTPUT << '+' << std::string(colWidths[i] + 2, '-') << (i + 1 < table.columns.size() ? "" : "+\n"); } } __DEBUGGER_OUTPUT.flush(); instance.tables.clear(); } ~TableManager() { flush(); } }; template std::string toStr(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } inline std::string strip(const std::string& str) { size_t start = str.find_first_not_of(" \t\n\r"); size_t end = str.find_last_not_of(" \t\n\r"); return (start == std::string::npos) ? "" : str.substr(start, end - start + 1); } inline std::vector split(const std::string& str) { std::vector res; size_t depth = 0, start = 0; for (size_t i = 0; i < str.size(); ++i) { if (str[i] == ',' && depth == 0) { res.push_back(strip(str.substr(start, i - start))); start = i + 1; } else if (str[i] == '(' || str[i] == '[' || str[i] == '{' || str[i] == '<') depth++; else if (str[i] == ')' || str[i] == ']' || str[i] == '}' || str[i] == '>') depth--; } res.push_back(strip(str.substr(start))); return res; } template void tdebug_helper(int line, const char* names, const Args&... args) { std::vector nameList = split(names); std::vector valueList = {toStr(args)...}; TableManager::addRow(line, nameList, valueList); } template void debug_impl(int line, const char* names, const Args&... args) { __DEBUGGER_OUTPUT << "[DEBUG] L" << line << ": "; auto nameList = split(names); size_t i = 0; ((__DEBUGGER_OUTPUT << (i++ ? ", " : "") << nameList[i - 1] << " = " << args), ...); __DEBUGGER_OUTPUT << endl; } } #define debug(...) Debugger::debug_impl(__LINE__, #__VA_ARGS__, __VA_ARGS__) #define tdebug(...) Debugger::tdebug_helper(__LINE__, #__VA_ARGS__, __VA_ARGS__) #define tflush() Debugger::TableManager::flush(); using namespace std; using mint = modint; using Vec2 = Geometry2D::Vector2D; const Vec2 Angles[] = {{0,1}, {-1,0}, {0,-1}, {1,0}}; int main () { auto [n, s, a] = in(); ll m = n - n / 2; ll upper = 0, lower = 0; rep(i, n) { if (i < n / 2) { upper <<= 1; upper += s[i] - '0'; } else { lower <<= 1; lower += s[i] - '0'; } } // debug(upper, lower); ll ans = INF; vectorlower_mods(min(a,1ll<(target), m); // }); } if (ans == INF) cout << -1 << endl; else cout << ans << endl; }