QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242048#6570. Who Watches the Watchmen?MovingUpAC ✓1425ms9204kbC++147.0kb2023-11-06 21:37:582023-11-06 21:37:59

Judging History

你现在查看的是最新测评结果

  • [2023-11-06 21:37:59]
  • 评测
  • 测评结果:AC
  • 用时:1425ms
  • 内存:9204kb
  • [2023-11-06 21:37:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

int sgn(ll a) {
	return (a > 0) - (a < 0);
}
struct point {
	ll x, y, z;
	point() {}
	point(ll a, ll b, ll c) {
		x = a, y = b, z = c;
	}
	point operator+(point o) {
		return {x + o.x, y + o.y, z + o.z};
	}
	point operator-(point o) {
		return {x - o.x, y - o.y, z - o.z};
	}
	point operator*(ll d) {
		return {x * d, y * d, z * d};
	}
	ll lensq() {
		return x * x + y * y + z * z;
	}
	bool operator==(point o) {
		return x == o.x && y == o.y && z == o.z;
	}
	bool operator!=(point o) {
		return !(*this == o);
	}
};

point cross(point a, point b) {
	return {
		a.y * b.z - a.z * b.y,
		a.z * b.x - a.x * b.z,
		a.x * b.y - a.y * b.x
	};
}

bool is_zero(point p) {
	return !p.x && !p.y && !p.z;
}

bool collinear(point a, point b) {
	point p = cross(a, b);
	return is_zero(p);
}

bool collinear(point a, point b, point c, point d) {
	return collinear(b - a, d - c);
}

bool same_direction(point a, point b) {
	return sgn(a.x) == sgn(b.x) && sgn(a.y) == sgn(b.y) && sgn(a.z) == sgn(b.z);
}

bool correct_orientation(point a, point dir, point b) {
	point vec_ab = b - a;
	return collinear(vec_ab, dir) && same_direction(vec_ab, dir);
}

bool intersect(point a, point dir_a, point b, point dir_b) {
	point X = cross(dir_a, dir_b);
	point Y = cross(b - a, dir_b);

	if (is_zero(X)) {
		return false;
	}

	if (!collinear(X, Y)) {
		return false;
	}

	if (sgn(X.x) != sgn(Y.x) || sgn(X.y) != sgn(Y.y) || sgn(X.z) != sgn(Y.z)) {
		return false;
	}

	X = cross(dir_b, dir_a);
	Y = cross(a - b, dir_a);

	if (is_zero(X)) {
		return false;
	}

	if (!collinear(X, Y)) {
		return false;
	}

	if (sgn(X.x) != sgn(Y.x) || sgn(X.y) != sgn(Y.y) || sgn(X.z) != sgn(Y.z)) {
		return false;
	}

	return true;
}

const ll inf = LLONG_MAX;
struct minimum_cost_bipartite_matching {
	int nl, nr;
	ll mc = 0;
	vector<int>ml, mr, ly;
	minimum_cost_bipartite_matching(int nl, int nr, vector<vector<ll>> &c) : 
		nl(nl), nr(nr), ml(nl, -1), mr(nr, -1), ly(nr) {
		vector<ll> s(nl), t(nr);
		for (int i = 0; i < nl; i++) {
			int x = i, y = -1;
			vector<bool> u(nr);
			vector<ll> md(nr, inf);
			while (x != -1) {
				ll ny = -1, d = inf;
				for (int j = 0; j < nr; j++)
					if (!u[j]) {
						ll v = c[x][j] - s[x] - t[j];
						if (v < md[j])
							md[j] = v, ly[j] = y;
						if (md[j] < d)
							d = md[j], ny = j;
					} 
				s[i] += d; mc += d;
				for (int j = 0; j < nr; j++)
					if (u[j])
						s[mr[j]] += d, t[j] -= d;
					else
						md[j] -= d;
				y = ny; u[y] = true; x = mr[y];
			}
			while (y != -1) {
				mr[y] = ly[y] != -1 ? mr[ly[y]] : i; ml[mr[y]] = y;
				y = ly[y];
			}
		}
	}
};

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	if (n == 1) {
		cout << "-1\n";
		return 0;
	}
	vector<pair<point, point>> v;
	for (int i = 0; i < n; i++) {
		point p;
		cin >> p.x >> p.y >> p.z;
		point dir;
		cin >> dir.x >> dir.y >> dir.z;
		v.push_back({p, dir});
	}

	vector<vector<ll>> edges(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		vector<bool> reachable(n, true);
		for (int j = 0; j < n; j++) {
			if (i == j) {
				continue;
			}
			point vec_ij = v[j].first - v[i].first;
			for (int k = 0; k < n; k++) {
				if (i == k || j == k) {
					continue;
				}

				point vec_ik = v[k].first - v[i].first;
				if (collinear(vec_ij, vec_ik)) {
					if (vec_ij.lensq() < vec_ik.lensq()) {
						reachable[k] = false;
					}
				}
			}
		}

		for (int j = 0; j < n; j++) {
			if (i == j || !reachable[j]) {
				edges[i][j] = mod;
				continue;
			}

			if (correct_orientation(v[i].first, v[i].second, v[j].first)) {
				edges[i][j] = 0;
			} else {
				edges[i][j] = 1;
			}
 		}
	}

	minimum_cost_bipartite_matching matching(n, n, edges);
	if (matching.mc < mod) {
		cout << matching.mc << "\n";
		return 0;
	}

	assert(n % 2 == 1);

	sort(v.begin(), v.end(), [](pair<point, point> A, pair<point, point> B) {
		if (A.first.x != B.first.x) {
			return A.first.x < B.first.x;
		}
		if (A.first.y != B.first.y) {
			return A.first.y < B.first.y;
		}
		return A.first.z < B.first.z; 
	});

	ll answer = LLONG_MAX;
	for (int i = 0; i < n; i++) {
		vector<pair<point, point>> cur_v;
		for (auto p : v) {
			if (p.first != v[i].first) {
				cur_v.push_back(p);
			}
		}
		vector<ll> pref_cost(cur_v.size(), mod), suf_cost(cur_v.size(), mod);
		for (int j = 1; j < cur_v.size(); j += 2) {
			ll cost = 0;
			if (!correct_orientation(cur_v[j - 1].first, cur_v[j - 1].second, cur_v[j].first)) {
				cost++;
			}
			if (!correct_orientation(cur_v[j].first, cur_v[j].second, cur_v[j - 1].first)) {
				cost++;
			}

			pref_cost[j] = cost;
			if (j - 2 >= 0) {
				pref_cost[j] += pref_cost[j - 2];
			}
		}

		for (int j = cur_v.size() - 2; j >= 0; j -= 2) {
			ll cost = 0;
			if (!correct_orientation(cur_v[j + 1].first, cur_v[j + 1].second, cur_v[j].first)) {
				cost++;
			}
			if (!correct_orientation(cur_v[j].first, cur_v[j].second, cur_v[j + 1].first)) {
				cost++;
			}

			suf_cost[j] = cost;
			if (j + 2 < cur_v.size()) {
				suf_cost[j] += suf_cost[j + 2];
			}
		}

		vector<vector<ll>> right_cost(cur_v.size(), vector<ll>(cur_v.size(), mod)), left_cost(cur_v.size(), vector<ll>(cur_v.size(), mod));
		for (int ii = 0; ii < cur_v.size(); ii++) {
			right_cost[ii][ii] = left_cost[ii][ii] = 0;
			ll cur_costR = 0, cur_costL = 0;
			for (int j = ii + 1; j < cur_v.size(); j++) {
				if (!correct_orientation(cur_v[j - 1].first, cur_v[j - 1].second, cur_v[j].first)) {
					cur_costR++;
				}
				if (!correct_orientation(cur_v[j].first, cur_v[j].second, cur_v[j - 1].first)) {
					cur_costL++;
				}
				right_cost[ii][j] = cur_costR;
				left_cost[ii][j] = cur_costL;
			}
		}

		// will move i
		for (int a = 0; a < cur_v.size(); a++) {
			// a will point to i
			point vec_a = cur_v[a].first;
			for (int b = 0; b < cur_v.size(); b++) {
				// i will point to b
				if (abs(a - b) % 2 != 1) {
					continue;
				}

				point vec_b = v[i].second * (-1);
				ll cand = 0;
				int L = min(a, b) - 1;
				if (L >= 0) {
					cand += pref_cost[L];
				}

				int R = max(a, b) + 1;
				if (R < cur_v.size()) {
					cand += suf_cost[R];
				}

				if (a < b) {
					cand += left_cost[a][b];
				} else {
					cand += right_cost[b][a];
				}

				if (collinear(cur_v[a].second, cur_v[a].first - v[i].first)) {
					if (!collinear(v[i].second, cur_v[a].first - v[i].first)) {
						cand++;
					} else {
						cand += 2;
					}
				} else {
					if (!collinear(v[i].second, cur_v[a].first - v[i].first)) {
						if (!intersect(cur_v[a].first, cur_v[a].second, cur_v[b].first, vec_b))  {
							cand++;
						}
					} else {
						cand++;
					}
				}
				cand += 1000;

				answer = min(answer, cand);
			}
		}
	}


	cout << answer << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3416kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1002

result:

ok single line: '1002'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

4
66 45 10 73 39 36
95 14 26 47 84 59
14 66 89 89 36 78
16 27 94 79 24 24

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3408kb

input:

3
0 0 0 1 0 0
1 1 1 1 0 0
2 2 2 1 0 0

output:

1002

result:

ok single line: '1002'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

3
0 0 0 1 1 1
1 1 1 1 0 0
2 2 2 1 0 0

output:

1001

result:

ok single line: '1001'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

3
0 0 0 1 0 0
1 1 1 1 0 0
2 2 2 -1 -1 -1

output:

1001

result:

ok single line: '1001'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3500kb

input:

3
0 0 0 1 0 0
1 1 1 1 2 2
2 2 2 -1 -1 -1

output:

1000

result:

ok single line: '1000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

3
0 0 0 1 0 0
1 1 1 1 2 2
2 2 2 1 1 1

output:

1001

result:

ok single line: '1001'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

1
0 0 0 3 1 4

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

4
0 0 0 1 1 1
1 0 0 -1 0 0
1 1 1 0 -1 0
1 0 1 0 1 0

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 377ms
memory: 5200kb

input:

500
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 -1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 1 0 0
8 0 0 1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0
11 0 0 -1 0 0
12 0 0 1 0 0
13 0 0 -1 0 0
14 0 0 1 0 0
15 0 0 1 0 0
16 0 0 1 0 0
17 0 0 -1 0 0
18 0 0 -1 0 0
19 0 0 -1 0 0
20 0 0 -1 0 0
21 0 0 1 0 0
22 0 0 1 0 0...

output:

250

result:

ok single line: '250'

Test #11:

score: 0
Accepted
time: 364ms
memory: 5104kb

input:

500
0 0 0 0 1 0
0 1 0 0 1 0
0 2 0 0 -1 0
0 3 0 0 1 0
0 4 0 0 1 0
0 5 0 0 1 0
0 6 0 0 1 0
0 7 0 0 1 0
0 8 0 0 1 0
0 9 0 0 1 0
0 10 0 0 -1 0
0 11 0 0 -1 0
0 12 0 0 1 0
0 13 0 0 -1 0
0 14 0 0 1 0
0 15 0 0 1 0
0 16 0 0 1 0
0 17 0 0 -1 0
0 18 0 0 -1 0
0 19 0 0 -1 0
0 20 0 0 -1 0
0 21 0 0 1 0
0 22 0 0 1 0...

output:

250

result:

ok single line: '250'

Test #12:

score: 0
Accepted
time: 368ms
memory: 5196kb

input:

500
0 0 0 0 0 1
0 0 1 0 0 1
0 0 2 0 0 -1
0 0 3 0 0 1
0 0 4 0 0 1
0 0 5 0 0 1
0 0 6 0 0 1
0 0 7 0 0 1
0 0 8 0 0 1
0 0 9 0 0 1
0 0 10 0 0 -1
0 0 11 0 0 -1
0 0 12 0 0 1
0 0 13 0 0 -1
0 0 14 0 0 1
0 0 15 0 0 1
0 0 16 0 0 1
0 0 17 0 0 -1
0 0 18 0 0 -1
0 0 19 0 0 -1
0 0 20 0 0 -1
0 0 21 0 0 1
0 0 22 0 0 1...

output:

250

result:

ok single line: '250'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

5
1 0 0 1 -1 0
2 0 0 0 1 0
3 0 0 -1 0 0
4 0 0 -1 0 0
5 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3436kb

input:

5
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 0 1 0
5 0 0 -1 -1 0

output:

1000

result:

ok single line: '1000'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

6
0 1 0 1 0 0
0 2 0 0 2 0
0 3 0 0 3 0
0 4 0 0 4 0
0 5 0 0 5 0
0 6 0 0 6 0

output:

4

result:

ok single line: '4'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

9
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
0 1 0 0 1 0
0 2 0 0 1 0
0 3 0 0 1 0
0 0 1 0 0 1
0 0 2 0 0 1
0 0 3 0 0 1

output:

3

result:

ok single line: '3'

Test #17:

score: 0
Accepted
time: 1336ms
memory: 9204kb

input:

499
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 -1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 1 0 0
8 0 0 1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0
11 0 0 -1 0 0
12 0 0 1 0 0
13 0 0 -1 0 0
14 0 0 1 0 0
15 0 0 1 0 0
16 0 0 1 0 0
17 0 0 -1 0 0
18 0 0 -1 0 0
19 0 0 -1 0 0
20 0 0 -1 0 0
21 0 0 1 0 0
22 0 0 1 0 0...

output:

1220

result:

ok single line: '1220'

Test #18:

score: 0
Accepted
time: 1317ms
memory: 9064kb

input:

499
0 0 0 0 1 0
0 1 0 0 1 0
0 2 0 0 -1 0
0 3 0 0 1 0
0 4 0 0 1 0
0 5 0 0 1 0
0 6 0 0 1 0
0 7 0 0 1 0
0 8 0 0 1 0
0 9 0 0 1 0
0 10 0 0 -1 0
0 11 0 0 -1 0
0 12 0 0 1 0
0 13 0 0 -1 0
0 14 0 0 1 0
0 15 0 0 1 0
0 16 0 0 1 0
0 17 0 0 -1 0
0 18 0 0 -1 0
0 19 0 0 -1 0
0 20 0 0 -1 0
0 21 0 0 1 0
0 22 0 0 1 0...

output:

1220

result:

ok single line: '1220'

Test #19:

score: 0
Accepted
time: 1425ms
memory: 9136kb

input:

499
0 0 0 0 0 1
0 0 1 0 0 1
0 0 2 0 0 -1
0 0 3 0 0 1
0 0 4 0 0 1
0 0 5 0 0 1
0 0 6 0 0 1
0 0 7 0 0 1
0 0 8 0 0 1
0 0 9 0 0 1
0 0 10 0 0 -1
0 0 11 0 0 -1
0 0 12 0 0 1
0 0 13 0 0 -1
0 0 14 0 0 1
0 0 15 0 0 1
0 0 16 0 0 1
0 0 17 0 0 -1
0 0 18 0 0 -1
0 0 19 0 0 -1
0 0 20 0 0 -1
0 0 21 0 0 1
0 0 22 0 0 1...

output:

1220

result:

ok single line: '1220'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3424kb

input:

5
0 0 0 0 -1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 0 0

output:

1001

result:

ok single line: '1001'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

5
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 0 1 0

output:

1001

result:

ok single line: '1001'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

5
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 0 -1 0
3 0 0 1 0 0
4 0 0 -1 0 0

output:

1001

result:

ok single line: '1001'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

5
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 0 -1 0
4 0 0 1 0 0

output:

1001

result:

ok single line: '1001'

Test #24:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

5
0 0 0 1 1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 -1 -1 0

output:

1001

result:

ok single line: '1001'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3504kb

input:

5
0 0 0 1 1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 1 0

output:

1001

result:

ok single line: '1001'

Test #26:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

5
0 0 0 5 -1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 -1 0

output:

1001

result:

ok single line: '1001'

Test #27:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

17
0 0 0 0 0 1
0 1 0 0 0 1
0 2 0 0 0 1
0 3 0 0 0 1
0 4 0 0 0 1
0 -1 0 0 0 1
0 -2 0 0 0 1
0 -3 0 0 0 1
0 -4 0 0 0 1
1 3 0 0 0 1
2 3 0 0 0 1
-1 3 0 0 0 1
-2 3 0 0 0 1
1 -3 0 0 0 1
2 -3 0 0 0 1
-1 -3 0 0 0 1
-2 -3 0 0 0 1

output:

17

result:

ok single line: '17'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

17
0 0 0 0 4 0
0 1 0 0 -1 0
0 2 0 0 -2 0
0 3 0 0 -3 0
0 4 0 0 -4 0
0 -1 0 0 1 0
0 -2 0 0 2 0
0 -3 0 0 3 0
0 -4 0 0 4 0
1 3 0 -1 -3 0
2 3 0 -1 -2 0
-1 3 0 1 -3 0
-2 3 0 2 -3 0
1 -3 0 -1 3 0
2 -3 0 -2 3 0
-1 -3 0 1 3 0
-2 -3 0 2 3 0

output:

10

result:

ok single line: '10'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

17
0 0 0 0 1 0
0 1 0 0 1 0
0 2 0 0 1 0
0 3 0 0 1 0
0 4 0 2 -1 0
0 -1 0 0 1 0
0 -2 0 0 1 0
0 -3 0 0 1 0
0 -4 0 0 1 0
1 3 0 -1 0 0
2 3 0 -1 0 0
-1 3 0 -1 0 0
-2 3 0 4 -6 0
1 -3 0 -1 0 0
2 -3 0 -1 0 0
-1 -3 0 -1 0 0
-2 -3 0 2 -1 0

output:

3

result:

ok single line: '3'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

5
0 0 0 1 1 1
0 0 1 0 0 1
0 0 2 0 0 1
0 0 3 0 0 1
0 0 4 0 -1 1

output:

1001

result:

ok single line: '1001'

Test #31:

score: 0
Accepted
time: 329ms
memory: 5132kb

input:

500
-455212 958307 274912 -88656 390687 881409
-498879 -623821 322766 -916023 347922 541726
-594515 -554311 -413504 -881701 -506880 -144667
658945 -503396 791805 314816 -830920 -769486
-200847 845218 468338 -166468 -49854 -287877
-820402 914874 916800 258029 -210000 -296727
702016 -389491 -31529 -52...

output:

499

result:

ok single line: '499'

Test #32:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

3
1000000 -1 -1 -1000000 -999999 -999999
-1 1000000 -1 101 -101 0
100 999899 -1 999999 1000000 999999

output:

1000

result:

ok single line: '1000'

Test #33:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

3
1000000 -1 -1 1000000 999999 999999
-1 1000000 -1 101 -101 0
100 999899 -1 999999 1000000 999999

output:

1001

result:

ok single line: '1001'

Test #34:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

3
1000000 -1 -1 -1000000 -999999 -999999
-1 1000000 -1 101 -101 0
100 999899 -1 -999999 -1000000 -999999

output:

1001

result:

ok single line: '1001'

Test #35:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

3
1000000 -1 -1 1000000 999999 999999
-1 1000000 -1 101 -101 0
100 999899 -1 -999999 -1000000 -999999

output:

1001

result:

ok single line: '1001'

Test #36:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

3
10 -1 -1 -10 -9 -9
-1 10 -1 11 -11 0
21 -12 -1 9 10 9

output:

1000

result:

ok single line: '1000'

Test #37:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 0 -1 0
3 0 0 1 0 0
4 0 0 -1 1 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #38:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

7
0 0 0 1 0 0
1 0 0 0 -1 0
2 0 0 -1 0 0
3 0 0 1 0 0
4 0 0 -1 1 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #39:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

7
0 0 0 0 -1 0
1 0 0 1 0 0
2 0 0 -1 0 0
3 0 0 1 0 0
4 0 0 -1 1 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #40:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 1 0
4 0 0 0 -1 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #41:

score: 0
Accepted
time: 0ms
memory: 3384kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 1 0
4 0 0 1 0 0
5 0 0 0 -1 0
6 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #42:

score: 0
Accepted
time: 0ms
memory: 3488kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 1 0
4 0 0 1 0 0
5 0 0 -1 0 0
6 0 0 0 -1 0

output:

1000

result:

ok single line: '1000'

Test #43:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 0 1 0
5 0 0 1 -1 0
6 0 0 -1 0 0
7 0 0 -1 0 0
8 0 0 -1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #44:

score: 0
Accepted
time: 0ms
memory: 3452kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 1 -1 0
5 0 0 0 1 0
6 0 0 -1 0 0
7 0 0 -1 0 0
8 0 0 -1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #45:

score: 0
Accepted
time: 1ms
memory: 3508kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 0 1 0
5 0 0 -1 0 0
6 0 0 1 -1 0
7 0 0 -1 0 0
8 0 0 -1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #46:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 0 1 0
5 0 0 -1 0 0
6 0 0 -1 0 0
7 0 0 1 -1 0
8 0 0 -1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #47:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 -1 -1 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 1 0 0
8 0 0 0 1 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #48:

score: 0
Accepted
time: 1ms
memory: 3444kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 1 0 0
5 0 0 -1 -1 0
6 0 0 1 0 0
7 0 0 1 0 0
8 0 0 0 1 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #49:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 -1 -1 0
7 0 0 1 0 0
8 0 0 0 1 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #50:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 -1 -1 0
8 0 0 0 1 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #51:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

11
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 -1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 0 1 0
8 0 0 -1 -1 0
9 0 0 1 0 0
10 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #52:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

27
-1000000 -1000000 -1000000 1000000 0 1000000
-1000000 -1000000 0 -1000000 0 1000000
-1000000 -1000000 1000000 -1000000 0 1000000
-1000000 0 -1000000 1000000 1000000 1000000
-1000000 0 0 0 -1000000 1000000
-1000000 0 1000000 1000000 -1000000 1000000
-1000000 1000000 -1000000 1000000 0 1000000
-100...

output:

17

result:

ok single line: '17'

Test #53:

score: 0
Accepted
time: 397ms
memory: 5124kb

input:

500
-999983 -999981 -999977 17 19 23
-999966 -999962 -999954 17 19 23
-999949 -999943 -999931 17 19 23
-999932 -999924 -999908 17 19 23
-999915 -999905 -999885 17 19 23
-999898 -999886 -999862 17 19 23
-999881 -999867 -999839 17 19 23
-999864 -999848 -999816 17 19 23
-999847 -999829 -999793 17 19 23...

output:

250

result:

ok single line: '250'

Test #54:

score: 0
Accepted
time: 358ms
memory: 5192kb

input:

500
999983 999981 999977 -17 -19 -23
999966 999962 999954 -17 -19 -23
999949 999943 999931 -17 -19 -23
999932 999924 999908 -17 -19 -23
999915 999905 999885 -17 -19 -23
999898 999886 999862 -17 -19 -23
999881 999867 999839 -17 -19 -23
999864 999848 999816 -17 -19 -23
999847 999829 999793 -17 -19 -23...

output:

250

result:

ok single line: '250'

Test #55:

score: 0
Accepted
time: 367ms
memory: 5104kb

input:

500
999686 -999841 999735 -314 159 -265
999372 -999682 999470 -314 159 -265
999058 -999523 999205 314 -159 265
998744 -999364 998940 -314 159 -265
998430 -999205 998675 -314 159 -265
998116 -999046 998410 -314 159 -265
997802 -998887 998145 -314 159 -265
997488 -998728 997880 -314 159 -265
997174 -9...

output:

250

result:

ok single line: '250'

Test #56:

score: 0
Accepted
time: 365ms
memory: 5136kb

input:

500
999900 -999800 999700 -100 200 -300
999800 -999600 999400 -100 200 -300
999700 -999400 999100 100 -200 300
999600 -999200 998800 -100 200 -300
999500 -999000 998500 -100 200 -300
999400 -998800 998200 -100 200 -300
999300 -998600 997900 -100 200 -300
999200 -998400 997600 -100 200 -300
999100 -9...

output:

250

result:

ok single line: '250'

Test #57:

score: 0
Accepted
time: 421ms
memory: 4920kb

input:

480
-2402 3028 3274 23 -29 -31
-79 99 143 23 -29 -31
3854 -4860 -5158 -23 29 31
1370 -1728 -1810 -23 29 31
-4127 5203 5599 23 -29 -31
-5461 6885 7397 23 -29 -31
2382 -3004 -3174 -23 29 31
-1965 2477 2685 23 -29 -31
2888 -3642 -3856 -23 29 31
-3782 4768 5134 23 -29 -31
1899 -2395 -2523 -23 29 31
59 -...

output:

122

result:

ok single line: '122'

Test #58:

score: 0
Accepted
time: 421ms
memory: 4844kb

input:

480
43422 13353 -25668 414 129 -256
1608 324 188 414 129 -256
-69186 -21735 43964 -414 -129 256
-24474 -7803 16316 -414 -129 256
74472 23028 -44868 414 129 -256
98484 30510 -59716 414 129 -256
-42690 -13479 27580 -414 -129 256
35556 10902 -20804 414 129 -256
-51798 -16317 33212 -414 -129 256
68262 2...

output:

123

result:

ok single line: '123'

Test #59:

score: 0
Accepted
time: 23ms
memory: 3732kb

input:

180
375 636 1057 -4 -8 -12
47 -20 73 4 8 12
331 548 925 -4 -8 -12
-29 -172 -155 4 8 12
-153 -420 -527 4 8 12
427 740 1213 -4 -8 -12
-173 -460 -587 4 8 12
-241 -596 -791 4 8 12
179 244 469 -4 -8 -12
159 204 409 -4 -8 -12
-161 -436 -551 4 8 12
399 684 1129 -4 -8 -12
223 332 601 -4 -8 -12
59 4 109 -4 -...

output:

42

result:

ok single line: '42'

Test #60:

score: 0
Accepted
time: 42ms
memory: 3896kb

input:

220
27 -85 15 12 8 4
927 515 315 -12 -8 -4
-93 -165 -25 12 8 4
1083 619 367 -12 -8 -4
39 -77 19 12 8 4
-1281 -957 -421 12 8 4
1143 659 387 -12 -8 -4
183 19 67 -12 -8 -4
1047 595 355 -12 -8 -4
567 275 195 -12 -8 -4
531 251 183 -12 -8 -4
-177 -221 -53 12 8 4
579 283 199 -12 -8 -4
-561 -477 -181 12 8 4...

output:

52

result:

ok single line: '52'

Test #61:

score: 0
Accepted
time: 0ms
memory: 3464kb

input:

60
-171 215 267 23 -29 -31
473 -597 -601 -23 29 31
312 -394 -384 -23 29 31
404 -510 -508 -23 29 31
197 -249 -229 -23 29 31
335 -423 -415 -23 29 31
-654 824 918 23 -29 -31
-493 621 701 23 -29 -31
565 -713 -725 -23 29 31
-217 273 329 23 -29 -31
-631 795 887 23 -29 -31
496 -626 -632 -23 29 31
-447 563 ...

output:

17

result:

ok single line: '17'

Test #62:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

3
-1 0 0 2 1 0
1 0 0 -2 1 0
3 0 0 -2 -1 0

output:

1001

result:

ok single line: '1001'

Test #63:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

5
0 0 0 0 1 0
10 0 0 -1 1 0
0 10 0 -1 -1 0
-10 0 0 1 -1 0
0 -10 0 1 1 0

output:

1

result:

ok single line: '1'

Test #64:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

5
0 2 0 0 1 0
10 0 0 -1 1 0
0 10 0 -1 -1 0
-10 0 0 1 -1 0
0 -10 0 1 1 0

output:

1

result:

ok single line: '1'

Test #65:

score: 0
Accepted
time: 309ms
memory: 5188kb

input:

500
464689 -654475 874948 278641 -792884 186354
-798268 -885245 366579 415873 -814492 568386
548594 757214 459960 -318745 -320885 285634
-970144 68165 91372 -935576 -557281 -82177
-71496 697792 859229 603072 -751718 -629380
-391402 -320266 -691800 99295 771407 -415586
131176 -704350 628899 959024 80...

output:

500

result:

ok single line: '500'

Test #66:

score: 0
Accepted
time: 307ms
memory: 5104kb

input:

500
660575 -715271 73415 436140 226362 12224
19467 916145 -662062 -510604 824283 454499
205202 -915814 -735123 -110822 -83586 808202
13120 -72969 106150 -211607 557293 169887
-5849 149098 -624091 831479 -195891 -854258
335561 -450902 467595 -612441 695943 -877490
-356999 -751820 -886079 499927 46503...

output:

500

result:

ok single line: '500'

Test #67:

score: 0
Accepted
time: 308ms
memory: 5100kb

input:

500
-425261 857089 -722463 345227 -983886 -779314
873569 -40018 -490178 580005 -863510 -254613
-435240 -520380 84908 -513784 564739 330588
-932188 -477605 -347322 492032 -294079 477227
-72311 862368 -29594 -887377 -627667 -608677
-775504 -953650 8567 -11911 -162415 -485409
822275 -380961 773749 9387...

output:

500

result:

ok single line: '500'

Test #68:

score: 0
Accepted
time: 309ms
memory: 5172kb

input:

500
-132886 502058 -877447 79042 35022 -322286
101780 -909854 172531 103616 -119015 -271777
289064 -256857 -663836 977205 -748931 -999133
-68650 848633 -3718 -874892 260143 -880264
399836 -18330 881394 -913991 761700 620864
642012 105194 -288186 637083 -765709 -480047
-818650 -112345 310067 -918378 ...

output:

500

result:

ok single line: '500'

Test #69:

score: 0
Accepted
time: 312ms
memory: 5188kb

input:

500
-455212 958307 274912 -88656 390687 881409
-498879 -623821 322766 -916023 347922 541726
-594515 -554311 -413504 -881701 -506880 -144667
658945 -503396 791805 314816 -830920 -769486
-200847 845218 468338 -166468 -49854 -287877
-820402 914874 916800 258029 -210000 -296727
702016 -389491 -31529 -52...

output:

500

result:

ok single line: '500'