Problem:
ブレイブ・フォース・ストーリー
English text is not available in this practice contest.
「最果ての地，ナイン・アイランドには特別な力を持つものが生きていた．
ある者は火，ある者は氷，ある者は風，ある者は土を意のままに操ることができた．
人はこれらの術者をこう呼んだ．『Brave Force』と・・・．時は戦国時代．権力者たちはBrave Forceを私欲のために使わんとBrave Force狩りを始めた．
 Brave Forceを巡る戦いが今始まろうとしている．」
以上は，あなたが今つくろうとしている戦略シミュレーションゲームのプロローグである．このプロローグは本問題には全く関係ない．
問題の説明に戻ろう．戦略シミュレーションの世界においては， 正6角形のマスがよく使われる． 
これは， 正方形のマスに比べて方向による距離の違いが小さく， 敷き詰めも可能であるからである．
今回はこのようなマップ上でコマを動かすことを考える．コマは各ターンごとに隣接するマスに移動させることができる．
もちろんマップ上には多くの障害物があってそこには移動することができない．さて一定のターン数が経過するまでにたどり着くことが可能なマスの数はいくつあるだろうか．
Input
入力はそれぞれがマップの情報を表す1つ以上のデータセットからなる．
データセットの最初の行には， 2つの整数が含まれていて， 1番目がターン数
t
で， 2番目が障害物の数
n
である．
それに続く
n
行にはそれぞれ障害物のマスの座標を表す2つの整数が含まれていて， 1番目が x 座標で， 2番目が y 座標である． 障害物の座標は互いに異なっている．
そして最後の行にはスタート位置のマスの座標を表す2つの整数が含まれていて， 1番目が x 座標で， 2番目が y 座標である． このマスには障害物はない． またこのマスは到達できるマスに含められる．
マスに割り当てられた座標は下の図のようになっている．
図B-1 マスに割り当てられた座標
入力の終わりは"0 0"を含む行で表される．
いずれの座標も絶対値が30以下である． ターン数は1以上30以下である． 障害物の数は0以上300以下である．
図B-2 Sample Input の1つ目のデータセット
Output
各マップについて到達できるマスの数を表す整数を各行に出力せよ． それ以外の余計な文字を出力に含めてはいけない．
Sample Input
1 1
1 0
0 0
2 2
-2 1
2 0
2 2
2 0
-1 1
4 4
-2 1
1 -2
1 2
3 -3
-2 0
4 6
0 1
1 1
1 0
-1 0
-1 -1
0 -1
0 0
0 0
Output for the Sample Input
6
18
19
58
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <cstdint>
#include <regex>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<long long, long long>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using vvvi = vector<vector<vector<int>>>;
using pii = pair<int, int>;
using vvb = vector<vector<bool>>;
using Graph = vector<vector<ll>>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 998244353;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (m); i >= (int)(n); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}

vi dx4 = {1, 0, -1, 0}, dy4 = {0, 1, 0, -1};
vi dx8 = {1, 1, 1, 0, 0, -1, -1, -1}, dy8 = {1, 0, -1, 1, -1, 1, 0, -1};
vi dx6 = {0, 1, 1, 0, -1, -1}, dy6 = {1, 1, 0, -1, -1, 0};

int main() {
    while (1) {
        int t, n;
        cin >> t >> n;
        if (t == 0 && n == 0) {
            break;
        }

        set<pii> st1;
        rep(i, n) {
            int x, y;
            cin >> x >> y;
            st1.insert({x, y});
        }

        int sx, sy;
        cin >> sx >> sy;

        set<pii> st2;
        set<pii> st3;
        st2.insert({sx, sy});
        rep(i, t) {
            for (auto [p, q] : st2) {
                rep(j, 6) {
                    int nx = p + dx6[j];
                    int ny = q + dy6[j];
                    if (st1.count({nx, ny}) == 0) {
                        st3.insert({nx, ny});
                    }
                }
            }
            for (auto [p, q] : st3) {
                st2.insert({p, q});
            }
        }

        cout << st2.size() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 510
memory_kb: 3712
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name
#define REP1(n) for(ll i=0;i<(n);i++)
#define REP2(i, n) for (ll i=0;i<(n);i++)
#define REP3(i, a, n) for (ll i=a;i<(n);i++)
#define REP4(i, a, b, n) for(ll i=a;i<(n);i+=b)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name
#define RREP1(n) for(ll i=(n)-1;i>=0;i--)
#define RREP2(i, n) for(ll i=(n)-1;i>=0;i--)
#define RREP3(i, a, n) for(ll i=(n)-1;i>=(a);i--)
#define RREP4(i, a, b, n) for(ll i=(n)-1;i>=(a);i-=(b))
#define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define len(n) (long long)(n).size()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvvc = vector<vvc>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;

ll intpow(ll a,ll b){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
        }
        a *= a;
        b /= 2;
    }
    return ans;
}
ll modpow(ll a,ll b,ll c){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b /= 2;
    }
    return ans;
}

