結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー 👑 p-adic
提出日時 2023-08-14 22:54:30
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 62,017 bytes
コンパイル時間 22,082 ms
コンパイル使用メモリ 325,964 KB
最終ジャッジ日時 2025-02-16 08:13:10
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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( MESSAGE ) cerr << MESSAGE << endl;
#define COUT( ANSWER ) cout << ANSWER << endl
#define ASSERT( A , MIN , MAX ) CERR( "ASSERT " << ( MIN ) << ( ( MIN ) <= A ? "<=" : ">" ) << A << ( A <= ( MAX ) ? "<=" : ">" ) << (
      MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) )
#define LIBRARY_SEARCH bool searched_library = false; LibrarySearch( searched_library ); if( searched_library ){ QUIT; };
#define START_WATCH( PROCESS_NAME ) StartWatch( PROCESS_NAME )
#define STOP_WATCH( HOW_MANY_TIMES ) StopWatch( HOW_MANY_TIMES )
#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( MESSAGE )
#define COUT( ANSWER ) cout << ANSWER << "\n"
#define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
#define LIBRARY_SEARCH
#define START_WATCH( PROCESS_NAME )
#define STOP_WATCH( HOW_MANY_TIMES )
#endif
// #define RANDOM_TEST
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#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 , A ) LL A; cin >> A
#define CIN_ASSERT( A , MIN , MAX ) TYPE_OF( MAX ) A; SET_ASSERT( A , MIN , MAX )
#define GETLINE( A ) string A; getline( cin , A )
#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR )
#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 QUIT return 0
#define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS )
#ifdef DEBUG
inline void AlertAbort( int n ) { CERR(
      "abortassert" ); }
void StartWatch( const string& process_name = "nothing" );
void StopWatch( const int& how_many_times = 1 );
#endif
#if defined( DEBUG ) && defined( RANDOM_TEST )
inline CEXPR( int , bound_random_test_num , 1000 );
#define START_MAIN FOR( random_test_num , 0 , bound_random_test_num ){ CERR( "(" << random_test_num << ")" );
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 ); continue; } else { CERR( ( ANSWER ) << " != " <<
      guchoku ); QUIT; }
