Problem:
忍ぶべし
あなたにはあるミッションが課せられている．それは，無限に広がる二次元グリッド上にある降下地点マス
(sx, sy)
へと人員を送り込み，その後敵陣に悟られることがないよう移動をサポートし，敵の基地があるマス
(gx, gy)
への潜入を成功させることだ．あなたはこの重要なミッションの潜入役を，忍び込みのプロ・忍小宮に託した．
忍小宮は上下左右の隣接した 4 マスのいずれかに移動することを繰り返し，敵の基地を目指す．また，迅速に任務を遂行するため，降下地点から敵の基地まで必ず最短距離となるよう移動を行う．
事前の偵察によるとこの 2 次元グリッド上には敵のセンサーが
N
個あり，
i
番目のセンサーは
(x
i
, y
i
)
を中心として 1 辺
2r
i
+ 1
の正方形領域，すなわち
|x - x
i
| ≤ r
i
かつ
|y - y
i
| ≤ r
i
を満たすような全てのマス
(x, y)
をカバーしていることがわかっている．忍小宮は 1 つ以上のセンサーにカバーされている領域に入ると敵に発見されてしまう．
ここで問題になるのは，現在のセンサーの配置ではどうしても忍小宮が最短距離の移動で敵の基地まで辿り着けない可能性があることだ．この場合，あなたはサポート役としてセンサーを破壊しなければならない．リスク・コストを軽減するため，破壊するセンサーの個数はできる限り少なくしたい．
例として，入力サンプルの 4 番目のデータセットは図 C-1 のようになる．図 C-2 のように 3 つのセンサーを取り除くことにより，忍小宮は最短距離で敵の基地まで辿り着くことができるようになり，この例ではこれが最小個数である．
図 C-1 入力サンプル 4 番目のデータセットの配置
図 C-2 入力サンプル 4 番目のデータセットにおける最小個数の例
勘のいいあなたはお気付きだろう．どうしてもセンサーに検知されてしまう忍小宮より，センサーに検知されずに破壊できるあなたの方が，忍び込みスキルが高いということに．そう，何を隠そう忍小宮は自分を忍び込みのプロだと勘違いしているだけのただの一般人であり，あなたこそが忍び込ませのプロ・忍駒瀬だったのだ．何も知らない忍小宮には気付かれず密やかに必要最低限のセンサーを破壊し，あたかも自分は忍び込みのプロなのだと忍小宮に思い込ませることが，忍び込ませのプロとしてのあなたの矜恃だ．まずはプロとしてあらかじめコストを見積もるため，忍小宮の任務を成功させるには最小でいくつのセンサーを破壊する必要があるか求めて欲しい．
Input
入力は 100 個以下のデータセットからなる． 各データセットは次の形式で表される．
N
sx
sy
gx
gy
x
1
y
1
r
1
...
x
N
y
N
r
N
最初の行はセンサーの個数
N
(
1 ≤ N ≤ 10
5
) を表す整数からなる．
2 行目の
sx
,
sy
は忍小宮の降下地点
(sx, sy)
を，
gx
,
gy
は敵の基地の位置
(gx, gy)
をそれぞれ表し，
1 ≤ sx, gx ≤ 1000
，
1 ≤ sy, gy ≤ 1000
を満たす．
続く
N
行の
i
行目は
i
番目のセンサーの情報であり，センサーが位置
(x
i
, y
i
)
を中心に 1 辺
2r
i
+1
の正方形領域をカバーしていることを表す．
1 ≤ x
i
≤ 1000
，
1 ≤ y
i
≤ 1000
，
0 ≤ r
i
≤ 1000
をそれぞれ満たす．
ここで，
(sx, sy)
と
(gx, gy)
は必ず異なるマスである．
入力の終わりは 1 つのゼロからなる行で表される．
Output
各データセットについて，忍小宮が
(sx, sy)
から
(gx, gy)
までセンサー領域を通らず最短距離で移動できるようにするために破壊する必要があるセンサーの最小個数を 1 行に出力せよ．
Sample Input
3
2 2 4 5
1 1 1
1 5 2
4 3 1
5
1 2 1 1
5 3 2
8 8 6
6 9 2
1 7 3
4 4 1
1
3 7 1 1
2 5 10
9
25 30 90 100
50 50 15
60 30 20
70 35 15
90 50 10
80 70 20
65 85 15
40 70 35
25 55 20
25 80 20
0
Output for the Sample Input
2
0
1
3

Submitted solutions:

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

ll INF = 1e18;

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;
}

void init() {}
ll n;
void input() { cin >> n; }
void solve() {
    vector<vector<ll>> ans(3005, vector<ll>(3005, 1e18));
    vector<vector<ll>> row(3005, vector<ll>(3005, 0));
    vector<vector<ll>> col(3005, vector<ll>(3005, 0));

    ll sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    if(sy > gy) {
        swap(sx, gx);
        swap(sy, gy);
    }
    sx += 1000;
    sy += 1000;
    gx += 1000;
    gy += 1000;

    ans[sx][sy] = 0;
    for(int i = 0; i < n; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a += 1000;
        b += 1000;
        ll lef = a - c, rig = a + c, top = b - c, bot = b + c;
        if(lef <= sx && sx <= rig && top <= sy && sy <= bot) {
            ans[sx][sy]++;
        }
        row[lef][top]++;
        row[rig + 1][top]--;
        col[(sx < gx ? lef : rig)][top]++;
        col[(sx < gx ? lef : rig)][bot + 1]--;
    }

    for(int i = 0; i < row.size(); i++) {
        for(int j = 1; j < row.size(); j++) {
            row[j][i] += row[j - 1][i];
        }
    }
    for(int i = 0; i < col.size(); i++) {
        for(int j = 1; j < col.size(); j++) {
            col[i][j] += col[i][j - 1];
        }
    }
    if(sx < gx) {
        for(int i = 900; i < 2100; i++) {
            for(int j = 900 ; j < 2100; j++) {
                ans[i][j] = min({ans[i - 1][j] + col[i][j],
                                 ans[i][j - 1] + row[i][j], ans[i][j]});
            }
        }
    } else {
        for(int i = 2100; i >= 900; i--) {
            for(int j = 900; j < 2100; j++) {
                ans[i][j] = min({ans[i + 1][j] + col[i][j],
                                 ans[i][j - 1] + row[i][j], ans[i][j]});
            }
        }
    }

    cout << ans[gx][gy] << endl;
}

