CF317B.Ants

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction ( xx , yy ) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions ( x+1x+1 , yy ), ( x1x-1 , yy ), ( xx , y+1y+1 ), ( xx , y1y-1 ) — one ant in each direction. No other ant movements will happen. Ants never interfere with each other.

Scientists have put a colony of nn ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.

输入格式

First input line contains integers nn ( 0<=n<=300000<=n<=30000 ) and tt ( 1<=t<=500001<=t<=50000 ), where nn is the number of ants in the colony and tt is the number of queries. Each of the next tt lines contains coordinates of a query junction: integers xix_{i} , yiy_{i} ( 109<=xi,yi<=109-10^{9}<=x_{i},y_{i}<=10^{9} ). Queries may coincide.

It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).

输出格式

Print tt integers, one per line — the number of ants at the corresponding junctions when the movement of the ants stops.

输入输出样例

  • 输入#1

    1 3
    0 1
    0 0
    0 -1
    

    输出#1

    0
    1
    0
    
  • 输入#2

    6 5
    0 -2
    0 -1
    0 0
    0 1
    0 2
    

    输出#2

    0
    1
    2
    1
    0
    

说明/提示

In the first sample the colony consists of the one ant, so nothing happens at all.

In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.

首页