#000066

reli

Traditionally, every leap year in the land of Baitovia a car race exhibition is held. Drivers and teams gather in the LowerBit City, where they show off their cars to an interested audience. Then each driver gets their number and the race begins. Drivers start going towards HigherBit City, one driver every 3 minutes, according to their starting numbers. By the end of the race, a big celebration is held in the HigherBit City after which the audience and participants collectively wash dishes. The winner of the race is declared only after the dishes are washed. Legend says that if the winner is declared while there are still dirty dishes, then there will be hunger until the next race.


But with modern times and modern views, the Ministry of Accidents, Cars, and Tourism believes that the race is too dangerous and wants to prohibit it. They say that the range of 3 minutes between two cars leads to the incredibly large amount of very risky passing. However, iff the interval was increased to 7 minutes, then the race would last until late in the night when no one would stay to wash the dishes. It is necessary to convince the representatives of the Ministry that despite the interval of 3 minutes there are not too many risky passings.


You know the data for the last race. More precisely: the number of participants N (1 <= N <= 100000) and the order in which the racers depart for the HigerBit City (their starting numbers). You are expected to determine the minimum number of passings that could happen in the race.


Note:

Participants' cars are marked with starting numbers from 1 to N, and they start in that order. In the race exactly two cars participate in every passing. Also, all the cars always make it to the finish line!


InputIn the first line of the standard input is the number of racers N. In each of the following N line there is one number. The i+1th line contains the starting number of the driver who was i-th at the finish line.

OutputWrite to the first and only line of the standard output the minimum number of passings modulus 10000.

Input:5
4
3
2
1
5

Output:6

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.