ifstream in;
ofstream out;
int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

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

    return 0;
}
accuracy: 1
time_ms: 7870
memory_kb: 215100
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define rrep(i, a, n) for(ll i = a; i >= n; i--)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1LL<<60;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main() {
    ll h = 1005, w = 1005;
    ll b = 1001;
    while(true){
        ll n; cin >> n;
        if(n == 0) break;
        ll f = 0;
        ll sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
        if(sx > gx){
            swap(sx, gx);
            swap(sy, gy);
        }
        if(sy > gy){
            f = 1;
            sy = b-sy;
            gy = b-gy;
        }
        vector<vector<ll>> tate(h,vector<ll>(w,0)), yoko(h,vector<ll>(w,0));
        ll ans = 0;
        rep(i,0,n){
            ll x, y, r; cin >> x >> y >> r;
            if(f) y = b-y;
            if(x-r <= sx && sx <= x+r && y-r <= sy && sy <= y+r){
                ans++;
                continue;
            }
            {
                ll x1 = max(0LL,x-r);
                ll x2 = min(b,x+r);
                ll y1 = max(0LL,y-r);
                ll y2 = min(b,y+r);
                tate[x1][y1]++;
                tate[x2+1][y1]--;
                yoko[x1][y1]++;
                yoko[x1][y2+1]--;
            }
        }
        rep(i,0,b)rep(j,0,b+1) tate[i+1][j] += tate[i][j];
        rep(i,0,b+1)rep(j,0,b) yoko[i][j+1] += yoko[i][j];
        vector<vector<ll>> dp(h,vector<ll>(w,INF));
        dp[sx][sy] = ans;
        rep(i,sx,b+1)rep(j,sy,b+1){
            chmin(dp[i+1][j], dp[i][j]+yoko[i+1][j]);
            chmin(dp[i][j+1], dp[i][j]+tate[i][j+1]);
        }
        cout << dp[gx][gy] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 27136
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <functional>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pii>;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<pll>;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main()
{
    while(1)
    {
        ll n;
        cin >> n;
        if(n==0) break;
        ll sx,sy,gx,gy,x,y,r;
        cin >> sx >> sy >> gx >> gy;

        vector<vl>sen;
        for(int i=0; i<n; i++)
        {
            cin >> x >> y >> r;
            sen.push_back({x,y,r});
        }
        if(sx > gx)
        {
            sx *= -1;
            gx *= -1;
            for(auto &s:sen)
            {
                s[0] *= -1;
            }
        }
        if(sy > gy)
        {
            sy *= -1;
            gy *= -1;
            for(auto &s:sen)
            {
                s[1] *= -1;
            }            
        }

        gx -= sx;
        gy -= sy;
        for(auto &s:sen)
        {
            s[0] -= sx;
            s[1] -= sy;
        }
        sx = sy = 0;

        ll base = 0;
        vector<vl>costd(1001,vl(1001,0)),costr(1001,vl(1001,0)),dp(1001,vl(1001,1e18));
        for(auto s:sen)
        {
            ll x = s[0], y = s[1], r = s[2];
            if(0<y-r && y-r<=gy)
            {
                ll lx = max(x - r, 0LL), rx = max(min(x + r + 1, gx+1),max(x - r, 0LL));
                costr[y-r-1][lx]++;
                costr[y-r-1][rx]--;
                //printf("WALL[%ld,%ld]:[%ld]\n",lx,rx,y-r);
            }
            if(0<x-r && x-r<=gx)
            {
                ll ly = max(y - r, 0LL), ry = max(min(y + r + 1, gy+1),max(y - r, 0LL));
                costd[x-r-1][ly]++;
                costd[x-r-1][ry]--;
                //printf("WALL[%ld]:[%ld,%ld]\n",x-r,ly,ry);
            }
            if(x-r<=sx && sx<=x+r && y-r<=sy && sy<=y+r) base++;
        }
        for(int i=0; i<1000; i++)
        {
            for(int j=0; j<1000; j++)
            {
                costd[i][j+1] += costd[i][j];
                costr[i][j+1] += costr[i][j];
            }
        }
        /*
        for(int i=0; i<5; i++)
        {
            for(int j=0; j<=5; j++)
            {
                cout << costd[i][j] << " ";
            }
            cout << endl;
        }
        for(int i=0; i<5; i++)
        {
            for(int j=0; j<=5; j++)
            {
                cout << costr[i][j] << " ";
            }
            cout << endl;
        }
        */

        dp[0][0] = 0;
        for(int i=0; i<=gx; i++)
        {
            for(int j=0; j<=gy; j++)
            {
                if(i!=0) dp[i][j] = min(dp[i][j],dp[i-1][j]+costd[i-1][j]);
                if(j!=0) dp[i][j] = min(dp[i][j],dp[i][j-1]+costr[j-1][i]);
            }
        }
        cout << dp[gx][gy]+base << endl;
    }
}
accuracy: 1
time_ms: 400
memory_kb: 32604
final_rank: 13

code_snippet: #include <bits/extc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a, b) (((a) + (b) - 1) / (b))
using pii = pair<int,int>;
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7;
// constexpr int mod = 998244353;
 
template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is >> p.first >> p.second; return (is); }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os << p.first << ' ' << p.second; return (os); }
template<class T> istream& operator>>(istream& is, vector<T>& v){ for (auto &&e : v) is >> e; return (is); }
template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for (auto &&e : v) os << e << ' '; return (os); }
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template<typename A, typename B, typename F>
inline bool compare(const A &a, const B &b, const F &f) {
    return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), f);
}
template<typename A, typename B>
inline bool compare(const A &a, const B &b) {
    return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
 
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class A, class B> using umap = unordered_map<A, B>;
template <class T> using uset = unordered_set<T>;
 
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
 
template <class T> void bye(T x){ cout << x << '\n'; exit(0); }
inline int square(int a){ return (a * a); }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int h = 1010, w = 1010;

    int n;
    int sx, sy, gx, gy;
    while (cin >> n >> sx >> sy >> gx >> gy, n) {
        vector<int> x(n), y(n), r(n);
        for (int i = 0; i < n; ++i) {
            cin >> x[i] >> y[i] >> r[i];
        }
        
        if (sx > gx) {
            swap(sx, gx);
            swap(sy, gy);
        }

        if (sy > gy) {
            sy = 1000 - sy + 1;
            gy = 1000 - gy + 1;
            for (int i = 0; i < n; ++i) {
                y[i] = 1000 - y[i] + 1;
            }
        }

        vector cost(2, vector(h, vector(w, 0)));
        int add = 0;

        for (int i = 0; i < n; ++i) {
            if (x[i] - r[i] <= sx && sx <= x[i] + r[i] &&
                y[i] - r[i] <= sy && sy <= y[i] + r[i]) {

                add++;
            }
            int min_x = max(0, x[i] - r[i]);
            int min_y = max(0, y[i] - r[i]);
            int max_x = min(w - 1, x[i] + r[i] + 1);
            int max_y = min(h - 1, y[i] + r[i] + 1);
            cost[0][min_y][min_x]++; // 左から
            cost[0][max_y][min_x]--;
            cost[1][min_y][min_x]++; // 上から
            cost[1][min_y][max_x]--;
        }

        for (int i = 1; i < h; ++i) {
            for (int j = 1; j < w; ++j) {
                cost[0][i][j] += cost[0][i - 1][j];
                cost[1][i][j] += cost[1][i][j - 1];
            }
        }

        vector dp(h, vector(w, INF));

        dp[sy][sx] = 0;

        for (int i = 1; i < h - 1; ++i) {
            for (int j = 1; j < w - 1; ++j) {
                chmin(dp[i][j + 1], dp[i][j] + cost[0][i][j + 1]);
                chmin(dp[i + 1][j], dp[i][j] + cost[1][i + 1][j]);
            }
        }

        cout << dp[gy][gx] + add << '\n';
    }

    return 0;
}
accuracy: 1
time_ms: 300
memory_kb: 16356
final_rank: 8

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

bool solve() {
    int N;
    cin >> N;
    if (N == 0) return false;
    const int M = 1010;
    int sr, sc, tr, tc;
    cin >> sr >> sc >> tr >> tc;
    bool fr = sr > tr, fc = sc > tc;
    if (fr) sr = 1000 - sr, tr = 1000 - tr;
    if (fc) sc = 1000 - sc, tc = 1000 - tc;
    vector<vector<int>> R(M, vector<int>(M, 0));
    vector<vector<int>> D(M, vector<int>(M, 0));
    int cnt = 0;
    while (N--) {
        int x, y, k;
        cin >> x >> y >> k;
        if (fr) x = 1000 - x;
        if (fc) y = 1000 - y;
        int u = max(0, x - k);
        int d = x + k + 1;
        int l = max(0, y - k);
        int r = y + k + 1;
        if (u <= sr && sr < d && l <= sc && sc < r) cnt++;
        if (0 <= u && u < M && 0 <= l && l < M) {
            R[u][l]++, D[u][l]++;
            if (d < M) R[d][l]--;
            if (r < M) D[u][r]--;
        }
    }
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            if (i) R[i][j] += R[i - 1][j];
            if (j) D[i][j] += D[i][j - 1];
        }
    }
    vector<vector<int>> DP(M, vector<int>(M, 1 << 30));
    DP[sr][sc] = cnt;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            if (i) DP[i][j] = min(DP[i][j], DP[i - 1][j] + D[i][j]);
            if (j) DP[i][j] = min(DP[i][j], DP[i][j - 1] + R[i][j]);
        }
    }
    cout << DP[tr][tc] << '\n';
    return true;
}

int main() {
    while (solve()) {}
}
accuracy: 1
time_ms: 280
memory_kb: 15488
final_rank: 7

code_snippet: //#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define REV_PRIORITY_QUEUE(tp) priority_queue<tp,vector<tp>,greater<tp>>
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T> bool inline chmin(T &x,T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}
template <typename T> bool inline chmax(T &x,T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template <typename T = long long> vector<T> inline get_vec(int n){
    vector<T> ans(n);
    for(int i = 0; i < n; i++)cin >> ans[i];
    return ans;
}
template <typename T> void inline print_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cout << vec[i];
        if(kaigyou || i == n - 1)cout << '\n';
        else cout << ' ';
    }
    if(!n)cout << '\n';
    return;
}
template <typename T> void inline debug_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cerr << vec[i];
        if(kaigyou || i == n - 1)cerr << '\n';
        else cerr << ' ';
    }
    if(!n)cerr << '\n';
    return;
}
vector<vector<int>> inline get_graph(int n,int m = -1,bool direct = false){
    if(m == -1)m = n - 1;
    vector<vector<int>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        if(!direct)g[v].push_back(u);
    }
    return g;
}

vector<int> make_inv(vector<int> p){
    int n = (int)p.size();
    vector<int> ans(n);
    for(int i = 0; i < n; i++)ans[p[i]] = i;
    return ans;
}


#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //複数の解法のアイデアを思いついた時は全部メモしておく
    //g++ -D_GLIBCXX_DEBUG -Wall -O2 XXX.cpp -o o
    while(1){
        int n;
        cin >> n;
        if(n == 0)return;
        int sx,sy,gx,gy;
        cin >> sx >> sy >> gx >> gy;
        bool minusx = (gx - sx < 0),minusy = (gy - sy < 0);
        auto convertx = [&](int x){
            int ans = x;
            ans -= sx;
            if(minusx)ans *= -1;
            return ans;
        };
        auto converty = [&](int y){
            int ans = y;
            ans -= sy;
            if(minusy)ans *= -1;
            return ans;
        };
        gx = convertx(gx),gy = converty(gy);
        int h = gx,w = gy;
        int ans = 0;
        vector<vector<int>> tate_imos(h + 2,vector<int>(w + 2,0)); auto yoko_imos = tate_imos;
        vector<vector<int>> tate(h + 2,vector<int>(w + 2,0)); auto yoko = tate;
        for(int i = 0; i < n; i++){
            int x,y,r;
            cin >> x >> y >> r;
            x = convertx(x),y = converty(y);
            if(x - r <= 0 && x + r >= 0 && y - r <= 0 && y + r >= 0){
                ans++;
                continue;
            }
            if(x - r <= h && x + r >= h && y - r <= w && y + r >= w){
                ans++;
                continue;
            }

            if(x + r < 0 || y + r < 0)continue;
            if(x - r > h || y - r > w)continue;
            //tate[x][y-r , y+r] ++
            //cerr << h << ' ' << w << el;
            //cerr << x << ' ' << y <<' '<< r << el;
            
            if(x - r >= 0 && x - r <= h + 1){tate_imos[x - r][max(y - r,0)]++; tate_imos[x - r][min(y + r + 1,w + 1)]--;}
            //else if(x + r >= 0 && x + r <= h + 1){tate_imos[x + r][max(y - r,0)]++; tate_imos[x + r][min(y + r + 1,w + 1)]--;}

            if(y - r >= 0 && y - r <= w + 1){yoko_imos[max(x - r,0)][y - r]++; yoko_imos[min(x + r + 1,h + 1)][y - r]--;}
            //else if(y + r >= 0 && y + r <= w + 1){yoko_imos[max(x - r,0)][y + r]++; yoko_imos[min(x + r + 1,h + 1)][y + r]--;}
        }
        //TEST();

        for(int i = 0; i < h + 2; i++){
            for(int j = 0; j < w + 2; j++){
                tate[i][j] = tate_imos[i][j];
                yoko[i][j] = yoko_imos[i][j];

                if(j != 0)tate[i][j] += tate[i][j - 1];
                if(i != 0)yoko[i][j] += yoko[i - 1][j];
            }
        }
        
        //TEST();

        vector<vector<int>> dp(h + 2,vector<int>(w + 2,INT_MAX / 2));
        dp[0][0] = 0;
        for(int i = 0; i <= h; i++){
            for(int j = 0; j <= w; j++){
                chmin(dp[i + 1][j],dp[i][j] + tate[i + 1][j]);
                chmin(dp[i][j + 1],dp[i][j] + yoko[i][j + 1]);
            }
        }
        //for(int i = 0; i < h + 2; i++)debug_vec(tate[i]);
        //cerr << el;
        //for(int i = 0; i < h + 2; i++)debug_vec(yoko[i]);
        //cerr << el;
        //for(int i = 0; i < h + 2; i++)debug_vec(dp[i]);
        
        assert(dp[h][w] < INT_MAX / 2);
        cout << dp[h][w] + ans << el;
    }
}

