#K88402. Counting Unique Colored Triangles

    ID: 37300 Type: Default 1000ms 256MiB

Counting Unique Colored Triangles

Counting Unique Colored Triangles

Andrew loves solving puzzles. In this problem, you are provided with a convex polygon that has (n) vertices, and each vertex is painted with a color denoted by an integer. Note that the same color may appear on multiple vertices, but the polygon might include several distinct colors. Your task is to determine the number of triangles that can be formed using three vertices such that every vertex in the triangle has a distinct color. Formally, if (m) is the number of unique colors present and (m \geq 3), then the number of valid triangles is given by (\binom{m}{3} = \frac{m \times (m - 1) \times (m - 2)}{6}). If (m < 3), no valid triangle can be formed.

inputFormat

The input consists of two lines. The first line contains a single integer (n) (with (n \geq 3)), representing the number of vertices of the polygon. The second line contains (n) space-separated integers where each integer represents the color of a vertex.

outputFormat

Output a single integer representing the number of valid triangles that can be formed with vertices of distinct colors.## sample

4
1 2 3 4
4