Problem:
Problem C
Honeycomb Distance
A plane is tiled completely with regular hexagons. 
Each hexagon is called a cell.
You can move in one step from a cell to one of its adjacent cells that share an edge. 
You want to know the minimum number of steps to move from the central cell to the specified cell.
Each cell is specified by a pair of integers. 
The central cell is (0, 0).
One of the directions perpendicular to the edges of the regular hexagons 
is defined to be the rightward direction. 
For each cell (
x, y
), its right adjacent cell is (
x
+ 1,
y
) and its upper-right adjacent cell is (
x, y
+ 1).
See the figure below.
Write a program that computes the minimum number of steps required to move from the cell (0, 0) to the cell (
x, y
) for given integers
x
and
y
.
Figure C-1: How to specify the cells
Input
The first line of the input contains only one positive integer
n,
which is the number of datasets.
n
does not exceed 100.
Each of the following
n
lines contains one dataset.
Each dataset consists of two integers
x
and
y
, which satisfy −1000 ≤
x
≤ 1000 and −1000 ≤
y
≤ 1000.
The destination cell is (
x, y
).
Output
For each dataset, output one line containing the minimum number
of steps required to move from the cell (0, 0) to the destination cell.
Sample Input
7
0 0
0 1
1 0
2 1
2 -1
-3 2
-1 -3
Output for the Sample Input
0
1
1
3
2
3
4

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using pll = pair<long long, long long>;

#define rrep1(a)          for(ll i = (ll)(a-1); i >= (ll)0 ; i--)
#define rrep2(i, a)       for(ll i = (ll)(a-1); i >= (ll)0; i--)
#define rrep3(i, a, b)    for(ll i = (ll)(a-1); i >=(b); i--)
#define rrep4(i, a, b, c) for(ll i = (ll)(a-1); i >=(b); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

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

#define fi first
#define se second
#define pb push_back
#define spa " "

//！？！？
#define O print

inline void scan(){}
template<class Head,class... Tail>
inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);}
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)

#pragma GCC diagnostic ignored "-Wunused-value"
void print(){cout << '\n';}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(std::cout << ... << (cout << ' ', b));cout << '\n';}
#pragma GCC diagnostic warning "-Wunused-value"

//int INF = 2147483647; // おおよそ2*10^9
ll inf = 1LL<<60; //おおよそ10^18
//ull UINF == おおよそ1.8*10^19

const vector<ll> dx = {1,1,0,0,-1,-1};
const vector<ll> dy = {0,-1,1,-1,0,1};

int main(){
    LL(n);
    vector<pll> goal(n);
    rep(n) cin >> goal[i].fi >> goal[i].se;
    const ll size = 2010;
    vector<vector<ll>> field(size,vector<ll>(size, inf));
    vector<vector<bool>> visited(size,vector<bool>(size,false));
    field[size/2][size/2] = 0;
    queue<tuple<ll,ll,ll>> q;
    q.push({size/2,size/2,0});
    while(!q.empty()){
        auto [x, y, cost] = q.front();
        q.pop();
        if(visited[x][y]) continue;
        visited[x][y] = true;
        field[x][y] = min(field[x][y], cost);
        rep(dx.size()){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || nx >= size || ny < 0 || ny >= size) continue;
            if(visited[nx][ny]) continue;
            q.push({nx,ny,cost + 1});
        }
    }
    rep(n){
        int ni = goal[i].fi + size/2;
        int nj = goal[i].se + size/2;
        cout << field[ni][nj] << endl;
    }
}
accuracy: 1
time_ms: 100
memory_kb: 36352
final_rank: 8

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>;
template<class T1, class T2> bool chmin(T1 &x, T2 y) { return x > y ? (x = y, true) : false; }
template<class T1, class T2> bool chmax(T1 &x, T2 y) { return x < y ? (x = y, true) : false; }

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

const int MAX=3000;
const int INF=1<<30;
const int dx[]={0,1,1,0,-1,-1},dy[]={1,0,-1,-1,0,1};
int dist[2*MAX+1][2*MAX+1];

void solve(){
    rep(i,0,2*MAX+1)rep(j,0,2*MAX+1)dist[i][j]=INF;
    dist[MAX][MAX]=0;
    queue<tuple<int,int,int>>q;
    q.push({dist[MAX][MAX],MAX,MAX});
    while(q.size()){
        auto[d,x,y]=q.front();
        q.pop();
        rep(i,0,6){
            int ex=x+dx[i],ey=y+dy[i];
            if(0<=ex&&ex<=2*MAX&&0<=ey&&ey<=2*MAX&&chmin(dist[ex][ey],d+1)){
                q.push({dist[ex][ey],ex,ey});
            }
        }
    }
}

int main() {
    solve();
    int N;
    cin>>N;
    vector<int>X(N),Y(N);
    rep(i,0,N){
        cin>>X[i]>>Y[i];
        cout<<dist[X[i]+MAX][Y[i]+MAX]<<endl;
    }
}
accuracy: 1
time_ms: 350
memory_kb: 144456
final_rank: 15

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

const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define all(v) v.begin(), v.end()
#define rall(a) a.rbegin(), a.rend()
#define fi first
#define se second
#define endl "\n"

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template <typename T>
using vc = vector<T>; // prioriy_queueに必要なのでここにこれ書いてます
template <typename T>
using vv = vc<vc<T>>;
#define int long long
using ll = long long;
ll INF = 2e18;

#ifdef ONLINE_JUDGE
// ジャッジ環境ではデバッグマクロを無効化
#define debug_x(x) \
    do             \
    {              \
    } while (0)
#define debug_vc(v) \
    do              \
    {               \
    } while (0)
#define debug_vv(v) \
    do              \
    {               \
    } while (0)
#else
// ローカルではデバッグ出力
#define debug_x(x) cout << #x << " = " << (x) << endl
#define debug_vc(v)                    \
    {                                  \
        cout << #v << endl;            \
        ll n = size(v);                \
        rep(i, n) cout << v[i] << ' '; \
        cout << endl;                  \
    } // 一次元配列を出力する
#define debug_vv(v)                                        \
    {                                                      \
        cout << #v << endl;                                \
        ll n = size(v);                                    \
        rep(i, n)                                          \
        {                                                  \
            rep(j, size(v[i])) { cout << v[i][j] << ' '; } \
            cout << endl;                                  \
        }                                                  \
    } // 二次元配列を出力する
