QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#551365 | #9244. Counting Strings | ucup-team087# | AC ✓ | 1976ms | 60696kb | C++20 | 54.8kb | 2024-09-07 16:36:16 | 2024-09-07 16:36:18 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
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); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(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>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#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) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = 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;
(check(x) ? ok : ng) = 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;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') { minus = 1, c = ibuf[pil++]; }
}
x = 0;
while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) { obuf[por++] = '-', x = -x; }
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __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 3 "main.cpp"
#line 2 "library/ds/my_bitset.hpp"
// https://codeforces.com/contest/914/problem/F
// https://yukicoder.me/problems/no/142
// わずかに普通の bitset より遅いときもあるようだが,
// 固定長にしたくないときや slice 操作が必要なときに使う
struct My_Bitset {
using T = My_Bitset;
int N;
vc<u64> dat;
// x で埋める
My_Bitset(int N = 0, int x = 0) : N(N) {
assert(x == 0 || x == 1);
u64 v = (x == 0 ? 0 : -1);
dat.assign((N + 63) >> 6, v);
if (N) dat.back() >>= (64 * len(dat) - N);
}
int size() { return N; }
void resize(int size) {
dat.resize((size + 63) >> 6);
int remainingBits = size & 63;
if (remainingBits != 0) {
u64 mask = (u64(1) << remainingBits) - 1;
dat.back() &= mask;
}
N = size;
}
// thanks to chatgpt!
class Proxy {
public:
Proxy(vc<u64> &d, int i) : dat(d), index(i) {}
operator bool() const { return (dat[index >> 6] >> (index & 63)) & 1; }
Proxy &operator=(u64 value) {
dat[index >> 6] &= ~(u64(1) << (index & 63));
dat[index >> 6] |= (value & 1) << (index & 63);
return *this;
}
void flip() {
dat[index >> 6] ^= (u64(1) << (index & 63)); // XOR to flip the bit
}
private:
vc<u64> &dat;
int index;
};
Proxy operator[](int i) { return Proxy(dat, i); }
bool operator==(const T &p) {
assert(N == p.N);
FOR(i, len(dat)) if (dat[i] != p.dat[i]) return false;
return true;
}
T &operator&=(const T &p) {
assert(N == p.N);
FOR(i, len(dat)) dat[i] &= p.dat[i];
return *this;
}
T &operator|=(const T &p) {
assert(N == p.N);
FOR(i, len(dat)) dat[i] |= p.dat[i];
return *this;
}
T &operator^=(const T &p) {
assert(N == p.N);
FOR(i, len(dat)) dat[i] ^= p.dat[i];
return *this;
}
T operator&(const T &p) const { return T(*this) &= p; }
T operator|(const T &p) const { return T(*this) |= p; }
T operator^(const T &p) const { return T(*this) ^= p; }
T operator~() const {
T p = (*this);
p.flip_range(0, N);
return p;
}
int count() {
int ans = 0;
for (u64 val: dat) ans += popcnt(val);
return ans;
}
int dot(T &p) {
assert(N == p.N);
int ans = 0;
FOR(i, len(dat)) ans += popcnt(dat[i] & p.dat[i]);
return ans;
}
int dot_mod_2(T &p) {
assert(N == p.N);
int ans = 0;
FOR(i, len(dat)) ans ^= popcnt_mod_2(dat[i] & p.dat[i]);
return ans;
}
int next(int i) {
chmax(i, 0);
if (i >= N) return N;
int k = i >> 6;
{
u64 x = dat[k];
int s = i & 63;
x = (x >> s) << s;
if (x) return (k << 6) | lowbit(x);
}
FOR(idx, k + 1, len(dat)) {
if (dat[idx] == 0) continue;
return (idx << 6) | lowbit(dat[idx]);
}
return N;
}
int prev(int i) {
chmin(i, N - 1);
if (i <= -1) return -1;
int k = i >> 6;
if ((i & 63) < 63) {
u64 x = dat[k];
x &= (u64(1) << ((i & 63) + 1)) - 1;
if (x) return (k << 6) | topbit(x);
--k;
}
FOR_R(idx, k + 1) {
if (dat[idx] == 0) continue;
return (idx << 6) | topbit(dat[idx]);
}
return -1;
}
My_Bitset range(int L, int R) {
assert(L <= R);
My_Bitset p(R - L);
int rm = (R - L) & 63;
FOR(rm) {
p[R - L - 1] = bool((*this)[R - 1]);
--R;
}
int n = (R - L) >> 6;
int hi = L & 63;
int lo = 64 - hi;
int s = L >> 6;
if (hi == 0) {
FOR(i, n) { p.dat[i] ^= dat[s + i]; }
} else {
FOR(i, n) { p.dat[i] ^= (dat[s + i] >> hi) ^ (dat[s + i + 1] << lo); }
}
return p;
}
int count_range(int L, int R) {
assert(L <= R);
int cnt = 0;
while ((L < R) && (L & 63)) cnt += (*this)[L++];
while ((L < R) && (R & 63)) cnt += (*this)[--R];
int l = L >> 6, r = R >> 6;
FOR(i, l, r) cnt += popcnt(dat[i]);
return cnt;
}
// [L,R) に p を代入
void assign_to_range(int L, int R, My_Bitset &p) {
assert(p.N == R - L);
int a = 0, b = p.N;
while (L < R && (L & 63)) { (*this)[L++] = bool(p[a++]); }
while (L < R && (R & 63)) { (*this)[--R] = bool(p[--b]); }
// p[a:b] を [L:R] に
int l = L >> 6, r = R >> 6;
int s = a >> 6, t = b >> t;
int n = r - l;
if (!(a & 63)) {
FOR(i, n) dat[l + i] = p.dat[s + i];
} else {
int hi = a & 63;
int lo = 64 - hi;
FOR(i, n) dat[l + i] = (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
}
}
// [L,R) に p を xor
void xor_to_range(int L, int R, My_Bitset &p) {
assert(p.N == R - L);
int a = 0, b = p.N;
while (L < R && (L & 63)) {
dat[L >> 6] ^= u64(p[a]) << (L & 63);
++a, ++L;
}
while (L < R && (R & 63)) {
--b, --R;
dat[R >> 6] ^= u64(p[b]) << (R & 63);
}
// p[a:b] を [L:R] に
int l = L >> 6, r = R >> 6;
int s = a >> 6, t = b >> t;
int n = r - l;
if (!(a & 63)) {
FOR(i, n) dat[l + i] ^= p.dat[s + i];
} else {
int hi = a & 63;
int lo = 64 - hi;
FOR(i, n) dat[l + i] ^= (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
}
}
// 行列基本変形で使うやつ
// p は [i:N) にしかないとして p を xor する
void xor_suffix(int i, My_Bitset &p) {
assert(N == p.N && 0 <= i && i < N);
FOR(k, i / 64, len(dat)) { dat[k] ^= p.dat[k]; }
}
// [L,R) に p を and
void and_to_range(int L, int R, My_Bitset &p) {
assert(p.N == R - L);
int a = 0, b = p.N;
while (L < R && (L & 63)) {
if (!p[a]) (*this)[L] = 0;
a++, L++;
}
while (L < R && (R & 63)) {
--b, --R;
if (!p[b]) (*this)[R] = 0;
}
// p[a:b] を [L:R] に
int l = L >> 6, r = R >> 6;
int s = a >> 6, t = b >> t;
int n = r - l;
if (!(a & 63)) {
FOR(i, n) dat[l + i] &= p.dat[s + i];
} else {
int hi = a & 63;
int lo = 64 - hi;
FOR(i, n) dat[l + i] &= (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
}
}
// [L,R) に p を or
void or_to_range(int L, int R, My_Bitset &p) {
assert(p.N == R - L);
int a = 0, b = p.N;
while (L < R && (L & 63)) {
dat[L >> 6] |= u64(p[a]) << (L & 63);
++a, ++L;
}
while (L < R && (R & 63)) {
--b, --R;
dat[R >> 6] |= u64(p[b]) << (R & 63);
}
// p[a:b] を [L:R] に
int l = L >> 6, r = R >> 6;
int s = a >> 6, t = b >> t;
int n = r - l;
if (!(a & 63)) {
FOR(i, n) dat[l + i] |= p.dat[s + i];
} else {
int hi = a & 63;
int lo = 64 - hi;
FOR(i, n) dat[l + i] |= (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
}
}
// [L,R) を 1 に変更
void set_range(int L, int R) {
while (L < R && (L & 63)) { set(L++); }
while (L < R && (R & 63)) { set(--R); }
FOR(i, L >> 6, R >> 6) dat[i] = u64(-1);
}
// [L,R) を 1 に変更
void reset_range(int L, int R) {
while (L < R && (L & 63)) { reset(L++); }
while (L < R && (R & 63)) { reset(--R); }
FOR(i, L >> 6, R >> 6) dat[i] = u64(0);
}
// [L,R) を flip
void flip_range(int L, int R) {
while (L < R && (L & 63)) { flip(L++); }
while (L < R && (R & 63)) { flip(--R); }
FOR(i, L >> 6, R >> 6) dat[i] ^= u64(-1);
}
// bitset に仕様を合わせる
void set(int i) { (*this)[i] = 1; }
void reset(int i) { (*this)[i] = 0; }
void flip(int i) { (*this)[i].flip(); }
void set() {
fill(all(dat), u64(-1));
resize(N);
}
void reset() { fill(all(dat), 0); }
void flip() {
FOR(i, len(dat) - 1) { dat[i] = u64(-1) ^ dat[i]; }
int i = len(dat) - 1;
FOR(k, 64) {
if (64 * i + k >= size()) break;
flip(64 * i + k);
}
}
bool any() {
FOR(i, len(dat)) {
if (dat[i]) return true;
}
return false;
}
int _Find_first() { return next(0); }
int _Find_next(int p) { return next(p + 1); }
static string TO_STR[256];
string to_string() const {
if (TO_STR[0].empty()) precompute();
string S;
for (auto &x: dat) { FOR(i, 8) S += TO_STR[(x >> (8 * i) & 255)]; }
S.resize(N);
return S;
}
static void precompute() {
FOR(s, 256) {
string x;
FOR(i, 8) x += '0' + (s >> i & 1);
TO_STR[s] = x;
}
}
};
string My_Bitset::TO_STR[256];
#line 2 "library/nt/primetable.hpp"
template <typename T = int>
vc<T> primetable(int LIM) {
++LIM;
const int S = 32768;
static int done = 2;
static vc<T> primes = {2}, sieve(S + 1);
if (done < LIM) {
done = LIM;
primes = {2}, sieve.assign(S + 1, 0);
const int R = LIM / 2;
primes.reserve(int(LIM / log(LIM) * 1.1));
vc<pair<int, int>> cp;
for (int i = 3; i <= S; i += 2) {
if (!sieve[i]) {
cp.eb(i, i * i / 2);
for (int j = i * i; j <= S; j += 2 * i) sieve[j] = 1;
}
}
for (int L = 1; L <= R; L += S) {
array<bool, S> block{};
for (auto& [p, idx]: cp)
for (int i = idx; i < S + L; idx = (i += p)) block[i - L] = 1;
FOR(i, min(S, R - L)) if (!block[i]) primes.eb((L + i) * 2 + 1);
}
}
int k = LB(primes, LIM + 1);
return {primes.begin(), primes.begin() + k};
}
#line 3 "library/nt/lpf_table.hpp"
// [0, LIM], 0, 1 には -1 が入る。
vc<int> lpf_table(ll LIM) {
auto primes = primetable(LIM);
vc<int> res(LIM + 1, -1);
FOR_R(i, len(primes)) {
auto p = primes[i];
FOR3(j, 1, LIM / p + 1) res[p * j] = p;
}
return res;
}
#line 2 "library/nt/factor.hpp"
#line 2 "library/random/base.hpp"
u64 RNG_64() {
static uint64_t x_
= uint64_t(chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count())
* 10150724397891781847ULL;
x_ ^= x_ << 7;
return x_ ^= x_ >> 9;
}
u64 RNG(u64 lim) { return RNG_64() % lim; }
ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
#line 2 "library/mod/mongomery_modint.hpp"
// odd mod.
// x の代わりに rx を持つ
template <int id, typename U1, typename U2>
struct Mongomery_modint {
using mint = Mongomery_modint;
inline static U1 m, r, n2;
static constexpr int W = numeric_limits<U1>::digits;
static void set_mod(U1 mod) {
assert(mod & 1 && mod <= U1(1) << (W - 2));
m = mod, n2 = -U2(m) % m, r = m;
FOR(5) r *= 2 - m * r;
r = -r;
assert(r * m == U1(-1));
}
static U1 reduce(U2 b) { return (b + U2(U1(b) * r) * m) >> W; }
U1 x;
Mongomery_modint() : x(0) {}
Mongomery_modint(U1 x) : x(reduce(U2(x) * n2)){};
U1 val() const {
U1 y = reduce(x);
return y >= m ? y - m : y;
}
mint &operator+=(mint y) {
x = ((x += y.x) >= m ? x - m : x);
return *this;
}
mint &operator-=(mint y) {
x -= (x >= y.x ? y.x : y.x - m);
return *this;
}
mint &operator*=(mint y) {
x = reduce(U2(x) * y.x);
return *this;
}
mint operator+(mint y) const { return mint(*this) += y; }
mint operator-(mint y) const { return mint(*this) -= y; }
mint operator*(mint y) const { return mint(*this) *= y; }
bool operator==(mint y) const {
return (x >= m ? x - m : x) == (y.x >= m ? y.x - m : y.x);
}
bool operator!=(mint y) const { return not operator==(y); }
mint pow(ll n) const {
assert(n >= 0);
mint y = 1, z = *this;
for (; n; n >>= 1, z *= z)
if (n & 1) y *= z;
return y;
}
};
template <int id>
using Mongomery_modint_32 = Mongomery_modint<id, u32, u64>;
template <int id>
using Mongomery_modint_64 = Mongomery_modint<id, u64, u128>;
#line 3 "library/nt/primetest.hpp"
bool primetest(const u64 x) {
assert(x < u64(1) << 62);
if (x == 2 or x == 3 or x == 5 or x == 7) return true;
if (x % 2 == 0 or x % 3 == 0 or x % 5 == 0 or x % 7 == 0) return false;
if (x < 121) return x > 1;
const u64 d = (x - 1) >> lowbit(x - 1);
using mint = Mongomery_modint_64<202311020>;
mint::set_mod(x);
const mint one(u64(1)), minus_one(x - 1);
auto ok = [&](u64 a) -> bool {
auto y = mint(a).pow(d);
u64 t = d;
while (y != one && y != minus_one && t != x - 1) y *= y, t <<= 1;
if (y != minus_one && t % 2 == 0) return false;
return true;
};
if (x < (u64(1) << 32)) {
for (u64 a: {2, 7, 61})
if (!ok(a)) return false;
} else {
for (u64 a: {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
if (!ok(a)) return false;
}
}
return true;
}
#line 5 "library/nt/factor.hpp"
template <typename mint>
ll rho(ll n, ll c) {
assert(n > 1);
const mint cc(c);
auto f = [&](mint x) { return x * x + cc; };
mint x = 1, y = 2, z = 1, q = 1;
ll g = 1;
const ll m = 1LL << (__lg(n) / 5);
for (ll r = 1; g == 1; r <<= 1) {
x = y;
FOR(r) y = f(y);
for (ll k = 0; k < r && g == 1; k += m) {
z = y;
FOR(min(m, r - k)) y = f(y), q *= x - y;
g = gcd(q.val(), n);
}
}
if (g == n) do {
z = f(z);
g = gcd((x - z).val(), n);
} while (g == 1);
return g;
}
ll find_prime_factor(ll n) {
assert(n > 1);
if (primetest(n)) return n;
FOR(100) {
ll m = 0;
if (n < (1 << 30)) {
using mint = Mongomery_modint_32<20231025>;
mint::set_mod(n);
m = rho<mint>(n, RNG(0, n));
} else {
using mint = Mongomery_modint_64<20231025>;
mint::set_mod(n);
m = rho<mint>(n, RNG(0, n));
}
if (primetest(m)) return m;
n = m;
}
assert(0);
return -1;
}
// ソートしてくれる
vc<pair<ll, int>> factor(ll n) {
assert(n >= 1);
vc<pair<ll, int>> pf;
FOR(p, 2, 100) {
if (p * p > n) break;
if (n % p == 0) {
ll e = 0;
do { n /= p, e += 1; } while (n % p == 0);
pf.eb(p, e);
}
}
while (n > 1) {
ll p = find_prime_factor(n);
ll e = 0;
do { n /= p, e += 1; } while (n % p == 0);
pf.eb(p, e);
}
sort(all(pf));
return pf;
}
vc<pair<ll, int>> factor_by_lpf(ll n, vc<int>& lpf) {
vc<pair<ll, int>> res;
while (n > 1) {
int p = lpf[n];
int e = 0;
while (n % p == 0) {
n /= p;
++e;
}
res.eb(p, e);
}
return res;
}
#line 7 "main.cpp"
#line 2 "library/string/suffix_array.hpp"
#line 2 "library/alg/monoid/min.hpp"
template <typename E>
struct Monoid_Min {
using X = E;
using value_type = X;
static constexpr X op(const X &x, const X &y) noexcept { return min(x, y); }
static constexpr X unit() { return infty<E>; }
static constexpr bool commute = true;
};
#line 2 "library/ds/sparse_table/sparse_table.hpp"
// 冪等なモノイドであることを仮定。disjoint sparse table より x 倍高速
template <class Monoid>
struct Sparse_Table {
using MX = Monoid;
using X = typename MX::value_type;
int n, log;
vvc<X> dat;
Sparse_Table() {}
Sparse_Table(int n) { build(n); }
template <typename F>
Sparse_Table(int n, F f) {
build(n, f);
}
Sparse_Table(const vc<X>& v) { build(v); }
void build(int m) {
build(m, [](int i) -> X { return MX::unit(); });
}
void build(const vc<X>& v) {
build(len(v), [&](int i) -> X { return v[i]; });
}
template <typename F>
void build(int m, F f) {
n = m, log = 1;
while ((1 << log) < n) ++log;
dat.resize(log);
dat[0].resize(n);
FOR(i, n) dat[0][i] = f(i);
FOR(i, log - 1) {
dat[i + 1].resize(len(dat[i]) - (1 << i));
FOR(j, len(dat[i]) - (1 << i)) {
dat[i + 1][j] = MX::op(dat[i][j], dat[i][j + (1 << i)]);
}
}
}
X prod(int L, int R) {
if (L == R) return MX::unit();
if (R == L + 1) return dat[0][L];
int k = topbit(R - L - 1);
return MX::op(dat[k][L], dat[k][R - (1 << k)]);
}
template <class F>
int max_right(const F check, int L) {
assert(0 <= L && L <= n && check(MX::unit()));
if (L == n) return n;
int ok = L, ng = n + 1;
while (ok + 1 < ng) {
int k = (ok + ng) / 2;
bool bl = check(prod(L, k));
if (bl) ok = k;
if (!bl) ng = k;
}
return ok;
}
template <class F>
int min_left(const F check, int R) {
assert(0 <= R && R <= n && check(MX::unit()));
if (R == 0) return 0;
int ok = R, ng = -1;
while (ng + 1 < ok) {
int k = (ok + ng) / 2;
bool bl = check(prod(k, R));
if (bl) ok = k;
if (!bl) ng = k;
}
return ok;
}
};
#line 5 "library/string/suffix_array.hpp"
// 辞書順 i 番目の suffix が j 文字目始まりであるとき、
// SA[i] = j, ISA[j] = i
// |S|>0 を前提(そうでない場合 dummy 文字を追加して利用せよ)
struct Suffix_Array {
vc<int> SA;
vc<int> ISA;
vc<int> LCP;
Sparse_Table<Monoid_Min<int>> seg;
bool build_seg;
Suffix_Array(string& s) {
build_seg = 0;
assert(len(s) > 0);
char first = 127, last = 0;
for (auto&& c: s) {
chmin(first, c);
chmax(last, c);
}
SA = calc_suffix_array(s, first, last);
calc_LCP(s);
}
Suffix_Array(vc<int>& s) {
build_seg = 0;
assert(len(s) > 0);
SA = calc_suffix_array(s);
calc_LCP(s);
}
// lcp(S[i:], S[j:])
int lcp(int i, int j) {
if (!build_seg) {
build_seg = true;
seg.build(LCP);
}
int n = len(SA);
if (i == n || j == n) return 0;
if (i == j) return n - i;
i = ISA[i], j = ISA[j];
if (i > j) swap(i, j);
return seg.prod(i, j);
}
// S[i:] との lcp が n 以上であるような半開区間
pair<int, int> lcp_range(int i, int n) {
if (!build_seg) {
build_seg = true;
seg.build(LCP);
}
i = ISA[i];
int a = seg.min_left([&](auto e) -> bool { return e >= n; }, i);
int b = seg.max_right([&](auto e) -> bool { return e >= n; }, i);
return {a, b + 1};
}
// -1: S[L1:R1) < S[L2, R2)
// 0: S[L1:R1) = S[L2, R2)
// +1: S[L1:R1) > S[L2, R2)
int compare(int L1, int R1, int L2, int R2) {
int n1 = R1 - L1, n2 = R2 - L2;
int n = lcp(L1, L2);
if (n == n1 && n == n2) return 0;
if (n == n1) return -1;
if (n == n2) return 1;
return (ISA[L1 + n] > ISA[L2 + n] ? 1 : -1);
}
private:
void induced_sort(const vc<int>& vect, int val_range, vc<int>& SA,
const vc<bool>& sl, const vc<int>& lms_idx) {
vc<int> l(val_range, 0), r(val_range, 0);
for (int c: vect) {
if (c + 1 < val_range) ++l[c + 1];
++r[c];
}
partial_sum(l.begin(), l.end(), l.begin());
partial_sum(r.begin(), r.end(), r.begin());
fill(SA.begin(), SA.end(), -1);
for (int i = (int)lms_idx.size() - 1; i >= 0; --i)
SA[--r[vect[lms_idx[i]]]] = lms_idx[i];
for (int i: SA)
if (i >= 1 && sl[i - 1]) SA[l[vect[i - 1]]++] = i - 1;
fill(r.begin(), r.end(), 0);
for (int c: vect) ++r[c];
partial_sum(r.begin(), r.end(), r.begin());
for (int k = (int)SA.size() - 1, i = SA[k]; k >= 1; --k, i = SA[k])
if (i >= 1 && !sl[i - 1]) { SA[--r[vect[i - 1]]] = i - 1; }
}
vc<int> SA_IS(const vc<int>& vect, int val_range) {
const int n = vect.size();
vc<int> SA(n), lms_idx;
vc<bool> sl(n);
sl[n - 1] = false;
for (int i = n - 2; i >= 0; --i) {
sl[i] = (vect[i] > vect[i + 1] || (vect[i] == vect[i + 1] && sl[i + 1]));
if (sl[i] && !sl[i + 1]) lms_idx.push_back(i + 1);
}
reverse(lms_idx.begin(), lms_idx.end());
induced_sort(vect, val_range, SA, sl, lms_idx);
vc<int> new_lms_idx(lms_idx.size()), lms_vec(lms_idx.size());
for (int i = 0, k = 0; i < n; ++i)
if (!sl[SA[i]] && SA[i] >= 1 && sl[SA[i] - 1]) {
new_lms_idx[k++] = SA[i];
}
int cur = 0;
SA[n - 1] = cur;
for (size_t k = 1; k < new_lms_idx.size(); ++k) {
int i = new_lms_idx[k - 1], j = new_lms_idx[k];
if (vect[i] != vect[j]) {
SA[j] = ++cur;
continue;
}
bool flag = false;
for (int a = i + 1, b = j + 1;; ++a, ++b) {
if (vect[a] != vect[b]) {
flag = true;
break;
}
if ((!sl[a] && sl[a - 1]) || (!sl[b] && sl[b - 1])) {
flag = !((!sl[a] && sl[a - 1]) && (!sl[b] && sl[b - 1]));
break;
}
}
SA[j] = (flag ? ++cur : cur);
}
for (size_t i = 0; i < lms_idx.size(); ++i) lms_vec[i] = SA[lms_idx[i]];
if (cur + 1 < (int)lms_idx.size()) {
auto lms_SA = SA_IS(lms_vec, cur + 1);
for (size_t i = 0; i < lms_idx.size(); ++i) {
new_lms_idx[i] = lms_idx[lms_SA[i]];
}
}
induced_sort(vect, val_range, SA, sl, new_lms_idx);
return SA;
}
vc<int> calc_suffix_array(const string& s, const char first = 'a',
const char last = 'z') {
vc<int> vect(s.size() + 1);
copy(begin(s), end(s), begin(vect));
for (auto& x: vect) x -= (int)first - 1;
vect.back() = 0;
auto ret = SA_IS(vect, (int)last - (int)first + 2);
ret.erase(ret.begin());
return ret;
}
vc<int> calc_suffix_array(const vc<int>& s) {
vc<int> ss = s;
UNIQUE(ss);
vc<int> vect(s.size() + 1);
copy(all(s), vect.begin());
for (auto& x: vect) x = LB(ss, x) + 1;
vect.back() = 0;
auto ret = SA_IS(vect, MAX(vect) + 2);
ret.erase(ret.begin());
return ret;
}
template <typename STRING>
void calc_LCP(const STRING& s) {
int n = s.size(), k = 0;
ISA.resize(n);
LCP.resize(n);
for (int i = 0; i < n; i++) ISA[SA[i]] = i;
for (int i = 0; i < n; i++, k ? k-- : 0) {
if (ISA[i] == n - 1) {
k = 0;
continue;
}
int j = SA[ISA[i] + 1];
while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
LCP[ISA[i]] = k;
}
LCP.resize(n - 1);
}
};
#line 1 "library/string/suffix_tree.hpp"
#line 1 "library/seq/cartesian_tree.hpp"
/*
辞書順で高さを unique して、木にしている。
極大長方形アルゴリズムで線形時間構築。
*/
template <typename T, bool IS_MIN>
struct CartesianTree {
int n;
vc<T>& A;
vc<pair<int, int>> range;
vc<int> lch, rch, par;
int root;
CartesianTree(vc<T>& A) : n(len(A)), A(A) {
range.assign(n, {-1, -1});
lch.assign(n, -1);
rch.assign(n, -1);
par.assign(n, -1);
if (n == 1) {
range[0] = {0, 1};
root = 0;
return;
}
auto is_sm = [&](int i, int j) -> bool {
if (IS_MIN) return (A[i] < A[j]) || (A[i] == A[j] && i < j);
return (A[i] > A[j]) || (A[i] == A[j] && i < j);
};
vc<int> st;
FOR(i, n) {
while (!st.empty() && is_sm(i, st.back())) {
lch[i] = st.back();
st.pop_back();
}
range[i].fi = (st.empty() ? 0 : st.back() + 1);
st.eb(i);
}
st.clear();
FOR_R(i, n) {
while (!st.empty() && is_sm(i, st.back())) {
rch[i] = st.back();
st.pop_back();
}
range[i].se = (st.empty() ? n : st.back());
st.eb(i);
}
FOR(i, n) if (lch[i] != -1) par[lch[i]] = i;
FOR(i, n) if (rch[i] != -1) par[rch[i]] = i;
FOR(i, n) if (par[i] == -1) root = i;
}
// (l, r, h)
tuple<int, int, T> maximum_rectangle(int i) {
auto [l, r] = range[i];
return {l, r, A[i]};
}
// (l, r, h)
T max_rectangle_area() {
assert(IS_MIN);
T res = 0;
FOR(i, n) {
auto [l, r, h] = maximum_rectangle(i);
chmax(res, (r - l) * h);
}
return res;
}
ll count_subrectangle(bool baseline) {
assert(IS_MIN);
ll res = 0;
FOR(i, n) {
auto [l, r, h] = maximum_rectangle(i);
ll x = (baseline ? h : h * (h + 1) / 2);
res += x * (i - l + 1) * (r - i);
}
return res;
}
};
#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 {
static constexpr bool is_directed = directed;
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; }
Graph() : N(0), M(0), prepared(0) {}
Graph(int N) : N(N), M(0), prepared(0) {}
void build(int n) {
N = n, M = 0;
prepared = 0;
edges.clear();
indptr.clear();
csr_edges.clear();
vc_deg.clear();
vc_indeg.clear();
vc_outdeg.clear();
}
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;
}
#ifdef FASTIO
// 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();
}
#endif
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];
}
#ifdef FASTIO
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);
}
}
#endif
vc<int> new_idx;
vc<bool> used_e;
// G における頂点 V[i] が、新しいグラフで i になるようにする
// {G, es}
// sum(deg(v)) の計算量になっていて、
// 新しいグラフの n+m より大きい可能性があるので注意
Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
if (len(new_idx) != N) new_idx.assign(N, -1);
int n = len(V);
FOR(i, n) new_idx[V[i]] = i;
Graph<T, directed> G(n);
vc<int> history;
FOR(i, n) {
for (auto&& e: (*this)[V[i]]) {
if (len(used_e) <= e.id) used_e.resize(e.id + 1);
if (used_e[e.id]) continue;
int a = e.frm, b = e.to;
if (new_idx[a] != -1 && new_idx[b] != -1) {
history.eb(e.id);
used_e[e.id] = 1;
int eid = (keep_eid ? e.id : -1);
G.add(new_idx[a], new_idx[b], e.cost, eid);
}
}
}
FOR(i, n) new_idx[V[i]] = -1;
for (auto&& eid: history) used_e[eid] = 0;
G.build();
return G;
}
Graph<T, true> to_directed_tree(int root = -1) {
if (root == -1) root = 0;
assert(!is_directed && prepared && M == N - 1);
Graph<T, true> G1(N);
vc<int> par(N, -1);
auto dfs = [&](auto& dfs, int v) -> void {
for (auto& e: (*this)[v]) {
if (e.to == par[v]) continue;
par[e.to] = v, dfs(dfs, e.to);
}
};
dfs(dfs, root);
for (auto& e: edges) {
int a = e.frm, b = e.to;
if (par[a] == b) swap(a, b);
assert(par[b] == a);
G1.add(a, b, e.cost);
}
G1.build();
return G1;
}
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 5 "library/string/suffix_tree.hpp"
// https://twitter.com/maspy_stars/status/1565901414236205057?s=20&t=S2Tu6ayozHcakxai8dmh4g
// 各ノードは、suffix array での長方形領域と見なして、
// グラフおよび、領域データを作る。
// sample: test/my_test/suffix_tree.test.cpp
template <typename SUFFIX>
pair<Graph<int, 1>, vc<tuple<int, int, int, int>>> suffix_tree(SUFFIX& X) {
auto SA = X.SA;
auto ISA = X.ISA;
auto LCP = X.LCP;
vc<tuple<int, int, int, int>> dat;
vc<pair<int, int>> edges;
int N = len(SA);
if (N == 1) {
Graph<int, 1> G(2);
G.add(0, 1);
G.build();
dat.eb(0, 1, 0, 0), dat.eb(0, 1, 0, 1);
return {G, dat};
}
dat.eb(0, N, 0, 0);
CartesianTree<int, true> CT(LCP);
auto dfs = [&](auto& dfs, int p, int idx, int h) -> void {
int L = CT.range[idx].fi;
int R = CT.range[idx].se + 1;
int hh = LCP[idx];
if (h < hh) {
edges.eb(p, len(dat));
p = len(dat);
dat.eb(L, R, h, hh);
}
if (CT.lch[idx] == -1) {
if (hh < N - SA[idx]) {
edges.eb(p, len(dat));
dat.eb(idx, idx + 1, hh, N - SA[idx]);
}
} else {
dfs(dfs, p, CT.lch[idx], hh);
}
if (CT.rch[idx] == -1) {
if (hh < N - SA[idx + 1]) {
edges.eb(p, len(dat));
dat.eb(idx + 1, idx + 2, hh, N - SA[idx + 1]);
}
} else {
dfs(dfs, p, CT.rch[idx], hh);
}
};
int r = CT.root;
if (LCP[r] > 0) {
edges.eb(0, 1);
dat.eb(0, N, 0, LCP[r]);
dfs(dfs, 1, r, LCP[r]);
} else {
dfs(dfs, 0, r, 0);
}
Graph<int, 1> G(len(dat));
for (auto&& [a, b]: edges) G.add(a, b);
G.build();
return {G, dat};
}
#line 2 "library/graph/tree.hpp"
#line 4 "library/graph/tree.hpp"
// HLD euler tour をとっていろいろ。
template <typename GT>
struct Tree {
using Graph_type = GT;
GT &G;
using WT = typename GT::cost_type;
int N;
vector<int> LID, RID, head, V, parent, VtoE;
vc<int> depth;
vc<WT> depth_weighted;
Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }
void build(int r = 0, bool hld = 1) {
if (r == -1) return; // build を遅延したいとき
N = G.N;
LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
depth.assign(N, -1), depth_weighted.assign(N, 0);
assert(G.is_prepared());
int t1 = 0;
dfs_sz(r, -1, hld);
dfs_hld(r, t1);
}
void dfs_sz(int v, int p, bool hld) {
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;
VtoE[e.to] = e.id;
dfs_sz(e.to, v, hld);
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 ×) {
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 heavy_child(int v) {
int k = LID[v] + 1;
if (k == N) return -1;
int w = V[k];
return (parent[w] == v ? w : -1);
}
int e_to_v(int eid) {
auto e = G.edges[eid];
return (parent[e.frm] == e.to ? e.frm : e.to);
}
int v_to_e(int v) { return VtoE[v]; }
int get_eid(int u, int v) {
if (parent[u] != v) swap(u, v);
assert(parent[u] == v);
return VtoE[u];
}
int ELID(int v) { return 2 * LID[v] - depth[v]; }
int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }
// 目標地点へ進む個数が k
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 la(int u, int v) { return LA(u, v); }
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 meet(int a, int b, int c) { return LCA(a, b) ^ LCA(a, c) ^ LCA(b, c); }
int lca(int u, int v) { return LCA(u, v); }
int subtree_size(int v, int root = -1) {
if (root == -1) return RID[v] - LID[v];
if (v == root) return N;
int x = jump(v, root, 1);
if (in_subtree(v, x)) return RID[v] - LID[v];
return N - RID[x] + LID[x];
}
int dist(int a, int b) {
int c = LCA(a, b);
return depth[a] + depth[b] - 2 * depth[c];
}
WT dist_weighted(int a, int b) {
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<int> collect_light(int v) {
vc<int> res;
bool skip = true;
for (auto &&e: G[v])
if (e.to != parent[v]) {
if (!skip) res.eb(e.to);
skip = false;
}
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;
}
// 辺の列の情報 (frm,to,str)
// str = "heavy_up", "heavy_down", "light_up", "light_down"
vc<tuple<int, int, string>> get_path_decomposition_detail(int u, int v) {
vc<tuple<int, int, string>> up, down;
while (1) {
if (head[u] == head[v]) break;
if (LID[u] < LID[v]) {
if (v != head[v]) down.eb(head[v], v, "heavy_down"), v = head[v];
down.eb(parent[v], v, "light_down"), v = parent[v];
} else {
if (u != head[u]) up.eb(u, head[u], "heavy_up"), u = head[u];
up.eb(u, parent[u], "light_up"), u = parent[u];
}
}
if (LID[u] < LID[v]) down.eb(u, v, "heavy_down");
elif (LID[v] < LID[u]) up.eb(u, v, "heavy_up");
reverse(all(down));
concat(up, 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;
}
// path [a,b] と [c,d] の交わり. 空ならば {-1,-1}.
// https://codeforces.com/problemset/problem/500/G
pair<int, int> path_intersection(int a, int b, int c, int d) {
int ab = lca(a, b), ac = lca(a, c), ad = lca(a, d);
int bc = lca(b, c), bd = lca(b, d), cd = lca(c, d);
int x = ab ^ ac ^ bc, y = ab ^ ad ^ bd; // meet(a,b,c), meet(a,b,d)
if (x != y) return {x, y};
int z = ac ^ ad ^ cd;
if (x != z) x = -1;
return {x, x};
}
};
#line 2 "library/ds/fastset.hpp"
// 64-ary tree
// space: (N/63) * u64
struct FastSet {
static constexpr u32 B = 64;
int n, log;
vvc<u64> seg;
FastSet() {}
FastSet(int n) { build(n); }
int size() { return n; }
template <typename F>
FastSet(int n, F f) {
build(n, f);
}
void build(int m) {
seg.clear();
n = m;
do {
seg.push_back(vc<u64>((m + B - 1) / B));
m = (m + B - 1) / B;
} while (m > 1);
log = len(seg);
}
template <typename F>
void build(int n, F f) {
build(n);
FOR(i, n) { seg[0][i / B] |= u64(f(i)) << (i % B); }
FOR(h, log - 1) {
FOR(i, len(seg[h])) {
seg[h + 1][i / B] |= u64(bool(seg[h][i])) << (i % B);
}
}
}
bool operator[](int i) const { return seg[0][i / B] >> (i % B) & 1; }
void insert(int i) {
for (int h = 0; h < log; h++) {
seg[h][i / B] |= u64(1) << (i % B), i /= B;
}
}
void add(int i) { insert(i); }
void erase(int i) {
u64 x = 0;
for (int h = 0; h < log; h++) {
seg[h][i / B] &= ~(u64(1) << (i % B));
seg[h][i / B] |= x << (i % B);
x = bool(seg[h][i / B]);
i /= B;
}
}
void remove(int i) { erase(i); }
// min[x,n) or n
int next(int i) {
assert(i <= n);
chmax(i, 0);
for (int h = 0; h < log; h++) {
if (i / B == seg[h].size()) break;
u64 d = seg[h][i / B] >> (i % B);
if (!d) {
i = i / B + 1;
continue;
}
i += lowbit(d);
for (int g = h - 1; g >= 0; g--) {
i *= B;
i += lowbit(seg[g][i / B]);
}
return i;
}
return n;
}
// max [0,x], or -1
int prev(int i) {
assert(i >= -1);
if (i >= n) i = n - 1;
for (int h = 0; h < log; h++) {
if (i == -1) break;
u64 d = seg[h][i / B] << (63 - i % B);
if (!d) {
i = i / B - 1;
continue;
}
i -= __builtin_clzll(d);
for (int g = h - 1; g >= 0; g--) {
i *= B;
i += topbit(seg[g][i / B]);
}
return i;
}
return -1;
}
bool any(int l, int r) { return next(l) < r; }
// [l, r)
template <typename F>
void enumerate(int l, int r, F f) {
for (int x = next(l); x < r; x = next(x + 1)) f(x);
}
string to_string() {
string s(n, '?');
for (int i = 0; i < n; ++i) s[i] = ((*this)[i] ? '1' : '0');
return s;
}
};
#line 13 "main.cpp"
constexpr int th = 1000;
using BS = My_Bitset;
int MEMO[13000][256];
void solve() {
FOR(block, 13000) {
FOR(i, 8) {
FOR(s, 1 << i) { MEMO[block][s | 1 << i] = MEMO[block][s] + (1 + 8 * block + i); }
}
}
LL(N);
STR(S);
Suffix_Array X(S);
ll ANS = 0;
auto [G, dat] = suffix_tree(X);
// すべてが good とした場合の ANS
for (auto& [a, b, c, d]: dat) {
// (c+1)+...+d
ANS += ll(c + d + 1) * (d - c) / 2;
}
FastSet yet(N);
FOR(i, N) yet.insert(i);
auto lpf = lpf_table(1 << 18);
vc<BS> SMALL_P(th);
FOR(p, th) {
if (lpf[p] == p) {
BS x(N + 1);
for (int i = 0; i <= N; i += p) x[i] = 1;
SMALL_P[p] = x;
}
}
auto get = [&](int a) -> BS {
yet.erase(a);
int n = X.SA[a] + 1; // index
// あとで
BS x(N + 1);
for (auto& [p, e]: factor_by_lpf(n, lpf)) {
if (p < th)
x |= SMALL_P[p];
else {
for (int i = 0; i <= N; i += p) x[i] = 1;
}
}
return x;
};
Tree<decltype(G)> tree(G);
auto dfs = [&](auto& dfs, int v) -> BS {
assert(tree.head[v] == v);
auto path = tree.heavy_path_at(v);
reverse(all(path));
BS x(N + 1, 1);
FOR(i, len(path)) {
int v = path[i];
for (auto& c: tree.collect_light(v)) {
BS y = dfs(dfs, c);
x &= y;
}
auto [a, b, c, d] = dat[v];
yet.enumerate(a, b, [&](int i) -> void { x &= get(i); });
while (c < d && c % 64 != 0) {
if (x[c]) ANS -= 1 + c;
c++;
}
while (c < d && d % 64 != 0) {
--d;
if (x[d]) ANS -= 1 + d;
}
if (c == d) continue;
int L = c / 64, R = d / 64;
FOR(b, L, R) {
u64 s = x.dat[b];
FOR(i, 8) ANS -= MEMO[b * 8 + i][s >> (8 * i) & 255];
}
// ながさ c+1,...,d
// FOR(i, c, d) {
// if (x[i]) { ANS -= 1 + i; }
// }
}
return x;
};
dfs(dfs, 0);
print(ANS);
}
signed main() {
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 17880kb
input:
4 abca
output:
14
result:
ok answer is '14'
Test #2:
score: 0
Accepted
time: 3ms
memory: 17744kb
input:
1 a
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 6ms
memory: 17804kb
input:
2 aa
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 6ms
memory: 17812kb
input:
2 ab
output:
3
result:
ok answer is '3'
Test #5:
score: 0
Accepted
time: 3ms
memory: 17824kb
input:
100 xgljgljgljjljjjjljtjljtgljgljgljjljjjjljtjljtjljgljljgljgljjljjjjljtjljtjljgljllljgllgljgljjglljgljl
output:
101808
result:
ok answer is '101808'
Test #6:
score: 0
Accepted
time: 0ms
memory: 17736kb
input:
100 ilhliaiehaiehldgeieieedveldgeaeaehldgeldgeiiedeiaiehaiehldgeieieedveiaehldgeihleiaeaehldgeiaeaeeheia
output:
103718
result:
ok answer is '103718'
Test #7:
score: 0
Accepted
time: 0ms
memory: 17724kb
input:
100 xoakgbazaclazfrmucgodlhrvazkyrqcwufonvcmqpvulhuudtmcfhsklletywchvvrxrjfgsfaoozzouzwfrtdlryfiqdtzjkcp
output:
104574
result:
ok answer is '104574'
Test #8:
score: 0
Accepted
time: 6ms
memory: 18044kb
input:
100 aabbaabbabaaabaaaaaabababbbabaabaaabaaabaaaabbbbababbbbbbabbbaabbbaaaaababababaabababaababaabbbabaaa
output:
103589
result:
ok answer is '103589'
Test #9:
score: 0
Accepted
time: 0ms
memory: 18252kb
input:
2000 mbrpuyrsqimuuwnmxsukdkfmhwytmfwwccfdkzljulnvlueciggqniuyocqxoiepzuzhnfwwccvmxyticsttujuzhnfwwccfwkbuuecinfwwccfwkbuueciggqniuyodfkhnfwwccfdkzljulnvlueciggqniuyocqccfwkbuueciggquyciggqniuyodfkevrpjzuzwyocqccfwkbuueciggquyciggqniuyodfkevrpjzuzhnfwwcoiynpzlqsjimovvcrzbggnciggqniuyodfkevrpjzuzhnfwy...
output:
801214345
result:
ok answer is '801214345'
Test #10:
score: 0
Accepted
time: 7ms
memory: 18252kb
input:
2000 kqxjsrvosiglekiyqcvcuziktmldotulfsjttakesboiiuwwukcuytllrixkibipmcfkibipmcfchmczrunxluomocoaltfiknghuglwiychueqazfcalzqgwoqeyifsawnaennubfacviqcwhstxgvjfggcluomocuomocoareueqazfcalzqgwoaxfchmczrunxecifuecidmpavuecidmpavxzysvebqavozoqsnnhimpjgcqnwfzhysnnaevxreouaxyykcuynghuglygfjcvyggcluomocuomo...
output:
806947518
result:
ok answer is '806947518'
Test #11:
score: 0
Accepted
time: 7ms
memory: 18272kb
input:
2000 uwgwftwgqszqrzzokbabeqpmnhlthazkxhncmmrkbhueafpsncvtpvxoxaatarvrmnpnkkrafkwzchacxcuphbwkmbtrxtydpsjzsvkskprttbyonkhwdsckvgtqvtjixayxggktqbwkhrcujsxfwiahxexnbjnzulzmpmubiqzbphrbpmvjjikcqftgnvzxzpzimpmidcmeescxhtqbukkwppipuumhpbyywdooxblckfuartpvrehkjspsscztazgtmpvqjpmjmezhroympynptcjcpvtzesfmair...
output:
812517617
result:
ok answer is '812517617'
Test #12:
score: 0
Accepted
time: 4ms
memory: 18060kb
input:
2000 aaababaaabaaaabbbaaabbaabaabbababaababbababbbbbbabaaaabbbbbbbabbbaabbababbaaabaababbababbbaaabbbabbaabbbaaabbabbabbbbabbbababaaaabbabbababaaabbbbbbababbbbabbbaababbabaabbbbababaaaababaaabbbabbaabaaabababaaababbbaabaaabbbbbabbaaaabbaabababbaaabbbbbaababbabaaaaaabababbaaabbbbabbbaaaababbabbbaaaba...
output:
812460124
result:
ok answer is '812460124'
Test #13:
score: 0
Accepted
time: 1965ms
memory: 36004kb
input:
100000 mglkvngcyzmvyrpxumiusfvkzutlgexoiyjezqsdudzbjxyovuhocbjeyhgjlncvsihuopxevcrvlmphgtmibfvqaffrgrpshxprppojmhvhfxffnscxprhrckqjefohfjadbasuksrljfonckgvvynyyhwtktgonksetyjxftgxhfyplekgmgtinfhslcmgxiiorcgndimffpvolzfrqnpdaijdkujoaqgwoowxkivrtboylhdvenwiqxbfovydkidseplcyqhheinoqrghnqilwrgkcxpkdzjrx...
output:
101324985069108
result:
ok answer is '101324985069108'
Test #14:
score: 0
Accepted
time: 1954ms
memory: 36012kb
input:
100000 knrammmidsuxwygkfulairkwldjfxyovcnfgxtajosuafyjflkjmzjfniohxucagrmthceicngqrasgcskanqrfkuqxeggafhlpxkicokvuatkxlduldrxkmhdiwxrjukqcpfbiuskbfejjxfafxpibpjzfycuaaoaerajqspchthdgnmhqwdqvkqfubyoibcflddbwbpvbtmomopuovdcbgdnifkkewxixmtcagsfifbnlrajtuccsxrjuqrphuoldurcnjwqwraoulyxsqsjkaxacouwujpyqfe...
output:
101324985069554
result:
ok answer is '101324985069554'
Test #15:
score: 0
Accepted
time: 261ms
memory: 28112kb
input:
40000 mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...
output:
6463823387870
result:
ok answer is '6463823387870'
Test #16:
score: 0
Accepted
time: 250ms
memory: 26384kb
input:
40000 wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww...
output:
6382800423488
result:
ok answer is '6382800423488'
Test #17:
score: 0
Accepted
time: 274ms
memory: 28260kb
input:
40000 bbbabbbbbbaabbaabaaaababaabaaabbbaaabaabbaaababbabbbbaabbaaababbbaababbaaabbabaaabbabbbbbbbbabaaaaaaabbabaababaabababaaaabaabaabbbbbbbaaaabaababbbbbaabbaabbaababbbbaaabaabbabbabbbaabaabbbbaabbabbbabababbbaaabbbaaababaaaaabbaaabaabaaabbabaaabbaabbaaabababaaabaabaaabaabbaabaabaabaabaababbaabbaaa...
output:
6485120267266
result:
ok answer is '6485120267266'
Test #18:
score: 0
Accepted
time: 27ms
memory: 26172kb
input:
40000 tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt...
output:
800020000
result:
ok answer is '800020000'
Test #19:
score: 0
Accepted
time: 1914ms
memory: 44228kb
input:
100000 ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...
output:
101137073335748
result:
ok answer is '101137073335748'
Test #20:
score: 0
Accepted
time: 1865ms
memory: 43536kb
input:
100000 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...
output:
100461213430599
result:
ok answer is '100461213430599'
Test #21:
score: 0
Accepted
time: 1976ms
memory: 35892kb
input:
100000 bslghenpredjtkgndijltrmysucihsrsnselcsrumqotigyzviasrrickbbtxylubpeqjkcbzerviihnnfymdhgpongdqkpfqwrblqzxdbecktaezedfndyncabehsgoxashszbyqbfnolnbcmsdaulgdyvhfpctmhdbfycfqgfoprbnsqosocnqxiwhvtmfrvxydutmasdmbshbknusybepunclxtynonodldbrgvcatizjscrifzbjfmwrbfedntreoumkuacuszsulqebqfloydlhabbhbtjnw...
output:
101324985069047
result:
ok answer is '101324985069047'
Test #22:
score: 0
Accepted
time: 194ms
memory: 60696kb
input:
100000 owalzrsepmooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...
output:
66609812613
result:
ok answer is '66609812613'
Test #23:
score: 0
Accepted
time: 1957ms
memory: 41440kb
input:
100000 swtpnyrtrjjvecymbvpjkcraazjzwjnawoihpmfnjkrhbnqbpgnfldgjuuesdtwipkvxqhfcjgyurqxsbnsfquesnjpyisnvjleuflxcovfiblfkixliqflqvswyvxrfjfoopdjsdowjsrwkokguvlqrrdfxfakqdnjrmtdxvzczvovsjhvelaizfasgyjvyudsyjkrassxoheuhfbbxdorxivdzgztosybvbaffyibkvjxdnluowqyyknsicqmvqjfnvhxqriftehsugfabpbszfvqyehuekphxi...
output:
101130039817037
result:
ok answer is '101130039817037'
Test #24:
score: 0
Accepted
time: 1914ms
memory: 45236kb
input:
100000 whogzkfhreoscnrbfzczzmpapeieazzzzzagazzayapzzzzaqfoacfffitsithrtnytiegycwzczzaytsxivfiiiveeezzaqfoaqfoacdtitfffiiiqchietnypeieafzaucwqfoacdttsithrtnyiiiqfuxiveeeuuaslaazzwzzaazzwzzzzzagazzayapzzzzaqfoacfffitsithrtnytiegycwzczzaytszztsitqfoacdttsithrtndiitfffiiiqcyapecdttsithaazoatazzayaaqfoac...
output:
100955554850350
result:
ok answer is '100955554850350'
Test #25:
score: 0
Accepted
time: 141ms
memory: 38928kb
input:
100000 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
5000050000
result:
ok answer is '5000050000'
Test #26:
score: 0
Accepted
time: 1624ms
memory: 38196kb
input:
99996 hfaeeqetfftvwktktfftaettttutjetjtjetjetktfftvatfjeljtakttttktfftvwklaettftvftjetjetktklftvjutjetjtjetjetvwklaettftvjutjetjjtftjetjtttttktjttljfftvwklaettfttftvjutjetjjtftjetjetktklfttvjutjetjettjeftfjeljtakttttktfftvwklaettftvftjetjetktklftvjutjetjtjetjetvwklaettftvjutjetjjtftjetjtttttktjttljf...
output:
97148038053410
result:
ok answer is '97148038053410'
Test #27:
score: 0
Accepted
time: 1423ms
memory: 42968kb
input:
99997 hazaorzbkzqhymcexwahmkkexwackcokahrzcexwahmcokazaorwahmcookxccokahrzcexwahcokahrskehmcorclclmkahrzcexwahmcokazaorwahmcookwcexwakokacoahmcookwahmcookxccokahrzcexwahmcokazaorwahxccokahrzcexwahmcokazaocokwamluorwahmcookwcexwahrzcxwahmcokwamlurclclskkxccokahrzcxhrzcexwahmcokazaorwahmzcexwaaorwahma...
output:
89901430986589
result:
ok answer is '89901430986589'
Test #28:
score: 0
Accepted
time: 1555ms
memory: 45792kb
input:
99998 ptkbpqxysqlmgpoyfjxysogysqlmgxgpogsystgmqysosgposqggtlmgxmgtgsqlmgysqggqxqlbsttsgposqlssysgytposgsqlmmqxmgpogsystgysmqxmmsgtggtpoyggtggtpospogjxysmqxysqlmgxmgtggpogsystgmqysosgposqlssgtmgxmgxmgtggtpospogjxysmqxysqlmgxmgtggtpostggtpogysqlmgysqggqxggtlmfjtgggslbsgtmgxmgxmgtggtpospogjxysmogtggtlm...
output:
93788469111158
result:
ok answer is '93788469111158'
Test #29:
score: 0
Accepted
time: 1673ms
memory: 42928kb
input:
99998 iddudaoqdudakrdanwwakrwdnoqduddanpakrwuuqakrdnpugaanpakrwuuqakrddanwwakrwdnoqduddanpaugaanpakrwuuqakrddanwwakrwdnoqduddakrddanwwakrwdnoqduddanpakrqduddanpaugaanpakrwuuqakrddanwwakrwdnduddanpakrwuuqakrdnpnpugakrwdnoqduddanpakrwuuqakrdnpnpunanwwakrwdnoqduddauoquoqnnwwwuuopurwuupuddakrddanwwakrwd...
output:
97357749831441
result:
ok answer is '97357749831441'
Extra Test:
score: 0
Extra Test Passed