template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; input(__VA_ARGS__)
#define CHA(...) char __VA_ARGS__; input(__VA_ARGS__)
#define VLL(name,length) vll name(length);rep(i,length){cin >> name[i];}
#define VVLL(name,h,w) vvll name(h,vll(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLL(name,a,b,c) vvvll name(a,vvll(b,vll(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VI(name,length) vi name(length);rep(i,length){cin >> name[i];}
#define VVI(name,h,w) vvi name(h,vi(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVI(name,a,b,c) vvvi name(a,vvll(b,vi(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VLD(name,length) vld name(length);rep(i,length){cin >> name[i];}
#define VVLD(name,h,w) vvld name(h,vld(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLD(name,a,b,c) vvvld name(a,vvld(b,vld(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VC(name,length) vc name(length);rep(i,length){cin >> name[i];}
#define VVC(name,h,w) vvc name(h,vc(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVC(name,a,b,c) vvvc name(a,vvc(b,vc(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VS(name,length) vs name(length);rep(i,length){cin >> name[i];}
#define VVS(name,h,w) vvs name(h,vs(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVS(name,a,b,c) vvvs name(a,vvs(b,vs(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define PLL(name) pll name;cin>>name.first>>name.second;
#define VPLL(name,length) vpll name(length);rep(i,length){cin>>name[i].first>>name[i].second;}

void print(){cout << "\n";}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
    os << "[";
    for (size_t i = 0; i < vec.size(); ++i) {
        os << vec[i];
        if (i + 1 < vec.size()) os << ", ";
    }
    os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::pair<T1, T2>>& a) {
    os << "[";
    for (size_t j = 0; j < a.size(); ++j) {
        os << "(" << a[j].first << ", " << a[j].second << ")";
		if (j + 1 < a.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<std::pair<T1, T2>>>& mat) {
	os << "[";
    for (size_t i = 0; i < mat.size(); ++i) {
		os << "[";
        for (size_t j = 0; j < mat[i].size(); ++j) {
            os << "(" << mat[i][j].first << ", " << mat[i][j].second << ")";
			if (j + 1 < mat[i].size()) os << ", ";
        }
		os << "]";
		if (i + 1 < mat.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
    os << "{";
    bool first = true;
    for (const auto& x : s) {
        if (!first) os << ", ";
        os << x;
        first = false;
    }
    os << "}";
    return os;
}

template <typename K, typename V>
std::ostream& operator<<(std::ostream& os, const std::map<K, V>& m) {
    os << "{";
    bool first = true;
    for (const auto& [key, val] : m) {
        if (!first) os << ", ";
        os << key << ": " << val;
        first = false;
    }
    os << "}";
    return os;
}

template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}

void write(){cout << "\n";}
template<class T, class... Ts>
void write(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}
void write(vll x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vi x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvi x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvi x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vld x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvld x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvld x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vc x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvc x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvc x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vs x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvs x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvs x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(pll x){cout << x.first << ' ' << x.second << '\n';}
void write(vpll x){rep(i,len(x)){cout << x[i].first << ' ' << x[i].second << '\n';}}
void write(vvpll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j].first << ' ' << x[i][j].second;if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}

template <typename T>
T sum(const std::vector<T>& v) {
    return std::accumulate(v.begin(), v.end(), T(0));
}

template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }



int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
    while(1){
        LL(t,n);
        if(n == 0 && t == 0){break;}
        map<ll,ll> mp;
        ll m = 1000000;
        rep(i,n){
            LL(x,y);
            mp[x * m + y] = 1;
        }
        map<ll,ll> dp;
        LL(sx,sy);
        dp[sx*m+sy] = 1;
        vpll dxy = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{0,0}};
        rep(i,t){
            map<ll,ll> ndp;
            for(auto [k,v]:dp){
                if(v == 0){continue;}
                ll x = k / m;
                ll y = k % m;
                for(auto [dx,dy]:dxy){
                    ll tx = x+dx;
                    ll ty = y+dy;
                    if(mp[tx*m+ty] == 0){
                        ndp[tx*m+ty] = 1;
                    }
                }
            }
            swap(dp,ndp);
        }
        ll ans = 0;
        for(auto [k,v]:dp){
            ans += v;
        }
        print(ans);

    }
}
accuracy: 1
time_ms: 670
memory_kb: 3968
final_rank: 15

code_snippet: #line 1 "A.cpp"
#include <iostream>
#include <utility>
#include <queue>
#include <vector>
#include <cassert>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, const T& b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, const T& b) {if (b<a) {a=b; return true;} return false;}
constexpr int INTINF = 100;
constexpr int INTMAX = 2147483647;
constexpr ll LLMAX = 9223372036854775807;
constexpr ll LLINF = 4450000000011100000;

