#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 #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; \ } \ } \ template inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); } template int Rank( bitset ( &A )[bound_L] , const int& L , const int& M ) { int i_min = 0; int i_curr; int j_curr = 0; while( i_min < L && j_curr < M ){ i_curr = i_min; while( A[i_curr][j_curr] == 0 && i_curr < L ){ i_curr++; } if( i_curr < L ){ swap( A[i_min] , A[i_curr] ); const bitset& A_i_min = A[i_min]; i_min++; while( ++i_curr < L ){ bitset& A_i_curr = A[i_curr]; if( A_i_curr[j_curr] == 1 ){ A_i_curr ^= A_i_min; } } } j_curr++; } return i_min; } int MAIN() { UNTIE; CEXPR( ll , bound_N , 1000000000000000000 ); CIN_ASSERT( N , 3 , bound_N ); N--; CEXPR( int , bound_M , 400 ); CIN_ASSERT( M , 3 , bound_M ); CEXPR( ll , bound_B , 1000000000 ); CIN_ASSERT( B , 2 , bound_B ); CEXPR( int , bound_Q , 1000 ); CIN_ASSERT( Q , 1 , bound_Q ); CEXPR( int , bound_V , bound_M * 2 ); int V = 0; map vertex{}; bitset d1[bound_M] = {}; FOR( m , 0 , M ){ bitset& d1m = d1[m]; CIN_ASSERT( i , 0 , N ); d1m[ vertex.count( i ) == 0 ? vertex[i] = V++ : vertex[i] ] = 1; CIN_ASSERT( j , i + 1 , N ); d1m[ vertex.count( j ) == 0 ? vertex[j] = V++ : vertex[j] ] = 1; } int M_minus = M - 1; bitset d2[bound_Q] = {}; FOR( q , 0 , Q ){ bitset& d2q = d2[q]; CIN_ASSERT( m0 , 0 , M_minus ); d2q[m0] = 1; CIN_ASSERT( m1 , m0 + 1 , M_minus ); d2q[m1] = 1; CIN_ASSERT( m2 , m1 + 1 , M_minus ); d2q[m2] = 1; assert( ( d1[m0] ^ d1[m1] ^ d1[m2] ) == 0 ); } int rank1 = Rank( d1 , M , V ); int rank2 = Rank( d2 , Q , M ); POWER_MOD( ker1 , 2 , M - rank1 , B ); POWER_MOD( im2 , 2 , rank2 , B ); cout << Residue( ker1 - im2 , B ) << " " << im2 << "\n"; QUIT; }