結果

問題 No.3677 Global Checksum
コンテスト
ユーザー kemuniku
提出日時 2026-09-05 04:51:59
言語 Nim
(2.2.10)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 58,081 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,020 ms
コンパイル使用メモリ 142,280 KB
実行使用メモリ 48,896 KB
最終ジャッジ日時 2026-09-05 04:52:13
合計ジャッジ時間 6,810 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 1 -- * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
--- Self-Recompiling with optimized settings ---
Command: cd /home/judge/data/code && export PATH=$HOME/.nimble/bin:$PATH && nim cpp -d:danger -d:second_compile -d:useMalloc --gc:none --panics:on --opt:speed --checks:off --passC:"-O3 -flto -m64 -march=native -ffast-math" --hints:off -o:a.out /home/judge/data/code/Main.nim




/home/judge/data/code/Main.nim(8, 9) template/generic instantiation of `optimize` from here
(25, 20) Warning: command line(1, 2) Warning: `gc:option` is deprecated; use `mm:option` instead [Deprecated]
command line(1, 2) Warning: `gc:option` is deprecated; use `mm:option` instead [Deprecated]
/home/linuxbrew/.linuxbrew/Cellar/nim/2.2.10/nim/lib/system/fatal.nim(62, 5) Warning: '(ref exceptn)(msg: message)' uses GC'ed memory [GcMem]
/home/linuxbrew/.linuxbrew/Cellar/nim/2.2.10/nim/lib/system.nim(1660, 28) Warning: 'newSeqOfCap(len)' uses GC'ed memory [GcMem]
/home/linuxbrew/.linuxbrew/Cellar/nim/2.2.10/nim/lib/std/syncio.nim(176, 45) Warning: '$strerror(errno)' uses GC'ed memory [GcMem]
/home/linuxbrew/.linuxbrew/Cellar/nim/2.2.10/nim/lib/std/syncio.nim(176, 62) Warning: '`&`("errno: ", $errno, " `", $strerror(errno), "`")' uses GC'ed memory [GcMem]
/home/linuxbrew/.linuxbrew/Cellar/nim/2.2.10/nim/lib/std/syncio.nim(161, 21) Warning: '(ref IOError)(msg: msg, parent: nil)' uses GC'ed memory [GcMem]
(1208, 27) Warning: 'setLen(result, chckRange(chckRange(written, -9223372036854775808,
                                   9223372036854775807), 0, 9223372036854775807))' uses GC'ed memory [GcMem] [User]




ソースコード

diff #
raw source code

