This page is still under construction.

Parts of this page are still being built. What you see may change.

Cruel Bingo

Time limit8sMemory limit512 MB

Summary
Given up to 8 pre-marked cells on an N by N bingo card, count the ways to reach exactly N unmarked cells while avoiding any full row, column, or diagonal, modulo 10007.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Bit manipulation, Implementation
Solved
No attempts yet

Problem

Bingo is a party game played by many players and one game master. Each player is given a bingo card containing N2 different numbers in an N × N grid (typically N = 5). The master draws numbers from a lottery one by one during the game. Each time a number is drawn, a player marks a square with that number if it exists. The player's goal is to have N marked squares in a single vertical, horizontal, or diagonal line and then call "Bingo!" The first player calling "Bingo!" wins the game.

In ultimately unfortunate cases, a card can have exactly N unmarked squares, or N(N-1) marked squares, but not a bingo pattern. Your task in this problem is to write a program counting how many such patterns are possible from a given initial pattern, which contains zero or more marked squares.

Input

The input is given in the following format:

N K
x1 y1
.
.
.
xK yK

The input begins with a line containing two numbers N (1 ≤ N ≤ 32) and K (0 ≤ K ≤ 8), which represent the size of the bingo card and the number of marked squares in the initial pattern respectively. Then K lines follow, each containing two numbers xi and yi to indicate the square at (xi, yi) is marked. The coordinate values are zero-based (i.e. 0 ≤ xi, yi ≤ N - 1). No pair of marked squares coincides.

Output

Count the number of possible non-bingo patterns with exactly N unmarked squares that can be made from the given initial pattern, and print the number in modulo 10007 in a line (since it is supposed to be huge). Rotated and mirrored patterns should be regarded as different and counted each.

Examples3

  1. Example 1

    Input
    4 2
    0 2
    3 1
    
    Expected output
    6
    
  2. Example 2

    Input
    4 2
    2 3
    3 2
    
    Expected output
    6
    
  3. Example 3

    Input
    10 3
    0 0
    4 4
    1 4
    
    Expected output
    1127