$$
\begin{array}{l}
\text { II. (40 points) Given } x_{i} \in\{\sqrt{2}-1, \sqrt{2}+1\} \\
(i=1,2, \cdots, 2013) \text {, let } \\
S=x_{1} x_{2}+x_{2} x_{3}+\cdots+x_{2012} x_{2013} .
\end{array}
$$

Find the number of different integer values that $S$ can take.
Because $(\sqrt{2}-1)^{2}=3-2 \sqrt{2}$,
$$
(\sqrt{2}+1)^{2}=3+2 \sqrt{2}, (\sqrt{2}-1)(\sqrt{2}+1)=1,
$$

Therefore, $x_{i} x_{i+1} \in\{3-2 \sqrt{2}, 3+2 \sqrt{2}, 1\}$.
Let the sum $S$ contain $a$ instances of $3+2 \sqrt{2}$, $b$ instances of $3-2 \sqrt{2}$, and $c$ instances of 1. Then $a, b, c \in \mathbf{N}$, and $a+b+c=2012$.
$$
\begin{array}{l}
\text { Hence } S=\sum_{i=1}^{2012} x_{i} x_{i+1} \\
=(3+2 \sqrt{2}) a+(3-2 \sqrt{2}) b+c \\
=3 a+3 b+c+2 \sqrt{2}(a-b).
\end{array}
$$

If $S$ is an integer, then $a=b$. At this time,
$$
\begin{aligned}
S= & a \\
& +c=6 a+(2012-2 a) \\
& =4 a+2012=4(a+503)(0 \leqslant a \leqslant 1006).
\end{aligned}
$$
(1) When $a=b=1006$, $\left\{x_{i}\right\}$ contains at least 1007 instances of $\sqrt{2}-1$ and 1007 instances of $\sqrt{2}+1$, i.e., at least 2014 numbers, which is a contradiction.

When $a=b=1005$, $\left\{x_{i}\right\}$ contains at least 1006 instances of $\sqrt{2}-1$ and 1006 instances of $\sqrt{2}+1$.
(i) $\left\{x_{i}\right\}$ contains 1006 instances of $\sqrt{2}-1$ and 1007 instances of $\sqrt{2}+1$.
Since $S$ contains 1005 instances of $(\sqrt{2}-1)^{2}$, these 1006 instances of $\sqrt{2}-1$ are consecutive in $\left\{x_{i}\right\}$, i.e.,
$$
\begin{array}{l}
x_{i}=\sqrt{2}+1(i=1,2, \cdots, k), \\
x_{k+i}=\sqrt{2}-1(i=1,2, \cdots, 1006), \\
x_{k+1006+i}=\sqrt{2}+1(i=1,2, \cdots, 1007-k),
\end{array}
$$

where $k \in\{1,2, \cdots, 1006\}$.
$$
\begin{array}{l} 
\text { Hence } \sum_{i=1}^{2012} x_{i} x_{i+1} \\
=(k-1)(\sqrt{2}+1)^{2}+1005(\sqrt{2}-1)^{2}+ \\
(1006-k)(\sqrt{2}+1)^{2}+2 \\
= 6032.
\end{array}
$$
(ii) $\left\{x_{i}\right\}$ contains 1007 instances of $\sqrt{2}-1$ and 1006 instances of $\sqrt{2}+1$.

Similarly,
$$
\begin{array}{l}
x_{i}=\sqrt{2}-1(i=1,2, \cdots, k), \\
x_{k+i}=\sqrt{2}+1(i=1,2, \cdots, 1006), \\
x_{k+1006+i}=\sqrt{2}-1(i=1,2, \cdots, 1007-k),
\end{array}
$$

where $k \in\{1,2, \cdots, 1006\}$.
Combining (i) and (ii), there are 2012 sequences $\left(x_{1}, x_{2}, \cdots, x_{2013}\right)$ that make $S$ reach the maximum value of 6032.
(2) Prove by mathematical induction: When
$$
a=b=t(t=1005,1004, \cdots, 1)
$$

there exists $\left\{x_{i}\right\}$ such that $S=4(a+503)$.
When $a=b=1005$, it has been proven in (1).
Assume that when $a=b=t(1<t \leqslant 1005)$, there exists $\left\{x_{i}\right\}$ such that $S=4(a+503)$.

Consider a segment of consecutive $\sqrt{2}+1$ (or $\sqrt{2}-1$) as a segment. Take one from each segment of $\sqrt{2}+1$ and $\sqrt{2}-1$ with a length greater than 1, and place them at the end of the sequence (if the original end is $\sqrt{2}-1$, place the taken $\sqrt{2}-1$ at the very end; if the original end is $\sqrt{2}+1$, place the taken $\sqrt{2}+1$ at the very end).
Thus, $a$ and $b$ each decrease by 1, and $c$ increases by 2. At this time, $S=4[(t-1)+503]$.
Therefore, when $a=b=t-1$, the conclusion holds.
In summary, the number of different integer values that $S$ can take is 1005.