#include using namespace std; using ll = long long; #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ); // #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 ); int main() { constexpr const int bound = 100000; CIN_ASSERT( N , 1 , bound ); int count[bound + 1] = {}; int Ai; int lim_Ai = 0; FOREQ( i , 1 , N ){ cin >> Ai; ASSERT( Ai , 0 , bound ); if( lim_Ai < Ai ){ lim_Ai = Ai; } count[Ai]++; } CHECK_REDUNDANT_INPUT; bool found_3 = false; int count_a; lim_Ai++; FOREQ( a , 0 , lim_Ai ){ count_a = count[a]; if( count_a == 0 ){ RETURN( a ); } else if( count_a == 1 ){ if( found_3 ){ RETURN( a ); } FOREQ( b , a + 1 , lim_Ai ){ count_a = count[b]; if( count_a == 0 ){ if( b * 2 - 1 == N ){ RETURN( b - 1 ); } else { RETURN( b ); } } else if( count_a == 1 ){ RETURN( b ); } } } else if( count_a > 2 ){ found_3 = true; } } QUIT; }