結果

問題 No.3001 ヘビ文字列
ユーザー 👑 p-adicp-adic
提出日時 2024-12-29 14:11:11
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 36,377 bytes
コンパイル時間 4,415 ms
コンパイル使用メモリ 229,756 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-01 07:42:48
合計ジャッジ時間 56,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 3 ms
6,816 KB
testcase_03 AC 3 ms
6,816 KB
testcase_04 AC 3 ms
6,816 KB
testcase_05 AC 3 ms
6,816 KB
testcase_06 AC 3 ms
6,816 KB
testcase_07 AC 3 ms
6,816 KB
testcase_08 AC 4 ms
6,820 KB
testcase_09 AC 3 ms
6,816 KB
testcase_10 AC 3 ms
6,816 KB
testcase_11 AC 3 ms
6,820 KB
testcase_12 AC 3 ms
6,816 KB
testcase_13 AC 4 ms
6,816 KB
testcase_14 AC 3 ms
6,816 KB
testcase_15 AC 433 ms
6,816 KB
testcase_16 AC 441 ms
6,820 KB
testcase_17 AC 421 ms
6,816 KB
testcase_18 AC 472 ms
6,816 KB
testcase_19 AC 458 ms
6,816 KB
testcase_20 AC 456 ms
6,820 KB
testcase_21 AC 428 ms
6,820 KB
testcase_22 AC 425 ms
6,816 KB
testcase_23 AC 456 ms
6,816 KB
testcase_24 AC 431 ms
6,820 KB
testcase_25 AC 34 ms
6,816 KB
testcase_26 AC 21 ms
6,816 KB
testcase_27 AC 18 ms
6,816 KB
testcase_28 AC 17 ms
6,816 KB
testcase_29 AC 20 ms
6,816 KB
testcase_30 AC 18 ms
6,820 KB
testcase_31 AC 18 ms
6,816 KB
testcase_32 AC 17 ms
6,816 KB
testcase_33 AC 17 ms
6,820 KB
testcase_34 AC 17 ms
6,816 KB
testcase_35 AC 27 ms
6,816 KB
testcase_36 AC 27 ms
6,820 KB
testcase_37 AC 27 ms
6,820 KB
testcase_38 AC 26 ms
6,816 KB
testcase_39 AC 26 ms
6,816 KB
testcase_40 AC 28 ms
6,820 KB
testcase_41 AC 27 ms
6,820 KB
testcase_42 AC 26 ms
6,816 KB
testcase_43 AC 28 ms
6,816 KB
testcase_44 AC 26 ms
6,820 KB
testcase_45 TLE -
testcase_46 AC 1,495 ms
6,820 KB
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 TLE -
testcase_53 AC 1,490 ms
6,816 KB
testcase_54 AC 1,373 ms
6,820 KB
testcase_55 AC 741 ms
6,816 KB
testcase_56 AC 801 ms
6,820 KB
testcase_57 AC 844 ms
6,820 KB
testcase_58 AC 798 ms
6,820 KB
testcase_59 AC 829 ms
6,816 KB
testcase_60 AC 789 ms
6,816 KB
testcase_61 AC 778 ms
6,816 KB
testcase_62 AC 829 ms
6,816 KB
testcase_63 AC 584 ms
6,820 KB
testcase_64 AC 840 ms
6,816 KB
testcase_65 AC 74 ms
6,820 KB
testcase_66 AC 100 ms
6,820 KB
testcase_67 AC 81 ms
6,820 KB
testcase_68 AC 39 ms
6,820 KB
testcase_69 AC 29 ms
6,820 KB
testcase_70 AC 52 ms
6,816 KB
testcase_71 AC 61 ms
6,816 KB
testcase_72 AC 56 ms
6,816 KB
testcase_73 AC 57 ms
6,816 KB
testcase_74 AC 42 ms
6,820 KB
testcase_75 AC 1,274 ms
6,820 KB
testcase_76 AC 1,399 ms
6,820 KB
testcase_77 AC 1,402 ms
6,820 KB
testcase_78 AC 1,498 ms
6,824 KB
testcase_79 AC 1,304 ms
6,816 KB
testcase_80 AC 1,108 ms
6,816 KB
testcase_81 AC 1,486 ms
6,824 KB
testcase_82 AC 1,284 ms
6,816 KB
testcase_83 AC 1,393 ms
6,816 KB
testcase_84 AC 1,499 ms
6,820 KB
testcase_85 AC 2 ms
6,820 KB
testcase_86 AC 2 ms
6,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 入力制約/フォーマットチェック
#ifndef INCLUDE_MODE
  #define INCLUDE_MODE
  // #define REACTIVE
  #define USE_GETLINE
#endif
#ifdef INCLUDE_MAIN

void Solve()
{
  GETLINE( S );
  RUN( S , c ){
    ASSERT( c , 'A' , 'Z' );
  }
  int N = S.size();
  CEXPR( int , bound_N , 2e6 );
  ASSERT( N , 2 , bound_N );
  constexpr PrimeEnumeration<1415> pe{};
  auto div = EnumerateDivisor( pe , N );
  div.pop_back();
  int d_best = -1;
  int opt = N + 1;
  RUN( div , d ){
    int Nd = N / d;
    int opt_temp = 0;
    FOR( i , 0 , d ){
      vector<int> h( 26 );
      int temp = 0;
      FOR( j , 0 , Nd ){
        temp = max( temp , ++h[S[i+j*d] - 'A'] );
      }
      opt_temp += Nd - temp;
      if( opt <= opt_temp ){
        break;
      }
    }
    if( opt > opt_temp ){
      opt = opt_temp;
      d_best = d;
    }
  }
  int Nd = N / d_best;
  FOR( i , 0 , d_best ){
    vector<int> h( 26 );
    FOR( j , 0 , Nd ){
      h[S[i+j*d_best] - 'A']++;
    }
    int c_opt = -1;
    int temp = 0;
    FOR( c , 0 , 26 ){
      if( temp < h[c] ){
        temp = h[c];
        c_opt = c;
      }
    }
    FOR( j , 0 , Nd ){
      S[i+j*d_best] = c_opt + 'A';
    }
  }
  RETURN( S );  
}
REPEAT_MAIN(1);

