Is there a formula to calculate all possible unique permutations of `n` elements over `p` positions?

Please imagine the following scenario:
I have `p` positions (cells/spaces) to fill each with one element, let's have use letters as elements for example.
I have `n` letters in total and there may be some duplicate ones among them but I know in advance how many unique letters I have, `s`, and how many duplicates I have for each letter (0 or more).

So, resuming the situation, we have:

`p` = number of positions (cells/spaces to be filled with one element each);

`n` = number of total elements available (we'll take letters);

`s` = number of single symbols (= the total number of elements not counting duplicated ones, so let's have `S` is the set containing these symbols, `s` is its cardinality: `s=|S|`);

Obvious rule here is:

```
n >= p >= 1

```

and

```
n >= s >= 1

```

('cause `s` is a sort of subset of the `n` elements without duplicates, `n = s` when there's no duplicated elements.)

Then we can have `Oi`, with `i = 1...s`, to know either the number of
 duplicates (`0 <= Oi < n`) -OR- instances (`1 <= Oi <= n`)
of every `S` symbol (free choice on this, even I prefer the latter approach).

As a clarification case let's consider the letters that form the word "*danicotra*" and suppose we have 9 free spaces to fill with them.
In this case we will have: `p = 9, n = 9 and s = 8`
 (`s` is 8 because there are two "*a*" in "*danicotra*" so we have 9 elements (`n`) but only 8 single symbols (`s`) keeping the duplicate elements aside);
the "symbols set" is `S={d,a,n,i,c,o,t,r}`
and therefore we'll have the following 8 single symbols:

```
Symbol1 = "d"
Symbol2 = "a"
Symbol3 = "n"
Symbol4 = "i"
Symbol5 = "c"
Symbol6 = "o"
Symbol7 = "t"
Symbol8 = "r"

```

and `Oi` (with `i = 1...8`), if we count number of duplicates per symbol, like this:

```
O1=0
O2=1
O3=0
O4=0
O5=0
O6=0
O7=0
O8=0

```

or if we count number of instances per symbol (that is my favored), like this:

```
O1=1
O2=2
O3=1
O4=1
O5=1
O6=1
O7=1
O8=1

```

Ok, now that we took the above as sample case (and I described what `p`, `n`, `s`, `S` and `Oi` are like in this situation), let's get back to the question: is there a general formula I can apply to know the number of the possible unique`(*)` permutations with it?

`(*)` unique = I mean, 'cause I might happen having repetitions/duplicates if a same "symbol" is present more than once amongst the elements and I don't want to take 'em into account (see image below for example)

[![enter image description here](https://i.stack.imgur.com/DaW7A.png)](https://i.stack.imgur.com/DaW7A.png)

**EDIT:**

There's a general formula that works only "*partially*":

$$
\frac{n!}{(n-p)! \ (\prod\_{i=1}^s O\_i!)}
$$

BUT, as I just said, it only works "*partially*", that is:

* it gives correct results only if I have no duplicated symbols amongst
`n` elements (`n = s`) OR when I have `(n-1) <= p <= n`,
* while it **fails** when I have duplicated elements amongst `n` symbols (`1 <= s < n`) AND I have `1 <= p < (n-1)`.

In other words, it works with the above example with the word "*danicotra*" just because I have 9 elements and 9 positions to fill (`n = p`) but if I need to calculate the same thing with, for instance, `p = 7` ... that's the pain! :(

So far I'm still looking for the right formula, that works *always*.

Thanks for help