3. Let $S=\{1,2, \cdots, n\}, A$ be an arithmetic sequence with at least two terms, a positive common difference, all terms of which are in $S$, and such that when the other elements of $S$ are placed before or after $A$, they cannot form an arithmetic sequence with the same common difference as $A$. Find the number of such $A$ (sequences with only two terms are also considered arithmetic sequences).

---

The translation preserves the original text's formatting and structure.
3. When $n=2 k$, in each sequence $A$ that meets the requirements, there must be two consecutive terms, with the former in $\{1,2, \cdots, k\}$ and the latter in $\{k+1, k+2, \cdots, n\}$. Conversely, by arbitrarily selecting one number from $\{1,2, \cdots, k\}$ and one from $\{k+1, k+2, \cdots, n\}$, and using their difference as the common difference, a sequence $A$ that meets the requirements can be constructed. This correspondence is a one-to-one mapping. Therefore, the number of $A$ is $k^{2}=\frac{n^{2}}{4}$.

When $n=2 k+1$, the situation is completely similar. The only difference is that $\{k+1, k+2, \cdots, n\}$ has $k+1$ elements, so the number of $A$ is $k(k+1)=\left(n^{2}-1\right) / 4$.
The two formulas can be unified as $\left[n^{2} / 4\right]$.