#709
Silver IV
It's Mooin' Time II
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John is trying to describe his favorite USACO contest to Elsie, but she is having trouble understanding why he likes it so much. He says "My favorite part of the contest was when Bessie said 'It's Mooin' Time' and mooed all over the contest."

Elsie still doesn't understand, so Farmer John downloads the contest as a text file and tries to explain what he means. The contest is defined as an array of NN (1N1061\le N\le 10^6) integers a1,a2,,aNa_1, a_2, \dots, a_N (1aiN1\le a_i\le N). Farmer John defines a moo as an array of three integers where the second integer equals the third but not the first. A moo is said to occur in the contest if it is possible to remove integers from the array until only the moo remains.

As Bessie allegedly "mooed all over the contest", help Elsie count the number of distinct moos that occur in the contest! Two moos are distinct if they do not consist of the same integers in the same order.

입력

The first line contains NN.

The second line contains NN space-separated integers a1,a2,,aNa_1,a_2,\dots,a_N.

출력

Output the number of distinct moos that occur in the contest.

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long" in Java, a "long long" in C/C++).

예제 입력 1

6
1 2 3 4 4 4

예제 출력 1

3

점수

Inputs 2-4: N102N\le 10^2Inputs 5-7: N104N\le 10^4Inputs 8-11: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver IV1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.