void calc(void){
    return;
}


signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7280
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; 0 <= i; --i)
template <typename T> bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void solve();
int N,sx,sy,gx,gy,x[1<<17],y[1<<17],r[1<<17];
signed main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int TESTCASES = 1<<30;
  //cin >> TESTCASES;
  while (TESTCASES--) {
    cin>>N;
    if(N==0)break;
    cin>>sx>>sy>>gx>>gy;
    rep(i,N)cin>>x[i]>>y[i]>>r[i];
    solve();
  }
}
void solve() {
  if(gx-sx<0){
    sx=-sx,gx=-gx;
    rep(i,N)x[i]=-x[i];
  }
  if(gy-sy<0){
    sy=-sy,gy=-gy;
    rep(i,N)y[i]=-y[i];
  }
  gx-=sx,gy-=sy;
  rep(i,N){
    x[i]-=sx,y[i]-=sy;
  }
  sx=0,sy=0;
  vector row(gx+1,vector<int>(gy+2));
  vector col(gx+2,vector<int>(gy+1));
  vector dp(gx+1,vector<int>(gy+1,1<<30));
  dp[0][0]=0;
  rep(i,N){
    if(x[i]-r[i]<=sx&&sx<=x[i]+r[i]&&y[i]-r[i]<=sy&&sy<=y[i]+r[i])++dp[0][0];
    int x0=x[i]-r[i],y0=y[i]-r[i];
    int x1=x[i]+r[i]+1,y1=y[i]+r[i]+1;
    if(gx<x0||gy<y0||x1<=0||y1<=0)continue;
    ++row[max(0,x0)][max(0,y0)];
    --row[max(0,x0)][min(gy+1,y1)];
    ++col[max(0,x0)][max(0,y0)];
    --col[min(gx+1,x1)][max(0,y0)];
  }
  rep(i,gx+1)rep(j,gy+1)row[i][j+1]+=row[i][j];
  rep(j,gy+1)rep(i,gx+1)col[i+1][j]+=col[i][j];
  rep(i,gx+1)rep(j,gy+1){
    if(i!=0)chmin(dp[i][j],dp[i-1][j]+row[i][j]);
    if(j!=0)chmin(dp[i][j],dp[i][j-1]+col[i][j]);
  }
  cout<<dp[gx][gy]<<'\n';
}
accuracy: 1
time_ms: 20
memory_kb: 7040
final_rank: 1

code_snippet: # include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double pi = acos(-1);
template<class T>constexpr T inf() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T hinf() { return inf<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); }
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); }
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; }
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(ll n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(ll n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a%b); };
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g*b; };
ll MOD(ll x, ll m){return (x%m+m)%m; }
ll FLOOR(ll x, ll m) {ll r = (x%m+m)%m; return (x-r)/m; }
template<class T> using dijk = priority_queue<T, vector<T>, greater<T>>;
# define all(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(all((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(all((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(all((rprpr)),(rprpr).begin(),TU<char>)
# define rep(i,upupu)         for(ll i = 0, i##_len = (upupu);(i) < (i##_len);(i)++)
# define reps(i,opopo)        for(ll i = 1, i##_len = (opopo);(i) <= (i##_len);(i)++)
# define len(x)                ((ll)(x).size())
# define bit(n)               (1LL << (n))
# define pb push_back
# define eb emplace_back
# define exists(c, e)         ((c).find(e) != (c).end())

struct INIT{
	INIT(){
		std::ios::sync_with_stdio(false);
		std::cin.tie(0);
		cout << fixed << setprecision(20);
	}
}INIT;

namespace mmrz {
	void solve();
}

int main(){
	mmrz::solve();
}
#define debug(...) (static_cast<void>(0))

using namespace mmrz;

// [BEGIN] template の include

int SOLVE(){
	int n;
	cin >> n;
	while(n == 0)return 1;
	
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;

	vector<int> x, y, r;
	
	int base = 0;
	{
		int _x, _y, _r;
		rep(i, n){
			cin >> _x >> _y >> _r;
			if(_x-_r <= sx && sx <= _x+_r && _y-_r <= sy && sy <= _y+_r){
				base++;
			}else{
				x.eb(_x);
				y.eb(_y);
				r.eb(_r);
			}
		}
		n = len(x);
	}

	if(sx > gx){
		sx = -sx+1000;
		gx = -gx+1000;
		rep(i, n)x[i] = -x[i]+1000;
	}

	if(sy > gy){
		sy = -sy+1000;
		gy = -gy+1000;
		rep(i, n)y[i] = -y[i]+1000;
	}

	sx += 1000;
	sy += 1000;
	gx += 1000;
	gy += 1000;

	rep(i, n){
		x[i] += 1000;
		y[i] += 1000;
	}
	
	vector walls_hor(3000, vector(3000, 0));
	vector walls_ver(3000, vector(3000, 0));
	rep(i, n){
		walls_hor[x[i]-r[i]][y[i]-r[i]]++;
		walls_hor[x[i]+r[i]+1][y[i]-r[i]]--;
		
		walls_ver[x[i]-r[i]][y[i]-r[i]]++;
		walls_ver[x[i]-r[i]][y[i]+r[i]+1]--;
	}

	rep(a, 3000){
		reps(b, 3000-1){
			walls_hor[b][a] += walls_hor[b-1][a];
			walls_ver[a][b] += walls_ver[a][b-1];
		}
	}

	rep(i, 3000)rep(j, 3000)assert(walls_hor[i][j] >= 0);
	rep(i, 3000)rep(j, 3000)assert(walls_ver[i][j] >= 0);

	vector dp(3000, vector(3000, hinf<int>()));

	dp[sx][sy] = dp[sx][sy] = 0;

	for(int X = sx;X <= gx;X++){
		for(int Y = sy;Y <= gy;Y++){
			
			if(X+1 <= gx)chmin(dp[X+1][Y], dp[X][Y] + walls_ver[X+1][Y]);
			if(Y+1 <= gy)chmin(dp[X][Y+1], dp[X][Y] + walls_hor[X][Y+1]);
		}
	}

	debug(base);
	cout << dp[gx][gy]+base << '\n';

	return 0;
}