#define FINISH_MAIN CERR( "" ); }
#else
#define START_MAIN
#define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX )
#define RETURN( ANSWER ) COUT( ( ANSWER ) ); QUIT
#define FINISH_MAIN
#endif
template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : -a; }
template <typename T> inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); }
#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 ); \
} \
} \
//
// EXPRESSIONANSWER調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 ); \
CERR( ( EXPRESSION DESIRED_INEQUALITY TARGET ? "" : "" ) ); \
assert( EXPRESSION DESIRED_INEQUALITY TARGET ); \
} else { \
CERR( " " << MINIMUM << ">" << MAXIMUM ); \
assert( MINIMUM <= MAXIMUM ); \
} \
// 調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 ) \
//
#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&
#define ASK_NUMBER( ... ) \
CERR( "" ); \
CERR( "" ); \
problems = { __VA_ARGS__ }; \
problems_size = problems.size(); \
FOR( i , 0 , problems_size ){ \
CERR( i << ": " << problems[i] ); \
} \
cin >> num; \
CERR( "" ); \
if( num < 0 || num >= problems_size ){ \
CERR( "" << problems_size - 1 << "" ); \
CERR( "" ); \
CERR( "" ); \
return; \
} \
num_temp = 0; \
#define ASK_YES_NO( QUESTION ) \
CERR( "" ); \
CERR( QUESTION << "[y/n]" ); \
cin >> reply; \
if( reply != "y" && reply != "n" ){ \
CERR( "y/n" ); \
CERR( "" ); \
CERR( "" ); \
return; \
} \
CERR( "" ); \
#define SLS( CLASS ) void CLASS ## LibrarySearch( int& num , int& num_temp , string& reply , vector<string>& problems , int& problems_size )
#define CALL_SLS( CLASS ) CLASS ## LibrarySearch( num , num_temp , reply , problems , problems_size )
SLS( ExplicitExpression );
SLS( ExplicitExpressionUnary );
SLS( ExplicitExpressionMultiary );
SLS( ExplicitExpressionIteration );
SLS( ExplicitExpressionArraySum );
SLS( ExplicitExpressionFunctionOnPermutation );
SLS( ExplicitExpressionFunctionOnTree );
SLS( FunctionOnTree );
SLS( ExplicitExpressionFunctionOnNonTreeGraph );
SLS( ExplicitExpressionOrder );
SLS( ExplicitExpressionProbability );
SLS( ExplicitExpressionOther );
SLS( Maximisation );
SLS( MaximisationExplicitExpression );
SLS( MaximisationFunctionOnArray );
SLS( MaximisationSubArraySum );
SLS( MaximisationArrayFunction );
SLS( MaximisationArrayLength );
SLS( MaximisationFunctionOnTree );
SLS( MinimisationMovingCost );
SLS( MaximisationStringMatching );
SLS( MaximisationBipartiteMatching );
SLS( MaximisationProbability );
SLS( Counting );
SLS( CountingExplicitExpression );
SLS( CountingArray );
SLS( CountingSubArray );
SLS( CountingSumFixedSubArray );
SLS( CountingRestrctedSubArray );
SLS( CountingRestrctedContinuousSubArray );
SLS( CountingRestrctedDiscontinuousSubArray );
SLS( CountingRestrctedSubPermutation );
SLS( CountingArbitraryArray );
SLS( CountingSubArrayImage );
SLS( CountingPartitionOfTree );
SLS( CountingString );
SLS( Solving );
SLS( Query );
SLS( QueryArray );
SLS( QueryGraph );
SLS( Decision );
SLS( DecisionConnectedness );
SLS( DecisionHigherConnectedness );
SLS( DecisionGame );
SLS( DecisionAccessibility );
SLS( DecisionSatisfiability );
SLS( Construction );
void LibrarySearch( bool& searched_library )
{
int num = 0;
vector<string> problems{};
int problems_size = 13;
int num_temp = 0;
string reply{};
ASK_YES_NO( "" );
if( reply != "y" ){
CERR( "" );
CERR( "" );
return;
}
searched_library = true;
ASK_NUMBER(
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( ExplicitExpression );
} else if( num == num_temp++ ){
CALL_SLS( Maximisation );
} else if( num == num_temp++ ){
CALL_SLS( Counting );
} else if( num == num_temp++ ){
CALL_SLS( Solving );
} else if( num == num_temp++ ){
CALL_SLS( Query );
} else if( num == num_temp++ ){
CALL_SLS( Decision );
} else if( num == num_temp++ ){
CALL_SLS( Construction );
}
ASK_YES_NO( "" );
if( reply == "y" ){
CERR( "" );
CERR( "" );
CERR( "N" );
CERR( "使" );
CERR( "TLE" );
CERR( "- " );
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\CoordinateCompress" );
CERR( "" );
CERR( "" );
CERR( "static" );
CERR( "" );
CERR( "" );
}
CERR( "" );
CERR( "" );
}
SLS( ExplicitExpression )
{
ASK_YES_NO( "" );
if( reply == "y" ){
CALL_SLS( ExplicitExpressionUnary );
} else {
CALL_SLS( ExplicitExpressionMultiary );
}
}
SLS( ExplicitExpressionUnary )
{
CERR( "OEIS" );
CERR( "https://oeis.org/?language=japanese" );
CERR( "" );
CERR( "" );
CERR( "- 調" );
CERR( "- p使" );
CERR( "- pp" );
CERR( " " );
CERR( "" );
CERR( "" );
CERR( "" );
CERR( "- " );
CERR( "- " );
CERR( "- " );
CERR( "- " );
CERR( "" );
}
SLS( ExplicitExpressionMultiary )
{
ASK_YES_NO( "" );
if( reply == "y" ){
CALL_SLS( ExplicitExpressionIteration );
} else {
ASK_NUMBER(
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionArraySum );
} else if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionFunctionOnPermutation );
} else if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionFunctionOnTree );
} else if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionFunctionOnNonTreeGraph );
} else if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionOrder );
} else if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionProbability );
} else if( num == num_temp++ ){
CALL_SLS( ExplicitExpressionOther );
}
}
}
SLS( ExplicitExpressionIteration )
{
CERR( "NTK" );
CERR( "- O((N + T)log_2 K)" );
CERR( " \\Mathematics\\Function\\Iteration\\Doubling" );
CERR( "- O(TN)" );
CERR( " \\Mathematics\\Function\\Iteration\\LoopDetection" );
CERR( "- O(N)" );
CERR( "" );
}
SLS( ExplicitExpressionArraySum )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CERR( "f" );
CERR( "f" );
CERR( "" );
CERR( "" );
CERR( "" );
CERR( "\\Mathematics\\Arithmetic\\Mod" );
CERR( "\\Mathematics\\Polynoial" );
CERR( "" );
} else if( num == num_temp++ ){
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CERR( "" );
CALL_SLS( ExplicitExpressionFunctionOnTree );
CERR( "" );
CERR( "f" );
CERR( "f" );
} else if( num == num_temp++ ){
CERR( "" );
CERR( "" );
}
}
CERR( "" );
CERR( "" );
}
SLS( ExplicitExpressionFunctionOnPermutation )
{
CERR( "- " );
CERR( " - O(N log_2 N)O(N^2)" );
CERR( " - O(N log_2 N)O(N)" );
CERR( "- " );
CERR( " - O(N^3)" );
CERR( " - O(N 2^N)" );
CERR( "" );
CERR( "" );
CERR( "" );
CERR( "- O(N^2)" );
CERR( "- O(N log_2 N)BIT" );
CERR( " \\Mathematics\\Combinatorial\\Permutation" );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\BIT" );
CERR( "" );
CERR( "" );
CERR( "" );
CERR( "i<j" );
CERR( "" );
CERR( "" );
}
SLS( ExplicitExpressionFunctionOnTree )
{
CALL_SLS( FunctionOnTree );
CERR( "" );
CERR( "DP" );
CERR( "\\Mathematics\\Geometry\\Graph\\DepthFirstSearch\\Tree" );
CERR( "" );
ASK_YES_NO( "fbit" );
if( reply == "y" ){
CERR( "Tvjbitsdp[v][s][j]" );
CERR( "v,s,j" );
CERR( "Tbit1" );
CERR( "ijbits=0,1dp[i][s][j]" );
CERR( "" );
CERR( "" );
CERR( "bitset" );
}
}
SLS( FunctionOnTree )
{
CERR( "f" );
CERR( "" );
CERR( "TPPpf(p)F(P)" );
CERR( "TT" );
CERR( "" );
CERR( "PppD(p)" );
CERR( "DP" );
CERR( "" );
CERR( "PpP'p" );
CERR( "F(P)=F(P')+f(p)" );
}
SLS( ExplicitExpressionFunctionOnNonTreeGraph )
{
CERR( "- " );
CERR( " - O(N 2^N)" );
CERR( " \\Mathematics\\Combinatorial\\ZetaTransform" );
CERR( " - O(N^2)" );
CERR( " \\Mathematics\\Combinatorial\\ZetaTransform\\MahlerTransform" );
CERR( "- " );
CERR( " \\Mathematics\\Combinatorial\\ZetaTransform" );
CERR( "" );
}
SLS( ExplicitExpressionOrder )
{
CERR( "Sa" );
CERR( "- si" );
CERR( " a[i]<=si" );
CERR( "- ia[i]Ss" );
CERR( " a[i]<=ss" );
CERR( "" );
}
SLS( ExplicitExpressionProbability )
{
CERR( "- " );
CERR( " - " );;
CERR( " \\Mathematics\\Combinatorial\\ZetaTransform" );
CERR( " - " );
CERR( " - " );
CERR( "- " );
CERR( " - " );
CERR( " - " );
CERR( "" );
}
SLS( ExplicitExpressionOther )
{
CERR( "- " );
CERR( " - " );
CERR( " - " );
CERR( " - " );
CERR( " https://ei1333.hateblo.jp/entry/2021/07/30/144201" );
CERR( "- " );
CERR( "" );
}
SLS( Maximisation )
{
ASK_NUMBER(
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( MaximisationExplicitExpression);
} else if( num == num_temp++ ){
CALL_SLS( MaximisationFunctionOnArray );
} else if( num == num_temp++ ){
CALL_SLS( MaximisationArrayLength );
} else if( num == num_temp++ ){
CALL_SLS( MaximisationFunctionOnTree );
} else if( num == num_temp++ ){
CALL_SLS( MinimisationMovingCost );
} else if( num == num_temp++ ){
CALL_SLS( MaximisationStringMatching );
} else if( num == num_temp++ ){
CALL_SLS( MaximisationBipartiteMatching );
} else if( num == num_temp++ ){
CALL_SLS( MaximisationProbability );
}
}
SLS( MaximisationExplicitExpression )
{
ASK_NUMBER(
"" ,
"" ,
""
);
if( num == num_temp++ ){
CERR( "" );
} else if( num == num_temp++ ){
CERR( "" );
} else if( num == num_temp++ ){
CERR( "" );
CERR( "- 調" );
CERR( "- " );
CERR( "- " );
CERR( "" );
}
CERR( "" );
CERR( "" );
}
SLS( MaximisationFunctionOnArray )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( MaximisationSubArraySum );
} else if( num == num_temp++ ){
CALL_SLS( MaximisationArrayFunction );
}
} else if( num == num_temp++ ){
CERR( "- " );
CERR( " idp[i]" );
CERR( " i" );
CERR( "- v" );
CERR( " v" );
CERR( "" );
}
}
SLS( MaximisationSubArraySum )
{
CERR( "NWV" );
CERR( "- B=∞" );
CERR( "- B<∞O(2^N)" );
CERR( "- B<∞O(N 2^{N/2})" );
CERR( "- B<∞O(NV)[B-V,B+V]" );
CERR( " " );
CERR( " https://stackoverflow.com/a/18949218" );
CERR( "- W10^5O((N+W)log_2 W)" );
CERR( " " );
CERR( " \\Mathematics\\Polynomial" );
CERR( "- O(N 2^N)bit" );
CERR( "" );
}
SLS( MaximisationArrayFunction )
{
CERR( "FA" );
CERR( "BF(B)" );
CERR( "fx" );
CERR( "- ixX(i)" );
CERR( "- ixi+1xdX(i)" );
CERR( "" );
CERR( "- O(sum_i X(i) dX(i))fxO(1)" );
CERR( " ix" );
CERR( "- O(N log_2 X(N))" );
CERR( " - fxO(N)x調x" );
CERR( " - fxO(N/x)x" );
CERR( "- O(N log_2 N)xfxO(log_2 N)" );
CERR( " x" );
CERR( "" );
}
SLS( MaximisationArrayLength )
{
CERR( "" );
CERR( "- " );
CERR( " " );
CERR( " \\Mathematics\\Combinatorial\\Counting\\IncreasingSubsequence" );
CERR( "- " );
CERR( " " );
CERR( " \\Mathematics\\Combinatorial\\Counting\\IncreasingSubsequence\\Subwalk" );
CERR( "" );
}
SLS( MaximisationFunctionOnTree )
{
CALL_SLS( FunctionOnTree );
CERR( "iF(P)dp[i]" );
CERR( "iO(N^2×f)" );
CERR( "" );
}
SLS( MinimisationMovingCost )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CERR( "" );
CERR( "" );
CERR( "- BFSDijkstra" );
CERR( " \\Mathematics\\Geometry\\Graph\\BreadthFirst" );
CERR( " \\Mathematics\\Geometry\\Graph\\Dijkstra" );
CERR( "- " );
CERR( " - O(V^3)FloydWarshall" );
CERR( " \\Mathematics\\Geometry\\Graph\\FloydWarshall" );
CERR( " - maxO(E(log_2 E + α(V)))UnionFind" );
CERR( " \\Utility\\VLTree\\UnionFindForest" );
CERR( "" );
CERR( "" );
CERR( "" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "HeldKarp" );
}
}
SLS( MaximisationStringMatching )
{
CERR( "" );
CERR( "- " );
CERR( "- " );
CERR( " - O(N)" );
CERR( " - O(N)" );
CERR( "- " );
CERR( " \\Utility\\String\\RollingHash" );
CERR( "- Z" );
CERR( " https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05" );
CERR( "- {0,1}" );
CERR( " " );
CERR( " \\Mathematics\\Arithmetic\\Mod" );
CERR( " \\Mathematics\\Polynomial" );
CERR( "" );
}
SLS( MaximisationBipartiteMatching )
{
CERR( "HopcroftKarp" );
CERR( "\\Mathematics\\Geometry\\Graph\\HopcroftKarp" );
CERR( "" );
}
SLS( MaximisationProbability )
{
CERR( "" );
CERR( "" );
CERR( "sdp[s]" );
CERR( "s" );
}
SLS( Counting )
{
ASK_NUMBER(
"" ,
"" ,
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( CountingExplicitExpression );
} else if( num == num_temp++ ){
CALL_SLS( CountingArray );
} else if( num == num_temp++ ){
CALL_SLS( CountingPartitionOfTree );
} else if( num == num_temp++ ){
CALL_SLS( CountingString );
}
}
SLS( CountingExplicitExpression )
{
CERR( "- " );
CERR( "- " );
CERR( "- " );
CERR( "" );
}
SLS( CountingArray )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( CountingSubArray );
} else if( num == num_temp++ ){
CALL_SLS( CountingArbitraryArray );
}
}
SLS( CountingSubArray )
{
ASK_NUMBER(
"" ,
""
""
);
if( num == num_temp++ ){
CALL_SLS( CountingSumFixedSubArray );
} else if( num == num_temp++ ){
CALL_SLS( CountingRestrctedSubArray );
} else if( num == num_temp++ ){
CALL_SLS( CountingSubArrayImage );
}
}
SLS( CountingSumFixedSubArray )
{
CERR( "NW" );
CERR( "- O(2^N)" );
CERR( "- O(2^N)" );
CERR( "- O(2^{N/2}N)" );
CERR( " " );
CERR( "- W10^5O((N+W)log_2 W)" );
CERR( " " );
CERR( " \\Mathematics\\Arithmetic\\Mod" );
CERR( " \\Mathematics\\Polynomial" );
CERR( "" );
}
SLS( CountingRestrctedSubArray )
{
ASK_NUMBER(
"" ,
"" ,
""
);
CERR( "NAL+n<=N+1n,L" );
CERR( "- iQ(i)" );
CERR( "- 0<=l<Ln-tuple(b_0,...,b_{n-1})R_l(b_0,...,b_{n-1})" );
CERR( "BP(B)" );
CERR( "B|B|Q(|B|)|B|<L+n0<=l<=|B|-n" );
CERR( " R_l(B_l,...,B_{l+n-1})" );
CERR( "" );
CERR( "" );
CERR( "N>=3(n,L)=(2,2)" );
CERR( "- Q(i)=i=3" );
CERR( "- R_0(b_0,b_1)=b_0<b_1" );
CERR( "- R_1(b_0,b_1)=b_0>b_1" );
CERR( "" );
CERR( "" );
if( num == num_temp++ ){
CALL_SLS( CountingRestrctedContinuousSubArray );
} else if( num == num_temp++ ){
CALL_SLS( CountingRestrctedDiscontinuousSubArray );
} else if( num == num_temp++ ){
CALL_SLS( CountingRestrctedSubPermutation );
}
CERR( "" );
CERR( "" );
CERR( "R_l(B)gcdmax" );
CERR( "" );
CERR( "\\Mathematics\\Combinatorial\\ZetaTransform" );
CERR( "" );
}
SLS( CountingRestrctedContinuousSubArray )
{
CERR( "P(B)AB" );
CERR( "- R_llO(N)" );
CERR( "- R_ll" );
CERR( " - O(N^2)" );
CERR( " - O(N^2)R_l" );
CERR( "" );
}
SLS( CountingRestrctedDiscontinuousSubArray )
{
CERR( "P(B)AB" );
CERR( "- n-1<=i<=max{j<=N|Q(j)}i" );
CERR( "- (0,1,...,N-1)n-1s" );
CERR( "" );
CERR( "i0<=l<=i-nR_l(B)" );
CERR( " n-1sABdp[i][s]" );
CERR( "i,s" );
CERR( "\\Mathematics\\Combinatorial\\Counting\\IncreasingSubsequence" );
CERR( "\\Mathematics\\Combinatorial\\Counting\\IncreasingSubsequence\\Subwalk" );
CERR( "" );
}
SLS( CountingRestrctedSubPermutation )
{
CERR( "P(B)AB" );
CERR( "- n-1<=|S|<=max{j<=N|Q(j)}(0,1,...,N-1)S" );
CERR( "- Sn-1s" );
CERR( "" );
CERR( "0<=l<=|S|-nR_l(B)n-1s" );
CERR( " SABdp[S][s]" );
CERR( "S,s" );
CERR( "" );
CERR( "s[0,N)^{n-1}S" );
CERR( "" );
CERR( "" );
CERR( "N" );
CERR( "7! ≒ 5×10^3" );
CERR( "8! ≒ 4×10^4" );
CERR( "9! ≒ 4×10^5" );
CERR( "10! ≒ 4×10^6" );
CERR( "11! ≒ 4×10^7" );
CERR( "12! ≒ 5×10^8" );
CERR( "" );
CERR( "\\Mathematics\\Combinatorial\\Permutation" );
CERR( "" );
}
SLS( CountingArbitraryArray )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CERR( "- " );
CERR( "- " );
CERR( " ivdp[i][v]" );
CERR( " i,v" );
} else if( num == num_temp++ ){
CERR( "- " );
CERR( "- " );
CERR( "- " );
}
CERR( "" );
}
SLS( CountingSubArrayImage )
{
CERR( "A" );
CERR( "A" );
CERR( "DP" );
CERR( "iAdp[i]" );
CERR( "s=A[j]j<ilast[i][s]" );
CERR( "i" );
CERR( "" );
CERR( "" );
}
SLS( CountingPartitionOfTree )
{
CALL_SLS( FunctionOnTree );
CERR( "F(P)P" );
CERR( "iF(P)=vPdp[i][v]" );
CERR( "i,vO(N^2 v_max×f)" );
CERR( "" );
}
SLS( CountingString )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CERR( "" );
CALL_SLS( CountingSubArrayImage );
} else if( num == num_temp++ ){
CERR( "" );
CERR( "- O(N^2)" );
CERR( "- O(N^2)Manacher" );
CERR( " https://snuke.hatenablog.com/entry/2014/12/02/235837" );
CERR( "" );
}
}
SLS( Solving )
{
CERR( "- 調" );
CERR( "- " );
CERR( "- " );
CERR( "" );
}
SLS( Query )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( QueryArray );
} else if( num == num_temp++ ){
CALL_SLS( QueryGraph );
}
}
SLS( QueryArray )
{
ASK_NUMBER(
"+使" ,
"使" ,
"*使" ,
"*使" ,
"(*,\\cdot)使" ,
"(+,\\cdot)使" ,
"max使"
);
if( num == num_temp++ ){
CERR( "- BIT" );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\BIT\\Template" );
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\SqrtDecomposition\\Template" );
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\Tree\\DifferenceSeqeuence" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "- BIT" );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\BIT\\IntervalMax\\Template" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "- BIT" );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\BIT\\Template\\Monoid" );
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\SqrtDecomposition\\Template\\Monoid" );
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\SegmentTree" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "- " );
CERR( " \\Mathematics\\Function\\Encoder" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\SqrtDecomposition\\Template\\Dual" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\AffineSpace\\SqrtDecomposition\\Template\\LazyEvaluation" );
CERR( "" );
} else if( num == num_temp++ ){
CERR( "max" );
CERR( "調max調" );
CERR( "" );
CERR( "" );
CERR( "maxmax調" );
CERR( "maxmax" );
CERR( "調" );
CERR( "調" );
CERR( "" );
CERR( "max{0,1}" );
CERR( "使" );
CERR( "" );
CERR( "" );
CERR( "" );
CERR( "B_qmax(A_i,B_q)" );
CERR( "- A'={(A_i,i)|i}O(N log N)" );
CERR( "- (B_q,q)_qB'O(Q log Q)" );
CERR( "- NC=(0,...,0)O(N)" );
CERR( "B'(B_q,q)" );
CERR( "A'A_i<B_qi" );
CERR( "- A'(A_i,i)O(N)" );
CERR( "- A_i0O(N log N)" );
CERR( "- C_i1O(log N)" );
CERR( "- A+C×B_qO(log N)" );
CERR( "O((N + Q)log N + Q log Q)" );
}
}
SLS( QueryGraph )
{
ASK_YES_NO( "" );
if( reply == "yes" ){
CERR( "- " );
CERR( " \\Mathematics\\SetTheory\\DirectProduct\\Tree\\DifferenceSeqeuence" );
} else {
CERR( "UnionFind" );
CERR( "\\Mathematics\\Geometry\\Graph\\DepthFirst\\Tree" );
CERR( "\\Utility\\VLTree" );
CERR( "\\Utility\\VLTree\\UnionFndForest" );
}
CERR( "" );
}
SLS( Decision )
{
ASK_NUMBER(
"0" ,
"" ,
"" ,
"" ,
""
);
if( num == num_temp++ ){
CALL_SLS( DecisionConnectedness );
} else if( num == num_temp++ ){
CALL_SLS( DecisionHigherConnectedness );
} else if( num == num_temp++ ){
CALL_SLS( DecisionGame );
} else if( num == num_temp++ ){
CALL_SLS( DecisionAccessibility );
} else if( num == num_temp++ ){
CALL_SLS( DecisionSatisfiability );
}
}
SLS( DecisionConnectedness )
{
CERR( "UnionFind" );
CERR( "\\Mathematics\\Geometry\\Graph\\BreadthFirst" );
CERR( "\\Utility\\VLTree\\UnionFindForest" );
CERR( "" );
CERR( "" );
}
SLS( DecisionHigherConnectedness )
{
CERR( "- " );
CERR( " \\Mathematics\\Geometry\\Graph\\DepthFirst" );
CERR( "- " );
CERR( "" );
}
SLS( DecisionGame )
{
CERR( "" );
CERR( "" );
}
SLS( DecisionAccessibility )
{
ASK_YES_NO( "" );
if( reply == "yes" ){
CERR( "" );
CERR( "- " );
CERR( "- " );
CERR( "" );
} else {
CERR( "" );
CALL_SLS( MinimisationMovingCost );
}
CERR( "" );
CALL_SLS( MinimisationMovingCost );
}
SLS( DecisionSatisfiability )
{
ASK_NUMBER(
"" ,
""
);
if( num == num_temp++ ){
CERR( "" );
CALL_SLS( DecisionConnectedness );
CERR( "" );
CERR( "" );
SLS( QueryArray );
} else if( num == num_temp++ ){
CERR( "" );
SLS( MaximisationBipartiteMatching );
}
}
SLS( Construction )
{
ASK_NUMBER(
"" ,
"" ,
"" ,
""
);
if( num == num_temp++ ){
CERR( "p" );
} else if( num == num_temp++ ){
CERR( "" );
CALL_SLS( DecisionAccessibility );
} else if( num == num_temp++ ){
CERR( "" );
CALL_SLS( DecisionGame );
} else if( num == num_temp++ ){
CERR( "" );
}
}
// Resetm_foundm_prev
// Shiftm_foundm_prev
// Breadth/DepthFirstConnectedComponentSearch
// Next()m_init
// O((m_init)+(m_initE))
#define DECLARATION_OF_FIRST_SEARCH( BREADTH ) \
template <int V_max> \
class BREADTH ## FirstSearch_Body \
{ \
\
protected: \
int m_V; \
int m_init; \
list<int> m_next; \
bool m_found[V_max]; \
int m_prev[V_max]; \
\
public: \
inline BREADTH ## FirstSearch_Body( const int& V ); \
inline BREADTH ## FirstSearch_Body( const int& V , const int& init ); \
\
inline void Reset( const int& init ); \
inline void Shift( const int& init ); \
\
inline const int& size() const; \
inline const int& init() const; \
inline bool& found( const int& i ); \
inline const int& prev( const int& i ) const; \
\
int Next(); \
\
private: \
virtual list<int> e( const int& t ) = 0; \
\
}; \
\
template <int V_max,list<int> E(const int&)> \
class BREADTH ## FirstSearch : \
public BREADTH ## FirstSearch_Body<V_max> \
{ \
\
public: \
\
template<typename... Args> inline BREADTH ## FirstSearch( const Args&... args ); \
\
private: \
inline list<int> e( const int& t ); \
\
}; \
\
template <int V_max,list<int> E(const int&)> void BREADTH ## FirstConnectedComponentSearch( const int& V , int ( &cc_numx )[V_max] , int& count );
      \