int dx[6] = {1, 1, 0, -1, -1, 0};
int dy[6] = {0, 1, 1, 0, -1, -1};

#line 1 "/home/harui/CompetitiveProgramming/library/debug.hpp"



#ifdef LOCAL
#define dbg(x) std::cerr << __LINE__ << " : " << #x << " = " << (x) << std::endl
#else
#define dbg(x) true
#endif

#line 13 "/home/harui/CompetitiveProgramming/library/debug.hpp"
#include <set>


template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '[';
  for (int i=0; i<int(vec.size()); i++) {
    os << vec[i];
    if (i != int(vec.size())-1) os << ", ";
  }
  os << ']';
  return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  os << '{';
  auto itr = st.begin();
  while (itr != st.end()) {
    os << *itr;
    itr = next(itr);
    if (itr != st.end()) os << ", ";
  }
  os << '}';
  return os;
}



#line 19 "A.cpp"

void solve(int T, int N) {
  dbg("called");
  constexpr int OFFSET = 300;
  // -30 <= x <= 30
  // 0 <= x + 30 <= 60
  vector<vector<bool>>A(OFFSET*2+1, vector<bool>(OFFSET*2+1, false));
  vector<vector<int>>dist(OFFSET*2+1, vector<int>(OFFSET*2+1, INTINF));

  for (int i=0; i<N; i++) {
    int x, y;
    cin >> x >> y;
    A[x+OFFSET][y+OFFSET] = true;
  }
  

  int sx, sy; cin >> sx >> sy;
  queue<pair<int,int>> que;
  dist[sx + OFFSET][sy + OFFSET] = 0;
  que.push(make_pair(sx,sy));

  while (!que.empty()) {
    pair<int,int> fr = que.front(); que.pop();
    int x = fr.first;
    int y = fr.second;
    assert(A[x+OFFSET][y+OFFSET]==false);
    assert(dist[x+OFFSET][y+OFFSET] < INTINF);
    for (int k=0; k<6; k++) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      if ((!A[nx+OFFSET][ny+OFFSET]) && chmin(dist[nx+OFFSET][ny+OFFSET], dist[x+OFFSET][y+OFFSET] + 1)) {
        que.push(make_pair(nx,ny));
      }
    }
  }


  int ans = 0;
  for (int x=-OFFSET; x<=OFFSET; x++) {
    for (int y=-OFFSET; y<=OFFSET; y++) {
      if (dist[x+OFFSET][y+OFFSET] <= T) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  dbg("end");
}

int main() {
  while (true) {
    dbg("loop");
    int t, n;
    cin >> t >> n;
    dbg(t);
    dbg(n);
    if (t == 0 && n == 0) break;
    solve(t,n);
  }
}
accuracy: 1
time_ms: 170
memory_kb: 4992
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;

bool solve() {
    int T, N;
    cin >> T >> N;
    if (T == 0 && N == 0) return false;
    const int M = 100;
    vector<vector<bool>> B(2 * M, vector<bool>(2 * M, false));
    while (N--) {
        int r, c;
        cin >> r >> c;
        B[r + M][c + M] = true;
    }
    int sr, sc;
    cin >> sr >> sc;
    vector<vector<int>> D(2 * M, vector<int>(2 * M, 1 << 30));
    D[sr + M][sc + M] = 0;
    queue<pair<int, int>> q;
    q.emplace(sr + M, sc + M);
    int dr[6] = {0, 1, 0, -1, 1, -1};
    int dc[6] = {1, 0, -1, 0, 1, -1};
    while (q.size()) {
        auto [r, c] = q.front();
        q.pop();
        for (int d = 0; d < 6; d++) {
            int nr = r + dr[d], nc = c + dc[d];
            if (0 <= nr && nr < 2 * M && 0 <= nc && nc < 2 * M && !B[nr][nc]) {
                if (D[nr][nc] > D[r][c] + 1) {
                    D[nr][nc] = D[r][c] + 1;
                    q.emplace(nr, nc);
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 2 * M; i++) {
        for (int j = 0; j < 2 * M; j++) {
            if (D[i][j] <= T) ans++;
        }
    }
    cout << ans << '\n';
    return true;
}

int main() {
    while (solve()) {}
}
accuracy: 1
time_ms: 120
memory_kb: 3840
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

template <typename A> void chmin(A &l, const A &r) {
    if(r < l)
        l = r;
}
template <typename A> void chmax(A &l, const A &r) {
    if(l < r)
        l = r;
}

ll mod = 998244353;

vector<char> isprime;
void init() {
    isprime.assign(1000005, 1);
    isprime[0] = 0;
    isprime[1] = 0;
    for(int i = 2; i < 1000005; i++) {
        if(isprime[i]) {
            for(int j = i * 2; j < 1000005; j += i) {
                isprime[j] = 0;
            }
        }
    }
}

ll n, m, s, t;
vector<a2> v;
void input() {
    cin >> m >> n;
    v.resize(n);
    for(auto &x : v)
        cin >> x[0] >> x[1];
    cin >> s >> t;
}
void solve() {
    set<a2> sh;
    for(auto &x : v)
        sh.insert(x);

    set<a2> ok;
    queue<pair<a2, int>> que;
    que.push({{s, t}, 0});
    ok.insert({s, t});

    vector<a2> adj = {{0, 1}, {1, 1}, {1, 0}, {0, -1}, {-1, -1}, {-1, 0}};

    while(que.size()) {
        auto f = que.front();
        que.pop();

        for(auto &x : adj) {
            ll p = f.first[0] + x[0];
            ll q = f.first[1] + x[1];

            if(ok.count({p, q}) == 0 && sh.count({p, q}) == 0 &&
               f.second + 1 <= m) {
                que.push({{p, q}, f.second + 1});
                ok.insert({p, q});
            }
        }
    }
    cout << ok.size() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // init();
    while(1) {
        input();
        if(n == 0 && m == 0)
            break;
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3664
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)

int main() {
    while(1){
        ll t,n;
        cin >> t >> n;
        if(t == 0)break;
        set<pair<ll,ll>> obstacle;
        set<pair<ll,ll>> cnt;
        queue<pair<pair<ll,ll>,ll>> q;
        rep(i, n){
            ll x,y;
            cin >> x >> y;
            obstacle.insert({x,y});
        }
        ll startx,starty;
        cin >> startx >> starty;
        q.push({{startx,starty},0ll});
        cnt.insert({startx,starty});
        while(!q.empty()){
            ll nowx = q.front().first.first;
            ll nowy = q.front().first.second;
            ll nowcost = q.front().second;
            q.pop();
            if(nowcost >= t)continue;
            for(ll i = -1; i <= 1; i++){
                for(ll j = -1; j <= 1; j++){
                    if(i == 1 && j == -1)continue;
                    if(j == 1 && i == -1)continue;
                    ll nx = nowx + i;
                    ll ny = nowy + j;
                    if(!cnt.count({nx,ny}) && !obstacle.count({nx,ny})){
                        cnt.insert({nx,ny});
                        q.push({{nx,ny},nowcost + 1});
                    }
                }
            }
        }
        cout << cnt.size() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3508
final_rank: 8

code_snippet: /*
#include "all.hpp"

int main() {
  io_setup();
}
*/

#include <bits/stdc++.h>
using namespace std;

int main() {
  auto nxt = [](pair<int, int> xy) -> vector<pair<int, int>>{
    auto [x, y] = xy;
    return {
      {x, y+1},
      {x+1, y+1},
      {x-1, y},
      {x+1, y},
      {x-1, y-1},
      {x, y-1},
    };
  };
  while(true) {
    int t, n;
    cin >> t >> n;
    if(t == 0) exit(0);
    set<pair<int, int>> block;
    for(int i=0; i<n; i++) {
      int u, v;
      cin >> u >> v;
      block.insert({u, v});
    }
    pair<int, int> start;
    cin >> start.first >> start.second;
    map<pair<int, int>, int> dist;
    for(int x=-60; x<=60; x++) 
      for(int y=-60; y<=60; y++) 
        dist[{x, y}] = 1'000'000'000;
    deque<pair<int,int>> q;
    q.push_back(start);
    dist[start] = 0;
    while(!q.empty()) {
      auto cur = q.front();
      q.pop_front();
      auto d = dist[cur];
      for(auto c : nxt(cur)) {
        if(dist[c] <= d+1) continue;
        if(block.contains(c)) continue;
        dist[c] = d+1;
        q.push_back(c);
      }
    }
    int ans = 0;
    for(int x=-60; x<=60; x++) 
      for(int y=-60; y<=60; y++) 
        if(dist[{x, y}] <= t) ans++;
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 1800
memory_kb: 4608
final_rank: 17

code_snippet: // https://codeforces.com/blog/entry/96344
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;

#if __cplusplus >= 202002L
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
#endif

template<typename T>
bool chmax(T& a, const T& b) {
    bool res = a < b;
    a = max(a, b);
    return res;
}
template<typename T>
bool chmin(T& a, const T& b){
    bool res = a > b;
    a = min(a, b);
    return res;
}

typedef vector<long long> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll>> vll;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;

const int inf = 1000000009;
const ll linf = 4000000000000000009;


// https://trap.jp/post/1224/
template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

void print(){
    cout << '\n';
}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << '\n';
}

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T, typename U>
T SUM(const vector<U> &A){
    T ret = 0;
    for (auto &&a: A) ret += a;
    return ret;
}

#define rep1(a)          for(int i = 0; i < a; i++)
#define rep2(i, a)       for(int i = 0; i < a; i++)
#define rep3(i, a, b)    for(int i = a; i < b; i++)
#define rep4(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i, a, b)    for(int i = a; i >= b; i--)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(v) v.begin(), v.end()
//---------------------------------

int dx[] = {0, 1, 1, 0, -1, -1};
int dy[] = {1, 1, 0, -1, -1, 0};

void solve(int t, int n){
    int a[1000][1000];
    rep(i, 1000) rep(j, 1000){
        a[i][j] = -1;
    }
    rep(i, n){
        int x,y; cin >> x >> y;
        a[x+500][y+500] = -2;
    }
    int ans = 1;
    int sx, sy; cin >> sx >> sy;
    a[sx+500][sy+500] = 0;
    deque<pii> d;
    d.push_back(mp(sx, sy));
    while(!d.empty()){
        auto [x, y] = d.front();
        d.pop_front();
        if(a[x+500][y+500] >= t) continue;
        rep(k, 6){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(a[nx+500][ny+500]==-1){
                a[nx+500][ny+500] = a[x+500][y+500] + 1;
                ans++;
                d.push_back(mp(nx, ny));
            }
        }
    }
    print(ans);
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t, n;
    cin >> t >> n;
    while(t > 0){
        solve(t, n);
        cin >> t >> n;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 7360
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define ov4(a, b, c, d, name, ...) name
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for (ll i = (a) - 1; i >= (b); i--)
#define fore(e, v) for (auto&& e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template <typename T, typename S>
bool chmin(T& a, const S& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
bool chmax(T& a, const S& b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;
#define i128 __int128_t
struct _ {
  _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

void solve();
int main(){
  while(1)solve();
}

void solve(){
  int T,N;
  cin>>T>>N;
  if(N==0&&T==0)exit(0);
  using ai2= array<int,2>;
  vector<ai2> ob(N);
  fore(i,ob)cin>>i[0]>>i[1];
  ai2 S;
  cin>>S[0]>>S[1];
  S[0]+=65,S[1]+=65;
  vector<vi>dist (140,vi(140,1e9));
  fore(i,ob){
    dist[i[0]+65][i[1]+65]=-1;
  }
  queue<ai2>bfs;
  vector<ai2> n={ai2{0,1},ai2{1,1},ai2{1,0},ai2{0,-1},ai2{-1,-1},ai2{-1,0}};
  bfs.push(ai2{S[0],S[1]});
  dist[S[0]][S[1]]=0;
  auto bound_ok=[&](int x,int y){
    return x>=0&&x<140&&y>=0&&y<140&&dist[x][y]!=-1;
  };
  while(bfs.size()){
    auto [x,y]=bfs.front();
    int d=dist[x][y];
    bfs.pop();
    fore(i,n){
      int x2=x+i[0],y2=y+i[1];
      if(bound_ok(x2,y2)&&dist[x2][y2]>d+1){
        dist[x2][y2]=d+1;
        bfs.push(ai2{x2,y2});
      }
    }
  }
  int ans=0;
  rep(i,140){
    rep(j,140){
      if(dist[i][j]!=-1&&dist[i][j]<=T)ans++;
    }
  }
  cout<<ans<<'\n';
}
accuracy: 1
time_ms: 50
memory_kb: 3456
final_rank: 5

code_snippet: /**
	author:  shobonvip
	created: 2025.04.24 17:46:57
**/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}



void solve(int t, int n) {

	int mx = 150;
	int geta = 75;
	vector c(mx, vector<bool>(mx, true));
	rep(i,0,n) {
		int x, y; cin >> x >> y;
		c[x + geta][y + geta] = false;
	}


	int sx, sy;
	cin >> sx >> sy;
	sx += geta;
	sy += geta;
	vector d(mx, vector<int>(mx, 1e9));
	d[sx][sy] = 0;
	deque<pair<int,int>> mada;
	mada.push_back(pair(sx, sy));
	while(!mada.empty()){
		auto [i, j] = mada.front();
		mada.pop_front();
		for (auto [x, y]:{
			pair(i, j+1),
			pair(i+1, j+1),
			pair(i+1, j),
			pair(i, j-1),
			pair(i-1, j-1),
			pair(i-1, j)
		}) {
			if (!(0<=x&&x<mx))continue;
			if (!(0<=y&&y<mx))continue;
			if (!c[x][y])continue;
			if(chmin(d[x][y],d[i][j]+1)){
				mada.push_back(pair(x,y));
			}
		}
	}
	int cnt=0;
	rep(i,0,mx){
		rep(j,0,mx){
			if(d[i][j]<=t){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
	while(true) {
		int h, w; cin >> h >> w;
		if (h == 0 && w == 0) break;
		solve(h, w);
	}
}
accuracy: 1
time_ms: 80
memory_kb: 3476
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;
int t,n;
vector<int> x,y;
int sx,sy;
int dx[] = {1,0,-1,-1,0,1};
int dy[] = {0,-1,-1,0,1,1};
int solve() {
    cin >> t >> n;
    if (t+n==0) exit(0);
    x.resize(n);
    y.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    cin >> sx >> sy;

    vector<vector<int>> dis(125, vector<int>(125, 1e9));
    int offset = 62;
    for (int i = 0; i < n; ++i) {
        x[i] -= sx;
        y[i] -= sy;
        x[i] += offset;
        y[i] += offset;
        dis[y[i]][x[i]] = 0;
    }

    using pii = pair<int,int>;
    queue<pii> q;
    q.emplace(offset, offset);
    dis[offset][offset] = 0;
    int cnt = 1;
    while (q.size()) {
        auto [xx,yy] = q.front(); q.pop();
        if (dis[yy][xx] == t) continue;
        for (int i = 0; i < 6; ++i) {
            int nx = xx + dx[i];
            int ny = yy + dy[i];
            if (dis[ny][nx] > dis[yy][xx] + 1) {
                dis[ny][nx] = dis[yy][xx] + 1;
                q.emplace(nx,ny);
                ++cnt;
            }
        }
    }
    return cnt;
}
int main() {
    while (true) {
        cout << solve() << '\n';
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3260
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int dx[6] = {1,0,-1,-1,0,1}, dy[6] = {1,1,0,-1,-1,0};

int main() {
while(1) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) return 0;
    bool X[201][201] = {};
    rep(i,0,201) rep(j,0,201) X[i][j] = true;
    rep(i,0,M) {
        int A, B;
        cin >> A >> B;
        A += 100, B += 100;
        X[A][B] = false;
    }
    int SX, SY;
    cin >> SX >> SY;
    SX += 100, SY += 100;
    queue<pair<int,int>> Q;
    vector<vector<int>> D(201,vector<int>(201,inf));
    D[SX][SY] = 0;
    Q.push({SX,SY});
    int ANS = 1;
    while(!Q.empty()) {
        pair<int,int> P = Q.front();
        Q.pop();
        if (D[P.first][P.second] == N) continue;
        rep(i,0,6) {
            int NX = P.first + dx[i], NY = P.second + dy[i];
            if (X[NX][NY]) {
                if (D[NX][NY] == inf) {
                    D[NX][NY] = D[P.first][P.second] + 1;
                    ANS++;
                    Q.push({NX,NY});
                }
            }
        }
    }
    cout << ANS << endl;
}
}
accuracy: 1
time_ms: 10
memory_kb: 3624
final_rank: 10

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

using ll = long long;
using i64 = long long;
using pll = pair<ll,ll>;
using plll = pair<pll,ll>;
using pii =pair<int,int>;

constexpr ll mod = 998244353;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int dX[4]={1,0,-1,0};
int dY[4]={0,-1,0,1};

//library


//end


int main(){
    while (true){
        int t,n;
        cin>>t>>n;
        if (t==0)break;
        set<pii> bad;
        for (int i=0; i<n; i++){
            int x,y ;
            cin>>x>>y;
            bad.emplace(x,y);
        }

        int x,y;
        cin>>x>>y;

        queue<tuple<int,int,int>> que;
        que.emplace(x,y,0);
        set<pii> visited;

        int ddx[6]={1,0,-1,0,1,-1};
        int ddy[6]={0,1,0,-1,1,-1};
        while (que.size()){
            auto [x,y,now] =que.front();
            que.pop();
            if (visited.count(make_pair(x,y)))continue;
            visited.insert(make_pair(x,y));
            if (now==t)continue;

            for (int d=0; d<6; d++){
                int nx=x+ddx[d],ny=y+ddy[d];
                //if (abs(nx)>30 || abs(ny)>30)continue;
                pii pr(nx,ny);
                if (bad.count(pr) || visited.count(pr))continue;
                que.emplace(nx,ny,now+1);
            }

        }
        cout<<visited.size()<<endl;





    }

}
accuracy: 1
time_ms: 90
memory_kb: 3388
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>; using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ll INF = 1LL << 60;
const ld PI = acos(-1);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec);
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr);
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const pair<T, U> &pa);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa);
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp);
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp);
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl);
 
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <class... T> std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; }
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl
#define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr)
#else
#define dbg(x) ((void)0)
#define dbgif(cond, x) ((void)0)
#endif
void solve();
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
//見切り発車で実装しては行けない．頭の中でコードが完全に出来上がるまで書き始めるな．
ll dx[] = {0,1,1,0,-1,-1};
ll dy[] = {1,1,0,-1,-1,0};
void solve(){
  while(true){
    int t, n;cin>>t>>n;
    if(t==0&&n==0)return;
    set<pl> ng;
    rep(i,n){
      ll x,y;cin>>x>>y;
      ng.insert({x,y});
    }
    ll sx,sy;cin>>sx>>sy;
    queue<pl> que;
    que.push({sx,sy});
    set<pl> seen;
    seen.insert({sx,sy});
    while(t--){
      queue<pl> nque;
      while(!que.empty()){
        auto [x,y] = que.front();
        que.pop();
        rep(d,6){
          int nx = x+dx[d];
          int ny = y+dy[d];
          if(!ng.count({nx,ny})&&!seen.count({nx,ny})){
            seen.insert({nx,ny});
            nque.push({nx,ny});
          }
        }
      }
      swap(nque,que);
    }
    cout<<seen.size()<<endl;
  }
}
accuracy: 1
time_ms: 70
memory_kb: 3556
final_rank: 9

code_snippet: #include<bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;
//using mint=modint1000000007;
//using mint=modint998244353;

const ll INF=1ll<<60;
ll mod10=1e9+7;
ll mod99=998244353;
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=a;i>=n;--i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

vll dx={0,1,0,-1,1,-1},dy={1,0,-1,0,1,-1};

bool solve(){
    ll t,N;cin>>t>>N;
    if(t==0&&N==0) return 0;
    vvll dist(1000,vll(1000,INF));
    set<P> st;
    rep(i,N){
        ll x,y;cin>>x>>y;
        x+=500,y+=500;
        st.insert({x,y});
    }

    ll sx,sy;
    cin>>sx>>sy;
    sx+=500,sy+=500;
    queue<P> q;
    q.push({sx,sy});
    dist[sx][sy]=0;
    while(q.size()){
        auto [nowi,nowj]=q.front();q.pop();
        if(dist[nowi][nowj]>t) continue;
        rep(k,6){
            ull toi=nowi+dx[k],toj=nowj+dy[k];
            if(!(toi<1000&&toj<1000)) continue;
            if(st.count({toi,toj})) continue;
            if(dist[toi][toj]!=INF) continue;
            q.push({toi,toj});
            dist[toi][toj]=dist[nowi][nowj]+1;
        }
    }

    ll ans=0;
    rep(i,1000) rep(j,1000) if(dist[i][j]<=t) ans++;
    cout<<ans<<endl;



    return 1;
}


int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   while(solve());
}
accuracy: 1
time_ms: 590
memory_kb: 11236
final_rank: 19

code_snippet: #include<bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;
//using mint=modint1000000007;
//using mint=modint998244353;

const ll INF=1ll<<60;
ll mod10=1e9+7;
ll mod99=998244353;
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=a;i>=n;--i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

vll dx={0,1,0,-1,1,-1},dy={1,0,-1,0,1,-1};

bool solve(){
    ll t,N;cin>>t>>N;
    if(t==0&&N==0) return 0;
    vvll dist(1000,vll(1000,INF));
    set<P> st;
    rep(i,N){
        ll x,y;cin>>x>>y;
        x+=500,y+=500;
        st.insert({x,y});
    }

    ll sx,sy;
    cin>>sx>>sy;
    sx+=500,sy+=500;
    queue<P> q;
    q.push({sx,sy});
    dist[sx][sy]=0;
    while(q.size()){
        auto [nowi,nowj]=q.front();q.pop();
        rep(k,6){
            ull toi=nowi+dx[k],toj=nowj+dy[k];
            if(!(toi<1000&&toj<1000)) continue;
            if(st.count({toi,toj})) continue;
            if(dist[toi][toj]!=INF) continue;
            q.push({toi,toj});
            dist[toi][toj]=dist[nowi][nowj]+1;
        }
    }

    ll ans=0;
    rep(i,1000) rep(j,1000) if(dist[i][j]<=t) ans++;
    cout<<ans<<endl;



    return 1;
}


int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   while(solve());
}
accuracy: 1
time_ms: 7520
memory_kb: 11328
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,s,t) for(ll i=s;i<(ll)(t);i++)
#define rrep(i,s,t) for(ll i=(ll)(t)-1;i>=(ll)s;i--)
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)

#define TT template<typename T>
TT using vec=vector<T>;
TT bool chmin(T &x,T y){return x>y?(x=y,true):false;}
TT bool chmax(T &x,T y){return x<y?(x=y,true):false;}

struct io_setup{
    io_setup(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout<<fixed<<setprecision(15);
    }
} io_setup;

const int dx[]={0,1,1,0,-1,-1},dy[]={1,1,0,-1,-1,0};
const int M=100;
const int INF=1<<30;

int solve(){
    int T,N;
    cin>>T>>N;
    if(T==0&&N==0)return 0;
    vector<int>X(N),Y(N);
    vector flag(2*M+1,vector<bool>(2*M+1));
    for(int i=0;i<N;i++){
        cin>>X[i]>>Y[i];
        X[i]+=M;
        Y[i]+=M;
        flag[X[i]][Y[i]]=true;
    }
    int sx,sy;
    cin>>sx>>sy;
    sx+=M;
    sy+=M;
    vector dp(2*M+1,vector<int>(2*M+1,INF));
    dp[sx][sy]=0;
    queue<tuple<int,int,int>>q;
    q.push(make_tuple(dp[sx][sy],sx,sy));
    while(q.size()){
        auto[c,x,y]=q.front();
        q.pop();
        if(dp[x][y]<c)continue;
        for(int i=0;i<6;i++){
            int ex=x+dx[i],ey=y+dy[i];
            if(0<=ex&&ex<=2*M&&0<=ey&&ey<=2*M&&c+1<=T&&!flag[ex][ey]&&chmin(dp[ex][ey],c+1)){
                q.push(make_tuple(dp[ex][ey],ex,ey));
            }
        }
    }
    int ans=0;
    for(int i=0;i<=2*M;i++){
        for(int j=0;j<=2*M;j++){
            if(dp[i][j]!=INF)ans++;
        }
    }
    cout<<ans<<"\n";
    return 1;
}

int main(){
    while(solve());
}
accuracy: 1
time_ms: 10
memory_kb: 3640
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int dx[]={0,1,1,0,-1,-1};
const int dy[]={1,1,0,-1,-1,0};

int main(){
	while(true){
		int T,N;cin>>T>>N;

		if(T==0)break;

		set<pair<int,int>>S;
		for(int i=0;i<N;i++){
			int x,y;cin>>x>>y;
			S.insert({x,y});
		}
		int sx,sy;
		cin>>sx>>sy;

		queue<pair<int,int>>Q;
		Q.push({sx,sy});

		set<pair<int,int>>seen;
		seen.insert({sx,sy});

		for(int t=0;t<T;t++){
			vector<pair<int,int>>nQ;

			while(!Q.empty()){
				auto[x,y]=Q.front();
				Q.pop();

				for(int i=0;i<6;i++){
					int nx=x+dx[i];
					int ny=y+dy[i];

					if(seen.count({nx,ny})||S.count({nx,ny})){
						continue;
					}

					seen.insert({nx,ny});
					nQ.push_back({nx,ny});
				}
			}
			
			for(auto x:nQ)Q.push(x);
		}


		cout<<seen.size()<<endl;
	}
}
accuracy: 1
time_ms: 70
memory_kb: 3504
final_rank: 7

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

const int p = 100;

vi dx = {1, 1, 0, -1, -1, 0}, dy = {0, 1, 1, 0, -1, -1};

int solve(int N, int T){
    vvi A(300, vi(300, inf));
    rep(i, N){
        int x, y; cin >> x >> y;
        A[x + p][y + p] = -1;
    }
    int sx, sy; cin >> sx >> sy;
    sx += p;
    sy += p;
    deque<pair<int, int>> q;
    q.push_back({sx, sy});
    int ans = 1;
    A[sx][sy] = 0;
    while (!q.empty()){
        auto [x, y] = q.front(); q.pop_front();
        if (A[x][y] == T) continue;
        rep(k, 6){
            int nx = x + dx[k], ny = y + dy[k];
            if (A[nx][ny] > A[x][y] + 1){
                A[nx][ny] = A[x][y] + 1;
                ans++;
                q.push_back({nx, ny});
            }
        }
    }
    return ans;
}

int main(){
    vc<int> ans;
    while (true){
        int T, N; cin >> T >> N;
        if (T == 0 && N == 0) break;
        ans.push_back(solve(N, T));
    }
    for (auto x : ans) cout << x << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3476
final_rank: 4

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, b) for (int i = 0; i < b; i++)
#define m_t 60
#define max (3 * m_t * (m_t + 1) + 1)
#define zero (max / 2)
#define mp make_pair
int dx[6] = {0, 1, -1, 1, -1, 0};
int dy[6] = {1, 1, 0, 0, -1, -1};

struct Node {
  int x, y, t;
};

int main() {
  int t, n;
  while (cin >> t >> n, t) {
    vector<int> field(max, 1);
    int x, y;
    rep(i, n) {
      cin >> x >> y;
      y = y * (m_t * 2 + m_t * 2 + 1 - abs(y)) / 2;
      field[zero + x + y] = 0;
    }
    int sx, sy;
    cin >> sx >> sy;
    x = sx;
    y = sy * (m_t * 2 + m_t * 2 + 1 - abs(sy)) / 2;
    field[zero + x + y] = 0;
    int ans = 0;
    deque<Node> rt;
    rt.push_back({sx, sy, 0});
    while (!rt.empty()) {
      ans++;
      Node node = rt.front();
      rt.pop_front();
      if (node.t < t) {
        rep(i, 6) {
          int nx = node.x + dx[i];
          int ny = (node.y + dy[i]) * (m_t * 2 + m_t * 2 + 1 - abs(node.y + dy[i])) / 2;
          if (field[zero + nx + ny]) {
            field[zero + nx + ny] = 0;
            rt.push_back({nx, node.y + dy[i], node.t + 1});
          }
        }
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3140
final_rank: 1