void mmrz::solve(){
	while(!SOLVE());
}
accuracy: 1
time_ms: 3600
memory_kb: 109932
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
using PP = pair<int, P>;
using PLL = pair<ll, ll>;
using PPLL = pair<ll, PLL>;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rrep(i, n) for(ll i = n - 1; i >= 0; --i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
#define all(v) v.begin(), v.end()
#define nC2(n) n * (n - 1) / 2
constexpr ll INF = 9009009009009009009LL;
constexpr int INF32 = 2002002002;
constexpr ll MOD = 998244353;
constexpr ll MOD107 = 1000000007;

// Linear Algebra ////////////////////////////////////////////////
const double Rad2Deg = 180.0 / M_PI;
const double Deg2Rad = M_PI / 180.0;
//////////////////////////////////////////////////////////////////

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

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 (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename Container,
          typename = std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              std::is_convertible_v<decltype(std::declval<Container>().begin()),
                                    typename Container::iterator>>>
ostream &operator<<(ostream &os, const Container &container) {
    auto it = container.begin();
    auto end = container.end();

    if (it != end) {
        os << *it;
        ++it;
    }
	for (; it != end; ++it) {
		os << " " << *it;
	}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1) os << " ";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {
	for (size_t i = 0; i < vv.size(); ++i) {
		os << vv[i];
		if (i != vv.size() - 1) os << "\n";
    }
    return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	assert(v.size() > 0);
	for (size_t i = 0; i < v.size(); ++i) is >> v[i];
	return is;
}
template <typename T>
istream& operator>>(istream& is, vector<vector<T>>& vv) {
	assert(vv.size() > 0);
	for (size_t i = 0; i < vv.size(); ++i) is >> vv[i];
	return is;
}

struct phash {
	template<class T1, class T2>
    inline size_t operator()(const pair<T1, T2> & p) const {
        auto h1 = hash<T1>()(p.first);
        auto h2 = hash<T2>()(p.second);

		size_t seed = h1 + h2; 
		h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = (h1 >> 16) ^ h1;
        seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
		h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = (h2 >> 16) ^ h2;
        seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};

template <typename T>
class segtree
{
protected:
	const T E;						// 単位元
	vector<T> _data;				// 完全二分木配列
	const function<T(T, T)> _query; // クエリ関数
	int _length;					// 葉の数

	T _query_sub(int a, int b, int k, int l, int r) const
	{
		if (r <= a || b <= l)
		{ // 完全に範囲外
			return E;
		}
		else if (a <= l && r <= b)
		{ // 完全に範囲内
			return _data[k];
		}
		else
		{ // 一部重なる
			T vl = _query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = _query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
			return _query(vl, vr);
		}
	}

public:
	/**
	 * @brief セグメント木
	 * @param len 配列の長さ
	 * @param e 単位元（評価するときの意味のない値。MinQueryの場合、min(x,
	 * INF)のINFは意味がない）
	 * @param query クエリ関数
	 */
	segtree(int len, T e, function<T(T, T)> query) : E(e), _query(std::move(query)), _length(1)
	{
		// 要素数を2の冪乗にする
		while (_length < len)
		{
			_length <<= 1;
		}
		_data.assign(_length * 2 - 1, E);
	}

	size_t size() const { return _length; }

	/**
	 * @remark O(1) 評価しないので、build()を呼ぶこと O(N)
	 */
	T &operator[](size_t i)
	{
		if (i < 0 || i >= _length)
			throw out_of_range("Index out of range");
		return _data[i + _length - 1];
	}

	/**
	 * @brief 構築 O(N)
	 */
	void build()
	{
		for (int i = _length - 2; i >= 0; --i)
		{
			_data[i] = _query(_data[i * 2 + 1], _data[i * 2 + 2]);
		}
	}

	/**
	 * @brief 更新 O(log N)
	 */
	void update(int i, T value)
	{
		if (i < 0 || i >= _length)
			throw out_of_range("Index out of range");
		i += _length - 1;
		_data[i] = value;
		while (i > 0)
		{
			i = (i - 1) >> 1;
			_data[i] = _query(_data[i * 2 + 1], _data[i * 2 + 2]);
		}
	}

	/**
	 * @brief 区間クエリ [a, b) O(log N)
	 */
	T query(int a, int b) const
	{
		if (a < 0 || b < 0 || a >= _length || b > _length)
			throw out_of_range("Index out of range");
		return _query_sub(a, b, 0, 0, _length);
	}

	static segtree<T> RangeMinimumQuery(int len, T e = numeric_limits<T>::max())
	{
		return segtree<T>(len, e, [](T a, T b)
						  { return min(a, b); });
	}

	static segtree<T> RangeMaximumQuery(int len, T e = numeric_limits<T>::min())
	{
		return segtree<T>(len, e, [](T a, T b)
						  { return max(a, b); });
	}

	static segtree<T> RangeSumQuery(int len, T e = 0)
	{
		return segtree<T>(len, e, [](T a, T b)
						  { return a + b; });
	}

	static segtree<T> RangeProductQuery(int len, T e = 1)
	{
		return segtree<T>(len, e, [](T a, T b)
						  { return a * b; });
	}

	static segtree<T> RangeXorQuery(int len, T e = 0)
	{
		return segtree<T>(len, e, [](T a, T b)
						  { return a ^ b; });
	}
};

template <typename T>
class lazy_segtree : public segtree<T>
{
private:
	vector<T> _lazy;

	// lazyを子のlazyに伝播させる関数
	const function<T(T, T)> _merge;
	// lazyをdataに適用する関数
	const function<T(T, T)> _apply;
	// lazyをdataに適用する時に、区間の長さに応じて値を変える関数
	const function<T(T, int)> _proportion;
	// lazyの単位元
	const T ME;

	void _eval(int k, int len)
	{
		if (_lazy[k] == ME)
			return;
		if (k < this->_length - 1)
		{
			_lazy[k * 2 + 1] = _merge(_lazy[k * 2 + 1], _lazy[k]);
			_lazy[k * 2 + 2] = _merge(_lazy[k * 2 + 2], _lazy[k]);
		}
		this->_data[k] = _apply(this->_data[k], _proportion(_lazy[k], len));
		_lazy[k] = ME;
	}

	void _update_core(int a, int b, T x, int k, int l, int r)
	{
		_eval(k, r - l);
		if (a <= l && r <= b)
		{
			_lazy[k] = _merge(_lazy[k], x);
			_eval(k, r - l);
		}
		else if (a < r && l < b)
		{
			_update_core(a, b, x, k * 2 + 1, l, (l + r) / 2);
			_update_core(a, b, x, k * 2 + 2, (l + r) / 2, r);
			this->_data[k] = this->_query(this->_data[k * 2 + 1], this->_data[k * 2 + 2]);
		}
	}

	T _query_core(int a, int b, int k, int l, int r)
	{
		_eval(k, r - l);
		if (r <= a || b <= l)
		{
			return this->E;
		}
		else if (a <= l && r <= b)
		{
			return this->_data[k];
		}
		else
		{
			T vl = _query_core(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = _query_core(a, b, k * 2 + 2, (l + r) / 2, r);
			return this->_query(vl, vr);
		}
	}

public:
	/**
	 * @brief 遅延セグメント木
	 * @param len 配列の長さ
	 * @param e 単位元
	 * @param queryFunc クエリ関数
	 * @param mergeFunc lazyを子のlazyに伝播させる関数
	 * @param applyFunc lazyをdataに適用する関数
	 * @param proportionFunc
	 * lazyをdataに適用する時に、区間の長さに応じて値を変える関数
	 * @param me lazyの単位元
	 */
	lazy_segtree(int len, T e, function<T(T, T)> queryFunc, function<T(T, T)> mergeFunc, function<T(T, T)> applyFunc, function<T(T, int)> proportionFunc, T me)
		: segtree<T>(len, e, queryFunc), _merge(mergeFunc), _apply(applyFunc), _proportion(proportionFunc), ME(me)
	{
		_lazy.assign(2 * this->_length - 1, ME);
	}

	/**
	 * @brief ランダムアクセス O(log N)
	 */
	T &operator[](size_t i)
	{
		if (i < 0 || i >= this->_length)
			throw out_of_range("Index out of range");
		query(i, i + 1);
		return this->_data[i + this->_length - 1];
	}

	using segtree<T>::update;
	/**
	 * @brief [a, b) 区間更新 O(log N)
	 */
	void update(int a, int b, T x)
	{
		_update_core(a, b, x, 0, 0, this->_length);
	}

	/**
	 * @brief 区間クエリ [a, b) O(log N)
	 */
	T query(int a, int b) { return _query_core(a, b, 0, 0, this->_length); }

	static lazy_segtree<T> RangeUpdateMinimumQuery(int len, T e = numeric_limits<T>::max())
	{
		return lazy_segtree<T>(
			len,
			e,
			[](T a, T b)
			{ return min(a, b); },
			[](T a, T b)
			{ return b; },
			[](T a, T b)
			{ return b; },
			[](T a, int b)
			{ return a; },
			numeric_limits<T>::max());
	}
	static lazy_segtree<T> RangeUpdateMaximumQuery(int len, T e = numeric_limits<T>::min())
	{
		return lazy_segtree<T>(
			len,
			e,
			[](T a, T b)
			{ return max(a, b); },
			[](T a, T b)
			{ return b; },
			[](T a, T b)
			{ return b; },
			[](T a, int b)
			{ return a; },
			numeric_limits<T>::min());
	}
	static lazy_segtree<T> RangeUpdateSumQuery(int len, T e = 0)
	{
		return lazy_segtree<T>(
			len,
			e,
			[](T a, T b)
			{ return a + b; },
			[](T a, T b)
			{ return b; },
			[](T a, T b)
			{ return b; },
			[](T a, int b)
			{ return a * b; },
			0);
	}

	static lazy_segtree<T> RangeAddMinimumQuery(int len, T e = numeric_limits<T>::max())
	{
		return lazy_segtree<T>(
			len,
			e,
			[](T a, T b)
			{ return min(a, b); },
			[](T a, T b)
			{ return a + b; },
			[](T a, T b)
			{ return a + b; },
			[](T a, int b)
			{ return a; },
			0);
	}
	static lazy_segtree<T> RangeAddMaximumQuery(int len, T e = numeric_limits<T>::min())
	{
		return lazy_segtree<T>(
			len,
			e,
			[](T a, T b)
			{ return max(a, b); },
			[](T a, T b)
			{ return a + b; },
			[](T a, T b)
			{ return a + b; },
			[](T a, int b)
			{ return a; },
			0);
	}
	static lazy_segtree<T> RangeAddSumQuery(int len, T e = 0)
	{
		return lazy_segtree<T>(
			len,
			e,
			[](T a, T b)
			{ return a + b; },
			[](T a, T b)
			{ return a + b; },
			[](T a, T b)
			{ return a + b; },
			[](T a, int b)
			{ return a * b; },
			0);
	}
};



int solve() {
	ll n;
	cin >> n;
	if (n == 0)
		return 1;

	PLL s, g;
	cin >> s.second >> s.first >> g.second >> g.first;

	const ll GSIZE = 1100;
	const ll CONSTRAINT = 1000;

	bool inverseX = false;
	if (g.first < s.first)
		swap(s, g);
	if (g.second < s.second) {
		inverseX = true;
		s.second = CONSTRAINT + 1 - s.second;
		g.second = CONSTRAINT + 1 - g.second;
	}

	vector<lazy_segtree<ll>> sumx(GSIZE, lazy_segtree<ll>::RangeAddSumQuery(GSIZE));
	vector<lazy_segtree<ll>> sumy(GSIZE, lazy_segtree<ll>::RangeAddSumQuery(GSIZE));

	ll ans = 0;
	rep(i, n)
	{
		ll x, y, r;
		cin >> x >> y >> r;
		if (inverseX) {
			x = CONSTRAINT + 1 - x;
		}

		if (max(abs(x - s.second), abs(y - s.first)) <= r) {
			ans++;
		}
		else {
			sumx[max(y - r, 0LL)].update(max(x - r, 0LL), min(x + r + 1, CONSTRAINT + 1), 1);
			sumy[max(x - r, 0LL)].update(max(y - r, 0LL), min(y + r + 1, CONSTRAINT + 1), 1);
		}
	}

	vector<vector<ll>> dist(GSIZE, vector<ll>(GSIZE, INF));
	dist[s.first][s.second] = 0;
	loop(i, s.first, g.first)
	{
		loop(j, s.second, g.second) {
			chmin(dist[i + 1][j], dist[i][j] + sumx[i + 1][j]);
			chmin(dist[i][j + 1], dist[i][j] + sumy[j + 1][i]);
		}
	}

	cout << dist[g.first][g.second] + ans << endl;
	return 0;
}

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

	while (!solve()) {}
	return 0;
}
accuracy: 1
time_ms: 2970
memory_kb: 153820
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
using PP = pair<int, P>;
using PLL = pair<ll, ll>;
using PPLL = pair<ll, PLL>;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rrep(i, n) for(ll i = n - 1; i >= 0; --i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
#define all(v) v.begin(), v.end()
#define nC2(n) n * (n - 1) / 2
constexpr ll INF = 9009009009009009009LL;
constexpr int INF32 = 2002002002;
constexpr ll MOD = 998244353;
constexpr ll MOD107 = 1000000007;

// Linear Algebra ////////////////////////////////////////////////
const double Rad2Deg = 180.0 / M_PI;
const double Deg2Rad = M_PI / 180.0;
//////////////////////////////////////////////////////////////////

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

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 (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename Container,
          typename = std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              std::is_convertible_v<decltype(std::declval<Container>().begin()),
                                    typename Container::iterator>>>
ostream &operator<<(ostream &os, const Container &container) {
    auto it = container.begin();
    auto end = container.end();

    if (it != end) {
        os << *it;
        ++it;
    }
	for (; it != end; ++it) {
		os << " " << *it;
	}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1) os << " ";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {
	for (size_t i = 0; i < vv.size(); ++i) {
		os << vv[i];
		if (i != vv.size() - 1) os << "\n";
    }
    return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	assert(v.size() > 0);
	for (size_t i = 0; i < v.size(); ++i) is >> v[i];
	return is;
}
template <typename T>
istream& operator>>(istream& is, vector<vector<T>>& vv) {
	assert(vv.size() > 0);
	for (size_t i = 0; i < vv.size(); ++i) is >> vv[i];
	return is;
}

struct phash {
	template<class T1, class T2>
    inline size_t operator()(const pair<T1, T2> & p) const {
        auto h1 = hash<T1>()(p.first);
        auto h2 = hash<T2>()(p.second);

		size_t seed = h1 + h2; 
		h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = (h1 >> 16) ^ h1;
        seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
		h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = (h2 >> 16) ^ h2;
        seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};





int solve() {
	ll n;
	cin >> n;
	if (n == 0)
		return 1;

	PLL s, g;
	cin >> s.second >> s.first >> g.second >> g.first;

	const ll GSIZE = 1100;
	const ll CONSTRAINT = 1000;

	bool inverseX = false;
	if (g.first < s.first)
		swap(s, g);
	if (g.second < s.second) {
		inverseX = true;
		s.second = CONSTRAINT + 1 - s.second;
		g.second = CONSTRAINT + 1 - g.second;
	}

	vvll imosx(GSIZE, vll(GSIZE, 0));
	vvll imosy(GSIZE, vll(GSIZE, 0));

	ll ans = 0;
	rep(i, n)
	{
		ll x, y, r;
		cin >> x >> y >> r;
		if (inverseX) {
			x = CONSTRAINT + 1 - x;
		}

		if (max(abs(x - s.second), abs(y - s.first)) <= r) {
			ans++;
		}
		else {
			imosx[max(y - r, 0LL)][max(x - r, 0LL)] += 1;
			imosx[max(y - r, 0LL)][min(x + r + 1, CONSTRAINT + 1)] += -1;
			imosy[max(x - r, 0LL)][max(y - r, 0LL)] += 1;
			imosy[max(x - r, 0LL)][min(y + r + 1, CONSTRAINT + 1)] += -1;
		}
	}

	vvll sumx(GSIZE, vll(GSIZE, 0)), sumy(GSIZE, vll(GSIZE, 0));
	rep(i, GSIZE) {
		ll sum = 0;
		rep(j, GSIZE)
		{
			sum += imosx[i][j];
			sumx[i][j] = sum;
		}
	}
	rep(i, GSIZE){
		ll sum = 0;
		rep(j, GSIZE) {
			sum += imosy[i][j];
			sumy[i][j] = sum;
		}
	}

	vector<vector<ll>> dist(GSIZE, vector<ll>(GSIZE, INF));
	// priority_queue<PPLL, vector<PPLL>, greater<PPLL>> q;
	// q.push({0, s});
	// dist[s.first][s.second] = 0;

	// while (!q.empty()) {
	// 	auto [nowCost, pos] = q.top();
	// 	auto [y, x] = pos;
	// 	q.pop();
	// 	if (dist[y][x] < nowCost) continue;

	// 	loop(i, 0, 1) {
	// 		ll nx = x + dx[i];
	// 		ll ny = y + dy[i];
	// 		if (nx < 1 || CONSTRAINT + 1 <= nx || ny < 1 || CONSTRAINT + 1 <= ny) continue;
	// 		// 下
	// 		if (i == 0) {
	// 			if (dist[ny][nx] <= nowCost + sumx[ny][nx]) continue;
	// 			dist[ny][nx] = nowCost + sumx[ny][nx];
	// 			q.push({dist[ny][nx], {ny, nx}});
	// 		}
	// 		else {
	// 			if (dist[ny][nx] <= nowCost + sumy[nx][ny]) continue;
	// 			dist[ny][nx] = nowCost + sumy[nx][ny];
	// 			q.push({dist[ny][nx], {ny, nx}});
	// 		}
	// 	}
	// }
	dist[s.first][s.second] = 0;
	loop(i, s.first, g.first)
	{
		loop(j, s.second, g.second) {
			chmin(dist[i + 1][j], dist[i][j] + sumx[i + 1][j]);
			chmin(dist[i][j + 1], dist[i][j] + sumy[j + 1][i]);
		}
	}

	cout << dist[g.first][g.second] + ans << endl;
	return 0;
}

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

	while (!solve()) {}
	return 0;
}
accuracy: 1
time_ms: 990
memory_kb: 50524
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
using PP = pair<int, P>;
using PLL = pair<ll, ll>;
using PPLL = pair<ll, PLL>;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rrep(i, n) for(ll i = n - 1; i >= 0; --i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
#define all(v) v.begin(), v.end()
#define nC2(n) n * (n - 1) / 2
constexpr ll INF = 9009009009009009009LL;
constexpr int INF32 = 2002002002;
constexpr ll MOD = 998244353;
constexpr ll MOD107 = 1000000007;

// Linear Algebra ////////////////////////////////////////////////
const double Rad2Deg = 180.0 / M_PI;
const double Deg2Rad = M_PI / 180.0;
//////////////////////////////////////////////////////////////////

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

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 (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename Container,
          typename = std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              std::is_convertible_v<decltype(std::declval<Container>().begin()),
                                    typename Container::iterator>>>
ostream &operator<<(ostream &os, const Container &container) {
    auto it = container.begin();
    auto end = container.end();

    if (it != end) {
        os << *it;
        ++it;
    }
	for (; it != end; ++it) {
		os << " " << *it;
	}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1) os << " ";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {
	for (size_t i = 0; i < vv.size(); ++i) {
		os << vv[i];
		if (i != vv.size() - 1) os << "\n";
    }
    return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	assert(v.size() > 0);
	for (size_t i = 0; i < v.size(); ++i) is >> v[i];
	return is;
}
template <typename T>
istream& operator>>(istream& is, vector<vector<T>>& vv) {
	assert(vv.size() > 0);
	for (size_t i = 0; i < vv.size(); ++i) is >> vv[i];
	return is;
}

struct phash {
	template<class T1, class T2>
    inline size_t operator()(const pair<T1, T2> & p) const {
        auto h1 = hash<T1>()(p.first);
        auto h2 = hash<T2>()(p.second);

		size_t seed = h1 + h2; 
		h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = (h1 >> 16) ^ h1;
        seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
		h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = (h2 >> 16) ^ h2;
        seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};





int solve() {
	ll n;
	cin >> n;
	if (n == 0)
		return 1;

	PLL s, g;
	cin >> s.second >> s.first >> g.second >> g.first;

	const ll GSIZE = 1100;
	const ll CONSTRAINT = 1000;

	bool inverseX = false;
	if (g.first < s.first)
		swap(s, g);
	if (g.second < s.second) {
		inverseX = true;
		s.second = CONSTRAINT + 1 - s.second;
		g.second = CONSTRAINT + 1 - g.second;
	}

	vvll imosx(GSIZE, vll(GSIZE, 0));
	vvll imosy(GSIZE, vll(GSIZE, 0));

	ll ans = 0;
	rep(i, n)
	{
		ll x, y, r;
		cin >> x >> y >> r;
		if (inverseX) {
			x = CONSTRAINT + 1 - x;
		}

		if (max(abs(x - s.second), abs(y - s.first)) <= r) {
			ans++;
		}
		else {
			imosx[max(y - r, 0LL)][max(x - r, 0LL)] += 1;
			imosx[max(y - r, 0LL)][min(x + r + 1, CONSTRAINT + 1)] += -1;
			imosy[max(x - r, 0LL)][max(y - r, 0LL)] += 1;
			imosy[max(x - r, 0LL)][min(y + r + 1, CONSTRAINT + 1)] += -1;
		}
	}

	vvll sumx(GSIZE, vll(GSIZE, 0)), sumy(GSIZE, vll(GSIZE, 0));
	rep(i, GSIZE) {
		ll sum = 0;
		rep(j, GSIZE)
		{
			sum += imosx[i][j];
			sumx[i][j] = sum;
		}
	}
	rep(i, GSIZE){
		ll sum = 0;
		rep(j, GSIZE) {
			sum += imosy[i][j];
			sumy[i][j] = sum;
		}
	}
	// cout << "----sumx----" << endl;
	// cout << sumx << endl;
	// cout << "----sumy----" << endl;
	// cout << sumy << endl;

	vector<vector<ll>> dist(GSIZE, vector<ll>(GSIZE, INF));
	priority_queue<PPLL, vector<PPLL>, greater<PPLL>> q;
	q.push({0, s});
	dist[s.first][s.second] = 0;

	while (!q.empty()) {
		auto [nowCost, pos] = q.top();
		auto [y, x] = pos;
		q.pop();
		if (dist[y][x] < nowCost) continue;

		loop(i, 0, 1) {
			ll nx = x + dx[i];
			ll ny = y + dy[i];
			if (nx < 1 || CONSTRAINT + 1 <= nx || ny < 1 || CONSTRAINT + 1 <= ny) continue;
			// 下
			if (i == 0) {
				if (dist[ny][nx] <= nowCost + sumx[ny][nx]) continue;
				dist[ny][nx] = nowCost + sumx[ny][nx];
				q.push({dist[ny][nx], {ny, nx}});
			}
			else {
				if (dist[ny][nx] <= nowCost + sumy[nx][ny]) continue;
				dist[ny][nx] = nowCost + sumy[nx][ny];
				q.push({dist[ny][nx], {ny, nx}});
			}
		}
	}
	
	cout << dist[g.first][g.second] + ans << endl;
	return 0;
}

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

	while (!solve()) {}
	return 0;
}
accuracy: 1
time_ms: 2930
memory_kb: 50624
final_rank: 16

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

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  // ios::sync_with_stdio(false);
  // std::cin.tie(nullptr);
  while (not solve());
  return 0;
}

// ICPC practice

bool solve() {
  int N;
  cin >> N;
  if (N == 0) return 1;

  int sy, sx, gy, gx;
  cin >> sx >> sy >> gx >> gy;
  vector<tuple<int, int, int>> yxr(N);
  for (auto &[y, x, r] : yxr) cin >> x >> y >> r;
  if (sy > gy) {
    sy = 2 * gy - sy;
    for (auto &[y, x, r] : yxr) y = 2 * gy - y;
  }
  if (sx > gx) {
    sx = 2 * gx - sx;
    for (auto &[y, x, r] : yxr) x = 2 * gx - x;
  }
  gx -= sx, gy -= sy;
  for (auto &[y, x, r] : yxr) x -= sx, y -= sy;
  sx = 0, sy = 0;

  const int H = gy + 1, W = gx + 1;
  vector<vi> left(H, vi(W));
  for (auto &[y, x, r] : yxr) {
    if (y - r < H && x - r < W) left[max(y - r, 0)][max(x - r, 0)]++;
    if (y + r + 1 < H && x - r < W) left[max(y + r + 1, 0)][max(x - r, 0)]--;
  }
  rep(j, 0, W) rep(i, 0, H - 1) left[i + 1][j] += left[i][j];
  vector<vi> up(H, vi(W));
  for (auto &[y, x, r] : yxr) {
    if (y - r < H && x - r < W) up[max(y - r, 0)][max(x - r, 0)]++;
    if (y - r < H && x + r + 1 < W) up[max(y - r, 0)][max(x + r + 1, 0)]--;
  }
  rep(i, 0, H) rep(j, 0, W - 1) up[i][j + 1] += up[i][j];

  vector<vi> dp(H, vi(W, N * 2));
  dp[0][0] = 0;
  for (auto [y, x, r] : yxr)
    if (abs(x - sx) <= r && abs(y - sy) <= r) dp[0][0]++;
  rep(i, 0, H) rep(j, 0, W) {
    if (i - 1 >= 0)
      dp[i][j] = min(dp[i][j], dp[i - 1][j] + up[i][j]);
    if (j - 1 >= 0)
      dp[i][j] = min(dp[i][j], dp[i][j - 1] + left[i][j]);
  }
  cout << dp[gy][gx] << endl;
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 6412
final_rank: 3

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

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  // ios::sync_with_stdio(false);
  // std::cin.tie(nullptr);
  while (not solve());
  return 0;
}

// ICPC practice

bool solve() {
  int N;
  cin >> N;
  if (N == 0) return 1;
  int sx, sy;
  int gx, gy;
  cin >> sx >> sy >> gx >> gy;
  vector<tuple<int, int, int>> xyr;
  rep(i, 0, N) {
    int x, y, r;
    cin >> x >> y >> r;
    xyr.emplace_back(x, y, r);
  }

  {
    // s<gにする
    bool fx = 0;
    bool fy = 0;
    if (sx > gx) fx = 1;
    if (sy > gy) fy = 1;
    if (fx) sx = 2 * gx - sx;
    if (fy) sy = 2 * gy - sy;
    for (auto &[x, y, r] : xyr) {
      if (fx) x = 2 * gx - x;
      if (fy) y = 2 * gy - y;
    }
    // s=0にする
    ll dx = sx, dy = sy;
    sx -= dx, sy -= dy;
    gx -= dx, gy -= dy;
    for (auto &[x, y, r] : xyr) x -= dx, y -= dy;
  }
  // cerr << sx << " " << sy << endl;
  // cerr << gx << " " << gy << endl;
  int W = gx + 10, H = gy + 10;
  vector<vi> left(W, vi(H, 0));
  vector<vi> up(W, vi(H, 0));

  for (auto [x, y, r] : xyr) {
    int lx = x - r;
    int rx = x + r;
    int ly = y - r;
    int ry = y + r;
    auto add = [&](int ax, int ay, int z, int f) -> void {
      ax = max(0, ax);
      ay = max(0, ay);
      if (ax < W && ay < H) {
        if (f == 0) left[ax][ay] += z;
        if (f == 1) up[ax][ay] += z;
      }
    };
    add(lx, ly, 1, 0);
    add(lx, ry + 1, -1, 0);

    add(lx, ly, 1, 1);
    add(rx + 1, ly, -1, 1);
  }

  rep(i, 0, W) rep(j, 0, H - 1)
      left[i][j + 1] += left[i][j];

  rep(i, 0, W - 1) rep(j, 0, H)
      up[i + 1][j] += up[i][j];

  int sd = 0;
  for (auto [x, y, r] : xyr)
    if (abs(x - sx) <= r && abs(y - sy) <= r)
      sd++;

  vector<vi> md(W, vi(H, N + 1010));
  md[sx][sy] = sd;
  rep(x, 0, W) rep(y, 0, H) {
    if (x - 1 >= 0) {
      int c = left[x][y];
      md[x][y] = min(md[x][y], md[x - 1][y] + c);
    }
    if (y - 1 >= 0) {
      int c = up[x][y];
      md[x][y] = min(md[x][y], md[x][y - 1] + c);
    }
  }
  cout << md[gx][gy] << endl;
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 6936
final_rank: 5

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

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  // ios::sync_with_stdio(false);
  // std::cin.tie(nullptr);
  while (not solve());
  return 0;
}

// ICPC practice

bool solve() {
  int N;
  cin >> N;
  if (N == 0) return 1;
  int sx, sy;
  int gx, gy;
  cin >> sx >> sy >> gx >> gy;
  vector<tuple<int, int, int>> xyr;
  rep(i, 0, N) {
    int x, y, r;
    cin >> x >> y >> r;
    xyr.emplace_back(x, y, r);
  }

  {
    // s<gにする
    bool fx = 0;
    bool fy = 0;
    if (sx > gx) fx = 1;
    if (sy > gy) fy = 1;
    if (fx) sx = 2 * gx - sx;
    if (fy) sy = 2 * gy - sy;
    for (auto &[x, y, r] : xyr) {
      if (fx) x = 2 * gx - x;
      if (fy) y = 2 * gy - y;
    }
    // s=0にする
    ll dx = sx, dy = sy;
    sx -= dx, sy -= dy;
    gx -= dx, gy -= dy;
    for (auto &[x, y, r] : xyr) x -= dx, y -= dy;
  }
  // cerr << sx << " " << sy << endl;
  // cerr << gx << " " << gy << endl;
  int W = gx + 10, H = gy + 10;
  vector<vi> left(W, vi(H, 0));
  vector<vi> up(W, vi(H, 0));

  for (auto [x, y, r] : xyr) {
    int lx = x - r;
    int rx = x + r;
    int ly = y - r;
    int ry = y + r;
    auto add = [&](int ax, int ay, int z, int f) -> void {
      ax = max(0, ax);
      ay = max(0, ay);
      if (ax < W && ay < H) {
        if (f == 0) left[ax][ay] += z;
        if (f == 1) up[ax][ay] += z;
      }
    };
    add(lx, ly, 1, 0);
    add(lx + 1, ly, -1, 0);
    add(lx, ry + 1, -1, 0);
    add(lx + 1, ry + 1, 1, 0);

    add(lx, ly, 1, 1);
    add(lx, ly + 1, -1, 1);
    add(rx + 1, ly, -1, 1);
    add(rx + 1, ly + 1, 1, 1);
  }

  rep(i, 0, W) rep(j, 0, H - 1) {
    left[i][j + 1] += left[i][j];
    up[i][j + 1] += up[i][j];
  }
  rep(i, 0, W - 1) rep(j, 0, H) {
    left[i + 1][j] += left[i][j];
    up[i + 1][j] += up[i][j];
  }

  int sd = 0;
  for (auto [x, y, r] : xyr)
    if (abs(x - sx) <= r && abs(y - sy) <= r)
      sd++;

  vector<vi> md(W, vi(H, N + 1010));
  md[sx][sy] = sd;
  rep(x, 0, W) rep(y, 0, H) {
    if (x - 1 >= 0) {
      int c = left[x][y];
      md[x][y] = min(md[x][y], md[x - 1][y] + c);
    }
    if (y - 1 >= 0) {
      int c = up[x][y];
      md[x][y] = min(md[x][y], md[x][y - 1] + c);
    }
  }
  cout << md[gx][gy] << endl;
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 6884
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}

int n;

void solve() {
    int sx,sy,gx,gy;
    vector<vector<int>> lf(1010,vector<int>(1010,0)),up(1010,vector<int>(1010,0));
    vector<vector<int>> dij(1010,vector<int>(1010,10000000));
    int ans = 1e9;

    bool about_x = false;
    bool about_y = false;
    cin >> sx >> sy >> gx >> gy;
    if (sx > gx) {
        sx = 1000-sx;
        gx = 1000-gx;
        about_x = true;
    }
    if (sy > gy) {
        sy = 1000-sy;
        gy = 1000-gy;
        about_y = true;
    }

    vector<vector<int>> v(n,vector<int> (3));
    rep(i,n) {
        rep(j,3) {
            cin >> v[i][j];
        }
        if (about_x) {
            v[i][0] = 1000-v[i][0];
        }
        if (about_y) {
            v[i][1] = 1000-v[i][1];
        }
    }

    rep(i,1010) {
        rep(j,1010) {
            lf[i][j] = 0;
            up[i][j] = 0;
        }
    }

    rep(i,n) {
        if (v[i][0]-v[i][2]<0) continue;
        lf[max(v[i][1]-v[i][2],0)][v[i][0]-v[i][2]]++;
        lf[min(v[i][1]+v[i][2]+1,1005)][v[i][0]-v[i][2]]--;
    }
    rep(i,1005) {
        rep(j,1005) {
            lf[j+1][i] += lf[j][i];
        }
    }

    rep(i,n) {
        if (v[i][1]-v[i][2]<0) continue;
        up[v[i][1]-v[i][2]][max(v[i][0]-v[i][2],0)]++;
        up[v[i][1]-v[i][2]][min(v[i][0]+v[i][2]+1,1005)]--;
    }
    rep(i,1005) {
        rep(j,1005) {
            up[i][j+1] += up[i][j];
        }
    }
    int start = 0;
    rep(i,n) {
        if (v[i][0]-v[i][2] <= sx && sx <= v[i][0]+v[i][2]) {
            if (v[i][1]-v[i][2] <= sy && sy <= v[i][1]+v[i][2]) {
                start++;
            }
        }
    }

    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;

   // cout << sx << ' ' << sy << ' ' << gx << ' ' << gy << endl;

    pq.push({start,{sx,sy}});
    dij[sx][sy] = start;
    while (!pq.empty()) {
        auto p = pq.top();
        int depth = p.first;
        int x = p.second.first;
        int y = p.second.second;
       // cout << depth << ' ' << x << ' ' << y << endl;
        pq.pop();
        if (dij[x][y] != depth) continue;
        
        if (x < gx) {
            if (dij[x+1][y] > depth+lf[y][x+1]) {
                dij[x+1][y] = depth+lf[y][x+1];
                pq.push({depth+lf[y][x+1],{x+1,y}});
            }
        }
        if (y < gy) {
            if (dij[x][y+1] > depth+up[y+1][x]) {
                dij[x][y+1] = depth+up[y+1][x];
                pq.push({depth+up[y+1][x],{x,y+1}});
            }
        }
    }

    cout << dij[gx][gy] << endl;
    return;

}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    while (cin >> n && n) {
        solve();
    }
}
accuracy: 1
time_ms: 260
memory_kb: 20916
final_rank: 9

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 = acos(-1.0);
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); } }

tuple<vl, vi> dijkstra(int s, int N, vv<pair<int, ll>> &g){
    using P = pair<ll, int>;
    vl dist(N, INF);
    vi bef(N);
    priority_queue<P, vc<P>, greater<P>> q;
    dist[s] = 0;
    q.push({0, s});
    while (!q.empty()){
        auto [c, now] = q.top();q.pop();
        if (dist[now] < c) continue;
        for (auto&& [nxt, nc]: g[now]) if (dist[nxt] > c + nc){
            dist[nxt] = c + nc;
            bef[nxt] = now;
            q.push({dist[nxt], nxt}); 
        }
    }
    return {dist, bef};
}

void solve(int N){
    int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--;
    vi X(N), Y(N), R(N); rep(i, N) cin >> X[i] >> Y[i] >> R[i];
    rep(i, N){
        X[i]--;
        Y[i]--;
    }
    if (sx > gx){
        sx = 999 - sx;
        gx = 999 - gx;
        rep(i, N) X[i] = 999 - X[i];
    }
    if (sy > gy){
        sy = 999 - sy;
        gy = 999 - gy;
        rep(i, N) Y[i] = 999 - Y[i];
    }
    int sub = 0;
    rep(i, N) if (X[i] - R[i] <= sx && sx <= X[i] + R[i] && Y[i] - R[i] <= sy && sy <= Y[i] + R[i]) sub++;
    vvi hedgecost(1010, vi(1010, 0)), wedgecost(1010, vi(1010, 0));
    rep(i, N){
        hedgecost[max(0, X[i] - R[i])][max(0, Y[i] - R[i])]++;
        hedgecost[max(0, X[i] - R[i])][min(1009, Y[i] + R[i] + 1)]--;
        wedgecost[max(0, X[i] - R[i])][max(0, Y[i] - R[i])]++;
        wedgecost[min(1009, X[i] + R[i] + 1)][max(0, Y[i] - R[i])]--;
    }
    rep(i, 1010){
        rep(j, 1009) hedgecost[i][j + 1] += hedgecost[i][j];
    }
    rep(j, 1010){
        rep(i, 1009) wedgecost[i + 1][j] += wedgecost[i][j];
    }
    // rep(i, 10){
    //     rep(j, 10) cout << hedgecost[i][j] << " ";
    //     cout << endl;
    // }
    // rep(i, 10){
    //     rep(j, 10) cout << wedgecost[i][j] << " ";
    //     cout << endl;
    // }

    // vv<pair<int, ll>> g(1000000);
    // rep(i, 1000) rep(j, 1000){
    //     if (i < 999) g[i * 1000 + j].push_back({(i + 1) * 1000 + j, hedgecost[i + 1][j]});
    //     if (j < 999) g[i * 1000 + j].push_back({i * 1000 + j + 1, wedgecost[i][j + 1]});
    // }
    // auto [dist, bef] = dijkstra(sx * 1000 + sy, 1000000, g);
    // cout << dist[gx * 1000 + gy] + sub << "\n";
    // using P = tuple<int, int, int>;
    vvi dist(1010, vi(1010, inf));
    // priority_queue<P, vc<P>, greater<P>> q;
    // dist[sx][sy] = 0;
    // q.push({0, sx, sy});
    // while (!q.empty()){
    //     auto [c, i, j] = q.top();q.pop();
    //     if (dist[i][j] < c) continue;
    //     if (i < 999 && dist[i + 1][j] > dist[i][j] + hedgecost[i + 1][j]){
    //         dist[i + 1][j] = dist[i][j] + hedgecost[i + 1][j];
    //         if (i + 1 == gx && j == gy) break;
    //         q.push({dist[i + 1][j], i + 1, j});
    //     }
    //     if (j < 999 && dist[i][j + 1] > dist[i][j] + wedgecost[i][j + 1]){
    //         dist[i][j + 1] = dist[i][j] + wedgecost[i][j + 1];
    //         if (i == gx && j + 1 == gy) break;
    //         q.push({dist[i][j + 1], i, j + 1});
    //     }
    // }
    dist[sx][sy] = 0;
    srep(i, sx, 1000) srep(j, sy, 1000){
        if (i < 999) dist[i + 1][j] = min(dist[i + 1][j], dist[i][j] + hedgecost[i + 1][j]);
        if (j < 999) dist[i][j + 1] = min(dist[i][j + 1], dist[i][j] + wedgecost[i][j + 1]);
    }
    cout << dist[gx][gy] + sub << "\n";
}

int main(){
    while (true){
        int N; cin >> N;
        if (N == 0) break;
        solve(N);
    }
}
accuracy: 1
time_ms: 240
memory_kb: 16184
final_rank: 6

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 = acos(-1.0);
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); } }

