Specialized Academic Council
Limits: 2 sec., 512 MiB
Zenyk is getting ready to defend his dissertation at Ivan Franko National University of Lviv (LNU). The defense is held by a specialized academic council of five people. It consists of scientists from LNU and scientists from other institutions, called official opponents. Marichka works at the university, and it is she who has to form the council for Zenyk’s defense.
All scientific institutions are numbered with integers from 1 to \(m\). Everyone knows that LNU is number one.
The council is formed by the following rules:
First of all, the council is made up of three scientists from LNU and two official opponents.
If such a council cannot be formed, it is made up of two scientists from LNU and three official opponents. If a council can be formed by the first rule, the second rule may not be used.
All official opponents in the council must be from different institutions.
The members of the council can only be chosen from \(n\) given scientists. For the \(i\)-th of them, the number \(a_i\) of their institution is known.
Two councils are different if at least one member is in one of them but not in the other. The order of the members does not matter.
Help Marichka find the number of ways to form the specialized council.
Input
The first line contains two integers \(n\) and \(m\) – the number of scientists and the number of institutions.
The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) – the institution numbers of the scientists.
Output
Print one integer – the number of ways to form the specialized council.
Constraints
\(5 \le n \le 500\),
\(2 \le m \le 500\),
\(1 \le a_i \le m\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 6 3 1 1 1 1 2 3 | 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 5 4 1 1 2 3 4 | 1 |
| Input (stdin) | Output (stdout) |
|---|---|
| 5 2 1 1 1 2 2 | 0 |
| Input (stdin) | Output (stdout) |
|---|---|
| 6 4 1 1 1 2 3 4 | 3 |
Notes
In the first example, there are four possible councils (given by the numbers of the scientists):
1, 2, 3, 5, 6;
1, 2, 4, 5, 6;
1, 3, 4, 5, 6;
2, 3, 4, 5, 6.
In the second example, three scientists from LNU cannot be chosen, so the council is made up of two scientists from LNU and three official opponents. The only possible council consists of the scientists 1, 2, 3, 4, 5.
In the third example, the opponents cannot be chosen from different institutions, so no council can be formed.
In the fourth example, a council of three scientists from LNU and two official opponents can be formed, so a council of two scientists from LNU and three opponents may not be formed. There are three possible councils (given by the numbers of the scientists):
1, 2, 3, 4, 5;
1, 2, 3, 4, 6;
1, 2, 3, 5, 6.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|