The shame question let tutu feel vertigo, then you?
You are given a sequence a = (a1, ......, aN) of length N consisting of integers between 1 and N.
Find the number of pair of integers i, j that satisfy all of the following conditions;
· 1 <= i < j <= N
· min(ai, aj) = i
· max(ai, aj) = j
2 <= N <= 10000
1 <= ai <= N
all values in input are integers
N
a1 ... aN
answer
10 5 8 2 2 1 6 7 2 9 10
8