tuple<vl, vi> dijkstra(int s, int N, vv<pair<int, ll>> &g){
    using P = pair<ll, int>;
    vl dist(N, INF);
    vi bef(N);
    priority_queue<P, vc<P>, greater<P>> q;
    dist[s] = 0;
    q.push({0, s});
    while (!q.empty()){
        auto [c, now] = q.top();q.pop();
        if (dist[now] < c) continue;
        for (auto&& [nxt, nc]: g[now]) if (dist[nxt] > c + nc){
            dist[nxt] = c + nc;
            bef[nxt] = now;
            q.push({dist[nxt], nxt}); 
        }
    }
    return {dist, bef};
}

void solve(int N){
    int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--;
    vi X(N), Y(N), R(N); rep(i, N) cin >> X[i] >> Y[i] >> R[i];
    rep(i, N){
        X[i]--;
        Y[i]--;
    }
    if (sx > gx){
        sx = 999 - sx;
        gx = 999 - gx;
        rep(i, N) X[i] = 999 - X[i];
    }
    if (sy > gy){
        sy = 999 - sy;
        gy = 999 - gy;
        rep(i, N) Y[i] = 999 - Y[i];
    }
    int sub = 0;
    rep(i, N) if (X[i] - R[i] <= sx && sx <= X[i] + R[i] && Y[i] - R[i] <= sy && sy <= Y[i] + R[i]) sub++;
    vvi hedgecost(1010, vi(1010, 0)), wedgecost(1010, vi(1010, 0));
    rep(i, N){
        hedgecost[max(0, X[i] - R[i])][max(0, Y[i] - R[i])]++;
        hedgecost[max(0, X[i] - R[i])][min(1009, Y[i] + R[i] + 1)]--;
        wedgecost[max(0, X[i] - R[i])][max(0, Y[i] - R[i])]++;
        wedgecost[min(1009, X[i] + R[i] + 1)][max(0, Y[i] - R[i])]--;
    }
    rep(i, 1010){
        rep(j, 1009) hedgecost[i][j + 1] += hedgecost[i][j];
    }
    rep(j, 1010){
        rep(i, 1009) wedgecost[i + 1][j] += wedgecost[i][j];
    }
    // rep(i, 10){
    //     rep(j, 10) cout << hedgecost[i][j] << " ";
    //     cout << endl;
    // }
    // rep(i, 10){
    //     rep(j, 10) cout << wedgecost[i][j] << " ";
    //     cout << endl;
    // }

    // vv<pair<int, ll>> g(1000000);
    // rep(i, 1000) rep(j, 1000){
    //     if (i < 999) g[i * 1000 + j].push_back({(i + 1) * 1000 + j, hedgecost[i + 1][j]});
    //     if (j < 999) g[i * 1000 + j].push_back({i * 1000 + j + 1, wedgecost[i][j + 1]});
    // }
    // auto [dist, bef] = dijkstra(sx * 1000 + sy, 1000000, g);
    // cout << dist[gx * 1000 + gy] + sub << "\n";
    using P = tuple<int, int, int>;
    vvi dist(1010, vi(1010, inf));
    priority_queue<P, vc<P>, greater<P>> q;
    dist[sx][sy] = 0;
    q.push({0, sx, sy});
    while (!q.empty()){
        auto [c, i, j] = q.top();q.pop();
        if (dist[i][j] < c) continue;
        if (i < 999 && dist[i + 1][j] > dist[i][j] + hedgecost[i + 1][j]){
            dist[i + 1][j] = dist[i][j] + hedgecost[i + 1][j];
            if (i + 1 == gx && j == gy) break;
            q.push({dist[i + 1][j], i + 1, j});
        }
        if (j < 999 && dist[i][j + 1] > dist[i][j] + wedgecost[i][j + 1]){
            dist[i][j + 1] = dist[i][j] + wedgecost[i][j + 1];
            if (i == gx && j + 1 == gy) break;
            q.push({dist[i][j + 1], i, j + 1});
        }
    }
    // dist[sx][sy] = 0;
    // srep(i, sx, 1000) srep(j, sy, 1000){
    //     if (i < 999) dist[i + 1][j] = min(dist[i + 1][j], dist[i][j] + hedgecost[i + 1][j]);
    //     if (j < 999) dist[i][j + 1] = min(dist[i][j + 1], dist[i][j] + wedgecost[i][j + 1]);
    // }
    cout << dist[gx][gy] + sub << "\n";
}

