| solution
				 stringlengths 11 983k | difficulty
				 int64 0 21 | language
				 stringclasses 2
				values | 
|---|---|---|
| 
	#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  double k, b;
  friend double operator*(const point& A, const point& B) {
    return 1.0 * A.x * B.y - 1.0 * A.y * B.x;
  }
} a[100005];
int N;
double ans, S;
map<int, int> F;
void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d%d", &a[i].x, &a[i].y);
}
void work() {
  a[N + 1] = a[1], S = 0, F.clear();
  double area = 0;
  for (int i = 1; i <= N; i++) area += a[i] * a[i + 1];
  if (area < -1e-9)
    for (int i = 1; i + i <= N + 1; i++) swap(a[i], a[N + 2 - i]);
  int mi = 1e9, ma = -1e9, l, r, t = 0;
  auto inc = [&](int i) { return i < N ? i + 1 : 1; };
  auto dec = [&](int i) { return i > 1 ? i - 1 : N; };
  for (int i = 1; i <= N; i++) {
    if (a[i].x < mi) mi = a[i].x, l = i;
    if (a[i].x > ma) ma = a[i].x, r = i;
    if (a[i].x != a[i + 1].x)
      a[i].k = 1.0 * (a[i].y - a[i + 1].y) / (a[i].x - a[i + 1].x),
      a[i].b = a[i].y - a[i].k * a[i].x;
    else
      F[a[i].x] += abs(a[i].y - a[i + 1].y) + 1, a[i].k = 1e99;
  }
  for (int x = mi, i = l, j = l; x <= ma; x++) {
    for (; dec(i) != r && a[dec(i)].x <= x; i = dec(i))
      ;
    for (; inc(j) != r && a[inc(j)].x <= x; j = inc(j))
      ;
    if (a[dec(i)].k >= 1e99 || a[j].k >= 1e99) continue;
    F[x] = floor(a[dec(i)].k * x + a[dec(i)].b + 1e-9) -
           ceil(a[j].k * x + a[j].b - 1e-9) + 1;
  }
  double u = 0, v = 0, w = 0;
  for (auto i : F)
    w += v, v += 2 * u + i.second, u += i.second, ans += w * i.second,
        S += i.second;
}
void doit() {
  work();
  for (int i = 1; i <= N; i++) swap(a[i].x, a[i].y);
  work();
  printf("%.9lf\n", 1.0 * ans / S / (S - 1));
}
int main() {
  init();
  doit();
  return 0;
}
 | 10 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
struct TPoint {
  long long x, y;
  TPoint(int x = 0, int y = 0) : x(x), y(y) {}
};
TPoint p[100011];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long lfloor(long long a, long long b);
long long lceil(long long a, long long b) {
  if (a < 0) {
    return -lfloor(-a, b);
  }
  return (a + b - 1) / b;
}
long long lfloor(long long a, long long b) {
  if (a < 0) {
    return -lceil(-a, b);
  }
  return a / b;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%I64d%I64d", &p[i].x, &p[i].y);
  }
  p[N] = p[0];
  long long S = 0;
  for (int i = 0; i < N; ++i) {
    S += (p[i + 1].y + p[i].y) * (p[i + 1].x - p[i].x);
  }
  if (S > 0) {
    reverse(p, p + N);
    p[N] = p[0];
  }
  S = std::abs(S);
  long long bord = 0;
  for (int i = 0; i < N; ++i) {
    bord += gcd(abs(p[i + 1].x - p[i].x), abs(p[i + 1].y - p[i].y));
  }
  long long total = (S + bord + 2) / 2;
  vector<TPoint> low, high, left, right;
  int m = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i].x < p[m].x || (p[i].x == p[m].x && p[i].y < p[m].y)) {
      m = i;
    }
  }
  low.push_back(p[m]);
  for (int i = m + 1;; ++i) {
    i = (i + N) % N;
    if (p[i].x > p[(i + N - 1) % N].x) {
      low.push_back(p[i]);
    } else {
      break;
    }
  }
  m = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i].x < p[m].x || (p[i].x == p[m].x && p[i].y > p[m].y)) {
      m = i;
    }
  }
  high.push_back(p[m]);
  for (int i = m + N - 1;; --i) {
    i = (i + N) % N;
    if (p[i].x > p[(i + 1) % N].x) {
      high.push_back(p[i]);
    } else {
      break;
    }
  }
  m = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i].y < p[m].y || (p[i].y == p[m].y && p[i].x < p[m].x)) {
      m = i;
    }
  }
  left.push_back(p[m]);
  for (int i = m + N - 1;; --i) {
    i = (i + N) % N;
    if (p[i].y > p[(i + 1) % N].y) {
      left.push_back(p[i]);
    } else {
      break;
    }
  }
  m = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i].y < p[m].y || (p[i].y == p[m].y && p[i].x > p[m].x)) {
      m = i;
    }
  }
  right.push_back(p[m]);
  for (int i = m + 1;; ++i) {
    i = (i + N) % N;
    if (p[i].y > p[(i + N - 1) % N].y) {
      right.push_back(p[i]);
    } else {
      break;
    }
  }
  long double ex2 = 0.0, ex = 0.0;
  {
    int li = 0, hi = 0;
    for (int x = -1000001; x <= 1000001; ++x) {
      if (x < low[0].x) {
        continue;
      }
      if (x > low.back().x) {
        break;
      }
      int l = low[li].y + lceil((x - low[li].x) * (low[li + 1].y - low[li].y),
                                (low[li + 1].x - low[li].x));
      int r =
          high[hi].y + lfloor((x - high[hi].x) * (high[hi + 1].y - high[hi].y),
                              (high[hi + 1].x - high[hi].x));
      int p = (r - l + 1);
      ex2 += (long double)1.0 * p * x * x;
      ex += (long double)1.0 * p * x;
      if (x == low[li + 1].x) {
        ++li;
      }
      if (x == high[hi + 1].x) {
        ++hi;
      }
    }
  }
  long double ey2 = 0.0, ey = 0.0;
  {
    int li = 0, ri = 0;
    for (int y = -1000001; y <= 1000001; ++y) {
      if (y < left[0].y) {
        continue;
      }
      if (y > left.back().y) {
        break;
      }
      int l =
          left[li].x + lceil((y - left[li].y) * (left[li + 1].x - left[li].x),
                             (left[li + 1].y - left[li].y));
      int r = right[ri].x +
              lfloor((y - right[ri].y) * (right[ri + 1].x - right[ri].x),
                     (right[ri + 1].y - right[ri].y));
      int p = (r - l + 1);
      ey2 += (long double)1.0 * p * y * y;
      ey += (long double)1.0 * p * y;
      if (y == left[li + 1].y) {
        ++li;
      }
      if (y == right[ri + 1].y) {
        ++ri;
      }
    }
  }
  ex2 /= total;
  ex /= total;
  ey2 /= total;
  ey /= total;
  long double ans = ex2 - ex * ex + ey2 - ey * ey;
  ans *= 1.0 * total / (total - 1);
  printf("%.10lf", (double)ans);
  return 0;
}
 | 10 | 
	CPP | 
| 
	#include <bits/stdc++.h>
const int N = 100000 + 9;
int n, n2;
long double sum, ans;
struct point {
  int x, y;
  point(const int _x, const int _y) : x(_x), y(_y) {}
  point() {}
} p[N * 2];
inline long long cpr(const point &a, const point &b, const point &c) {
  return 1ll * (b.x - a.x) * (c.y - a.y) - 1ll * (c.x - a.x) * (b.y - a.y);
}
inline double sqr(const double x) { return x * x; }
void work1() {
  sum = 0;
  int l = 1, r = 1, Max = -99999999;
  for (int i = 1; i <= n2; ++i) {
    if (p[i].x < p[l].x) l = i;
    if (p[i].x <= p[r].x) r = i;
    Max = std::max(Max, p[i].x);
  }
  if (p[l].x == p[l + 1].x) ++l;
  if (p[r].x == p[r - 1].x) --r;
  for (int i = p[l].x; i <= Max; ++i) {
    if (p[l + 1].x < i) ++l;
    if (p[r - 1].x < i) --r;
    int bot = std::ceil((p[l + 1].y - p[l].y) * 1.0 / (p[l + 1].x - p[l].x) *
                            (i - p[l].x) +
                        p[l].y);
    int top = std::floor((p[r - 1].y - p[r].y) * 1.0 / (p[r - 1].x - p[r].x) *
                             (i - p[r].x) +
                         p[r].y);
    sum += (top - bot + 1);
  }
}
void work() {
  int l = 1, r = 1, Max = -99999999;
  for (int i = 1; i <= n2; ++i) {
    if (p[i].x < p[l].x) l = i;
    if (p[i].x <= p[r].x) r = i;
    Max = std::max(Max, p[i].x);
  }
  if (p[l].x == p[l + 1].x) ++l;
  if (p[r].x == p[r - 1].x) --r;
  long double sum1 = 0, sum2 = 0, sum3 = 0;
  for (int i = p[l].x; i <= Max; ++i) {
    if (p[l + 1].x < i) ++l;
    if (p[r - 1].x < i) --r;
    int bot = std::ceil((p[l + 1].y - p[l].y) * 1.0 / (p[l + 1].x - p[l].x) *
                            (i - p[l].x) +
                        p[l].y);
    int top = std::floor((p[r - 1].y - p[r].y) * 1.0 / (p[r - 1].x - p[r].x) *
                             (i - p[r].x) +
                         p[r].y);
    sum1 += sum2;
    sum2 += sum3 * 2 + (top - bot + 1);
    sum3 += (top - bot + 1);
    ans += (top - bot + 1) / (sum * (sum - 1)) * sum1;
  }
}
int main() {
  scanf("%d", &n);
  n2 = 2 * n;
  for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
  p[n + 1] = p[1];
  long long S = 0;
  for (int i = 1; i <= n; ++i) S += cpr(point(0, 0), p[i], p[i + 1]);
  if (S < 0) std::reverse(p + 1, p + 1 + n);
  for (int i = 1; i <= n; ++i) {
    p[i + n] = p[i];
  }
  work1();
  work();
  for (int i = 1; i <= n2; ++i) {
    std::swap(p[i].x, p[i].y);
    p[i].x = -p[i].x;
  }
  work();
  printf("%.8f\n", (double)(ans));
}
 | 10 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5, X = (int)2e6 + 100;
int n, x[N], y[N], cnt[X];
long double work() {
  long double area = 0;
  for (int i = 0; i < n; i++) area += x[i + 1] * y[i] - x[i] * y[i + 1];
  if (area < 0) {
    reverse(x, x + n);
    x[n] = x[0];
    reverse(y, y + n);
    y[n] = y[0];
  }
  long long tot = 0;
  long double ans1 = 0, ans2 = 0;
  for (int i = 0; i < X; i++) cnt[i] = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] < x[i + 1]) {
      for (int j = x[i]; j < x[i + 1]; j++)
        cnt[j] += floor(
            y[i] + 1. * (y[i + 1] - y[i]) / (x[i + 1] - x[i]) * (j - x[i]) +
            1e-8);
      if (x[i + 1] >= x[(i + 2) % n]) cnt[x[i + 1]] += y[i + 1];
    } else if (x[i] > x[i + 1]) {
      for (int j = x[i]; j > x[i + 1]; j--)
        cnt[j] -= floor(
            y[i] + 1. * (y[i + 1] - y[i]) / (x[i + 1] - x[i]) * (j - x[i]) -
            1e-8);
      if (x[i + 1] <= x[(i + 2) % n]) cnt[x[i + 1]] -= y[i + 1] - 1;
    }
  }
  for (int i = 0; i < X; i++) {
    tot += cnt[i];
    ans1 += 1. * i * cnt[i];
    ans2 += 1. * i * i * cnt[i];
  }
  return (ans2 * tot - 2 * ans1 * ans1 + ans2 * tot) / tot / (tot - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d%d", &x[i], &y[i]), x[i] += X / 2, y[i] += X / 2;
  x[n] = x[0];
  y[n] = y[0];
  long double ans = work();
  for (int i = 0; i <= n; i++) swap(x[i], y[i]);
  ans += work();
  printf("%.12lf\n", double(ans / 2));
}
 | 10 | 
	CPP | 
| 
	#include <bits/stdc++.h>
int n, minn = 1e9, maxx;
int x[200100], y[200100], s = 1, ss = 1;
double ans, sum, cnt[2000100], tot;
int main() {
  int i, j, h, t, p1, p2;
  double pp1, pp2;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", x + i, y + i);
    x[i] += 1000000;
    y[i] += 1000000;
    x[n + i] = x[i];
    y[n + i] = y[i];
    if (x[i] < x[s]) s = i;
    if (x[i] > x[ss]) ss = i;
  }
  minn = 1e9;
  maxx = 0;
  for (i = 1; i <= n; ++i)
    if (x[i] == x[s]) {
      if (y[i] < minn) minn = y[i];
      if (maxx < y[i]) maxx = y[i];
    }
  cnt[x[s]] = maxx - minn + 1;
  minn = 1e9;
  maxx = 0;
  for (i = 1; i <= n; ++i)
    if (x[i] == x[ss]) {
      if (y[i] < minn) minn = y[i];
      if (maxx < y[i]) maxx = y[i];
    }
  cnt[x[ss]] = maxx - minn + 1;
  h = s;
  t = s + n;
  for (i = x[s] + 1; i < x[ss]; ++i) {
    while (x[h + 1] < i) ++h;
    while (x[t - 1] < i) --t;
    pp1 = ((double)y[h + 1] - y[h]) * (i - x[h]) / (x[h + 1] - x[h]) + y[h];
    pp2 = ((double)y[t - 1] - y[t]) * (i - x[t]) / (x[t - 1] - x[t]) + y[t];
    p1 = pp1 + 1e-3;
    p2 = pp2 + 1e-3;
    if (pp1 < pp2) {
      if (((long long)y[h + 1] - y[h]) * (i - x[h]) % (x[h + 1] - x[h]) == 0)
        --p1;
      cnt[i] = p2 - p1;
    } else {
      if (((long long)y[t - 1] - y[t]) * (i - x[t]) % (x[t - 1] - x[t]) == 0)
        --p2;
      cnt[i] = p1 - p2;
    }
  }
  tot = sum = 0.0;
  for (i = x[s]; i <= x[ss]; ++i) {
    tot += cnt[i];
    sum += (double)cnt[i] * i;
  }
  for (i = x[s]; i <= x[ss]; ++i)
    ans += tot * 2 * cnt[i] * i * i - 2 * cnt[i] * i * sum;
  s = ss = 1;
  for (i = 1; i <= n; ++i) {
    if (y[i] < y[s]) s = i;
    if (y[i] > y[ss]) ss = i;
  }
  minn = 1e9;
  maxx = 0;
  for (i = 1; i <= n; ++i)
    if (y[i] == y[s]) {
      if (x[i] < minn) minn = x[i];
      if (maxx < x[i]) maxx = x[i];
    }
  cnt[y[s]] = maxx - minn + 1;
  minn = 1e9;
  maxx = 0;
  for (i = 1; i <= n; ++i)
    if (y[i] == y[ss]) {
      if (x[i] < minn) minn = x[i];
      if (maxx < x[i]) maxx = x[i];
    }
  cnt[y[ss]] = maxx - minn + 1;
  h = s;
  t = s + n;
  for (i = y[s] + 1; i < y[ss]; ++i) {
    while (y[h + 1] < i) ++h;
    while (y[t - 1] < i) --t;
    pp1 = ((double)x[h + 1] - x[h]) * (i - y[h]) / (y[h + 1] - y[h]) + x[h];
    pp2 = ((double)x[t - 1] - x[t]) * (i - y[t]) / (y[t - 1] - y[t]) + x[t];
    p1 = pp1 + 1e-3;
    p2 = pp2 + 1e-3;
    if (pp1 < pp2) {
      if (((long long)x[h + 1] - x[h]) * (i - y[h]) % (y[h + 1] - y[h]) == 0)
        --p1;
      cnt[i] = p2 - p1;
    } else {
      if (((long long)x[t - 1] - x[t]) * (i - y[t]) % (y[t - 1] - y[t]) == 0)
        --p2;
      cnt[i] = p1 - p2;
    }
  }
  tot = sum = 0.0;
  for (i = y[s]; i <= y[ss]; ++i) {
    tot += cnt[i];
    sum += (double)cnt[i] * i;
  }
  for (i = y[s]; i <= y[ss]; ++i)
    ans += tot * 2 * cnt[i] * i * i - 2 * cnt[i] * i * sum;
  printf("%.7lf\n", ans / tot / (tot - 1.0) / 2);
  return 0;
}
 | 10 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int N;
