This was a problem from the AOPS Intermediate Probability and Counting book, from a chapter on Principle of Inclusion Exclusion (PIE). I was able to follow the solution, but don't understand why PIE applies to the problem.
Essentially, they find the number of ways to seat exactly 1-5 pairs of twins together, and use PIE to calculate the number of ways that at least 1 pair of twins is together, and subtracts it from the total number of ways with no restriction.
So they do #ways-pair1 - #ways-pair2 + #ways-pair3 - #ways-pair4 + #ways-pair5
However, why does PIE work for this? When I think of PIE I think of venn diagrams and sets. The formula for PIE with n sets is basically sum (alternating sign) of the nth elementary symmetric sums, but intersecting instead of multiplying.
What would the sets in this problem be?
The sets, which you have called pair$n$, are the number of ways to seat the people so there are at least $n$ pairs next to each other. The point is that if you have exactly $2$ pairs seated next to each other you have counted the arrangement twice in pair$1$ so need to subtract one. If you have $3$ pairs seated next to each other you have counted the arrangement three times in pair$1$ and added them, then counted it three times in pair$2$ and subtracted them, so you need to add it in once and so on.