int main(){
    while (true){
        int N; cin >> N;
        if (N == 0) break;
        solve(N);
    }
}
accuracy: 0.5
time_ms: 660
memory_kb: 16408
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;

int sum[4][1 << 10][1 << 10];

void solve()
{
    const int siz = 1024;
    int n;
    cin >> n;
    if (n == 0) exit(0);
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    for (int i = 0; i < 4; ++i)
    {
        for (int j = 0; j < siz; ++j)
        {
            for (int k = 0; k < siz; ++k) sum[i][j][k] = 0;
        }
    }
    vector<int> x(n), y(n), r(n);
    for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> r[i];
    for (int i = 0; i < n; ++i)
    {
        if (x[i] - r[i] - 1 >= 0)
        {
            ++sum[0][x[i] - r[i] - 1][max(0, y[i] - r[i])];
            --sum[0][x[i] - r[i] - 1][min(siz - 1, y[i] + r[i] + 1)];
        }
        if (y[i] - r[i] - 1 >= 0)
        {
            ++sum[1][max(x[i] - r[i], 0)][y[i] - r[i] - 1];
            --sum[1][min(siz - 1, x[i] + r[i] + 1)][y[i] - r[i] - 1];
        }
        if (x[i] + r[i] + 1 < siz)
        {
            ++sum[2][x[i] + r[i] + 1][max(0, y[i] - r[i])];
            --sum[2][x[i] + r[i] + 1][min(siz - 1, y[i] + r[i] + 1)];
        }
        if (y[i] + r[i] + 1 < siz)
        {
            ++sum[3][max(x[i] - r[i], 0)][y[i] + r[i] + 1];
            --sum[3][min(siz - 1, x[i] + r[i] + 1)][y[i] + r[i] + 1];
        }
    }
    for (int i = 0; i < siz - 1; ++i)
    {
        for (int j = 0; j < siz; ++j)
        {
            sum[1][i + 1][j] += sum[1][i][j];
            sum[3][i + 1][j] += sum[3][i][j];
        }
    }
    for (int i = 0; i < siz; ++i)
    {
        for (int j = 0; j < siz - 1; ++j)
        {
            sum[0][i][j + 1] += sum[0][i][j];
            sum[2][i][j + 1] += sum[2][i][j];
        }
    }
    int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
    int d1 = (sx <= gx ? 0 : 2), d2 = (sy <= gy ? 1 : 3);
    vector<vector<int>> dis(siz, vector<int> (siz, 1e9));
    dis[sx][sy] = 0;
    for (unsigned i = sx; i < siz; i += dx[d1])
    {
        for (unsigned j = sy; j < siz; j += dy[d2])
        {
            unsigned nx = i + dx[d1], ny = j;
            if (nx < siz) dis[nx][ny] = min(dis[nx][ny], dis[i][j] + sum[d1][i][j]);
            nx = i, ny = j + dy[d2];
            if (ny < siz) dis[nx][ny] = min(dis[nx][ny], dis[i][j] + sum[d2][i][j]);
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i)
    {
        int dx = abs(sx - x[i]), dy = abs(sy - y[i]);
        cnt += (dx <= r[i] && dy <= r[i]);
    }
    cout << dis[gx][gy] + cnt << endl;
}

int main() {
    while (true) solve();
}
accuracy: 1
time_ms: 680
memory_kb: 24760
final_rank: 12

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int sensors_number,start_x,start_y,goal_x,goal_y;
int sensor_x[1<<17],sensor_y[1<<17],sensor_radius[1<<17];
void rotate_coordinates(int&x,int &y)
{
    int tmp=x;
    x=y;
    y=1001-tmp;
}
void rotate_all_coordinates()
{
    rotate_coordinates(start_x,start_y);
    rotate_coordinates(goal_x,goal_y);
    for(int i=0;i<sensors_number;i++)rotate_coordinates(sensor_x[i],sensor_y[i]);
}
int dp[1010][1010];
int sensor_left[1010][1010],sensor_up[1010][1010];
signed main()
{
    while(cin>>sensors_number,sensors_number)
    {
        cin>>start_x>>start_y>>goal_x>>goal_y;
        for(int i=0;i<sensors_number;i++)
        {
            cin>>sensor_x[i]>>sensor_y[i]>>sensor_radius[i];
        }
        while(!(start_x<=goal_x&&start_y<=goal_y))rotate_all_coordinates();
        for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)
        {
            dp[i][j]=1e9;
            sensor_left[i][j]=0;
            sensor_up[i][j]=0;
        }
        dp[start_x][start_y]=0;
        for(int i=0;i<sensors_number;i++)
        {
            int lx=max(sensor_x[i]-sensor_radius[i],0),ly=max(sensor_y[i]-sensor_radius[i],0),rx=min(sensor_x[i]+sensor_radius[i],1000),ry=min(sensor_y[i]+sensor_radius[i],1000);
            if(lx<=start_x&&start_x<=rx&&ly<=start_y&&start_y<=ry)dp[start_x][start_y]++;
            sensor_left[lx][ly]++;
            sensor_left[rx+1][ly]--;
            sensor_up[lx][ly]++;
            sensor_up[lx][ry+1]--;
        }
        for(int i=0;i<1010;i++)
        {
            for(int j=1;j<1010;j++)
            {
                sensor_left[j][i]+=sensor_left[j-1][i];
                sensor_up[i][j]+=sensor_up[i][j-1];
            }
        }
        for(int i=0;i<1009;i++)for(int j=0;j<1009;j++)
        {
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]+sensor_left[i][j+1]);
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]+sensor_up[i+1][j]);
        }
        cout<<dp[goal_x][goal_y]<<endl;
    }
}
accuracy: 1
time_ms: 540
memory_kb: 16248
final_rank: 10