#else // INCLUDE_MAIN
#ifdef INCLUDE_LIBRARY

// https://github.com/p-adic/cpp
// VVV ライブラリは以下に挿入する。redefinitionを避けるため圧縮元はincludeしない。

/* 圧縮用 */
#define TE template
#define TY typename
#define US using
#define ST static
#define AS assert
#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 LE length
#define PW Power
#define MO move
#define TH this
#define CRI CO int&
#define CRUI CO uint&
#define CRL CO ll&
#define VI virtual 
#define IS basic_istream<char,Traits>
#define OS basic_ostream<char,Traits>
#define ST_AS static_assert
#define reMO_CO remove_const
#define is_COructible_v is_constructible_v
#define rBE rbegin

// PrimeEnumeration:
// val_limit = 316 ≒ sqrt(1e5) -> length = 65
// val_limit = 448 ≒ sqrt(2e5) -> length = 86
// val_limit = 1e5 -> length = 9592
// val_limit = 1e6 -> length = 78498
// nの素因数分解:PrimeFactorisation(CO PE/LD& pe,CO INT& n) O(√n/log n)/O(log n)
// nの素羃への分解:PrimePowerFactorisation(CO PE/LD& pe,CO INT& n) O(√n/log n)/O(log n)
// CountDivisor( n ):
// n <= 1e3 -> answer <= 32
// n <= 1e4 -> answer <= 64
// n <= 1e5 -> answer <= 128
// n <= 1e6 -> answer <= 256
// nの約数数え上げ:CountDivisor(CO PE/LD& pe,INT n) O(√n/log n)/O(log n)
// nの約数辞書順列挙:EnumerateDivisor(CO PE/LD& pe,INT n) O(√n/log n)/O(log n/log log n)
// SZ未満の数の約数全列挙:TotalEnumerateDivisor(CRI SZ(,FUNC f,U init)) O(size log size)
TE <int val_limit,int le_max = val_limit>CL PrimeEnumeration{PU:bool m_is_composite[val_limit];int m_val[le_max];int m_le;CE PrimeEnumeration();IN CRI OP[](CRI i)CO;CE CRI Get(CRI i)CO;CE CO bool& IsComposite(CRI n)CO;CE CRI length()CO NE;};
TE <int val_limit,int le_max> CE PrimeEnumeration<val_limit,le_max>::PrimeEnumeration():m_is_composite(),m_val(),m_le(0){for(int i = 2;i < val_limit;i++){if(! m_is_composite[i]){if(i <=(val_limit - 1)/ i){for(int j = i * i;j < val_limit;j += i){m_is_composite[j]= true;}}m_val[m_le++]= i;if(m_le >= le_max){break;}}}}TE <int val_limit,int le_max> IN CRI PrimeEnumeration<val_limit,le_max>::OP[](CRI i)CO{AS(0 <= i && i < m_le);RE m_val[i];}TE <int val_limit,int le_max> CE CRI PrimeEnumeration<val_limit,le_max>::Get(CRI i)CO{RE m_val[i];}TE <int val_limit,int le_max> CE CO bool& PrimeEnumeration<val_limit,le_max>::IsComposite(CRI n)CO{RE m_is_composite[n];}TE <int val_limit,int le_max> CE CRI PrimeEnumeration<val_limit,le_max>::length()CO NE{RE m_le;}
CL HeapPrimeEnumeration{PU:int m_val_limit;VE<bool> m_is_composite;VE<int> m_val;int m_le;IN HeapPrimeEnumeration(CRI val_limit);IN CRI OP[](CRI i)CO;IN CRI Get(CRI i)CO;IN bool IsComposite(CRI n)CO;IN CRI length()CO NE;};
IN HeapPrimeEnumeration::HeapPrimeEnumeration(CRI val_limit):m_val_limit(val_limit),m_is_composite(m_val_limit),m_val(),m_le(0){for(int i = 2;i < m_val_limit;i++){if(! m_is_composite[i]){if(i <=(m_val_limit - 1)/ i){for(int j = i * i;j < val_limit;j += i){m_is_composite[j]= true;}}m_val.push_back(i);}}m_le = m_val.SZ();}IN CRI HeapPrimeEnumeration::OP[](CRI i)CO{AS(0 <= i && i < m_le);RE m_val[i];}IN CRI HeapPrimeEnumeration::Get(CRI i)CO{RE OP[](i);}IN bool HeapPrimeEnumeration::IsComposite(CRI n)CO{AS(0 <= n && n < m_val_limit);RE m_is_composite[n];}IN CRI HeapPrimeEnumeration::length()CO NE{RE m_le;}

TE <TY PE> auto CheckPE(CO PE& pe)-> decltype(pe.IsComposite(0),true_type());TE <TY...> false_type CheckPE(...);TE <TY T>CE bool IsPE = decltype(CheckPE(declval<T>()))();

TE <int val_limit>CL LeastDivisor{PU:int m_val[val_limit];CE LeastDivisor()NE;IN CRI OP[](CRI i)CO;CE CRI Get(CRI i)CO;CE int length()CO NE;};
TE <int val_limit> CE LeastDivisor<val_limit>::LeastDivisor()NE:m_val{}{for(int d = 2;d < val_limit;d++){if(m_val[d]== 0){for(int n = d;n < val_limit;n += d){m_val[n]== 0?m_val[n]= d:d;}}}}TE <int val_limit> IN CRI LeastDivisor<val_limit>::OP[](CRI i)CO{AS(0 <= i && i < val_limit);RE m_val[i];}TE <int val_limit> CE CRI LeastDivisor<val_limit>::Get(CRI i)CO{RE m_val[i];}TE <int val_limit> CE int LeastDivisor<val_limit>::length()CO NE{RE val_limit;}
CL HeapLeastDivisor{PU:int m_val_limit;VE<int> m_val;IN HeapLeastDivisor(CRI val_limit)NE;IN CRI OP[](CRI i)CO;IN CRI Get(CRI i)CO;IN CRI length()CO NE;};
IN HeapLeastDivisor::HeapLeastDivisor(CRI val_limit)NE:m_val_limit(val_limit),m_val(m_val_limit){for(int d = 2;d < m_val_limit;d++){if(m_val[d]== 0){for(int n = d;n < m_val_limit;n += d){m_val[n]== 0?m_val[n]= d:d;}}}}IN CRI HeapLeastDivisor::OP[](CRI i)CO{AS(0 <= i && i < m_val_limit);RE m_val[i];}IN CRI HeapLeastDivisor::Get(CRI i)CO{RE m_val[i];}IN CRI HeapLeastDivisor::length()CO NE{RE m_val_limit;}

