Given a finite binary string $S$ of symbols $X,O$ we define $\Delta(S)=n(X)-n(O)$ where $n(X),n(O)$ respectively denote number of $X$'s and $O$'s in a string. For example $\Delta(XOOXOOX)=3-4=-1$. We call a string $S$ $\emph{balanced}$ if every substring $T$ of $S$ has $-2\le \Delta(T)\le 2$. Find number of balanced strings of length $n$.
To solve the problem of finding the number of balanced strings of length \( n \), we need to understand the constraints and properties of balanced strings. A string \( S \) is balanced if every substring \( T \) of \( S \) satisfies \( -2 \leq \Delta(T) \leq 2 \), where \(\Delta(T) = n(X) - n(O)\).

1. **Define the Problem in Terms of Automata:**
   We can model the problem using a finite automaton. The states of the automaton will represent the possible values of \(\Delta(T)\) for any substring \( T \) of \( S \). Since \(\Delta(T)\) must be between -2 and 2, we have 5 possible states: \(-2, -1, 0, 1, 2\).

2. **Transition Between States:**
   Each symbol \( X \) or \( O \) in the string will cause a transition between these states:
   - Reading an \( X \) increases \(\Delta(T)\) by 1.
   - Reading an \( O \) decreases \(\Delta(T)\) by 1.

3. **Construct the Transition Matrix:**
   We can represent the transitions using a matrix \( A \), where \( A[i][j] \) represents the number of ways to transition from state \( i \) to state \( j \):
   \[
   A = \begin{pmatrix}
   0 & 1 & 0 & 0 & 0 \\
   1 & 0 & 1 & 0 & 0 \\
   0 & 1 & 0 & 1 & 0 \\
   0 & 0 & 1 & 0 & 1 \\
   0 & 0 & 0 & 1 & 0
   \end{pmatrix}
   \]
   Here, the rows and columns correspond to the states \(-2, -1, 0, 1, 2\) respectively.

4. **Initial State and Final State:**
   The initial state is \( \Delta = 0 \) (the string starts with no symbols). The final state must also be \( \Delta = 0 \) for the entire string to be balanced.

5. **Counting Paths of Length \( n \):**
   To find the number of balanced strings of length \( n \), we need to count the number of paths of length \( n \) in the automaton that start and end at state 0. This can be done using matrix exponentiation:
   \[
   A^n = \text{number of paths of length } n \text{ between states}
   \]
   The entry \( A^n[3][3] \) (since state 0 is the 3rd row/column in our matrix) will give us the number of balanced strings of length \( n \).

6. **Matrix Exponentiation:**
   Compute \( A^n \) using matrix exponentiation techniques. This involves repeated squaring to efficiently compute the power of the matrix.

7. **Extract the Result:**
   The number of balanced strings of length \( n \) is given by the entry \( A^n[3][3] \).

The final answer is \( \boxed{ A^n[3][3] } \).