code_snippet: #include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    using namespace __gnu_pbds;
    
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)

    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    using P=pair<ll,ll>;
    using T=tuple<int,int,int>;
    const ll INF=1001001001; 
    const ll INFL=1e18;
    const ll mod=998244353;

    void solve(int n){
        P s,g;
        cin>>s.first>>s.second>>g.first>>g.second;
        int m=2001;
        vector<vector<int>>right(m+5,vector<int>(m+5));
        vector<vector<int>>down(m+5,vector<int>(m+5));
        vector<vector<int>>dp(m+5,vector<int>(m+5,INF));

        vector<T>p;
        int need=0;
        rep(i,n){
            int x,y,r;
            cin>>x>>y>>r;
            bool out=false;
            if(s.first>=x-r&&s.first<=x+r&&s.second>=y-r&&s.second<=y+r){
                out=true;
            }
            if(g.first>=x-r&&g.first<=x+r&&g.second>=y-r&&g.second<=y+r){
                out=true;
            }
            if(out){
                need++;
            }else{
                p.push_back(make_tuple(x,y,r));
            }
        }
        
        if(s.first>g.first)swap(s,g);
        if(s.second>g.second){
            s.second=m-s.second;
            g.second=m-g.second;
            for(auto& [x,y,r]:p){
                y=m-y;
            }
        }
        dp[s.second][s.first]=need;
        for(auto& [x,y,r]:p){
            right[max(0,y-r)][max(0,x-r-1)]++;
            right[min(m,y+r+1)][max(0,x-r-1)]--;

            down[max(0,y-r-1)][max(0,x-r)]++;
            down[max(0,y-r-1)][min(m,x+r+1)]--;
        }
         

        rep(j,m){
            rep(i,m){
                right[i+1][j]+=right[i][j];
            }
        }
        rep(i,m){
            rep(j,m){
                down[i][j+1]+=down[i][j];
            }
        }
        rep(i,m){
            rep(j,m){
                chmin(dp[i+1][j],dp[i][j]+down[i][j]);
                chmin(dp[i][j+1],dp[i][j]+right[i][j]);
            }
        }
        cout<<dp[g.second][g.first]<<endl;
    }

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n;
        while(1){
            cin>>n;
            if(n==0)break;
            solve(n);
        }
        
        return 0;
    }
accuracy: 1
time_ms: 1310
memory_kb: 51864
final_rank: 15