TE <TY PE,TY INT>auto PrimeFactorisation(CO PE& pe,INT n)-> enable_if_t<IsPE<PE>,pair<VE<INT>,VE<int>>>{AS(n > 0);VE<INT> P{};VE<int> E{};CRI le = pe.length();for(int i = 0;i < le;i++){auto& p = pe[i];if(n % p == 0){int e = 1;WH((n /= p)% p == 0){e++;}P.push_back(p);E.push_back(e);}else if(n / p < p){break;}}if(n != 1){P.push_back(n);E.push_back(1);}RE{MO(P),MO(E)};}TE <TY LD>auto PrimeFactorisation(CO LD& ld,int n)-> enable_if_t<!IsPE<LD>,pair<VE<int>,VE<int>>>{AS(n > 0);VE<int> P{};VE<int> E{};if(n > 1){P.push_back(ld[n]);E.push_back(1);n /= ld[n];}WH(n > 1){if(P.back()!= ld[n]){P.push_back(ld[n]);E.push_back(1);}else{E.back()++;}n /= ld[n];}RE{MO(P),MO(E)};}TE <TY PE,TY INT>auto PrimePowerFactorisation(CO PE& pe,INT n)-> enable_if_t<IsPE<PE>,tuple<VE<INT>,VE<int>,VE<INT>>>{AS(n > 0);VE<INT> P{};VE<int> E{};VE<INT> Q{};CRI le = pe.length();for(int i = 0;i < le;i++){auto& p = pe[i];if(n % p == 0){int e = 1;INT q = p;WH((n /= p)% p == 0){e++;q *= p;}P.push_back(p);E.push_back(e);Q.push_back(q);}else if(n / p < p){break;}}if(n != 1){P.push_back(n);E.push_back(1);Q.push_back(n);}RE{MO(P),MO(E),MO(Q)};}TE <TY LD>auto PrimePowerFactorisation(CO LD& ld,int n)-> enable_if_t<!IsPE<LD>,tuple<VE<int>,VE<int>,VE<int>>>{AS(n > 0);VE<int> P{};VE<int> E{};VE<int> Q{};if(n > 1){P.push_back(ld[n]);E.push_back(1);Q.push_back(ld[n]);n /= ld[n];}WH(n > 1){if(P.back()!= ld[n]){P.push_back(ld[n]);E.push_back(1);Q.push_back(ld[n]);}else{Q.back()*= ld[n];E.back()++;}n /= ld[n];}RE{MO(P),MO(E),MO(Q)};}

TE <TY INT> INT CountDivisorBody(VE<int>& E)NE{CO int LE = E.SZ();INT AN = 1;for(int i = 0;i < LE;i++){AN *= ++E[i];}RE AN;}TE <TY PE,TY INT>INT CountDivisor(CO PE& pe,INT n)NE{auto[P,E]= PrimeFactorisation(pe,MO(n));RE CountDivisorBody<INT>(E);}

TE <TY INT> VE<INT> EnumerateDivisorBody(CO VE<INT>& P,VE<int>& E){CO int le = P.SZ();VE AN(CountDivisorBody<INT>(E),INT(1));int SZ = 1;for(int i = 0;i < le;i++){auto& P_i = P[i];auto& E_i = E[i];INT q = 1;int j_shift = 0;for(int e = 1;e < E_i;e++){q *= P_i;j_shift += SZ;for(int j = 0;j < SZ;j++){AN[j + j_shift]= AN[j]* q;}}SZ *= E_i;}RE AN;}TE <TY PE,TY INT>auto EnumerateDivisor(CO PE& pe,INT n)-> enable_if_t<IsPE<PE>,VE<INT>>{auto[P,E]= PrimeFactorisation(pe,MO(n));RE EnumerateDivisorBody(P,E);}TE <TY LD,TY INT>auto EnumerateDivisor(CO LD& ld,INT n)-> enable_if_t<!IsPE<LD>,VE<INT>>{VE<INT> P{};VE<int> E{};WH(n > 1){auto& p = ld[n];int e = 1;WH((n /= p)% p == 0){e++;}P.push_back(p);E.push_back(e);}RE EnumerateDivisorBody(P,E);}TE <TY INT>VE<VE<INT>> TotalEnumerateDivisor(CO INT& SZ)NE{VE<VE<INT>> AN(SZ);for(INT d = 1;d < SZ;d++){for(INT n = 0;n < SZ;n += d){AN[n].push_back(d);}}RE AN;}TE <TY INT,TY FUNC,TY U>VE<U> TotalEnumerateDivisor(CO INT& SZ,FUNC f,CO U& init)NE{ST_AS(is_invocable_r_v<U,FUNC,U,CO INT&>);VE<U> AN(SZ,init);for(INT d = 1;d < SZ;d++){for(INT n = 0;n < SZ;n += d){AN[n]= f(MO(AN[n]),d);}}RE AN;}

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

