3. On each of the lines $x=2$ and $x=15$, there are 400 points with ordinates $1,2,3, \ldots, 400$. In how many ways can three points be chosen from the 800 marked points so that they form the vertices of a right triangle?
Answer: 320868.

Solution. There are two possibilities.

1) The hypotenuse of the triangle lies on one of the lines, and the vertex of the right angle is on the second line. Let $ABC$ be the given triangle with a right angle at vertex $C$, and $CH$ be its height dropped to the hypotenuse. From the proportionality of segments of a right triangle, we get that $CH^2 = AH \cdot BH$, i.e., $AH \cdot BH = 169$. Since $AH$ and $BH$ are integers, the following cases are possible: $AH = BH = 13$, $AH = 169$ and $BH = 1$, $AH = 1$ and $BH = 169$.

In the first of these cases, the hypotenuse $AB$, equal to 26, can be placed in $374 \cdot 2 = 748$ ways (400 - 26 ways of placement on each of the two given lines), and the position of vertex $C$ is uniquely determined.

In the second and third cases, the length of the hypotenuse is 170, and it can be placed in $2(400 - 170) = 460$ ways. For each position of the hypotenuse, there are two ways to place the vertex - resulting in $2 \cdot 460 = 920$ ways.

2) One of the legs of the triangle (let's call it $BC$) is perpendicular to the given lines, and the second leg ($AC$) lies on one of the given lines. Then the position of the leg $BC$ can be chosen in 400 ways. For each variant of the placement of the leg $BC$, the vertex $A$ can be placed in 798 ways (all points except the already chosen $B$ and $C$ are suitable) - in total, we get $400 \cdot 798 = 319200$ ways.

In total, we get $748 + 920 + 319200 = 320868$ ways.