4. On each of the lines $y=3$ and $y=4$, there are 73 points with abscissas $1,2,3, \ldots, 73$. In how many ways can three points be chosen from the marked 146 so that they form the vertices of a right triangle?
Answer: 10654.

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 the segments of the right triangle, we get that $CH^2 = AH \cdot BH$, i.e., $AH \cdot BH = 1$. Since $AH$ and $BH$ are integers, then $AH = BH = 1$.

The hypotenuse $AB$, equal to 2, can be placed in $71 \cdot 2 = 142$ ways (with $73 - 2$ ways of placement on each of the two given lines), and the position of vertex $C$ is uniquely determined.

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

In total, we get $142 + 10512 = 10654$ ways.