#define INCLUDE_MAIN
#include __FILE__
#else // INCLUDE_LIBRARY
#ifdef DEBUG
  #define _GLIBCXX_DEBUG
  #define DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE2 )
  #define SIGNAL signal( SIGABRT , &AlertAbort );
  #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " , ( MIN ) , ( ( MIN ) <= A ? "<=" : ">" ) , A , ( A <= ( MAX ) ? "<=" : ">" ) , ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) )
  #define COUT( ... ) VariadicCout( cout << "出力:" , __VA_ARGS__ ) << endl
  #define COUTNS( ... ) VariadicCoutNonSep( cout , __VA_ARGS__ ) << flush
  #define CERR( ... ) VariadicCout( cerr , __VA_ARGS__ ) << endl
  #define CERRNS( ... ) VariadicCout( cerr , __VA_ARGS__ ) << flush
  #define COUT_A( A , N ) OUTPUT_ARRAY( cout << "出力:"  , A , N ) << endl
  #define CERR_A( A , N ) OUTPUT_ARRAY( cerr , A , N ) << endl
  int exec_mode = 0;
#else
  #pragma GCC optimize ( "O3" )
  #pragma GCC optimize ( "unroll-loops" )
  #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
  #define SIGNAL 
  #define DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE1 )
  #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
  #define COUT( ... ) VariadicCout( cout , __VA_ARGS__ ) << ENDL
  #define COUTNS( ... ) VariadicCoutNonSep( cout , __VA_ARGS__ )
  #define CERR( ... ) 
  #define CERRNS( ... ) 
  #define COUT_A( A , N ) OUTPUT_ARRAY( cout , A , N ) << ENDL
  #define CERR_A( A , N ) 
#endif
#ifdef REACTIVE
  #ifdef DEBUG
    #define RSET( A , ... ) A = __VA_ARGS__
  #else
    #define RSET( A , ... ) cin >> A
  #endif
  #define RCIN( LL , A , ... ) LL A; RSET( A , __VA_ARGS__ )
  #define ENDL endl
#else
  #define ENDL "\n"
#endif
#ifdef USE_GETLINE
  #define SET_LL( A ) { GETLINE( A ## _str ); A = stoll( A ## _str ); }
  #define GETLINE_SEPARATE( SEPARATOR , ... ) string __VA_ARGS__; VariadicGetline( cin , SEPARATOR , __VA_ARGS__ )
  #define GETLINE( ... ) GETLINE_SEPARATE( '\n' , __VA_ARGS__ )
#else
  #define SET_LL( A ) cin >> A
  #define CIN( LL , ... ) LL __VA_ARGS__; VariadicCin( cin , __VA_ARGS__ )
  #define SET_A( I , N , ... ) VariadicResize( N + I , __VA_ARGS__ ); FOR( VARIABLE_FOR_SET_A , 0 , N ){ VariadicSet( cin , VARIABLE_FOR_SET_A + I , __VA_ARGS__ ); }
  #define CIN_A( LL , I , N , ... ) vector<LL> __VA_ARGS__; SET_A( I , N , __VA_ARGS__ )
  #define CIN_AA( LL , I0 , N0 , I1 , N1 , VAR ) vector<vector<LL>> VAR( N0 + I0 ); FOR( VARIABLE_FOR_CIN_AA , 0 , N0 ){ SET_A( I1 , N1 , VAR[VARIABLE_FOR_CIN_AA + I0] ); }
#endif
#include <bits/stdc++.h>
using namespace std;
#define REPEAT_MAIN( BOUND ) int main(){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); SIGNAL; CEXPR( int , bound_test_case_num , BOUND ); int test_case_num = 1; if constexpr( bound_test_case_num > 1 ){ CERR( "テストケースの個数を入力してください。" ); SET_ASSERT( test_case_num , 1 , bound_test_case_num ); } FOR( test_case , 0 , test_case_num ){ if constexpr( bound_test_case_num > 1 ){ CERR( "testcase" , test_case , ":" ); } Solve(); CERR( "" ); } CHECK_REDUNDANT_INPUT; }
#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 CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE
#define SET_ASSERT( A , MIN , MAX ) SET_LL( A ); ASSERT( A , MIN , MAX )
#define SET_A_ASSERT( I , N , A , MIN , MAX ) FOR( VARIABLE_FOR_SET_A , 0 , N ){ SET_ASSERT( A[VARIABLE_FOR_SET_A + I] , MIN , MAX ); }
#define SET_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) FOR( VARIABLE_FOR_SET_AA0 , 0 , N0 ){ FOR( VARIABLE_FOR_SET_AA1 , 0 , N1 ){ SET_ASSERT( A[VARIABLE_FOR_SET_AA0 + I0][VARIABLE_FOR_SET_AA1 + I1] , MIN , MAX ); } }
#define CIN_ASSERT( A , MIN , MAX ) decldecay_t( MAX ) A; SET_ASSERT( A , MIN , MAX )
#define CIN_A_ASSERT( I , N , A , MIN , MAX ) vector<decldecay_t( MAX )> A( N + I ); SET_A_ASSERT( I , N , A , MIN , MAX )
#define CIN_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) vector A( N0 + I0 , vector<decldecay_t( MAX )>( N1 + I1 ) ); SET_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( decldecay_t( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOREQ( VAR , INITIAL , FINAL ) for( decldecay_t( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )
#define FOREQINV( VAR , INITIAL , FINAL ) for( decldecay_t( INITIAL ) VAR = INITIAL ; VAR + 1 > FINAL ; VAR -- )
#define ITR( ARRAY ) auto begin_ ## ARRAY = ARRAY .BE() , itr_ ## ARRAY = begin_ ## ARRAY , end_ ## ARRAY = ARRAY .EN()
#define FOR_ITR( ARRAY ) for( ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ )
#define RUN( ARRAY , ... ) for( auto&& __VA_ARGS__ : ARRAY )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES )
#define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS )
#define RETURN( ... ) COUT( __VA_ARGS__ ); return

// 型のエイリアス
#define decldecay_t( VAR ) decay_t<decltype( VAR )>
template <typename F , typename...Args> using ret_t = decltype( declval<F>()( declval<Args>()... ) );
template <typename T> using inner_t = typename T::type;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using lld = __float128;
template <typename INT> using T2 = pair<INT,INT>;
template <typename INT> using T3 = tuple<INT,INT,INT>;
template <typename INT> using T4 = tuple<INT,INT,INT,INT>;
using path = pair<int,ll>;