#define DEFINITION_OF_FIRST_SEARCH( BREADTH , PUSH ) \
template <int V_max> inline BREADTH ## FirstSearch_Body<V_max>::BREADTH ## FirstSearch_Body( const int& V ) : m_V( V ) , m_init() , m_next() ,
      m_found() , m_prev() { assert( m_V <= V_max ); for( int i = 0 ; i < m_V ; i++ ){ m_prev[i] = -1; } } \
template <int V_max> inline BREADTH ## FirstSearch_Body<V_max>::BREADTH ## FirstSearch_Body( const int& V , const int& init ) : BREADTH ##
      FirstSearch_Body( V ) { m_init = init; m_next.push_back( m_init ); m_found[m_init] = true; } \
template <int V_max,list<int> E(const int&)> template <typename... Args> inline BREADTH ## FirstSearch<V_max,E>::BREADTH ## FirstSearch( const
      Args&... args ) : BREADTH ## FirstSearch_Body<V_max>( args... ) {} \
\
template <int V_max> inline void BREADTH ## FirstSearch_Body<V_max>::Reset( const int& init ) { m_init = init; assert( m_init < m_V ); m_next
      .clear(); m_next.push_back( m_init ); for( int i = 0 ; i < m_V ; i++ ){ m_found[i] = i == m_init; m_prev[i] = -1; } } \
