23. From a rectangle with sides $a$ and $b$, a triangle with legs $a_{1}$ and $b_{1}$ has been cut off. How should the remaining part be trimmed to obtain a rectangle of the largest area with sides parallel to the sides of the original rectangle?
23. Let a triangle with vertex $C$ be cut off from rectangle $ABCD$, resulting in pentagon $ABEFD$. The desired rectangle $AB_1C_1D_1$ should have vertex $C_1$ on line $EF$. The problem is to find the position of vertex $C_1$. Extend sides $AB$ and $AD$ of the rectangle to intersect with the extension of segment $EF$, forming triangle $AMN$. Introduce the following notations: $AM=m, AN=n, B_1C_1=AD_1=x$. From the similarity of triangles $AMN$ and $D_1C_1N$, we have $\frac{C_1D_1}{m}=\frac{n-x}{n}$. Therefore, $C_1D_1=\frac{m}{n}(n-x)$ and $S=\frac{m}{n}(n-x)x$ is the area of the desired rectangle. In this case,

$$
m=a+\frac{a_1}{b_1}\left(b-b_1\right), n=b+\frac{b_1}{a_1}\left(a-a_1\right)
$$

The maximum value of $S$ coincides with the maximum value of the product $(n-x)x$, which we obtain when $x=\frac{n}{2}=\frac{b}{2}+\frac{b_1}{2a_1}\left(a-a_1\right)$.