long double ans;
pair<int, int> Point[100005];
long double Number[2000005];
long double Partial[2000005], cnt = 0;
const int add = 1000000;
vector<long double> Ox[2000005];
void Read() {
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> Point[i].first >> Point[i].second;
}
void Coef(long double& A, long double& B, long double& C,
          pair<long double, long double> p1,
          pair<long double, long double> p2) {
  A = p1.second - p2.second;
  B = p2.first - p1.first;
  C = -A * p1.first - B * p1.second;
}
void precalcRange() {
  Point[N + 1] = Point[1];
  for (int i = 1; i <= N; i++) {
    int left = Point[i].first, right = Point[i + 1].first;
    if (left > right) swap(left, right);
    if (left == right) {
      Ox[left + add].push_back((long double)Point[i].second);
      Ox[left + add].push_back((long double)Point[i + 1].second);
      continue;
    }
    for (int j = left; j <= right; j++) {
      long double A, B, C;
      Coef(A, B, C, Point[i], Point[i + 1]);
      long double Y = (-C - A * j) / (B);
      Ox[j + add].push_back(Y);
    }
  }
  for (int x = -1000000; x <= 1000000; x++) {
    if (Ox[x + add].size() == 0) continue;
    long double Min = Ox[x + add][0], Max = Min;
    for (int i = 1; i < Ox[x + add].size(); i++) {
      Min = min(Min, Ox[x + add][i]);
      Max = max(Max, Ox[x + add][i]);
    }
    if (floor(Max) < ceil(Min)) continue;
    Number[x + add] = floor(Max) - ceil(Min) + 1;
  }
}
void Solve() {
  long double sum = Number[0], curr = Number[0], last = Number[0];
  Partial[0] = 2.0 * Number[0];
  cnt = 0;
  cnt += Number[0];
  for (int i = -1000000 + 1; i <= 1000000; i++) {
    cnt += Number[i + add];
    if (i == 0) {
      int d;
      d = 0;
    }
    Partial[i + add] = 2.0 * Number[i + add];
    ans += Number[i + add] * last;
    if (i + add > 0) Partial[i + add] += Partial[i + add - 1];
    sum += Partial[i + add] - Number[i + add];
    last += sum;
  }
}
int main() {
  Read();
  precalcRange();
  Solve();
  for (int i = 1; i <= N; i++) swap(Point[i].first, Point[i].second);
  for (int i = 0; i <= add * 2; i++) {
    Partial[i] = Number[i] = 0.0;
    Ox[i].clear();
  }
  precalcRange();
  Solve();
  cout << fixed << setprecision(15) << ans / ((cnt) * (cnt - 1));
  return 0;
}
 | 10 | 
	CPP | 
| 
	from sys import *
f = lambda: map(int, stdin.readline().split())
n, t = f()
m = 65
r = range(m)
p = [[0] * m for i in r]
p[1][0] = n // 4
p[0][0] = n % 4
q = k = 1
while q:
    k += 1
    q = 0
    for x in r[1:k]:
        for y in r[:x + 1]:
            if p[x][y] < 4: continue
            q = 1
            d = p[x][y] // 4
            p[x][y] %= 4
            p[x + 1][y] += d
            if x > y:
                if x > y + 1:
                    p[x][y + 1] += d
                    p[x - 1][y] += d
                else:
                    p[x][x] += 2 * d
                    if y: p[y][y] += 2 * d
                    else: p[x][y] += d
            if y: p[x][y - 1] += d if y > 1 else 2 * d
s = []
for j in range(t):
    x, y = f()
    x, y = abs(x), abs(y)
    if x < y: x, y = y, x
    s.append(p[x][y] if x < m else 0)
stdout.write('\n'.join(map(str, s))) | 8 | 
	PYTHON3 | 
| 
	#include <bits/stdc++.h>
