#pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include using namespace std; using ll = long long; #define MAIN main #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #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 FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n" #define RETURN( ANSWER ) COUT( ANSWER ); QUIT inline CEXPR( int , bound_d , 60 ); int g( ll n ) { static int memory[bound_d] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; int answer = -1; int& gn = n < 60 ? memory[n] : answer; if( gn >= 0 ){ return gn; } bool found[bound_d] = {}; int d = 0; while( n != 0 ){ if( ( n & 1 ) == 1 ){ found[ g( d ) ] = true; } d++; n >>= 1; } gn = 0; while( found[gn] ){ gn++; } return gn; } int MAIN() { UNTIE; CEXPR( int , bound_N , 100000 ); CIN_ASSERT( N , 1 , bound_N ); CEXPR( ll , bound_Ai , 1000000000000000000 ); bool even = true; int grundy = 0; REPEAT( N ){ CIN_ASSERT( Ai , -bound_Ai , bound_Ai ); if( Ai < 0 ){ even = !even; } else { grundy ^= g( Ai ); } } RETURN( ( even && grundy == 0 ) ? 2 : 1 ); }