template <int V_max> inline void BREADTH ## FirstSearch_Body<V_max>::Shift( const int& init ) { m_init = init; assert( m_init < m_V ); m_next
      .clear(); if( ! m_found[m_init] ){ m_next.push_back( m_init ); m_found[m_init] = true; } } \
\
template <int V_max> inline const int& BREADTH ## FirstSearch_Body<V_max>::size() const { return m_V; } \
template <int V_max> inline const int& BREADTH ## FirstSearch_Body<V_max>::init() const { return m_init; } \
template <int V_max> inline bool& BREADTH ## FirstSearch_Body<V_max>::found( const int& i ) { assert( i < m_V ); return m_found[i]; } \
template <int V_max> inline const int& BREADTH ## FirstSearch_Body<V_max>::prev( const int& i ) const { assert( i < m_V ); return m_prev[i]; } \
\
template <int V_max> \
int BREADTH ## FirstSearch_Body<V_max>::Next() \
{ \
\
if( m_next.empty() ){ \
\
return -1; \
\
} \
\
const int i_curr = m_next.front(); \
m_next.pop_front(); \
list<int> edge = e( i_curr ); \
\
while( ! edge.empty() ){ \
\
const int& i = edge.front(); \
bool& found_i = found( i ); \
\
if( ! found_i ){ \
\
m_next.PUSH( i ); \
m_prev[i] = i_curr; \
found_i = true; \
\
} \
\
edge.pop_front(); \
\
} \
\
return i_curr; \
\
} \
\
template <int V_max,list<int> E(const int&)> inline list <int> BREADTH ## FirstSearch<V_max,E>::e( const int& t ) { return E( t ); } \
\
template <int V_max,list<int> E(const int&)> void BREADTH ## FirstConnectedComponentSearch( const int& V , int ( &cc_num )[V_max] , int& count ) \
{ \
\
BREADTH ## FirstSearch<V_max,E> bfs{ V }; \
count = 0; \
\
for( int i = 0 ; i < V ; i++ ){ \
\
cc_num[i] = -1; \
\
} \
\
for( int i = 0 ; i < V ; i++ ){ \
\
if( cc_num[i] == -1 ){ \
\
bfs.Shift( i ); \
int j = bfs.Next(); \
\
while( j != -1 ? cc_num[j] == -1 : false ){ \
\
cc_num[j] = count; \
j = bfs.Next(); \
\
} \
\
count++; \
\
} \
\
} \
\
return; \
\
} \
DECLARATION_OF_FIRST_SEARCH( Breadth );
DEFINITION_OF_FIRST_SEARCH( Breadth , push_back );
// inline CEXPR( int , bound_N , 10 );
inline DEXPR( int , bound_N , 100000 , 100 ); // 05
// inline CEXPR( int , bound_N , 1000000000 ); // 09
// inline CEXPR( ll , bound_N , 1000000000000000000 ); // 018
TYPE_OF( bound_N ) N;
// // inline CEXPR( TYPE_OF( bound_N ) , bound_M , bound_N );
// // inline CEXPR( int , bound_M , 10 );
// inline DEXPR( int , bound_M , 100000 , 100 ); // 05
// // inline CEXPR( int , bound_M , 1000000000 ); // 09
// // inline CEXPR( ll , bound_M , 1000000000000000000 ); // 018
// TYPE_OF( bound_M ) M;
// inline DEXPR( int , bound_H , 1000 , 10 );
// // inline DEXPR( int , bound_H , 100000 , 10 ); // 05
// // inline CEXPR( int , bound_H , 1000000000 ); // 09
// inline CEXPR( int , bound_W , bound_H );
// #if bound_H < ( 1 << 16 )
// inline CEXPR( int , bound_HW , bound_H * bound_W );
// #else
// inline CEXPR( ll , bound_HW , ll( bound_H ) * bound_W );
// #endif
// // CEXPR( int , bound_HW , 100000 ); // 05
// // CEXPR( int , bound_HW , 1000000000 ); // 05
// int H , W;
// inline int EnumHW( const int& h , const int& w ) { return h * W + w; }
// inline pair<int,int> EnumHW_inv( const int& v ) { return { v / W , v % W }; }
// 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(i,j);if(i>0){e[EnumHW(i-1,j)].push_back(v);}if(i+1<H){e[EnumHW(i+1,j)].push_back(v);}if(j>0){e[EnumHW(i,j-1)]
    .push_back(v);}if(j+1<W){e[EnumHW(i,j+1)].push_back(v);}}}}
