Under construction

Still being built. Things may change

Double Move

Time limit5sMemory limit512 MB

Summary
Given n stones and some already declared pairs of candidate stones, count the scenarios in which Alice and Bob each win when both play optimally.
Level

Hard9 of 10

Topics
Game theory, Combinatorics, Math
Solved
No attempts yet

Problem

Alice and Bob are playing a game, and Claire is helping them. There are stones, numbered from 11 to nn. The game consists of three phases.

In the first phase, Alice and Bob make alternating moves. Alice moves first. In each move, a player declares their intention to take a stone, but instead of naming the stone, they name two options. The two options may be the same. A player may also name stones that were already named in earlier moves. No stones are actually taken in this phase. The first phase ends when n+1n+1 declarations have been made.

In the second phase, Claire picks one of the two options in each of the n+1n+1 declarations by saying "first" or "second". Each sequence of n+1n+1 choices made by Claire is a scenario. There are exactly 2n+12^{n+1} scenarios. Even when the two options in a declaration are the same, choosing "first" and choosing "second" count as different scenarios.

In the third phase, Alice and Bob take stones according to Claire's choices. The first player who cannot make the required move, because the stone is already taken, loses the game. Since there are nn stones and n+1n+1 moves, one of the players must lose.

Alice and Bob know that Claire picks each of the 2n+12^{n+1} scenarios with equal probability. When playing optimally, each player tries to minimize the number of scenarios in which they lose.

You are given nn and the state of the game partway through the first phase: a sequence of kk declarations that have already been made. These declarations can be arbitrary. From this point on, Alice and Bob play optimally as described above. For each player, find the number of scenarios in which that player wins.

Input

The first line contains two space-separated integers nn and kk (1≤n≤351 \le n \le 35, 0≤k≤n+10 \le k \le n+1): the number of stones and the number of declarations already made.

Each of the next kk lines contains two space-separated integers, the numbers of the two stones in one declaration, in the order they were made. Both numbers are between 11 and nn, inclusive, and they need not be distinct.

When k<n+1k < n+1, the parity of kk determines which player makes the next declaration.

Output

Print one line with two space-separated integers: the number of scenarios in which Alice wins and the number of scenarios in which Bob wins, assuming both players play the rest of the game optimally. The sum of the two numbers must equal 2n+12^{n+1}.

Hint

The first sample matches the example in the statement. No declarations remain, so we only count Claire's choices that lead to an Alice win and to a Bob win. Alice wins if Claire picks stone 11 for her first move and stone 33 for her second move, and loses in all other cases.

In the second example, if Alice starts by declaring "1 1", Bob answers "2 2", and whatever Alice declares third, she loses. Claire can pick stone 11 for the first move and stone 22 for the second, leaving no stone for Alice's third move. This is not Alice's best opening. She should declare "1 2" instead. Then, no matter how Bob and Alice play afterward, each of them wins in 44 of the 88 scenarios.

Examples2

  1. Example 1

    Input
    3 4
    1 3
    2 2
    3 2
    1 3
    
    Expected output
    4 12
    
  2. Example 2

    Input
    2 0
    
    Expected output
    4 4