#K66932. Counting Distinct Permutations

    ID: 32530 Type: Default 1000ms 256MiB

Counting Distinct Permutations

Counting Distinct Permutations

You are given a list of n non-negative integers. Your task is to compute the number of distinct permutations that can be constructed by rearranging the list. In other words, if the list contains repeated elements, two permutations that are identical should be counted as one unique permutation.

Mathematically, the answer is given by the formula:

$$\frac{n!}{\prod_{i=1}^{k} (c_i)!}$$

where \(n\) is the total number of elements, \(c_i\) is the number of occurrences of the \(i^{th}\) distinct element, and \(k\) is the number of distinct elements in the list.

inputFormat

The input is given via standard input (stdin) and consists of two parts:

  • The first line contains a single integer \(n\) representing the number of elements in the list.
  • The second line contains \(n\) non-negative integers separated by spaces.

outputFormat

Output a single integer to standard output (stdout) which is the number of distinct permutations that can be formed from the list.

## sample
3
1 2 3
6