結果

問題 No.2086 A+B問題
ユーザー 👑 p-adicp-adic
提出日時 2023-09-22 13:12:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 43,816 bytes
コンパイル時間 4,822 ms
コンパイル使用メモリ 257,856 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 04:55:52
合計ジャッジ時間 4,856 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef DEBUG
  #define _GLIBCXX_DEBUG
  #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ); signal( SIGABRT , &AlertAbort )
  #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , DEBUG_VALUE )
  #define CERR( ... ) VariadicCout( cerr , __VA_ARGS__ ) << endl
  #define COUT( ... ) VariadicCout( cout << "出力: " , __VA_ARGS__ ) << endl
  #define CERR_A( A , N ) OUTPUT_ARRAY( cerr , A , N ) << endl
  #define COUT_A( A , N ) cout << "出力: "; OUTPUT_ARRAY( cout , A , N ) << endl
  #define CERR_ITR( A ) OUTPUT_ITR( cerr , A ) << endl
  #define COUT_ITR( A ) cout << "出力: "; OUTPUT_ITR( cout , A ) << endl
  #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " , ( MIN ) , ( ( MIN ) <= A ? "<=" : ">" ) , A , ( A <= ( MAX ) ? "<=" : ">" ) , ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) )
  #define AUTO_CHECK bool auto_checked = true; AutoCheck( auto_checked ); if( auto_checked ){ return 0; };
#else
  #pragma GCC optimize ( "O3" )
  #pragma GCC optimize ( "unroll-loops" )
  #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
  #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr )
  #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , VALUE )
  #define CERR( ... ) 
  #define COUT( ... ) VariadicCout( cout , __VA_ARGS__ ) << "\n"
  #define CERR_A( A , N ) 
  #define COUT_A( A , N ) OUTPUT_ARRAY( cout , A , N ) << "\n"
  #define CERR_ITR( A ) 
  #define COUT_ITR( A ) OUTPUT_ITR( cout , A ) << "\n"
  #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
  #define AUTO_CHECK
#endif
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using lld = __float128;
// #define RANDOM_TEST
#if defined( DEBUG ) && defined( RANDOM_TEST )
  ll GetRand( const ll& Rand_min , const ll& Rand_max );
 #define SET_ASSERT( A , MIN , MAX ) CERR( #A , " = " , ( A = GetRand( MIN , MAX ) ) )
 #define RETURN( ANSWER ) if( ( ANSWER ) == guchoku ){ CERR( ANSWER , "==" , guchoku ); goto END_MAIN; } else { CERR( ANSWER , "!=" , guchoku ); QUIT; }
#else
  #define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX )
  #define RETURN( ANSWER ) COUT( ANSWER ); QUIT
#endif
#define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) )
#define TYPE_OF( VAR ) decay_t<decltype( VAR )>
#define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE
#define CIN( LL , ... ) LL __VA_ARGS__; VariadicCin( cin , __VA_ARGS__ )
#define CIN_ASSERT( A , MIN , MAX ) TYPE_OF( MAX ) A; SET_ASSERT( A , MIN , MAX )
#define CIN_A( LL , A , N ) LL A[N]; FOR( VARIABLE_FOR_CIN_A , 0 , N ){ cin >> A[VARIABLE_FOR_CIN_A]; }
#define GETLINE_SEPARATE( SEPARATOR , ... ) string __VA_ARGS__; VariadicGetline( cin , SEPARATOR , __VA_ARGS__ )
#define GETLINE( ... ) GETLINE_SEPARATE( " " , ... )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- )
#define AUTO_ITR( ARRAY ) auto itr_ ## ARRAY = ARRAY .begin() , end_ ## ARRAY = ARRAY .end()
#define FOR_ITR( ARRAY ) for( AUTO_ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT_ ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES )
#define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS )
#define OUTPUT_ARRAY( OS , A , N ) FOR( VARIABLE_FOR_OUTPUT_ARRAY , 0 , N ){ OS << A[VARIABLE_FOR_OUTPUT_ARRAY] << (VARIABLE_FOR_OUTPUT_ARRAY==N-1?"":" "); } OS
#define OUTPUT_ITR( OS , A ) { auto ITERATOR_FOR_OUTPUT_ITR = A.begin() , END_FOR_OUTPUT_ITR = A.end(); bool VARIABLE_FOR_OUTPUT_ITR = ITERATOR_FOR_COUT_ITR != END_FOR_COUT_ITR; while( VARIABLE_FOR_OUTPUT_ITR ){ OS << *ITERATOR_FOR_COUT_ITR; ( VARIABLE_FOR_OUTPUT_ITR = ++ITERATOR_FOR_COUT_ITR != END_FOR_COUT_ITR ) ? OS : OS << " "; } } OS
#define QUIT goto END_MAIN
#define TEST_CASE_NUM( BOUND ) DEXPR( int , bound_T , BOUND , min( BOUND , 100 ) ); int T = 1; if constexpr( bound_T > 1 ){ SET_ASSERT( T , 1 , bound_T ); }
#define START_MAIN REPEAT( T ){ { if constexpr( bound_T > 1 ){ CERR( "testcase " , VARIABLE_FOR_REPEAT_T , ":" ); }
#define START_WATCH chrono::system_clock::time_point watch = chrono::system_clock::now()
#define CURRENT_TIME static_cast<double>( chrono::duration_cast<chrono::microseconds>( chrono::system_clock::now() - watch ).count() / 1000.0 )
#define CHECK_WATCH( TL_MS ) ( CURRENT_TIME < TL_MS - 100.0 )
#define FINISH_MAIN QUIT; } END_MAIN: CERR( "" ); }

