How can I find the number of ways a sequence of numbers (may contain similar items) could be rearranged so that a number is not placed in the same place as it or its similar numbers were placed.

For example, `[0,0,0,1,1,1]` could be rearranged in only one way and that is `[1,1,1,0,0,0]`.

`[0,0,0,1,1,1,1]` cannot be arranged in any way.

`[1,2,2,14]` can be arranged in 2 ways i.e `[2,1,14,2], [2,14,1,2]`.

`[1,1,2,2,14]` can be arranged in 4 ways i.e `[14,2,1,1,2], [2,2,14,1,1], [2,2,1,14,1], [2,14,1,1,2]`.

The math solution is available but I was thinking some easy way out using the programming concepts. Math code is is a little like this.. (Excuse me i could not post in the correct format)

```
∫∞0 Ln1(x)..Lnr(x)e−xdx

```

where r is the number of items, ni is the number of occurrences of item i and Lk is the k-th Laguerre polynomial. For instance, for 1,1,2,2,14, we have r=3, n1=2, n2=2, n3=1, so up to a sign the number of rearrangements is

```
∫∞0 L2(x)L2(x)L1(x)e−xdx 
= ∫∞0 12(x2−4x+2)12(x2−4x+2)(1−x)e−xdx 
= ∫∞0(−14x5+94x4−7x3+9x2−5x+1)e−xdx
= −4

```

But I was thinking if there are any python libraries which could generate all permutations as desired by us.