/* VVV 常設ライブラリの非圧縮版は以下に挿入する。*/
// Random
ll GetRand( const int& Rand_min , const int& Rand_max ) { assert( Rand_min <= Rand_max ); ll answer = time( NULL ); return answer * rand() % ( Rand_max + 1 - Rand_min ) + Rand_min; }

// Set
#define DECLARATION_OF_HASH( ... )				\
  struct hash<__VA_ARGS__>					\
  {								\
								\
    inline size_t operator()( const __VA_ARGS__& n ) const;	\
								\
  };								\

class is_ordered
{

private:
  is_ordered() = delete;
  template <typename T> static constexpr auto Check( const T& t ) -> decltype( t < t , true_type() );
  static constexpr false_type Check( ... );

public:
  template <typename T> static constexpr const bool value = is_same_v< decltype( Check( declval<T>() ) ) , true_type >;

};

template <typename T>
using Set = conditional_t<is_constructible_v<unordered_set<T>>,unordered_set<T>,conditional_t<is_ordered::value<T>,set<T>,void>>;

// Tuple
#define DECLARATION_OF_ARITHMETIC_FOR_TUPLE( OPR )			\
  template <typename T , typename U , template <typename...> typename V> inline auto operator OPR ## =( V<T,U>& t0 , const V<T,U>& t1 ) -> decltype( ( get<0>( t0 ) , t0 ) )&; \
  template <typename T , typename U , typename V> inline tuple<T,U,V>& operator OPR ## =( tuple<T,U,V>& t0 , const tuple<T,U,V>& t1 ); \
  template <typename T , typename U , typename V , typename W> inline tuple<T,U,V,W>& operator OPR ## =( tuple<T,U,V,W>& t0 , const tuple<T,U,V,W>& t1 ); \
  template <typename ARG , typename T , typename U , template <typename...> typename V> inline auto operator OPR ## =( V<T,U>& t0 , const ARG& t1 ) -> decltype( ( get<0>( t0 ) , t0 ) )&; \
  template <typename ARG , typename T , typename U , typename V> inline tuple<T,U,V>& operator OPR ## =( tuple<T,U,V>& t0 , const ARG& t1 ); \
  template <typename ARG , typename T , typename U , typename V , typename W> inline tuple<T,U,V,W>& operator OPR ## =( tuple<T,U,V,W>& t0 , const ARG& t1 ); \
  template <template <typename...> typename V , typename...ARGS , typename ARG> inline auto operator OPR( const V<ARGS...>& t0 , const ARG& t1 ) -> decldecay_t( ( get<0>( t0 ) , t0 ) ) \

#define DEFINITION_OF_ARITHMETIC_FOR_TUPLE( OPR )			\
  template <typename T , typename U , template <typename...> typename V> inline auto operator OPR ## =( V<T,U>& t0 , const V<T,U>& t1 ) -> decltype( ( get<0>( t0 ) , t0 ) )& { get<0>( t0 ) OPR ## = get<0>( t1 ); get<1>( t0 ) OPR ## = get<1>( t1 ); return t0; } \
  template <typename T , typename U , typename V> inline tuple<T,U,V>& operator OPR ## =( tuple<T,U,V>& t0 , const tuple<T,U,V>& t1 ) { get<0>( t0 ) OPR ## = get<0>( t1 ); get<1>( t0 ) OPR ## = get<1>( t1 ); get<2>( t0 ) OPR ## = get<2>( t1 ); return t0; } \
  template <typename T , typename U , typename V , typename W> inline tuple<T,U,V,W>& operator OPR ## =( tuple<T,U,V,W>& t0 , const tuple<T,U,V,W>& t1 ) { get<0>( t0 ) OPR ## = get<0>( t1 ); get<1>( t0 ) OPR ## = get<1>( t1 ); get<2>( t0 ) OPR ## = get<2>( t1 ); get<3>( t0 ) OPR ## = get<3>( t1 ); return t0; } \
  template <typename ARG , typename T , typename U , template <typename...> typename V> inline auto operator OPR ## =( V<T,U>& t0 , const ARG& t1 ) -> decltype( ( get<0>( t0 ) , t0 ) )& { get<0>( t0 ) OPR ## = t1; get<1>( t0 ) OPR ## = t1; return t0; } \
  template <typename ARG , typename T , typename U , typename V> inline tuple<T,U,V>& operator OPR ## =( tuple<T,U,V>& t0 , const ARG& t1 ) { get<0>( t0 ) OPR ## = t1; get<1>( t0 ) OPR ## = t1; get<2>( t0 ) OPR ## = t1; return t0; } \
  template <typename ARG , typename T , typename U , typename V , typename W> inline tuple<T,U,V,W>& operator OPR ## =( tuple<T,U,V,W>& t0 , const ARG& t1 ) { get<0>( t0 ) OPR ## = t1; get<1>( t0 ) OPR ## = t1; get<2>( t0 ) OPR ## = t1; get<3>( t0 ) OPR ## = t1; return t0; } \
  template <template <typename...> typename V , typename...ARGS , typename ARG> inline auto operator OPR( const V<ARGS...>& t0 , const ARG& t1 ) -> decldecay_t( ( get<0>( t0 ) , t0 ) ) { auto t = t0; return move( t OPR ## = t1 ); } \

#define DECLARATION_OF_INCREMENT_FOR_TUPLE( INCR )			\
  template <typename T , typename U , template <typename...> typename V> inline auto operator INCR( V<T,U>& t ) -> decltype( ( get<0>( t ) , t ) )&; \
  template <typename T , typename U , typename V> inline tuple<T,U,V>& operator INCR ( tuple<T,U,V>& t ); \
  template <typename T , typename U , typename V , typename W> inline tuple<T,U,V,W>& operator INCR ( tuple<T,U,V,W>& t ); \

#define DEFINITION_OF_INCREMENT_FOR_TUPLE( INCR )			\
  template <typename T , typename U , template <typename...> typename V> inline auto operator INCR( V<T,U>& t ) -> decltype( ( get<0>( t ) , t ) )& { INCR get<0>( t ); INCR get<1>( t ); return t; } \
  template <typename T , typename U , typename V> inline tuple<T,U,V>& operator INCR ( tuple<T,U,V>& t ) { INCR get<0>( t ); INCR get<1>( t ); INCR get<2>( t ); return t; } \
  template <typename T , typename U , typename V , typename W> inline tuple<T,U,V,W>& operator INCR ( tuple<T,U,V,W>& t ) { INCR get<0>( t ); INCR get<1>( t ); INCR get<2>( t ); INCR get<3>( t ); return t; }	\

DEFINITION_OF_ARITHMETIC_FOR_TUPLE( + );
DEFINITION_OF_ARITHMETIC_FOR_TUPLE( - );
DEFINITION_OF_ARITHMETIC_FOR_TUPLE( * );
DEFINITION_OF_ARITHMETIC_FOR_TUPLE( / );
DEFINITION_OF_ARITHMETIC_FOR_TUPLE( % );

DEFINITION_OF_INCREMENT_FOR_TUPLE( ++ );
DEFINITION_OF_INCREMENT_FOR_TUPLE( -- );

template <class Traits , typename T> inline basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& is , tuple<T>& arg ){ return is >> get<0>( arg ); }
template <class Traits , typename T , typename U , template <typename...> typename V> inline auto operator>>( basic_istream<char,Traits>& is , V<T,U>& arg ) -> decltype((get<0>(arg),is))& { return is >> get<0>( arg ) >> get<1>( arg ); }
template <class Traits , typename T , typename U , typename V> inline basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& is , tuple<T,U,V>& arg ) { return is >> get<0>( arg ) >> get<1>( arg ) >> get<2>( arg ); }
template <class Traits , typename T , typename U , typename V , typename W> inline basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& is , tuple<T,U,V,W>& arg ) { return is >> get<0>( arg ) >> get<1>( arg ) >> get<2>( arg ) >> get<3>( arg ); }

