We need to compute the total number of triangles that can be formed using points placed on the sides of a square. The problem: There is a square. On each side of the square, there are n points placed (excluding the corners). So total points = 4n. None coincide with corners. We need total number of triangles formed using these points as vertices. That is, choose any 3 distinct points among the 4n points, and if they are not collinear, they form a triangle. However, points lie on the sides of a square; some sets of three points may be collinear if they lie on the same side. So triangles that are degenerate (collinear points) should be excluded. So total triangles = C(4n, 3) - (number of collinear triples).
Since points are placed on the sides, collinearity can occur only if all three points are from the same side (because any two points on different sides are not collinear unless they are on the same line, but sides are distinct lines; the only lines are the four sides. So collinear triples are exactly triples of points that all lie on the same side. There is no other collinearity because three points from two sides might be collinear if they lie on a diagonal? But points are on the sides only, so three points from e.g., two adjacent sides cannot be collinear because they'd lie on two different lines. However, it might be possible that three points, each from a different side, could be collinear? In a square, lines passing through points on different sides - would that be possible? Possibly if the three points are on the extensions? But the square's sides are four line segments; points lie on the segments, but three points from three different sides cannot be collinear because any line can intersect a convex polygon in at most two points (unless it goes along an edge). Actually, a line could intersect a square at two points (or along a side). Since the points are on the boundary, it's possible that a line passes through two points on opposite sides (like a line through left and right sides) and also through a point on the top side? That would be three collinear points on the square boundary? Let's examine: Square with vertices (0,0), (1,0), (1,1), (0,1). Points on the edges. Consider the line y = x. It passes through (0,0) and (1,1) which are corners (not included), and also through the interior, but does it intersect other edges? At x=0, y=0 (corner); at x=1, y=1 (corner). So it only hits corners. There's no other boundary point on that line. For a line that passes through a point on the top side (y=1, x between 0 and 1) and a point on the right side (x=1, y between 0 and 1) - line connecting them: slope (1 - y)/(x-1) etc. This line will intersect the square at exactly those two points (plus possibly corners if extended). Could it also intersect another side at a distinct point? Typically, a line intersecting a convex polygon can intersect at at most two points unless it coincides with an edge. So three points on the boundary being collinear would require them all lie on the same edge, because otherwise they'd be on two different edges, but a line can intersect the boundary at at most two points (the polygon is convex). However, if the line passes through a corner, it could intersect at two edges meeting at that corner, but the points are not at corners. So indeed, the only sets of three points on the boundary that are collinear are those that lie on the same side. So collinear triples = sum over each side of C(n, 3). Since there are 4 sides, each with n points, total collinear triples = 4 * C(n, 3).
But wait: Could three points on two adjacent sides be collinear if they are on the line that goes through the corner? For example, take a point on the left side very close to the top-left corner, and a point on the top side very close to the same corner. The line through them would essentially be almost the diagonal through that corner, but the corner itself is not a point among the set, but the line would pass through the corner (which is not a point) and then through those two points. Could it also pass through a third point on some side? Possibly if we pick a point on the right side that lies exactly on the extension of that line? The line from left side near top-left to top side near top-left is almost a line that goes from that corner into the interior; it might intersect the opposite side? Actually, consider left side: x=0, y in (0,1). Top side: y=1, x in (0,1). Take point A = (0, a) with a<1, point B = (b,1) with b>0. The line AB passes through these points. It will intersect the square boundary at possibly two points: entry and exit. It enters at A (on left edge) and exits at B (top edge). There's no third intersection with the boundary. So no third point on the square boundary lies on that line except possibly at corners if extended. So indeed, any line that passes through two points on two different sides will intersect the square's boundary at exactly those two points (unless it goes through a corner). So no collinearity across sides. So the only collinear triples are from the same side. So total triangles = C(4n,3) - 4*C(n,3).
But the problem says: "You are given a square with 'n' points on each side of the square. None of these points co-incide with the corners of this square. You have to compute the total number of triangles that can be formed using these '4n' points (n points on each side of the square) as vertices of the triangle." Example: Input: 1, n=1 -> output 4. Let's test: n=1, total points = 4. C(4,3)=4. Collinear triples: each side has 1 point, C(1,3)=0, so total triangles =4. That matches example. So formula works.
But is that all? Could there be triangles that are degenerate due to three points that are collinear but not on the same side, like if two points are on opposite sides and the third also on one of those sides but exactly on the line connecting them? For three points to be collinear, they must lie on some line. Since they are on the boundary, the line may intersect the square at two points. But could it intersect at three? Suppose we have a line that passes through a corner. The corner is not a point among our set, but could it happen that three points lie on that line? The line through a corner will intersect the square along two edges meeting at that corner, but only at that corner. Points on those edges lying exactly on that line would be collinear with the corner, but if the corner is excluded, then the points on the edges near the corner might be collinear? Actually, consider the line x=0 (left side). Points on left side are collinear; that's already accounted. Similarly y=0, etc. For a line through a corner but not along the sides, it will intersect the square at exactly that corner and at another point on the opposite side? For example, line through top-left corner (0,1) and bottom-right corner (1,0) is y = 1 - x. Points on that line inside the square: It will intersect the boundary at those two corners. It does not pass through any other boundary points because the line enters at (0,1) and exits at (1,0). Any interior point on that line is interior, not on boundary. So there is no third boundary point (excluding corners) on that line. So no collinearity.
What about a line that passes through two points on opposite sides, say left and right sides. That line will intersect the square at those two points only (since left side x=0, right side x=1, the line will intersect top or bottom only if the line is horizontal? But if the line connects (0, a) and (1, b) with a and b in (0,1), the line is not vertical/horizontal. It will cross the interior. The square boundary consists of four edges. The line segment from (0,a) to (1,b) lies entirely inside the square? Actually, if a and b are between 0 and 1, the line segment connecting them might cross the top or bottom if the line extends beyond? The line segment is within the square if its y values between 0 and 1 for all x in [0,1]. Since the line is linear, y = a + (b-a)x. At x=0, y=a in (0,1). At x=1, y=b in (0,1). For the segment to stay inside, we need that for all x in (0,1), y stays within [0,1]. That is true if a and b are in (0,1) and the line doesn't exit through top or bottom earlier. It could exit if the line goes outside the vertical bounds before reaching x=1. For example, a=0.1, b=0.9. The line y = 0.1 + 0.8x, at x=0, y=0.1; at x=1, y=0.9; it's monotonic; stays within 0.1 to 0.9, fine. If a=0.9, b=0.1, then y = 0.9 - 0.8x, decreasing; at x=0.5, y=0.5; still within. So always between 0 and 1 because it's a convex combination of numbers in (0,1). So the line segment lies entirely within the square and only touches the boundary at the two endpoints on the left and right sides. So no other boundary point lies on that line. Similarly for top and bottom.
Thus indeed, collinear triples only occur if all three points are on the same side. So the answer is straightforward: total = C(4n, 3) - 4*C(n, 3).
But we must ensure that n can be up to 100. So maximum points = 400. C(400,3) = 400399398/6 = something about 10.5 million? Actually compute: 400399=159600; 159600398 = 159600400 - 1596002 = 63,840,000 - 319,200 = 63,520,800; divide by 6 = 10,586,800. That's about 10.6 million. So fits in 32-bit int? 10.6 million fits in 32-bit signed (max ~2.147e9). But 4C(n,3) for n=100: C(100,3)=161700? Actually 1009998/6 = 1009702/6? Let's compute: 10099=9900; 990098=970200; /6 = 161700. Times 4 = 646800. So total for n=100: C(400,3) - 646800 = 10,586,800 - 646,800 = 9,940,000? Actually compute: 10,586,800 - 646,800 = 9,940,000. So <10 million. So fits easily in 32-bit int. But multiple test cases T? Not given maximum but likely moderate. So answer is straightforward.
But wait, the problem statement might be from some contest, perhaps they expect careful handling: "n points on each side of the square. None of these points co-incide with the corners of this square." So indeed total points = 4n. Triangles are formed using these points as vertices. So answer = C(4n,3) - 4*C(n,3).
But check small n: n=2. Then total points=8. C(8,3)=56. Collinear: each side has 2 points, C(2,3)=0? Actually C(2,3)=0. So total=56. But is that correct? Let's manually consider: 8 points: top side 2, bottom 2, left 2, right 2. Are there any collinear triples? Three points on same side: need 3 points but only 2 per side -> no. So all 56 triples form triangles? Check: Could there be a triple that is collinear across sides? Possibly if one point on top and two on bottom? The line connecting a top point and a bottom point could be vertical if they are aligned? But top and bottom are horizontal segments. A vertical line could pass through a point on top and bottom only if they share same x-coordinate. But we have points on top side: (x,1) for some x; bottom: (x,0) for some x. If we pick one point on top with x=a, and one point on bottom with x=a, then the line is vertical x=a. Does that line also intersect left or right? It goes through the entire vertical line x=a, which if a is not 0 or 1, will pass through the interior and also intersect the left and right? Actually vertical line x=a with a between 0 and 1 will intersect the top at (a,1) and bottom at (a,0) and that's it; it does not intersect the left or right because those are at x=0 and x=1. So if we also pick a point on left side at (0,b), it will not be on x=a unless a=0, which is excluded (corner). So cannot be collinear. Similarly, if we pick two points on the top side? Only two exist, so no triple. So all triples are non-collinear? But consider three points: two on top side, one on bottom side. Could they be collinear? For three points to be collinear, they must lie on a line. Two points on top (y=1) and one on bottom (y=0). The two top points define a line that is horizontal if they have same y=1? Actually any two distinct points on the top side share y=1, so line is horizontal y=1. The bottom point has y=0, so not on that line. So not collinear. Two points on left (x=0) and one on right (x=1) -> line through two left points is vertical x=0; right point x=1 not on line. So no. Three points on two sides could be collinear if the line through one point on top and one point on bottom passes also through a point on left or right? To test: we need three points A, B, C such that they are collinear. That would imply the line determined by A and B contains C. But as argued earlier, the line through two points on two different sides will intersect the boundary only at those two points (unless it passes through a corner). So C would have to be one of those two points. So not possible. So indeed all 56 triples form non-degenerate triangles. So answer matches.
Now check n=3: total points =12. C(12,3)=220. Collinear triples: each side has 3 points, C(3,3)=1, so total 4 collinear triples. So triangles = 220-4=216. Is that plausible? Possibly yes.
Thus the solution is simple.
But wait, we must consider that the points are placed on each side, but they could be anywhere along the side (except corners). However, they might be placed such that some three points from two sides are collinear? Let's think: Suppose the square's sides are not necessarily at integer coordinates; points are arbitrary. The condition for collinearity of three points A, B, C is that they lie on a common line. For points on two different sides, we need to check if a line can contain two points from two sides and also a third point from a third side. As argued, a line intersecting the boundary of a convex polygon can do so at most two points. Since the square is convex, any line can intersect its boundary at at most two points (unless it coincides with an edge). This is a known property. Therefore, no three distinct boundary points (excluding corners) can be collinear unless they are on the same edge. The only subtlety: If the line is tangent to the square (touching at a corner) then it could intersect at exactly one point (the corner) plus maybe grazes? Actually tangent at a corner would have intersection that is just the corner point? But for a convex polygon, a line can intersect the polygon in a line segment if it is along an edge, or in a single point if it touches at a vertex but not along edges. But if it passes through a vertex, it might intersect the polygon along two edges if the line goes through interior? Actually, consider a line that goes through a corner and also goes inside the square. For a convex polygon, the intersection of a line with the polygon is either empty, a single point, or a line segment. If the line passes through a corner and also through interior, then the intersection is a line segment from that corner to some point on the opposite side? Let's examine: The line enters the polygon at some boundary point and exits at another. If it passes through a corner, it could have the corner as one of the intersection points. But the intersection is still a segment: from entry to exit. The entry point could be a corner, exit another point. But the line could also have the corner as the only intersection if it's tangent? But if it goes through a corner and then stays outside, the intersection might be just that point. But the line still can intersect the polygon at that one point. So the maximum number of distinct points on the boundary that lie on a given line and are part of the polygon (including vertices) can be 2? Actually, could it be more? If the line coincides with an edge, then infinitely many points, but that's an edge. If the line goes through two parallel sides? That's not possible because sides are not parallel? Actually two opposite sides are parallel. A line that is not parallel to them can intersect each at most once. If it is parallel to a side, it could intersect at most that side (if it coincides) or none. But if it's parallel to a side, it might intersect that side in a segment if it coincides exactly. Otherwise it might not intersect at all. So the maximum number of distinct boundary points (excluding coincident points) that can be collinear and also be part of the polygon is at most 2, unless the line contains an entire edge, then infinitely many. Since we only have points on edges, and we are picking distinct points, the scenario where a line contains an entire edge is exactly when we consider points on the same side. So that's covered. So indeed no other collinear triples.
Thus formula is correct.
Now we must output the total number of triangles as integer.
But could there be a twist: The points are on each side, but perhaps they are not necessarily distinct? They are distinct because each side has n points and corners excluded. So fine.
Now we need to implement a solution that reads T and for each n outputs the result.
But wait, check constraints: n ≤ 100. So simple.
But let's also test with n=0? The problem says n points on each side, likely n≥1. But if n=0, total points=0, triangles=0? But not needed.
Now some may ask: "You are given a square with 'n' points on each side of the square. None of these points co-incide with the corners of this square. You have to compute the total number of triangles that can be formed using these '4n' points (n points on each side of the square) as vertices of the triangle." This is a classic combinatorial geometry problem.
But maybe there is a nuance: The points are placed on each side, but the square's sides are lines; the points might be considered vertices of the triangle, and triangles might be degenerate if they are collinear. However, some triangles may have area zero also if three points lie on two sides that are collinear? That doesn't happen as argued.
Another nuance: Could three points be collinear if two are on one side and the third is on the extension of that side but not on the square? But the third is on the square boundary, so it must be on that side to be collinear. So fine.
Thus answer is C(4n,3) - 4*C(n,3). So we need to compute combinations.
Now since n up to 100, we can compute using integer arithmetic: C(N,3) = N*(N-1)*(N-2)/6. For N=4n. So we can compute.
But note: There is also a possibility of triangles formed using the corners? The problem says using these 4n points as vertices. The corners are not included. So we don't consider them. So we are correct.
But maybe the problem originally includes corners? It says "None of these points co-incide with the corners of this square." So corners are not part of the set. So only the points on sides.
Thus final solution:
For each test case:
- Read n.
- total = (4n)(4n-1)(4n-2)//6 - 4( n*(n-1)*(n-2)//6 )
- Print total.
But careful: For n < 3, C(n,3) = 0 because we can't choose 3 if n<3. So in formula, we can compute safely using max(0,...) or just compute product with n-2 which could be negative. So we should compute C(n,3) as 0 if n<3. But n≥1, so for n=1 or 2, C(n,3)=0. In product formula: n*(n-1)(n-2)/6 for n=1 gives 10*(-1)/6 = 0, works if we use integer division? 10(-1) = 0, so 0/6=0; in integer arithmetic, 0/6=0. For n=2: 210=0, fine. So the product formula works as 0 because one factor is zero. So we can safely compute product without special case, as long as we use multiplication that yields 0. But be careful: In Python, it's fine. In C++/Java, integer multiplication with negative might produce negative zero? Actually 210 = 0, fine. For n=1: 10(-1) = -0? Actually 1*0 = 0, 0 * (-1) = 0, so 0. So fine. So formula works for n≥0.
Thus answer is straightforward.
But let me double-check for n=1, formula: total = C(4,3)-4*C(1,3) = 4-0=4. Good.
For n=2: total = C(8,3) = 56. Good.
For n=3: C(12,3)=220, C(3,3)=1, 4*1=4, total=216.
For n=4: 4n=16, C(16,3)=560? Let's compute: 161514/6 = (3360)/6? Actually 1615=240, 24014=3360, /6=560. C(4,3)=4, 4*4=16? Actually C(4,3)=4, times 4 =16. So total = 560-16=544.
Now, are there any other constraints? Possibly the problem expects output for multiple test cases.
Thus implement:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
T = int(data[0])
out = []
for i in range(1, T+1):
n = int(data[i])
total_triangles = (4n)(4n-1)(4n-2)//6 - 4(n*(n-1)*(n-2)//6)
out.append(str(total_triangles))
sys.stdout.write("\n".join(out))
That solves it.
But the user gave a conversation stating "You are given a square...", they want a solution. So I'll provide the reasoning and final code.
I'll also note that the solution is O(T) time.
Given the problem constraints (n ≤ 100), the numbers fit within standard 32-bit integer, but in Python it's arbitrary.
Potential pitfalls: None.
Thus answer.
But I'll also include a note about why collinear triples only from same side.
I'll produce the final response.
```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out_lines = []
for i in range(1, t + 1):
n = int(data[i])
# total combinations of 3 points out of 4n
total_triples = (4 * n) * (4 * n - 1) * (4 * n - 2) // 6
# subtract collinear triples (all on the same side)
collinear = 4 * (n * (n - 1) * (n - 2) // 6)
triangles = total_triples - collinear
out_lines.append(str(triangles))
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()