import macros;macro ImportExpand(s:untyped):untyped = parseStmt($s[2])
# source: src/cplib/tmpl/sheep.nim
ImportExpand "cplib/tmpl/sheep" <=== "when not declared CPLIB_TMPL_SHEEP:\n    const CPLIB_TMPL_SHEEP* = 1\n    {.warning[UnusedImport]: off.}\n    {.hint[XDeclaredButNotUsed]: off.}\n    import algorithm\n    import sequtils\n    import tables\n    import macros\n    import math\n    import sets\n    import strutils\n    import strformat\n    import sugar\n    import heapqueue\n    import streams\n    import deques\n    import bitops\n    import std/lenientops\n    import options\n    when not declared CPLIB_TMPL_FASTIO:\n        const CPLIB_TMPL_FASTIO* = 1\n        {.passC: \"-mavx2\".}\n        when defined(fastioNoMmap):\n            {.passC: \"-DCPLIB_FASTIO_NO_MMAP\".}\n        import macros\n    \n        # 入力系\n        {.emit: \"\"\"\n    #include <cstdio>\n    #include <cstddef>\n    #include <cstdint>\n    #include <cstring>\n    #include <immintrin.h>\n    #include <string>\n    #include <sys/mman.h>\n    #include <sys/stat.h>\n    \n    namespace cplib_fastio_input {\n    constexpr std::size_t buffer_size = 1U << 20;\n    constexpr std::size_t safe_integer_bytes = 32;\n    \n    struct InputState {\n      alignas(64) char buffer[buffer_size];\n      std::size_t cursor;\n      std::size_t length;\n      const char* mapped;\n      bool initialized;\n    };\n    \n    inline InputState& input_state() {\n      static InputState state = {};\n      return state;\n    }\n    \n    inline std::string& token_storage() {\n      static std::string storage;\n      return storage;\n    }\n    \n    #if defined(__GNUC__) || defined(__clang__)\n    #define CPLIB_FASTIO_ALWAYS_INLINE inline __attribute__((always_inline))\n    #define CPLIB_FASTIO_NIM_ALWAYS_INLINE \\\n        static inline __attribute__((always_inline))\n    #define CPLIB_FASTIO_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))\n    #elif defined(_MSC_VER)\n    #define CPLIB_FASTIO_ALWAYS_INLINE __forceinline\n    #define CPLIB_FASTIO_NIM_ALWAYS_INLINE static __forceinline\n    #define CPLIB_FASTIO_UNLIKELY(condition) (condition)\n    #else\n    #define CPLIB_FASTIO_ALWAYS_INLINE inline\n    #define CPLIB_FASTIO_NIM_ALWAYS_INLINE static inline\n    #define CPLIB_FASTIO_UNLIKELY(condition) (condition)\n    #endif\n    \n    inline void initialize(InputState& state) {\n      if (state.initialized) return;\n      state.initialized = true;\n    \n    #ifndef CPLIB_FASTIO_NO_MMAP\n      struct stat st;\n      const int fd = fileno(stdin);\n      if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode) && st.st_size > 0) {\n        void* p = mmap(nullptr, static_cast<std::size_t>(st.st_size),\n                       PROT_READ, MAP_PRIVATE, fd, 0);\n        if (p != MAP_FAILED) {\n          state.mapped = static_cast<const char*>(p);\n          state.length = static_cast<std::size_t>(st.st_size);\n          madvise(const_cast<char*>(state.mapped), state.length,\n                  MADV_SEQUENTIAL);\n        }\n      }\n    #endif\n    }\n    \n    inline bool refill(InputState& state) {\n      state.length =\n          fread_unlocked(state.buffer, 1, buffer_size, stdin);\n      state.cursor = 0;\n      return state.length != 0;\n    }\n    \n    inline int get_char() {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped != nullptr) {\n        if (state.cursor == state.length) return -1;\n        return static_cast<unsigned char>(state.mapped[state.cursor++]);\n      }\n      if (state.cursor == state.length && !refill(state)) return -1;\n      return static_cast<unsigned char>(state.buffer[state.cursor++]);\n    }\n    \n    inline bool has_eight_digits(const char* source) {\n      // 正しい整数入力では、数字・符号・空白を上位4bitだけで判別できる。\n      std::uint64_t bytes;\n      std::memcpy(&bytes, source, sizeof(bytes));\n      return ((bytes ^ 0x3030303030303030ULL) &\n              0xf0f0f0f0f0f0f0f0ULL) == 0;\n    }\n    \n    inline unsigned parse_eight_digits(const char* source) {\n      std::uint64_t digits;\n      std::memcpy(&digits, source, sizeof(digits));\n      digits ^= 0x3030303030303030ULL;\n      digits = (digits * ((10ULL << 8) + 1) >> 8) &\n          0x00ff00ff00ff00ffULL;\n      digits = (digits * ((100ULL << 16) + 1) >> 16) &\n          0x0000ffff0000ffffULL;\n      return static_cast<unsigned>(\n          digits * ((10000ULL << 32) + 1) >> 32);\n    }\n    \n    inline unsigned digit_at(const char* source) {\n      return static_cast<unsigned>(static_cast<unsigned char>(*source)) -\n             static_cast<unsigned>('0');\n    }\n    \n    template <bool negative>\n    CPLIB_FASTIO_ALWAYS_INLINE bool try_parse_digits_unchecked(\n            const char*& source, long long& output) {\n      long long value = 0;\n      if (has_eight_digits(source)) {\n        const long long digits =\n            static_cast<long long>(parse_eight_digits(source));\n        value = negative ? value * 100000000LL - digits\n                         : value * 100000000LL + digits;\n        source += 8;\n        if (has_eight_digits(source)) {\n          const long long next_digits =\n              static_cast<long long>(parse_eight_digits(source));\n          value = negative ? value * 100000000LL - next_digits\n                           : value * 100000000LL + next_digits;\n          source += 8;\n          for (int pair = 0; pair < 2; ++pair) {\n            const unsigned first = digit_at(source);\n            if (first >= 10U) {\n              output = value;\n              return true;\n            }\n            const unsigned second = digit_at(source + 1);\n            if (second >= 10U) {\n              ++source;\n              output = negative\n                  ? value * 10 - static_cast<long long>(first)\n                  : value * 10 + static_cast<long long>(first);\n              return true;\n            }\n            value = negative\n                ? value * 100 - static_cast<long long>(first * 10U + second)\n                : value * 100 + static_cast<long long>(first * 10U + second);\n            source += 2;\n          }\n          if (digit_at(source) < 10U) return false;\n          output = value;\n          return true;\n        }\n      }\n      for (;;) {\n        const unsigned first = digit_at(source);\n        if (first >= 10U) {\n          output = value;\n          return true;\n        }\n        const unsigned second = digit_at(source + 1);\n        if (second >= 10U) {\n          ++source;\n          output = negative ? value * 10 - static_cast<long long>(first)\n                            : value * 10 + static_cast<long long>(first);\n          return true;\n        }\n        value = negative\n            ? value * 100 - static_cast<long long>(first * 10U + second)\n            : value * 100 + static_cast<long long>(first * 10U + second);\n        source += 2;\n      }\n    }\n    \n    template <bool negative>\n    inline long long parse_digits_bounded(const char*& source,\n                                          const char* end) {\n      long long value = 0;\n      while (end - source >= 8 && has_eight_digits(source)) {\n        const long long digits =\n            static_cast<long long>(parse_eight_digits(source));\n        value = negative ? value * 100000000LL - digits\n                         : value * 100000000LL + digits;\n        source += 8;\n      }\n      while (end - source >= 2) {\n        const unsigned first = digit_at(source);\n        const unsigned second = digit_at(source + 1);\n        if (first >= 10U) return value;\n        if (second >= 10U) {\n          ++source;\n          return negative ? value * 10 - static_cast<long long>(first)\n                          : value * 10 + static_cast<long long>(first);\n        }\n        value = negative\n            ? value * 100 - static_cast<long long>(first * 10U + second)\n            : value * 100 + static_cast<long long>(first * 10U + second);\n        source += 2;\n      }\n      if (source != end) {\n        const unsigned digit = digit_at(source);\n        if (digit < 10U) {\n          value = negative ? value * 10 - static_cast<long long>(digit)\n                           : value * 10 + static_cast<long long>(digit);\n          ++source;\n        }\n      }\n      return value;\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE bool try_parse_unsigned_digits_unchecked(\n            const char*& source, unsigned long long& output) {\n      unsigned long long value = 0;\n      if (has_eight_digits(source)) {\n        value = static_cast<unsigned long long>(parse_eight_digits(source));\n        source += 8;\n        if (has_eight_digits(source)) {\n          value = value * 100000000ULL +\n                  static_cast<unsigned long long>(parse_eight_digits(source));\n          source += 8;\n          for (int pair = 0; pair < 2; ++pair) {\n            const unsigned first = digit_at(source);\n            if (first >= 10U) {\n              output = value;\n              return true;\n            }\n            const unsigned second = digit_at(source + 1);\n            if (second >= 10U) {\n              ++source;\n              output = value * 10ULL + first;\n              return true;\n            }\n            value = value * 100ULL + first * 10U + second;\n            source += 2;\n          }\n          if (digit_at(source) < 10U) return false;\n          output = value;\n          return true;\n        }\n      }\n      for (;;) {\n        const unsigned first = digit_at(source);\n        if (first >= 10U) {\n          output = value;\n          return true;\n        }\n        const unsigned second = digit_at(source + 1);\n        if (second >= 10U) {\n          ++source;\n          output = value * 10ULL + first;\n          return true;\n        }\n        value = value * 100ULL + first * 10U + second;\n        source += 2;\n      }\n    }\n    \n    inline unsigned long long parse_unsigned_digits_bounded(\n            const char*& source, const char* end) {\n      unsigned long long value = 0;\n      while (end - source >= 8 && has_eight_digits(source)) {\n        value = value * 100000000ULL +\n                static_cast<unsigned long long>(parse_eight_digits(source));\n        source += 8;\n      }\n      while (end - source >= 2) {\n        const unsigned first = digit_at(source);\n        const unsigned second = digit_at(source + 1);\n        if (first >= 10U) return value;\n        if (second >= 10U) {\n          ++source;\n          return value * 10ULL + first;\n        }\n        value = value * 100ULL + first * 10U + second;\n        source += 2;\n      }\n      if (source != end) {\n        const unsigned digit = digit_at(source);\n        if (digit < 10U) {\n          value = value * 10ULL + digit;\n          ++source;\n        }\n      }\n      return value;\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE long long read_mapped_at(\n            const char*& source, const char* end) {\n      while (source != end &&\n             static_cast<unsigned char>(*source) <=\n                 static_cast<unsigned char>(' ')) {\n        ++source;\n      }\n      if (source == end) return 0;\n      const bool negative = *source == '-';\n      if (negative || *source == '+') ++source;\n      if (end - source >= static_cast<std::ptrdiff_t>(safe_integer_bytes)) {\n        const char* parsed = source;\n        long long value;\n        const bool complete = negative\n            ? try_parse_digits_unchecked<true>(parsed, value)\n            : try_parse_digits_unchecked<false>(parsed, value);\n        if (complete) {\n          source = parsed;\n          return value;\n        }\n      }\n      return negative ? parse_digits_bounded<true>(source, end)\n                      : parse_digits_bounded<false>(source, end);\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE unsigned long long read_uint_mapped_at(\n            const char*& source, const char* end) {\n      while (source != end &&\n             static_cast<unsigned char>(*source) <=\n                 static_cast<unsigned char>(' ')) {\n        ++source;\n      }\n      if (source == end) return 0;\n      const bool negative = *source == '-';\n      if (negative || *source == '+') ++source;\n      if (end - source >= static_cast<std::ptrdiff_t>(safe_integer_bytes)) {\n        const char* parsed = source;\n        unsigned long long value;\n        if (try_parse_unsigned_digits_unchecked(parsed, value)) {\n          source = parsed;\n          return negative ? 0ULL - value : value;\n        }\n      }\n      const unsigned long long value =\n          parse_unsigned_digits_bounded(source, end);\n      return negative ? 0ULL - value : value;\n    }\n    \n    inline long long read_int_stream_slow(InputState& state) {\n      bool negative = state.buffer[state.cursor] == '-';\n      if (negative || state.buffer[state.cursor] == '+') {\n        ++state.cursor;\n        if (state.cursor == state.length && !refill(state)) return 0;\n      }\n      long long value = 0;\n      for (;;) {\n        while (state.cursor != state.length) {\n          const unsigned digit = digit_at(state.buffer + state.cursor);\n          if (digit >= 10U) return value;\n          value = negative ? value * 10 - static_cast<long long>(digit)\n                           : value * 10 + static_cast<long long>(digit);\n          ++state.cursor;\n        }\n        if (!refill(state)) return value;\n      }\n    }\n    \n    inline unsigned long long read_uint_stream_slow(InputState& state) {\n      const bool negative = state.buffer[state.cursor] == '-';\n      if (negative || state.buffer[state.cursor] == '+') {\n        ++state.cursor;\n        if (state.cursor == state.length && !refill(state)) return 0;\n      }\n      unsigned long long value = 0;\n      for (;;) {\n        while (state.cursor != state.length) {\n          const unsigned digit = digit_at(state.buffer + state.cursor);\n          if (digit >= 10U) return negative ? 0ULL - value : value;\n          value = value * 10ULL + digit;\n          ++state.cursor;\n        }\n        if (!refill(state)) return negative ? 0ULL - value : value;\n      }\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE long long read_int_stream(InputState& state) {\n      for (;;) {\n        if (state.cursor == state.length && !refill(state)) return 0;\n        while (state.cursor != state.length &&\n               static_cast<unsigned char>(state.buffer[state.cursor]) <=\n                   static_cast<unsigned char>(' ')) {\n          ++state.cursor;\n        }\n        if (state.cursor != state.length) break;\n      }\n      if (state.length - state.cursor < safe_integer_bytes) {\n        return read_int_stream_slow(state);\n      }\n      const char* source = state.buffer + state.cursor;\n      const bool negative = *source == '-';\n      if (negative || *source == '+') ++source;\n      long long value;\n      const bool complete = negative\n          ? try_parse_digits_unchecked<true>(source, value)\n          : try_parse_digits_unchecked<false>(source, value);\n      if (!complete) return read_int_stream_slow(state);\n      state.cursor = static_cast<std::size_t>(source - state.buffer);\n      return value;\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE unsigned long long read_uint_stream(\n            InputState& state) {\n      for (;;) {\n        if (state.cursor == state.length && !refill(state)) return 0;\n        while (state.cursor != state.length &&\n               static_cast<unsigned char>(state.buffer[state.cursor]) <=\n                   static_cast<unsigned char>(' ')) {\n          ++state.cursor;\n        }\n        if (state.cursor != state.length) break;\n      }\n      if (state.length - state.cursor < safe_integer_bytes) {\n        return read_uint_stream_slow(state);\n      }\n      const char* source = state.buffer + state.cursor;\n      const bool negative = *source == '-';\n      if (negative || *source == '+') ++source;\n      unsigned long long value;\n      if (!try_parse_unsigned_digits_unchecked(source, value)) {\n        return read_uint_stream_slow(state);\n      }\n      state.cursor = static_cast<std::size_t>(source - state.buffer);\n      return negative ? 0ULL - value : value;\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE long long read_int() {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped == nullptr) return read_int_stream(state);\n      const char* source = state.mapped + state.cursor;\n      const long long value =\n          read_mapped_at(source, state.mapped + state.length);\n      state.cursor = static_cast<std::size_t>(source - state.mapped);\n      return value;\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE unsigned long long read_uint() {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped == nullptr) return read_uint_stream(state);\n      const char* source = state.mapped + state.cursor;\n      const unsigned long long value =\n          read_uint_mapped_at(source, state.mapped + state.length);\n      state.cursor = static_cast<std::size_t>(source - state.mapped);\n      return value;\n    }\n    \n    template <class T>\n    inline void read_int_array(T* output, std::size_t count) {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped != nullptr) {\n        const char* source = state.mapped + state.cursor;\n        const char* const end = state.mapped + state.length;\n        for (std::size_t i = 0; i < count; ++i) {\n          output[i] = static_cast<T>(read_mapped_at(source, end));\n        }\n        state.cursor = static_cast<std::size_t>(source - state.mapped);\n      } else {\n        for (std::size_t i = 0; i < count; ++i) {\n          output[i] = static_cast<T>(read_int_stream(state));\n        }\n      }\n    }\n    \n    inline bool fastio_is_space(char value) {\n      return static_cast<unsigned char>(value) <=\n             static_cast<unsigned char>(' ');\n    }\n    \n    inline void skip_spaces(const char*& source, const char* end) {\n      while (source != end && fastio_is_space(*source)) ++source;\n    }\n    \n    inline void consume_separator(const char*& source, const char* end) {\n      if (source != end) {\n        ++source;\n        skip_spaces(source, end);\n      }\n    }\n    \n    inline unsigned parse_eight_digits_simd(const char* source) {\n      const __m128i bytes = _mm_loadl_epi64(\n          reinterpret_cast<const __m128i*>(source));\n      const __m128i digits = _mm_sub_epi8(bytes, _mm_set1_epi8('0'));\n      const __m128i pairs = _mm_maddubs_epi16(\n          digits, _mm_setr_epi8(10, 1, 10, 1, 10, 1, 10, 1,\n                                0, 0, 0, 0, 0, 0, 0, 0));\n      const __m128i quads = _mm_madd_epi16(\n          pairs, _mm_setr_epi16(100, 1, 100, 1, 0, 0, 0, 0));\n      return static_cast<unsigned>(_mm_cvtsi128_si32(quads)) * 10000U +\n          static_cast<unsigned>(_mm_cvtsi128_si32(_mm_srli_si128(quads, 4)));\n    }\n    \n    // 呼び出し元で空白を除去済み。長い先頭ゼロと末尾は境界付き処理へ戻す。\n    inline std::uint32_t read_u32_digits(const char*& source, const char* end) {\n      if (source == end) return 0;\n      const bool negative = *source == '-';\n      if (negative || *source == '+') ++source;\n      unsigned long long value = 0;\n      if (end - source >= 16) {\n        if (has_eight_digits(source)) {\n          value = parse_eight_digits_simd(source);\n          const unsigned ninth = digit_at(source + 8);\n          const unsigned tenth = digit_at(source + 9);\n          if (ninth >= 10U) {\n            source += 8;\n          } else if (tenth >= 10U) {\n            value = value * 10ULL + ninth;\n            source += 9;\n          } else if (digit_at(source + 10) >= 10U) {\n            value = value * 100ULL + ninth * 10U + tenth;\n            source += 10;\n          } else {\n            value = parse_unsigned_digits_bounded(source, end);\n          }\n        } else {\n          for (;;) {\n            const unsigned first = digit_at(source);\n            if (first >= 10U) break;\n            const unsigned second = digit_at(source + 1);\n            if (second >= 10U) {\n              value = value * 10ULL + first;\n              ++source;\n              break;\n            }\n            value = value * 100ULL + first * 10U + second;\n            source += 2;\n          }\n        }\n      } else {\n        value = parse_unsigned_digits_bounded(source, end);\n      }\n      return static_cast<std::uint32_t>(negative ? 0ULL - value : value);\n    }\n    \n    CPLIB_FASTIO_ALWAYS_INLINE std::uint32_t read_u32() {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped != nullptr) {\n        const char* source = state.mapped + state.cursor;\n        const char* const end = state.mapped + state.length;\n        skip_spaces(source, end);\n        const std::uint32_t value = read_u32_digits(source, end);\n        consume_separator(source, end);\n        state.cursor = static_cast<std::size_t>(source - state.mapped);\n        return value;\n      }\n      const char* source = state.buffer + state.cursor;\n      const char* const end = state.buffer + state.length;\n      skip_spaces(source, end);\n      if (CPLIB_FASTIO_UNLIKELY(end - source <\n                               static_cast<std::ptrdiff_t>(safe_integer_bytes))) {\n        return static_cast<std::uint32_t>(read_uint_stream(state));\n      }\n      const std::uint32_t value = read_u32_digits(source, end);\n      // 長い先頭ゼロがrefill境界をまたぐ場合は、元の位置から読み直す。\n      if (CPLIB_FASTIO_UNLIKELY(source == end)) {\n        return static_cast<std::uint32_t>(read_uint_stream(state));\n      }\n      consume_separator(source, end);\n      state.cursor = static_cast<std::size_t>(source - state.buffer);\n      return value;\n    }\n    \n    inline bool try_read_four_nine_digit_u32(\n            const char*& source, const char* end, std::uint32_t* output) {\n      if (end - source < 40) return false;\n      if (!fastio_is_space(source[9]) || !fastio_is_space(source[19]) ||\n          !fastio_is_space(source[29]) || !fastio_is_space(source[39])) {\n        return false;\n      }\n      const __m128i first_two = _mm_unpacklo_epi64(\n          _mm_loadl_epi64(reinterpret_cast<const __m128i*>(source)),\n          _mm_loadl_epi64(reinterpret_cast<const __m128i*>(source + 10)));\n      const __m128i last_two = _mm_unpacklo_epi64(\n          _mm_loadl_epi64(reinterpret_cast<const __m128i*>(source + 20)),\n          _mm_loadl_epi64(reinterpret_cast<const __m128i*>(source + 30)));\n      const __m256i bytes = _mm256_set_m128i(last_two, first_two);\n      const __m256i is_digit = _mm256_and_si256(\n          _mm256_cmpgt_epi8(bytes, _mm256_set1_epi8('/')),\n          _mm256_cmpgt_epi8(_mm256_set1_epi8(':'), bytes));\n      if (static_cast<unsigned>(_mm256_movemask_epi8(is_digit)) !=\n          0xffffffffU) {\n        return false;\n      }\n    \n      const unsigned digit0 = digit_at(source + 8);\n      const unsigned digit1 = digit_at(source + 18);\n      const unsigned digit2 = digit_at(source + 28);\n      const unsigned digit3 = digit_at(source + 38);\n      const bool ninth_digits = (digit0 < 10U) & (digit1 < 10U) &\n                                (digit2 < 10U) & (digit3 < 10U);\n      if (!ninth_digits) return false;\n    \n      const __m256i digits =\n          _mm256_sub_epi8(bytes, _mm256_set1_epi8('0'));\n      const __m256i pairs = _mm256_maddubs_epi16(\n          digits, _mm256_setr_epi8(\n              10, 1, 10, 1, 10, 1, 10, 1,\n              10, 1, 10, 1, 10, 1, 10, 1,\n              10, 1, 10, 1, 10, 1, 10, 1,\n              10, 1, 10, 1, 10, 1, 10, 1));\n      const __m256i quads = _mm256_madd_epi16(\n          pairs, _mm256_setr_epi16(\n              100, 1, 100, 1, 100, 1, 100, 1,\n              100, 1, 100, 1, 100, 1, 100, 1));\n      const __m256i weighted = _mm256_mullo_epi32(\n          quads, _mm256_setr_epi32(\n              10000, 1, 10000, 1, 10000, 1, 10000, 1));\n      const __m256i sums =\n          _mm256_hadd_epi32(weighted, _mm256_setzero_si256());\n      const __m128i first_eight = _mm_unpacklo_epi64(\n          _mm256_castsi256_si128(sums),\n          _mm256_extracti128_si256(sums, 1));\n      const __m128i values = _mm_add_epi32(\n          _mm_mullo_epi32(first_eight, _mm_set1_epi32(10)),\n          _mm_setr_epi32(static_cast<int>(digit0),\n                         static_cast<int>(digit1),\n                         static_cast<int>(digit2),\n                         static_cast<int>(digit3)));\n      _mm_storeu_si128(reinterpret_cast<__m128i*>(output), values);\n      source += 40;\n      return true;\n    }\n    \n    inline void read_uint_array(std::uint32_t* output, std::size_t count) {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped != nullptr) {\n        const char* source = state.mapped + state.cursor;\n        const char* const end = state.mapped + state.length;\n        skip_spaces(source, end);\n        std::size_t i = 0;\n        unsigned nine_digit_count = 0;\n        // 最初の16要素を読みながら分布を確認し、短い整数ではAVX判定を省く。\n        if (count >= 64) {\n          for (; i < 16; ++i) {\n            nine_digit_count += end - source >= 10 &&\n                fastio_is_space(source[9]) && has_eight_digits(source) &&\n                digit_at(source + 8) < 10U;\n            output[i] = read_u32_digits(source, end);\n            consume_separator(source, end);\n          }\n        }\n        if (nine_digit_count >= 12) {\n          while (i < count) {\n            if (count - i >= 4 && try_read_four_nine_digit_u32(\n                    source, end, output + i)) {\n              i += 4;\n              skip_spaces(source, end);\n            } else {\n              output[i++] = read_u32_digits(source, end);\n              if (i != count) consume_separator(source, end);\n            }\n          }\n        } else {\n          while (i < count) {\n            output[i++] = read_u32_digits(source, end);\n            if (i != count) consume_separator(source, end);\n          }\n        }\n        state.cursor = static_cast<std::size_t>(source - state.mapped);\n      } else {\n        std::size_t i = 0;\n        unsigned nine_digit_count = 0;\n        if (count >= 64) {\n          for (; i < 16; ++i) {\n            output[i] = static_cast<std::uint32_t>(read_uint_stream(state));\n            nine_digit_count += output[i] >= 100000000U &&\n                                output[i] < 1000000000U;\n          }\n        }\n        if (nine_digit_count >= 12) {\n          while (count - i >= 4) {\n            const char* source = state.buffer + state.cursor;\n            const char* const end = state.buffer + state.length;\n            skip_spaces(source, end);\n            if (try_read_four_nine_digit_u32(source, end, output + i)) {\n              state.cursor = static_cast<std::size_t>(source - state.buffer);\n              i += 4;\n            } else {\n              state.cursor = static_cast<std::size_t>(source - state.buffer);\n              // refillをまたぐ整数は既存のストリーム処理で最後まで読む。\n              output[i++] = static_cast<std::uint32_t>(read_uint_stream(state));\n            }\n          }\n        }\n        for (; i < count; ++i) {\n          output[i] = static_cast<std::uint32_t>(read_uint_stream(state));\n        }\n      }\n    }\n    \n    template <class T>\n    inline void read_uint_array(T* output, std::size_t count) {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped != nullptr) {\n        const char* source = state.mapped + state.cursor;\n        const char* const end = state.mapped + state.length;\n        for (std::size_t i = 0; i < count; ++i) {\n          output[i] = static_cast<T>(read_uint_mapped_at(source, end));\n        }\n        state.cursor = static_cast<std::size_t>(source - state.mapped);\n      } else {\n        for (std::size_t i = 0; i < count; ++i) {\n          output[i] = static_cast<T>(read_uint_stream(state));\n        }\n      }\n    }\n    \n    inline const char* read_token(std::size_t* output_length) {\n      InputState& state = input_state();\n      if (CPLIB_FASTIO_UNLIKELY(!state.initialized)) initialize(state);\n      if (state.mapped != nullptr) {\n        const char* source = state.mapped + state.cursor;\n        const char* const end = state.mapped + state.length;\n        while (source != end &&\n               static_cast<unsigned char>(*source) <=\n                   static_cast<unsigned char>(' ')) {\n          ++source;\n        }\n        const char* const token = source;\n        while (source != end &&\n               static_cast<unsigned char>(*source) >\n                   static_cast<unsigned char>(' ')) {\n          ++source;\n        }\n        state.cursor = static_cast<std::size_t>(source - state.mapped);\n        *output_length = static_cast<std::size_t>(source - token);\n        return token;\n      }\n    \n      for (;;) {\n        if (state.cursor == state.length && !refill(state)) {\n          *output_length = 0;\n          return \"\";\n        }\n        while (state.cursor != state.length &&\n               static_cast<unsigned char>(state.buffer[state.cursor]) <=\n                   static_cast<unsigned char>(' ')) {\n          ++state.cursor;\n        }\n        if (state.cursor != state.length) break;\n      }\n    \n      const std::size_t token_begin = state.cursor;\n      while (state.cursor != state.length &&\n             static_cast<unsigned char>(state.buffer[state.cursor]) >\n                 static_cast<unsigned char>(' ')) {\n        ++state.cursor;\n      }\n      if (state.cursor != state.length) {\n        *output_length = state.cursor - token_begin;\n        return state.buffer + token_begin;\n      }\n    \n      std::string& storage = token_storage();\n      storage.assign(state.buffer + token_begin,\n                     state.length - token_begin);\n      while (refill(state)) {\n        while (state.cursor != state.length &&\n               static_cast<unsigned char>(state.buffer[state.cursor]) >\n                   static_cast<unsigned char>(' ')) {\n          ++state.cursor;\n        }\n        storage.append(state.buffer, state.cursor);\n        if (state.cursor != state.length) break;\n      }\n      *output_length = storage.size();\n      return storage.c_str();\n    }\n    \n    #undef CPLIB_FASTIO_UNLIKELY\n    #undef CPLIB_FASTIO_ALWAYS_INLINE\n    } // namespace cplib_fastio_input\n    \"\"\".}\n    \n        proc fastioGetChar(): cint {.importcpp: \"cplib_fastio_input::get_char()\", nodecl, inline.}\n        proc fastioReadInt(): clonglong {.importcpp: \"cplib_fastio_input::read_int()\", nodecl, inline.}\n        proc fastioReadUInt(): culonglong {.importcpp: \"cplib_fastio_input::read_uint()\", nodecl, inline.}\n        proc fastioReadUInt32(): uint32 {.importcpp: \"cplib_fastio_input::read_u32()\", nodecl, inline.}\n        proc fastioReadSignedArray[T: SomeSignedInt](values: ptr T, count: csize_t) {.importcpp: \"cplib_fastio_input::read_int_array(@)\", nodecl, inline.}\n        proc fastioReadUnsignedArray[T: SomeUnsignedInt](values: ptr T, count: csize_t) {.importcpp: \"cplib_fastio_input::read_uint_array(@)\", nodecl, inline.}\n        proc fastioReadToken(length: ptr csize_t): cstring\n            {.importcpp: \"cplib_fastio_input::read_token(@)\", nodecl, inline.}\n    \n        type FastioInteger = int | int8 | int16 | int32 | int64 |\n            uint | uint8 | uint16 | uint32 | uint64\n    \n        when NimMajor >= 2:\n            template fastioNewSeqUninit(T: typedesc, length: int): untyped =\n                newSeqUninit[T](length)\n    \n            template fastioNewStringUninit(length: int): untyped =\n                newStringUninit(length)\n        else:\n            template fastioNewSeqUninit(T: typedesc, length: int): untyped =\n                newSeqUninitialized[T](length)\n    \n            template fastioNewStringUninit(length: int): untyped =\n                newString(length)\n    \n        proc ii(): int {.inline,\n                codegenDecl: \"CPLIB_FASTIO_NIM_ALWAYS_INLINE $# $#$#\".} =\n            fastioReadInt().int\n        proc lii(N: int): seq[int] {.inline.} =\n            result = fastioNewSeqUninit(int, N)\n            if N > 0:\n                fastioReadSignedArray(addr result[0], N.csize_t)\n    \n        # 型だけなら1要素、長さと型ならseqとして読み込む。\n        proc input[T: FastioInteger](valueType: typedesc[T]): T {.inline,\n                codegenDecl: \"CPLIB_FASTIO_NIM_ALWAYS_INLINE $# $#$#\".} =\n            when T is range:\n                {.error: \"input supports only primitive integer types\".}\n            elif T is SomeSignedInt:\n                T(fastioReadInt())\n            elif T is uint32:\n                fastioReadUInt32()\n            else:\n                T(fastioReadUInt())\n    \n        proc input[T: FastioInteger](N: int, valueType: typedesc[T]): seq[T] {.inline.} =\n            when T is range:\n                {.error: \"input supports only primitive integer types\".}\n            else:\n                result = fastioNewSeqUninit(T, N)\n                if N > 0:\n                    when T is SomeSignedInt:\n                        fastioReadSignedArray(addr result[0], N.csize_t)\n                    else:\n                        fastioReadUnsignedArray(addr result[0], N.csize_t)\n    \n        proc si(): string {.inline.} =\n            var length: csize_t\n            let source = fastioReadToken(addr length)\n            result = fastioNewStringUninit(length.int)\n            if length != 0:\n                copyMem(addr result[0], source, length.int)\n    \n        # 出力系\n        {.emit: \"\"\"\n    #include <cstdio>\n    #include <cstddef>\n    #include <cstdint>\n    #include <cstring>\n    #include <type_traits>\n    \n    namespace cplib_fastio_output {\n    struct StdoutBuffer {\n      static constexpr std::size_t capacity = 1U << 16;\n      alignas(64) char data[capacity];\n    \n      StdoutBuffer() { setvbuf(stdout, data, _IOFBF, capacity); }\n    };\n    \n    static StdoutBuffer stdout_buffer;\n    \n    struct FourDigits {\n      char data[10000][4];\n      constexpr FourDigits() : data{} {\n        for (unsigned i = 0; i < 10000; ++i) {\n          data[i][0] = static_cast<char>('0' + i / 1000);\n          data[i][1] = static_cast<char>('0' + i / 100 % 10);\n          data[i][2] = static_cast<char>('0' + i / 10 % 10);\n          data[i][3] = static_cast<char>('0' + i % 10);\n        }\n      }\n    };\n    \n    constexpr FourDigits four_digit_table{};\n    \n    inline const FourDigits& four_digits() {\n      return four_digit_table;\n    }\n    \n    inline char* reserve_bytes(std::FILE* output, std::size_t size) {\n    #if defined(__GLIBC__)\n      // stdio自身のバッファを使い、echo/write/flushFileとの出力順を保つ。\n      if (output->_IO_write_ptr != nullptr &&\n          output->_IO_write_end != nullptr &&\n          static_cast<std::size_t>(output->_IO_write_end -\n                                   output->_IO_write_ptr) >= size) {\n        return output->_IO_write_ptr;\n      }\n    #endif\n      return nullptr;\n    }\n    \n    inline void commit_bytes(std::FILE* output, char* end) {\n    #if defined(__GLIBC__)\n      output->_IO_write_ptr = end;\n    #else\n      (void)output;\n      (void)end;\n    #endif\n    }\n    \n    inline char* write_small(char* output, unsigned value,\n                             const FourDigits& table) {\n      if (value >= 1000) {\n        std::memcpy(output, table.data[value], 4);\n        return output + 4;\n      }\n      if (value >= 100) {\n        std::memcpy(output, table.data[value] + 1, 3);\n        return output + 3;\n      }\n      if (value >= 10) {\n        std::memcpy(output, table.data[value] + 2, 2);\n        return output + 2;\n      }\n      *output++ = static_cast<char>('0' + value);\n      return output;\n    }\n    \n    inline char* write_four(char* output, unsigned value,\n                            const FourDigits& table) {\n      std::memcpy(output, table.data[value], 4);\n      return output + 4;\n    }\n    \n    inline char* write_unsigned_32(char* output, std::uint32_t value,\n                                   const FourDigits& table) {\n      if (value < 10000U) return write_small(output, value, table);\n      const std::uint32_t quotient = value / 10000U;\n      const unsigned low = static_cast<unsigned>(value - quotient * 10000U);\n      if (quotient < 10000U) {\n        output = write_small(output, quotient, table);\n        return write_four(output, low, table);\n      }\n      const unsigned high = quotient / 10000U;\n      const unsigned middle = quotient - high * 10000U;\n      output = write_small(output, high, table);\n      output = write_four(output, middle, table);\n      return write_four(output, low, table);\n    }\n    \n    inline char* write_unsigned_64(char* output, std::uint64_t value,\n                                   const FourDigits& table) {\n      if (value < 10000ULL) {\n        return write_small(output, static_cast<unsigned>(value), table);\n      }\n      const std::uint64_t quotient1 = value / 10000ULL;\n      const unsigned chunk1 = static_cast<unsigned>(value - quotient1 * 10000ULL);\n      if (quotient1 < 10000ULL) {\n        output = write_small(output, static_cast<unsigned>(quotient1), table);\n        return write_four(output, chunk1, table);\n      }\n      const std::uint64_t quotient2 = quotient1 / 10000ULL;\n      const unsigned chunk2 = static_cast<unsigned>(quotient1 - quotient2 * 10000ULL);\n      if (quotient2 < 10000ULL) {\n        output = write_small(output, static_cast<unsigned>(quotient2), table);\n        output = write_four(output, chunk2, table);\n        return write_four(output, chunk1, table);\n      }\n      const std::uint64_t quotient3 = quotient2 / 10000ULL;\n      const unsigned chunk3 = static_cast<unsigned>(quotient2 - quotient3 * 10000ULL);\n      if (quotient3 < 10000ULL) {\n        output = write_small(output, static_cast<unsigned>(quotient3), table);\n        output = write_four(output, chunk3, table);\n        output = write_four(output, chunk2, table);\n        return write_four(output, chunk1, table);\n      }\n      const std::uint64_t quotient4 = quotient3 / 10000ULL;\n      const unsigned chunk4 = static_cast<unsigned>(quotient3 - quotient4 * 10000ULL);\n      output = write_small(output, static_cast<unsigned>(quotient4), table);\n      output = write_four(output, chunk4, table);\n      output = write_four(output, chunk3, table);\n      output = write_four(output, chunk2, table);\n      return write_four(output, chunk1, table);\n    }\n    \n    template <class Unsigned>\n    inline char* write_unsigned_dispatch(char* output, Unsigned value,\n                                         const FourDigits& table,\n                                         std::true_type) {\n      return write_unsigned_32(output, static_cast<std::uint32_t>(value), table);\n    }\n    \n    template <class Unsigned>\n    inline char* write_unsigned_dispatch(char* output, Unsigned value,\n                                         const FourDigits& table,\n                                         std::false_type) {\n      return write_unsigned_64(output, static_cast<std::uint64_t>(value), table);\n    }\n    \n    template <class Unsigned>\n    inline char* write_unsigned(char* output, Unsigned value,\n                                const FourDigits& table) {\n      return write_unsigned_dispatch(output, value, table,\n          std::integral_constant<bool, (sizeof(Unsigned) <= 4)>{});\n    }\n    \n    template <class Integer>\n    inline std::size_t join_integers(\n            const Integer* values, std::size_t count, char* output,\n            const char* separator, std::size_t separator_length) {\n      const FourDigits& table = four_digits();\n      char* cursor = output;\n      using Unsigned = typename std::make_unsigned<Integer>::type;\n      for (std::size_t i = 0; i < count; ++i) {\n        const Integer value = values[i];\n        Unsigned magnitude = static_cast<Unsigned>(value);\n        if (std::is_signed<Integer>::value && value < 0) {\n          *cursor++ = '-';\n          magnitude = Unsigned(0) - magnitude;\n        }\n        cursor = write_unsigned(cursor, magnitude, table);\n        if (i + 1 != count) {\n          std::memcpy(cursor, separator, separator_length);\n          cursor += separator_length;\n        }\n      }\n      return static_cast<std::size_t>(cursor - output);\n    }\n    \n    class BufferedWriter {\n     public:\n      static constexpr std::size_t capacity = 1U << 16;\n    \n      explicit BufferedWriter(std::FILE* output)\n          : length_(0), output_(output) {}\n    \n      inline char* reserve_integer() {\n        constexpr std::size_t max_integer_length = 21;\n        if (capacity - length_ < max_integer_length) flush();\n        return data_ + length_;\n      }\n    \n      inline void commit(char* end) {\n        length_ = static_cast<std::size_t>(end - data_);\n      }\n    \n      inline void append(const char* source, std::size_t size) {\n        if (size <= capacity - length_) {\n          std::memcpy(data_ + length_, source, size);\n          length_ += size;\n          return;\n        }\n        flush();\n        if (size >= capacity) {\n          fwrite_unlocked(source, 1, size, output_);\n        } else {\n          std::memcpy(data_, source, size);\n          length_ = size;\n        }\n      }\n    \n      inline void flush() {\n        if (length_ != 0) {\n          fwrite_unlocked(data_, 1, length_, output_);\n          length_ = 0;\n        }\n      }\n    \n     private:\n      char data_[capacity];\n      std::size_t length_;\n      std::FILE* output_;\n    };\n    \n    template <class Integer>\n    inline void print_integers(std::FILE* output, const Integer* values,\n                             std::size_t count,\n                             const char* separator,\n                             std::size_t separator_length) {\n      const FourDigits& table = four_digits();\n      BufferedWriter writer(output);\n      using Unsigned = typename std::make_unsigned<Integer>::type;\n      for (std::size_t i = 0; i < count; ++i) {\n        char* cursor = writer.reserve_integer();\n        const Integer value = values[i];\n        Unsigned magnitude = static_cast<Unsigned>(value);\n        if (std::is_signed<Integer>::value && value < 0) {\n          *cursor++ = '-';\n          magnitude = Unsigned(0) - magnitude;\n        }\n        cursor = write_unsigned(cursor, magnitude, table);\n        writer.commit(cursor);\n        if (i + 1 != count) writer.append(separator, separator_length);\n      }\n      writer.append(\"\\n\", 1);\n      writer.flush();\n    }\n    \n    template <class Integer>\n    inline void print_one(std::FILE* output, Integer value) {\n      const FourDigits& table = four_digits();\n      char buffer[22];\n      char* const reserved = reserve_bytes(output, sizeof(buffer));\n      char* const begin = reserved == nullptr ? buffer : reserved;\n      char* cursor = begin;\n      using Unsigned = typename std::make_unsigned<Integer>::type;\n      Unsigned magnitude = static_cast<Unsigned>(value);\n      if (std::is_signed<Integer>::value && value < 0) {\n        *cursor++ = '-';\n        magnitude = Unsigned(0) - magnitude;\n      }\n      cursor = write_unsigned(cursor, magnitude, table);\n      *cursor++ = '\\n';\n      if (reserved != nullptr) {\n        commit_bytes(output, cursor);\n      } else {\n        fwrite_unlocked(buffer, 1,\n                        static_cast<std::size_t>(cursor - buffer), output);\n      }\n    }\n    \n    } // namespace cplib_fastio_output\n    \"\"\".}\n    \n        proc fastioJoinInts[T: SomeInteger](values: ptr T, count: csize_t,\n                output: ptr char, separator: cstring, separatorLen: csize_t): csize_t\n            {.importcpp: \"cplib_fastio_output::join_integers(@)\", nodecl.}\n        proc fastioPrintInts[T: SomeInteger](output: File, values: ptr T,\n                count: csize_t, separator: cstring, separatorLen: csize_t)\n            {.importcpp: \"cplib_fastio_output::print_integers(@)\", nodecl.}\n        proc fastioPrintInt[T: SomeInteger](output: File, value: T)\n            {.importcpp: \"cplib_fastio_output::print_one(@)\", nodecl.}\n    \n        proc print_internal(prop: tuple[f: File, sepc: string, endc: string,\n                flush: bool], args: openArray[string]) =\n            for i in 0 ..< args.len:\n                prop.f.write(args[i])\n                if i != args.len - 1:\n                    prop.f.write(prop.sepc)\n                else:\n                    prop.f.write(prop.endc)\n            if prop.flush:\n                prop.f.flushFile()\n    \n        proc print*(prop: tuple[f: File, sepc: string, endc: string, flush: bool],\n                args: varargs[string, `$`]) =\n            print_internal(prop, args)\n    \n        proc fastioPrintWithSeparator(sep: string, args: varargs[string, `$`]) =\n            print_internal((f: stdout, sepc: sep, endc: \"\\n\", flush: false), args)\n    \n        proc fastioAppendInteger[T: SomeInteger](destination: var string, value: T) =\n            var magnitude: uint64\n            when T is SomeSignedInt:\n                let signedValue = value.int64\n                if signedValue < 0:\n                    destination.add('-')\n                    magnitude = uint64(-(signedValue + 1)) + 1'u64\n                else:\n                    magnitude = signedValue.uint64\n            else:\n                magnitude = value.uint64\n    \n            if magnitude == 0:\n                destination.add('0')\n                return\n            var digits: array[20, char]\n            var count = 0\n            while magnitude != 0:\n                digits[count] = char(ord('0') + int(magnitude mod 10))\n                magnitude = magnitude div 10\n                inc count\n            while count != 0:\n                dec count\n                destination.add(digits[count])\n    \n        # 整数は4桁テーブルを使うC++フォーマッタへまとめて渡す。\n        proc fastioJoinImpl[T](a: openArray[T], sep: string): string =\n            when nimvm:\n                result = newStringOfCap(a.len * 4)\n                for i, value in a:\n                    if i != 0:\n                        result.add(sep)\n                    when T is SomeInteger:\n                        fastioAppendInteger(result, value)\n                    else:\n                        result.add($value)\n            else:\n                if a.len == 0:\n                    return \"\"\n                when T is SomeInteger and sizeof(T) in [4, 8]:\n                    const digits = when sizeof(T) == 8: 20\n                                   elif T is SomeSignedInt: 11\n                                   else: 10\n                    result = fastioNewStringUninit(\n                        a.len * digits + (a.len - 1) * sep.len)\n                    let written = fastioJoinInts(unsafeAddr a[0],\n                        a.len.csize_t, addr result[0], sep.cstring, sep.len.csize_t)\n                    result.setLen(written.int)\n                elif compiles(T.umod()) and compiles(a[0].val()):\n                    # Montgomery表現を含め、公開値へ正規化してから一括変換する。\n                    var canonical = fastioNewSeqUninit(uint32, a.len)\n                    for i, value in a:\n                        canonical[i] = value.val.uint32\n                    result = fastioJoinImpl(canonical, sep)\n                else:\n                    result = newStringOfCap(a.len * 4)\n                    for i, value in a:\n                        if i != 0:\n                            result.add(sep)\n                        when T is SomeInteger:\n                            fastioAppendInteger(result, value)\n                        else:\n                            result.add($value)\n    \n        proc join*[T: not string](a: openArray[T], sep: string = \"\"): string {.inline.} =\n            fastioJoinImpl(a, sep)\n    \n        proc fastioPrintArrayImpl[T](a: openArray[T], sep: string) =\n            if a.len == 0:\n                stdout.write('\\n')\n                return\n            when T is SomeInteger and sizeof(T) in [4, 8]:\n                fastioPrintInts(stdout, unsafeAddr a[0], a.len.csize_t,\n                    sep.cstring, sep.len.csize_t)\n            elif compiles(T.umod()) and compiles(a[0].val()):\n                var canonical = fastioNewSeqUninit(uint32, a.len)\n                for i, value in a:\n                    canonical[i] = value.val.uint32\n                fastioPrintArrayImpl(canonical, sep)\n            else:\n                stdout.write(fastioJoinImpl(a, sep))\n                stdout.write('\\n')\n    \n        proc fastioPrintOneImpl[T](value: T, sep: string) =\n            when T is SomeInteger and sizeof(T) in [4, 8]:\n                fastioPrintInt(stdout, value)\n            elif compiles(T.umod()) and compiles(value.val()):\n                fastioPrintInt(stdout, value.val.uint32)\n            else:\n                fastioPrintWithSeparator(sep, value)\n    \n        proc fastioPrintIntegerMany[T: SomeInteger](sep: string,\n                values: varargs[T]) =\n            fastioPrintArrayImpl(values, sep)\n    \n        # Python風に print(*X) と書くと、Xを空白区切りで1行に出力する。\n        template `*`*[T](values: openArray[T]): string =\n            fastioJoinImpl(values, \" \")\n    \n        # 最後の文字列引数をsepと誤認しないよう、名前付きsepはマクロで処理する。\n        macro print*(args: varargs[untyped]): untyped =\n            var sep = newLit(\" \")\n            var hasSep = false\n            var values: seq[NimNode]\n            for arg in args:\n                if arg.kind == nnkExprEqExpr and arg[0].eqIdent(\"sep\"):\n                    if hasSep:\n                        error(\"sep can only be specified once\", arg)\n                    sep = arg[1]\n                    hasSep = true\n                else:\n                    values.add(arg)\n            var splatValues: NimNode\n            if values.len == 1:\n                if values[0].kind == nnkPrefix and values[0][0].eqIdent(\"*\"):\n                    splatValues = values[0][1]\n                elif values[0].kind in nnkCallKinds and values[0].len == 3 and\n                        values[0][0].eqIdent(\"fastioJoinImpl\"):\n                    # オーバーロード解決時に *values が先に展開された場合。\n                    splatValues = values[0][1]\n            if not splatValues.isNil:\n                result = newCall(bindSym\"fastioPrintArrayImpl\", splatValues, sep)\n            elif values.len == 1:\n                result = newCall(bindSym\"fastioPrintOneImpl\", values[0], sep)\n            else:\n                let integerCall = newCall(bindSym\"fastioPrintIntegerMany\", sep)\n                let fallbackCall = newCall(bindSym\"fastioPrintWithSeparator\", sep)\n                for value in values:\n                    integerCall.add(value)\n                    fallbackCall.add(value)\n                result = quote do:\n                    when compiles(`integerCall`):\n                        `integerCall`\n                    else:\n                        `fallbackCall`\n    \n    macro getSymbolName(x: typed): string = x.toStrLit\n    macro debug*(args: varargs[untyped]): untyped =\n        when defined(debug):\n            result = newNimNode(nnkStmtList, args)\n            template prop(e: string = \"\"): untyped = (f: stderr, sepc: \"\", endc: e, flush: true)\n            for i, arg in args:\n                if arg.kind == nnkStrLit:\n                    result.add(quote do: print(prop(), \"\\\"\", `arg`, \"\\\"\"))\n                else:\n                    result.add(quote do: print(prop(\": \"), getSymbolName(`arg`)))\n                    result.add(quote do: print(prop(), `arg`))\n                if i != args.len - 1: result.add(quote do: print(prop(), \", \"))\n                else: result.add(quote do: print(prop(), \"\\n\"))\n        else:\n            return (quote do: discard)\n    #chmin,chmax\n    template `max=`(x, y) =\n        let yVal = y # yが計算式の場合に評価を1回にするため\n        if x < yVal:\n            x = yVal\n\n    template `min=`(x, y) =\n        let yVal = y\n        if x > yVal:\n            x = yVal\n    proc chmin[T](x: var T, y: T):bool=\n        if x > y:\n            x = y\n            return true\n        return false\n    proc chmax[T](x: var T, y: T):bool=\n        if x < y:\n            x = y\n            return true\n        return false\n    #bit演算\n    proc `%`*(x: int, y: int): int =\n        result = x mod y\n        if y > 0 and result < 0: result += y\n        if y < 0 and result > 0: result += y\n    proc `//`*(x: int, y: int): int{.inline.} =\n        result = x div y\n        if y > 0 and result * y > x: result -= 1\n        if y < 0 and result * y < x: result -= 1\n    proc `%=`(x: var int, y: int): void = x = x%y\n    proc `//=`(x: var int, y: int): void = x = x//y\n    proc `**`(x: int, y: int): int = x^y\n    proc `**=`(x: var int, y: int): void = x = x^y\n    proc `^`(x: int, y: int): int = x xor y\n    proc `|`(x: int, y: int): int = x or y\n    proc `&`(x: int, y: int): int = x and y\n    proc `>>`(x: int, y: int): int = x shr y\n    proc `<<`(x: int, y: int): int = x shl y\n    proc `~`(x: int): int = not x\n    proc `^=`(x: var int, y: int): void = x = x ^ y\n    proc `&=`(x: var int, y: int): void = x = x & y\n    proc `|=`(x: var int, y: int): void = x = x | y\n    proc `>>=`(x: var int, y: int): void = x = x >> y\n    proc `<<=`(x: var int, y: int): void = x = x << y\n    proc `[]`(x: int, n: int): bool = (x and (1 shl n)) != 0\n    #便利な変換\n    proc `!`(x: char, a = '0'): int = int(x)-int(a)\n    #定数\n    when not declared CPLIB_UTILS_CONSTANTS:\n        const CPLIB_UTILS_CONSTANTS* = 1\n        const INF32*: int32 = 1001000027.int32\n        const INF64*: int = int(3300300300300300491)\n    \n    const INF = INF64\n    #converter\n\n    #range\n    iterator range(start: int, ends: int, step: int): int =\n        var i = start\n        if step < 0:\n            while i > ends:\n                yield i\n                i += step\n        elif step > 0:\n            while i < ends:\n                yield i\n                i += step\n    iterator range(ends: int): int = (for i in 0..<ends: yield i)\n    iterator range(start: int, ends: int): int = (for i in\n            start..<ends: yield i)\n\n    proc dump[T](arr:seq[seq[T]])=\n        for i in 0..<len(arr):\n            echo arr[i]\n\n    proc sum(slice:HSlice[int,int]):int=\n        return (slice.a+slice.b)*len(slice)//2\n    \n    proc `<`[T](l,r:seq[T]):bool=\n        for i in 0..<min(len(l),len(r)):\n            if l[i] > r[i]:\n                return false\n            elif l[i] < r[i]:\n                return true\n        return len(l) < len(r)\n    \n    # Yes/No\n    proc yes*(b: bool = true): void = print(if b: \"Yes\" else: \"No\")\n\n    template dblock(body: untyped) =\n        when defined(debug):\n            block:\n                body\n"
# source: src/cplib/tmpl/optimize.nim
ImportExpand "cplib/tmpl/optimize" <=== "when not declared CPLIB_TMPL_OPTIMIZE:\n    const CPLIB_TMPL_OPTIMIZE* = 1\n    import macros\n    import strutils\n    import std/compilesettings\n    macro optimize*(arg: static string = \"\"\"nim c -d:danger -d:second_compile -d:useMalloc --gc:arc --panics:on --opt:speed --checks:off --passC:\"-flto -m64 -march=native -ffast-math\" --hints:off \"\"\") =\n        let isSecond = defined(second_compile)\n        let isDebug = defined(debug)\n\n        if (not isSecond) and (not isDebug):\n            if \"-d:second_compile\" notin arg:\n                error(\"plz add -d:second_compile\")\n            let sourcePath = querySetting(SingleValueSetting.projectFull)\n            let projectDir = sourcePath[0..<sourcePath.rfind('/')]\n            let outFile = querySetting(SingleValueSetting.outFile)\n            let outFlag = if outFile.len > 0: \"-o:\" & outFile & \" \" else: \"-o:a.out \"\n            var cmd = \"cd \" & projectDir & \" && export PATH=$HOME/.nimble/bin:$PATH && \" & arg\n            cmd.add(outFlag & sourcePath)\n\n            echo \"--- Self-Recompiling with optimized settings ---\"\n            echo \"Command: \", cmd\n            echo \"\\n\\n\\n\"\n\n            let output = staticExec(cmd)\n            warning(output)\n            echo \"\\n\\n\\n\"\n\n            quit(0)"

{.define: fastioNoMmap.}
optimize("""nim cpp -d:danger -d:second_compile -d:useMalloc --gc:none --panics:on --opt:speed --checks:off --passC:"-O3 -flto -m64 -march=native -ffast-math" --hints:off """)


var H,W = ii()
var A = input(H*W,uint32)
var S = newseqwith(H,uint32(0))
for i in 0..<(H):
    for j in 0..<(W):
        S[i] += A[i*W+j]
var T = S.sum()
S.applyit((it + T))
print(S.join("\n"))
0