template <class Traits , typename T> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const tuple<T>& arg ) { return os << get<0>( arg ); }
template <class Traits , typename T , typename U , template <typename...> typename V> inline auto operator<<( basic_ostream<char,Traits>& os , const V<T,U>& arg ) -> decltype((get<0>(arg),os))& { return os << get<0>( arg ) << " " << get<1>( arg ); }
template <class Traits , typename T , typename U , typename V> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const tuple<T,U,V>& arg ) { return os << get<0>( arg ) << " " << get<1>( arg ) << " " << get<2>( arg ); }
template <class Traits , typename T , typename U , typename V , typename W> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const tuple<T,U,V,W>& arg ) { return os << get<0>( arg ) << " " << get<1>( arg ) << " " << get<2>( arg ) << " " << get<3>( arg ); }

#define DEFINITION_OF_HASH_FOR_TUPLE( PAIR )				\
  template <typename T , typename U> inline size_t hash<PAIR<T,U>>::operator()( const PAIR<T,U>& n ) const { static const size_t seed = ( GetRand( 1e3 , 1e8 ) << 1 ) | 1; static const hash<T> h0; static const hash<U> h1; return ( h0( get<0>( n ) ) * seed ) ^ h1( get<1>( n ) ); } \

template <typename T> DECLARATION_OF_HASH( tuple<T> );
template <typename T , typename U> DECLARATION_OF_HASH( pair<T,U> );
template <typename T , typename U> DECLARATION_OF_HASH( tuple<T,U> );
template <typename T , typename U , typename V> DECLARATION_OF_HASH( tuple<T,U,V> );
template <typename T , typename U , typename V , typename W> DECLARATION_OF_HASH( tuple<T,U,V,W> );

template <typename T> inline size_t hash<tuple<T>>::operator()( const tuple<T>& n ) const { static const hash<T> h; return h(get<0>( n ) ); }
DEFINITION_OF_HASH_FOR_TUPLE( pair );
DEFINITION_OF_HASH_FOR_TUPLE( tuple );
template <typename T , typename U , typename V> inline size_t hash<tuple<T,U,V>>::operator()( const tuple<T,U,V>& n ) const { static const size_t seed = ( GetRand( 1e3 , 1e8 ) << 1 ) | 1; static const hash<pair<T,U>> h01; static const hash<V> h2; return ( h01( { get<0>( n ) , get<1>( n ) } ) * seed ) ^ h2( get<2>( n ) ); }
template <typename T , typename U , typename V , typename W> inline size_t hash<tuple<T,U,V,W>>::operator()( const tuple<T,U,V,W>& n ) const { static const size_t seed = ( GetRand( 1e3 , 1e8 ) << 1 ) | 1; static const hash<pair<T,U>> h01; static const hash<pair<V,W>> h23; return ( h01( { get<0>( n ) , get<1>( n ) } ) * seed ) ^ h23( { get<2>( n ) , get<3>( n ) } ); }

// Vector
#define DECLARATION_OF_ARITHMETIC_FOR_VECTOR( V , OPR )			\
  template <typename T> inline V<T>& operator OPR ## = ( V<T>& a , const T& t ); \
  template <typename T> inline V<T>& operator OPR ## = ( V<T>& a0 , const V<T>& a1 ); \
  template <typename T , typename U> inline V<T> operator OPR( V<T> a , const U& u ); \