// 入出力用関数
template <class Traits> inline basic_istream<char,Traits>& VariadicCin( basic_istream<char,Traits>& is ) { return is; }
template <class Traits , typename Arg , typename... ARGS> inline basic_istream<char,Traits>& VariadicCin( basic_istream<char,Traits>& is , Arg& arg , ARGS&... args ) { return VariadicCin( is >> arg , args... ); }
template <class Traits> inline basic_istream<char,Traits>& VariadicGetline( basic_istream<char,Traits>& is , const char& separator ) { return is; }
template <class Traits , typename Arg , typename... ARGS> inline basic_istream<char,Traits>& VariadicGetline( basic_istream<char,Traits>& is , const char& separator , Arg& arg , ARGS&... args ) { return VariadicGetline( getline( is , arg , separator ) , separator , args... ); }
template <class Traits , typename Arg> inline basic_ostream<char,Traits>& VariadicCout( basic_ostream<char,Traits>& os , const Arg& arg ) { return os << arg; }
template <class Traits , typename Arg1 , typename Arg2 , typename... ARGS> inline basic_ostream<char,Traits>& VariadicCout( basic_ostream<char,Traits>& os , const Arg1& arg1 , const Arg2& arg2 , const ARGS&... args ) { return VariadicCout( os << arg1 << " " , arg2 , args... ); }

// 算術用関数
template <typename T> inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); }
inline ll MIN( const ll& a , const ll& b ){ return min( a , b ); }
inline ull MIN( const ull& a , const ull& b ){ return min( a , b ); }
inline ll MAX( const ll& a , const ll& b ){ return max( a , b ); }
inline ull MAX( const ull& a , const ull& b ){ return max( a , b ); }

#define POWER( ANSWER , ARGUMENT , EXPONENT )				\
  static_assert( ! is_same<TYPE_OF( ARGUMENT ),int>::value && ! is_same<TYPE_OF( ARGUMENT ),uint>::value ); \
  TYPE_OF( ARGUMENT ) ANSWER{ 1 };					\
  {									\
    TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT );	\
    TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT );	\
    while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){			\
      if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){			\
	ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER;			\
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER;	\
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\

#define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO )		\
  ll ANSWER{ 1 };							\
  {									\
    ll ARGUMENT_FOR_SQUARE_FOR_POWER = ( ( MODULO ) + ( ( ARGUMENT ) % ( MODULO ) ) ) % ( MODULO ); \
    TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT );	\
    while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){			\
      if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){			\
	ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\

#define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_INDEX , CONSTEXPR_LENGTH , MODULO ) \
  static ll ANSWER[CONSTEXPR_LENGTH];					\
  static ll ANSWER_INV[CONSTEXPR_LENGTH];				\
  static ll INVERSE[CONSTEXPR_LENGTH];					\
  {									\
    ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1;				\
    ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL;			\
    FOREQ( i , 1 , MAX_INDEX ){						\
      ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= ( MODULO ); \
    }									\
    ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \
    FOREQ( i , 2 , MAX_INDEX ){						\
      ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = ( MODULO ) - ( ( ( ( MODULO ) / i ) * INVERSE[ ( MODULO ) % i ] ) % ( MODULO ) ) ) %= ( MODULO ); \
    }									\
  }									\

