6-138 $S$ is the set of all non-negative integers. Find all functions $f: S \rightarrow S$, $g: S \rightarrow S, h: S \rightarrow S$ that satisfy the following two conditions:
(1) For any $m, n \in S, f(m+n)=g(m)+h(n)+2 m n$.
(2) $g(1)=h(1)=1$.
[Solution] In condition (1), let $n=0$, we have
i.e. $\square$
$$f(m)=g(m)+h(0)$$
$$\begin{array}{r}
g(m)=f(m)-h(0). \\
\text { In condition (1), let } m=0, \text { we have } \\
f(n)=g(0)+h(n),
\end{array}$$

i.e. $\square$
$$\begin{array}{l}
h(n)=f(n)-g(0). \\
\text { In condition (1), let } m=n=0, \text { we have } \\
f(0)=g(0)+h(0). \\
\text { Substituting (1), (2), and (3) into condition (1), we get } \\
f(m+n)=f(m)+f(n)+2 m n-f(0).
\end{array}$$
(The equation containing 3 functions has now been reduced to an equation with only one function).

In the above equation, let $m=1$, we get
$$f(n+1)=f(n)+2 n+(f(1)-f(0)).$$

In the above equation, substitute $n-1, n-2, \cdots, 0$ for $n$ respectively, we get $n$ equations:
$$\begin{array}{l}
f(n)=f(n-1)+2(n-1)+(f(1)-f(0)) \\
f(n-1)=f(n-2)+2(n-2)+(f(1)-f(0)) \\
\cdots \cdots \cdots \cdots \\
f(2)=f(1)+2 \cdot 1+(f(1)-f(0)) \\
f(1)=f(0)+2 \cdot 0+(f(1)-f(0))
\end{array}$$

Adding these $n$ equations, we get

i.e. $\square$
$$\begin{array}{l}
f(n)=n(n-1)+n f(1)-(n-1) f(0). \\
\text { In (1), let } m=1, \text { we have } \\
g(1)=f(1)-h(0). \\
\text { In (2), let } n=1, \text { we have. } \\
\quad h(1)=f(1)-g(0).
\end{array}$$

Using condition (2), the above two equations can be transformed into
$$f(1)=h(0)+1=g(0)+1$$

Thus
$$h(0)=g(0).$$

Let
Substituting into (3) we get
$$h(0)=g(0)=a(a \text { is a non-negative integer }),$$

and we have
$$f(0)=2 a,$$
$$f(1)=h(0)+1=a+1$$

Substituting the above two equations into (4) we get
i.e. $\square$
$$f(n)=n(n-1)+n(a+1)-(n-1) \cdot 2 a,$$
$$f(n)=n^{2}-a n+2 a$$

Substituting the above equation into (1) and (2) respectively, we get
$$g(n)=n^{2}-a n+a$$
$$h(n)=n^{2}-a n+a.$$

Next, we discuss the range of $a$.
Clearly, when $n$ is a non-negative integer, if $g(n)$ is a non-negative integer, then $f(n)$, $g(n)$, and $h(n)$ are all non-negative integers. Therefore, we only need to discuss $g(n)$.

If $a=2 k$ ( $k$ is a non-negative integer), then
$$g(n)=n^{2}-2 k n+2 k=(n-k)^{2}-k^{2}+2 k,$$

Therefore, the minimum value of $g(n)$ is
By the problem $\square$
$$g(k)=-k^{2}+2 k,$$

So $\square$
$$g(k) \geqslant 0$$
( 20
$$k=0,1,2,$$

Thus
$$a=0,2,4.$$

If $a=2 k+1$ ( $k$ is a non-negative integer), then
$$\begin{aligned}
g(n) & =n^{2}-(2 k+1) n+(2 k+1) \\
& =\left(n-\frac{2 k+1}{2}\right)^{2}-\frac{1}{4}(2 k+1)^{2}+(2 k+1)
\end{aligned}$$

Noting that $n$ is a non-negative integer, the minimum value of $g(n)$ is
By the problem $\square$
$$g(k)=g(k+1)=-k^{2}+k+1$$

i.e. $\square$

So
$$g(k) \geqslant 0,$$
$$\begin{array}{l}
g(k)=-k^{2}+k+1=-\left(k-\frac{1}{2}\right)^{2}+\frac{5}{4} \geqslant 0, \\
k=0,1 .
\end{array}$$

Thus $\square$
$$a=1,3.$$

Conversely, when $a \in\{0,1,2,3,4\}$, it can be verified that the functions
$$\begin{array}{l}
f(n)=n^{2}-a n+2 a, \\
g(n)=h(n)=n^{2}-a n+a,
\end{array}$$

satisfy all the conditions of the problem.
Therefore, the complete solution to the problem is
$$\begin{array}{l}
f(n)=n^{2}-a n+2 a, \\
g(n)=h(n)=n^{2}-a n+a,
\end{array}$$

where $a \in\{0,1,2,3,4\}$.