count how many permutations of numbers from 0 to 9 exist such that the first element is greater than 1 and the last one is less than 8. here is the solution using inclusion exclusion principle:
We  denote by X the set of permutations in which the first element is ≤1 and Y the set of permutations in which the last element is ≥8. Then the number of "bad" permutations, as on the inclusion-exclusion formula, will be:
|X∪Y|=|X|+|Y|−|X∩Y|
After a simple combinatorial calculation, we will get to:
2⋅9!+2⋅9!−2⋅2⋅8!
and then we subtract this value from 10!
I don't understand how do they end up with the combinatorial calculation of 2⋅9!+2⋅9!−2⋅2⋅8!
 A: There are two types of "bad permutations".  $X$ = Those that have $0$ or $1$ in the first place.  $Y$ = Those that have $8$ or $9$ in the last place. But then there are $X\cap Y$ that have both $0$ or $1$ in the first place and have $8$ or $9$ in the last place.
To figure out $|X|$ we have two choices for position $ONE$. $ONE$ can be $0$ or $1$.  Position $TWO$ can be anything but $ONE$ so there are $9$ choices.  Position $THREE$ can be anything but $ONE$ or $TWO$ so that's $8$ choices and so on.  So there are $2*9*8*7*6*5*4*3*2*1=2*9!$ permutations that satisfy $X$.
To figure out $|Y|$ we have two choices for position $TEN$.  $TEN$ can be $8$ or $9$.  Position $ONE$ can be anything but $TEN$ so there are $9$ choices.  And so on.  So there are $2*9*8*7*6*5*4*3*2*1=2*9!$ permutations that satisfy $Y$.
But then there are $X\cap Y$ that do both.  To figure out $|X\cap Y|$ we have two choices for position $ONE$; $0$ or $1$.  ANd we have two choices for position $TEN$; $8$ or $9$.  Then position $TWO$ can be anything but $ONE$ or $TEN$ so that is $8$ choices.  ANd position $THREE$ can be anything but $ONE, TEN$ or $TWO$ so that is $7$  choices.  An so on  SO there are $2*2*8*7*6*5*4*3*2*1= 4*8!$ permutations that satisfy $X\cap Y$.
But in counting the permutations in $X$ we counted the permutations in $X\cap Y$.  And in counting the permutations in $Y$ we counted the permutations in $X\cap Y$ again.  So we counted the bad permutations in $X\cap Y$ twice when we only should have counted them once.
So that total number of bad permutations are, all the permutations in $X$ (including $X\cap Y$) and all the permutations in $Y$ that DON"T include the permutation in $X\cap Y$ as we already counted them.  SO $|X| + |Y| - |X\cap Y| = (2*9!) + (2*9!) - (4*8!)$.
