Number of lists in which an element is repeated consecutively exactly twice I have an integer list that is n long and each value can be ranging from 1 .. n.
I need a formula that tells me how many of all possible lists for a given n, that have one or more consecutive sequences of a length of exactly 2 of the same number and no other consecutive sequences that are longer than 2.
For example for n=5:
These two should count: 
{ 1, 1, 5, 3, 3 }
{ 2, 3, 2, 5, 5 }

Where as these should not:
{ 1, 1, 1, 2, 2 }
{ 1, 3, 2, 5, 4 }

I've been attempting to do this by looking at the possible sequences using the following formula where x = n-1:
(n) x n n = x * n^3
x (n) x n = x^2 * n^2
n x (n) x = x^2 * n^2
n n x (n) = x * n^3

And sum these four up.
However, these also needs to take overlaps between the four into account. This is where I could use a bit of help..? What would the formulas be for excluding the overlaps?
An alternative approach would also be welcome.
Going trough all sequences counting manually is not an option - I need this to work for for n larger than what makes that approach computationally feasible.
If it helps anyone, I've written a little program that runs trough all the sequences and counts have the following results:
n = 2
L[2]: 2
L[1]: 2

n = 3
L[3]: 3
L[2]: 12
L[1]: 12

n = 4
L[4]: 4
L[3]: 24
L[2]: 120
L[1]: 108

n = 5
L[5]: 5
L[4]: 40
L[3]: 280
L[2]: 1520
L[1]: 1280

Where n = 5, L[2]: 1520 is the result I've asked for a formula to in the above question.
 A: How many sequences   of length $q$ of numbers  from $\{1,...,p\}$ are there such that consecutive elements are always different?
For the first element of such a sequence we can selcet one of the $p$ different values of $\{1,...,p\}$. For the following $q-1$ positions we can select 
always all values from $\{1,...,p\}$ except the value of its predecessor in the sequence. These are $p-1$ possible values. So we have
$$ p(p-1)^{q-1}$$
different sequences.
$\Omega_n$ is the number of sequences of length $n$ with elements from $\{1,\ldots,n\}$ 
such that no three consecutive elements have the same value but at least one pair of 
consecutive elements have the same value.
$\Omega_{n,k}$ is the number of sequences of length $n$ with elements from $\{1,\ldots,n\}$ 
such that no three consecutive elements have the same value but exactly $k$ pairs of 
consecutive elements have the same value.
For arbitrary $n$  there are  $k \le \frac{n}{2}$ different possible values for the number  of consecutive element pairs that have equal values. 
We have 
$$|\Omega_{n}|=\sum_{k=1}^{\lfloor \frac{n}{2}\rfloor }|\Omega_{n,k}|$$
Now we select a $k$. Choose a sequence of $n-k$ values from $\{1,\ldots,n\}$ such that two consecutive values always differ. 
There are $n (n-1)^{n-k-1}$ such sequences. For such a sequence we select $k$ of its elements (there are $\binom{n-k}{k}$ such possibilities)
and insert an element with the same value after each selected value. So
$$|\Omega_{n,k}|=\binom{n-k}{k}n(n-1)^{n-k-1}$$
and
$$|\Omega_{n}|=\sum_{k=1}^{\lfloor \frac{n}{2}\rfloor }\binom{n-k}{k}n(n-1)^{n-k-1}$$


*

*For $n=3$ there are  $12$ sequences.

*For $n=4$ there are t $120$ sequences.

*For $n=5$ there are  $1520$ sequences.
The answer to the original question is deleted