#define DEFINITION_OF_ARITHMETIC_FOR_VECTOR( V , OPR )			\
  template <typename T> inline V<T>& operator OPR ## = ( V<T>& a , const T& t ) { for( auto& s : a ){ s OPR ## = t; } return a; } \
  template <typename T> inline V<T>& operator OPR ## = ( V<T>& a0 , const V<T>& a1 ) { assert( a0.size() <= a1.size() ); auto itr0 = a0.begin() , end0 = a0.end(); auto itr1 = a1.begin(); while( itr0 != end0 ){ *( itr0++ ) OPR ## = *( itr1++ ); } return a0; } \
  template <typename T , typename U> inline V<T> operator OPR( V<T> a , const U& u ) { return move( a OPR ## = u ); } \

#define DECLARATION_OF_INCREMENT_FOR_VECTOR( V , INCR )		\
  template <typename T> inline V<T>& operator INCR( V<T>& a );	\

#define DEFINITION_OF_INCREMENT_FOR_VECTOR( V , INCR )			\
  template <typename T> inline V<T>& operator INCR( V<T>& a ) { for( auto& i : a ){ INCR i; } return a; } \

#define DECLARATION_OF_ARITHMETICS_FOR_VECTOR( V )			\
  DECLARATION_OF_ARITHMETIC_FOR_VECTOR( V , + );			\
  DECLARATION_OF_ARITHMETIC_FOR_VECTOR( V , - );			\
  DECLARATION_OF_ARITHMETIC_FOR_VECTOR( V , * );			\
  DECLARATION_OF_ARITHMETIC_FOR_VECTOR( V , / );			\
  DECLARATION_OF_ARITHMETIC_FOR_VECTOR( V , % );			\
  DECLARATION_OF_INCREMENT_FOR_VECTOR( V , ++ );			\
  DECLARATION_OF_INCREMENT_FOR_VECTOR( V , -- );			\
  template <typename T> inline V<T> operator*( const T& scalar , V<T> v ) \

#define DEFINITION_OF_ARITHMETICS_FOR_VECTOR( V )			\
  DEFINITION_OF_ARITHMETIC_FOR_VECTOR( V , + );				\
  DEFINITION_OF_ARITHMETIC_FOR_VECTOR( V , - );				\
  DEFINITION_OF_ARITHMETIC_FOR_VECTOR( V , * );				\
  DEFINITION_OF_ARITHMETIC_FOR_VECTOR( V , / );				\
  DEFINITION_OF_ARITHMETIC_FOR_VECTOR( V , % );				\
  DEFINITION_OF_INCREMENT_FOR_VECTOR( V , ++ );				\
  DEFINITION_OF_INCREMENT_FOR_VECTOR( V , -- );				\
  template <typename T> inline V<T> operator*( const T& scalar , V<T> v ) { for( auto& t : v ){ t *= scalar; } return move( v ); } \

DEFINITION_OF_ARITHMETICS_FOR_VECTOR( vector );
DEFINITION_OF_ARITHMETICS_FOR_VECTOR( list );

template <typename V> inline auto Get( V& a ) { return [&]( const int& i = 0 ) -> const decldecay_t( a[0] )& { return a[i]; }; }
template <typename T = int> inline vector<T> id( const int& size ) { vector<T> answer( size ); for( int i = 0 ; i < size ; i++ ){ answer[i] = i; } return answer; }

template <typename T> inline void Sort( vector<T>& a , const bool& reversed ) { if( reversed ){ static auto comp = []( const T& t0 , const T& t1 ) { return t1 < t0; }; sort( a.begin() , a.end() , comp ); } else { sort( a.begin() , a.end() ); } }

template <typename T> inline vector<int> IndexSort( const vector<T>& a , const bool& reversed ) { auto index = id<int>( a.size() ); if( reversed ){ sort( index.begin() , index.end() , [&]( const int& i , const int& j ) { return a[j] < a[i]; } ); } else { sort( index.begin() , index.end() , [&]( const int& i , const int& j ) { return a[i] < a[j]; } ); } return index; }

template <typename T , typename U = T> inline U Sum( const vector<T>& a ) { U answer{}; for( auto& x : a ){ answer += x; } return answer; }
template <typename T , typename U = T> inline U Product( const vector<T>& a ) { U answer{}; for( auto& x : a ){ answer *= x; } return answer; }

#define DECLARATION_OF_COUT_FOR_VECTOR( V ) template <class Traits , typename Arg> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const V<Arg>& arg )
#define DEFINITION_OF_COUT_FOR_VECTOR( V ) template <class Traits , typename Arg> inline basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os , const V<Arg>& arg ) { auto begin = arg.begin() , end = arg.end(); auto itr = begin; while( itr != end ){ ( itr == begin ? os : os << " " ) << *itr; itr++; } return os; }

DEFINITION_OF_COUT_FOR_VECTOR( vector );
DEFINITION_OF_COUT_FOR_VECTOR( list );
DEFINITION_OF_COUT_FOR_VECTOR( set );
DEFINITION_OF_COUT_FOR_VECTOR( unordered_set );

inline void VariadicResize( const int& size ) {}
template <typename Arg , typename... ARGS> inline void VariadicResize( const int& size , Arg& arg , ARGS&... args ) { arg.resize( size ); VariadicResize( size , args... ); }

// Map
#define DECLARATION_OF_ARITHMETIC_FOR_MAP( MAP , OPR )			\
  template <typename T , typename U> inline MAP<T,U>& operator OPR ## = ( MAP<T,U>& a , const pair<T,U>& v ); \
  template <typename T , typename U> inline MAP<T,U>& operator OPR ## = ( MAP<T,U>& a0 , const MAP<T,U>& a1 ); \
  template <typename T , typename U , typename ARG> inline MAP<T,U> operator OPR( MAP<T,U> a , const ARG& arg ); \

#define DEFINITION_OF_ARITHMETIC_FOR_MAP( MAP , OPR )			\
  template <typename T , typename U> inline MAP<T,U>& operator OPR ## = ( MAP<T,U>& a , const pair<T,U>& v ) { a[v.first] OPR ## = v.second; return a; } \
  template <typename T , typename U> inline MAP<T,U>& operator OPR ## = ( MAP<T,U>& a0 , const MAP<T,U>& a1 ) { for( auto& [t,u] : a1 ){ a0[t] OPR ## = u; } return a0; } \
  template <typename T , typename U , typename ARG> inline MAP<T,U> operator OPR( MAP<T,U> a , const ARG& arg ) { return move( a OPR ## = arg ); } \

#define DECLARATION_OF_ARITHMETICS_FOR_MAP( MAP )	\
  DECLARATION_OF_ARITHMETIC_FOR_MAP( MAP , + );		\
  DECLARATION_OF_ARITHMETIC_FOR_MAP( MAP , - );		\
  DECLARATION_OF_ARITHMETIC_FOR_MAP( MAP , * );		\
  DECLARATION_OF_ARITHMETIC_FOR_MAP( MAP , / );		\
  DECLARATION_OF_ARITHMETIC_FOR_MAP( MAP , % );		\

#define DEFINITION_OF_ARITHMETICS_FOR_MAP( MAP ) \
  DEFINITION_OF_ARITHMETIC_FOR_MAP( MAP , + );	\
  DEFINITION_OF_ARITHMETIC_FOR_MAP( MAP , - );	\
  DEFINITION_OF_ARITHMETIC_FOR_MAP( MAP , * );	\
  DEFINITION_OF_ARITHMETIC_FOR_MAP( MAP , / );	\
  DEFINITION_OF_ARITHMETIC_FOR_MAP( MAP , % );	\

template <typename T , typename U>
using Map = conditional_t<is_constructible_v<unordered_map<T,int>>,unordered_map<T,U>,conditional_t<is_ordered::value<T>,map<T,U>,void>>;

DEFINITION_OF_ARITHMETICS_FOR_MAP( map );
DEFINITION_OF_ARITHMETICS_FOR_MAP( unordered_map );

// StdStream
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>& VariadicSet( basic_istream<char,Traits>& is , const int& i ) { return is; }
template <class Traits , typename Arg , typename... ARGS> inline basic_istream<char,Traits>& VariadicSet( basic_istream<char,Traits>& is , const int& i , Arg& arg , ARGS&... args ) { return VariadicSet( is >> arg[i] , i , 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 , Arg&& arg ) { return os << forward<Arg>( arg ); }
template <class Traits , typename Arg1 , typename Arg2 , typename... ARGS> inline basic_ostream<char,Traits>& VariadicCout( basic_ostream<char,Traits>& os , Arg1&& arg1 , Arg2&& arg2 , ARGS&&... args ) { return VariadicCout( os << forward<Arg1>( arg1 ) << " " , forward<Arg2>( arg2 ) , forward<ARGS>( args )... ); }

template <class Traits , typename Arg> inline basic_ostream<char,Traits>& VariadicCoutNonSep( basic_ostream<char,Traits>& os , Arg&& arg ) { return os << forward<Arg>( arg ); }
template <class Traits , typename Arg1 , typename Arg2 , typename... ARGS> inline basic_ostream<char,Traits>& VariadicCoutNonSep( basic_ostream<char,Traits>& os , Arg1&& arg1 , Arg2&& arg2 , ARGS&&... args ) { return VariadicCoutNonSep( os << forward<Arg1>( arg1 ) , forward<Arg2>( arg2 ) , forward<ARGS>( args )... ); }

template <class Traits , typename ARRAY> inline basic_ostream<char,Traits>& CoutArray( basic_ostream<char,Traits>& os , const int& i_start , const int& i_ulim , ARRAY&& a ) { for( int i = i_start ; i < i_ulim ; i++ ){ ( i == i_start ? os : ( os << " " ) ) << a[i]; } return os; }
/* AAA 常設ライブラリの非圧縮版は以上に挿入する。*/

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

// 入力フォーマットチェック用
// 1行中の変数の個数をSEPARATOR区切りで確認
#define GETLINE_COUNT( S , VARIABLE_NUMBER , SEPARATOR ) GETLINE( S ); int VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S = 0; int VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S  = S.size(); { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S[i] == SEPARATOR ){ count++; } } assert( VARIABLE_NUMBER == 0 ? size == 0 : count + 1 == VARIABLE_NUMBER ); }
// 余計な入力の有無を確認
#if defined( DEBUG ) || defined( REACTIVE )
  #define CHECK_REDUNDANT_INPUT 
#else
  #ifdef USE_GETLINE
    #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin )
  #else
    #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin )
  #endif
#endif
// MIN <= N <= MAXを満たすNをSから構築
#define STOI( S , N , MIN , MAX ) decldecay_t( MAX ) N = 0; decldecay_t( MAX ) BOUND ## N = max( decldecay_t( MAX )( abs( MIN ) ) , abs( MAX ) ); { bool VARIABLE_FOR_POSITIVITY_FOR_GETLINE = true; assert( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ); if( S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_GETLINE = false; VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; assert( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ); } assert( S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) != " " ); string VARIABLE_FOR_LETTER_FOR_GETLINE{}; int VARIABLE_FOR_DIGIT_FOR_GETLINE{}; while( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ? ( VARIABLE_FOR_LETTER_FOR_GETLINE = S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) ) != " " : false ){ VARIABLE_FOR_DIGIT_FOR_GETLINE = stoi( VARIABLE_FOR_LETTER_FOR_GETLINE ); assert( N < BOUND ## N / 10 ? true : N == BOUND ## N / 10 && VARIABLE_FOR_DIGIT_FOR_GETLINE <= BOUND ## N % 10 ); N = N * 10 + VARIABLE_FOR_DIGIT_FOR_GETLINE; VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } if( ! VARIABLE_FOR_POSITIVITY_FOR_GETLINE ){ N *= -1; } if( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ){ VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } ASSERT( N , MIN , MAX ); }
#define STOI_A( S , I , N , A , MIN , MAX ) vector<decldecay_t( MAX )> A( N + I ); FOR( VARIABLE_FOR_STOI_A , 0 , N ){ STOI( S , A ##_VARIABLE_FOR_STOI_A , MIN , MAX ); A[VARIABLE_FOR_STOI_A + I] = A ##_VARIABLE_FOR_STOI_A; }
// Sをstring SEPARATORで区切りTを構築
#define SEPARATE( S , T , SEPARATOR ) string T{}; { assert( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ); int VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S_prev = VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S; assert( S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) != SEPARATOR ); string VARIABLE_FOR_LETTER_FOR_GETLINE{}; while( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ? ( VARIABLE_FOR_LETTER_FOR_GETLINE = S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) ) != SEPARATOR : false ){ VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } T = S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S_prev , VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S - VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S_prev ); if( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ){ VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } }

#define INCLUDE_LIBRARY
#include __FILE__
#endif // INCLUDE_LIBRARY
#endif // INCLUDE_MAIN
0