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
that is
$$
f(m)=g(m)+h(0),
$$
$g(m)=f(m)-h(0)$.
In condition (1), let $m=0$, we have
$$
f(n)=g(0)+h(n),
$$

that is
$$
h(n)=f(n)-g(0).
$$

In condition (1), let $m=n=0$, we have
$$
f(0)=g(0)+h(0).
$$

Substituting (1), (2), and (3) into condition (1), we get
$$
f(m+n)=f(m)+f(n)+2mn-f(0).
$$
(The equation with 3 functions in the problem has now been transformed into an equation with only one function.)
In the above equation, let $m=1$, we get
$$
f(n+1)=f(n)+2n+(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(\ldots \ldots \ldots \\
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
$$
\begin{array}{l}
f(n)=f(0)+2 \cdot[1+2+\cdots+(n-1)]+n(f(1)-f(0)), \\
f(n)=n(n-1)+n f(1)-(n-1) f(0).
\end{array}
$$

In equation (1), let $m=1$, we have
$$
g(1)=f(1)-h(0)
$$

In equation (2), let $n=1$, we have
$$
h(1)=f(1)-g(0)
$$

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

Thus,
$$
\begin{array}{l}
h(0)=g(0). \\
h(0)=g(0)=a \quad (a \text{ is a non-negative integer}),
\end{array}
$$

Substituting into (3), we get
and
$$
f(0)=2a,
$$

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

Substituting the above two equations into (4), we get
that is
$$
\begin{array}{l}
f(n)=n(n-1)+n(a+1)-(n-1) \cdot 2a, \\
f(n)=n^2-an+2a.
\end{array}
$$

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

and
$$
h(n)=n^2-an+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=2k$ ($k$ is a non-negative integer), then
$$
g(n)=n^2-2kn+2k=(n-k)^2-k^2+2k,
$$

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

So
$$
g(k) \geqslant 0,
$$

So
$$
k=0,1,2,
$$

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

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

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

That is
$$
g(k) \geqslant 0,
$$
$$
g(k)=-k^2+k+1=-\left(k-\frac{1}{2}\right)^2+\frac{5}{4} \geqslant 0,
$$

So
$$
k=0,1.
$$

Thus
$$
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-an+2a, \\
g(n)=h(n)=n^2-an+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-an+2a, \\
g(n)=h(n)=n^2-an+a,
\end{array}
$$

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