2024-02-28 12:24:12 +01:00
|
|
|
|
#pragma region includes
|
2023-07-10 20:20:19 +02:00
|
|
|
|
#include <algorithm>
|
2023-07-29 15:27:25 +02:00
|
|
|
|
#include <array>
|
2023-07-23 11:39:05 +02:00
|
|
|
|
#include <bit>
|
2023-07-29 15:27:25 +02:00
|
|
|
|
#include <bitset>
|
2023-07-10 20:20:19 +02:00
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cctype>
|
2023-07-29 15:27:25 +02:00
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <cmath>
|
2023-07-10 20:20:19 +02:00
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <functional>
|
2023-07-29 15:27:25 +02:00
|
|
|
|
#include <iomanip>
|
2023-05-14 14:39:42 +02:00
|
|
|
|
#include <iostream>
|
2023-07-23 11:39:05 +02:00
|
|
|
|
#include <map>
|
2023-07-29 15:27:25 +02:00
|
|
|
|
#include <numeric>
|
2023-07-10 20:20:19 +02:00
|
|
|
|
#include <optional>
|
2023-07-23 11:39:05 +02:00
|
|
|
|
#include <queue>
|
2023-07-29 15:27:25 +02:00
|
|
|
|
#include <random>
|
2023-07-23 11:39:05 +02:00
|
|
|
|
#include <set>
|
2023-07-10 20:20:19 +02:00
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2024-02-28 12:24:12 +01:00
|
|
|
|
#pragma endregion includes
|
2023-05-14 14:39:42 +02:00
|
|
|
|
|
2023-07-29 15:57:32 +02:00
|
|
|
|
#pragma region helpers
|
2023-07-23 11:39:05 +02:00
|
|
|
|
|
2023-08-12 23:16:08 +02:00
|
|
|
|
#pragma region aliases
|
|
|
|
|
#define LOOP(var, n) for (auto var = 0; var < n; ++var)
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
using V = std::vector<T>;
|
|
|
|
|
|
|
|
|
|
template <typename K, typename V>
|
|
|
|
|
using M = std::map<K, V>;
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
using S = std::set<T>;
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
using Q = std::deque<T>;
|
|
|
|
|
|
|
|
|
|
using i8 = std::int8_t;
|
|
|
|
|
using u8 = std::uint8_t;
|
|
|
|
|
using i16 = std::int16_t;
|
|
|
|
|
using u16 = std::uint16_t;
|
|
|
|
|
using i32 = std::int32_t;
|
|
|
|
|
using u32 = std::uint32_t;
|
|
|
|
|
using i64 = std::int64_t;
|
|
|
|
|
using u64 = std::uint64_t;
|
|
|
|
|
#pragma endregion /* aliases */
|
|
|
|
|
|
2023-08-12 23:16:31 +02:00
|
|
|
|
#pragma region data structures
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct max_heap {
|
|
|
|
|
using container = std::vector<T>;
|
|
|
|
|
|
|
|
|
|
typename container::size_type size() const { return h.size(); }
|
|
|
|
|
|
|
|
|
|
void push(T item) {
|
|
|
|
|
h.push_back(item);
|
|
|
|
|
std::push_heap(h.begin(), h.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T pop() {
|
|
|
|
|
std::pop_heap(h.begin(), h.end());
|
|
|
|
|
T item = std::move(h.back());
|
|
|
|
|
h.pop_back();
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
container h;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct min_heap {
|
|
|
|
|
using container = std::vector<T>;
|
|
|
|
|
|
|
|
|
|
typename container::size_type size() const { return h.size(); }
|
|
|
|
|
|
|
|
|
|
void push(T item) {
|
|
|
|
|
h.push_back(item);
|
|
|
|
|
std::push_heap(h.begin(), h.end(), std::greater<>{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T pop() {
|
|
|
|
|
std::pop_heap(h.begin(), h.end(), std::greater<>{});
|
|
|
|
|
T item = std::move(h.back());
|
|
|
|
|
h.pop_back();
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
container h;
|
|
|
|
|
};
|
|
|
|
|
#pragma endregion /* data structures */
|
|
|
|
|
|
2023-08-12 23:02:33 +02:00
|
|
|
|
#pragma region debug
|
|
|
|
|
void dbg_out() { std::cerr << std::endl; }
|
|
|
|
|
template <typename Head, typename... Tail>
|
|
|
|
|
void dbg_out(Head H, Tail... T) {
|
|
|
|
|
std::cerr << ' ' << H;
|
|
|
|
|
dbg_out(T...);
|
|
|
|
|
}
|
2024-02-28 12:25:35 +01:00
|
|
|
|
#ifdef _MF_TEST
|
2023-08-12 23:02:33 +02:00
|
|
|
|
#define dbg(...) \
|
|
|
|
|
std::cerr << '[' << __FILE__ << ':' << __LINE__ << "] (" << #__VA_ARGS__ \
|
|
|
|
|
<< "):", \
|
|
|
|
|
dbg_out(__VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define dbg(...)
|
|
|
|
|
#endif
|
|
|
|
|
#pragma endregion debug
|
|
|
|
|
|
|
|
|
|
#pragma region functional
|
|
|
|
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
|
|
|
|
|
template <class Fun>
|
|
|
|
|
class y_combinator_result {
|
|
|
|
|
Fun fun_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
template <class T>
|
|
|
|
|
explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}
|
|
|
|
|
template <class... Args>
|
|
|
|
|
decltype(auto) operator()(Args &&...args) {
|
|
|
|
|
return fun_(std::ref(*this), std::forward<Args>(args)...);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
template <class Fun>
|
|
|
|
|
decltype(auto) y_combinator(Fun &&fun) {
|
|
|
|
|
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
|
|
|
|
|
}
|
|
|
|
|
#pragma endregion /* functional */
|
|
|
|
|
|
|
|
|
|
#pragma region input
|
2023-08-12 23:17:31 +02:00
|
|
|
|
template <typename Container>
|
|
|
|
|
void collect(Container &c, std::size_t size) {
|
|
|
|
|
auto it = std::inserter(c, c.begin());
|
2023-08-12 23:02:33 +02:00
|
|
|
|
|
|
|
|
|
for (auto i = 0u; i < size; ++i) {
|
2023-08-12 23:17:31 +02:00
|
|
|
|
typename Container::value_type x;
|
2023-08-12 23:02:33 +02:00
|
|
|
|
std::cin >> x;
|
2023-08-12 23:17:31 +02:00
|
|
|
|
it = std::move(x);
|
2023-08-12 23:02:33 +02:00
|
|
|
|
}
|
2023-08-12 23:17:31 +02:00
|
|
|
|
}
|
2023-08-12 23:02:33 +02:00
|
|
|
|
|
2023-08-12 23:17:31 +02:00
|
|
|
|
template <typename Container>
|
|
|
|
|
Container collect(std::size_t size) {
|
|
|
|
|
Container c{};
|
|
|
|
|
collect(c, size);
|
|
|
|
|
return c;
|
2023-08-12 23:02:33 +02:00
|
|
|
|
}
|
2024-02-28 12:25:12 +01:00
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::map<T, std::size_t> collect_count(std::size_t size) {
|
|
|
|
|
std::map<T, std::size_t> counts;
|
|
|
|
|
|
|
|
|
|
for (auto i = 0u; i < size; ++i) {
|
|
|
|
|
T x;
|
|
|
|
|
std::cin >> x;
|
|
|
|
|
++counts[x];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return counts;
|
|
|
|
|
}
|
2023-08-12 23:02:33 +02:00
|
|
|
|
#pragma endregion /* input */
|
|
|
|
|
|
2023-07-29 15:57:32 +02:00
|
|
|
|
#pragma region math
|
2023-07-10 11:39:30 +02:00
|
|
|
|
long pow(long base, long exp) {
|
2023-07-10 14:23:09 +02:00
|
|
|
|
if (exp == 0) return 1;
|
2023-07-10 11:39:30 +02:00
|
|
|
|
long half = pow(base, exp / 2);
|
2023-07-10 14:23:09 +02:00
|
|
|
|
if (exp % 2 == 0) return half * half;
|
2023-07-10 11:39:30 +02:00
|
|
|
|
return half * half * base;
|
|
|
|
|
}
|
2023-08-12 23:19:59 +02:00
|
|
|
|
|
2023-08-12 23:20:17 +02:00
|
|
|
|
template <typename T>
|
|
|
|
|
T isqrt(T x) {
|
|
|
|
|
assert(x >= 0);
|
|
|
|
|
|
|
|
|
|
auto max_shift = 8 * sizeof(T) - 1;
|
|
|
|
|
auto shift = (max_shift - std::countl_zero(x)) & ~1;
|
|
|
|
|
auto bit = 1 << shift;
|
|
|
|
|
|
|
|
|
|
T result = 0;
|
|
|
|
|
while (bit != 0) {
|
|
|
|
|
if (x >= (result + bit)) {
|
|
|
|
|
x -= result + bit;
|
|
|
|
|
result = (result >> 1) + bit;
|
|
|
|
|
} else {
|
|
|
|
|
result = (result >> 1);
|
|
|
|
|
}
|
|
|
|
|
bit = bit >> 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-12 23:19:59 +02:00
|
|
|
|
template <std::int64_t MODULO = 1000000007>
|
|
|
|
|
struct Z {
|
|
|
|
|
Z(std::int64_t x = 0) : x(x % MODULO) {}
|
|
|
|
|
|
|
|
|
|
Z pow(std::uint32_t exp) const {
|
|
|
|
|
auto ans = 1;
|
|
|
|
|
auto base = x;
|
|
|
|
|
|
|
|
|
|
for (; exp > 0; exp >>= 1) {
|
|
|
|
|
if (exp % 2 == 1) {
|
|
|
|
|
ans *= base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base *= base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Z inv() const {
|
|
|
|
|
assert(x != 0);
|
|
|
|
|
return pow(MODULO - 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Z operator-() const { return {-x}; }
|
|
|
|
|
Z operator+=(const Z &rhs) { x = (x + rhs.x) % MODULO; }
|
|
|
|
|
Z operator-=(const Z &rhs) { x = (x - rhs.x) % MODULO; }
|
|
|
|
|
Z operator*=(const Z &rhs) { x = (x * rhs.x) % MODULO; }
|
|
|
|
|
Z operator/=(const Z &rhs) { x = (x * rhs.inv().x) % MODULO; }
|
|
|
|
|
|
|
|
|
|
friend Z operator+(Z lhs, const Z &rhs) { return lhs += rhs; }
|
|
|
|
|
friend Z operator-(Z lhs, const Z &rhs) { return lhs -= rhs; }
|
|
|
|
|
friend Z operator*(Z lhs, const Z &rhs) { return lhs *= rhs; }
|
|
|
|
|
friend Z operator/(Z lhs, const Z &rhs) { return lhs /= rhs; }
|
|
|
|
|
|
|
|
|
|
friend std::istream &operator>>(std::istream &is, Z &z) {
|
|
|
|
|
is >> z.x;
|
|
|
|
|
z.x %= MODULO;
|
|
|
|
|
return is;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &os, const Z &z) {
|
|
|
|
|
return os << z.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::int64_t x;
|
|
|
|
|
};
|
2023-07-29 15:57:32 +02:00
|
|
|
|
#pragma endregion /* math */
|
2023-07-10 11:39:30 +02:00
|
|
|
|
|
2023-07-29 15:57:32 +02:00
|
|
|
|
#pragma region output
|
|
|
|
|
template <typename T, typename U>
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, std::pair<T, U> const &p) {
|
|
|
|
|
return os << p.first << " " << p.second;
|
|
|
|
|
}
|
2023-07-23 11:39:05 +02:00
|
|
|
|
|
2023-07-29 16:00:10 +02:00
|
|
|
|
template <typename C, typename T = typename std::enable_if<
|
|
|
|
|
!std::is_same<C, std::string>::value,
|
|
|
|
|
typename C::value_type>::type>
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const C &v) {
|
|
|
|
|
std::string sep;
|
|
|
|
|
for (const T &x : v) {
|
|
|
|
|
os << sep << x, sep = " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return os;
|
|
|
|
|
}
|
2023-07-23 11:39:05 +02:00
|
|
|
|
|
2023-07-29 15:57:32 +02:00
|
|
|
|
template <typename T>
|
|
|
|
|
inline void answer(const T &ans) {
|
2024-02-28 12:25:35 +01:00
|
|
|
|
|
|
|
|
|
#ifdef _MF_TEST
|
|
|
|
|
std::cout << "Answer: ";
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-07-29 15:57:32 +02:00
|
|
|
|
std::cout << ans << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 12:25:35 +01:00
|
|
|
|
inline void yes() { answer("YES"); }
|
|
|
|
|
inline void no() { answer("NO"); }
|
|
|
|
|
inline void yesno(bool ans) { answer(ans ? "YES" : "NO"); }
|
2023-07-29 16:01:18 +02:00
|
|
|
|
#pragma endregion /* output */
|
|
|
|
|
|
2023-08-19 00:32:36 +02:00
|
|
|
|
#pragma region rng
|
|
|
|
|
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
|
|
|
|
|
#pragma endregion /* rng */
|
|
|
|
|
|
2023-07-29 15:57:32 +02:00
|
|
|
|
#pragma endregion /* helpers */
|
2023-07-10 14:23:09 +02:00
|
|
|
|
|
2023-07-23 11:39:05 +02:00
|
|
|
|
// for ‹N› test cases, uncomment for single test case
|
|
|
|
|
// #define SINGLE
|
|
|
|
|
|
|
|
|
|
namespace solution {
|
2023-07-10 14:23:09 +02:00
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2023-05-14 14:39:42 +02:00
|
|
|
|
void solve() {
|
|
|
|
|
// TODO
|
2023-07-29 15:59:06 +02:00
|
|
|
|
dbg("Hello from debug");
|
|
|
|
|
answer("Hello");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tests() {
|
|
|
|
|
// TODO
|
2023-05-14 14:39:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-23 11:39:05 +02:00
|
|
|
|
} // namespace solution
|
2023-05-14 14:39:42 +02:00
|
|
|
|
|
2023-07-23 11:39:05 +02:00
|
|
|
|
using namespace solution;
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2024-02-28 12:25:35 +01:00
|
|
|
|
#ifdef _MF_UNIT_TESTS
|
2023-07-10 14:23:09 +02:00
|
|
|
|
|
2023-07-29 15:59:06 +02:00
|
|
|
|
int main(void) {
|
|
|
|
|
tests();
|
|
|
|
|
return 0;
|
2023-07-10 14:23:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2023-05-14 14:39:42 +02:00
|
|
|
|
int main(void) {
|
2023-07-29 15:59:06 +02:00
|
|
|
|
int N = 1;
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2023-07-29 15:59:06 +02:00
|
|
|
|
#ifndef SINGLE
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2023-07-29 15:59:06 +02:00
|
|
|
|
std::cin >> N;
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2023-07-29 15:59:06 +02:00
|
|
|
|
#endif
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2023-07-29 15:59:06 +02:00
|
|
|
|
while (N-- > 0) {
|
|
|
|
|
solve();
|
2023-07-10 09:53:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 14:39:42 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2023-07-10 09:53:39 +02:00
|
|
|
|
|
2023-07-10 14:23:09 +02:00
|
|
|
|
#endif
|