1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once


#include <iostream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <vector><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iterator><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <utility>
#include <tuple><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <ranges><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <concepts><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.


#include "snippet/aliases.hpp"

#include "internal/dev_env.hpp"
#include "internal/resolving_rank.hpp"

#include "utility/functional.hpp"

#include "numeric/modular/modint_interface.hpp"

#include "adaptor/valarray.hpp"


namespace uni {


template<std::derived_from<std::ios_base> Source = std::istream>
struct input_adaptor {
    using source_type = Source;

  private:
    template<class T>
        requires std::derived_from<T, std::valarray<typename T::value_type>>
    auto _set(uni::internal::resolving_rank<6>, T& val) noexcept(NO_EXCEPT) -> int {
        this->operator()(ALL(val));
        return 0;
    }

    template<class T>
        requires
            requires (source_type& in, T& val) {
                in >> val;
            }
    int _set(uni::internal::resolving_rank<5>, T& val) noexcept(NO_EXCEPT) {
        *this->in >> val;
        return 0;
    }

    template<std::ranges::range T>
    int _set(uni::internal::resolving_rank<4>, T& val) noexcept(NO_EXCEPT) {
        this->operator()(std::ranges::begin(val), std::ranges::end(val));
        return 0;
    }

    template<class T>
        requires
            requires (T& val) {
                val.first;
                val.second;
            }
    int _set(uni::internal::resolving_rank<3>, T& val) noexcept(NO_EXCEPT) {
        *this >> val.first >> val.second;
        return 0;
    }

    template<class T>
        requires
            requires (T& val) {
                std::get<0>(val);
            }
    int _set(uni::internal::resolving_rank<2>, T& val) noexcept(NO_EXCEPT) {
        tuple_for_each([this](auto&& v) { *this >> v; }, val);
        return 0;
    }

    template<uni::internal::modint_family T>
    int _set(uni::internal::resolving_rank<1>, T& val) noexcept(NO_EXCEPT) {
        std::int64_t v; std::cin >> v;
        val = { v };
        return 0;
    }

    template<class T>
        requires
            requires {
                typename T::value_type;
            }
    int _set(uni::internal::resolving_rank<0>, T& val) noexcept(NO_EXCEPT) {
        typename T::value_type v; *this >> v;
        val = { v };
        return 0;
    }

  protected:
    template<class T>
    source_type *set(T& val) noexcept(NO_EXCEPT) {
        this->_set(uni::internal::resolving_rank<10>{}, val);
        return this->in;
    }

    template<class T>
    source_type *set(T&& _val) noexcept(NO_EXCEPT) {
        T val = _val;
        this->_set(uni::internal::resolving_rank<10>{}, val);
        return this->in;
    }

  public:
    using char_type = typename source_type::char_type;

    source_type *in;

    input_adaptor(source_type *_in = &std::cin) noexcept(NO_EXCEPT) : in(_in) {}

    template<class T>
    inline input_adaptor& operator>>(T&& s) noexcept(NO_EXCEPT) {
        this->set(std::forward<T>(s));
        return *this;
    }

    template<class T>
    inline T one() noexcept(NO_EXCEPT) {
        T val; *this >> val;
        return val;
    }

    template<class T>
    inline auto& operator()(T& val) noexcept(NO_EXCEPT) {
        *this >> val;
        return *this;
    }

    template<class T, class... Args>
    inline auto& operator()(T& head, Args&... tail) noexcept(NO_EXCEPT) {
        *this >> head;
        this->operator()(tail...);
        return *this;
    }

    template<std::input_or_output_iterator I, std::sentinel_for<I> S>
    inline auto& operator()(I first, S last) noexcept(NO_EXCEPT) {
        for(I itr=first; itr!=last; ++itr) *this >> *itr;
        return *this;
    }

    explicit operator bool() const noexcept(NO_EXCEPT) { return (bool)*this->in; }
};


} // namespace uni