#P7527. [USACO21OPEN] United Cows of Farmer John G

[USACO21OPEN] United Cows of Farmer John G

Description

The United Cows of Farmer John (UCFJ) is going to select a team to participate in the International bOvine olympIad (IOI).

There are NN cows taking part in the team selection. They stand in a line, and cow ii has breed bib_i.

The team will be a contiguous interval containing at least two cows—namely, cows lrl \dots r for some 1l<rN1 \le l < r \le N. The cows at the two ends will be designated as leaders. To avoid conflicts within the same breed, each leader must have a breed different from every other member of the team (including the other leader).

Please help UCFJ find the number of ways to choose a team that can be sent to the IOI.

Input Format

The first line contains NN.

The second line contains NN integers b1,b2,,bNb_1, b_2, \dots, b_N, each in the range [1,N][1, N].

Output Format

Output one line with the number of possible teams.

7
1 2 3 4 3 2 5
13

Hint

Sample Explanation

Each team corresponds to the following pair of leaders:

$$(1,2),(1,3),(1,4),(1,7),(2,3),(2,4),(3,4),(4,5),(4,6),(4,7),(5,6),(5,7),(6,7).$$

Constraints

1N2×1051 \le N \le 2 \times 10^5.

Translated by ChatGPT 5