numeric/int128.hpp
- View this file on GitHub
- Last update: 2024-07-27 23:01:00+09:00
- Include:
#include "numeric/int128.hpp"
Depends on
internal/dev_env.hpp
macro/basic.hpp
macro/overload.hpp
snippet/internal/types.hpp
snippet/iterations.hpp
Required by
action/range_sequence_hash.hpp
adaptor/internal/input.hpp
adaptor/io.hpp
algebraic/rolling_hash.hpp
convolution/internal/butterfly.hpp
convolution/sum.hpp
data_structure/dynamic_segment_tree.hpp
data_structure/dynamic_sequence.hpp
data_structure/dynamic_set.hpp
data_structure/internal/dynamic_tree.hpp
data_structure/internal/tree_dumper.hpp
data_structure/red_black_tree.hpp
data_structure/treap.hpp
debugger/debug.hpp
debugger/test.cpp
graph/centroid_decomposition.hpp
graph/centroid_path_decomposition.hpp
graph/connected_components.hpp
graph/internal/01bfs.hpp
graph/internal/bfs.hpp
graph/internal/dijkstra.hpp
graph/is_bipartite.hpp
graph/lowest_common_ancestor.hpp
graph/manhattan_minimum_spanning_tree.hpp
graph/minimum_paph_cover.hpp
graph/parse_grid.hpp
graph/reachability_test.hpp
graph/shortest_path.hpp
graph/spanning_tree.hpp
graph/topological_sort.hpp
graph/tree_diamiter.hpp
graph/tree_hash.hpp
hash/sequence_hasher.hpp
include/actions.hpp
include/adaptors.hpp
include/algebraic.hpp
include/all.hpp
include/convolutions.hpp
include/data_structures.hpp
include/graph_theory.hpp
include/hashes.hpp
include/numeric.hpp
include/template.hpp
numeric/binomial_coefficient.hpp
numeric/factorial.hpp
numeric/fast_prime.hpp
numeric/internal/divisors.hpp
numeric/internal/factorize.hpp
numeric/internal/primality_test.hpp
numeric/internal/primitive_root.hpp
numeric/matrix.hpp
numeric/modular/barrett_reduction.hpp
numeric/modular/modint.hpp
numeric/modular/modint_interface.hpp
numeric/modular/montgomery_reduction.hpp
random/engine.hpp
structure/graph.hpp
template/debug.hpp
template/standard.hpp
template/using.hpp
verify/aizu-online-judge/itp1_1_a/internal/dynamic_sequence.0000.hpp
verify/aizu-online-judge/itp1_1_a/internal/dynamic_sequence.0001.hpp
Verified with
verify/aizu-online-judge/0342/0000.test.cpp
verify/aizu-online-judge/1508/0000.test.cpp
verify/aizu-online-judge/1508/0001.test.cpp
verify/aizu-online-judge/1508/0002.test.cpp
verify/aizu-online-judge/1549/0000.test.cpp
verify/aizu-online-judge/1549/0001.test.cpp
verify/aizu-online-judge/1549/0002.test.cpp
verify/aizu-online-judge/1549/0003.test.cpp
verify/aizu-online-judge/2320/0000.test.cpp
verify/aizu-online-judge/2426/0000.test.cpp
verify/aizu-online-judge/alds1_10_c/0000.test.cpp
verify/aizu-online-judge/alds1_11_d/0000.test.cpp
verify/aizu-online-judge/alds1_11_d/0001.test.cpp
verify/aizu-online-judge/alds1_14_b/0000.test.cpp
verify/aizu-online-judge/cgl_1_a/0000.test.cpp
verify/aizu-online-judge/cgl_1_b/0000.test.cpp
verify/aizu-online-judge/cgl_1_c/0000.test.cpp
verify/aizu-online-judge/cgl_2_a/0000.test.cpp
verify/aizu-online-judge/cgl_2_b/0000.test.cpp
verify/aizu-online-judge/cgl_2_c/0000.test.cpp
verify/aizu-online-judge/cgl_3_a/0000.test.cpp
verify/aizu-online-judge/cgl_3_b/0000.test.cpp
verify/aizu-online-judge/cgl_4_a/0000.test.cpp
verify/aizu-online-judge/cgl_7_a/0000.test.cpp
verify/aizu-online-judge/cgl_7_b/0000.test.cpp
verify/aizu-online-judge/cgl_7_c/0000.test.cpp
verify/aizu-online-judge/dsl_1_a/0000.test.cpp
verify/aizu-online-judge/dsl_2_a/0000.test.cpp
verify/aizu-online-judge/dsl_2_d/0000.test.cpp
verify/aizu-online-judge/dsl_2_d/0001.test.cpp
verify/aizu-online-judge/dsl_2_d/0002.test.cpp
verify/aizu-online-judge/dsl_2_d/0003.test.cpp
verify/aizu-online-judge/dsl_2_d/0004.test.cpp
verify/aizu-online-judge/dsl_2_d/0005.test.cpp
verify/aizu-online-judge/dsl_2_d/0006.test.cpp
verify/aizu-online-judge/dsl_2_d/0007.test.cpp
verify/aizu-online-judge/dsl_2_d/0008.test.cpp
verify/aizu-online-judge/dsl_2_d/0009.test.cpp
verify/aizu-online-judge/dsl_2_e/0000.test.cpp
verify/aizu-online-judge/dsl_2_e/0001.test.cpp
verify/aizu-online-judge/dsl_2_f/0000.test.cpp
verify/aizu-online-judge/dsl_2_f/0001.test.cpp
verify/aizu-online-judge/dsl_2_f/0002.test.cpp
verify/aizu-online-judge/dsl_2_f/0003.test.cpp
verify/aizu-online-judge/dsl_2_f/0004.test.cpp
verify/aizu-online-judge/dsl_2_f/0005.test.cpp
verify/aizu-online-judge/dsl_2_g/0000.test.cpp
verify/aizu-online-judge/dsl_2_g/0001.test.cpp
verify/aizu-online-judge/dsl_2_g/0002.test.cpp
verify/aizu-online-judge/dsl_2_g/0003.test.cpp
verify/aizu-online-judge/dsl_2_h/0000.test.cpp
verify/aizu-online-judge/dsl_2_h/0001.test.cpp
verify/aizu-online-judge/dsl_2_h/0002.test.cpp
verify/aizu-online-judge/dsl_2_h/0003.test.cpp
verify/aizu-online-judge/dsl_2_h/0004.test.cpp
verify/aizu-online-judge/dsl_2_i/0000.test.cpp
verify/aizu-online-judge/grl_1_a/0000.test.cpp
verify/aizu-online-judge/itp1_1_a/0000.test.cpp
verify/aizu-online-judge/itp1_1_a/0001.test.cpp
verify/aizu-online-judge/itp1_1_a/0002.test.cpp
verify/aizu-online-judge/itp1_1_a/0003.test.cpp
verify/aizu-online-judge/itp1_1_a/0004.test.cpp
verify/aizu-online-judge/itp1_1_a/0005.test.cpp
verify/aizu-online-judge/itp1_1_a/0006.test.cpp
verify/aizu-online-judge/itp1_1_a/0007.test.cpp
verify/aizu-online-judge/itp1_1_a/0008.test.cpp
verify/aizu-online-judge/itp1_1_a/0009.test.cpp
verify/aizu-online-judge/itp1_1_a/0010.test.cpp
verify/aizu-online-judge/itp1_1_a/0011.test.cpp
verify/aizu-online-judge/itp1_1_a/0012.test.cpp
verify/aizu-online-judge/itp1_1_a/0013.test.cpp
verify/aizu-online-judge/itp1_1_a/0014.test.cpp
verify/aizu-online-judge/itp1_1_a/0015.test.cpp
verify/aizu-online-judge/itp1_6_c/0000.test.cpp
verify/aizu-online-judge/ntl_1_a/0000.test.cpp
verify/yosupo-judge/associative_array/0000.test.cpp
verify/yosupo-judge/associative_array/0001.test.cpp
verify/yosupo-judge/associative_array/0002.test.cpp
verify/yosupo-judge/associative_array/0003.test.cpp
verify/yosupo-judge/binomial_coefficient/0000.test.cpp
verify/yosupo-judge/binomial_coefficient_prime_mod/0000.test.cpp
verify/yosupo-judge/binomial_coefficient_prime_mod/0001.test.cpp
verify/yosupo-judge/binomial_coefficient_prime_mod/0002.test.cpp
verify/yosupo-judge/binomial_coefficient_prime_mod/0003.test.cpp
verify/yosupo-judge/bipartitematching/0000.test.cpp
verify/yosupo-judge/convolution_mod/0000.test.cpp
verify/yosupo-judge/convolution_mod_1000000007/0000.test.cpp
verify/yosupo-judge/counting_primes/0000.test.cpp
verify/yosupo-judge/deque_operate_all_composite/0000.test.cpp
verify/yosupo-judge/deque_operate_all_composite/0001.test.cpp
verify/yosupo-judge/deque_operate_all_composite/0002.test.cpp
verify/yosupo-judge/deque_operate_all_composite/0003.test.cpp
verify/yosupo-judge/deque_operate_all_composite/0004.test.cpp
verify/yosupo-judge/deque_operate_all_composite/0005.test.cpp
verify/yosupo-judge/double_ended_priority_queue/0000.test.cpp
verify/yosupo-judge/dynamic_sequence_range_affine_range_sum/0000.test.cpp
verify/yosupo-judge/dynamic_sequence_range_affine_range_sum/0001.test.cpp
verify/yosupo-judge/dynamic_sequence_range_affine_range_sum/0002.test.cpp
verify/yosupo-judge/dynamic_sequence_range_affine_range_sum/0003.test.cpp
verify/yosupo-judge/dynamic_sequence_range_affine_range_sum/0004.test.cpp
verify/yosupo-judge/dynamic_sequence_range_affine_range_sum/0005.test.cpp
verify/yosupo-judge/enumerate_primes/0000.test.cpp
verify/yosupo-judge/enumerate_quotients/0000.test.cpp
verify/yosupo-judge/factorize/0000.test.cpp
verify/yosupo-judge/gcd_convolution/0000.test.cpp
verify/yosupo-judge/kth_root_integer/0000.test.cpp
verify/yosupo-judge/lca/0000.test.cpp
verify/yosupo-judge/lca/0001.test.cpp
verify/yosupo-judge/lcm_convolution/0000.test.cpp
verify/yosupo-judge/longest_increasing_subsequence/0000.test.cpp
verify/yosupo-judge/manhattanmst/0000.test.cpp
verify/yosupo-judge/many_aplusb_128bit/0000.test.cpp
verify/yosupo-judge/matrix_det_arbitrary_mod/0000.test.cpp
verify/yosupo-judge/matrix_det_arbitrary_mod/0001.test.cpp
verify/yosupo-judge/matrix_product/0000.test.cpp
verify/yosupo-judge/matrix_product/0001.test.cpp
verify/yosupo-judge/matrix_product/0002.test.cpp
verify/yosupo-judge/matrix_product/0003.test.cpp
verify/yosupo-judge/matrix_product/0004.test.cpp
verify/yosupo-judge/matrix_product/0005.test.cpp
verify/yosupo-judge/matrix_product/0006.test.cpp
verify/yosupo-judge/matrix_product/0007.test.cpp
verify/yosupo-judge/matrix_product/0008.test.cpp
verify/yosupo-judge/matrix_product/0009.test.cpp
verify/yosupo-judge/matrix_product/0010.test.cpp
verify/yosupo-judge/matrix_product/0011.test.cpp
verify/yosupo-judge/matrix_product/0012.test.cpp
verify/yosupo-judge/matrix_product/0013.test.cpp
verify/yosupo-judge/matrix_product/0014.test.cpp
verify/yosupo-judge/matrix_product/0015.test.cpp
verify/yosupo-judge/persistent_queue/0000.test.cpp
verify/yosupo-judge/point_add_range_sum/0000.test.cpp
verify/yosupo-judge/point_add_range_sum/0001.test.cpp
verify/yosupo-judge/point_add_range_sum/0002.test.cpp
verify/yosupo-judge/point_add_range_sum/0003.test.cpp
verify/yosupo-judge/point_add_range_sum/0004.test.cpp
verify/yosupo-judge/point_set_range_composite/0000.test.cpp
verify/yosupo-judge/point_set_range_composite/0001.test.cpp
verify/yosupo-judge/point_set_range_composite/0002.test.cpp
verify/yosupo-judge/point_set_range_composite/0003.test.cpp
verify/yosupo-judge/predecessor_problem/0000.test.cpp
verify/yosupo-judge/predecessor_problem/0001.test.cpp
verify/yosupo-judge/predecessor_problem/0002.test.cpp
verify/yosupo-judge/predecessor_problem/0003.test.cpp
verify/yosupo-judge/primality_test/0000.test.cpp
verify/yosupo-judge/primitive_root/0000.test.cpp
verify/yosupo-judge/queue_operate_all_composite/0000.test.cpp
verify/yosupo-judge/queue_operate_all_composite/0001.test.cpp
verify/yosupo-judge/queue_operate_all_composite/0002.test.cpp
verify/yosupo-judge/queue_operate_all_composite/0003.test.cpp
verify/yosupo-judge/queue_operate_all_composite/0004.test.cpp
verify/yosupo-judge/queue_operate_all_composite/0005.test.cpp
verify/yosupo-judge/range_affine_range_sum/0000.test.cpp
verify/yosupo-judge/range_affine_range_sum/0001.test.cpp
verify/yosupo-judge/range_affine_range_sum/0002.test.cpp
verify/yosupo-judge/range_affine_range_sum/0003.test.cpp
verify/yosupo-judge/range_affine_range_sum/0004.test.cpp
verify/yosupo-judge/range_affine_range_sum/0005.test.cpp
verify/yosupo-judge/range_affine_range_sum/0006.test.cpp
verify/yosupo-judge/range_affine_range_sum/0007.test.cpp
verify/yosupo-judge/range_affine_range_sum/0008.test.cpp
verify/yosupo-judge/range_kth_smallest/0000.test.cpp
verify/yosupo-judge/range_kth_smallest/0001.test.cpp
verify/yosupo-judge/range_kth_smallest/0002.test.cpp
verify/yosupo-judge/range_kth_smallest/0003.test.cpp
verify/yosupo-judge/range_reverse_range_sum/0000.test.cpp
verify/yosupo-judge/rectangle_sum/0000.test.cpp
verify/yosupo-judge/rectangle_sum/0001.test.cpp
verify/yosupo-judge/shortest_path/0000.test.cpp
verify/yosupo-judge/shortest_path/0001.test.cpp
verify/yosupo-judge/shortest_path/0002.test.cpp
verify/yosupo-judge/static_range_frequency/0000.test.cpp
verify/yosupo-judge/static_range_frequency/0001.test.cpp
verify/yosupo-judge/static_range_sum/0000.test.cpp
verify/yosupo-judge/static_range_sum/0001.test.cpp
verify/yosupo-judge/static_range_sum/0002.test.cpp
verify/yosupo-judge/static_range_sum/0003.test.cpp
verify/yosupo-judge/static_range_sum/0004.test.cpp
verify/yosupo-judge/static_range_sum/0005.test.cpp
verify/yosupo-judge/static_range_sum/0006.test.cpp
verify/yosupo-judge/static_range_sum/0007.test.cpp
verify/yosupo-judge/static_range_sum/0008.test.cpp
verify/yosupo-judge/staticrmq/0000.test.cpp
verify/yosupo-judge/staticrmq/0001.test.cpp
verify/yosupo-judge/staticrmq/0002.test.cpp
verify/yosupo-judge/staticrmq/0003.test.cpp
verify/yosupo-judge/system_of_linear_equations/0000.test.cpp
verify/yukicoder/649/0000.test.cpp
verify/yukicoder/738/0000.test.cpp
verify/yukicoder/789/0000.test.cpp
verify/yukicoder/789/0001.test.cpp
Code
#pragma once
#include <cctype>
#include <cassert>
#include <iostream>
#include <string>
#include <algorithm>
#include "snippet/internal/types.hpp"
#include "snippet/iterations.hpp"
#include "internal/dev_env.hpp"
namespace std {
template<class C, class S>
auto& operator>>(std::basic_istream<C, S>& in, uni::i128& v) noexcept(NO_EXCEPT) {
std::string str; in >> str;
v = 0;
bool negative = (str[0] == '-');
REP(d, std::ranges::next(str.begin(), negative), str.end()) {
assert(std::isdigit(*d));
v = v * 10 + *d - '0';
}
if(negative) v *= -1;
return in;
}
template<class C, class S>
auto& operator>>(std::basic_istream<C, S>& in, uni::u128& v) noexcept(NO_EXCEPT) {
std::string str; in >> str;
v = 0U;
assert(str[0] != '-');
REP(d, str.begin(), str.end()) {
assert(std::isdigit(*d));
v = v * 10U + *d - '0';
}
return in;
}
template<class C, class S>
auto& operator<<(std::basic_ostream<C, S>& out, uni::i128 v) noexcept(NO_EXCEPT) {
if(v == 0) return out << 0;
if(v < 0) out << '-', v *= -1;
std::string str;
while(v > 0) str += static_cast<char>(v%10) + '0', v /= 10;
std::reverse(str.begin(), str.end());
return out << str;
}
template<class C, class S>
auto& operator<<(std::basic_ostream<C, S>& out, uni::u128 v) noexcept(NO_EXCEPT) {
if(v == 0) return out << 0U;
std::string str;
while(v > 0) str += static_cast<char>(v%10U) + '0', v /= 10U;
std::reverse(str.begin(), str.end());
return out << str;
}
}
#line 2 "numeric/int128.hpp"
#include <cctype>
#include <cassert>
#include <iostream>
#include <string>
#include <algorithm>
#line 2 "snippet/internal/types.hpp"
#include <cstdint>
namespace uni {
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;
#ifdef __GNUC__
using i128 = __int128_t;
using u128 = __uint128_t;
using f128 = __float128;
#endif
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
} // namespace uni
#line 2 "snippet/iterations.hpp"
#include <type_traits>
#line 2 "macro/overload.hpp"
#define $OVERLOAD2(arg0, arg1, cmd, ...) cmd
#define $OVERLOAD3(arg0, arg1, arg2, cmd, ...) cmd
#define $OVERLOAD4(arg0, arg1, arg2, arg3, cmd, ...) cmd
#define $OVERLOAD5(arg0, arg1, arg2, arg3, arg4, cmd, ...) cmd
#define $OVERLOAD6(arg0, arg1, arg2, arg3, arg4, arg5, cmd, ...) cmd
#line 2 "macro/basic.hpp"
#define TO_STRING_AUX(x) #x
#define TO_STRING(x) TO_STRING_AUX(x)
#define CONCAT_AUX(x, y) x##y
#define CONCAT(x, y) CONCAT_AUX(x, y)
#define UNPAREN_AUX(...) __VA_ARGS__
#define UNPAREN(...) __VA_ARGS__
#line 6 "snippet/iterations.hpp"
#define LOOP(n) REPI(CONCAT(_$, __COUNTER__), n)
#define REPI(i,n) for(std::remove_cvref_t<decltype(n)> i=0, CONCAT(i, $)=(n); i<CONCAT(i, $); ++i)
#define REPF(i,l,r) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>> i=(l), CONCAT(i, $)=(r); i<CONCAT(i, $); ++i)
#define REPIS(i,l,r,s) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>,std::remove_cvref_t<decltype(s)>> i=(l), CONCAT(i, $)=(r); i<CONCAT(i, $); i+=(s))
#define REPR(i,n) for(auto i=(n); --i>=0;)
#define REPB(i,l,r) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>> i=(r), CONCAT(i, $)=(l); --i>=CONCAT(i, $);)
#define REPRS(i,l,r,s) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>,std::remove_cvref_t<decltype(s)>> i=(l)+((r)-(l)-1)/(s)*(s), CONCAT(i, $)=(l); i>=CONCAT(i, $); (i-=(s)))
#define REP(...) $OVERLOAD4(__VA_ARGS__, REPIS, REPF, REPI, LOOP)(__VA_ARGS__)
#define REPD(...) $OVERLOAD4(__VA_ARGS__, REPRS, REPB, REPR)(__VA_ARGS__)
#define FORO(i,n) for(int i=0, CONCAT(i, $)=static_cast<int>(n); i<=CONCAT(i, $); ++i)
#define FORI(i,l,r) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>> i=(l), CONCAT(i, $)=(r); i<=CONCAT(i, $); ++i)
#define FORIS(i,l,r,s) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>,std::remove_cvref_t<decltype(s)>> i=(l), CONCAT(i, $)=(r); i<=CONCAT(i, $); i+=(s))
#define FORRO(i,n) for(auto i=(n); i>=0; --i)
#define FORR(i,l,r) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>> i=(r), CONCAT(i, $)=(l); i>=CONCAT(i, $); --i)
#define FORRS(i,l,r,s) for(std::common_type_t<std::remove_cvref_t<decltype(l)>,std::remove_cvref_t<decltype(r)>,std::remove_cvref_t<decltype(s)>> i=(l)+((r)-(l))/(s)*(s), CONCAT(i, $)=(l); i>=CONCAT(i, $); i-=(s))
#define FOR(...) $OVERLOAD4(__VA_ARGS__, FORIS, FORI, FORO)(__VA_ARGS__)
#define FORD(...) $OVERLOAD4(__VA_ARGS__, FORRS, FORR, FORRO)(__VA_ARGS__)
#define ITR1(e0,v) for(const auto &e0 : (v))
#define ITRP1(e0,v) for(auto e0 : (v))
#define ITRR1(e0,v) for(auto &e0 : (v))
#define ITR2(e0,e1,v) for(const auto [e0, e1] : (v))
#define ITRP2(e0,e1,v) for(auto [e0, e1] : (v))
#define ITRR2(e0,e1,v) for(auto &[e0, e1] : (v))
#define ITR3(e0,e1,e2,v) for(const auto [e0, e1, e2] : (v))
#define ITRP3(e0,e1,e2,v) for(auto [e0, e1, e2] : (v))
#define ITRR3(e0,e1,e2,v) for(auto &[e0, e1, e2] : (v))
#define ITR4(e0,e1,e2,e3,v) for(const auto [e0, e1, e2, e3] : (v))
#define ITRP4(e0,e1,e2,e3,v) for(auto [e0, e1, e2, e3] : (v))
#define ITRR4(e0,e1,e2,e3,v) for(auto &[e0, e1, e2, e3] : (v))
#define ITR5(e0,e1,e2,e3,e4,v) for(const auto [e0, e1, e2, e3, e4] : (v))
#define ITRP5(e0,e1,e2,e3,e4,v) for(auto [e0, e1, e2, e3, e4] : (v))
#define ITRR5(e0,e1,e2,e3,e4,v) for(auto &[e0, e1, e2, e3, e4] : (v))
#define ITR(...) $OVERLOAD6(__VA_ARGS__, ITR5, ITR4, ITR3, ITR2, ITR1)(__VA_ARGS__)
#define ITRP(...) $OVERLOAD6(__VA_ARGS__, ITRP5, ITRP4, ITRP3, ITRP2, ITRP1)(__VA_ARGS__)
#define ITRR(...) $OVERLOAD6(__VA_ARGS__, ITRR5, ITRR4, ITRR3, ITRR2, ITRR1)(__VA_ARGS__)
#line 12 "numeric/int128.hpp"
#line 2 "internal/dev_env.hpp"
#ifdef LOCAL_JUDGE
inline constexpr bool DEV_ENV = true;
inline constexpr bool NO_EXCEPT = false;
#else
inline constexpr bool DEV_ENV = false;
inline constexpr bool NO_EXCEPT = true;
#endif // LOCAL_JUDGE
#if __cplusplus >= 202100L
#define CPP20 true
#define CPP23 true
#elif __cplusplus >= 202002L
#define CPP20 true
#define CPP23 false
#else
#define CPP20 false
#define CPP23 false
#endif
#line 14 "numeric/int128.hpp"
namespace std {
template<class C, class S>
auto& operator>>(std::basic_istream<C, S>& in, uni::i128& v) noexcept(NO_EXCEPT) {
std::string str; in >> str;
v = 0;
bool negative = (str[0] == '-');
REP(d, std::ranges::next(str.begin(), negative), str.end()) {
assert(std::isdigit(*d));
v = v * 10 + *d - '0';
}
if(negative) v *= -1;
return in;
}
template<class C, class S>
auto& operator>>(std::basic_istream<C, S>& in, uni::u128& v) noexcept(NO_EXCEPT) {
std::string str; in >> str;
v = 0U;
assert(str[0] != '-');
REP(d, str.begin(), str.end()) {
assert(std::isdigit(*d));
v = v * 10U + *d - '0';
}
return in;
}
template<class C, class S>
auto& operator<<(std::basic_ostream<C, S>& out, uni::i128 v) noexcept(NO_EXCEPT) {
if(v == 0) return out << 0;
if(v < 0) out << '-', v *= -1;
std::string str;
while(v > 0) str += static_cast<char>(v%10) + '0', v /= 10;
std::reverse(str.begin(), str.end());
return out << str;
}
template<class C, class S>
auto& operator<<(std::basic_ostream<C, S>& out, uni::u128 v) noexcept(NO_EXCEPT) {
if(v == 0) return out << 0U;
std::string str;
while(v > 0) str += static_cast<char>(v%10U) + '0', v /= 10U;
std::reverse(str.begin(), str.end());
return out << str;
}
}