This page is still under construction.

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

Brave Force Story

Interview

Time limit8sMemory limit512 MB

Summary
Count how many hexagonal cells a piece can reach in at most t turns on a grid with obstacles, given axial coordinates and a starting cell.
Level

Medium5 of 10

Topics
BFS, Graph, Implementation, Simulation
Solved
No attempts yet

Problem

"In Nine Island, the land at the farthest edge, lived those with special powers. Some could command fire, some ice, some wind, and some earth as they pleased. People called these sorcerers 'Brave Force.' It was the Sengoku period. The powerful, seeking to use Brave Force for their own greed, began hunting them. The battle over Brave Force is about to begin."

So goes the prologue of the strategy simulation game you are about to create. This prologue has nothing at all to do with this problem.

Back to the problem statement. In the world of strategy simulations, regular hexagonal cells are often used. Compared with square cells, the distance varies less with direction, and they tile the plane without gaps.

This time, consider moving a piece on such a map. The piece can be moved to an adjacent cell each turn. Of course, the map has many obstacles, and the piece cannot move into those cells. How many cells can the piece reach within a fixed number of turns?

Input

The input consists of one or more data sets, each describing a map.

The first line of a data set contains two integers: the first is the number of turns t, and the second is the number of obstacles n.

Each of the following n lines contains two integers giving the coordinates of an obstacle cell: the first is the x coordinate and the second is the y coordinate. The obstacle coordinates are all distinct.

The last line contains two integers giving the coordinates of the starting cell: the first is the x coordinate and the second is the y coordinate. This cell has no obstacle. This cell is also counted as reachable.

The coordinates assigned to cells are as shown in the figure below.

Figure B-1. Coordinates assigned to cells

The end of the input is marked by a line containing "0 0".

Every coordinate has an absolute value of at most 30. The number of turns is between 1 and 30 inclusive. The number of obstacles is between 0 and 300 inclusive.

Figure B-2. The first data set of the Sample Input

Output

For each map, print on its own line the number of cells that can be reached. Do not include any other extra characters in the output.

Examples1

  1. Example 1

    Input
    1 1
    1 0
    0 0
    2 2
    -2 1
    2 0
    2 2
    2 0
    -1 1
    4 4
    -2 1
    1 -2
    1 2
    3 -3
    -2 0
    4 6
    0 1
    1 1
    1 0
    -1 0
    -1 -1
    0 -1
    0 0
    0 0
    
    Expected output
    6
    18
    19
    58
    1