We need to solve the problem: Given n points in 5-dimensional space, we need to find good points. A point a is good if there do NOT exist two distinct points b and c (b != c, both not equal to a) such that the angle between vectors (b - a) and (c - a) is acute (< 90 degrees). Equivalent: For point a, for every pair of distinct b,c (b!=c, b != a, c != a) the angle between (b-a) and (c-a) is >= 90 degrees (i.e., non-acute). Or we could say: a is good if all such vectors from a to other points form pairwise angles of at least 90 degrees. Actually it's "there exist b and c such that angle is acute" makes a bad. So good means no such pair exists.
We have n up to 1000. Brute-force for each point a: consider vectors from a to all other points. There are up to 999 vectors (each 5-dim). Need to check if there exists any pair of distinct vectors with acute angle (dot product > 0, since cos = dot/(|v||w|) > 0). The angle is strictly less than 90 degrees if dot product > 0. So we need to check for any pair (i,j) i!=j, (v_i·v_j) > 0. If any, then a is bad.
But checking all pairs O(n^3) overall (n points * ( (n-1)^2 ) ) = O(n^3) ~ 10^9 for n=1000 => too slow.
We need better approach.
Observing that dimensions = 5 (fixed). Maybe we can use geometry properties: In d dimensions, set of vectors with pairwise non-acute angles (dot <=0) is limited. Known fact: In Euclidean space of dimension d, the maximum size of a set of vectors with pairwise obtuse (or right) angles? Actually can we have many vectors with all pairwise dot <=0? In R^d, the maximum number of vectors with pairwise obtuse angles (strictly > 90?) Not exactly. But we are checking for existence of any acute pair. For a given point a, we have m = n-1 vectors. If m > something, then must have acute pair? Possibly. But we need exact condition: For point a to be good, the set of vectors must have all pairwise dot <=0.
What is maximum size of a set of vectors in R^5 such that all pairwise dot <=0? This is similar to the concept of "obtuse" or "non-acute" sets. There is known result: In d-dimensional Euclidean space, the maximum number of vectors that can be pairwise non-acute (i.e., have dot <=0) is at most 2d? Actually, consider the problem of equiangular lines? No. For vectors with non-positive dot product, there is a bound: In R^d, there can be at most 2d vectors such that the angle between any two is at least 90 degrees. For example, in the plane (d=2), you can have at most 4 vectors with pairwise angles >= 90? Let's check: In 2D, you can have 3 vectors at 120° each, which are all >90°, but dot product? cos120 = -0.5 <0, so non-acute. So 3 > 2d? 2d=4, so 3 <=4, ok. Actually you can have 4? The coordinate axes: (1,0), (-1,0), (0,1), (0,-1). Angle between (1,0) and (-1,0) is 180°, which is >90°, but dot = -1 <0. Between (1,0) and (0,1) is 90°, dot=0. So all pairwise dot <=0? Check (1,0) and (0,-1): dot=0. (1,0) and (-1,0): -1. (0,1) and (0,-1): -1. So indeed all pairwise dot <=0. So 4 vectors works in 2D. That's 2d. Could there be 5? Probably not. In 3D, the maximum is 6? The coordinate axes and their negatives: (1,0,0),(-1,0,0),(0,1,0),(0,-1,0),(0,0,1),(0,0,-1) => all pairwise dot <=0? Check (1,0,0) and (0,1,0): 0, ok; (1,0,0) and (-1,0,0): -1; (1,0,0) and (0,-1,0): 0; (1,0,0) and (0,0,1): 0; (1,0,0) and (0,0,-1):0. So works. That's 6=23. Can we have 7? Probably not. In d dimensions, maximum size of a set of vectors with pairwise non-positive dot product (i.e., <=0) is at most 2d. This is a known result: For a set of vectors in R^d with mutual angles at least 90°, the maximum cardinality is 2d. This can be proved by linear independence arguments. Indeed, if we have more than 2d vectors, then by a certain sign assignment they become linearly dependent? Alternatively, the bound is 2d. I recall the problem "Angles and Sides" in Codeforces? Possibly it's a known CF problem: "Bad and Good points in 5-dimensional space". Actually there is Codeforces problem 251A? Not sure. But I've seen similar problem: Given points in 5D, find points that are "good". The solution often uses the property that if there are more than 11? Wait 5 dimensions => 2d = 10. But points can be many. Actually check: For a point to be good, all vectors from it to other points must be pairwise non-acute. So if n-1 > 25 =10, then automatically point is bad (since maximum set size with pairwise non-acute is <=10). But careful: The bound is on vectors, not points? The vectors are from a to other points. However, note that vectors can be scaled arbitrarily, but dot product condition is scaling invariant: if u and v are vectors, the sign of dot product is scale invariant. So the direction matters. So the bound applies to any set of rays (half-lines) with pairwise angle >= 90°. In R^5, the maximum number of such rays is 10. Actually I think it's 2*5 =10. But I've also seen a bound: In d-dimensional space, the maximum number of mutually obtuse vectors (strictly >90) is d+1? No, that's for simplex? For acute angles? There's many variants.
Let's verify: In 2D, 4 is maximum. In 3D, 6 is maximum. So pattern 2d. In 5D, maximum 10. So if a point has more than 10 other points (i.e., n-1 > 10 => n > 11), then it must be bad. But the problem allows n up to 1000, so many points will be automatically bad if they have >10 neighbors. But careful: The condition for bad is existence of any acute pair. Could a set of >10 vectors have all pairwise angles >=90? The bound says no, it's impossible. So if n > 11, then any point with more than 10 neighbors is automatically bad. That means only points such that the total number of points n <= 11 could possibly be good? But wait: The point itself is one of the n points; other points count. So if n is 1000, any point has 999 neighbors, which is >10, so all points would be bad? But the sample 1 has n=6, which is <=11, and there is a good point (the origin). Actually n=6 < 11, so it's possible. But if n=12, would every point be bad? Possibly. Let's test: Suppose we have 12 points. For any point a, there are 11 other points. If the maximum number of pairwise non-acute vectors is 10, then with 11 vectors there must be at least one acute pair, so a is bad. So indeed, for n>=12, no good points. But is that bound always strict? Let's confirm the bound.
We need to be careful: The vectors are from a to other points. They are not required to be unit vectors, but sign of dot product only depends on direction. So we can consider normalized directions. The condition: For all distinct b,c, (b-a)·(c-a) <= 0. That is, pairwise dot <=0.
Claim: In R^d, any set of vectors with pairwise dot <=0 has size at most 2d.
Proof: Suppose we have m vectors v_i. Consider the set of vectors and their negatives? Actually we can show that they are linearly independent after a sign assignment. Standard approach: If we take any subset of these vectors, they cannot all lie in a half-space containing the origin? Actually there is known result: A set of vectors with mutual non-positive inner products in R^d has size at most 2d. One way: Consider the convex hull; there is relation to contact numbers? But I'm pretty sure it's correct for d=5.
Let's quickly reason: Suppose we have m vectors v_i with v_i·v_j <= 0 for i != j. Then we can define a matrix of dot products. For any scalars x_i >=0, the squared length of sum(x_i v_i) is sum x_i^2 |v_i|^2 + 2 sum_{i<j} x_i x_j (v_i·v_j) <= sum x_i^2 |v_i|^2. Not directly helpful.
Another approach: If we have such vectors, we can consider them as points on the unit sphere, with pairwise dot <=0. The spherical code with angular separation at least 90°: maximum size in d dimensions? Indeed, that's the kissing number? Actually the maximum number of points on a sphere such that the angular distance between any two is at least 90° is known as the "maximal size of a set of points on the sphere with pairwise obtuse angles". That is the problem of constructing an orthant? Actually the maximum is 2d, achieved by the cross polytope: the vertices of the cross polytope normalized? The cross polytope in d dimensions has 2d vertices: (1,0,...,0), (-1,0,...,0), (0,1,0,...,0), (0,-1,...), etc. Their pairwise dot product is either -1 if opposite, 0 if different axes, <=0. So indeed 2d is achievable. Can we have more? For d=2, try 5 points on a circle with pairwise angles >= 90? That would mean at most 4. For d=3, try 7? I think 6 is max. So bound holds.
Thus if n-1 > 2*5 = 10, then a is bad. So for n>=12, no good points. For n <= 11, we can brute-force check each point: For each point a, compute vectors to all other points, and check pairwise dot > 0. Since n<=11, m <= 10, checking O(m^2) = O(100) per point, total O(n * n^2) = O(1331) trivial. So we can just implement that.
But is the bound rigorous? Let's verify for d=5: Could there be a set of 11 vectors in R^5 with pairwise dot <=0? If not, then our reasoning is correct. I think it's a known fact: The maximum cardinality of a set of vectors in R^d with pairwise non-positive inner products is at most 2d. I've seen it as "obtuse code" or "acute set"? Actually there is also a result: In R^d, the maximum number of points such that any two vectors form an obtuse or right angle is at most 2d. It can be proven by linear algebra: Consider these vectors and also their negatives? Actually we can prove: Suppose we have m vectors v_i. Consider the matrix A (d x m) whose columns are v_i. Then the Gram matrix G = A^T A has non-positive off-diagonals. Then one can show that m <= 2d. I recall a known lemma: If we have vectors u1,...,uk in R^d such that u_i·u_j <= 0 for i != j, then they are linearly independent after possibly flipping signs? Wait, there's a result: There exists a selection of signs ε_i = ±1 such that the set {ε_i u_i} is linearly independent? Not sure.
But I'm fairly confident the bound is correct. However, we need to be careful: The vectors are not required to be non-zero? Actually points are distinct, so b != a, so vectors are non-zero. So okay.
But also consider possibility that some vectors could be exactly opposite directions? That yields dot product negative (if exactly opposite, dot = -|v||w| < 0). So okay.
Thus for n >= 12, answer is 0. But let's double-check with problem constraints: n up to 1000. Many solutions on Codeforces (if this is from CF) likely use this bound. Indeed I recall a CF problem "Dima and Bacteria" no. Actually there is CF Round #... about "Good Points" in 5D. I've seen it: "CF 251B? Or something: "Points in 5D". Many participants used the property that if n > 11, answer is 0. So likely it's correct.
Nevertheless, we should verify with some small examples: n=1, there are no other points, so condition "there exist different points b and c" cannot be satisfied, so point is good? The definition: "We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors ab and ac is acute. Otherwise, the point is called good." For n=1, there are no b and c distinct from a, so condition fails, thus a is good. So answer is 1 and index 1. That matches bound? n=1 <= 11, so we can compute. For n=2: then for point a, there is only one other point b, but we need two different points b and c, both distinct from a. Since only b exists, no pair, so both points are good? Actually for point a, we need b and c different and both not equal to a. There is only b; we cannot choose two distinct b,c. So condition fails => a is good. Similarly point b is good. So both good. So answer 2 indices 1,2. But wait: is that consistent with definition? "there are different points b and c, not equal to a" means b and c are two distinct points from the set, both not equal to a. If there is only one other point, it's impossible to find two distinct b and c. So good. So for n=2, both good. But what about bound? n=2 => m=n-1=1 <=10, so it's possible. So fine.
Now, for n=3: we need to check. Possibly all are good if no acute angle found. For sample 2, n=3, answer 0, meaning all are bad. So not automatic. So we need to check.
Thus algorithm:
- Read n and points.
- If n > 11: output 0 (no good points). Actually if n >= 12, then for each point a, there are at least 11 other points. But is it possible that some point a has exactly 11 vectors? Yes n>=12 => for any a, m >= 11 > 10. So a must be bad. So answer 0.
- Else (n <= 11): For each point a (index i from 1..n):
- For each j != i, compute vector v_j = point_j - point_i.
- Let list L = these vectors (non-zero).
- Check if there exist two distinct vectors u, v in L such that dot(u,v) > 0.
- If not, then i is good.
Collect good indices.
- Output count and indices.
Complexity O(n^3) but n<=11 so fine.
But we need to be careful about integer coordinates. Dot product can be up to? Coordinates up to 1000, differences up to 2000, squared sum up to 5*2000^2=20e6, dot product up to similar magnitude. Use 64-bit ints.
Now, is the bound indeed 2*d? Let's double-check for d=5: Could there be 11 vectors with pairwise non-positive dot? I recall a known result: In R^d, the maximum number of vectors with pairwise obtuse (strictly >90) is d+1? Actually, think about the regular simplex: In R^d, you can have d+1 vectors (from center to vertices of a regular simplex) with mutual angle arccos(-1/d). For d=5, that's arccos(-0.2) ~ 101.5°, which is > 90°. So those vectors have dot product = -|v_i||v_j|/d? Actually if they are from center to vertices, the vectors are not all pairwise obtuse? Wait: For a regular simplex in R^d, the vectors from the centroid to the vertices have equal pairwise angles, and the cosine is -1/d. For d>=2, -1/d is > -1 and <0. So they are all obtuse (<180, >90). So d+1 vectors (e.g., 6 in 5D) can be pairwise obtuse. So maximum size might be more than 2d? Let's test: In 2D, d=2, d+1=3, but we found 4 vectors with pairwise dot <=0 (the cross). So 3 is not maximum. In 3D, d+1=4, but we have 6. So d+1 is not maximum. There is also the concept of "spherical code with minimal angular separation 90°". The maximum size of a set of points on the unit sphere such that the inner product <= 0 (i.e., angle >= 90°) is known as the "orthant" or "max size of an obtuse set". I recall that the maximum is 2d, and it's achieved by the vertices of the cross polytope. And it's known that you cannot have more than 2d. I can try to prove: Suppose we have m vectors v_i in R^d with v_i·v_j <= 0 for i != j. Then consider the matrix A (d x m). Then the Gram matrix G = A^T A has non-positive off-diagonals. Now, define w_i = v_i / ||v_i||, unit vectors. Then w_i·w_j <= 0. We can consider these as points on the sphere. Now, consider the conic combination: If we take any linear combination with nonnegative coefficients, the squared length is >= sum coefficient_i^2 (since each ||w_i||=1) + 2 sum_{i<j} coeff_i coeff_j (w_i·w_j) <= sum coeff_i^2? Actually w_i·w_j <=0, so sum_{i<j} term is non-positive, thus squared length <= sum coeff_i^2. Not sure.
Alternatively, there's a known result: In R^d, the maximum number of pairwise non-acute vectors is at most 2d. This appears in some combinatorial geometry problems. I've seen it used in Codeforces problem "Points on the Plane"? Actually there is CF problem 1046C? Not sure.
I can attempt to prove: Suppose we have vectors v_1,...,v_m such that for i != j, v_i·v_j <= 0. Then they are all linearly independent? Not necessarily: Example: In 2D, (1,0), (0,1), (-1,0), (0,-1) are not all linearly independent? Actually they span R^2, but there are 4 vectors, linearly dependent. So no.
Another approach: Consider the convex cone generated by the vectors. If they are all in a half-space? Actually if v_i·v_j <=0, it might be possible that they are "pointing" in different orthants. There is a known lemma: The maximum number of vectors with pairwise non-positive dot products in R^d is at most 2d. It's sometimes attributed to "Sylvester's theorem" or "Fisher's inequality"? No.
Let's try to see if 11 vectors in R^5 could exist. Suppose we have 11 unit vectors with pairwise dot <=0. Then consider their sum (or a certain linear combination). If we take the sum of all vectors, its squared length = sum_i ||v_i||^2 + 2 sum_{i<j} v_i·v_j <= 11 + 0 = 11. So length <= sqrt(11). Not helpful.
We can try a dimension argument: Represent each vector v_i as a point on the sphere. For each vector, consider the hemisphere defined by the hyperplane orthogonal to it? Possibly use Radon's theorem? Not.
I recall a known bound: The maximum cardinality of a set of points on the unit sphere with pairwise inner product at most 0 is 2d. This is a special case of the "Rankin bound" for spherical codes with minimal angle 90°. The Rankin bound for spherical codes: For maximal size A(n, φ) for angle φ, there are bounds. For φ = 90°, the maximum is 2n (for n dimensions). In fact, it's known that the maximum number of points on a sphere with minimal angular separation at least 90° is at most 2n, and this is achieved by the cross polytope. Indeed, this is standard in coding theory: The maximum size of a spherical code with minimum angle at least 90° is 2n. For angle > 90°, it is at most n+1 (for >90°, the simplex). So for >= 90°, it's at most 2n. Since we require angle <= 90°? Actually we require angle >= 90° (non-acute). So that's exactly the bound. So for 5D, max size is 10.
Thus n-1 > 10 => impossible to have all pairwise non-acute. So a is bad. So for n >=12, answer 0.
But what about n=11? Then n-1=10, which is exactly the bound. So it's possible that a point could be good if its 10 vectors are arranged as the cross polytope directions. But not necessarily; many configurations will be bad. So we need to check.
So the solution: if n <= 11, do brute-force check; else output 0.
But wait: Could there be a case where n=12 but still a point is good because some vectors are zero? But vectors cannot be zero because points distinct. So no.
Thus algorithm is simple.
But we need to be careful about the angle definition: It says "angle between vectors ab and ac is acute (i.e. strictly less than 90°)". So condition for bad is: exists b != c, b != a, c != a such that (b-a)·(c-a) > 0. (Strictly > 0). If dot = 0 (right angle), it's not acute, so doesn't make bad. So condition for good: For all distinct b, c, (b-a)·(c-a) <= 0.
Now, for n=0? Not possible.
Edge case: n=1, output 1 and 1. For n=2, both good: output 2, then 1 and 2.
Implementation details: Points can be up to 1000 coordinate values, differences up to 2000. Dot product can be up to about 5 * 2000 * 2000 = 20e6? Actually each coordinate difference up to 2000, so product up to 4e6 per dimension, sum 5 gives 20e6. So within 32-bit signed? 20e6 fits, but sum of many might not exceed 2^31? But we can use 64-bit to be safe.
Now, testing sample 1:
n=6.
points: 0,0,0,0,0; (1,0,0,0,0); (0,1,0,0,0); (0,0,1,0,0); (0,0,0,1,0); (0,0,0,0,1)
For point 1 (origin): vectors are the other points: (1,0,0,0,0), (0,1,0,0,0), (0,0,1,0,0), (0,0,0,1,0), (0,0,0,0,1). Dot between any two distinct vectors = 0. So none >0 => good.
For point 2 (1,0,0,0,0): vectors: to origin: (-1,0,0,0,0) = - (1,0,0,0,0); to (0,1,0,0,0): (-1,1,0,0,0); to (0,0,1,0,0): (-1,0,1,0,0); to (0,0,0,1,0): (-1,0,0,1,0); to (0,0,0,0,1): (-1,0,0,0,1). Now compute dot between some pair: e.g., (-1,0,0,0,0) and (-1,1,0,0,0): dot = 1 + 0 =1 >0 => acute, so point 2 is bad. Similarly others. So only point 1 good.
Matches.
Sample 2: n=3 points given. Check all points? Let's test manually: Points: A=(0,0,1,2,0), B=(0,0,9,2,0), C=(0,0,5,9,0). Compute vectors for A: to B = (0,0,8,0,0), to C = (0,0,4,7,0). Dot = 00+00+84+07+00 = 32 >0 => acute => A bad. For B: to A = (0,0,-8,0,0), to C = (0,0,-4,7,0). Dot = 0+0+(-8)(-4)+0*7+0 = 32 >0 => B bad. For C: to A = (0,0,-4,-7,0), to B = (0,0,4,-7,0). Dot = 0+0+(-4)4 + (-7)(-7)+0 = -16 + 49 = 33 >0 => C bad. So all bad => output 0. Good.
Now, check n=2 scenario: both good. So algorithm should output 2\n1\n2.
Now, regarding the bound of 2d=10: Are there any exotic configurations where more than 10 vectors can all have pairwise dot <=0? Let's try to conceive in 5D. Could we have 11 vectors? Suppose we take the 10 cross polytope vectors: e1, -e1, e2, -e2, e3, -e3, e4, -e4, e5, -e5 (unit basis). Pairwise dot: if they are opposite (e1 and -e1) dot = -1; if they are different axes, dot=0. So works. Now add an 11th vector, say (1,1,0,0,0). Its dot with e1 = 1 >0 => acute. So fails. But maybe there is some clever set not containing opposites but still >10? There is a known bound: In R^d, the maximum number of vectors with pairwise non-positive dot product is at most 2d. I'm convinced.
Therefore, we can implement as described.
But wait: What about the case n=11? Then m=10. It's possible that point a is good if its 10 vectors are like cross polytope directions (or any set of 10 vectors with pairwise dot <=0). So we need to check.
But is it also possible that for n=11, but some points may have m=10, but they could still be good even if vectors are not exactly cross polytope; the condition is pairwise dot <=0. So we can check by brute-force.
Thus overall algorithm.
Now, we need to print indices in ascending order.
Edge cases: n=0? Not possible.
Now, let's ensure we correctly interpret "different points b and c, not equal to a". This means b and c are two distinct points, both different from a. So if there is only one other point, condition can't be satisfied.
Implementation plan:
- Read n.
- Initialize list of points: each point as tuple/list of 5 ints.
- If n > 11: just output 0 and exit? But wait: The problem expects to output k and then indices, even if k=0. So we output 0 and maybe nothing else? In sample 2 output: "0" with no extra lines? Actually sample output:
Output
0
So just a single line with 0. So we output "0". So if n > 11, we print 0.
- Else n <= 11:
good_indices = []
For i in range(n):
vectors = []
for j in range(n):
if j==i: continue
compute diff = [p[j][k] - p[i][k] for k in range(5)]
vectors.append(diff)
# Now check pairwise dot products > 0
m = len(vectors)
good_flag = True
for u in range(m):
for v in range(u+1, m):
dot = 0
for d in range(5):
dot += vectors[u][d] * vectors[v][d]
if dot > 0:
good_flag = False
break
if not good_flag: break
if good_flag:
good_indices.append(i+1) # indices start at 1
Print len(good_indices)
For idx in good_indices: print(idx)
We need to ensure we consider the possibility that m=0 or 1. For m=0 or 1, the nested loops don't execute, so good_flag stays True, so good. That's correct.
Complexity O(n^3) but n<=11 so fine.
Now, final check: The condition for a point to be good is that for all pairs (b,c) distinct and !=a, dot <=0. That's what we check.
But is there any nuance about using integer arithmetic? Dot product >0 is integer, so safe.
Now, confirm bound: Could there be a case where n=12 but some point has exactly 11 vectors but maybe some of them are zero? No.
Thus solution stands.
But before finalizing, let's double-check the bound in literature: I want to be certain. Search memory: In Euclidean space R^d, what is the maximum number of vectors with pairwise non-positive inner product? It is indeed at most 2d. This is sometimes called the "Sylvester's theorem"? Actually Sylvester's theorem deals with sets of points on a line? Not.
Consider the Gram matrix G = A^T A. G is m x m, with non-positive off-diagonals. Now, consider the matrix B = I + D, where D? Hmm. Another known fact: The rank of such a matrix is at least m/2? Actually there is result: For a set of vectors with pairwise non-positive dot product, they lie in a cone of angle at most 90°, and the maximum number is 2d. Could be proven by contradiction: If there are m > 2d vectors, then you can choose a subset of size > d such that they are all in some open half-space? Actually consider the function f(x) = sum_i sign(v_i·x)? Not.
A more rigorous proof: For each vector v_i, consider the hyperplane orthogonal to it. The condition v_i·v_j <=0 means that v_j lies in the closed half-space opposite to v_i? Actually if v_i·v_j <=0, then the angle >= 90°, so v_j is not in the same direction as v_i. It could be exactly orthogonal.
Suppose we have m > 2d. Then consider the set of these vectors and their negatives. Actually if we have v_i, then -v_i also satisfies? But we don't have -v_i. However, we can double the set by including both v_i and -v_i? Not helpful.
One standard proof: Map each vector v_i to a point on the unit sphere. For each point, consider the hemisphere centered at it (the set of points with dot >0). The condition v_i·v_j <=0 means that v_j is not in the open hemisphere centered at v_i (since dot >0 would be inside). So each point is not in the hemisphere of any other. This is reminiscent of the "hemisphere problem": maximum number of points on a sphere such that no point lies in the open hemisphere of another. Actually if v_i·v_j <=0, then v_j is not inside the hemisphere defined by v_i (the set where dot>0). So each point is outside the hemisphere of every other point. So we have a set of points on the sphere such that none lies in the hemisphere centered at any other. The maximum size of such a set is 2d. I think this is a known result: The maximum cardinality of a set of points on the unit sphere in R^d with the property that no point is contained in the open hemisphere centered at another is 2d. This is sometimes attributed to "Danzer and Grünbaum" or "Sphere-packing"? Actually there is a known theorem: In R^d, the maximum number of points on the unit sphere such that the angular distance between any two is at least 90° is 2d. Yes.
Thus bound holds.
Hence solution is correct.
But one nuance: The vectors are not normalized, but as noted, dot product sign is scale-invariant. So the condition v_i·v_j <=0 is equivalent to normalized vectors having dot <=0. So the spherical bound applies.
Therefore, final solution: if n > 11: print 0; else brute-force.
But wait: Could there be a scenario where n=12 but point a's vectors include some that are exactly opposite? That's still dot negative. But we need all pairwise <=0. The bound says impossible to have 11 vectors with pairwise <=0. So even with some zero? Actually zero vector can't occur. So no.
Now, note that the bound is 2d. For d=5, 2d=10. So m <= 10 possible. So for n-1 > 10, impossible. So for n >=12, all points are bad. So output 0.
Thus complexity is O(min(n,12)^3) which is fine.
Let's test with n=12 but with coordinates chosen to be exactly the 12 points: origin plus 11 points that are the 10 cross polytope points plus maybe an extra? Actually to have n=12, we could have points such that from a particular point, the vectors to the other 11 are all pairwise non-acute? The bound says impossible. So at least one point will have acute pair? Actually the condition for a point being good is that all its outgoing vectors are pairwise non-acute. For n=12, from any point, there are 11 outgoing vectors. The bound says you can't have 11 vectors pairwise non-acute in 5D. So all points are bad. So output 0.
Now, confirm that there is no special case where some vectors are collinear or something that might violate the bound? The bound holds for any set of vectors (non-zero). So fine.
Thus solution is simple.
But wait: There is a nuance: The definition of bad requires existence of b and c (distinct) such that angle is acute. If there is only one other point, it's automatically good. That's consistent with m=1 <= 10, so check.
Now, about output format: "print k integers, each on their own line". Actually example: they printed 1 then on next line 1. So for 0, just print 0.
Thus implementation straightforward.
Now, we need to ensure we use 64-bit int for dot product: up to 5*(2000*2000)=20 million, fits in 32-bit int, but safe anyway.
Edge case: n=0? Not.
Double-check: Could there be any scenario where n=11 but one point is good? Possibly yes. For instance, take a point at origin, and 10 other points at coordinates (1,0,0,0,0), (-1,0,0,0,0), (0,1,0,0,0), (0,-1,0,0,0), (0,0,1,0,0), (0,0,-1,0,0), (0,0,0,1,0), (0,0,0,-1,0), (0,0,0,0,1), (0,0,0,0,-1). That's 10 points. n=11 (origin plus those 10). For origin, all pairwise dot =0 or -1? Actually between (1,0,0,0,0) and (-1,0,0,0,0): dot = -1 <0; between (1,0,0,0,0) and (0,1,0,0,0): dot=0; etc. So origin good. So answer would include index of origin. For other points? For point (1,0,0,0,0), vectors to others: includes origin (-1,0,0,0,0) dot with others? Need check. For (1,0,0,0,0), vector to origin is (-1,0,0,0,0). Vector to (0,1,0,0,0) is (-1,1,0,0,0). Dot = 1>0? Compute: (-1)*(-1)? Wait: Actually vector to (0,1,0,0,0) = (-1,1,0,0,0). Dot with vector to origin = (-1,0,0,0,0) dot (-1,1,0,0,0) = (1+0)=1 >0 => acute, so that point is bad. So only origin good. So in that set, k=1.
Thus algorithm would detect.
Now, check n=11 with some configuration where more than one point is good? Possibly if we take all points as vertices of a cross polytope? That is, each point is one of the basis vectors or negatives, but no origin. Then for each point, the vectors to others will include both some orthogonal and some opposite. For a basis vector e1, we have -e1, e2, -e2, ... . The vector from e1 to e2 is e2-e1. From e1 to -e1 is -2e1. Dot (e2-e1)·(-2e1) = ( -2 * (e2·e1?) Actually e2·e1=0, so (e2-e1)·(-2e1) = ( - (e1)·(-2e1) )? Let's compute: (e2 - e1) dot (-2e1) = e2·(-2e1) + (-e1)·(-2e1) = 0 + 2(e1·e1) = 2 >0. So acute. So bad. So only if there is a central point perhaps good. So not many.
Thus algorithm fine.
Now, ensure we treat "different points b and c" meaning b and c are different from each other and both not a. So if n=2, there are no such pairs. So good.
Now, consider n=3, we need to check all pairs. Done.
Now, about output: print k then each index on separate lines. So we can do:
print(len(good))
if good: for idx in good: print(idx)
But even if len=0, just print 0.
Now, implement in Python.
But careful: Input reading: first line n, then n lines each with 5 ints.
Now, we need to handle the case n>11: output 0. But what if n=12 but some points have less than 11 vectors? Actually from any point, the number of other points is n-1 = 11 >10. So all points have >10 vectors. So all bad. So output 0.
Thus we can just early exit.
One more nuance: The bound of 2d might be for unit vectors, but we have non-zero vectors. However, sign of dot product is scale-invariant. So if we have m vectors, we can normalize them to unit length without affecting sign. So the bound applies.
But what about the case where vectors are exactly opposite? That's dot negative. So fine.
Thus algorithm stands.
Now, I'll write the solution in Python.
But wait, let's double-check with n=0? Not.
Now, we should also consider if any vector is zero? Points distinct ensures not.
Now, code:
def is_good(pidx, points):
n = len(points)
a = points[pidx]
vectors = []
for j in range(n):
if j == pidx: continue
v = [points[j][k] - a[k] for k in range(5)]
vectors.append(v)
m = len(vectors)
for i in range(m):
for j in range(i+1, m):
dot = 0
for k in range(5):
dot += vectors[i][k] * vectors[j][k]
if dot > 0:
return False
return True
def main():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it))
points = []
for _ in range(n):
coords = [int(next(it)) for __ in range(5)]
points.append(coords)
if n > 11:
print(0)
return
good = []
for i in range(n):
if is_good(i, points):
good.append(i+1)
print(len(good))
for idx in good:
print(idx)
if name == "main":
main()
That should work.
But let's test quickly with given samples.
Sample 1: n=6 <=11, compute good: only index 1 -> prints 1 then 1. Sample 2: n=3 -> prints 0.
Now, test n=2: Input: 2\n0 0 0 0 0\n1 0 0 0 0 -> output: 2\n1\n2. That seems correct.
Now, test n=12: say 12 points all zero? But points must be distinct, can't all zero. But whatever, output 0.
Thus solution seems correct.
Now, consider potential pitfalls: The bound of 2d=10 is used; but what about d=5, but coordinates are integers? That doesn't matter. So fine.
But is it possible that for n=11, some point might be good even though it has 10 vectors, but the bound says it's possible; we check.
But we need to be absolutely sure about the bound: Is it exactly 2d? I want to prove quickly: Suppose we have m vectors v_i in R^d with v_i·v_j <= 0 for i != j. Consider the following: For each i, let u_i = v_i / ||v_i||. Then u_i·u_j <= 0 for i != j. Now, consider the matrix M whose rows are u_i? Actually we can consider the linear map x -> sum_i x_i u_i. There is known result: The set of vectors {u_i} is such that they are linearly independent in a certain sense. Actually, we can prove m <= 2d by considering that the convex cone generated by them cannot contain a line? Another approach: For each i, define the closed hemisphere H_i = { x ∈ S^{d-1} : x·u_i ≥ 0 }. Condition u_i·u_j <= 0 implies u_j ∉ interior(H_i) for i != j? Actually if u_i·u_j > 0, then u_j is inside H_i; but we have <=0, so u_j is on the boundary or outside. So each H_i contains only u_i (and perhaps others on the boundary). The sets H_i are hemispherical caps. It's known that at most 2d hemispheres can be placed without overlapping? Actually, there is a result: In R^d, one can have at most 2d points on the sphere such that the distance between any two is at least 90°, which is exactly the spherical code with angle 90°. The Rankin bound states: For a spherical code with minimal angle θ, if θ > 90°, then maximum size is d+1; if θ = 90°, maximum size is 2d. Yes, that's the known bound. So for angle >= 90°, maximum is 2d. Since we require <= 90°, it's exactly the same. So we can cite that.
Thus safe.
But we need to consider that our vectors might not be unit length, but we can normalize.
Therefore, final answer.
Now, about time: O(n^3) worst-case when n=11 => 1331*? Actually 11 points: for each point 10 vectors, check 45 pairs -> 11455=2475 operations, trivial.
Thus solution passes.
Now, note: The problem statement includes images, but we ignore.
Now, I'll produce final answer.
But wait: There might be another nuance: The angle defined uses the scalar product formula; they said "angle between vectors (b - a) and (c - a) is acute (i.e. strictly less than π/2)". So condition dot > 0. So we used that.
Now, we must ensure we treat "strictly less" accordingly.
Now, confirm that if dot = 0, it's not acute, so doesn't cause bad.
Now, are there any floating point issues? None, using integers.
Thus final solution.
Now, produce final explanation.
Now, think about any potential trap: The bound of 2d is for sets of vectors from the same point? Actually the vectors are from a fixed origin (point a). That's exactly the spherical code centered at a. So it's exactly the bound. So no.
Now, we must consider that n could be 0? Not.
Thus answer final.
But I recall that there is a Codeforces problem "Points in 5-dimensional space" (maybe CF 214A?). I think the solution is exactly that: if n > 11 output 0 else brute.
Thus final solution.
Now, I'll write final message. ```python
import sys
def is_good(point_idx, points):
"""Return True if point with index point_idx is good."""
a = points[point_idx]
vectors = []
for j in range(len(points)):
if j == point_idx:
continue
# compute vector from a to points[j]
v = [points[j][k] - a[k] for k in range(5)]
vectors.append(v)
m = len(vectors)
# check all pairs for a positive dot product
for i in range(m):
vi = vectors[i]
for j in range(i + 1, m):
vj = vectors[j]
dot = 0
for k in range(5):
dot += vi[k] * vj[k]
if dot > 0: # acute angle found
return False
return True
def main():
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it))
points = []
for _ in range(n):
coords = [int(next(it)) for _ in range(5)]
points.append(coords)
# In 5‑dimensional space, at most 10 vectors can have pairwise
# non‑acute angles. Therefore, if n > 11, every point has >10 neighbours
# and must be bad.
if n > 11:
print(0)
return
good_indices = []
for i in range(n):
if is_good(i, points):
good_indices.append(i + 1) # convert to 1‑based
print(len(good_indices))
for idx in good_indices:
print(idx)
if name == "main":
main()