What is maximum a number of to form right-triangles from in n straight lines I am interested what is maximum a number of to form  right-triangles from in $n=100$ straight lines   
such $n=3$,then maximum number of is $1$,see fig:$\Delta ABC$ is right-triangles.

$n=4$ then the maximum number of is $3$,see following fig,$\Delta ABC,\Delta ABD,\Delta DAC$ are right-triangles.

 A: Hint: Take two lines at right-angles to each other. Any line not parallel to the first two crosses each once to make one right-angled triangle. 
[See comments: think about the situation after four lines are already in place]
Suppose there is a line which makes no right-angle with any other line - if there is a right-angled triangle which doesn't contain that line then the line can be rotated (and translated if necessary to avoid degeneracy) so that it is perpendicular to one of the sides of that right-angled triangle - consider the cases.

Thinking about non-degenerate configurations with lots of right-angled triangles in, each such triangle contains a right-angle. Each right-angle defines a pair of directions. Let there be $r$ such pairs of directions in the configuration.
We partition the lines in the configuration as follows. For the lines making right-angles we have $a_i$ lines parallel to one direction and $b_i$ perpendicular to this $(1\le i \le r)$. We have $c$ lines which are perpendicular to no other line at all.
There are $n$ lines in total, so that $\sum a_i+\sum b_i+c=n$
Now the lines in the pair of directions represented by $i$ make $a_ib_i$ right-angles. Each of the other $n-a_i-b_i$ lines forms a right-angled triangle with each of these $a_ib_i$ vertices. The number of right-angled triangles in the configuration is therefore $$S=\sum _{i=1}^ra_ib_i(n-a_i-b_i)$$
Now it is clear that if $c\gt 1$ we can leave the $c$ lines in general position relative to all the directions $i$ (thus leaving the number of existing right-angled triangles unchanged) but arrange them in two perpendicular directions giving additional vertices for additional right-angled triangles. So we certainly have $c\le 1$.

Now suppose there are two sets of perpendicular lines with $p$ perpendicular to $q$ and $s$ perpendicular to $t$ so that $n=p+q+r+s+t$ and the number of triangles  is $pq(n-p-q)+st(n-s-t)=pqs+pqt+pst+qst=T$ - this is a homogeneous expression. Now suppose we try to increase the number of triangles by increasing $p$ by $1$ and decreasing $q$ by $1$ giving $$(p+1)(q-1)(s+t)+st(p+q)=T+(q-p-1)(s+t)$$ and this is an increase iff $q\gt p+1$. In this case (by homogeneity), whenever two of the numbers differ by two or more, we increase the value of $T$ if we alter them to be closer to each other.
So if we assign the values $0$ or $1$ to $a,b,c$ the best we can do with four directions and $n=4m+a+b+c$ is $$m(m+a)(2m+b+c)+(m+b)(m+c)(2m+a)=4m^3+3(a+b+c)m^2+2(ab+ac+bc)m+abc$$

Let's look at what happens if there are $4m+1$ in two cases.
If we have four directions, the above formula has $a=1, b=c=0$ and gives $4m^3+3m^2$. The spare line makes $m$ right-angle vertices for $2m$ lines to complete, and completes triangles with $m^2$ of the existing vertices.
If we have four directions in two pairs, with $m$ lines in each direction, that gives $4m^3$ triangles and a single line in a different direction adds $2m^2$, which is less than before.
So if we are adding a line to an existing configuration of $n$ lines and we make it parallel to $p$ existing lines and perpendicular to $q$, we add $q$ right-angle vertices for $n-p-q$ lines to complete, and we need a count $r$ of the right-angled vertices formed by other sets. We add $q(n-p-q)+r$ triangles. Certainly we pick the larger of $p$ and $q$.
