Counting the number of words made of $2n$ letters 
Compute the number of words made of $2n$ letters taken from the alphabet $\{a_1, a_2,\ldots,a_n\}$ such that each letters occurs exactly twice and no two consecutive letters are equal.

I started first of all thinking about the possibilities when we are not restricted by the fact that two consecutive letters are equal. Because we need to choose $2n$, and letters occur exactly twice, so that we can permute each letter pair $2!$ times, we will have something like this: $$\frac{2n!}{(2!)^n} = \frac{2n!}{2^n}$$
Now, I have to somehow exclude the possibilities when two consecutive letters are equal. I was stuck here, then I came across the answer to the problem (which I assume is the same problem), from Putnam and Beyond, page 326 in the PDF, and 309 of the book. I see that he has used inclusion-exclusion principle, but I didn't quite get how the numbers were obtained. Any explanation of that answer, or another solution is highly welcomed.

I'll expand slightly on the answer. 
We assume we have $2n$ letters $L = \{a_1,\ldots,a_n,a'_1,\ldots,a'_n\}$ that we permute in $(2n)!$ ways. Then we consider $a_i$ and $a'_i$ to be the same letter, so that the end result is garantueed to have all letters exactly twice. But then we can exchange every pair $a_i$, $a'_i$ without affecting the end result, so we have to divide by $(2!)^n = 2^n$. So we $\frac{(2n)!}{2^n}$ total permutations. 
So we have to count all permuations that have some pair (or more) of adjacent equal letters. So define $A_k$ to be the subset of all permutations of $L$ such that $a_k$ is next to $a'_k$.
Then 
$$\biggl|\bigcup_{i=1}^n A_i\biggr| = \sum_{i=1}^n\left|A_i\right|\;
-\sum_{1 \le i < j \le n}\left|A_i\cap A_j\right|\; 
+ \sum_{1 \le i < j < k \le n}\left|A_i\cap A_j\cap A_k\right|\;-\ \ldots\ +\; \left(-1\right)^{n-1} \left|A_1\cap\cdots\cap A_n\right|\text{.}$$ 
The total minus this number is what we are looking for.
Now to count $A_k$ for a fixed $k$, we create a fake letter $A_k$ which equals $a_k a'_k$. Then we permute $L \cup \{A_k\} \setminus \{a_k, a'_k\}$, which has $(2n-1)$ elements. After permuting those in $(2n-1)!$ many ways, we identify the $a_i, a'_i$ for $i \neq k$ again, so we have $\frac{(2n-1)!}{2^{n-1}}$ such permutations. So the sum of the $A_i$ is just $n$ that (once for every index).
Now for the intersections of $l$ many $A_k$, we create $l$ fake letters $A_i$, and then permute $(2n- l)!$ many letters, divide by $2^{n-l}$ (for switching the remaining letters), and note that we have $\binom{n}{k}$ many such intersections, all with the same number. 
Now plug in the formula. 
