Problem

Source: From the Indian Team Selection Tests 2007

Tags: geometry, rectangle, combinatorics unsolved, combinatorics



Given a finite string $S$ of symbols $X$ and $O$, we write $@(S)$ for the number of $X$'s in $S$ minus the number of $O$'s. (For example, $@(XOOXOOX) =-1$.) We call a string $S$ balanced if every substring $T$ of (consecutive symbols) $S$ has the property $-2 \leq @(T) \leq 2$. (Thus $XOOXOOX$ is not balanced since it contains the sub-string $OOXOO$ whose $@$-value is $-3$.) Find, with proof, the number of balanced strings of length $n$.