// const string direction[4] = {"U","R","D","L"};
// 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);}
// inline int DirectionNumberOnGrid( const int& v , const int& w ){auto [i,j]=EnumHW_inv(v);auto [k,h]=EnumHW_inv(w);return DirectionNumberOnGrid(i
    ,j,k,h);}
// inline int ReverseDirectionNumberOnGrid( const int& n ){assert(0<=n&&n<4);return(n+2)%4;}
list<int> e[bound_N*2];
// list<int> e[bound_HW];
list<int> E( const int& i )
{
list<int> answer = e[i];
//
return answer;
}
// template <typename T> inline T add( 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 T multiply( const T& t0 , const T& t1 ) { return t0 * t1; }
// template <typename T> inline const T& one() { static const T o = 1; return o; }
// inline CEXPR( ll , P , 998244353 );
// inline CEXPR( ll , P , 1000000007 );
int main()
{
UNTIE;
LIBRARY_SEARCH;
START_MAIN;
// DEXPR( int , bound_T , 100000 , 100 );
// CIN_ASSERT( T , 1 , bound_T );
// REPEAT( T ){
// }
cin >> N;
N *= 2;
CIN( ll , M );
REPEAT( M ){
CIN( ll , A );
CIN( ll , B );
A--;
B--;
e[A].push_back(B);
e[B].push_back(A);
}
int colour[bound_N*2];
int cc;
BreadthFirstConnectedComponentSearch<bound_N*2,E>( N , colour , cc );
int num[bound_N*2] = {};
FOR( i , 0 , N ){
num[colour[i]]++;
}
int answer = 0;
FOR( i , 0 , cc ){
answer += num[i] % 2;
}
// SET_ASSERT( N , 1 , bound_N );
// SET_ASSERT( M , 1 , bound_M );
// SET_ASSERT( H , 1 , bound_H );
// SET_ASSERT( W , 1 , bound_W );
// TYPE_OF( bound_HW ) HW = TYPE_OF( bound_HW )( H ) * W;
// assert( HW <= bound_HW );
// // CEXPR( int , bound_Ai , 10 );
// // CEXPR( int , bound_Ai , 100000 ); // 05
// CEXPR( int , bound_Ai , 1000000000 ); // 09
// // CEXPR( ll , bound_Ai , 1000000000000000000 ); // 018
// // CEXPR( int , bound_Bi , bound_Ai );
// int A[bound_N];
// // ll A[bound_N];
// int B[bound_N];
// // ll B[bound_N];
// FOR( i , 0 , N ){
// CIN_ASSERT( Ai , 0 , bound_Ai );
// A[i] = Ai;
// CIN_ASSERT( Bi , 0 , bound_Bi );
// B[i] = Bi;
// }
// FOR( i , 0 , M ){
// CIN_ASSERT( ui , 1 , N );
// CIN_ASSERT( vi , 1 , N );
// ui--;
// vi--;
// e[ui].push_back( vi );
// e[vi].push_back( ui );
// }
// DEXPR( int , bound_Q , 100000 , 100 );
// CIN_ASSERT( Q , 1 , bound_Q );
// REPEAT( Q ){
// COUT( N );
// }
// ll guchoku = Guchoku();
// ll answer = 0;
// if( answer == guchoku ){
// CERR( answer << " == " << guchoku );
// } else {
// CERR( answer << " != " << guchoku );
// QUIT;
// }
COUT( ( answer / 2 ) );
FINISH_MAIN;
QUIT;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0