#define AUTO_GENERATED
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/runenumerate/
#include "../../../src/io/fastin/lib.hpp"
#include "../../../src/io/fastout/lib.hpp"
#include "../../../src/str/run/hash/lib.hpp"
using namespace tifa_libs;
CEXP u32 MOD = 998244353;
#include "../../../src/math/ds/mint/ms/lib.hpp"
#include "../../../src/str/hash/substr2/lib.hpp"
using namespace tifa_libs;
using mint = mint_ms<MOD>;
using namespace tifa_libs;
using mint0 = mint_ms<998244353>;
using mint1 = mint_ms<1000000007>;
using hashstr = hash_substr2<mint0, mint1>;
int main() {
strn s;
tifa_libs::fin_uint >> s;
auto res = tifa_libs::run_hash<hashstr>(s);
tifa_libs::fout << res.size() << '\n';
for (auto& [a, b, c] : res) tifa_libs::fout << a << ' ' << b << ' ' << c << '\n';
return 0;
}
#line 1 "test/cpv/library-checker-string/runenumerate.mints-ms.hashstr-hashstr2s.cpp"
#define AUTO_GENERATED
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/runenumerate/
#line 2 "src/io/fastin/lib.hpp"
#line 2 "src/util/alias/others/lib.hpp"
#line 2 "src/util/consts/lib.hpp"
#line 2 "src/util/alias/num/lib.hpp"
#line 2 "src/util/util/lib.hpp"
// https://github.com/Tiphereth-A/CP-lib
#include <bits/extc++.h>
// clang-format off
namespace tifa_libs {
#define CEXP constexpr
#define CEXPE constexpr explicit
#define CR const&
#define CP const*
#define PC *const
#define CPC const*const
#define TPN typename
#define NE noexcept
#define CNE const noexcept
#define ND [[nodiscard]]
#define cT_(...) std::conditional_t<sizeof(__VA_ARGS__) <= sizeof(size_t) * 2, __VA_ARGS__, __VA_ARGS__ CR>
// NOLINTNEXTLINE(misc-const-correctness)
#define flt_(T, i, l, r, ...) for (T i = (l), i##e = (r)__VA_OPT__(, ) __VA_ARGS__; i < i##e; ++i)
#define retif_(cond, if_true, ...) if cond return if_true __VA_OPT__(; else return __VA_ARGS__)
#ifdef ONLINE_JUDGE
#undef assert
#define assert(x) 42
#endif
using namespace std::ranges;
using namespace std::literals;
template <class T>
CEXP T abs(T x) NE { retif_((x < 0), -x, x); }
} // namespace tifa_libs
// clang-format on
#line 4 "src/util/alias/num/lib.hpp"
// clang-format off
namespace tifa_libs {
#define mk0_(w, t) using w = t; using c##w = const t
#define mk_(w, t) mk0_(w, t); CEXP w operator""_##w(unsigned long long x) NE { return (w)x; }
mk_(i8, int8_t) mk_(u8, uint8_t) mk_(i16, int16_t) mk_(u16, uint16_t) mk_(i32, int32_t) mk_(u32, uint32_t) mk_(i64, int64_t) mk_(u64, uint64_t) mk_(isz, ssize_t) mk_(usz, size_t) mk_(chr, char) mk_(schr, signed char) mk_(uchr, unsigned char) mk_(sint, signed) mk_(uint, unsigned);
mk0_(i128, __int128_t); mk0_(u128, __uint128_t); mk0_(f32, float); mk0_(f64, double); mk0_(f128, long double);
#undef mk0_
#undef mk_
} // namespace tifa_libs
// clang-format on
#line 4 "src/util/consts/lib.hpp"
// clang-format off
namespace tifa_libs {
using std::numbers::pi_v;
template <std::floating_point FP>
inline FP eps_v = std::sqrt(std::numeric_limits<FP>::epsilon());
template <std::floating_point FP>
CEXP void set_eps(FP v) NE { eps_v<FP> = v; }
CEXP u32 TIME = ((__TIME__[0] & 15) << 20) | ((__TIME__[1] & 15) << 16) | ((__TIME__[3] & 15) << 12) | ((__TIME__[4] & 15) << 8) | ((__TIME__[6] & 15) << 4) | (__TIME__[7] & 15);
CEXP auto STR2U16 = [] { std::array<u32, 65536> table{}; table.fill(-1_u32); flt_ (u32, i, 48, 58) flt_ (u32, j, 48, 58) table[i << 8 | j] = (j & 15) * 10 + (i & 15); return table; }();
inline const auto fn_0 = [](auto&&...) NE {};
inline const auto fn_is0 = [](auto x) NE { return x == 0; };
} // namespace tifa_libs
// clang-format on
#line 4 "src/util/alias/others/lib.hpp"
namespace tifa_libs {
template <class T>
struct chash {
CEXP static u64 C = u64(pi_v<f128> * 2e18) | 71;
CEXP u64 operator()(T x) CNE { return __builtin_bswap64(((u64)x ^ TIME) * C); }
};
// clang-format off
#define mk_(w, t) using w = t; using c##w = const t;
mk_(strn, std::string) mk_(strnv, std::string_view)
#undef mk_
template <class T> struct edge_t { T w; u32 u, v; CEXP auto operator<=>(edge_t CR) const = default; }; template <class T> using cedge_t = const edge_t<T>;
template <class T> struct pt3 { T _0, _1, _2; CEXP auto operator<=>(pt3 CR) const = default; }; template <class T> using cpt3 = const pt3<T>;
template <class T> struct pt4 { T _0, _1, _2, _3; CEXP auto operator<=>(pt4 CR) const = default; }; template <class T> using cpt4 = const pt4<T>;
#define mkT_(w, t, ...) template <class T> using w = t __VA_OPT__(, ) __VA_ARGS__; template <class T> using c##w = const t __VA_OPT__(, ) __VA_ARGS__;
mkT_(ptt, std::pair<T, T>) mkT_(alc, std::pmr::polymorphic_allocator<T>) mkT_(vec, std::vector<T>) mkT_(vvec, vec<vec<T>>) mkT_(v3ec, vvec<vec<T>>) mkT_(vecpt, vec<ptt<T>>) mkT_(vvecpt, vvec<ptt<T>>) mkT_(ptvec, ptt<vec<T>>) mkT_(ptvvec, ptt<vvec<T>>)
#undef mkT_
template <class T> using itl = std ::initializer_list<T>;
template <class T, usz ext = std::dynamic_extent> using spn = std::span<T const, ext>;
template <class T, usz N> using arr = std::array<T, N>; template <class T, usz N> using carr = std::array<const T, N>;
template <class U, class T> using vecp = vec<std::pair<U, T>>; template <class U, class T> using vvecp = vvec<std::pair<U, T>>;
template <class U, class T> using vvecp = vvec<std::pair<U, T>>; template <class U, class T> using vvvecp = vvec<vvec<std::pair<U, T>>>;
#ifdef PB_DS_ASSOC_CNTNR_HPP
template <class T, class C = std::less<T>> using set = __gnu_pbds::tree<T, __gnu_pbds::null_type, C>;
template <class K, class V, class C = std::less<K>> using map = __gnu_pbds::tree<K, V, C>;
// hset<u64> s({}, {}, {}, {}, {1<<16});
template <class T, class HF = chash<T>> using hset = __gnu_pbds::gp_hash_table<T, __gnu_pbds::null_type, HF>;
// hmap<u64, int> s({}, {}, {}, {}, {1<<16});
template <class K, class V, class HF = chash<K>> using hmap = __gnu_pbds::gp_hash_table<K, V, HF>;
#else
using std::set, std::map;
template <class T, class HF = chash<T>> using hset = std::unordered_set<T, HF>;
template <class K, class V, class HF = chash<K>> using hmap = std::unordered_map<K, V, HF>;
#endif
#ifdef PB_DS_PRIORITY_QUEUE_HPP
template <class T, class C = std::less<T>> using pq = __gnu_pbds::priority_queue<T, C>;
#else
template <class T, class C = std::less<T>> using pq = std::priority_queue<T, vec<T>, C>;
#endif
template <class T> using pqg = pq<T, std::greater<T>>;
// clang-format on
#define mk1_(V, A, T) using V##A = V<T>;
#define mk_(V, A, T) mk1_(V, A, T) mk1_(c##V, A, T)
#define mk(A, T) mk_(edge_t, A, T) mk_(ptt, A, T) mk_(pt3, A, T) mk_(pt4, A, T) mk_(vec, A, T) mk_(vvec, A, T) mk_(v3ec, A, T) mk_(vecpt, A, T) mk_(vvecpt, A, T) mk_(ptvec, A, T) mk_(ptvvec, A, T) mk1_(spn, A, T) mk1_(itl, A, T)
mk(b, bool) mk(c, chr) mk(i, i32) mk(u, u32) mk(ii, i64) mk(uu, u64) mk(t, isz) mk(z, usz) mk(f, f32) mk(d, f64) mk(s, strn);
#undef mk
#undef mk_
#undef mk1_
} // namespace tifa_libs
#line 2 "src/util/traits/math/lib.hpp"
// clang-format off
#line 4 "src/util/traits/math/lib.hpp"
namespace tifa_libs {
template <class T> concept char_c = std::same_as<T, char> || std::same_as<T, signed char> || std::same_as<T, unsigned char>;
#pragma GCC diagnostic ignored "-Wpedantic"
template <class T> concept s128_c = std::same_as<T, __int128_t> || std::same_as<T, __int128>;
template <class T> concept u128_c = std::same_as<T, __uint128_t> || std::same_as<T, unsigned __int128>;
template <class T> concept i128_c = s128_c<T> || u128_c<T>;
#pragma GCC diagnostic warning "-Wpedantic"
template <class T> concept imost64_c = std::integral<T> && sizeof(T) * __CHAR_BIT__ <= 64;
template <class T> concept smost64_c = imost64_c<T> && std::signed_integral<T>;
template <class T> concept umost64_c = imost64_c<T> && std::unsigned_integral<T>;
template <class T> concept int_c = i128_c<T> || imost64_c<T>;
template <class T> concept sint_c = s128_c<T> || smost64_c<T>;
template <class T> concept uint_c = u128_c<T> || umost64_c<T>;
template <class T> concept arithm_c = std::is_arithmetic_v<T> || int_c<T>;
template <class T> concept mint_c = requires(T x) { {x.mod()} -> uint_c; {x.val()} -> uint_c; };
template <class T> concept dft_c = requires(T x, std::vector<TPN T::data_t> v, u32 n) { {x.size()} -> std::same_as<u32>; x.bzr(n); x.dif(v, n); x.dit(v, n); };
template <class T> concept ntt_c = dft_c<T> && requires(T x) { T::max_size; T::G; };
template <class T> struct to_sint : std::make_signed<T> {};
template <> struct to_sint<u128> { using type = i128; };
template <> struct to_sint<i128> { using type = i128; };
template <class T> using to_sint_t = TPN to_sint<T>::type;
template <class T> struct to_uint : std::make_unsigned<T> {};
template <> struct to_uint<u128> { using type = u128; };
template <> struct to_uint<i128> { using type = u128; };
template <class T> using to_uint_t = TPN to_uint<T>::type;
template <arithm_c T> struct to_bigger : std::make_unsigned<T> {};
#define _(w,ww) template <> struct to_bigger<w> { using type = ww; }
#define _2(w,ww) _(i##w,i##ww); _(u##w,u##ww);
_2(8, 16); _2(16, 32); _2(32, 64); _2(64, 128); _(f32, f64); _(f64, f128);
#undef _2
#undef _
template <class T> using to_bigger_t = TPN to_bigger<T>::type;
template <arithm_c T> CEXP T inf_v = [] {
if CEXP(sint_c<T>) return T(to_uint_t<T>(-1) / 4 - 1);
else if CEXP(uint_c<T>) return T(-1) / 2 - 1;
else return std::numeric_limits<T>::max() / 2 - 1;
}();
} // namespace tifa_libs
// clang-format on
#line 5 "src/io/fastin/lib.hpp"
#ifdef __linux__
#include <sys/mman.h>
#include <sys/stat.h>
#endif
namespace tifa_libs {
struct fastin_data {
CEXP static u32 BUF = 0x200005;
FILE* f_ = nullptr;
#ifdef __linux__
chr *bg, *ed, *p;
struct stat Fl;
void rebind(FILE* f = nullptr) NE {
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
if (!f_) munmap(bg, Fl.st_size + 1);
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
if (!f) return;
auto fd = fileno(f_ = f);
fstat(fd, &Fl);
p = (bg = (chr*)mmap(nullptr, Fl.st_size + 4, PROT_READ, MAP_PRIVATE, fd, 0));
ed = bg + Fl.st_size;
madvise(bg, Fl.st_size + 4, MADV_SEQUENTIAL);
}
ND bool iseof() CNE { return p == ed; }
~fastin_data() NE { rebind(); }
#else
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
chr buf[BUF], *ed, *p;
void rebind(FILE* f) NE { f_ = f, p = ed = buf; }
ND bool iseof() NE {
if (p == ed) [[unlikely]]
ed = (p = buf) + fread(buf, 1, BUF, f_);
return p == ed;
}
#endif
fastin_data(FILE* f = stdin) NE { assert(f), rebind(f); }
fastin_data(fastin_data CR) = delete;
fastin_data& operator=(fastin_data CR) = delete;
};
// clang-format off
enum FIN_SET : u8 { FS_NEWLINE = 1, FS_SPACE = 2, FS_NEG = 4, FS_NUM = 8, FS_ALPHA = 16, FS_OTHERS = 32 };
// clang-format on
template <u32 charset>
class fastin {
fastin_data& data;
static CEXP bool is_cntrl(chr c) NE {
if CEXP (charset & FS_OTHERS) return iscntrl(c);
else if CEXP (charset & FS_NEWLINE) return c < 32;
else return false;
}
static CEXP bool is_cntrls(chr c) NE {
if CEXP (charset & FS_OTHERS) return !isgraph(c);
else if CEXP (charset & (FS_NEWLINE | FS_SPACE)) return c <= 32;
else return false;
}
static CEXP bool is_digit(chr c) NE {
if CEXP (charset & (FS_ALPHA | FS_OTHERS)) return isdigit(c);
else if CEXP (!(charset & FS_NUM)) return false;
else if CEXP (!(charset & FS_NEG)) return c > 32;
else return c >= 48;
}
static CEXP bool is_neg_digit(chr c) NE {
if CEXP (!(charset & FS_NEG)) return is_digit(c);
else if CEXP (charset & (FS_ALPHA | FS_OTHERS)) return c == '-' || isdigit(c);
else return c > 32;
}
#ifdef __linux__
template <bool ignore_space = true>
void read_str(strn& n) NE {
chr* l;
if CEXP (ignore_space) {
skip_cntrls(), l = data.p;
while (!is_cntrls(*data.p)) ++data.p;
} else {
skip_cntrl(), l = data.p;
while (!is_cntrl(*data.p)) ++data.p;
}
n.assign(l, data.p);
}
#else
template <bool ignore_space>
void read_str(strn& n) NE {
if CEXP (n.clear(); ignore_space) {
n.push_back(skip_cntrls().get());
while (!is_cntrls(peek())) n.push_back(get());
} else {
n.push_back(skip_cntrl().get());
while (!is_cntrl(peek())) n.push_back(get());
}
}
#endif
public:
fastin(fastin_data& data) NE : data(data) {}
fastin(fastin CR) = delete;
fastin& operator=(fastin CR) = delete;
chr peek() NE {
if (data.iseof()) [[unlikely]]
return EOF;
return *data.p;
}
chr get_unchk() NE { return *data.p++; }
chr get() NE {
if (data.iseof()) [[unlikely]]
return EOF;
return get_unchk();
}
#define SKIP(name, pred) \
fastin& skip_##name() NE { \
while (pred(peek())) get_unchk(); \
return *this; \
}
SKIP(cntrl, is_cntrl)
SKIP(cntrls, is_cntrls)
SKIP(ndigit, !is_digit)
SKIP(nnegdigit, !is_neg_digit)
#undef SKIP
template <class T>
requires(imost64_c<T> && !char_c<T>)
fastin& operator>>(T& n) NE {
if CEXP (std::same_as<T, bool>) n = skip_ndigit().get() != '0';
else {
n = 0;
bool is_neg = false;
if CEXP ((charset & FS_NEG) && std::signed_integral<T>) is_neg = (skip_nnegdigit().peek() == '-' && get_unchk());
else skip_ndigit();
std::conditional_t<sizeof(T) < sizeof(u32), u32, to_uint_t<T>> n_ = 0;
#ifdef __linux__
// clang-format off
#define _ {while (~STR2U16[*(u16*)data.p]) (n_ *= 100) += STR2U16[*(u16*)data.p], data.p += 2; if (is_digit(peek())) (n_ *= 10) += get_unchk() & 15;}
if ((usz)data.p & 1) { if (is_digit(peek())) [[likely]] { (n_ *= 10) += get_unchk() & 15; _ } } else _;
#undef _
// clang-format on
#else
while (is_digit(peek())) (n_ *= 10) += get_unchk() & 15;
#endif
if CEXP (sint_c<T>)
if (is_neg) n_ = -n_;
n = (T)n_;
}
return *this;
}
fastin& operator>>(std::floating_point auto& n) NE {
static strn s;
(*this >> s), std::from_chars(begin(s).base(), end(s).base(), n);
return *this;
}
//! ignore cntrl and space
fastin& operator>>(char_c auto& n) NE {
n = skip_cntrls().get();
return *this;
}
fastin& operator>>(strn& n) NE {
read_str<true>(n);
return *this;
}
fastin& getline(strn& n) NE {
read_str<false>(n);
return *this;
}
//! NOT ignore cntrl and space
fastin& strict_read(char_c auto& n) NE {
n = get();
return *this;
}
fastin& operator>>(fastin& (*func)(fastin&)) NE { return func(*this); }
};
inline fastin_data fid_stdin;
inline fastin<FS_NEWLINE | FS_SPACE | FS_NEG | FS_NUM | FS_ALPHA | FS_OTHERS> fin(fid_stdin);
inline fastin<FS_NEWLINE | FS_SPACE | FS_NEG | FS_NUM> fin_int(fid_stdin);
inline fastin<FS_NEWLINE | FS_SPACE | FS_NUM> fin_uint(fid_stdin);
template <u32 w>
inline fastin<w>& ws(fastin<w>& f) NE { return f.skip_cntrls(); }
} // namespace tifa_libs
#line 2 "src/io/fastout/lib.hpp"
#line 5 "src/io/fastout/lib.hpp"
namespace tifa_libs {
class fastout {
CEXP static u32 BUF = 0x200005, INTBUF = 63;
FILE* f_ = nullptr;
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
chr int_buf[INTBUF];
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
chr buf[BUF], *p;
chr CPC ed = buf + BUF;
std::chars_format fmt = std::chars_format::general;
int precision = 6;
fastout& write_str(chr CP n, usz len = 0) NE {
if (!len) len = strlen(n);
usz l_;
chr CP n_ = n;
while (p + len >= ed) memcpy(p, n_, l_ = usz(ed - p)), p += l_, n_ += l_, len -= l_, flush();
return memcpy(p, n_, len), p += len, *this;
}
public:
fastout(FILE* f = stdout) NE { rebind(f); }
fastout(fastout CR) = delete;
fastout& operator=(fastout CR) = delete;
~fastout() NE { flush(); }
void rebind(FILE* f) NE { f_ = f, p = buf; }
void flush() NE { fwrite(buf, 1, usz(p - buf), f_), p = buf; }
fastout& operator<<(char_c auto n) NE {
if (p == ed) [[unlikely]]
flush();
*(p++) = n;
return *this;
}
fastout& operator<<(chr CP n) NE { return write_str(n); }
fastout& operator<<(strn CR str) NE { return write_str(str.data(), str.size()); }
fastout& operator<<(strnv str) NE { return write_str(str.data(), str.size()); }
template <class T>
requires(smost64_c<T> && !char_c<T>)
fastout& operator<<(T n) NE {
if CEXP (sizeof(T) < sizeof(i32)) return *this << (i32)n;
else {
if (n < 0) return *this << '-' << -to_uint_t<T>(n);
return *this << to_uint_t<T>(n);
}
}
template <class T>
requires(umost64_c<T> && !char_c<T>)
fastout& operator<<(T n) NE {
if CEXP (std::same_as<T, bool>) return *this << (chr(n | '0'));
else if CEXP (sizeof(T) < sizeof(u32)) return *this << (u32)n;
else if (usz(p - buf) >= BUF - INTBUF) [[unlikely]] {
auto res = std::to_chars(int_buf, int_buf + INTBUF, n);
return write_str(int_buf, usz(res.ptr - int_buf));
} else {
auto res = std::to_chars(p, buf + BUF, n);
p = res.ptr;
return *this;
}
}
fastout& operator<<(std::floating_point auto n) NE {
if (usz(p - buf) >= BUF - INTBUF) [[unlikely]] {
auto res = std::to_chars(int_buf, int_buf + INTBUF, n, fmt, precision);
return write_str(int_buf, usz(res.ptr - int_buf));
} else {
auto res = std::to_chars(p, buf + BUF, n, fmt, precision);
p = res.ptr;
return *this;
}
}
fastout& setf(std::chars_format f) NE {
fmt = f;
return *this;
}
//! only tested in libstdc++
fastout& operator<<(decltype(std::setprecision(0)) p) NE {
precision = *(int*)(&p);
return *this;
}
fastout& operator<<(fastout& (*func)(fastout&)) NE { return func(*this); }
};
inline fastout fout;
inline fastout& scientific(fastout& f) NE { return f.setf(std::chars_format::scientific); }
inline fastout& fixed(fastout& f) NE { return f.setf(std::chars_format::fixed); }
inline fastout& hexfloat(fastout& f) NE { return f.setf(std::chars_format::hex); }
inline fastout& defaultfloat(fastout& f) NE { return f.setf(std::chars_format::general); }
inline fastout& endl(fastout& f) NE {
(f << '\n').flush();
return f;
}
using std::setprecision;
} // namespace tifa_libs
#line 2 "src/str/run/hash/lib.hpp"
#line 2 "src/edh/discretization/lib.hpp"
#line 2 "src/fast/rsort32/lib.hpp"
#line 4 "src/fast/rsort32/lib.hpp"
namespace tifa_libs {
template <class C>
requires(std::is_array_v<C> && std::integral<decltype(std::declval<C>()[0])> && sizeof(std::declval<C>()[0]) == 4) || (std::contiguous_iterator<TPN C::iterator> && std::integral<TPN C::value_type> && sizeof(TPN C::value_type) == 4)
void rsort32(C& a) NE {
if (a.size() <= 1) return;
if (a.size() <= 200'000) {
std::ranges::sort(a);
return;
}
arr<u32, 256> _0{}, _1{}, _2{}, _3{};
cu32 n = (u32)a.size();
vecu b(n);
u32 *a_ = (u32*)a.data(), *b_ = (u32*)b.data();
for (cu32 *_ = a_ + n, *i = a_; i < _; ++i) ++_0[*i & 255], ++_1[*i >> 8 & 255], ++_2[*i >> 16 & 255], ++_3[*i >> 24 & 255];
flt_ (u32, i, 1, 256) _0[i] += _0[i - 1], _1[i] += _1[i - 1], _2[i] += _2[i - 1], _3[i] += _3[i - 1];
for (u32 CP i = a_ + n; --i >= a_;) b_[--_0[*i & 255]] = *i;
for (u32 CP i = b_ + n; --i >= b_;) a_[--_1[*i >> 8 & 255]] = *i;
for (u32 CP i = a_ + n; --i >= a_;) b_[--_2[*i >> 16 & 255]] = *i;
for (u32 CP i = b_ + n; --i >= b_;) a_[--_3[*i >> 24 & 255]] = *i;
if CEXP (std::is_signed_v<TPN C::value_type>) {
u32 i = n;
while (i && a[i - 1] < 0) --i;
rotate(a_, a_ + n, a_ + i);
}
}
template <class C>
requires(std::is_array_v<C> && std::integral<decltype(std::declval<C>()[0])> && sizeof(std::declval<C>()[0]) == 4) || range<C>
void sort(C& a) NE {
if CEXP (std::is_array_v<C> || (std::contiguous_iterator<TPN C::iterator> && std::integral<TPN C::value_type> && sizeof(TPN C::value_type) == 4)) rsort32(a);
else std::ranges::sort(a);
}
} // namespace tifa_libs
#line 4 "src/edh/discretization/lib.hpp"
namespace tifa_libs {
template <common_range T>
CEXP T uniq(T v) NE {
tifa_libs::sort(v);
auto r = unique(begin(v), end(v));
return {begin(v), begin(r)};
}
template <common_range T>
CEXP std::pair<T, vecu> gen_id(T CR v) NE {
const T _ = uniq(v);
vecu _1;
_1.reserve(v.size());
flt_ (u32, i, 0, (u32)v.size()) _1.push_back(u32(lower_bound(_, v[i]) - begin(_)));
return {_, _1};
}
} // namespace tifa_libs
#line 2 "src/str/hash/lcpf/lib.hpp"
#line 4 "src/str/hash/lcpf/lib.hpp"
namespace tifa_libs {
// @return length of longest common prefix of suffixes a[i, a.size()) and b[j, b.size())
template <class hashstr_t>
CEXP u32 lcpf_hash(hashstr_t CR a, hashstr_t CR b, u32 i, u32 j, u32 lmax = 0) NE {
if (!lmax) lmax = (u32)max(a.size(), b.size());
u32 l = 0, r = min({lmax, a.size() - i, b.size() - j}) + 1;
while (l + 1 < r) {
cu32 m = (l + r) / 2;
(a.get(i, m) == b.get(j, m) ? l : r) = m;
}
return l;
}
} // namespace tifa_libs
#line 2 "src/str/hash/lcsf/lib.hpp"
#line 4 "src/str/hash/lcsf/lib.hpp"
namespace tifa_libs {
// @return length of longest common suffix of prefixes a[0, i) and b[0, j)
template <class hashstr_t>
CEXP u32 lcsf_hash(hashstr_t CR a, hashstr_t CR b, u32 i, u32 j, u32 lmax = 0) NE {
if (!lmax) lmax = (u32)max(a.size(), b.size());
u32 l = 0, r = min({lmax, i, j}) + 1;
while (l + 1 < r) {
cu32 m = (l + r) / 2;
(a.get(i - m, m) == b.get(j - m, m) ? l : r) = m;
}
return l;
}
} // namespace tifa_libs
#line 6 "src/str/run/hash/lib.hpp"
namespace tifa_libs {
// @return {p, l, r}, uniqued
template <class hashstr_t>
CEXP vec<pt3u> run_hash(strnv s) NE {
cu32 n = (u32)s.size();
vecu st(n + 1);
vec<pt3u> runs;
hashstr_t hs;
hs.set(s);
flt_ (u32, inv, 0, 2) {
st[0] = n + 1;
for (u32 i = n, top = 0, lt = 0; i; --i) {
while (top) {
cu32 x = min(st[top] - i, st[top - 1] - st[top]);
lt = s[i - 1] == s[st[top] - 1] ? lcpf_hash(hs, hs, i - 1, st[top] - 1, x) : 0;
if ((lt == x && st[top] - i < st[top - 1] - st[top]) || (lt < x && ((s[i + lt - 1] < s[st[top] + lt - 1]) ^ inv))) {
--top;
lt = 0;
} else break;
}
cu32 j = st[top], x = i > 1 && s[i - 2] == s[j - 2] ? lcsf_hash(hs, hs, i - 1, j - 1, j - i) : 0;
if (st[++top] = i; x < j - i)
if (u32 y = s[i + lt - 1] == s[j + lt - 1] ? lt + lcpf_hash(hs, hs, i + lt - 1, j + lt - 1, n) : lt;
x + y >= j - i) runs.emplace_back(j - i, i - x - 1, j + y - 1);
}
}
return uniq(runs);
}
} // namespace tifa_libs
#line 6 "test/cpv/library-checker-string/runenumerate.mints-ms.hashstr-hashstr2s.cpp"
using namespace tifa_libs;
CEXP u32 MOD = 998244353;
#line 2 "src/math/ds/mint/ms/lib.hpp"
#line 2 "src/nt/mod/montgomery/lib.hpp"
#line 4 "src/nt/mod/montgomery/lib.hpp"
namespace tifa_libs {
template <u32 MOD>
struct montgomery {
static CEXP u32 MOD2 = MOD << 1, R2 = -(u64)(MOD) % MOD, R = [] {
u32 iv = MOD * (2 - MOD * MOD);
iv *= 2 - MOD * iv, iv *= 2 - MOD * iv;
return iv * (MOD * iv - 2);
}();
static_assert(MOD & 1);
static_assert(-R * MOD == 1);
static_assert((MOD >> 30) == 0);
static_assert(MOD != 1);
static CEXP u32 reduce(u64 x) NE { return u32((x + u64((u32)x * R) * MOD) >> 32); }
static CEXP u32 norm(u32 x) NE { return x - (MOD & -((MOD - 1 - x) >> 31)); }
};
template <> // dynamic
struct montgomery<0> {
u32 R, R2, MOD, MOD_ODD, OFFSET, MASK;
CEXP montgomery() NE = default;
CEXPE montgomery(u32 m) NE { reset(m); }
CEXP void reset(u32 m) NE {
for (assert(!(m == 1 || m >> 31)), MOD = MOD_ODD = m, OFFSET = 0; (MOD_ODD & 1) == 0; ++OFFSET, MOD_ODD /= 2);
MASK = (1_u32 << OFFSET) - 1_u32;
u32 iv = MOD_ODD * (2 - MOD_ODD * MOD_ODD);
iv *= 2 - MOD_ODD * iv, iv *= 2 - MOD_ODD * iv, R = iv * (MOD_ODD * iv - 2), R2 = u32(-u64(MOD_ODD) % MOD_ODD);
}
ND CEXP u32 norm(i32 x) CNE { return u32(x + (-(x < 0) & (i32)MOD)); }
ND CEXP u32 reduce(u64 x) CNE {
cu32 t = u32((x + u64((u32)x * R) * MOD_ODD) >> 32);
return t - (MOD_ODD & -((MOD_ODD - 1 - t) >> 31));
}
ND CEXP u32 tsf(u32 x) CNE { retif_((!OFFSET) [[likely]], reduce(u64(x) * R2), reduce(u64(x % MOD_ODD) * R2) << OFFSET | (x & MASK)); }
};
} // namespace tifa_libs
#line 2 "src/math/ds/mint/_base/lib.hpp"
#line 2 "src/nt/inverse/lib.hpp"
#line 2 "src/nt/gl/inv_gcd/lib.hpp"
#line 2 "src/math/safe_mod/lib.hpp"
#line 4 "src/math/safe_mod/lib.hpp"
namespace tifa_libs {
template <int_c T>
CEXP T safe_mod(T x, to_uint_t<T> mod) NE {
if CEXP (sint_c<T>) {
if (x <= -(T)mod || x >= (T)mod) x %= (T)mod;
retif_((x < 0), x + (T)mod, x);
} else {
retif_((x >= mod), x % mod, x);
}
}
} // namespace tifa_libs
#line 2 "src/nt/gl/exgcd/lib.hpp"
#line 4 "src/nt/gl/exgcd/lib.hpp"
namespace tifa_libs {
// Binary exgcd
template <uint_c U, bool only_x = false>
CEXP auto exgcd_b(U a, U b) NE {
using T = to_sint_t<U>;
if CEXP (only_x) {
if (!a) return std::make_tuple(b, (T)0);
if (!b) return std::make_tuple(a, (T)1);
} else {
if (!a) return std::make_tuple(b, (T)0, (T) !!b);
if (!b) return std::make_tuple(a, (T)1, (T)0);
}
auto r = std::__countr_zero(a | b);
a >>= r, b >>= r;
T x = (T)a, y = (T)b, s = 1, t = 0, u = 0, v = 1;
while (x) {
while (!(x & 1))
if (x /= 2; !((s | t) & 1)) s /= 2, t /= 2;
else s = (s + (T)b) / 2, t = (t - (T)a) / 2;
while (!(y & 1))
if (y /= 2; !((u | v) & 1)) u /= 2, v /= 2;
else u = (u + (T)b) / 2, v = (v - (T)a) / 2;
if (x >= y) x -= y, s -= u, t -= v;
else y -= x, u -= s, v -= t;
}
if (y > 1) a /= (U)y, b /= (U)y;
if (a && (U)abs(v) >= a) {
const T _ = v / (T)a;
v -= _ * (T)a, u += _ * (T)b;
}
if (b && (U)abs(u) >= b) {
const T _ = u / (T)b;
u -= _ * (T)b, v += _ * (T)a;
}
if (const T u_ = u + (T)b, v_ = v - (T)a; abs(u_) + abs(v_) <= abs(u) + abs(v)) u = u_, v = v_;
if (const T u_ = u - (T)b, v_ = v + (T)a; abs(u_) + abs(v_) <= abs(u) + abs(v)) u = u_, v = v_;
if CEXP (only_x) return std::make_tuple(U(y << r), u);
else return std::make_tuple(U(y << r), u, v);
}
// @return then return tuple(g, x[, y]) s.t. g = gcd(a, b), xa + yb = g, |x| + |y| is the minimal (primary) and x <= y (secondarily)
template <sint_c T, bool only_x = false>
CEXP auto exgcd(T a, T b) NE {
using U = to_uint_t<T>;
if (auto [x, y] = minmax(a, b); x >= 0 && y <= T(U(-1) >> sizeof(U))) return exgcd_b<U, only_x>((U)a, (U)b);
if CEXP (only_x) {
T s = 1, u = 0;
while (b) {
T c = a / b;
std::tie(s, u, a, b) = std::make_tuple(u, s - u * c, b, a - b * c);
}
return std::make_tuple((U)a, s);
} else {
T s = 1, t = 0, u = 0, v = 1;
while (b) {
T c = a / b;
std::tie(s, t, u, v, a, b) = std::make_tuple(u, v, s - u * c, t - v * c, b, a - b * c);
}
return std::make_tuple((U)a, s, t);
}
}
} // namespace tifa_libs
#line 6 "src/nt/gl/inv_gcd/lib.hpp"
namespace tifa_libs {
template <uint_c T>
CEXP ptt<T> inv_gcd(T n, T mod) NE {
using U = to_sint_t<T>;
auto [g, x] = exgcd<U, true>(U(n % mod), (U)mod);
return {g, safe_mod(x, mod)};
}
} // namespace tifa_libs
#line 4 "src/nt/inverse/lib.hpp"
namespace tifa_libs {
// simple but slower: inv(n, mod) -> 1 < n ? mod - inv(mod % n, n) * mod / n : 1;
template <uint_c T, uint_c U>
CEXP U inverse(T n, U mod) NE {
auto [g, x] = inv_gcd(U(n % mod), mod);
assert(g == 1);
return x;
}
} // namespace tifa_libs
#line 2 "src/util/traits/others/lib.hpp"
// clang-format off
#line 4 "src/util/traits/others/lib.hpp"
namespace tifa_libs {
//! only for template without non-type argument
template <class, template <class...> class> CEXP bool specialized_from_v = false;
template <template <class...> class T, class... Args> CEXP bool specialized_from_v<T<Args...>, T> = true;
static_assert(specialized_from_v<vecu, std::vector>);
template <class T> concept container_c = common_range<T> && !std::is_array_v<std::remove_cvref_t<T>> && !std::same_as<std::remove_cvref_t<T>, strn> && !std::same_as<std::remove_cvref_t<T>, strnv>;
template <class T> concept istream_c = std::derived_from<T, std::istream> || std::derived_from<T, std::wistream> || requires(T is) { is.peek(); };
template <class T> concept ostream_c = std::derived_from<T, std::ostream> || std::derived_from<T, std::wostream> || requires(T os) { os.flush(); };
} // namespace tifa_libs
// clang-format on
#line 5 "src/math/ds/mint/_base/lib.hpp"
namespace tifa_libs::mint_impl_ {
struct mint_tag_base {};
template <std::derived_from<mint_tag_base> tag_t>
struct mint : tag_t {
CEXP mint() = default;
CEXP mint(int_c auto v) NE : tag_t(v) {}
using raw_t = tag_t::raw_t;
using sraw_t = to_sint_t<raw_t>;
static CEXP sraw_t smod() NE { return (sraw_t)tag_t::mod(); }
ND CEXP sraw_t sval() CNE { return (sraw_t)tag_t::val(); }
template <int_c T>
CEXPE operator T() CNE { return (T)tag_t::val(); }
CEXP mint& operator+=(mint CR r) NE {
mint::add(r);
return *this;
}
CEXP mint& operator-=(mint CR r) NE {
mint::sub(r);
return *this;
}
CEXP mint& operator*=(mint CR r) NE {
mint::mul(r);
return *this;
}
CEXP mint& operator/=(mint CR r) NE { return *this = *this * r.inv(); }
CEXP mint CR operator+() CNE { return *this; }
CEXP mint operator-() CNE { return tag_t::template neg<mint>(); }
ND CEXP mint inv() CNE { return inverse(tag_t::val(), tag_t::mod()); }
friend CEXP mint operator+(mint l, mint CR r) NE { return l += r; }
friend CEXP mint operator-(mint l, mint CR r) NE { return l -= r; }
friend CEXP mint operator*(mint l, mint CR r) NE { return l *= r; }
friend CEXP mint operator/(mint l, mint CR r) NE { return l /= r; }
friend CEXP bool operator==(mint CR l, mint CR r) NE { return l.val() == r.val(); }
friend CEXP auto operator<=>(mint CR l, mint CR r) NE { return l.sval() <=> r.sval(); }
friend auto& operator>>(istream_c auto& is, mint& x) NE {
i64 _;
is >> _, x = mint(_);
return is;
}
friend auto& operator<<(ostream_c auto& os, mint CR x) NE { return os << x.val(); }
friend CEXP auto abs(mint CR x) NE { return x.val(); }
};
} // namespace tifa_libs::mint_impl_
#line 5 "src/math/ds/mint/ms/lib.hpp"
namespace tifa_libs {
template <u64 MOD_>
class mint_ms_tag : public mint_impl_::mint_tag_base {
static_assert(MOD_ <= UINT32_MAX);
using core = montgomery<MOD_>;
public:
static CEXP bool FIXED_MOD = true;
protected:
using raw_t = u32;
raw_t v_{};
CEXP mint_ms_tag() NE = default;
CEXP mint_ms_tag(int_c auto v) NE : v_{mod(v)} {}
public:
static CEXP raw_t mod(sint_c auto v) NE {
if CEXP (smost64_c<decltype(v)>) {
retif_((v >= 0 && (u64)v < mod()) [[likely]], core::reduce(u64((raw_t)v) * core::R2));
}
return core::reduce(u64(i32(v % (i32)mod()) + (i32)mod()) * core::R2);
}
static CEXP raw_t mod(uint_c auto v) NE {
if CEXP (umost64_c<decltype(v)>) {
retif_((cu64 x = (u64)v; x < mod()) [[likely]], core::reduce(x * core::R2), core::reduce(u64(x % mod()) * core::R2));
} else retif_((v < mod()) [[likely]], core::reduce(u64((raw_t)v) * core::R2), core::reduce(u64((raw_t)(v % mod())) * core::R2));
}
static CEXP raw_t mod() NE { return MOD_; }
ND CEXP raw_t val() CNE { return core::norm(core::reduce(v_)); }
CEXP raw_t& data() NE { return v_; }
protected:
template <class mint>
ND CEXP auto neg() CNE {
mint res;
res.v_ = (core::MOD2 & -raw_t(v_ != 0)) - v_;
return res;
}
CEXP void add(mint_ms_tag CR r) NE { v_ += r.v_ - core::MOD2, v_ += core::MOD2 & -(v_ >> 31); }
CEXP void sub(mint_ms_tag CR r) NE { v_ -= r.v_, v_ += core::MOD2 & -(v_ >> 31); }
CEXP void mul(mint_ms_tag CR r) NE { v_ = core::reduce(u64(v_) * r.v_); }
};
template <u64 MOD>
using mint_ms = mint_impl_::mint<mint_ms_tag<MOD>>;
} // namespace tifa_libs
#line 2 "src/str/hash/substr2/lib.hpp"
#line 2 "src/str/hash/substr/lib.hpp"
#line 4 "src/str/hash/substr/lib.hpp"
namespace tifa_libs {
template <class mint, u32 base = 131>
class hash_substr {
static inline vec<mint> p;
vec<mint> hash;
public:
CEXP void set(strnv s) NE {
cu32 n = (u32)s.size();
for (hash.resize(1, 0), hash.reserve(n + 1); cchr c : s) hash.push_back(hash.back() * base + (u32)c + 1);
if (p.size() <= n) {
if (p.reserve(n + 1); p.empty()) p.push_back(1);
while (p.size() <= n) p.push_back(p.back() * base);
}
}
ND CEXP u32 size() CNE { return u32(hash.size() - 1); }
CEXP mint get(u32 pos, u32 len = -1_u32) CNE {
assert(!p.empty() && pos < hash.size());
return hash[pos + min(len, (u32)hash.size() - 1 - pos)] - hash[pos] * p[len];
}
};
} // namespace tifa_libs
#line 4 "src/str/hash/substr2/lib.hpp"
namespace tifa_libs {
template <class mint0, class mint1, u32 base = 131>
class hash_substr2 {
hash_substr<mint0, base> h0;
hash_substr<mint1, base> h1;
public:
CEXP void set(strnv s) NE { h0.set(s), h1.set(s); }
ND CEXP u32 size() CNE { return h0.size(); }
CEXP std::pair<mint0, mint1> get(u32 pos, u32 len = -1_u32) CNE { return {h0.get(pos, len), h1.get(pos, len)}; }
};
} // namespace tifa_libs
#line 12 "test/cpv/library-checker-string/runenumerate.mints-ms.hashstr-hashstr2s.cpp"
using namespace tifa_libs;
using mint = mint_ms<MOD>;
using namespace tifa_libs;
using mint0 = mint_ms<998244353>;
using mint1 = mint_ms<1000000007>;
using hashstr = hash_substr2<mint0, mint1>;
int main() {
strn s;
tifa_libs::fin_uint >> s;
auto res = tifa_libs::run_hash<hashstr>(s);
tifa_libs::fout << res.size() << '\n';
for (auto& [a, b, c] : res) tifa_libs::fout << a << ' ' << b << ' ' << c << '\n';
return 0;
}