fast io
#include <cctype>
#include <concepts>
#include <cstring>
#include <iostream>
using namespace std;
struct fast_input {
static constexpr unsigned N = (1 << 23);
char s[N];
unsigned i, n;
char read_char() {
if (i == n) {
cin.read(s, N), n = cin.gcount(), i = 0;
}
return s[i++];
}
template <signed_integral T>
fast_input& operator>>(T& x) {
char c;
for (; !isdigit(c = read_char()) && c != '-';) {
}
bool f = c == '-';
if (f) {
c = read_char();
}
for (x = 0; isdigit(c); x = x * 10 + c - '0', c = read_char()) {
}
if (f) {
x = -x;
}
return *this;
}
template <unsigned_integral T>
fast_input& operator>>(T& x) {
char c;
for (; !isdigit(c = read_char());) {
}
for (x = 0; isdigit(c); x = x * 10 + c - '0', c = read_char()) {
}
return *this;
}
fast_input& operator>>(char &x) {
for (; isspace(x = read_char()); ) {
}
return *this;
}
fast_input& operator>>(string &x) {
x.clear();
char c;
for (; isspace(c = read_char()); ) {
}
for (; !isspace(c); x.push_back(c), c = read_char()) {
}
return *this;
}
} fin;
struct fast_output {
static constexpr unsigned N = (1 << 23);
char s[N];
unsigned n;
~fast_output() { flush(); }
void put_char(char c) {
if (n == N) {
flush();
}
s[n++] = c;
}
void flush() { cout.write(s, n), n = 0; }
template <signed_integral T>
fast_output& operator<<(T x) {
if (x == 0) {
put_char('0');
return *this;
}
if (x < 0) {
put_char('-');
x = -x;
}
static char v[20];
int t = 0;
for (; x; v[t++] = x % 10 + '0', x /= 10) {
}
for (; t; put_char(v[--t])) {
}
return *this;
}
template <unsigned_integral T>
fast_output& operator<<(T x) {
if (x == 0) {
put_char('0');
return *this;
}
static char v[20];
int t = 0;
for (; x; v[t++] = x % 10 + '0', x /= 10) {
}
for (; t; put_char(v[--t])) {
}
return *this;
}
fast_output& operator<<(char x) {
put_char(x);
return *this;
}
fast_output& operator<<(const string& x) {
auto p = x.data();
auto xn = x.size();
for (; n + xn > N; flush()) {
unsigned m = N - n;
memcpy(s + n, p, m), n += m, p += m, xn -= m;
}
memcpy(s + n, p, xn), n += xn;
return *this;
}
fast_output& operator<<(const char* x) {
auto xn = strlen(x);
for (; n + xn > N; flush()) {
unsigned m = N - n;
memcpy(s + n, x, m), n += m, x += m, xn -= m;
}
memcpy(s + n, x, xn), n += xn;
return *this;
}
} fout;