#K87982. Unique Display Arrangements of Pastries
Unique Display Arrangements of Pastries
Unique Display Arrangements of Pastries
You are given a list of n pastries, where some pastries may be identical. Your task is to compute the total number of unique display arrangements that can be formed using all the pastries. The number of unique arrangements can be calculated using the formula:
$$\text{Answer} = \frac{n!}{n_1! \times n_2! \times \cdots} $$where:
- n is the total number of pastries, and
- ni is the frequency of each distinct pastry.
For example, if the list is ["Cake", "Donut", "Cake"], then n = 3 and the frequency of "Cake" is 2 and "Donut" is 1. The number of unique arrangements is:
Your program should read from stdin and write the answer to stdout.
inputFormat
The first line of the input contains an integer n — the number of pastries.
The second line contains n space-separated strings representing the names of the pastries.
For example:
3 Cake Donut Cake
outputFormat
Output a single integer — the number of unique display arrangements of the pastries.
For the above example, the output should be:
3## sample
3
Cake Donut Cake
3
</p>