#endif

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define drep(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define nfor(i, s, n) for (ll i = s; i < n; i++)        // i=s,s+1...n-1 ノーマルfor
#define dfor(i, s, n) for (ll i = (s) - 1; i >= n; i--) // s-1スタートでnまで落ちる

using ld = long double;
using bl = bool;

template <class T>
using pq = priority_queue<T, vc<T>>; // 大きい順
template <class T>
using pq_g = priority_queue<T, vc<T>, greater<T>>; // 小さい順

using vl = vc<ll>;
using vvl = vv<ll>;
using vvvl = vv<vl>;
using vvvvl = vv<vvl>;
using vs = vc<string>;
using vvs = vv<string>;
using vb = vc<bl>;
using vvb = vv<bl>;
using vvvb = vv<vb>;
using vld = vc<ld>;
using vvld = vv<ld>;
using vvvld = vv<vld>;
using P = pair<ll, ll>;
using vP = vc<P>;
using vvP = vc<vP>;
using vvvP = vv<vP>;

#define pb push_back

#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define YN                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    } // if(a==b)YN;
#define dame cout << -1 << endl

string dir = "DRUL"; // 第4象限の場合

bool out_grid(ll i, ll j, ll h, ll w)
{ // trueならcontinue
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

vl di = {1, 0, -1, 0, -1, 1}; // vl di={1,1,0,-1,-1,-1,0,1};
vl dj = {0, 1, 0, -1, 1, -1}; // vl dj={0,1,1,1,0,-1,-1,-1};

void solve()
{
    ll x, y;
    cin >> x >> y;

    vvl dist(2011,vl(2011,-1));
    dist[1005][1005] = 0;
    queue<P> que;
    que.push({1005,1005});
    while(!que.empty()){
        auto [i,j] = que.front();
        que.pop();
        rep(k,6){
            ll ni = i + di[k];
            ll nj = j + dj[k];
            if(ni<0||ni>2010||nj<0||nj>2010)continue;
            if(dist[ni][nj]==-1){
                dist[ni][nj] = dist[i][j] + 1;
                if(ni==x+1005&&nj==y+1005){
                    que = {};
                    break;
                }
                que.push({ni,nj});
            }
        }
    }
    cout << dist[x+1005][y+1005] << endl;

    return;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    rep(i, n)
    {
        solve();
    }
    return 0;
}

/*
shift+alt+Fで成形
f2で変数名変更

スニペット
basic
 m:atcoder以外用
 ma:ABC/ARC用
 mahc:AHC用
math
 floor:床関数
 ceil:天井関数
 comv:二項係数
 modpow: a^b mod m
 GCD:最大公約数
 extGCD:拡張ユークリッド互除法
 PFD:素因数分解
 isprime:エラトステネスの篩
 matrixpow:行列累乗
data_structure
 seg:セグメント木
technic
 Compress:座標圧縮
 runlength:ランレングス圧縮
graph
 warshall:ワーシャルフロイド法
 dfs:深さ優先探索
 bfs:幅優先探索
 LCA:最近共通祖先
*/
accuracy: 1
time_ms: 3460
memory_kb: 34992
final_rank: 17

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

typedef struct _pos{
    ll x,y;
}pos;
pos operator+(pos a,pos b){
    return {a.x+b.x,a.y+b.y};
}
bool operator<(const pos a,const pos b){
    if(a.x>b.x)return true;
    if(a.x==b.x){
        if(a.y>b.y)return true;
    }
    return false;
}
pos pos_move[6]={{0,1},{1,0},{1,-1},{0,-1},{-1,0},{-1,1}};

using ans_type = ll;

int main(void){
    vector<ans_type>ans;
    ll i,j,k;

    ll dist[2009][2009];
    ll add=1000;

    ll t,T;
    cin>>T;
    rep(t,T){
        pos p;
        cin>>p.x>>p.y;

        if(p.x==0 && p.y==0){
            ans.push_back(0);
            continue;
        }
        
        ans_type a;
        queue<pos>q;
        
        rep(i,2009)rep(j,2009)dist[i][j]=INT64_MAX;

        q.push({0,0});
        dist[0+add][0+add]=0;

        bool end=0;
        while(dist[p.x+add][p.y+add]==INT64_MAX){
            pos now=q.front();q.pop();
            // clog<<now.x<<" "<<now.y<<endl;
            rep(i,6){
                pos next=now+pos_move[i];
                if(abs(next.x)>1000)continue;
                if(abs(next.y)>1000)continue;
                if(dist[now.x+add][now.y+add]+1<dist[next.x+add][next.y+add]){
                    dist[next.x+add][next.y+add]=dist[now.x+add][now.y+add]+1;
                    q.push(next);
                }
            }
        }
        a=dist[p.x+add][p.y+add];
        ans.push_back(a);
    }

    rep(i,ans.size())cout<<ans[i]<<endl;
    return 0;
}
accuracy: 1
time_ms: 3260
memory_kb: 35072
final_rank: 16

code_snippet: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

namespace atcoder {

    // Implement (union by size) + (path compression)
    // Reference:
    // Zvi Galil and Giuseppe F. Italiano,
    // Data structures and algorithms for disjoint set union problems
    struct dsu {
    public:
        dsu() : _n(0) {}
        explicit dsu(int n) : _n(n), parent_or_size(n, -1) {}

        int merge(int a, int b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            int x = leader(a), y = leader(b);
            if (x == y) return x;
            if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
            parent_or_size[x] += parent_or_size[y];
            parent_or_size[y] = x;
            return x;
        }

        bool same(int a, int b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            return leader(a) == leader(b);
        }

        int leader(int a) {
            assert(0 <= a && a < _n);
            return _leader(a);
        }

        int size(int a) {
            assert(0 <= a && a < _n);
            return -parent_or_size[leader(a)];
        }

        std::vector<std::vector<int>> groups() {
            std::vector<int> leader_buf(_n), group_size(_n);
            for (int i = 0; i < _n; i++) {
                leader_buf[i] = leader(i);
                group_size[leader_buf[i]]++;
            }
            std::vector<std::vector<int>> result(_n);
            for (int i = 0; i < _n; i++) {
                result[i].reserve(group_size[i]);
            }
            for (int i = 0; i < _n; i++) {
                result[leader_buf[i]].push_back(i);
            }
            result.erase(
                std::remove_if(result.begin(), result.end(),
                    [&](const std::vector<int>& v) { return v.empty(); }),
                result.end());
            return result;
        }

    private:
        int _n;
        // root node: -1 * component size
        // otherwise: parent
        std::vector<int> parent_or_size;

        int _leader(int a) {
            if (parent_or_size[a] < 0) return a;
            return parent_or_size[a] = _leader(parent_or_size[a]);
        }
    };

}  // namespace atcoder

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define foreach(i, n) for (auto i : (n))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

template <typename K, typename V>
using umap = std::unordered_map<K, V>;
template <typename K>
using uset = std::unordered_set<K>;

using grid = vector<vector<char>>;
using graph = vector<vector<int>>;
using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>;
using vld = vector<ld>; using vvld = vector<vector<ld>>;
using vb = vector<bool>; using vvb = vector<vector<bool>>;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i]; 
        x[i] += 1000;
        y[i] += 1000;
    }
    int dx[6] = {1, 0,  1,  0, -1, -1};
    int dy[6] = {0, 1, -1, -1,  0,  1};
    vvi dist(2001, vi(2001, -1));
    dist[1000][1000] = 0;
    queue<pair<int, int>> q;
    q.push({ 1000,1000 });
    while (!q.empty()) {
        pair<int, int> d = q.front();
        q.pop();
        rep(i, 6) {
            int nx = d.first + dx[i];
            int ny = d.second + dy[i];
            if (nx < 0 || 2000 < nx) continue;
            if (ny < 0 || 2000 < ny) continue;
            if (dist[nx][ny] != -1) continue;
            dist[nx][ny] = dist[d.first][d.second] + 1;
            q.push({ nx, ny });
        }
    }
    rep(i, n) {
        cout << dist[x[i]][y[i]] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 19128
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<vector<int>> s(2002,vector<int>(2002,1e9));
    queue<pair<int,int>> que;
    s[1000][1000] = 0;
    que.push({1000,1000});
    while(!que.empty()){
        auto [x,y] = que.front();
        que.pop();
        if(x+1<2002&&s[x][y]+1<s[x+1][y]){
            s[x+1][y] = s[x][y] + 1;
            que.push({x+1,y});
        }
        if(x-1>=0&&s[x][y]+1<s[x-1][y]){
            s[x-1][y] = s[x][y] + 1;
            que.push({x-1,y});
        }
        if(y+1<2002&&s[x][y]+1<s[x][y+1]){
            s[x][y+1] = s[x][y] + 1;
            que.push({x,y+1});
        }
        if(y-1>=0&&s[x][y]+1<s[x][y-1]){
            s[x][y-1] = s[x][y] + 1;
            que.push({x,y-1});
        }
        if(x+1<2002&&y-1>=0&&s[x][y]+1<s[x+1][y-1]){
            s[x+1][y-1] = s[x][y] + 1;
            que.push({x+1,y-1});
        }
        if(x-1>=0&&y+1<2002&&s[x][y]+1<s[x-1][y+1]){
            s[x-1][y+1] = s[x][y] + 1;
            que.push({x-1,y+1});
        }
    }
    while(n--){
        int x,y;
        cin >> x >> y;
        cout << s[x+1000][y+1000] << endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 19008
final_rank: 1

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

using namespace std;

using lint = long long;

using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

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

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

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

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

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

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

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

int main() {
  cin.tie(0)->sync_with_stdio(0);
  vector<int> dx6 = {1, 1, 0, -1, -1, 0};
  vector<int> dy6 = {-1, 0, 1, 1, 0, -1};
  map<pair<int, int>, int> dist;
  dist[{0, 0}] = 0;
  queue<pair<int, int>> q;
  q.emplace(0, 0);
  bool fin = false;
  while (!q.empty()) {
    auto [i, j] = q.front();
    q.pop();
    rep(k, 6) {
      int ny = i + dy6[k];
      int nx = j + dx6[k];
      if (!(-1000 <= ny and ny <= 1000 and -1000 <= nx and nx <= 1000)) continue;
      if (!dist.contains({ny, nx})) {
        dist[{ny, nx}] = dist[{i, j}] + 1;
        q.emplace(ny, nx);
      }
    }
  }

  int n;
  in(n);
  rep(i, n) {
    int x, y;
    in(x, y);
    out(dist[{y, x}]);
  }
}
accuracy: 1
time_ms: 3670
memory_kb: 253696
final_rank: 20

code_snippet: #include <bits/stdc++.h>
const int OFFSET = 1000;
int D[2010][2010];
bool in(int x, int y) {
    return -1000 <= x and x <= 1000 and -1000 <= y and y <= 1000;
}
void set(int x, int y, int v) {
    assert(-1000 <= x and x <= 1000);
    assert(-1000 <= y and y <= 1000);
    D[x + OFFSET][y + OFFSET] = v;
}
int get(int x, int y) {
    assert(-1000 <= x and x <= 1000);
    assert(-1000 <= y and y <= 1000);
    return D[x + OFFSET][y + OFFSET];
}
const int dx[]{0,-1,-1,0,1,1}, dy[]{1,1,0,-1,-1,0};
int main() {
    for (int i = -1000 ; i <= 1000 ; i++) for (int j = -1000 ; j <= 1000 ; j++) {
        set(i, j, -1);
    }
    set(0, 0, 0);
    std::queue<std::pair<int, int>> que;
    que.push({0, 0});
    while (que.size()) {
        const auto [x, y] = que.front();
        que.pop();
        const int dist = get(x, y);
        for (int d = 0 ; d < 6 ; d++) {
            const int nx = x + dx[d], ny = y + dy[d];
            if (in(nx, ny) and get(nx, ny) == -1) {
                set(nx, ny, dist + 1);
                que.push({nx, ny});
            }
        }
    }
    int N;
    std::cin >> N;
    while (N--) {
        int x, y;
        std::cin >> x >> y;
        std::cout << get(x, y) << '\n';
    }
}
accuracy: 1
time_ms: 60
memory_kb: 19248
final_rank: 5

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

int main() {
    int INF = int(1e9);
    vector<vector<int>> dist(2001, vector<int>(2001,INF));
    using P = pair<int, int>;
    queue<P> que;
    que.push({1000,1000});
    dist[1000][1000] = 0;
    int dx[] = {1,0,-1,-1,0,1};
    int dy[] = {0,1,1,0,-1,-1};

    while(que.size()) {
        auto [x,y] = que.front(); que.pop();
        for (int k=0; k<6; k++) {
            int nx = x+dx[k], ny = y+dy[k];
            if (nx<0 || 2001<=nx || ny<0 || 2001<=ny) continue;
            if (dist[x][y]+1 < dist[nx][ny]) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    

    int N;
    cin >> N;
    while(N--) {
        int x, y;
        cin >> x >> y;
        x+=1000; y+=1000;
        cout << dist[x][y] << endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 19328
final_rank: 4

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,start,end) for (ll i = start;i >= (ll)(end);i--)
#define repn(i,end) for(ll i = 0; i <= (ll)(end); i++)
#define reps(i,start,end) for(ll i = start; i < (ll)(end); i++)
#define repsn(i,start,end) for(ll i = start; i <= (ll)(end); i++)
#define each(p,a) for(auto &p:a)
typedef vector<ll> vll;
typedef vector<pair<ll ,ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef set<ll> sll;
typedef map<ll , ll> mpll;
typedef pair<ll ,ll> pll;
typedef tuple<ll , ll , ll> tpl3;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (ll)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
inline ll lfloor(ll x,ll m){return (x - ((x % m+ m)%m))/m;}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
//0indexed
inline ll topbit(ll a){assert(a != 0);return 63 - __builtin_clzll(a);}
inline ll smlbit(ll a){assert(a != 0);return __builtin_ctzll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,1,1,0,-1,-1};
vector<ll> _yo = {1,0,-1,-1,0,1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
	
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

void solve(ll x,ll y){

}

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

	map<pll,ll> mp;
	queue<pll> que;
	mp[{0,0}] = 0;
	que.push({0,0});
	while(!que.empty()){
		auto[nowy,nowx] = que.front();
		que.pop();
		if(abs(nowy) >1000 or abs(nowx)> 1000)continue;
		rep(p,6){
			ll ny = nowy + _ta[p];
			ll nx = nowx + _yo[p];
			if(!mp.contains({ny,nx})){
			  mp[{ny,nx}]= mp[{nowy,nowx}]+1;
				que.push({ny,nx});
			}
		}

	}
	LL(n);
	rep(i,n){
		LL(x,y);
		cout << mp[{y,x}] << endl;
	}
}
accuracy: 1
time_ms: 3300
memory_kb: 254208
final_rank: 19

code_snippet: #include <iostream>
#include <utility>
#include <queue>
#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 = 1000001000;
constexpr int INTMAX = 2147483647;
constexpr ll LLMAX = 9223372036854775807;
constexpr ll LLINF = 4450000000011100000;

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

bool isin(int x, int y) {
  return -1000 <= x && x <= 1000 && -1000 <= y && y <= 1000;
}

void solve() {
  int x, y; cin >> x >> y;

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

  cout << dist[OFFSET+x][OFFSET+y] << endl;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  for (int i=0; i<n; i++) {
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 2390
memory_kb: 19232
final_rank: 14

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

using i64 = long long;

constexpr int V = 1000;
int dis[2 * V + 1][2 * V + 1];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    memset(dis, -1, sizeof(dis));
    vector<pair<int, int>> q{{0, 0}};
    dis[V][V] = 0;

    for (int i = 0; i < q.size(); i++) {
        auto [x, y] = q[i];
        for (auto [dx, dy] : {pair(1, 0), {0, 1}, {-1, 1}, {-1, 0}, {0, -1}, {1, -1}}) {
            int nx = x + dx, ny = y + dy;
            if (abs(nx) <= 1000 && abs(ny) <= 1000 && dis[nx + V][ny + V] == -1) {
                dis[nx + V][ny + V] = dis[x + V][y + V] + 1;
                q.emplace_back(nx, ny);
            }
        }
    }

    int t;
    cin >> t;

    auto solve = [&]() {
        int x, y;
        cin >> x >> y;
        cout << dis[x + V][y + V] << '\n';
    };

    while (t--) {
        solve();
    }
    
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 53396
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int C = 1100;
const int INF = 1e9;
const vector<int> dx = {0, 1, 1, 0, -1, -1};
const vector<int> dy = {1, 0, -1, -1, 0, 1};
int main() {
  int MAX = 2100;
  int zero = 1010;
  vector<vector<int>> dist(MAX, vector<int> (MAX, INF));
  dist[zero][zero] = 0;
  queue<pair<int, int>> Q;
  Q.emplace(zero, zero);
  while (!Q.empty()) {
    auto [tx, ty] = Q.front();
    Q.pop();
    for (int i = 0; i < 6; i++) {
      int nx = tx + dx[i], ny = ty + dy[i];
      if (0 <= nx && nx <= zero * 2 && 0 <= ny && ny <= zero * 2 && dist[nx][ny] == INF) {
        dist[nx][ny] = dist[tx][ty] + 1;
        Q.emplace(nx, ny);
      }
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    cout << dist[zero + x][zero + y] << '\n';
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 20688
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (auto i = (m); i < (n); i++)
#define rept(i, n) rep(i, 0, n)
#define repr(i, m, n) for (auto i = (m); i-- > (n);)
#define reptr(i, n) repr(i, 0, n)
#define all(x) begin(x), end(x)
#define sz(x) (int)size(x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;

uint dist[2001][2001];
const int dx[] = {1, 0, -1, -1, 0, 1};
const int dy[] = {0, 1, 1, 0, -1, -1};
pii que[2001 * 2001], *p = que, *q = que;

void solve() {
	memset(dist, -1, sizeof(dist));
	dist[1000][1000] = 0;
	*q++ = pii(1000, 1000);
	while (p != q) {
		auto [x, y] = *p++;
		rept(i, 6) {
			uint x2 = x + dx[i], y2 = y + dy[i];
			if (x2 < 2001 and y2 < 2001 and dist[x2][y2] > dist[x][y] + 1) {
				dist[x2][y2] = dist[x][y] + 1;
				*q++ = pii(x2, y2);
			}
		}
	}

	int n; scanf("%d", &n);
	while (n--) {
		int x, y; scanf("%d%d", &x, &y);
		printf("%d\n", dist[x+1000][y+1000]);
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n = 1;
	// scanf("%d", &n);
	while (n--) solve();
}
accuracy: 1
time_ms: 40
memory_kb: 50500
final_rank: 10

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

const int di[6]{1, 1, 0, 0, -1, -1};
const int dj[6]{0, -1, -1, 1, 0, 1};
int ans[2007][2007];

void bfs() {
  queue<tuple<int, int, int>> q;
  q.emplace(1000, 1000, 0);
  memset(ans, -1, sizeof ans);
  ans[1000][1000] = 0;

  while (!q.empty()) {
    const auto [i, j, dist] = q.front();
    q.pop();

    for (int d = 0; d < 6; d++) {
      const int i2 = i + di[d];
      const int j2 = j + dj[d];

      if (i2 > 2000 || j2 > 2000) continue;
      if (i2 < 0 || j2 < 0) continue;
      if (ans[i2][j2] != -1) continue;

      ans[i2][j2] = dist + 1;
      q.emplace(i2, j2, dist + 1);
    }
  }
}

int main() {
  int t;
  cin >> t;

  bfs();

  while (t--) {
    int i, j;
    cin >> i >> j;
    i += 1000;
    j += 1000;
    cout << ans[i][j] << endl;
  }
}
accuracy: 1
time_ms: 40
memory_kb: 19240
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
int tx,ty;
int dx[6]={1,0,-1,-1,0,1},dy[6]={0,1,1,0,-1,-1};
void solve(){
  cin>>tx>>ty;
  vector dist(2<<10,vector<int>(2<<10,-1));
  int x0=1001,y0=1001;
  dist[x0][y0]=0;
  queue<pair<int,int>>que;
  que.push({x0,y0});
  while(!que.empty()){
    auto[x,y]=que.front();
    que.pop();
    for(int dir=0;dir<6;++dir){
      int xx=x+dx[dir],yy=y+dy[dir];
      if(!(0<=xx&&xx<=2*x0&&0<=yy&&yy<=2*y0))continue;
      if(dist[xx][yy]==-1){
        dist[xx][yy]=dist[x][y]+1;
        que.push({xx,yy});
      }
    }
  }
  cout<<dist[x0+tx][y0+ty]<<'\n';
}
int main(){
  cin.tie(0)->sync_with_stdio(0);
  int n;cin>>n;
  while(n--)solve();
}
accuracy: 1
time_ms: 5620
memory_kb: 19820
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> VP;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
#define OUT(n) cout << n << "\n"
//constexpr ll MOD=998244353;
//constexpr ll MOD=1000000007;
//constexpr ll INF=2e18;


int main() {
  ll N;
  cin >> N;

  VVI xy(2010, VI(2010, -1));

  xy[1000][1000] = 0;

  queue<int> q;
  q.push(10001000);
  int dx[] = {1, 0, -1, 0, -1, 1};
  int dy[] = {0, 1, 0, -1, 1, -1};
  while(!q.empty()){
    int x = q.front() / 10000;
    int y = q.front() % 10000;
    q.pop();
    REP(i, 6){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx < 0 || nx > 2000 || ny < 0 || ny > 2000) continue;
      if(xy[nx][ny] != -1) continue;
      xy[nx][ny] = xy[x][y] + 1;
      q.push(nx * 10000 + ny);
    }
  }

  REP(i, N){
    ll x, y;
    cin >> x >> y;
    OUT(xy[x + 1000][y + 1000]);
  }
}
accuracy: 1
time_ms: 60
memory_kb: 35036
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF=9e18;

int main() {
    ll N;
    cin>>N;
    vector<ll> x (N);
    vector<ll> y (N);

    for (ll a = 0; a < N; a++){
        cin>>x[a]>>y[a];
    }
    vector<vector<ll>> hai (2100,vector<ll>(2100,-1));
    hai[1000][1000]=0;
    queue<pair<ll,ll>>q;
    q.push({1000,1000});
    vector<ll> dx={0,1,0,-1,-1,1};
    vector<ll> dy={1,0,-1,0,1,-1};

    while(1){
        if(q.empty()){
            break;
        }
        ll nowx=q.front().first;
        ll nowy=q.front().second;
        ll kyori=hai[nowx][nowy];
        q.pop();
        for (ll a = 0; a < 6; a++){
            ll nextx=nowx+dx[a];
            ll nexty=nowy+dy[a];
            if(0<=nextx&&nextx<=2000&&0<=nexty&&nexty<=2000&&hai[nextx][nexty]==-1){
                hai[nextx][nexty]=kyori+1;
                q.push({nextx,nexty});
            }
        }

    }
    for (ll a = 0; a < N; a++){
        ll xxx=x[a]+1000;
        ll yyy=y[a]+1000;
        cout<<hai[xxx][yyy]<<endl;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 37984
final_rank: 9

code_snippet: #include<bits/stdc++.h> 
using namespace std;
using ll=long long int;
using Int=__int128;
#define ALL(A) A.begin(),A.end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
template<typename T> constexpr int bitUP(T x,int a){return (x>>a)&1;}
//→　↓　←　↑ 
int dh[6]={0,1,0,-1,1,-1}, dw[6]={1,0,-1,0,-1,1};
//右上から時計回り
//int dh[8]={-1,0,1,1,1,0,-1,-1}, dw[8]={1,1,1,0,-1,-1,-1,0};
long double EPS = 1e-6;
long double PI = acos(-1);
const ll INF=(1LL<<62);
const int MAX=(1<<30);
//constexpr ll MOD=1000000000+7;
constexpr ll MOD=998244353;


inline void bin101(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

using pii=pair<int,int>;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using psi=pair<string,int>;
using pis=pair<int,string>;
using psl=pair<string,ll>;
using pls=pair<ll,string>;
using pss=pair<string,string>;
using pII=pair<Int,Int>;

template<class T>
using minimum_queue=priority_queue<T,vector<T>,greater<T>>;

using Graph=vector<vector<int>>;

template<class T >
struct Edge {
    int from, to;
    T cost;
    Edge(int from,int to,T cost):from(from),to(to),cost(cost){}
    Edge()=default;

    bool operator<(const Edge<T> &e){
        return cost<e.cost;
    }
    bool operator<=(const Edge<T> &e){
        return cost<=e.cost;
    }
};


//https://kenkoooo.hatenablog.com/entry/2016/11/30/163533
//__int128 出力
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
            __uint128_t tmp = value < 0 ? -value : value;
            char buffer[128];
            char *d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}
//__int128 入力
inline istream &operator>>(istream &is,Int &x) {
    auto parse=[](string &s){
        __int128 ret = 0;
        for (size_t i = 0; i < s.length(); i++){
            if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0';
        }
        if(s.size() and s[0]=='-') ret*=-1;
        return ret;
    };
    string s;
    is>>s;
    x=parse(s);
	return is;
}

template<typename T >
struct edge {
	int to;
	T cost;
	edge()=default;
	edge(int to, T cost) : to(to), cost(cost) {}

};
template<typename T>
using WeightGraph=vector<vector<edge<T>>>;

template<typename T>
void CinGraph(int M,WeightGraph<T> &g,bool directed=false,bool index1=true){
    while(M--){
        int s,t;
        T cost;
        cin>>s>>t>>cost;
        if(index1) s--,t--;
        g[s].emplace_back(t,cost);
        if(not directed) g[t].emplace_back(s,cost);
    }
}

void CinGraph(int M,Graph &g,bool directed=false,bool index1=true){
    while(M--){
        int s,t;
        cin>>s>>t;
        if(index1) s--,t--;
        g[s].push_back(t);
        if(not directed) g[t].push_back(s);
    }
}


//0-indexed vector cin
template<typename T>
inline istream &operator>>(istream &is,vector<T> &v) {
    for(size_t i=0;i<v.size();i++) is>>v[i];
	return is;
}
 
//0-indexed vector cin
template<typename T>
inline istream &operator>>(istream &is,vector<vector<T>> &v) {
    for(size_t i=0;i<v.size();i++){
        is>>v[i];
    }
    return is;
}
//vector cout
template<typename T>
inline ostream &operator<<(ostream &os,const vector<T> &v) {
    bool sp=true;
    if(string(typeid(T).name())=="c") sp=false;
    for(size_t i=0;i<v.size();i++){
        if(i and sp) os<<" ";
        os<<v[i];
    }
    return os;
}
//vector<vector> cout
template<typename T>
inline ostream &operator<<(ostream &os,const vector<vector<T>> &v) {
    for(size_t i=0;i<v.size();i++){
        os<<v[i];
        if(i+1!=v.size()) os<<"\n";
    }
    return os;
}

//Graph out
template<typename T>
inline ostream &operator<<(ostream &os,const Graph &g) {
    for(size_t i=0;i<g.size();i++){
        for(int to:g[i]){
            os<<i<<"->"<<to<<" ";
        }
        os<<endl;
    }
    return os;
}

//WeightGraph out
template<typename T>
inline ostream &operator<<(ostream &os,const WeightGraph<T> &g) {
    for(size_t i=0;i<g.size();i++){
        for(auto e:g[i]){
            os<<i<<"->"<<e.to<<"("<<e.cost<<") ";
        }
        os<<endl;
    }
    return os;
}


//要素数n 初期値x
template<typename T>
inline vector<T> vmake(size_t n,T x){
	return vector<T>(n,x);
}

//a,b,c,x data[a][b][c] 初期値x
template<typename... Args>
auto vmake(size_t n,Args... args){
	auto v=vmake(args...);
	return vector<decltype(v)>(n,move(v));
}
template<typename V,typename T>
void fill(V &v,const T value){
    v=value;
}

template<typename V,typename T>
void fill(vector<V> &vec,const T value){
    for(auto &v:vec) fill(v,value);
}

//pair cout
template<typename T, typename U>
inline ostream &operator<<(ostream &os,const pair<T,U> &p) {
	os<<p.first<<" "<<p.second;
	return os;
}
 
//pair cin
template<typename T, typename U>
inline istream &operator>>(istream &is,pair<T,U> &p) {
	is>>p.first>>p.second;
	return is;
}
 
//ソート
template<typename T>
inline void vsort(vector<T> &v){
    sort(v.begin(),v.end());
}
 
//逆順ソート
template<typename T>
inline void rvsort(vector<T> &v){
	sort(v.rbegin(),v.rend());
}

//1ビットの数を返す
inline int popcount(int x){
	return __builtin_popcount(x);
}
//1ビットの数を返す
inline int popcount(ll x){
	return __builtin_popcountll(x);
}
template<typename T>
inline void Compress(vector<T> &C){
    sort(C.begin(),C.end());
    C.erase(unique(C.begin(),C.end()),C.end());
}
template<typename T>
inline int lower_idx(const vector<T> &C,T value){
    return lower_bound(C.begin(),C.end(),value)-C.begin();
}
template<typename T>
inline int upper_idx(const vector<T> &C,T value){
    return upper_bound(C.begin(),C.end(),value)-C.begin();
}
//時計回りに90度回転
template<typename T>
inline void rotate90(vector<vector<T>> &C){
    vector<vector<T>> D(C[0].size(),vector<T>(C.size()));
    for(int h=0;h<C.size();h++){
        for(int w=0;w<C[h].size();w++){
            D[w][C.size()-1-h]=C[h][w];
        }
    }
    C=D;
}
//0indexを想定
bool OutGrid(ll h,ll w,ll H,ll W){
    return (h>=H or w>=W or h<0 or w<0);
}

void NO(){
    cout<<"NO"<<"\n";
}
void YES(){
    cout<<"YES"<<"\n";
}
void No(){
    cout<<"No"<<"\n";
}
void Yes(){
    cout<<"Yes"<<"\n";
}
namespace overflow{
    template<typename T>
    T max(){
        return numeric_limits<T>::max();
    }
    template<typename T>
    T ADD(T a,T b){
        T res;
        return __builtin_add_overflow(a,b,&res)?max<T>():res;
    }
    template<typename T>
    T MUL(T a,T b){
        T res;
        return __builtin_mul_overflow(a,b,&res)?max<T>():res;
    }
};
using namespace overflow;
struct mint{
    using u64=uint_fast64_t;
    u64 a;
    constexpr mint() :a(0){}
    constexpr mint(ll x) :a((x>=0)?(x%MOD):(x%MOD+MOD) ) {}

    inline constexpr mint operator+(const mint rhs)const noexcept{
        return mint(*this)+=rhs;
    }
    inline constexpr mint operator-(const mint rhs)const noexcept{
        return mint(*this)-=rhs;
    }
    inline constexpr mint operator*(const mint rhs)const noexcept{
        return mint(*this)*=rhs;
    }
    inline constexpr mint operator/(const mint rhs)const noexcept{
        return mint(*this)/=rhs;
    }
    inline constexpr mint operator+(const ll rhs) const noexcept{
        return mint(*this)+=mint(rhs);
    }
    inline constexpr mint operator-(const ll rhs)const noexcept{
        return mint(*this)-=mint(rhs);
    }
    inline constexpr mint operator*(const ll rhs)const noexcept{
        return mint(*this)*=mint(rhs);
    }
    inline constexpr mint operator/(const ll rhs)const noexcept{
        return mint(*this)/=mint(rhs);
    }

    inline constexpr mint &operator+=(const mint rhs)noexcept{
        a+=rhs.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    inline constexpr mint &operator-=(const mint rhs)noexcept{
        if(rhs.a>a) a+=MOD;
        a-=rhs.a;
        return *this;
    }
    inline constexpr mint &operator*=(const mint rhs)noexcept{
        a=(a*rhs.a)%MOD;
        return *this;
    }
    inline constexpr mint &operator/=(mint rhs)noexcept{
        a=(a*rhs.inverse().a)%MOD;
        return *this;
    }
    inline constexpr mint &operator+=(const ll rhs)noexcept{
        return *this+=mint(rhs);
    }
    inline constexpr mint &operator-=(const ll rhs)noexcept{
        return *this-=mint(rhs);
    }
    inline constexpr mint &operator*=(const ll rhs)noexcept{
        return *this*=mint(rhs);
    }
    inline constexpr mint &operator/=(const ll rhs)noexcept{
        return *this/=mint(rhs);
    }

    inline constexpr mint operator=(const ll x)noexcept{
        a=(x>=0)?(x%MOD):(x%MOD+MOD);
        return *this;
    }

    inline constexpr bool operator==(const mint p)const noexcept{
        return a==p.a;
    }

    inline constexpr bool operator!=(const mint p)const noexcept{
        return a!=p.a;
    }

    inline constexpr mint pow(ll N) const noexcept{
        mint ans(1LL),p(a);
        while(N>0){
            if(bitUP(N,0)){
                ans*=p;
            }
            p*=p;
            N>>=1;
        }
        return ans;
    }
    inline constexpr mint inverse() const noexcept{
        return pow(MOD-2);
    }

};
inline constexpr mint operator+(const ll &a,const mint &b)noexcept{
    return mint(a)+=b;
}
inline constexpr mint operator-(const ll &a,const mint &b)noexcept{
    return mint(a)-=b;
}
inline constexpr mint operator*(const ll &a,const mint &b)noexcept{
    return mint(a)*=b;
}
inline constexpr mint operator/(const ll &a,const mint &b)noexcept{
    return mint(a)/=b;
}
//cout
inline ostream &operator<<(ostream &os,const mint &p) {
    return os<<p.a;
}

//cin
inline istream &operator>>(istream &is,mint &p) {
    ll t;
    is>>t;
    p=t;
    return is;
}

struct Binominal{
    vector<mint> fac,finv,inv; //fac[n]:n! finv:(n!)の逆元
    int sz;
    Binominal(int n=10) :sz(1){
        if(n<=0) n=10;
        init(n);
    }
    inline void init(int n){
        fac.resize(n+1,1);
        finv.resize(n+1,1);
        inv.resize(n+1,1);
        for(int i=sz+1;i<=n;i++){
            fac[i]=fac[i-1]*i;
            inv[i]=MOD-inv[MOD%i]*(MOD/i);
            finv[i]=finv[i-1]*inv[i];
        }
        sz=n;
    }
    //nCk(n,k<=N) をO(1)で求める
    inline mint com(int n,int k){
        if(n<k) return mint(0);
        if(n<0 || k<0) return mint(0);
        if(n>sz) init(n);
        return fac[n]*finv[k]*finv[n-k];
    }
    //nCk(k<=N) をO(k)　で求める 
    inline mint rcom(ll n,int k){
        if(n<0 || k<0 || n<k) return mint(0);
        if(k>sz) init(k);
        mint ret(1);
        for(int i=0;i<k;i++){
            ret*=n-i;
        }
        ret*=finv[k];
        return ret;
    }

    //重複組み合わせ n種類のものから重複を許してk個を選ぶ
    //〇がn個,|がk個
    inline mint h(int n,int k){
        return com(n+k-1,k);
    }
    //順列の公式
    inline mint P(int n,int k){
        if(n<k) return 0;
        if(n>sz) init(n);
        return fac[n]*finv[n-k];
    }

};
vector<int> Subset(int S,bool zero=false,bool full=false){
    vector<int> ret;
    int now=(S-1)&S;
    if(full and S){
        ret.push_back(S);
    }
    do{
        ret.push_back(now);
        now=(now-1)&S;
    }while(now!=0);
    if(zero){
        ret.push_back(0);
    }
    return ret;
}
template<typename T>
T SUM(const vector<T> &v,int s,int t){
    chmax(s,0);
    chmin(t,int(v.size())-1);
    if(s>t) return 0;
    if(s==0) return v[t];
    else return v[t]-v[s-1];
}
template<typename T>
void buildSUM(vector<T> &v){
    for(size_t i=1;i<v.size();i++){
        v[i]+=v[i-1];
    }
    return;
}

template<class T>
inline bool operator==(const vector<T> &v,const T x)noexcept{
    for(T a:v){
        if(a!=x) return false;
    }
    return true;
}
template<class T>
inline bool operator!=(const vector<T> &v,const T x)noexcept{
    return not (v==x);
}

template<class T>
inline void operator-=(vector<T> &v,const T x)noexcept{
    for(T &a:v){
        a-=x;
    }
}

template<class T>
inline void operator+=(vector<T> &v,const T x)noexcept{
    for(T &a:v){
        a+=x;
    }
}

template<class T>
inline T extract(queue<T> &que){
    assert(que.size());
    T x=que.front();
    que.pop();
    return x;
}

template<class T>
inline T extract(priority_queue<T> &pq){
    assert(pq.size());
    T x=pq.top();
    pq.pop();
    return x;
}

template<class T>
inline T extract(minimum_queue<T> &pq){
    assert(pq.size());
    T x=pq.top();
    pq.pop();
    return x;
}

template<class T>
inline T extract(stack<T> &st){
    assert(st.size());
    T x=st.top();
    st.pop();
    return x;
}

template<class S,class T>
inline void append(vector<S> &u,const vector<T> &v){
    for(T x:v){
        u.push_back(x);
    }
}
inline ll mask(int x){
    return (1LL<<x)-1;
}

int half=2500;
auto dist=vmake(5000,5000,MAX);


void solve(){
    queue<pii> que;
    dist[half][half]=0;
    que.push({half,half});

    while(true){
        pii now=extract(que);
        int h=now.first,w=now.second;
        for(int i=0;i<6;i++){
            int nh=h+dh[i],nw=w+dw[i];
            if(OutGrid(nh,nw,5000,5000)) continue;
            if(dist[nh][nw]!=MAX) continue;
            dist[nh][nw]=dist[h][w]+1;
            que.push({nh,nw});
        }
        if(que.empty()) break;
    }

    int N;
    cin>>N;
    while(N--){
        int x,y;
        cin>>x>>y;
        cout<<dist[x+half][y+half]<<"\n";
    }
}

int main(){
    bin101();
    int T=1;
    //cin>>T;
    while(T--) solve();
}
accuracy: 1
time_ms: 440
memory_kb: 101360
final_rank: 13

code_snippet: #ifdef DEBUG
#include"stdlibrary.h"
#else
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#endif
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using ll=long long;
using datas=std::pair<ll,ll>;
using ddatas=std::pair<long double,long double>;
using tdata=std::pair<ll,datas>;
using vec=std::vector<ll>;
using mat=std::vector<vec>;
using pvec=std::vector<datas>;
using pmat=std::vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
// #define For(i,a,b) if(const std::int64_t _iterate_from=a,_iterate_to=b;_iterate_from<_iterate_to)for(const std::int64_t i:std::views::iota(_iterate_from,_iterate_to))
#define For(i,a,b) for(ll i=a;i<b;++i)
#define bFor(i,b,a) for(ll i=b-1;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) std::begin(v),std::end(v)
#define allr(v) std::rbegin(v),std::rend(v)
#define vsort(v) std::sort(all(v))
#define vrsort(v) std::sort(allr(v))
#define uniq(v) vsort(v),(v).erase(std::unique(all(v)),std::end(v))
#define endl "\n"
#define popcount __builtin_popcountll
#define print(x) std::cout<<x<<endl
#define printyes print("Yes")
#define printno print("No")
#define printYES print("YES")
#define printNO print("NO")
#define output(v) do{bool f=0;for(auto outi:v){std::cout<<(f?" ":"")<<outi;f=1;}std::cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
// constexpr ll mod=1000000007;
constexpr ll mod=998244353;
constexpr ll inf=1LL<<60;
constexpr long double eps=1e-9;
const long double PI=acosl(-1);
template<class T,auto x=T::mod()> std::ostream& operator<<(std::ostream& os,const T& v){return os<<v.val();}
template<class T> std::ostream& operator<<(std::ostream& os,const std::vector<T>& v);
template<class T,class F> std::ostream& operator<<(std::ostream& os,const std::set<T,F>& v);
template<class T,class F> std::ostream& operator<<(std::ostream& os,const std::multiset<T,F>& v);
template<class T,class E,class F> std::ostream& operator<<(std::ostream& os,const std::map<T,E,F>& v);
template<class T,class E> std::ostream& operator<<(std::ostream& os,const std::pair<T,E>& p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T> std::ostream& operator<<(std::ostream& os,const std::vector<T>& v){
  os<<"{";bool f=false;
  for(auto& x:v){if(f)os<<",";os<<x;f=true;}
  os<<"}";
  return os;
}
template<class T,class F> std::ostream& operator<<(std::ostream& os,const std::set<T,F>& v){
  os<<"{";bool f=false;
  for(auto& x:v){if(f)os<<",";os<<x;f=true;}
  os<<"}";
  return os;
}
template<class T,class F> std::ostream& operator<<(std::ostream& os,const std::multiset<T,F>& v){
  os<<"{";bool f=false;
  for(auto& x:v){if(f)os<<",";os<<x;f=true;}
  os<<"}";
  return os;
}
template<class T,class E,class F> std::ostream& operator<<(std::ostream& os,const std::map<T,E,F>& v){
  os<<"{";bool f=false;
  for(auto& x:v){if(f)os<<",";os<<x;f=true;}
  os<<"}";
  return os;
}
template<class T> inline bool chmax(T& a,const T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,const T b){bool x=a>b;if(x)a=b;return x;}
#ifdef DEBUG
void debugg(){std::cout<<endl;}
template<class T,class... Args>void debugg(const T& x,const Args&... args){std::cout<<" "<<x;debugg(args...);}
#define debug(...) cout<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debugg(__VA_ARGS__)
#else
#define debug(...) (void(0))
#endif

inline void startupcpp(void) noexcept{
  cin.tie(0)->sync_with_stdio(0);
  cout<<fixed<<setprecision(15);
}

ll modinv(ll a,const ll m=mod) noexcept{
  ll b=m,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+m)%m;
}

ll moddevide(const ll a,const ll b) noexcept{return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(const ll n,const ll r){
  if(n<r||r<0)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1)modncrlistp[i]=modncrlistp[i-1]*i%mod;
    modncrlistm[n]=modinv(modncrlistp[n]);
    for(i=n;i>size;--i)modncrlistm[i-1]=modncrlistm[i]*i%mod;
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n,const ll m=mod){
  if(n<0)return 0;
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%m;
    a=a*a%m;
    n>>=1;
  }
  return res;
}

constexpr ll gcd(const ll a,const ll b) noexcept{return (!b)?abs(a):(a%b==0)?abs(b):gcd(b,a%b);}
constexpr ll lcm(const ll a,const ll b) noexcept{return a/gcd(a,b)*b;}

// #include<atcoder/all>
// using mint=atcoder::modint998244353;
// void operator>>(istream& is,mint& v){long long x;is>>x;v=x;}

ll N,M,K,H,W,Q,A,B,C,D;
string s,t;
ll ans;
int dist[4000][4000];
int main(){
  startupcpp();
// int codeforces;cin>>codeforces;while(codeforces--){
  constexpr ll dx[6]={1,0,-1,-1,0,1},dy[6]={0,1,1,0,-1,-1};
  queue<tuple<ll,ll,ll>> que;
  que.emplace(1,2000,2000);
  while(!que.empty()){
    auto [d,x,y]=que.front();que.pop();
    if(dist[x][y]!=0)continue;
    dist[x][y]=d;
    rep(i,6){
      ll nx=x+dx[i],ny=y+dy[i];
      if(nx<0||nx>=4000||ny<0||ny>=4000)continue;
      if(dist[nx][ny]==0)que.emplace(d+1,nx,ny);
    }
  }
  cin>>N;
  while(N--){
    cin>>A>>B;
    print(dist[A+2000][B+2000]-1);
  }
// }
}
accuracy: 1
time_ms: 230
memory_kb: 66860
final_rank: 12