31. Given that $A$ and $B$ are finite sets composed of different positive real numbers, $n$ ($n>1$) is a given positive integer, and both $A$ and $B$ have at least $n$ elements. If the sum of any $n$ different real numbers in $A$ belongs to $B$, and the product of any $n$ different real numbers in $B$ belongs to $A$, find the maximum number of elements in $A$ and $B$.
(52nd Belarusian Mathematical Olympiad (Final B Category))
Assume set $A$ contains $m$ elements, denoted as $a_{1}, a_{2}$, $\cdots, a_{m}$, and satisfies $0n$. Let
$$
\begin{array}{l}
S=a_{1}+a_{2}+\cdots+a_{n+1}, \\
P=\left(S-a_{1}\right)\left(S-a_{2}\right) \cdots\left(S-a_{n+1}\right),
\end{array}
$$

Then $S-a_{k}(k=1,2, \cdots, n+1)$ belongs to $B$. Furthermore, let
$$
\begin{array}{l}
\alpha_{1}=\frac{P}{S-a_{1}}, \alpha_{2}=\frac{P}{S-a_{2}}, \cdots, \alpha_{n+1}=\frac{P}{S-a_{n+1}}, \\
\alpha_{k}=\frac{P\left(S-a_{1}-a_{n+1}+a_{k}\right)}{\left(S-a_{n}\right)\left(S-a_{n+1}\right)}, k=n+2, \cdots, m, \\
\alpha_{m+1}=\frac{P\left(S-a_{1}-a_{n}+a_{m}\right)}{\left(S-a_{n}\right)\left(S-a_{n+1}\right)} .
\end{array}
$$

Then $\alpha_{i}(i=1,2, \cdots, m+1)$ are all the products of $n$ different elements in $B$. Therefore, $\alpha_{i}$ all belong to $A$, and satisfy
$$
\alpha_{1}<\alpha_{2}<\cdots<\alpha_{n+1}<\alpha_{n+2}<\cdots<\alpha_{m}<\alpha_{m+1},
$$

which contradicts the fact that $A$ has $m$ elements. Therefore, $A$ has at most $n$ elements. Thus, it is known that $A$ has $n$ elements.

If $b_{1}, b_{2}, \cdots, b_{n+1} \in B$, and satisfy $0<b_{1}<b_{2}<\cdots$ $<b_{n+1}$. Let $\prod=b_{1} b_{2} \cdots b_{n+1}$, then $\frac{\prod}{b_{k}}(k=1,2, \cdots, n+$ 1) belongs to $A$, and satisfies $0<\frac{\Pi}{b_{n+1}}<\frac{\Pi}{b_{n}}<\cdots<\frac{\Pi}{b_{1}}$, which is a contradiction.
Therefore, both $A$ and $B$ have $n$ elements, and the maximum value sought is $2 n$. Taking $A=\{1,2, \cdots, n\}$,
$$
B=\left\{1,2, \cdots, n-2, \frac{n(n+1)}{2}, \frac{2(n-1)}{(n+1)!}\right\},
$$

it is known that $2 n$ can be achieved.