// 二分探索テンプレート
// EXPRESSIONがANSWERの広義単調関数の時、EXPRESSION >= TARGETの整数解を格納。
#define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , DESIRED_INEQUALITY , TARGET , INEQUALITY_FOR_CHECK , UPDATE_U , UPDATE_L , UPDATE_ANSWER ) \
  static_assert( ! is_same<TYPE_OF( TARGET ),uint>::value && ! is_same<TYPE_OF( TARGET ),ull>::value ); \
  ll ANSWER = MINIMUM;							\
  if( MINIMUM <= MAXIMUM ){						\
    ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM;				\
    ll VARIABLE_FOR_BINARY_SEARCH_U = MAXIMUM;				\
    ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \
    ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH;			\
    while( VARIABLE_FOR_BINARY_SEARCH_L != VARIABLE_FOR_BINARY_SEARCH_U ){ \
      VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( EXPRESSION ) - ( TARGET ); \
      CERR( "二分探索中: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << "-" << TARGET << "=" << VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ); \
      if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH INEQUALITY_FOR_CHECK 0 ){	\
	VARIABLE_FOR_BINARY_SEARCH_U = UPDATE_U;			\
      } else {								\
	VARIABLE_FOR_BINARY_SEARCH_L = UPDATE_L;			\
      }									\
      ANSWER = UPDATE_ANSWER;						\
    }									\
    CERR( "二分探索終了: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << ( EXPRESSION > TARGET ? ">" : EXPRESSION < TARGET ? "<" : "=" ) << TARGET ); \
    if( EXPRESSION DESIRED_INEQUALITY TARGET ){				\
      CERR( "二分探索成功" );						\
    } else {								\
      CERR( "二分探索失敗" );						\
      ANSWER = MAXIMUM + 1;						\
    }									\
  } else {								\
    CERR( "二分探索失敗: " << MINIMUM << ">" << MAXIMUM );		\
    ANSWER = MAXIMUM + 1;						\
  }									\

// 単調増加の時にEXPRESSION >= TARGETの最小解を格納。
#define BS1( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , >= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調増加の時にEXPRESSION <= TARGETの最大解を格納。
#define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , > , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調減少の時にEXPRESSION >= TARGETの最大解を格納。
#define BS3( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , < , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調減少の時にEXPRESSION <= TARGETの最小解を格納。
#define BS4( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , <= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// t以下の値が存在すればその最大値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MaximumLeq( set<T>& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.upper_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; }
// t未満の値が存在すればその最大値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MaximumLt( set<T>& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.lower_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; }
// t以上の値が存在すればその最小値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MinimumGeq( set<T>& S , const T& t ) { return S.lower_bound( t ); }
// tより大きい値が存在すればその最小値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MinimumGt( set<T>& S , const T& t ) { return S.upper_bound( t ); }

// データ構造用関数
template <typename T> inline T add( const T& t0 , const T& t1 ) { return t0 + t1; }
template <typename T> inline T xor_add( const T& t0 , const T& t1 ){ return t0 ^ t1; }
template <typename T> inline T multiply( const T& t0 , const T& t1 ) { return t0 * t1; }
template <typename T> inline const T& zero() { static const T z = 0; return z; }
template <typename T> inline const T& one() { static const T o = 1; return o; }\
template <typename T> inline T add_inv( const T& t ) { return -t; }
template <typename T> inline T id( const T& v ) { return v; }

// グリッド問題用関数
int H , W , H_minus , W_minus , HW;
inline pair<int,int> EnumHW( const int& v ) { return { v / W , v % W }; }
inline int EnumHW_inv( const int& h , const int& w ) { return h * W + w; }
const string direction[4] = {"U","R","D","L"};
// (i,j)->(k,h)の方向番号を取得
inline int DirectionNumberOnGrid( const int& i , const int& j , const int& k , const int& h ){return i<k?2:i>k?0:j<h?1:j>h?3:(assert(false),-1);}
// v->wの方向番号を取得
inline int DirectionNumberOnGrid( const int& v , const int& w ){auto [i,j]=EnumHW(v);auto [k,h]=EnumHW(w);return DirectionNumberOnGrid(i,j,k,h);}
// 方向番号の反転U<->D、R<->L
inline int ReverseDirectionNumberOnGrid( const int& n ){assert(0<=n&&n<4);return(n+2)%4;}

// デバッグ用関数
#ifdef DEBUG
  inline void AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); }
  void AutoCheck( bool& auto_checked );
#endif

// 圧縮用
#define TE template
#define TY typename
#define US using
#define ST static
#define IN inline
#define CL class
#define PU public
#define OP operator
#define CE constexpr
#define CO const
#define NE noexcept
#define RE return 
#define WH while
#define VO void
#define VE vector
#define LI list
#define BE begin
#define EN end
#define SZ size
#define MO move
#define TH this
#define CRI CO int&
#define CRUI CO uint&
#define CRL CO ll&

// VVV ライブラリは以下に挿入する。
#define SFINAE_FOR_EXTENDED_ULL( DEFAULT )				\
  typename T , enable_if_t<is_constructible<UINT,decay_t<T> >::value>* DEFAULT \

#define STATIC_ASSERT_FOR_EXTENDED_ULL					\
  static_assert( !is_same<UINT,ull>::value || digit == 64 );		\
  if constexpr( !is_same<UINT,ull>::value ){				\
    static_assert( !is_same<typename UINT::base,ull>::value || digit == 128 ); \
    if constexpr( !is_same<typename UINT::base,ull>::value ){		\
	static_assert( is_same<UINT,Extended_ull<typename UINT::base,digit/2> >::value ); \
    }									\
  }								\

// 静的にメモリを確保するため、桁数が大きすぎるとメモリが不足となる。
template <typename UINT , int digit>
class Extended_ull
{