int n, t;
int q[50000][5];
int sh[2500][2500];
bool vis[2500][2500];
void bfs() {
  int i = 0, j = 1;
  sh[1000][1000] = n;
  q[0][0] = 1000;
  q[0][1] = 1000;
  while (i < j) {
    int x = q[i % 40000][0], y = q[i % 40000][1];
    sh[x + 1][y] += sh[x][y] / 4;
    sh[x - 1][y] += sh[x][y] / 4;
    sh[x][y + 1] += sh[x][y] / 4;
    sh[x][y - 1] += sh[x][y] / 4;
    sh[x][y] %= 4;
    vis[x][y] = 0;
    if (vis[x + 1][y] == 0 && sh[x + 1][y] >= 4)
      q[j % 40000][0] = x + 1, q[j % 40000][1] = y, j++, vis[x + 1][y] = 1;
    if (vis[x - 1][y] == 0 && sh[x - 1][y] >= 4)
      q[j % 40000][0] = x - 1, q[j % 40000][1] = y, j++, vis[x - 1][y] = 1;
    if (vis[x][y + 1] == 0 && sh[x][y + 1] >= 4)
      q[j % 40000][0] = x, q[j % 40000][1] = y + 1, j++, vis[x][y + 1] = 1;
    if (vis[x][y - 1] == 0 && sh[x][y - 1] >= 4)
      q[j % 40000][0] = x, q[j % 40000][1] = y - 1, j++, vis[x][y - 1] = 1;
    i++;
  }
}
int main() {
  scanf("%d %d", &n, &t);
  bfs();
  for (int i = 0; i < t; i++) {
    int h, g;
    scanf("%d %d", &h, &g);
    h += 1000;
    g += 1000;
    if (h < 0 || h > 2000 || g < 0 || g > 2000)
      printf("0\n");
    else
      printf("%d\n", sh[h][g]);
  }
  getchar();
  getchar();
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int n, m, a[205 << 1][205 << 1];
queue<pair<int, int> > q;
int main() {
  cin >> n >> m;
  a[205][205] = n;
  if (n >> 2) q.push(make_pair(205, 205));
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x = p.first + dx[i];
      int y = p.second + dy[i];
      a[x][y] += a[p.first][p.second] >> 2;
      if ((a[x][y] >> 2) && !((a[x][y] - (a[p.first][p.second] >> 2)) >> 2))
        q.push(make_pair(x, y));
    }
    a[p.first][p.second] %= 4;
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (x < -205 || x >= 205 || y < -205 || y >= 205)
      cout << 0 << "\n";
    else
      cout << a[x + 205][y + 205] << "\n";
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int MAX = 200, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int ans[MAX * 2 + 1][MAX * 2 + 1];
int main() {
  int n, t, x, y;
  scanf("%d%d", &n, &t);
  queue<int> Q;
  Q.push(MAX), Q.push(MAX);
  ans[MAX][MAX] = n;
  while (!Q.empty()) {
    x = Q.front(), Q.pop();
    y = Q.front(), Q.pop();
    if (ans[x][y] >= 4) {
      for (int i = 0; i < 4; ++i) {
        int tx = x + dx[i], ty = y + dy[i];
        ans[tx][ty] += ans[x][y] / 4;
        if (ans[tx][ty] > 3) Q.push(tx), Q.push(ty);
      }
      ans[x][y] %= 4;
    }
  }
  while (t--) {
    scanf("%d%d", &x, &y);
    if (abs(x) > MAX || abs(y) > MAX)
      puts("0");
    else {
      printf("%d\n", ans[x + MAX][y + MAX]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
long long a[205][205];
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, -1, 1};
queue<pair<long long, long long> > q;
int main() {
  long long n, t;
  cin >> n >> t;
  a[100][100] = n;
  if (n >= 4) q.push(make_pair(100, 100));
  while (!q.empty()) {
    long long x = q.front().first;
    long long y = q.front().second;
    q.pop();
    if (a[x][y] < 4) continue;
    long long add = a[x][y] / 4;
    a[x][y] %= 4;
    for (long long i = 0; i < 4; i++) {
      long long nx = x + dx[i];
      long long ny = y + dy[i];
      long long temp = a[nx][ny];
      a[nx][ny] += add;
      if (temp < 4 && a[nx][ny] >= 4) {
        q.push(make_pair(nx, ny));
      }
    }
  }
  while (t--) {
    long long x, y;
    scanf("%lld", &x);
    scanf("%lld", &y);
    if (x < -100 || x > 100 || y < -100 || y > 100) {
      cout << "0\n";
    } else
      cout << a[100 + x][100 + y] << "\n";
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
__inline bool nextInt(int &val) {
  char ch;
  int sgn = 1;
  while ((ch = getchar()) != EOF) {
    if (ch == '-') sgn = -1;
    if (ch >= '0' && ch <= '9') break;
  }
  if (ch == EOF) return false;
  val = (int)(ch - '0');
  while (true) {
    ch = getchar();
    if (ch >= '0' && ch <= '9') {
      val = 10 * val + (int)(ch - '0');
    } else
      break;
  }
  val *= sgn;
  return true;
}
__inline bool nextString(string &s) {
  char ch;
  while ((ch = getchar()) != EOF) {
    if (ch >= 33 && ch <= 126) break;
  }
  if (ch == EOF) return false;
  s = string(1, ch);
  while (true) {
    ch = getchar();
    if (ch >= 33 && ch <= 126) {
      s = s + string(1, ch);
    } else
      break;
  }
  return true;
}
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int n, q, x[55888], y[55888], t[2 * 80][2 * 80][2];
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d", &n, &q);
  for (int iq = 0; iq < (q); iq++) scanf("%d%d", x + iq, y + iq);
  memset(t, 0, sizeof(t));
  ;
  int cur = 0, ncur;
  t[80][80][cur] = n;
  bool ok = true;
  int step = 0;
  while (ok) {
    step++;
    ncur = 1 - cur;
    for (int ix = 0; ix < (2 * 80); ix++)
      for (int iy = 0; iy < (2 * 80); iy++) t[ix][iy][ncur] = 0;
    for (int ix = (-80); ix < (80); ix++)
      for (int iy = (-80); iy < (80); iy++) {
        if (t[ix + 80][iy + 80][cur] >= 4) {
          int add = t[ix + 80][iy + 80][cur] / 4;
          t[ix + 80][iy + 80][ncur] += t[ix + 80][iy + 80][cur] % 4;
          for (int way = 0; way < (4); way++) {
            int nx = ix + dx[way], ny = iy + dy[way];
            t[nx + 80][ny + 80][ncur] += add;
          }
        } else {
          t[ix + 80][iy + 80][ncur] += t[ix + 80][iy + 80][cur];
        }
      }
    ok = false;
    for (int ix = 0; ix < 2 * 80 && !ok; ix++)
      for (int iy = 0; iy < 2 * 80 && !ok; iy++)
        ok = t[ix][iy][ncur] != t[ix][iy][cur];
    cur = ncur;
  }
  for (int iq = 0; iq < (q); iq++) {
    if (((x[iq]) > 0 ? (x[iq]) : -(x[iq])) >= 80 ||
        ((y[iq]) > 0 ? (y[iq]) : -(y[iq])) >= 80)
      printf("0\n");
    else
      printf("%d\n", t[80 + x[iq]][80 + y[iq]][cur]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int cnt[1005][1005];
int Ox = 505, Oy = 505;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
queue<pair<int, int> > Q;
bool inq[1005][1005];
inline void init(int n) {
  cnt[Ox][Oy] = n;
  Q.push(make_pair(Ox, Oy));
  pair<int, int> u;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    inq[u.first][u.second] = 0;
    for (int d = 0; d < 4; ++d) {
      int x = u.first + dx[d], y = u.second + dy[d];
      cnt[x][y] += cnt[u.first][u.second] / 4;
      if (cnt[x][y] >= 4) {
        if (!inq[x][y]) {
          inq[x][y] = 1;
          Q.push(make_pair(x, y));
        }
      }
    }
    cnt[u.first][u.second] %= 4;
  }
}
inline bool in(int x, int y) {
  return 0 <= x && x < 1000 && 0 <= y && y < 1000;
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  init(n);
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += Ox;
    y += Oy;
    if (in(x, y))
      printf("%d\n", cnt[x][y]);
    else
      puts("0");
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mp;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int maxn = 100 + 100 + 10;
int a[maxn][maxn], t;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> a[100][100] >> t;
  bool flag = true;
  while (flag) {
    flag = false;
    for (int i = 1; i <= 200; i++)
      for (int j = 1; j <= 200; j++) {
        if (a[i][j] >= 4) {
          flag = true;
          int x = a[i][j] / 4;
          a[i + 1][j] += x;
          a[i][j + 1] += x;
          a[i - 1][j] += x;
          a[i][j - 1] += x;
          a[i][j] -= x * 4;
        }
      }
  }
  for (int i = 1; i <= t; i++) {
    int x, y;
    cin >> x >> y;
    if (x > -100 && x < 100 && y > -100 && y < 100)
      cout << a[100 + x][100 + y] << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int arr[700][700];
void solve(int x, int y) {
  if (arr[x][y] < 3)
    arr[x][y]++;
  else {
    arr[x][y] = 0;
    solve(x + 1, y);
    solve(x - 1, y);
    solve(x, y + 1);
    solve(x, y - 1);
  }
}
int main() {
  int n, t, x, y;
  cin >> n >> t;
  for (int i = 0; i < n; i++) solve(300, 300);
  for (int i = 0; i < t; i++) {
    cin >> x >> y;
    if (x < (-200) || x > 200 || y < (-200) || y > 200)
      cout << 0 << endl;
    else
      cout << arr[x + 300][y + 300] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4096;
const int off = 145;
int n, q, A[MAXN][MAXN];
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
int main() {
  while (scanf("%d %d", &n, &q) >= 1) {
    A[off][off] = n;
    bool ok = false;
    while (!ok) {
      ok = true;
      for (int i = (-off); i < (int)(off + 1); i++) {
        for (int j = (-off); j < (int)(off + 1); j++) {
          if (A[off + i][off + j] >= 4) {
            for (int k = (0); k < (int)(4); k++) {
              int p = i + dr[k];
              int q = j + dc[k];
              A[off + p][off + q] += A[off + i][off + j] / 4;
            }
            A[off + i][off + j] %= 4;
            ok = false;
          }
        }
      }
    }
    for (int i = (0); i < (int)(q); i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      if (abs(a) > off) {
        printf("0\n");
        continue;
      }
      if (abs(b) > off) {
        printf("0\n");
        continue;
      }
      printf("%d\n", A[off + a][off + b]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
int ans[4002][4002];
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
void dfs(int x, int y) {
  int t = ans[x][y] / 4;
  ans[x][y] %= 4;
  for (int i = 0; i < 4; i++) ans[x + dx[i]][y + dy[i]] += t;
  for (int i = 0; i < 4; i++)
    if (ans[x + dx[i]][y + dy[i]] >= 4) dfs(x + dx[i], y + dy[i]);
}
int main() {
  int n, q;
  cin >> n >> q;
  ans[2000][2000] = n;
  dfs(2000, 2000);
  for (int p = 0; p < q; p++) {
    int a, b;
    cin >> a >> b;
    if (abs(a) > 2000 || abs(b) > 2000)
      cout << 0 << "\n";
    else
      cout << ans[a + 2000][b + 2000] << "\n";
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int T[3000][3000], f, c, nf, nc, n, m;
long long x, y;
queue<pair<int, int> > Q;
const int mf[] = {0, 0, 1, -1}, mc[] = {-1, 1, 0, 0};
void bfs() {
  Q.push(pair<int, int>(1000, 1000));
  while (!Q.empty()) {
    f = Q.front().first;
    c = Q.front().second;
    Q.pop();
    if (T[f][c] >= 4)
      for (int i = 0; i < 4; i++) {
        nf = mf[i] + f;
        nc = mc[i] + c;
        T[nf][nc] += T[f][c] / 4;
        Q.push(pair<int, int>(nf, nc));
      }
    T[f][c] %= 4;
  }
}
int main() {
  scanf("%d %d\n", &n, &m);
  T[0 + 1000][0 + 1000] = n;
  bfs();
  for (int i = 1; i <= m; i++) {
    scanf("%I64d %I64d", &x, &y);
    if (x > -1000 && x < 1000 && y < 1000 && y > -1000)
      printf("%d\n", T[x + 1000][y + 1000]);
    else
      printf("0\n");
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int tab[300][300];
int res[300][300];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int in(int i, int j) { return (i >= 0 && i < 300 && j >= 0 && j < 300); }
int main() {
  int n, t, r, f, x, y;
  cin >> n >> t;
  r = 0;
  tab[70][70] = n;
  do {
    f = 0;
    for (int i = 0; i <= 140; i++) {
      for (int j = 0; j <= 140; j++) {
        tab[i][j] += res[i][j];
        res[i][j] = 0;
        if (tab[i][j] > 3) {
          for (int k = 0; k < 4; k++)
            if (in(i + dx[k], j + dy[k]))
              res[i + dx[k]][j + dy[k]] += tab[i][j] / 4;
          f = 1;
        }
        tab[i][j] = tab[i][j] % 4;
      }
    }
  } while (f == 1);
  for (int i = 0; i < t; i++) {
    cin >> x >> y;
    x += 70;
    y += 70;
    if (x > 140 || x < 0 || y > 140 || y < 0)
      cout << 0 << endl;
    else
      cout << tab[x][y] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
static const int MAXSZ = 70;
static const int MAXSZ_VALID = 67;
int g[MAXSZ][MAXSZ] = {{0}};
inline bool step() {
  static int h[MAXSZ][MAXSZ];
  memset(h, 0, sizeof h);
  for (int i = 0; i < MAXSZ - 1; ++i)
    for (int j = 0; j < MAXSZ - 1; ++j) {
      if (j) h[i][j - 1] += g[i][j] / 4;
      h[i][j + 1] += g[i][j] / 4;
      if (i) h[i - 1][j] += g[i][j] / 4;
      h[i + 1][j] += g[i][j] / 4;
    }
  for (int i = 0; i < MAXSZ; ++i) h[0][i] += g[1][i] / 4;
  for (int i = 0; i < MAXSZ; ++i) h[i][0] += g[i][1] / 4;
  for (int i = 0; i < MAXSZ; ++i)
    for (int j = 0; j < MAXSZ; ++j) h[i][j] += g[i][j] % 4;
  if (memcmp(g, h, sizeof h) == 0) return false;
  memcpy(g, h, sizeof h);
  return true;
}
int n, t;
int main() {
  scanf("%d%d", &n, &t);
  g[0][0] = n;
  while (step())
    ;
  int x, y;
  for (int i = 0; i < t; ++i) {
    scanf("%d%d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x >= MAXSZ_VALID || y >= MAXSZ_VALID)
      puts("0");
    else
      printf("%d\n", g[x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int neigh[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int a[200][200];
int main() {
  int i, j, k, m, n, tmp, x, y;
  memset(a, 0, sizeof(a));
  vector<pair<int, int> > q;
  scanf("%d%d", &n, &m);
  q.clear();
  q.push_back(make_pair(100, 100));
  a[100][100] = n;
  for (i = 0; i < q.size(); i++) {
    tmp = a[q[i].first][q[i].second] / 4;
    a[q[i].first][q[i].second] %= 4;
    for (j = 0; j < 4; j++) {
      x = q[i].first + neigh[j][0];
      y = q[i].second + neigh[j][1];
      a[x][y] += tmp;
      if ((a[x][y] - tmp < 4) && (a[x][y] >= 4)) q.push_back(make_pair(x, y));
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    if ((abs(x) >= 100) || (abs(y) >= 100))
      printf("0\n");
    else
      printf("%d\n", a[x + 100][y + 100]);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int arr[200][200];
void solve(int x, int y) {
  if (arr[x][y] < 3)
    arr[x][y]++;
  else {
    arr[x][y] = 0;
    solve(x + 1, y);
    solve(x - 1, y);
    solve(x, y + 1);
    solve(x, y - 1);
  }
}
int main() {
  int n, t, x, y;
  cin >> n >> t;
  for (int i = 0; i < n; i++) solve(80, 80);
  for (int i = 0; i < t; i++) {
    cin >> x >> y;
    if (x < (-80) || x > 80 || y < (-80) || y > 80)
      cout << 0 << endl;
    else
      cout << arr[x + 80][y + 80] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
const int N = 65;
int t, x, y, a[N + N][N + N];
int main() {
  scanf("%d%d", &a[N][N], &t);
  bool flag = 1;
  while (flag) {
    flag = 0;
    for (x = 1; x < N + N; x++)
      for (y = 1; y < N + N; y++)
        if (a[x][y] >= 4) {
          flag = 1;
          a[x + 1][y] += a[x][y] / 4;
          a[x - 1][y] += a[x][y] / 4;
          a[x][y + 1] += a[x][y] / 4;
          a[x][y - 1] += a[x][y] / 4;
          a[x][y] %= 4;
        }
  }
  while (t--) {
    scanf("%d%d", &x, &y);
    printf("%d\n", abs(x) < N && abs(y) < N ? a[N + x][N + y] : 0);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int _G[299][299];
bool _inQueue[299][299];
queue<pair<int, int> > q;
int main(void) {
  int n = 0;
  int t = 0;
  scanf("%d %d", &n, &t);
  _G[(0) + (144)][(0) + (144)] = n;
  _inQueue[(0) + (144)][(0) + (144)] = true;
  q.push(pair<int, int>(0, 0));
  while (!q.empty()) {
    pair<int, int> tx = q.front();
    q.pop();
    int x = tx.first;
    int y = tx.second;
    _inQueue[(x) + (144)][(y) + (144)] = false;
    int addIt = _G[(x) + (144)][(y) + (144)] / 4;
    _G[(x) + (144)][(y) + (144)] %= 4;
    _G[(x - 1) + (144)][(y) + (144)] += addIt;
    _G[(x) + (144)][(y - 1) + (144)] += addIt;
    _G[(x + 1) + (144)][(y) + (144)] += addIt;
    _G[(x) + (144)][(y + 1) + (144)] += addIt;
    if (_G[(x - 1) + (144)][(y) + (144)] >= 4 &&
        !_inQueue[(x - 1) + (144)][(y) + (144)]) {
      _inQueue[(x - 1) + (144)][(y) + (144)] = true;
      q.push(pair<int, int>(x - 1, y));
    }
    if (_G[(x) + (144)][(y - 1) + (144)] >= 4 &&
        !_inQueue[(x) + (144)][(y - 1) + (144)]) {
      _inQueue[(x) + (144)][(y - 1) + (144)] = true;
      q.push(pair<int, int>(x, y - 1));
    }
    if (_G[(x + 1) + (144)][(y) + (144)] >= 4 &&
        !_inQueue[(x + 1) + (144)][(y) + (144)]) {
      _inQueue[(x + 1) + (144)][(y) + (144)] = true;
      q.push(pair<int, int>(x + 1, y));
    }
    if (_G[(x) + (144)][(y + 1) + (144)] >= 4 &&
        !_inQueue[(x) + (144)][(y + 1) + (144)]) {
      _inQueue[(x) + (144)][(y + 1) + (144)] = true;
      q.push(pair<int, int>(x, y + 1));
    }
  }
  while (t--) {
    int x = 0;
    int y = 0;
    scanf("%d %d", &x, &y);
    if (x < -144 || x > 144 || y < -144 || y > 144)
      puts("0");
    else
      printf("%d\n", _G[(x) + (144)][(y) + (144)]);
  }
  while (getchar() != EOF)
    ;
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int b[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
int a[405][405], c[405][405];
int n, t, last;
void solve() {
  a[200][200] = n;
  int step = 0;
  while (1) {
    bool diff = 0;
    memset(c, 0, sizeof c);
    for (int i = 200 - step; i <= 200 + step; i++)
      for (int j = 200 - step; j <= 200 + step; j++) {
        if (a[i][j] < 4) continue;
        diff = 1;
        int u = a[i][j] / 4;
        a[i][j] %= 4;
        for (int x = 0; x < 4; x++) {
          int _i = i + b[x][0], _j = j + b[x][1];
          c[_i][_j] += u;
        }
      }
    step = min(step + 1, 64);
    for (int i = 200 - step; i <= 200 + step; i++)
      for (int j = 200 - step; j <= 200 + step; j++) {
        a[i][j] += c[i][j];
      }
    if (!diff) break;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> t;
  solve();
  while (t--) {
    int x, y;
    cin >> x >> y;
    x += 200;
    y += 200;
    if (x < 0 || y < 0 || x > 400 || y > 400)
      cout << "0\n";
    else {
      int k = a[x][y];
      cout << k << '\n';
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int a[1010][1010], n, x, y, t;
void work(int x, int y) {
  if (a[x][y] < 3) {
    a[x][y]++;
  } else {
    a[x][y] = 0;
    work(x + 1, y);
    work(x - 1, y);
    work(x, y + 1);
    work(x, y - 1);
  }
}
int main() {
  scanf("%d %d", &n, &t);
  for (int i = 1; i <= n; i++) {
    work(500, 500);
  }
  while (t--) {
    scanf("%d %d", &x, &y);
    if (x > 100 || y > 100 || x < -100 || y < -100) {
      printf("0\n");
    } else {
      printf("%d\n", a[x + 500][y + 500]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, arr[200][200] = {0}, u, v;
  bool done = false;
  cin >> n >> q;
  arr[99][99] = n;
  while (!done) {
    done = true;
    for (int x = 0; x < 200; ++x) {
      for (int y = 0; y < 200; ++y) {
        if (arr[x][y] >= 4) {
          done = false;
          if (x + 1 < 200) arr[x + 1][y] += arr[x][y] / 4;
          if (x - 1 >= 0) arr[x - 1][y] += arr[x][y] / 4;
          if (y + 1 < 200) arr[x][y + 1] += arr[x][y] / 4;
          if (y - 1 >= 0) arr[x][y - 1] += arr[x][y] / 4;
          arr[x][y] %= 4;
        }
      }
    }
  }
  while (q--) {
    cin >> u >> v;
    if (u + 99 >= 200 || u + 99 < 0 || v + 99 >= 200 || v + 99 < 0)
      cout << 0 << endl;
    else
      cout << arr[u + 99][v + 99] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int v[200 + 10][200 + 10];
bool f[200 + 10][200 + 10];
queue<pair<int, int> > q;
pair<int, int> tmp[10000];
int sz;
int main() {
  int n, t;
  cin >> n >> t;
  int bs = 100;
  for (int i = 0; i <= 200; ++i)
    for (int j = 0; j <= 200; ++j) f[i][j] = false, v[i][j] = 0;
  v[bs][bs] = n;
  if (n >= 4) {
    f[bs][bs] = true;
    q.push(make_pair(bs, bs));
  }
  while (true) {
    if (q.empty()) break;
    int i, j;
    sz = 0;
    while (!q.empty()) {
      i = q.front().first;
      j = q.front().second;
      q.pop();
      f[i][j] = false;
      v[i][j] -= 4;
      ++v[i + 1][j];
      ++v[i - 1][j];
      ++v[i][j - 1];
      ++v[i][j + 1];
      tmp[sz++] = make_pair(i, j);
    }
    for (int t = 0; t < sz; ++t) {
      i = tmp[t].first;
      j = tmp[t].second;
      if (v[i][j] >= 4 && !f[i][j]) {
        f[i][j] = true;
        q.push(make_pair(i, j));
      }
      if (v[i + 1][j] >= 4 && !f[i + 1][j]) {
        f[i + 1][j] = true;
        q.push(make_pair(i + 1, j));
      }
      if (v[i - 1][j] >= 4 && !f[i - 1][j]) {
        f[i - 1][j] = true;
        q.push(make_pair(i - 1, j));
      }
      if (v[i][j - 1] >= 4 && !f[i][j - 1]) {
        f[i][j - 1] = true;
        q.push(make_pair(i, j - 1));
      }
      if (v[i][j + 1] >= 4 && !f[i][j + 1]) {
        f[i][j + 1] = true;
        q.push(make_pair(i, j + 1));
      }
    }
  }
  for (int i = 0; i < t; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (abs(x) > 65 || abs(y) > 65) {
      printf("0");
    } else {
      printf("%d", v[bs - y][bs + x]);
    }
    printf("\n");
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  const int N = 200, M = 100;
  vector<vector<int> > a(N), b(N);
  for (int i = 0; i < N; i++) a[i].resize(N), b[i].resize(N);
  a[M][M] = n;
  while (1) {
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) b[i][j] = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) {
        if (a[i][j] >= 4) {
          cnt++;
          b[i][j] += a[i][j] & 3;
          b[i][j + 1] += a[i][j] >> 2;
          b[i][j - 1] += a[i][j] >> 2;
          b[i + 1][j] += a[i][j] >> 2;
          b[i - 1][j] += a[i][j] >> 2;
        } else
          b[i][j] += a[i][j];
      }
    a = b;
    if (cnt == 0) break;
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    x += M, y += M;
    if (x < 0 || x >= N || y < 0 || y >= N) {
      puts("0");
      continue;
    }
    printf("%d\n", a[x][y]);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}
const int of = 80;
int c[of * 2 + 1][of * 2 + 1];
bool f[of * 2 + 1][of * 2 + 1];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  c[of][of] = n;
  vector<int> v1, v2;
  if (n > 3) {
    v1.push_back(of << 16 | of);
  }
  int mx = 0;
  bool flag = true;
  while (flag) {
    flag = false;
    v2.clear();
    for (int i = 0; i < v1.size(); ++i) {
      int y = v1[i] >> 16 & 0xffff;
      int x = v1[i] & 0xffff;
      if (c[y][x] < 4) {
        continue;
      }
      int k = c[y][x] >> 2;
      c[y][x] -= k * 4;
      flag = true;
      for (int j = 0; j < 4; ++j) {
        int ny = y + dy[j], nx = x + dx[j];
        c[ny][nx] += k;
        mx = max(mx, nx);
        if (c[ny][nx] > 3 && !f[ny][nx]) {
          f[ny][nx] = true;
          v2.push_back(ny << 16 | nx);
        }
      }
    }
    v1.swap(v2);
    memset(f, 0, sizeof f);
  }
  int qy, qx;
  for (int i = 0; i < t; ++i) {
    scanf("%d%d", &qx, &qy);
    int res = 0;
    if (abs(qx) < of - 1 && abs(qy) < of - 1) {
      res = c[qx + of][qy + of];
    }
    printf("%d\n", res);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
bool workingLocal = false;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-9;
template <class T>
void chmin(T &t, T f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
  if (t < f) t = f;
}
inline int getint() {
  int a;
  return scanf("%d", &a) ? a : (fprintf(stderr, "trying to read\n"), -1);
}
inline double getdouble() {
  double a;
  return scanf("%lf", &a) ? a : (fprintf(stderr, "trying to read\n"), -1.0);
}
const int N = 100;
int a[2 * N + 1][2 * N + 1];
int done() {
  for (int i = (int)0; i < (int)2 * N + 1; ++i)
    for (int j = (int)0; j < (int)2 * N + 1; ++j)
      if (a[i][j] >= 4) return false;
  return true;
}
void myCode() {
  int n = getint();
  a[N][N] = n;
  while (!done()) {
    for (int i = (int)0; i < (int)2 * N + 1; ++i)
      for (int j = (int)0; j < (int)2 * N + 1; ++j)
        if (a[i][j] >= 4) {
          if (i > 0) a[i - 1][j] += a[i][j] / 4;
          if (j > 0) a[i][j - 1] += a[i][j] / 4;
          if (i < 2 * N) a[i + 1][j] += a[i][j] / 4;
          if (j < 2 * N) a[i][j + 1] += a[i][j] / 4;
          a[i][j] %= 4;
        }
  }
  int t = getint();
  while (t--) {
    int first = abs(getint()), second = abs(getint());
    if (first >= N || second >= N)
      printf("0\n");
    else
      printf("%d\n", a[first + N][second + N]);
  }
}
int main() {
  srand(time(NULL));
  myCode();
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int n, t, f[140][140];
void dq(int x, int y) {
  if (f[x][y] < 4) return;
  int k = f[x][y] / 4;
  f[x][y] %= 4;
  f[x + 1][y] += k;
  dq(x + 1, y);
  f[x - 1][y] += k;
  dq(x - 1, y);
  f[x][y + 1] += k;
  dq(x, y + 1);
  f[x][y - 1] += k;
  dq(x, y - 1);
}
int main() {
  cin >> f[70][70] >> t;
  dq(70, 70);
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (x < -70 || x >= 70 || y < -70 || y >= 70)
      cout << 0 << endl;
    else
      cout << f[x + 70][y + 70] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
void CI(int &_x) { scanf("%d", &_x); }
void CO(int &_x) { cout << _x; }
template <typename T>
void getarray(T a[], int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void printarray(T a[], int n) {
  for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dr4[4] = {0, 0, 1, -1};
int dc4[4] = {-1, 1, 0, 0};
int kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
int a = 1000;
int n, t;
int dis[3000][3000];
void bfs() {
  queue<pair<int, int> > Q;
  Q.push(make_pair(0, 0));
  dis[a + 0][a + 0] += n;
  while (!Q.empty()) {
    pair<int, int> top = Q.front();
    Q.pop();
    int per = dis[top.first + a][a + top.second] / 4;
    dis[top.first + a][top.second + a] %= 4;
    if (per == 0) continue;
    for (int i = 0; i < 4; i++) {
      int x = top.first + dr4[i];
      int y = top.second + dc4[i];
      dis[x + a][a + y] += per;
      Q.push(make_pair(x, y));
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> t;
  bfs();
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (abs(x) > a || abs(y) > a) {
      cout << 0 << "\n";
    } else {
      cout << dis[a + x][y + a] << "\n";
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
template <class T>
bool read(T &x) {
  char *s;
  s = (char *)malloc(10);
  if (sizeof(x) == 1)
    strcpy(s + 1, " %c");
  else if (sizeof(x) == 4)
    strcpy(s + 1, "%d");
  else if (sizeof(x) == 8)
    strcpy(s + 1, "%lld");
  int k = scanf(s + 1, &x);
  free(s);
  return k != -1;
}
using namespace std;
int a[400][400], b[400][400];
int main() {
  int i, j, t, x, y, ok = 1;
  cin >> a[89][89] >> t;
  while (ok) {
    ok = 0;
    memset(b, 0, sizeof b);
    for (int i = 1; i <= 180; i++)
      for (int j = 1; j <= 180; j++) {
        if (a[i][j] < 4) continue;
        b[i][j] -= a[i][j] / 4 * 4;
        b[i + 1][j] += a[i][j] / 4;
        b[i - 1][j] += a[i][j] / 4;
        b[i][j + 1] += a[i][j] / 4;
        b[i][j - 1] += a[i][j] / 4;
        ok = 1;
      }
    for (int i = 0; i <= 180; i++)
      for (int j = 0; j <= 180; j++) a[i][j] += b[i][j];
  }
  while (t--) {
    cin >> x >> y;
    if (abs(x) > 87 or abs(y) > 87)
      cout << 0 << endl;
    else
      cout << a[x + 89][y + 89] << endl;
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
long long a[1000][1000];
inline void add(long long x, long long y) {
  if (a[x][y] < 3)
    a[x][y]++;
  else if (a[x][y] == 3) {
    a[x][y] = 0;
    add(x + 1, y);
    add(x, y + 1);
    add(x - 1, y);
    add(x, y - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) add(500, 500);
  long long t;
  cin >> t;
  long long x, y;
  for (long long i = 0; i < t; i++) {
    cin >> x >> y;
    x = abs(x);
    y = abs(y);
    x += 500;
    y += 500;
    if (x > 1000 || y > 1000)
      cout << "0" << endl;
    else
      cout << a[x][y] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
short a[10005][10005] = {{0}};
int n, t, x, y;
const int fx[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
inline int ok(int x, int y) {
  if (x < 0 || y < 0 || x >= 10005 || y >= 10005) return 0;
  return 1;
}
void Do(int x, int y) {
  int tmp = a[x][y] / 4;
  a[x][y] %= 4;
  for (int i = 0; i < 4; ++i) {
    int xx = x + fx[i][0], yy = y + fx[i][1];
    if (!ok(xx, yy)) continue;
    a[xx][yy] += tmp;
    if (i == 2 && yy == 0) a[xx][yy] += tmp;
    if (i == 3 && xx == 0) a[xx][yy] += tmp;
    if (a[xx][yy] >= 4) Do(xx, yy);
  }
}
inline void init() {
  if (n < 4) return;
  Do(0, 0);
}
int main(int argc, char **argv) {
  scanf("%d%d", &n, &t);
  a[0][0] = n;
  init();
  while (t--) {
    scanf("%d%d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x >= 10005 || y >= 10005)
      puts("0");
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << '\n';
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << '\n';
}
const long long A = 500;
const long long N = 1500;
long long t[N][N];
void oblivious() {
  long long n, k;
  cin >> n >> k;
  long long sz = 0;
  t[A][A] = n;
  while (true) {
    bool ok = false;
    for (long long i = A - sz; i <= A + sz; i++) {
      for (long long j = A - sz; j <= A + sz; j++) {
        if (t[i][j] >= 4) {
          if (max(abs(i - A), abs(j - A)) == sz) {
            sz++;
          }
          ok = true;
          t[i - 1][j] += t[i][j] / 4;
          t[i + 1][j] += t[i][j] / 4;
          t[i][j - 1] += t[i][j] / 4;
          t[i][j + 1] += t[i][j] / 4;
          t[i][j] %= 4;
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    if (max(abs(x), abs(y)) > sz) {
      cout << 0 << '\n';
    } else {
      cout << t[A + x][A + y] << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    oblivious();
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int a[500][500];
int main() {
  int n, t;
  while (scanf("%d%d", &n, &t) == 2) {
    memset(a, 0, sizeof(a));
    a[200][200] = n;
    int sz = 0;
    while (1) {
      bool flag = true;
      for (int i = 200 - sz; i <= 200 + sz; i++)
        for (int j = 200 - sz; j <= 200 + sz; j++)
          if (a[i][j] >= 4) {
            flag = false;
            if (max(abs(i - 200), abs(j - 200)) == sz) sz++;
            a[i - 1][j] += a[i][j] / 4;
            a[i + 1][j] += a[i][j] / 4;
            a[i][j - 1] += a[i][j] / 4;
            a[i][j + 1] += a[i][j] / 4;
            a[i][j] %= 4;
          }
      if (flag) break;
    }
    int x, y;
    while (t--) {
      scanf("%d%d", &x, &y);
      if (x < -200 || y < -200 || x > 200 || y > 200)
        printf("0\n");
      else
        printf("%d\n", a[x + 200][y + 200]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  while (cin >> n >> m) {
    int cont[505][505] = {};
    queue<pair<int, int> > q;
    cont[250][250] = n;
    if (n >= 4) q.push({250, 250});
    while (!q.empty()) {
      int x = q.front().first;
      int y = q.front().second;
      q.pop();
      int num = cont[x][y];
      int div = num / 4;
      cont[x][y] %= 4;
      if (cont[x][y + 1] + div >= 4 && cont[x][y + 1] < 4) {
        q.push({x, y + 1});
      }
      cont[x][y + 1] += div;
      if (cont[x][y - 1] + div >= 4 && cont[x][y - 1] < 4) {
        q.push({x, y - 1});
      }
      cont[x][y - 1] += div;
      if (cont[x + 1][y] + div >= 4 && cont[x + 1][y] < 4) {
        q.push({x + 1, y});
      }
      cont[x + 1][y] += div;
      if (cont[x - 1][y] + div >= 4 && cont[x - 1][y] < 4) {
        q.push({x - 1, y});
      }
      cont[x - 1][y] += div;
    }
    while (m--) {
      int add1, add2;
      cin >> add1 >> add2;
      if (abs(add1) > 250 || abs(add2) > 250) {
        cout << 0 << '\n';
      } else
        cout << cont[add1 + 250][add2 + 250] << '\n';
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
const int MAXM = MAXN * 2 + 1;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int n, t, graph[MAXM][MAXM], t_graph[MAXM][MAXM];
int main() {
  scanf("%d%d", &n, &t);
  graph[MAXN][MAXN] = n;
  bool found = n > 0;
  while (found) {
    found = false;
    memset(t_graph, 0, sizeof(t_graph));
    for (int i = 0; i < MAXM; i++) {
      for (int j = 0; j < MAXM; j++) {
        if (graph[i][j] >= 4) {
          found = true;
          for (int k = 0; k < 4; k++) {
            int nx = i + dx[k], ny = j + dy[k];
            t_graph[nx][ny] += graph[i][j] / 4;
          }
        }
        t_graph[i][j] += graph[i][j] % 4;
      }
    }
    memcpy(graph, t_graph, sizeof(graph));
  }
  for (int i = 0; i < t; i++) {
    int x, y, ans;
    scanf("%d%d", &x, &y);
    if (abs(x) > MAXN || abs(y) > MAXN) {
      ans = 0;
    } else {
      ans = graph[x + MAXN][y + MAXN];
    }
    printf("%d\n", ans);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int cnt[2 * 300][2 * 300];
bool visited[2 * 300][2 * 300];
int cx[] = {0, 0, 1, -1}, cy[] = {-1, 1, 0, 0};
int main() {
  int N, T;
  cin >> N >> T;
  cnt[300][300] = N;
  queue<pair<int, int> > Q;
  Q.push(pair<int, int>(300, 300));
  visited[300][300] = true;
  while (!Q.empty()) {
    pair<int, int> front = Q.front();
    Q.pop();
    int num = cnt[front.first][front.second];
    if (num >= 4) {
      int delta = cnt[front.first][front.second] / 4;
      cnt[front.first][front.second] %= 4;
      for (int i = 0; i < 4; i++) {
        int ii = front.first + cx[i];
        int jj = front.second + cy[i];
        cnt[ii][jj] += delta;
        if (!visited[ii][jj] && cnt[ii][jj] >= 4) {
          visited[ii][jj] = true;
          Q.push(pair<int, int>(ii, jj));
        }
      }
    }
    visited[front.first][front.second] = false;
  }
  int x, y;
  for (int i = 0; i < T; i++) {
    scanf("%d %d", &x, &y);
    x += 300;
    y += 300;
    if (x < 0 || y < 0 || x >= 2 * 300 || y >= 2 * 300)
      printf("0\n");
    else
      printf("%d\n", cnt[x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int n;
int C[2][2][1005 * 1005], save[1005][1005], q[2], sol[1005][1005],
    last_upd[1005][1005];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
inline void expand(int coada[2][1005 * 1005], int timp, int p) {
  for (int i = 1; i <= q[p]; ++i) {
    int xc = coada[0][i], yc = coada[1][i];
    save[xc][yc] = sol[xc][yc];
  }
  q[1 - p] = 0;
  for (int i = 1; i <= q[p]; ++i) {
    int xc = coada[0][i], yc = coada[1][i], xv, yv;
    for (int d = 0; d < 4; ++d) {
      xv = xc + dx[d];
      yv = yc + dy[d];
      sol[xv][yv] += (save[xc][yc] >> 2);
      if (sol[xv][yv] >= 4 && last_upd[xv][yv] != timp) {
        last_upd[xv][yv] = timp;
        ++q[1 - p];
        C[1 - p][0][q[1 - p]] = xv, C[1 - p][1][q[1 - p]] = yv;
      }
    }
    sol[xc][yc] -= save[xc][yc];
    sol[xc][yc] += (save[xc][yc] & 3);
    if (sol[xc][yc] >= 4 && last_upd[xc][yc] != timp) {
      last_upd[xc][yc] = timp;
      ++q[1 - p];
      C[1 - p][0][q[1 - p]] = xc, C[1 - p][1][q[1 - p]] = yc;
    }
  }
}
int main() {
  scanf("%d", &n);
  int xc = 500, yc = 500;
  ++q[0];
  C[0][0][1] = xc;
  C[0][1][1] = yc;
  sol[xc][yc] = n;
  int p = 0, timp = 0;
  while (q[p]) {
    expand(C[p], ++timp, p);
    p = 1 - p;
  }
  int tests, x, y;
  scanf("%d", &tests);
  for (int i = 1; i <= tests; ++i) {
    scanf("%d %d", &x, &y);
    if (x > xc || x < -xc || y > yc || y < -yc) {
      printf("%d\n", 0);
    } else {
      printf("%d\n", sol[xc + x][yc + y]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int BX = 128, BY = 128;
int table[BX * 2][BY * 2];
pair<int, int> stk[BX * BY];
int main() {
  int N, T;
  scanf("%d%d", &N, &T);
  int len = 0;
  stk[len++] = pair<int, int>(BX, BY);
  table[BX][BY] = N;
  int total = 0;
  while (len--) {
    pair<int, int> p = stk[len];
    int m = table[p.first][p.second] / 4;
    table[p.first][p.second] %= 4;
    for (int d = 0; d < 4; d++) {
      int dx = p.first + "1210"[d] - '1';
      int dy = p.second + "2101"[d] - '1';
      if (table[dx][dy] < 4 && table[dx][dy] + m >= 4)
        stk[len++] = pair<int, int>(dx, dy);
      table[dx][dy] += m;
    }
  }
  while (T--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += BX;
    y += BY;
    if (0 <= x && x < BX * 2 && 0 <= y && y <= BY * 2)
      printf("%d\n", table[x][y]);
    else
      puts("0");
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3000 + 10, mod = 1000000007;
int a[MAX_N][MAX_N], n, t;
void make(int x, int y) {
  a[x - 1][y] += a[x][y] / 4;
  a[x][y - 1] += a[x][y] / 4;
  a[x + 1][y] += a[x][y] / 4;
  a[x][y + 1] += a[x][y] / 4;
  a[x][y] %= 4;
  if (a[x - 1][y] >= 4) make(x - 1, y);
  if (a[x][y - 1] >= 4) make(x, y - 1);
  if (a[x + 1][y] >= 4) make(x + 1, y);
  if (a[x][y + 1] >= 4) make(x, y + 1);
}
int32_t main() {
  cin >> n >> t;
  a[1500][1500] = n;
  make(1500, 1500);
  int x, y;
  while (t--) {
    cin >> x >> y;
    x += 1500, y += 1500;
    if (x >= 3000 || y >= 3000 || x < 0 || y < 0)
      cout << "0" << '\n';
    else
      cout << a[x][y] << '\n';
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j, k, n, a[300][300];
  scanf("%d %d ", &n, &t);
  for (i = 0; i < 300; i++)
    for (j = 0; j < 300; j++) a[i][j] = 0;
  a[150][150] = n;
  queue<int> x;
  queue<int> y;
  x.push(150);
  y.push(150);
  while (!x.empty()) {
    if (a[x.front()][y.front()] >= 4) {
      a[x.front() + 1][y.front()] += (a[x.front()][y.front()] / 4);
      x.push(x.front() + 1);
      y.push(y.front());
      a[x.front()][y.front() + 1] += (a[x.front()][y.front()] / 4);
      x.push(x.front());
      y.push(y.front() + 1);
      a[x.front() - 1][y.front()] += (a[x.front()][y.front()] / 4);
      x.push(x.front() - 1);
      y.push(y.front());
      a[x.front()][y.front() - 1] += (a[x.front()][y.front()] / 4);
      x.push(x.front());
      y.push(y.front() - 1);
      a[x.front()][y.front()] = a[x.front()][y.front()] % 4;
    }
    x.pop();
    y.pop();
  }
  while (t--) {
    scanf("%d %d", &i, &j);
    if (abs(i) > 299 || abs(j) > 299)
      printf("0\n");
    else
      printf("%d\n", a[i + 150][j + 150]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int n, T;
int Place(int x, int y) { return (x + 1000) * 1005 + y + 1000; }
int ans[10000000];
int q[30000005];
int main() {
  scanf("%d%d", &n, &T);
  int l = 0, r = 1;
  int st = Place(0, 0);
  q[l] = st;
  ans[st] = n;
  while (l != r) {
    int tmp = q[l];
    l++;
    int t2;
    int d = ans[tmp];
    ans[tmp] = d % 4;
    d /= 4;
    bool f;
    t2 = tmp - 1005;
    f = (ans[t2] < 4);
    ans[t2] += d;
    if (f && ans[t2] >= 4) {
      q[r] = t2;
      r++;
    }
    t2 = tmp + 1005;
    f = (ans[t2] < 4);
    ans[t2] += d;
    if (f && ans[t2] >= 4) {
      q[r] = t2;
      r++;
    }
    t2 = tmp - 1;
    f = (ans[t2] < 4);
    ans[t2] += d;
    if (f && ans[t2] >= 4) {
      q[r] = t2;
      r++;
    }
    t2 = tmp + 1;
    f = (ans[t2] < 4);
    ans[t2] += d;
    if (f && ans[t2] >= 4) {
      q[r] = t2;
      r++;
    }
  }
  while (T--) {
    int x, y;
    scanf("%d%d", &x, &y);
    int tmp;
    if (x > 10000 || y > 10000 || x < -10000 || y < -10000)
      tmp = -1;
    else
      tmp = Place(x, y);
    if (tmp < 0 || tmp >= 10000000) tmp = 0;
    printf("%d\n", ans[tmp]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int xx[] = {-1, 0, 1, 0};
int yy[] = {0, 1, 0, -1};
int ans[2 * 1005][2 * 1005];
void DFS(int x, int y) {
  int Val = ans[x][y] / 4;
  ans[x][y] = ans[x][y] % 4;
  if (Val == 0) return;
  for (int i = 0; i <= 3; i++) {
    int u = x + xx[i];
    int v = y + yy[i];
    ans[u][v] += Val;
    DFS(u, v);
  }
}
int main() {
  int n, m, u, v;
  cin >> n >> m;
  ans[1005][1005] = n;
  DFS(1005, 1005);
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    if (abs(u) >= 1005 || abs(v) >= 1005)
      cout << 0 << endl;
    else
      cout << ans[u + 1005][v + 1005] << endl;
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int dx[] = {+0, +0, +1, -1};
int dy[] = {+1, -1, +0, +0};
int vis[N][N];
int n;
void dfs(int x, int y, int n) {
  vis[x][y] += n;
  if (vis[x][y] <= 3) return;
  vis[x][y] -= 4;
  if (vis[x][y] >= 4) dfs(x, y, 0);
  for (int i = 0; i < 4; i++) {
    int a = x + dx[i];
    int b = y + dy[i];
    dfs(a, b, 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  dfs(100, 100, n);
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (x <= -200 || x >= 200 || y <= -200 || y >= 200)
      cout << "0\n";
    else
      cout << vis[x + 100][y + 100] << "\n";
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int m;
int n;
short col[2][2048][2048];
char was[2048][2048];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cm;
pair<int, int> v[1000000];
int main() {
  int mx = 1024, my = 1024;
  int t;
  cin >> n >> t;
  v[cm++] = make_pair(mx, my);
  col[0][mx][my] = n;
  was[mx][my] = 1;
  int ct = 0;
  while (1) {
    int o = cm;
    int ff = 0;
    for (int i = 0; i < (o); i++) {
      int cx = v[i].first;
      int cy = v[i].second;
      col[1 ^ ct][cx][cy] = 0;
    }
    for (int i = 0; i < (o); i++) {
      int cx = v[i].first;
      int cy = v[i].second;
      int o = col[ct][cx][cy];
      int f = o >= 4;
      if (f) {
        o -= 4;
        ff += f;
        for (int j = 0; j < (4); j++) {
          int nx = cx + dx[j];
          int ny = cy + dy[j];
          if (nx < mx || ny < my) continue;
          if (!was[nx][ny]) {
            v[cm++] = make_pair(nx, ny);
            was[nx][ny] = 1;
          }
          if (nx == mx && cx > mx || ny == my && cy > my)
            col[ct ^ 1][nx][ny] += 2;
          else
            col[ct ^ 1][nx][ny]++;
        }
      }
      col[1 ^ ct][cx][cy] += o;
    }
    ct ^= 1;
    if (!ff) break;
  }
  for (int i = 0; i < (t); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = abs(x);
    y = abs(y);
    if (abs(x) >= 1024 || abs(y) >= 1024) {
      cout << 0 << '\n';
    } else
      cout << col[ct][x + 1024][y + 1024] << '\n';
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void checkmin(T &a, T b) {
  if (a > b) a = b;
}
const int N = 129;
const int M = 64;
int a[N][N], b[N][N];
void solve() {
  int n, t;
  scanf("%d%d", &n, &t);
  a[M][M] = n;
  int maxi = 0, x, y;
  while (1) {
    int f = 0;
    x = M - maxi;
    y = M + maxi;
    for (int i = x; i <= y; i++)
      for (int j = x; j <= y; j++) b[i][j] = a[i][j];
    for (int i = x; i <= y; i++)
      for (int j = x; j <= y; j++) {
        if (a[i][j] >= 4) {
          b[i][j] -= 4;
          b[i + 1][j] += 1;
          b[i - 1][j] += 1;
          b[i][j + 1] += 1;
          b[i][j - 1] += 1;
          f = 1;
          maxi = max(maxi, i + 1 - M);
        }
      }
    x = M - maxi;
    y = M + maxi;
    for (int i = x; i <= y; i++)
      for (int j = x; j <= y; j++) a[i][j] = b[i][j];
    if (f == 0) break;
  }
  for (int i = 0; i < (t); i++) {
    scanf("%d %d", &x, &y);
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x > 64 || y > 64)
      printf("0\n");
    else
      printf("%d\n", a[M + x][M + y]);
  }
}
int main() {
  solve();
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void PLAY1() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int res[1005][1005];
int main() {
  PLAY1();
  int n, t;
  cin >> n >> t;
  queue<pair<int, int>> qu;
  qu.push({0, 0});
  res[300][300] = n;
  while ((int)qu.size()) {
    int curx = qu.front().first;
    int cury = qu.front().second;
    qu.pop();
    if (res[curx + 300][cury + 300] < 4) continue;
    for (int k = 0; k < 4; k++) {
      int tox = dx[k] + curx;
      int toy = dy[k] + cury;
      res[tox + 300][toy + 300] += res[curx + 300][cury + 300] / 4;
      if (res[tox + 300][toy + 300] >= 4) qu.push({tox, toy});
    }
    res[curx + 300][cury + 300] %= 4;
  }
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (abs(x) >= 300 || abs(y) >= 300)
      cout << 0 << endl;
    else
      cout << res[x + 300][y + 300] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, 1, -1, 0};
const int of = 100;
int g[233][233];
int inq[233][233];
void dfs(int tx, int ty) {
  if (g[tx][ty] < 3) {
    g[tx][ty]++;
    return;
  }
  g[tx][ty] = 0;
  for (int i = 0; i < 4; i++) {
    int nx = tx + dx[i];
    int ny = ty + dy[i];
    dfs(nx, ny);
  }
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  while (n--) dfs(of, of);
  for (int i = 0; i < t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += of;
    y += of;
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    int ans = 0;
    if (max(x, y) >= 233)
      ans = 0;
    else
      ans = g[x][y];
    printf("%d\n", ans);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
const int MAXN = 131;
const int ox = 65;
const int oy = 65;
int a[MAXN][MAXN], b[MAXN][MAXN];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
void init() {
  int i, j, k;
  memset(b, 0, sizeof(b));
  int p = MAXN - 1;
  bool ok = false;
  for (i = 1; i <= p; i++)
    for (j = 1; j <= p; j++)
      if (a[i][j] > 3) {
        for (k = 0; k < 4; k++) b[i + dx[k]][j + dy[k]] += a[i][j] / 4;
        b[i][j] -= a[i][j] / 4 * 4;
      }
  for (i = 1; i <= p; i++)
    for (j = 1; j <= p; j++) {
      a[i][j] += b[i][j];
      if (a[i][j] > 3) ok = true;
    }
  if (ok) init();
}
int main() {
  int n, x, y, T;
  scanf("%d%d", &n, &T);
  a[ox][oy] = n;
  init();
  while (T--) {
    scanf("%d%d", &x, &y);
    x += ox;
    y += oy;
    if (x >= MAXN || y >= MAXN || x < 0 || y < 0)
      puts("0");
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e6 + 9;
const int Maxv = 3015;
pair<int, int> Que[Maxn * 10];
int bg, ed;
bool arr_mark[Maxv][Maxv];
int arr_num[Maxv][Maxv];
inline int num(pair<int, int> p) {
  int x = p.first, y = p.second;
  if (abs(x) >= Maxv / 2 - 1 || abs(y) >= Maxv / 2 - 1) return 0;
  return arr_num[x + Maxv / 2][y + Maxv / 2];
}
inline void ins(const int &x, const int &y) {
  if (!arr_mark[x + Maxv / 2][y + Maxv / 2] && num(make_pair(x, y)) >= 4) {
    arr_mark[x + Maxv / 2][y + Maxv / 2] = 1;
    Que[ed++] = make_pair(x, y);
    ed %= Maxn;
  }
}
int main() {
  int n;
  cin >> n;
  arr_num[Maxv / 2][Maxv / 2] = n;
  ins(0, 0);
  while (bg != ed) {
    int x = Que[bg].first, y = Que[bg++].second;
    bg %= Maxn;
    int cnt = arr_num[x + Maxv / 2][y + Maxv / 2] / 4;
    arr_num[x + Maxv / 2][y + Maxv / 2] %= 4;
    arr_mark[x + Maxv / 2][y + Maxv / 2] = 0;
    for (int r = -1; r < 2; r++) {
      for (int l = -1; l < 2; l++) {
        if (abs(r + l) == 1) {
          int nx = r + x, ny = l + y;
          arr_num[nx + Maxv / 2][ny + Maxv / 2] += cnt;
          ins(nx, ny);
        }
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", num(make_pair(x, y)));
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int x[] = {0, 0, 1, -1};
const int y[] = {1, -1, 0, 0};
short int q[10000000];
int sQ = 0;
short int p[10000000];
int sP = 0;
short int mp[300][300] = {0};
int main() {
  int n, t;
  cin >> n >> t;
  mp[150][150] = n;
  q[0] = 150;
  sQ = 1;
  p[0] = 150;
  sP = 1;
  while (1) {
    bool f = true;
    for (int v = 150 - 68; v < 150 + 68; ++v)
      for (int u = 150 - 68; u < 150 + 68; ++u) {
        short int qanak = mp[u][v] / 4;
        if (qanak > 0) {
          f = false;
          for (int i = 0; i < 4; ++i) {
            mp[u + x[i]][v + y[i]] += qanak;
          }
          mp[u][v] %= 4;
        }
      }
    if (f) break;
  }
  for (int h = 0; h < t; ++h) {
    int x, y;
    cin >> x >> y;
    if (x + 150 < 0 || x + 150 >= 300 || y + 150 < 0 || y + 150 >= 300)
      cout << 0 << endl;
    else
      cout << mp[x + 150][y + 150] << endl;
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a[2];
int n, t;
int add = 100;
int minx = add, maxx = add;
int main() {
  a[0].resize(210);
  a[1].resize(210);
  for (int i = 0; i < 210; i++) a[0][i].resize(210), a[1][i].resize(210);
  cin >> n >> t;
  a[1][add][add] = n;
  while (1 == 1) {
    bool fl = 0;
    a[0].swap(a[1]);
    for (int i = minx; i <= maxx; i++)
      for (int j = minx; j <= maxx; j++) a[1][i][j] = a[0][i][j];
    for (int i = minx; i <= maxx; i++)
      for (int j = minx; j <= maxx; j++) {
        if (a[0][i][j] >= 4) {
          fl = 1;
          minx = min(minx, i - 1);
          minx = min(minx, j - 1);
          maxx = max(maxx, i + 1);
          maxx = max(maxx, j + 1);
          a[1][i + 1][j] += a[1][i][j] / 4;
          a[1][i - 1][j] += a[1][i][j] / 4;
          a[1][i][j - 1] += a[1][i][j] / 4;
          a[1][i][j + 1] += a[1][i][j] / 4;
          a[1][i][j] %= 4;
        }
      }
    if (fl == 0) break;
  }
  for (int i = 0; i < t; i++) {
    int xx, yy;
    scanf("%d%d", &xx, &yy);
    xx += add;
    yy += add;
    if (min(xx, yy) < minx || max(xx, yy) > maxx)
      printf("%d\n", 0);
    else
      printf("%d\n", a[1][xx][yy]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
#pragma optimize("", on)
#pragma optimization_level 3
using namespace std;
const int N = 70;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
int g[N + 1][N + 1], h[N + 1][N + 1];
int main() {
  int i, j, k, n, t, flag = 1, m = 0, x, y, cnt = 0;
  pair<int, int> tmp;
  scanf("%d%d", &n, &t);
  g[0][0] = n;
  while (flag) {
    flag = 0;
    memset(h, 0, sizeof(h));
    for (i = 0; i < 70; i++)
      for (j = 0; j < 70; j++) {
        if (g[i][j] >= 4) {
          flag = 1;
          h[i][j] -= 4;
          for (k = 0; k < 4; k++) {
            x = i + dx[k], y = j + dy[k];
            if (x < 0 || y < 0) continue;
            if ((x == 0 && y == 0) ||
                ((i != 0 && j != 0) && (x == 0 || y == 0))) {
              h[x][y] += 2;
            } else
              h[x][y] += 1;
          }
        }
      }
    for (i = 0; i < N; i++)
      for (j = 0; j < N; j++) {
        g[i][j] += h[i][j];
      }
    assert(g[N][N] == 0);
  }
  for (i = 0; i < t; i++) {
    scanf("%d %d", &x, &y);
    x = abs(x);
    y = abs(y);
    if (x > N || y > N)
      k = 0;
    else
      k = g[x][y];
    printf("%d\n", k);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	from sys import *
     
f = lambda: map(int, stdin.readline().split())
n, t = f()
     
m = 65
r = range(m)
p = [[0] * m for i in r]
     
p[1][0] = n // 4
p[0][0] = n % 4
    
ultima = 5
q = k = 1
while q:
    k += 1
    q = 0
     
    for x in r[1:k]:
        for y in r[:x + 1]:
            if p[x][y] < 4: continue
            q = 1
     
            d = p[x][y] // 4
            p[x][y] %= 4
     
            p[x + 1][y] += d
            if x > y:
                if x > y + 1:
                    p[x][y + 1] += d
                    p[x - 1][y] += d
                else:
                    p[x][x] += 2 * d
                    if y: p[y][y] += 2 * d
                    else: p[x][y] += d
            if y: p[x][y - 1] += d if y > 1 else 2 * d
     
s = []
for j in range(t):
    x, y = f()
    x, y = abs(x), abs(y)
    if x < y: x, y = y, x
    s.append(p[x][y] if x < m else 0)
     
stdout.write('\n'.join(map(str, s)))
 					 	 	 	  			     	 		 	 	 | 8 | 
	PYTHON3 | 
| 
	#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int c[1000][1000];
bool vis[1000][1000];
struct XX {
  int x;
  int y;
};
queue<XX> q;
int main() {
  int n, Q;
  int i, j, k;
  int x, y, v;
  XX now;
  while (scanf("%d%d", &n, &Q) != EOF) {
    memset(c, 0, sizeof(c));
    memset(vis, false, sizeof(vis));
    XX temp = {500, 500};
    q.push(temp);
    vis[500][500] = true;
    c[500][500] = n;
    while (!q.empty()) {
      now = q.front();
      q.pop();
      v = c[now.x][now.y] >> 2;
      for (i = 0; i < 4; i++) {
        x = now.x + dx[i];
        y = now.y + dy[i];
        c[x][y] += v;
        if (c[x][y] > 3 && !vis[x][y]) {
          XX temp1 = {x, y};
          q.push(temp1);
          vis[x][y] = true;
        }
      }
      c[now.x][now.y] %= 4;
      vis[now.x][now.y] = false;
    }
    while (Q--) {
      scanf("%d%d", &x, &y);
      x = abs(x);
      y = abs(y);
      if (x > 500 || y > 500)
        puts("0");
      else
        printf("%d\n", c[x + 500][y + 500]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int const B_SZ = 70;
int board1[2 * B_SZ + 2][2 * B_SZ + 2] = {0};
int main() {
  int n, t;
  scanf("%d %d", &n, &t);
  board1[B_SZ][B_SZ] = n;
  int iter = 0;
  int mx = 0;
  queue<pair<int, int> > q;
  if (n > 3) q.push(make_pair(B_SZ, B_SZ));
  queue<pair<int, int> > nq;
  while (!q.empty()) {
    int i = q.front().first, j = q.front().second;
    q.pop();
    board1[i][j] -= 4;
    if (board1[i][j] > 3) q.push(make_pair(i, j));
    if (++board1[i][j - 1] == 4) q.push(make_pair(i, j - 1));
    if (++board1[i][j + 1] == 4) q.push(make_pair(i, j + 1));
    if (++board1[i - 1][j] == 4) q.push(make_pair(i - 1, j));
    if (++board1[i + 1][j] == 4) q.push(make_pair(i + 1, j));
  }
  while (t--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x += B_SZ, y += B_SZ;
    if (x < 0 || x >= 2 * B_SZ + 2 || y < 0 || y >= 2 * B_SZ + 2)
      printf("0\n");
    else
      printf("%d\n", board1[x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MXN = 3e5 + 10;
const int MXM = 500;
const int MID = 250;
int n, q;
int mp[MXM][MXM], inq[MXM][MXM];
vector<pair<int, int>> dir = {{0, +1}, {0, -1}, {+1, 0}, {-1, 0}};
vector<pair<int, int>> Q;
void solve() {
  Q.push_back({MID, MID});
  int p = 0;
  while (p < Q.size()) {
    int x, y;
    tie(x, y) = Q[p++];
    inq[x][y] = 0;
    int t = mp[x][y] / 4;
    mp[x][y] -= 4 * t;
    for (auto Pr : dir) {
      int xp = x + Pr.first, yp = y + Pr.second;
      mp[xp][yp] += t;
      if (!inq[xp][yp] && mp[xp][yp] > 3) {
        Q.push_back({xp, yp});
        inq[xp][yp] = 1;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  mp[MID][MID] = n;
  solve();
  while (q--) {
    int x, y;
    cin >> x >> y;
    x += MID, y += MID;
    if (x >= MXM || y >= MXM || x < 0 || y < 0)
      cout << "0\n";
    else
      cout << mp[x][y] << '\n';
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return ans % mod;
}
const int maxi = 1000;
int arr[maxi][maxi];
int n, m, k, l, j;
void dfs(int x, int y) {
  int antsdiv = arr[x][y] / 4;
  arr[x][y] -= 4 * antsdiv;
  arr[x - 1][y] += antsdiv;
  if (arr[x - 1][y] >= 4) dfs(x - 1, y);
  arr[x + 1][y] += antsdiv;
  if (arr[x + 1][y] >= 4) dfs(x + 1, y);
  arr[x][y - 1] += antsdiv;
  if (arr[x][y - 1] >= 4) dfs(x, y - 1);
  arr[x][y + 1] += antsdiv;
  if (arr[x][y + 1] >= 4) dfs(x, y + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  cin >> n;
  arr[500][500] = n;
  dfs(500, 500);
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (abs(x) > 100 || abs(y) > 100) {
      cout << "0\n";
      continue;
    }
    cout << arr[x + 500][y + 500] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = 70, M = 70, x_[4] = {0, 1, 0, -1}, y_[4] = {1, 0, -1, 0};
int n, t, tot[N + N + 5][M + M + 5] = {}, tmp[N + N + 5][M + M + 5] = {};
void init() {
  scanf("%d%d", &n, &t);
  tot[N][M] = n;
  bool flag = true;
  int sum = 0;
  while (flag) {
    flag = false;
    for (int i = 0; i < N + N; ++i)
      for (int j = 0; j < M + M; ++j) tmp[i][j] = 0;
    for (int i = 0; i < N + N; ++i)
      for (int j = 0; j < M + M; ++j) {
        tmp[i][j] += tot[i][j] & 3;
        if (tot[i][j] >= 4) {
          flag = true;
          for (int k = 0; k < 4; ++k)
            tmp[i + x_[k]][j + y_[k]] += tot[i][j] >> 2;
        }
      }
    for (int i = 0; i < N + N; ++i)
      for (int j = 0; j < M + M; ++j) tot[i][j] = tmp[i][j];
    ++sum;
  }
}
void work() {
  int x, y;
  for (int i = 1; i <= t; ++i) {
    scanf("%d%d", &x, &y);
    if (-N < x && x < N && -M < y && y < M)
      printf("%d\n", tot[x + N][y + M]);
    else
      puts("0");
  }
}
int main() {
  init();
  work();
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int ace[120][120], now[120][120];
void fun(int n) {
  ace[0][0] = n;
  int i, j, k;
  int my = 1, x, y;
  ;
  while (my) {
    my = 0;
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        now[i][j] = ace[i][j];
      }
    }
    for (i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        if (now[i][j] >= 4) {
          for (int k = 0; k < 4; k++) {
            x = dx[k] + i;
            y = dy[k] + j;
            if (x < 0 or y < 0) continue;
            ace[x][y]++;
            if (x == 0 && i != x) ace[x][y]++;
            if (y == 0 && j != y) ace[x][y]++;
          }
          ace[i][j] -= 4;
          my = 1;
        }
      }
    }
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        now[i][j] = ace[i][j];
      }
    }
  }
}
int main() {
  int i, j, k, l, m, n, t;
  scanf("%d%d", &n, &t);
  fun(n);
  while (t--) {
    scanf("%d%d", &i, &j);
    i = abs(i);
    j = abs(j);
    if (i > 100 || j > 100)
      printf("0\n");
    else
      printf("%d\n", ace[i][j]);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int c = 210;
int mat[c][c];
int zap, mur;
int main() {
  cin >> mur >> zap;
  mat[c / 2][c / 2] = mur;
  bool flag = true;
  while (flag == true) {
    flag = false;
    for (int i = 1; i < c - 1; i++) {
      for (int j = 1; j < c - 1; j++) {
        if (mat[i][j] >= 4) {
          flag = true;
        }
        mat[i - 1][j] += mat[i][j] / 4;
        mat[i + 1][j] += mat[i][j] / 4;
        mat[i][j - 1] += mat[i][j] / 4;
        mat[i][j + 1] += mat[i][j] / 4;
        mat[i][j] %= 4;
      }
    }
  }
  for (int i = 0; i < zap; i++) {
    int x, y;
    cin >> x >> y;
    if ((abs(x) > 103) || (abs(y) > 103)) {
      cout << 0 << "\n";
    } else {
      cout << mat[x + c / 2][y + c / 2] << "\n";
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = 65;
int t, a[N + N][N + N];
int main() {
  scanf("%d%d", a[N] + N, &t);
  bool ff = 1;
  while (ff) {
    ff = 0;
    for (int x = 1; x < N + N; ++x) {
      for (int y = 1; y < N + N; ++y) {
        if (a[x][y] >= 4) {
          ff = 1;
          a[x + 1][y] += a[x][y] / 4;
          a[x - 1][y] += a[x][y] / 4;
          a[x][y + 1] += a[x][y] / 4;
          a[x][y - 1] += a[x][y] / 4;
          a[x][y] %= 4;
        }
      }
    }
  }
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", abs(x) < N && abs(y) < N ? a[N + x][N + y] : 0);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar(), f = 0;
  for (; c < '0' || c > '9'; c = getchar())
    if (!(c ^ 45)) f = 1;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
}
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}, DX = 404;
int n, t, a[810][810];
queue<pair<int, int> > q;
int main() {
  read(n), read(t), a[DX][DX] = n, q.push(make_pair(0, 0));
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    int ad;
    if (a[x + DX][y + DX] < 4)
      continue;
    else
      ad = a[x + DX][y + DX] / 4, a[x + DX][y + DX] %= 4;
    for (int i = 0; i < 4; i++) {
      int tx = x + dx[i], ty = y + dy[i];
      a[tx + DX][ty + DX] += ad;
      if (a[tx + DX][ty + DX] >= 4) q.push(make_pair(tx, ty));
    }
  }
  for (int x, y; t--;) {
    read(x), read(y);
    if (x >= DX || x <= -DX || y >= DX || y <= -DX)
      puts("0");
    else
      printf("%d\n", a[x + DX][y + DX]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int constructAntGrid(int curx, int cury, int m[1000][1000]) {
  if (m[curx][cury] < 4) {
    return 0;
  }
  m[curx][cury + 1] += m[curx][cury] / 4;
  m[curx + 1][cury] += m[curx][cury] / 4;
  m[curx][cury - 1] += m[curx][cury] / 4;
  m[curx - 1][cury] += m[curx][cury] / 4;
  m[curx][cury] %= 4;
  constructAntGrid(curx + 1, cury, m);
  constructAntGrid(curx, cury + 1, m);
  constructAntGrid(curx - 1, cury, m);
  constructAntGrid(curx, cury - 1, m);
  return 0;
}
int main(int argc, char *argv[]) {
  int n_ants, n_queries;
  cin >> n_ants >> n_queries;
  int m[1000][1000];
  m[500][500] = n_ants;
  constructAntGrid(500, 500, m);
  for (int i = 0; i < n_queries; i++) {
    long long int x, y;
    cin >> x >> y;
    if (500 + x >= 1000 || 500 + y >= 1000 || 500 + y < 0 || 500 + x < 0)
      cout << 0 << endl;
    else
      cout << m[500 + x][500 + y] << endl;
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int M[132][132][2];
int f(int x) { return x + 132 / 2; }
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool in(int x, int y) { return abs(x) < 132 / 2 && abs(y) < 132 / 2; }
int main() {
  memset(M, 0, sizeof M);
  int n, t, a = 0, est = 0, x, y;
  scanf("%d%d", &n, &t);
  M[f(0)][f(0)][0] = n;
  bool ok = 1;
  while (ok) {
    ok = 0;
    for (int i = -a; i <= a; i++)
      for (int j = -a; j <= a; j++) {
        if (M[f(i)][f(j)][est] > 3) {
          ok = 1;
          for (int k = 0; k < 4; k++)
            M[f(i + dx[k])][f(j + dy[k])][!est] += M[f(i)][f(j)][est] / 4;
          M[f(i)][f(j)][!est] = M[f(i)][f(j)][est] % 4;
          M[f(i)][f(j)][est] = 0;
        } else {
          M[f(i)][f(j)][!est] += M[f(i)][f(j)][est];
          M[f(i)][f(j)][est] = 0;
        }
      }
    if (M[f(a + 1)][f(0)][!est] != 0) a++;
    est = !est;
  }
  while (t--) {
    scanf("%d%d", &x, &y);
    if (in(x, y))
      printf("%d\n", M[f(x)][f(y)][est]);
    else
      puts("0");
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
using db = long double;
using pll = pair<long long, long long>;
const int maxN = 32000;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int a[2000][2000];
int b[1000][1000];
int used[1000][1000];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, i, j, z, k, n;
  cin >> n;
  int centerx = 500, centery = 500;
  a[centerx][centery] = n;
  queue<pair<int, int> > q;
  q.push(make_pair(centerx, centery));
  ++used[centerx][centery];
  int total = 0;
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    int cx = cur.first, cy = cur.second;
    --used[cx][cy];
    if (a[cx][cy] >= 4) {
      int val = a[cx][cy] / 4;
      for (int k = 0; k < 4; ++k) {
        a[cx + dx[k]][cy + dy[k]] += val;
        if (!used[cx + dx[k]][cy + dy[k]]) {
          q.push(make_pair(cx + dx[k], cy + dy[k]));
          ++used[cx + dx[k]][cy + dy[k]];
        }
        ++total;
      }
    }
    a[cx][cy] %= 4;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    x += centerx, y += centery;
    if (x < 0 || x >= 1000 || y < 0 || y >= 1000) {
      printf("0\n");
    } else {
      printf("%d\n", a[x][y]);
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); }
double dcmp(double a, double b) {
  return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1;
}
const int mx = 150;
int grid[2][mx * 2][mx * 2];
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};
int main() {
  int n;
  scanf("%d", &n);
  int t;
  scanf("%d", &t);
  grid[0][mx][mx] = n;
  int flag = 1;
  int p = 0;
  int cnt = 0;
  while (flag) {
    cnt++;
    flag = 0;
    p = !p;
    memset(grid[p], 0, sizeof grid[p]);
    for (int i = 0; i < 2 * mx; i++) {
      for (int j = 0; j < 2 * mx; j++) {
        if (grid[!p][i][j] < 4) {
          grid[p][i][j] += grid[!p][i][j];
        } else {
          flag = 1;
          for (long long k = 0; k < 4; k++) {
            grid[p][i + dx[k]][j + dy[k]] += grid[!p][i][j] / 4;
          }
          grid[p][i][j] += grid[!p][i][j] % 4;
        }
      }
    }
  }
  int a, b;
  for (long long i = 0; i < t; i++) {
    scanf("%d%d", &a, &b);
    if (a + mx >= 2 * mx || a + mx < 0)
      printf("0\n");
    else if (b + mx >= 2 * mx || b + mx < 0)
      printf("0\n");
    else
      printf("%d\n", grid[p][a + mx][b + mx]);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
const int pivot = 200;
int n, q;
int x, y;
int lat[400][400];
int main() {
  scanf("%d %d", &n, &q);
  lat[pivot][pivot] = n;
  while (true) {
    bool change = false;
    for (int i = pivot - MAX; i <= pivot + MAX; i++)
      for (int j = pivot - MAX; j <= pivot + MAX; j++)
        if (lat[i][j] >= 4) {
          change = true;
          int go = lat[i][j] / 4;
          lat[i][j] %= 4;
          lat[i + 1][j] += go;
          lat[i - 1][j] += go;
          lat[i][j + 1] += go;
          lat[i][j - 1] += go;
        }
    if (!change) break;
  }
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    if (abs(x) > MAX || abs(y) > MAX) {
      printf("0\n");
    } else {
      printf("%d\n", lat[pivot + y][pivot + x]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int E = 70;
const int N = 2 * E;
int d[N][N];
int add[N][N];
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
bool flag = 1;
int main() {
  int n;
  cin >> n;
  d[E][E] = n;
  while (flag) {
    flag = 0;
    for (int i = 1; i < N - 1; i++) {
      for (int j = 1; j < N - 1; j++) {
        for (int k = 0; k < 4; k++) d[i + dx[k]][j + dy[k]] += d[i][j] / 4;
        d[i][j] %= 4;
      }
    }
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++)
        if (d[i][j] >= 4) flag = 1;
  }
  int m;
  cin >> m;
  for (int q = 0; q < m; q++) {
    int x, y;
    cin >> x >> y;
    if (x + E < N && x + E >= 0 && y + E < N && y + E >= 0)
      cout << d[x + E][y + E];
    else
      cout << 0;
    cout << "\n";
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int OFFSET = 100;
int c[200][200];
int inque[200][200];
queue<int> Q;
int main(void) {
  int n, t;
  scanf("%d%d", &n, &t);
  c[OFFSET][OFFSET] = n;
  if (n >= 4) {
    Q.push(0);
    Q.push(0);
  }
  inque[OFFSET][OFFSET] = 1;
  const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    int y = Q.front();
    Q.pop();
    inque[x + OFFSET][y + OFFSET] = 0;
    int v = c[x + OFFSET][y + OFFSET] / 4;
    c[x + OFFSET][y + OFFSET] %= 4;
    for (int i = 0; i < 4; i++) {
      int nx = x + OFFSET + dx[i], ny = y + OFFSET + dy[i];
      c[nx][ny] += v;
      if (c[nx][ny] >= 4 && !inque[nx][ny]) {
        inque[nx][ny] = 1;
        Q.push(nx - OFFSET);
        Q.push(ny - OFFSET);
      }
    }
  }
  for (int i = 0; i < t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (abs(x) > 64 || abs(y) > 64)
      puts("0");
    else
      printf("%d\n", c[x + OFFSET][y + OFFSET]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int ll = 130;
int n, t;
int a[500][500], b[500][500];
int main() {
  cin >> n >> t;
  memset(a, 0, sizeof(a));
  a[ll][ll] = n;
  while (true) {
    int ff = 0, l = ll;
    for (register int i = 1; i <= l * 2; i++)
      for (register int j = 1; j <= l * 2; j++)
        if (a[i][j] >= 4) {
          int t = a[i][j] >> 2;
          ff = 1;
          a[i + 1][j] += t;
          a[i][j + 1] += t;
          a[i - 1][j] += t;
          a[i][j - 1] += t;
          a[i][j] = a[i][j] & 3;
        }
    if (!ff) break;
  }
  for (int i = 0; i < t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (abs(x) <= ll && abs(y) <= ll)
      printf("%d\n", a[x + ll][y + ll]);
    else
      printf("0\n");
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int grid[8000][8000];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool inRange(int x, int y) { return x >= 0 && y >= 0 && x < 8000 && y < 8000; }
int main() {
  for (int i = 0; i < 8000; i++)
    for (int j = 0; j < 8000; j++) grid[i][j] = 0;
  int N, T;
  cin >> N >> T;
  queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  grid[0][0] = N;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    if (grid[x][y] < 4) continue;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (!inRange(nx, ny)) continue;
      if (nx == 0 && ny == 0) {
        grid[nx][ny] += (grid[x][y] / 4) * 2;
      } else if (nx == 0 || ny == 0) {
        grid[nx][ny] += (grid[x][y] / 4) * ((x == 0 || y == 0) ? 1 : 2);
      } else {
        grid[nx][ny] += (grid[x][y] / 4);
      }
      if (grid[nx][ny] >= 4) q.push(make_pair(nx, ny));
    }
    grid[x][y] = grid[x][y] % 4;
  }
  for (int i = 0; i < T; i++) {
    int x, y;
    cin >> x >> y;
    x = abs(x);
    y = abs(y);
    if (inRange(x, y))
      cout << grid[x][y] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10, S = N / 2;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int ans = 0;
struct arr {
  int a[N][N];
  int& operator[](pair<int, int> pi) {
    int nima = pi.first;
    int sepanta = pi.second;
    if (nima < 0) nima += S;
    if (sepanta < 0) sepanta += S;
    if (nima >= N || sepanta >= N || nima < 0 || sepanta < 0) return ans;
    return a[nima][sepanta];
  }
} sepi;
int main() {
  int n, t;
  cin >> n >> t;
  sepi[{0, 0}] = n;
  deque<pair<int, int> > dq;
  dq.push_back({0, 0});
  while (!dq.empty()) {
    pair<int, int> pi = dq.front();
    dq.pop_front();
    if (sepi[pi] < 4) continue;
    int add = sepi[pi] / 4;
    sepi[pi] -= add * 4;
    for (int i = 0; i < 4; i++) {
      sepi[{pi.first + dx[i], pi.second + dy[i]}] += add;
      dq.push_back({pi.first + dx[i], pi.second + dy[i]});
    }
  }
  cout << endl;
  while (t--) {
    int x, y;
    cin >> x >> y;
    cout << sepi[{x, y}] << endl;
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
const int nmax = 140;
int h[nmax][nmax];
int n, t, cnt;
int px[] = {-1, 0, 1, 0};
int py[] = {0, -1, 0, 1};
inline void add(int x, int y, int n) { h[x][y] += n; }
void push(int x, int y) {
  cnt++;
  int now = h[x][y] / 4;
  if (now > 0) {
    for (int i = 0; i < (int)(4); i++) add(x + px[i], y + py[i], now);
    h[x][y] -= now * 4;
    for (int i = 0; i < (int)(4); i++) push(x + px[i], y + py[i]);
  }
}
int main() {
  cin >> n >> t;
  add(nmax / 2, nmax / 2, n);
  push(nmax / 2, nmax / 2);
  for (int i = 0; i < (int)(t); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x += nmax / 2;
    y += nmax / 2;
    if (x < 0 || y < 0 || x >= nmax || y >= nmax)
      cout << 0 << endl;
    else
      cout << h[x][y] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int maz[1050][1050];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
struct node {
  int x, y;
  node() {}
  node(int a, int b) {
    x = a;
    y = b;
  }
};
queue<node> Q;
bool vist[202][202];
bool bfs() {
  memset(vist, 0, sizeof(vist));
  while (!Q.empty()) Q.pop();
  bool flag = 0;
  for (int i = 0; i < 202; i++) {
    for (int j = 0; j < 202; j++) {
      if (maz[i][j] >= 4) {
        Q.push(node(i, j));
        flag = 1;
      }
    }
  }
  if (!flag) return true;
  while (!Q.empty()) {
    node now = Q.front();
    Q.pop();
    vist[now.x][now.y] = 1;
    int tmp = maz[now.x][now.y];
    maz[now.x][now.y] = tmp % 4;
    for (int i = 0; i < 4; i++) {
      int xx = now.x + dx[i];
      int yy = now.y + dy[i];
      if (xx < 0 || yy < 0 || xx >= 200 || yy >= 200) continue;
      maz[xx][yy] += tmp / 4;
    }
  }
  return false;
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  memset(maz, 0, sizeof(maz));
  maz[100][100] = n;
  while (!bfs())
    ;
  int x, y;
  while (t--) {
    scanf("%d%d", &x, &y);
    if (x > 100 || y > 100 || x <= -100 || y <= -100)
      puts("0");
    else
      printf("%d\n", maz[x + 100][y + 100]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int main() {
  static int a[150][150];
  static int b[150][150];
  memset(a, 0, sizeof(a));
  int x1, x2, y1, y2;
  int st = 150 / 2;
  x1 = 150 / 2;
  x2 = 150 / 2;
  y1 = 150 / 2;
  y2 = 150 / 2;
  int num, Q;
  scanf("%d %d", &num, &Q);
  a[x1][y1] = num;
  int i, j;
  memset(b, 0, sizeof(b));
  while (1) {
    char flag = 0;
    for (i = x1; i <= x2; i++) {
      for (j = x1; j <= x2; j++) {
        if (a[i][j] >= 4) {
          flag = 1;
          b[i][j] -= 4;
          b[i - 1][j]++;
          b[i + 1][j]++;
          b[i][j - 1]++;
          b[i][j + 1]++;
        }
      }
    }
    int x3, x4, y3, y4;
    x3 = x1;
    x4 = x2;
    y3 = y1;
    y4 = y2;
    for (i = x1 - 1; i <= x2 + 1; i++) {
      if (b[i][y1 - 1]) y3 = y1 - 1;
      if (b[i][y2 + 1]) y4 = y2 + 1;
    }
    for (j = y1 - 1; j <= y2 + 1; j++) {
      if (b[x1 - 1][j]) x3 = x1 - 1;
      if (b[x2 + 1][j]) x4 = x2 + 1;
    }
    x1 = x3;
    x2 = x4;
    y1 = y3;
    y2 = y4;
    if (!flag) break;
    for (i = x1; i <= x2; i++) {
      for (j = x1; j <= x2; j++) {
        a[i][j] += b[i][j];
        b[i][j] = 0;
      }
    }
  }
  int iQ;
  for (iQ = 0; iQ < Q; iQ++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x += st;
    y += st;
    if ((x < x1) || (x > x2) || (y < y1) || (y > y2))
      printf("0\n");
    else
      printf("%d\n", a[x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
struct node {
  int x, y;
  node() {}
  node(int a, int b) {
    x = a;
    y = b;
  }
  bool operator<(const node &a) const {
    return x < a.x || (x == a.x && y < a.y);
  }
} a[100010];
int vis[2000][2000];
bool inq[2000][2000];
queue<node> q;
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= t; i++) scanf("%d%d", &a[i].x, &a[i].y);
  node st = node(0, 0);
  vis[N][N] = n;
  inq[N][N] = 1;
  q.push(st);
  while (!q.empty()) {
    node temp = q.front();
    q.pop();
    inq[temp.x + N][temp.y + N] = 0;
    int now = vis[temp.x + N][temp.y + N];
    for (int i = 0; i < 4; i++) {
      int tx = temp.x + dx[i], ty = temp.y + dy[i];
      node hh = node(tx, ty);
      vis[tx + N][ty + N] += now / 4;
      if (vis[tx + N][ty + N] >= 4 && !inq[tx + N][ty + N]) {
        q.push(hh);
        inq[tx + N][ty + N] = 1;
      }
    }
    vis[temp.x + N][temp.y + N] = now % 4;
  }
  for (int i = 1; i <= t; i++) {
    if (abs(a[i].x) >= N || abs(a[i].y) >= N)
      puts("0");
    else
      printf("%d\n", vis[a[i].x + N][a[i].y + N]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int m;
int n;
short col[2][2048][2048];
char was[2048][2048];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cm;
pair<int, int> v[1000000];
int main() {
  int mx = 1024, my = 1024;
  int t;
  cin >> n >> t;
  v[cm++] = make_pair(mx, my);
  col[0][mx][my] = n;
  was[mx][my] = 1;
  int ct = 0;
  while (1) {
    int o = cm;
    int ff = 0;
    for (int i = 0; i < (o); i++) {
      int cx = v[i].first;
      int cy = v[i].second;
      col[1 ^ ct][cx][cy] = 0;
    }
    for (int i = 0; i < (o); i++) {
      int cx = v[i].first;
      int cy = v[i].second;
      int o = col[ct][cx][cy];
      int f = o >= 4;
      if (f) {
        int dd = o / 4;
        o %= 4;
        ff += f;
        for (int j = 0; j < (4); j++) {
          int nx = cx + dx[j];
          int ny = cy + dy[j];
          if (nx < mx || ny < my) continue;
          if (!was[nx][ny]) {
            v[cm++] = make_pair(nx, ny);
            was[nx][ny] = 1;
          }
          if (nx == mx && cx > mx || ny == my && cy > my)
            col[ct ^ 1][nx][ny] += 2 * dd;
          else
            col[ct ^ 1][nx][ny] += dd;
        }
      }
      col[1 ^ ct][cx][cy] += o;
    }
    ct ^= 1;
    if (!ff) break;
  }
  for (int i = 0; i < (t); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = abs(x);
    y = abs(y);
    if (abs(x) >= 1024 || abs(y) >= 1024) {
      cout << 0 << '\n';
    } else
      cout << col[ct][x + 1024][y + 1024] << '\n';
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int n, t;
int a[2000 + 5][2000 + 5];
bool c[2000 + 5][2000 + 5];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
void ini() {
  for (int i = 0; i < 2000; i++)
    for (int j = 0; j < 2000; j++) a[i][j] = c[i][j] = 0;
  a[500][500] = n;
  queue<pair<int, int> > q;
  q.push(make_pair(500, 500));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    c[u.first][u.second] = 0;
    int k = a[u.first][u.second] / 4;
    for (int i = 0; i < 4; i++) {
      int x = u.first + dx[i];
      int y = u.second + dy[i];
      a[x][y] += k;
      if (!c[x][y] && a[x][y] > 3) {
        q.push(make_pair(x, y));
        c[x][y] = 1;
      }
    }
    a[u.first][u.second] %= 4;
  }
}
int main() {
  cin >> n >> t;
  ini();
  while (t--) {
    long long x, y;
    cin >> x >> y;
    if (abs(x) > 500 || abs(y) > 500)
      cout << 0 << endl;
    else
      cout << a[x + 500][y + 500] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const int n_ = 1e5 + 5;
int dx[] = {0, 0, 1, -1}, dy[] = {-1, 1, 0, 0};
int f[5003][5003], n, vis[5003][5003];
queue<pair<int, int>> q;
vector<pair<int, int>> v;
int main() {
  scanf("%d", &n);
  f[2500][2500] = n;
  if (n > 3) q.push({2500, 2500});
  int nx, ny;
  while (q.size()) {
    pair<int, int> i = q.front();
    q.pop();
    vis[i.first][i.second] = 0;
    int d = f[i.first][i.second] >> 2;
    f[i.first][i.second] &= 3;
    for (int j = 0; j < 4; j++) {
      nx = i.first + dx[j];
      ny = i.second + dy[j];
      f[nx][ny] += d;
      if (f[nx][ny] > 3 && !vis[nx][ny]) {
        vis[nx][ny] = 1;
        q.push({nx, ny});
      }
    }
  }
  int t, u, v;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &u, &v);
    u += 2500;
    v += 2500;
    if (u > 5000 || v > 5000 || v < 0 || u < 0)
      puts("0");
    else
      printf("%d\n", f[u][v]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q;
int arr[200][200];
int add[200][200];
int dy[4] = {0, 0, 1, -1};
int dx[4] = {1, -1, 0, 0};
int main() {
  int n, m;
  cin >> n >> m;
  arr[100][100] = n;
  q.push({100, 100});
  bool good = true;
  while (good) {
    good = false;
    memset(add, 0, sizeof(add));
    while (!q.empty()) {
      int y = q.front().first;
      int x = q.front().second;
      q.pop();
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        add[ny][nx] += arr[y][x] / 4;
      }
    }
    for (int i = 0; i < 200; i++)
      for (int j = 0; j < 200; j++) {
        arr[i][j] %= 4;
        arr[i][j] += add[i][j];
        if (arr[i][j] >= 4) {
          good = true;
          q.push({i, j});
        }
      }
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x += 100;
    y += 100;
    if (x >= 0 && x < 200 && y >= 0 && y < 200) {
      cout << arr[y][x] << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[1000][1000];
void solve(int x, int y, int n) {
  a[x][y] += n;
  n = a[x][y];
  if (a[x][y] < 4)
    return;
  else {
    a[x][y] = n % 4;
    solve(x + 1, y, n / 4);
    solve(x, y + 1, n / 4);
    solve(x, y - 1, n / 4);
    solve(x - 1, y, n / 4);
  }
}
int main() {
  int n = read(), q = read();
  solve(500, 500, n);
  for (int i = 0; i < q; i++) {
    int x = read(), y = read();
    if (x > 100 || x < -100 || y > 100 || y < -100)
      cout << "0" << endl;
    else
      printf("%d\n", a[x + 500][y + 500]);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[1000][1000];
void solve(int x, int y) {
  if (a[x][y] < 3)
    a[x][y]++;
  else {
    a[x][y] = 0;
    solve(x + 1, y);
    solve(x, y + 1);
    solve(x, y - 1);
    solve(x - 1, y);
  }
}
int main() {
  int n = read(), q = read();
  for (int i = 0; i < n; i++) solve(500, 500);
  for (int i = 0; i < q; i++) {
    int x = read(), y = read();
    if (x > 100 || x < -100 || y > 100 || y < -100)
      cout << "0" << endl;
    else
      printf("%d\n", a[x + 500][y + 500]);
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
int arr[400][400];
void f(int x, int y) {
  if (arr[x][y] < 4) return;
  arr[x][y + 1] += arr[x][y] / 4;
  arr[x][y - 1] += arr[x][y] / 4;
  arr[x + 1][y] += arr[x][y] / 4;
  arr[x - 1][y] += arr[x][y] / 4;
  arr[x][y] %= 4;
  f(x, y + 1);
  f(x, y - 1);
  f(x + 1, y);
  f(x - 1, y);
}
int main() {
  int n, t, i;
  scanf("%d %d", &n, &t);
  arr[200][200] = n;
  f(200, 200);
  for (i = 0; i < t; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (x + 200 > 400 || y + 200 > 400 || x + 200 < 0 || y + 200 < 0)
      printf("0\n");
    else
      printf("%d\n", arr[x + 200][y + 200]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 160;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, t;
  cin >> n >> t;
  int cnt[N][N];
  memset(cnt, 0, sizeof(cnt));
  cnt[N / 2][N / 2] = n;
  bool found = false;
  do {
    found = false;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (cnt[i][j] >= 4) {
          found = true;
          int c = cnt[i][j];
          cnt[i - 1][j] += c / 4;
          cnt[i][j - 1] += c / 4;
          cnt[i + 1][j] += c / 4;
          cnt[i][j + 1] += c / 4;
          cnt[i][j] = c % 4;
        }
      }
    }
  } while (found);
  for (int i = 0; i < t; i++) {
    int x, y;
    cin >> x >> y;
    x += N / 2, y += N / 2;
    if (x < 0 || y < 0 || x >= N || y >= N) {
      cout << 0 << '\n';
    } else {
      cout << cnt[x][y] << '\n';
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int Asize = 1000;
int A[Asize][Asize] = {{0}};
void func(int x, int y) {
  if (A[x][y] < 4) return;
  int a = A[x][y] / 4;
  A[x][y] %= 4;
  A[x - 1][y] += a;
  func(x - 1, y);
  A[x][y - 1] += a;
  func(x, y - 1);
  A[x][y + 1] += a;
  func(x, y + 1);
  A[x + 1][y] += a;
  func(x + 1, y);
}
int main(void) {
  int t;
  cin >> A[Asize / 2][Asize / 2] >> t;
  func(Asize / 2, Asize / 2);
  for (int i = 0; i < t; i++) {
    int x, y;
    cin >> x >> y;
    if (x < -Asize / 2 || x > Asize / 2 || y < -Asize / 2 || y > Asize / 2)
      cout << 0 << endl;
    else
      cout << A[Asize / 2 + x][Asize / 2 + y] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int f[2 * 100 + 10][2 * 100 + 10];
vector<pair<int, int> > v;
void insert(int x, int y, int d) {
  if ((f[x][y] < 4) && (f[x][y] + d >= 4)) v.push_back(make_pair(x, y));
  f[x][y] += d;
}
int get(int x, int y) {
  if (x < -100) return 0;
  if (x >= 100) return 0;
  if (y < -100) return 0;
  if (y >= 100) return 0;
  return f[x + 100][y + 100];
}
int d[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
int main() {
  int n, m;
  while (scanf("%d %d ", &n, &m) != EOF) {
    for (int i = 0; i < 2 * 100 + 10; ++i)
      for (int j = 0; j < 2 * 100 + 10; ++j) f[i][j] = 0;
    v.clear();
    insert(100, 100, n);
    for (int i = 0; i < v.size(); ++i) {
      int x = v[i].first;
      int y = v[i].second;
      int s = f[x][y] / 4;
      f[x][y] -= s * 4;
      for (int j = 0; j < 4; ++j) insert(x + d[j][0], y + d[j][1], s);
    }
    for (int i = 0; i < m; ++i) {
      int x, y;
      scanf("%d %d ", &x, &y);
      cout << get(x, y) << endl;
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int MaxN = 50005, MaxSize = 205, offset = 102;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int qx[MaxN], qy[MaxN];
int a[MaxSize][MaxSize];
bool good(int x) { return 0 <= x && x < MaxSize; }
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= t; i++) scanf("%d%d", qx + i, qy + i);
  memset(a, 0, sizeof(a));
  a[offset][offset] = n;
  int maxLeft = offset, maxRight = offset;
  int move = 0, cnt = 0;
  while (true) {
    cnt++;
    bool up = false;
    maxRight = offset + offset - maxLeft;
    int nLeft = maxLeft;
    for (int i = maxLeft - 1; i <= maxRight + 1; ++i) {
      int j = maxLeft - 1;
      if (((i + j) % 2) ^ move == 0) j++;
      for (; j <= maxRight + 1; j += 2)
        for (int k = 0; k < 4; k++) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          a[i][j] += a[nx][ny] / 4;
          if (a[i][j] >= 4 && i == maxLeft - 1) {
            nLeft = i;
          }
          up |= a[nx][ny] >= 4;
        }
    }
    for (int i = maxLeft - 1; i <= maxRight + 1; ++i)
      for (int j = maxLeft - 1; j <= maxRight + 1; ++j)
        if (((i + j) % 2) ^ move == 0) a[i][j] %= 4;
    maxLeft = nLeft;
    move ^= 1;
    if (!up) break;
  }
  for (int i = 1; i <= t; ++i)
    if (abs(qx[i]) >= 100 || abs(qy[i]) >= 100)
      printf("0\n");
    else
      printf("%d\n", a[qx[i] + offset][qy[i] + offset]);
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int A[1005][1005];
int main() {
  int antCount;
  scanf("%d", &antCount);
  int L = 0;
  A[500][500] = antCount;
  while (1) {
    int c = 0;
    for (int x = 500 - L; x <= 500 + L; x++)
      for (int y = 500 - L; y <= 500 + L; y++) {
        if (A[x][y] >= 4) {
          if (abs(x - 500) == L || abs(y - 500) == L) {
            L++;
          }
          c = 1;
          A[x - 1][y] += A[x][y] / 4;
          A[x + 1][y] += A[x][y] / 4;
          A[x][y - 1] += A[x][y] / 4;
          A[x][y + 1] += A[x][y] / 4;
          A[x][y] %= 4;
        }
      }
    if (!c) break;
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (abs(x) > L || abs(y) > L) {
      printf("0\n");
    } else {
      printf("%d\n", A[x + 500][y + 500]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 3;
const int p = 200;
int a[2][N][N], n, Q, cur = 0, dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
bool vis[N][N];
bool in(int x, int y) { return 0 <= x && x <= 400 && 0 <= y && y <= 400; }
struct note {
  int x, y, v;
  note() {}
  note(int _x, int _y, int _v) {
    x = _x;
    y = _y;
    v = _v;
  }
};
int main() {
  scanf("%d%d", &n, &Q);
  memset(a, 0, sizeof a);
  a[cur][p][p] = n;
  queue<note> q;
  queue<pair<int, int> > qq;
  if (n >= 4) qq.push(make_pair(p, p));
  while (1) {
    bool f = 0;
    while (!qq.empty()) {
      int i = qq.front().first, j = qq.front().second;
      qq.pop();
      f = 1;
      a[cur ^ 1][i][j] = a[cur][i][j] % 4;
      q.push(note(i, j, a[cur][i][j] / 4));
      a[cur][i][j] %= 4;
      vis[i][j] = 0;
    }
    if (!f) break;
    cur ^= 1;
    while (!q.empty()) {
      note u = q.front();
      q.pop();
      int nx, ny;
      for (int i = 0; i < 4; i++) {
        nx = u.x + dir[i][0];
        ny = u.y + dir[i][1];
        if (!in(nx, ny)) continue;
        a[cur][nx][ny] += u.v;
        a[cur ^ 1][nx][ny] = a[cur][nx][ny];
        if (a[cur][nx][ny] >= 4) {
          if (!vis[nx][ny]) {
            vis[nx][ny] = 1;
            qq.push(make_pair(nx, ny));
          }
        }
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x += p, y += p;
    if (!in(x, y))
      printf("0\n");
    else
      printf("%d\n", a[cur][x][y]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, 1, -1};
int m[3000][3000];
void process(int n) {
  queue<pair<int, int> > q;
  q.push(make_pair(1500, 1500));
  m[1500][1500] = n;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    int cnt = m[x][y];
    if (cnt < 4) {
      m[x][y] = cnt;
      q.pop();
      continue;
    } else {
      m[x][y] = cnt % 4;
      q.pop();
      for (int i = 0; i < 4; i++) {
        q.push(make_pair(x + dr[i], y + dc[i]));
        m[x + dr[i]][y + dc[i]] += cnt / 4;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, t;
  cin >> n >> t;
  process(n);
  int a, b;
  for (int i = 0; i < t; i++) {
    cin >> a >> b;
    if (a + 1500 >= 3000 || b + 1500 >= 3000 || a + 1500 < 0 || b + 1500 < 0) {
      cout << "0"
           << "\n";
    } else {
      cout << m[a + 1500][b + 1500] << "\n";
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int a[140][140];
int x[140 * 140], y[140 * 140], c[140 * 140], ptr = 0;
int xx[100000], yy[100000], pptr;
bool v[140][140], v2[140][140];
int b[140][140];
int maxX;
void construct() {
  pptr = 0;
  xx[pptr] = 70;
  yy[pptr++] = 70;
  memset(v, 0, sizeof(v));
  while (1) {
    int ch = 0;
    ptr = 0;
    for (int pp = 0; pp < pptr; pp++) {
      int i = xx[pp], j = yy[pp];
      if (a[i][j] >= 4) {
        ch = 1;
        if (v[i][j] == 0) {
          b[i][j] = 4;
          x[ptr] = i;
          y[ptr++] = j;
          v[i][j] = 1;
        } else
          b[i][j] += 4;
        i++;
        if (v[i][j] == 0) {
          b[i][j] = -1;
          x[ptr] = i;
          y[ptr++] = j;
          v[i][j] = 1;
        } else
          b[i][j] += -1;
        i -= 2;
        if (v[i][j] == 0) {
          b[i][j] = -1;
          x[ptr] = i;
          y[ptr++] = j;
          v[i][j] = 1;
        } else
          b[i][j] += -1;
        i++;
        j++;
        if (v[i][j] == 0) {
          b[i][j] = -1;
          x[ptr] = i;
          y[ptr++] = j;
          v[i][j] = 1;
        } else
          b[i][j] += -1;
        j -= 2;
        if (v[i][j] == 0) {
          b[i][j] = -1;
          x[ptr] = i;
          y[ptr++] = j;
          v[i][j] = 1;
        } else
          b[i][j] += -1;
      }
    }
    pptr = 0;
    for (int i = 0; i < ptr; i++) {
      maxX = max(x[i], maxX);
      a[x[i]][y[i]] -= b[x[i]][y[i]];
      if (a[x[i]][y[i]] >= 4) xx[pptr] = x[i], yy[pptr++] = y[i];
      v[x[i]][y[i]] = 0;
    }
    if (ch == 0) break;
  }
}
int main() {
  int n, t;
  cin >> n >> t;
  a[70][70] = n;
  construct();
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (x + 70 < 0 || x + 70 >= 140 || y + 70 >= 140 || y + 70 < 0)
      cout << 0 << endl;
    else
      cout << a[x + 70][y + 70] << endl;
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn][maxn];
int n, q, x, y;
inline void solve(int x, int y) {
  if (a[x][y] < 3)
    a[x][y]++;
  else {
    a[x][y] = 0;
    solve(x + 1, y);
    solve(x, y + 1);
    solve(x, y - 1);
    solve(x - 1, y);
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (register int i = 0; i < n; i++) solve(500, 500);
  for (register int i = 0; i < q; i++) {
    scanf("%d%d", &x, &y);
    if (x > 100 || x < -100 || y > 100 || y < -100)
      printf("0\n");
    else
      printf("%d\n", a[x + 500][y + 500]);
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
int cnt[300][300], vst[300][300], flag, q[1000000];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int N, z, T, qb, qf, x, y, i, xx, yy;
  while (scanf("%d%d", &N, &T) == 2) {
    memset(cnt, 0, sizeof(cnt));
    cnt[150][150] = N;
    qb = qf = 0;
    if (N >= 4) {
      q[qb++] = 150;
      q[qb++] = 150;
    }
    flag++;
    while (qf != qb) {
      x = q[qf++];
      if (qf == 1000000) qf = 0;
      y = q[qf++];
      if (qf == 1000000) qf = 0;
      vst[x][y] = 0;
      cnt[x][y] -= 4;
      for (i = 0; i < 4; i++) {
        xx = x + dx[i];
        yy = y + dy[i];
        cnt[xx][yy]++;
        if (cnt[xx][yy] >= 4) {
          if (vst[xx][yy] != flag) {
            vst[xx][yy] = flag;
            q[qb++] = xx;
            if (qb == 1000000) qb = 0;
            q[qb++] = yy;
            if (qb == 1000000) qb = 0;
          }
        }
      }
      if (cnt[x][y] >= 4) {
        vst[x][y] = flag;
        q[qb++] = x;
        if (qb == 1000000) qb = 0;
        q[qb++] = y;
        if (qb == 1000000) qb = 0;
      }
    }
    for (; T--;) {
      scanf("%d%d", &x, &y);
      if ((x + 150 < 0 || x + 150 >= 300 || y + 150 < 0 || y + 150 >= 300))
        puts("0");
      else
        printf("%d\n", cnt[x + 150][y + 150]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
using namespace std;
const int M = 300;
int cnt[2 * M + 1][2 * M + 1];
const int dx[] = {0, 1, 0, -1, 0};
void dfs(int x, int y) {
  if (cnt[y][x] < 4) return;
  int add = cnt[y][x] / 4;
  cnt[y][x] %= 4;
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i], yy = y + dx[1 + i];
    cnt[yy][xx] += add;
    dfs(xx, yy);
  }
}
int main() {
  int n, t;
  cin >> n >> t;
  cnt[M][M] = n;
  dfs(M, M);
  while (t--) {
    int x, y;
    cin >> x >> y;
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x < y) swap(x, y);
    if (x >= M || y >= M) {
      cout << 0 << '\n';
    } else {
      cout << cnt[y + M][x + M] << '\n';
    }
  }
}
 | 8 | 
	CPP | 
| 
	#include <bits/stdc++.h>
int main() {
  const int F = 4;
  const int N = 65;
  long a[2 * N][2 * N] = {0};
  long t(0);
  scanf("%ld %ld", &a[N][N], &t);
  bool done(false);
  while (!done) {
    done = true;
    for (long x = 1; x < 2 * N - 1; x++) {
      for (long y = 1; y < 2 * N - 1; y++) {
        if (a[x][y] < F) {
          continue;
        }
        done = false;
        a[x + 1][y] += a[x][y] / F;
        a[x - 1][y] += a[x][y] / F;
        a[x][y + 1] += a[x][y] / F;
        a[x][y - 1] += a[x][y] / F;
        a[x][y] %= F;
      }
    }
  }
  while (t--) {
    long x, y;
    scanf("%ld %ld", &x, &y);
    if (x < -N || x >= N || y < -N || y >= N) {
      puts("0");
    } else {
      printf("%ld\n", a[N + x][N + y]);
    }
  }
  return 0;
}
 | 8 | 
	CPP | 
			Subsets and Splits
				
	
				
			
				
No community queries yet
The top public SQL queries from the community will appear here once available.