The layout of Farmer John's farm is quite peculiar, with a large circular road running around the perimeter of the main field where his cows graze during the day. Every morning, the cows cross this road on their way into the field, and every evening they cross it again as they leave the field and return to the barn.
As we know, cows are creatures of habit, and each cow crosses the road in the same way every day. Each cow enters the field at a different point from where she exits, and all crossing points are distinct. Farmer John owns cows, conveniently identified by integer IDs through , so there are exactly crossing points around the road. Farmer John records these crossing points by scanning around the circle clockwise and writing down the ID of the cow at each crossing point. This produces a sequence of numbers in which each cow ID appears exactly twice. He does not record which crossing points are entry points and which are exit points.
Looking at his map of crossing points, Farmer John is curious about how many pairs of cows might cross paths during the day. He calls a pair of cows a "crossing pair" if the path from the entry point to the exit point of cow must cross the corresponding path of cow . Please help Farmer John determine the total number of crossing pairs.
The first line contains number n~(1 \le n \le 50000). The next lines contain the cow IDs of the crossing points in clockwise order.
Print the total number of crossing pairs.
Example 1