  template <typename T , int d> friend class Extended_ull;

private:
  UINT m_n[2];
  bool m_is_zero;

public:
  inline constexpr Extended_ull() noexcept;
  template <SFINAE_FOR_EXTENDED_ULL( = nullptr )> inline constexpr Extended_ull( T n0 ) noexcept;
  template <SFINAE_FOR_EXTENDED_ULL( = nullptr )> inline constexpr Extended_ull( T n0 , T n1 ) noexcept;
  inline constexpr Extended_ull( const UINT ( &n )[2] ) noexcept;
  inline constexpr Extended_ull( UINT ( &&n )[2] ) noexcept;
  inline constexpr Extended_ull( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull( Extended_ull<UINT,digit>&& n ) noexcept;

  inline constexpr Extended_ull<UINT,digit>& operator=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator=( Extended_ull<UINT,digit>&& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator+=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator-=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator*=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator/=( const Extended_ull<UINT,digit>& n );
  inline constexpr Extended_ull<UINT,digit>& operator%=( const Extended_ull<UINT,digit>& n );
  inline constexpr Extended_ull<UINT,digit>& operator&=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator|=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator^=( const Extended_ull<UINT,digit>& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator<<=( const int& n ) noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator>>=( const int& n ) noexcept;

  inline constexpr Extended_ull<UINT,digit>& operator++() noexcept;
  inline constexpr Extended_ull<UINT,digit>& operator--() noexcept;
  inline constexpr Extended_ull<UINT,digit> operator++( int ) noexcept;
  inline constexpr Extended_ull<UINT,digit> operator--( int ) noexcept;

  inline constexpr Extended_ull<UINT,digit> operator+( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator-() const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator-( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator*( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator/( const Extended_ull<UINT,digit>& n ) const;
  inline constexpr Extended_ull<UINT,digit> operator%( const Extended_ull<UINT,digit>& n ) const;
  inline constexpr Extended_ull<UINT,digit> operator~() const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator&( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator|( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator^( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator<<( const int& n ) const noexcept;
  inline constexpr Extended_ull<UINT,digit> operator>>( const int& n ) const noexcept;

  inline constexpr bool operator==( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr bool operator==( const ull& n ) const noexcept;
  template <typename T> inline constexpr bool operator!=( const T& n ) const noexcept;
  template <typename T> inline constexpr bool operator<=( const T& n ) const noexcept;
  template <typename T> inline constexpr bool operator>=( const T& n ) const noexcept;
  inline constexpr bool operator<( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr bool operator<( const ull& n ) const noexcept;
  inline constexpr bool operator>( const Extended_ull<UINT,digit>& n ) const noexcept;
  inline constexpr bool operator>( const ull& n ) const noexcept;

  inline constexpr const UINT& GetLowerDigit() const noexcept;
  inline constexpr const UINT& GetUpperDigit() const noexcept;

  inline constexpr Extended_ull<UINT,digit> Quotient( const Extended_ull<UINT,digit>& n );
  inline constexpr UINT Sqrt() const noexcept;
  inline constexpr ull Cast() const noexcept;

  static inline constexpr Extended_ull<UINT,digit> Sum( const UINT& n0 , const UINT& n1 ) noexcept;
  static inline constexpr Extended_ull<UINT,digit> Prod( const UINT& n0 , const UINT& n1 ) noexcept;
  static inline constexpr void swap( Extended_ull<UINT,digit>& n0 , Extended_ull<UINT,digit>& n1 ) noexcept;

  using base = UINT;

};

template <typename UINT , int digit> inline constexpr void swap( Extended_ull<UINT,digit>& n0 , Extended_ull<UINT,digit>& n1 ) noexcept;

// ULL = ul2 = ullの時、受け取り上限は2^64 - 1 = 18446744073709551615 ≒ 1.8×10^19
// ULL = ul3 = ulllの時、受け取り上限は18446744073709551615999999999999999999 ≒ 1.8×10^37
// ULL = ul4 = ullllの時、受け取り上限は約1.8×10^73
// ULL = ul5 = ulllllの時、受け取り上限は約1.8×10^145
template <typename ULL , int digit> inline ULL stoeull( string s );
template <typename UINT , int digit , class Traits> inline basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& is , Extended_ull<UINT,digit>& n );

template <typename UINT , int digit> inline string to_string( Extended_ull<UINT,digit> n );
template <typename UINT , int digit , class Traits> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const Extended_ull<UINT,digit>& n );


template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>::Extended_ull() noexcept : m_n() , m_is_zero( true ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }
template <typename UINT , int digit> template <SFINAE_FOR_EXTENDED_ULL()> inline constexpr Extended_ull<UINT,digit>::Extended_ull( T n0 ) noexcept : m_n{ UINT( n0 ) , UINT( 0 ) } , m_is_zero( n0 == 0 ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }
template <typename UINT , int digit> template <SFINAE_FOR_EXTENDED_ULL()> inline constexpr Extended_ull<UINT,digit>::Extended_ull( T n0 , T n1 ) noexcept : m_n{ UINT( n0 ) , UINT( n1 ) } , m_is_zero( n0 == 0 && n1 == 0 ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>::Extended_ull( const UINT ( &n )[2] ) noexcept : m_n{ n[0] , n[1] } , m_is_zero( m_n[0] == 0 && m_n[1] == 0 ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>::Extended_ull( UINT ( &&n )[2] ) noexcept : m_n{ move( n[0] ) , move( n[1] ) } , m_is_zero( m_n[0] == 0 && m_n[1] == 0 ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>::Extended_ull( const Extended_ull<UINT,digit>& n ) noexcept : m_n{ n.m_n[0] , n.m_n[1] } , m_is_zero( n.m_is_zero ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>::Extended_ull( Extended_ull<UINT,digit>&& n ) noexcept : m_n{ move( n.m_n[0] ) , move( n.m_n[1] ) } , m_is_zero( n.m_is_zero ) { STATIC_ASSERT_FOR_EXTENDED_ULL; }

template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator=( const Extended_ull<UINT,digit>& n ) noexcept { m_n[0] = n.m_n[0]; m_n[1] = n.m_n[1]; m_is_zero = n.m_is_zero; return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator=( Extended_ull<UINT,digit>&& n ) noexcept { m_n[0] = move( n.m_n[0] ); m_n[1] = move( n.m_n[1] ); m_is_zero = n.m_is_zero; return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator+=( const Extended_ull<UINT,digit>& n ) noexcept { return operator=( operator+( n ) ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator-=( const Extended_ull<UINT,digit>& n ) noexcept { return operator=( operator-( n ) ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator*=( const Extended_ull<UINT,digit>& n ) noexcept { return operator=( operator*( n ) ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator/=( const Extended_ull<UINT,digit>& n ) { return *this = Quotient( n ); }

template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator%=( const Extended_ull<UINT,digit>& n )
{

  assert( !n.m_is_zero );
  Extended_ull<UINT,digit> answer{};
  int l = 0;
  int r = ( digit << 1 );

  while( l + 1 < r ){

    int m = ( l + r ) >> 1;
    ( ( *this >> m ) >= n ? l : r ) = m;

  }

  Extended_ull<UINT,digit> power_n = n << l;

  for( int d = l ; d >= 0 ; d-- ){

    if( *this >= power_n ){

      *this -= power_n;

    }

    power_n >>= 1;

  }

  m_is_zero = m_n[0] == 0 && m_n[1] == 0;
  return *this;

}

template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator&=( const Extended_ull<UINT,digit>& n ) noexcept { if( !m_is_zero && n.m_is_zero ){ return operator=( n ); } m_n[0] &= n.m_n[0]; m_n[1] &= n.m_n[1]; m_is_zero = m_n[0] == 0 && m_n[1] == 0; return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator|=( const Extended_ull<UINT,digit>& n ) noexcept { if( !n.m_is_zero ){ if( m_is_zero ){ return operator=( n ); }  m_n[0] |= n.m_n[0]; m_n[1] |= n.m_n[1]; m_is_zero = m_is_zero || n.m_is_zero; } return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator^=( const Extended_ull<UINT,digit>& n ) noexcept { if( !n.m_is_zero ){ if( !m_is_zero ){ return operator=( n ); } m_n[0] ^= n.m_n[0]; m_n[1] ^= n.m_n[1]; m_is_zero = m_n[0] == 0 && m_n[1] == 0; } return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator<<=( const int& n ) noexcept { m_is_zero || n == 0 ? m_is_zero : n < digit ? ( ( m_n[1] <<= n ) |= ( m_n[0] >> ( digit - n ) ) , m_n[0] <<= n , m_is_zero = m_n[0] == 0 && m_n[1] == 0 ) : n < ( digit << 1 ) ? ( m_n[1] = ( m_n[0] << ( n - digit ) ) , m_n[0] = 0 , m_is_zero = m_n[1] == 0 ) : ( m_n[1] = m_n[0] = 0 , m_is_zero = true ); return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator>>=( const int& n ) noexcept { m_is_zero || n == 0 ? m_is_zero : n < digit ? ( ( m_n[0] >>= n ) |= ( m_n[1] << ( digit - n ) ) , m_n[1] >>= n , m_is_zero = m_n[0] == 0 && m_n[1] == 0 ) : n < ( digit << 1 ) ? ( m_n[0] = ( m_n[1] >> ( n - digit ) ) , m_n[1] = 0 , m_is_zero = m_n[0] == 0 ) : ( m_n[0] = m_n[1] = 0 , m_is_zero = true ); return *this; }


template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator++() noexcept { m_is_zero = ++m_n[0] == 0 ? ++m_n[1] == 0 : false; return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit>& Extended_ull<UINT,digit>::operator--() noexcept { if( m_n[0]-- == 0 ){ m_n[1]--; } m_is_zero = m_n[0] == 0 && m_n[1] == 0; return *this; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator++( int ) noexcept { const Extended_ull<UINT,digit> answer = *this; operator++(); return answer; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator--( int ) noexcept { const Extended_ull<UINT,digit> answer = *this; operator--(); return answer; }


template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator+( const Extended_ull<UINT,digit>& n ) const noexcept { if( m_is_zero ){ return n; } if( n.m_is_zero ){ return *this; } Extended_ull<UINT,digit> answer = Sum( m_n[0] , n.m_n[0] ); answer.m_n[1] += m_n[1] + n.m_n[1]; answer.m_is_zero = answer.m_n[0] == 0 && answer.m_n[1] == 0; return answer; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator-() const noexcept { return m_is_zero ? *this : ++( operator~() ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator-( const Extended_ull<UINT,digit>& n ) const noexcept { return operator+( -n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator*( const Extended_ull<UINT,digit>& n ) const noexcept { if( m_is_zero ){ return *this; } if( n.m_is_zero ){ return n; } Extended_ull<UINT,digit> answer = Prod( m_n[0] , n.m_n[0] ); answer.m_n[1] += m_n[1] * n.m_n[0] + m_n[0] * n.m_n[1]; answer.m_is_zero = answer.m_n[0] == 0 && answer.m_n[1] == 0; return answer; }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator/( const Extended_ull<UINT,digit>& n ) const { return move( Extended_ull<UINT,digit>( *this ) /= n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator%( const Extended_ull<UINT,digit>& n ) const { return move( Extended_ull<UINT,digit>( *this ) %= n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator~() const noexcept { return Extended_ull<UINT,digit>( ~m_n[0] , ~m_n[1] ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator&( const Extended_ull<UINT,digit>& n ) const noexcept { Extended_ull<UINT,digit> answer = *this; return move( answer &= n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator|( const Extended_ull<UINT,digit>& n ) const noexcept { Extended_ull<UINT,digit> answer = *this; return move( answer |= n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator^( const Extended_ull<UINT,digit>& n ) const noexcept { Extended_ull<UINT,digit> answer = *this; return move( answer ^= n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator<<( const int& n ) const noexcept { Extended_ull<UINT,digit> answer = *this; return move( answer <<= n ); }
template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::operator>>( const int& n ) const noexcept { Extended_ull<UINT,digit> answer = *this; return move( answer >>= n ); }


template <typename UINT , int digit> inline constexpr bool Extended_ull<UINT,digit>::operator==( const Extended_ull<UINT,digit>& n ) const noexcept { return ( m_is_zero && n.m_is_zero ) || ( m_n[0] == n.m_n[0] && m_n[1] == n.m_n[1] ); }
template <typename UINT , int digit> inline constexpr bool Extended_ull<UINT,digit>::operator==( const ull& n ) const noexcept { return n == 0 ? m_is_zero : ( m_n[0] == n && m_n[1] == 0 ); }
template <typename UINT , int digit> template <typename T> inline constexpr bool Extended_ull<UINT,digit>::operator!=( const T& n ) const noexcept { return !( *this == n ); }
template <typename UINT , int digit> template <typename T> inline constexpr bool Extended_ull<UINT,digit>::operator<=( const T& n ) const noexcept { return !( *this > n ); }
template <typename UINT , int digit> template <typename T> inline constexpr bool Extended_ull<UINT,digit>::operator>=( const T& n ) const noexcept { return !( *this < n ); }
template <typename UINT , int digit> inline constexpr bool Extended_ull<UINT,digit>::operator<( const Extended_ull<UINT,digit>& n ) const noexcept { return ( m_is_zero && !n.m_is_zero ) || m_n[1] < n.m_n[1] || ( m_n[1] == n.m_n[1] && m_n[0] < n.m_n[0] ); }
template <typename UINT , int digit> inline constexpr bool Extended_ull<UINT,digit>::operator<( const ull& n ) const noexcept { return n == 0 ? m_is_zero : ( m_n[1] == 0 && m_n[0] < n ); }
template <typename UINT , int digit> inline constexpr bool Extended_ull<UINT,digit>::operator>( const Extended_ull<UINT,digit>& n ) const noexcept { return n < *this; }
template <typename UINT , int digit> inline constexpr bool Extended_ull<UINT,digit>::operator>( const ull& n ) const noexcept { return n == 0 ? !m_is_zero : ( m_n[1] > 0 || m_n[0] > n ); }


template <typename UINT , int digit> inline constexpr const UINT& Extended_ull<UINT,digit>::GetLowerDigit() const noexcept { return m_n[0]; }
template <typename UINT , int digit> inline constexpr const UINT& Extended_ull<UINT,digit>::GetUpperDigit() const noexcept { return m_n[1]; }

template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::Quotient( const Extended_ull<UINT,digit>& n )
{

  assert( !n.m_is_zero );
  Extended_ull<UINT,digit> answer{};
  int l = 0;
  int r = ( digit << 1 );

  while( l + 1 < r ){

    int m = ( l + r ) >> 1;
    ( ( *this >> m ) >= n ? l : r ) = m;

  }

  Extended_ull<UINT,digit> power = Extended_ull<UINT,digit>( 1 ) << l;
  Extended_ull<UINT,digit> power_n = n << l;

  for( int d = l ; d >= 0 ; d-- ){

    if( *this >= power_n ){

      *this -= power_n;
      answer |= power;

    }

    power_n >>= 1;
    power >>= 1;

  }

  return answer;

}

template <typename UINT , int digit> inline constexpr UINT Extended_ull<UINT,digit>::Sqrt() const noexcept
{

  constexpr const UINT UINT_max = ~( UINT( 0 ) ); 
  constexpr const Extended_ull<UINT,digit> threshold{ 1 , UINT_max - 1 };
  
  if( threshold <= *this ){

    return UINT_max;

  }
  
  UINT l = 0;
  UINT r = UINT_max;

  while( l + 1 < r ){

    UINT m = ( ( l + r ) >> 1 );
    ( Extended_ull<UINT,digit>::Prod( m , m ) <= *this ? l : r ) = move( m );

  }
  
  return l;

}

template <typename UINT , int digit> inline constexpr ull Extended_ull<UINT,digit>::Cast() const noexcept
{

  if constexpr( is_same<UINT,ull>::value ){

      return m_n[0];
    
    } else {

    return m_n[0].Cast();

  }

}


template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::Sum( const UINT& n0 , const UINT& n1 ) noexcept
{
  
  if constexpr ( is_same<UINT,ull>::value ){

      constexpr const ull digit_half = digit >> 1;
      constexpr const ull low_bit = ( ull( 1 ) << digit_half ) - 1;
      ull temp[2] = {
	( n0 & low_bit ) + ( n1 & low_bit ) ,
	( n0 >> digit_half ) + ( n1 >> digit_half )
      };
      temp[1] += ( temp[0] >> digit_half );
      ( temp[0] &= low_bit ) |= ( temp[1] << digit_half );
      temp[1] >>= digit_half;
      return Extended_ull<UINT,digit>( move( temp ) );

    } else {

    UINT temp[2] = {
      UINT::Sum( n0.m_n[0] , n1.m_n[0] ) ,
      UINT::Sum( n0.m_n[1] , n1.m_n[1] )
    };
    temp[1] += temp[0].m_n[1];
    temp[0].m_n[1] = move( temp[1].m_n[0] );
    temp[0].m_is_zero = temp[0].m_n[0] == 0 && temp[0].m_n[1] == 0;
    temp[1].m_n[0] = move( temp[1].m_n[1] );
    temp[1].m_n[1] = 0;
    temp[1].m_is_zero = temp[1].m_n[0] == 0 && temp[1].m_n[1] == 0;
    return Extended_ull<UINT,digit>( move( temp ) );

  }

}

template <typename UINT , int digit> inline constexpr Extended_ull<UINT,digit> Extended_ull<UINT,digit>::Prod( const UINT& n0 , const UINT& n1 ) noexcept
{
  
  if constexpr ( is_same<UINT,ull>::value ){

      constexpr const ull digit_half = digit >> 1;
      constexpr const ull low_bit = ( ull( 1 ) << digit_half ) - 1;
      const ull n0_copy[2] = { n0 & low_bit , n0 >> digit_half };
      const ull n1_copy[2] = { n1 & low_bit , n1 >> digit_half };
      ull temp0[2] = { n0_copy[0] * n1_copy[0] , n0_copy[1] * n1_copy[1] };
      ull temp1[2] = { n0_copy[0] * n1_copy[1] , n0_copy[1] * n1_copy[0] };
      temp0[1] += ( temp1[0] >> digit_half ) + ( temp1[1] >> digit_half );
      ( temp1[1] &= low_bit ) += ( temp1[0] &= low_bit ) + ( temp0[0] >> digit_half );
      temp0[1] += temp1[1] >> digit_half;
      ( temp0[0] &= low_bit ) |= ( temp1[1] << digit_half );
      return Extended_ull<UINT,digit>( move( temp0 ) );

    } else {

    UINT temp0[2] = { UINT::Prod( n0.m_n[0] , n1.m_n[0] ) , UINT::Prod( n0.m_n[1] , n1.m_n[1] ) };
    UINT temp1[2] = { UINT::Prod( n0.m_n[0] , n1.m_n[1] ) , UINT::Prod( n0.m_n[1] , n1.m_n[0] ) };
    temp0[1] += UINT::Sum( temp1[0].m_n[1] , temp1[1].m_n[1] );
    temp1[1] = UINT::Sum( temp1[0].m_n[0] , temp1[1].m_n[0] );
    temp1[1] += temp0[0].m_n[1];
    temp0[1] += temp1[1].m_n[1];
    temp0[0].m_n[1] = move( temp1[1].m_n[0] );
    temp0[0].m_is_zero = temp0[0].m_n[0] == 0 && temp0[0].m_n[1] == 0;
    return Extended_ull<UINT,digit>( move( temp0 ) );
    
  }

}

template <typename UINT , int digit> inline constexpr void Extended_ull<UINT,digit>::swap( Extended_ull<UINT,digit>& n0 , Extended_ull<UINT,digit>& n1 ) noexcept { swap( n0.m_n , n1.m_n ); swap( n0.m_is_zero , n1.m_is_zero ); }

template <typename UINT , int digit> inline constexpr void swap( Extended_ull<UINT,digit>& n0 , Extended_ull<UINT,digit>& n1 ) noexcept { Extended_ull<UINT,digit>::swap( n0 , n1 ); }


template <typename ULL> inline ULL stoeull( string s , const vector<ULL>& ten_power , const int& length )
{

  if constexpr ( is_same<ULL,ull>::value ){

      return stoull( s );

    } else {

    using UINT = typename ULL::base;
    static vector<UINT> ten_power_sub = { 1 };
    static int length_sub = 1;
    const int size = s.size();
    const int size_half0 = size / 2;
    const int size_half1 = size - size_half0;

    while( size_half0 >= length_sub ){

      assert( length_sub < length );
      ten_power_sub.push_back( ten_power[length_sub].GetLowerDigit() );
      length_sub++;

    }
    
    return size_half0 > 0 ? ULL::Prod( stoeull<UINT>( s.substr( 0 , size_half1 ) , ten_power_sub , length_sub ) , ten_power_sub[size_half0] ) + stoeull<UINT>( s.substr( size_half1 ) , ten_power_sub , length_sub ) : ULL( stoeull<UINT>( move( s ) , ten_power_sub , length_sub ) );

  }

}

template <typename ULL> inline ULL stoeull( string s )
{

  if constexpr ( is_same<ULL,ull>::value ){

      return stoull( s );

    } else {

    using UINT = typename ULL::base;
    static vector<UINT> ten_power = { 1 };
    static int length = 1;
    const int size = s.size();
    const int size_half0 = size / 2;
    const int size_half1 = size - size_half0;

    while( size_half0 >= length ){

      ten_power.push_back( ten_power.back() * 10 );
      length++;

    }
    
    return size_half0 > 0 ? ULL::Prod( stoeull<UINT>( s.substr( 0 , size_half1 ) , ten_power , length ) , ten_power[size_half0] ) + stoeull<UINT>( s.substr( size_half1 ) , ten_power , length ) : ULL( stoeull<UINT>( move( s ) , ten_power , length ) );

  }

}


template <typename UINT , int digit , class Traits> inline basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& is , Extended_ull<UINT,digit>& n )
{

  string temp;
  is >> temp;
  n = stoeull<Extended_ull<UINT,digit> >( move( temp ) );
  return is;

}

template <typename UINT , int digit> inline string to_string( Extended_ull<UINT,digit> n )
{

  list<char> temp{};
  static const Extended_ull<UINT,digit> ten{ 10 };

  while( n != 0 ){

    Extended_ull<UINT,digit> n_div = n.Quotient( ten );
    temp.push_front( to_string( n.Cast() )[0] );
    n = move( n_div );

  }

  if( temp.empty() ){

    temp.push_back( '0' );

  }

  string answer = "";

  for( auto itr = temp.begin() , end = temp.end() ; itr != end ; itr++ ){

    answer += *itr;

  }

  return answer;

}

template <typename UINT , int digit , class Traits> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const Extended_ull<UINT,digit>& n ) { return os << to_string( n ); }

using ulll = Extended_ull<ull,64>;
using ullll = Extended_ull<ulll,128>;
using ulllll = Extended_ull<ullll,256>;

using ul2 = ull;
using ul3 = Extended_ull<ul2,64*1>;
using ul4 = Extended_ull<ul3,64*2>; // 十進法で36桁、64bit整数2個の積まで対応
using ul5 = Extended_ull<ul4,64*4>;
using ul6 = Extended_ull<ul5,64*8>; // 十進法で144桁、64bit整数8個の積まで対応
using ul7 = Extended_ull<ul6,64*16>;
using ul8 = Extended_ull<ul7,64*32>;
using ul9 = Extended_ull<ul8,64*64>; // 十進法で1152桁、64bit整数64個の積まで対応
using ul10 = Extended_ull<ul9,64*128>;
using ul11 = Extended_ull<ul10,64*256>;
using ul12 = Extended_ull<ul11,64*512>; // 十進法で10^5桁オーバー
using ul13 = Extended_ull<ul12,64*1024>; // 手元の環境だと小さい数の演算でも実行時メモリ不足
using ul14 = Extended_ull<ul13,64*2048>;
using ul15 = Extended_ull<ul14,64*4096>;
using ul16 = Extended_ull<ul15,64*8192>;
using ul17 = Extended_ull<ul16,64*16384>;
using ul18 = Extended_ull<ul17,64*32768>;
using ul19 = Extended_ull<ul18,64*65536>; // 手元の環境だとコンストラクタでも実行時メモリ不足
using ul20 = Extended_ull<ul19,64*131072>; // 手元の環境だとコンパイル時メモリ不足
using ul21 = Extended_ull<ul20,64*262144>;
using ul22 = Extended_ull<ul21,64*524288>;
using ul23 = Extended_ull<ul22,64*1048576>;

// AAA ライブラリは以上に挿入する。

// データ構造使用畤のNの上限
// inline CEXPR( int , bound_N , 10 );
inline DEXPR( int , bound_N , 100000 , 100 ); // 0が5個
// inline CEXPR( int , bound_N , 1000000000 ); // 0が9個
// inline CEXPR( ll , bound_N , 1000000000000000000 ); // 0が18個

// データ構造使用畤のMの上限
// inline CEXPR( TYPE_OF( bound_N ) , bound_M , bound_N );
// inline CEXPR( int , bound_M , 10 );
inline DEXPR( int , bound_M , 100000 , 100 ); // 0が5個
// inline CEXPR( int , bound_M , 1000000000 ); // 0が9個
// inline CEXPR( ll , bound_M , 1000000000000000000 ); // 0が18個

// データ構造や壁配列使用畤のH,Wの上限
inline DEXPR( int , bound_H , 1000 , 20 );
// inline DEXPR( int , bound_H , 100000 , 10 ); // 0が5個
// inline CEXPR( int , bound_H , 1000000000 ); // 0が9個
inline CEXPR( int , bound_W , bound_H );
static_assert( ll( bound_H ) * bound_W < ll( 1 ) << 31 );
inline CEXPR( int , bound_HW , bound_H * bound_W );
// CEXPR( int , bound_HW , 100000 ); // 0が5個
// CEXPR( int , bound_HW , 1000000 ); // 0が6個
inline void SetEdgeOnGrid( const string& Si , const int& i , list<int> ( &e )[bound_HW] , const char& walkable = '.' ){FOR(j,0,W){if(Si[j]==walkable){int v = EnumHW_inv(i,j);if(i>0){e[EnumHW_inv(i-1,j)].push_back(v);}if(i+1<H){e[EnumHW_inv(i+1,j)].push_back(v);}if(j>0){e[EnumHW_inv(i,j-1)].push_back(v);}if(j+1<W){e[EnumHW_inv(i,j+1)].push_back(v);}}}}
inline void SetEdgeOnGrid( const string& Si , const int& i , list<pair<int,ll> > ( &e )[bound_HW] , const char& walkable = '.' ){FOR(j,0,W){if(Si[j]==walkable){const int v=EnumHW_inv(i,j);if(i>0){e[EnumHW_inv(i-1,j)].push_back({v,1});}if(i+1<H){e[EnumHW_inv(i+1,j)].push_back({v,1});}if(j>0){e[EnumHW_inv(i,j-1)].push_back({v,1});}if(j+1<W){e[EnumHW_inv(i,j+1)].push_back({v,1});}}}}
inline void SetWallOnGrid( const string& Si , const int& i , bool ( &non_wall )[bound_H+1][bound_W+1] , const char& walkable = '.'  , const char& unwalkable = '#' ){bool(&non_wall_i)[bound_W+1]=non_wall[i];FOR(j,0,W){non_wall_i[j]=Si[j]==walkable?true:(assert(Si[j]==unwalkable),false);}}

// using path_type = int;
// // using path_type = pair<int,ll>;
// CEXPR( int , bound_E , bound_M ); // bound_Mのデフォルト値は10^5。
// // CEXPR( int , bound_E , bound_HW ); // bound_HWのデフォルト値は10^6。
// list<path_type> e[bound_E] = {};
// list<path_type> E( const int& i )
// {
//   list<path_type> answer{};
//   list<path_type> answer = e[i];
//   // 入力によらない処理
//   return answer;
// }

// ライブラリをここに挿入しない。

int main()
{
  UNTIE;
  AUTO_CHECK;
  // START_WATCH;
  TEST_CASE_NUM( 1 );
  START_MAIN;

  CIN( ul5 , A );
  CIN( ul5 , B );
  RETURN( A + B );

  FINISH_MAIN;
}
0