Cow Baseball

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John's NN cows (3N10003 \le N \le 1000) stand in a row on the number line, and no two of them stand at the same position. They are practicing throws with a baseball before an important game against the cows on the neighboring farm.

While Farmer John watches, three cows (X,Y,Z)(X, Y, Z) complete two successful throws. Cow XX throws the ball to cow YY, who stands to the right of XX, and then cow YY throws the ball to cow ZZ, who stands to the right of YY. The second throw travels at least as far as the first one and no more than twice as far. Count the triples (X,Y,Z)(X, Y, Z) that Farmer John could have been watching.

Input

  • Line 1: the number of cows, NN.
  • Lines 2 to N+1N + 1: each line holds the position of one cow, an integer between 00 and 100000000100\,000\,000.

Output

  • Line 1: the number of triples (X,Y,Z)(X, Y, Z) where YY is to the right of XX, ZZ is to the right of YY, and the distance from YY to ZZ is at least the distance from XX to YY and at most twice that distance.

Hint

In the first example five cows stand at positions 33, 11, 1010, 77, 44. The four triples that work are the cows at positions (1,3,7)(1, 3, 7), (1,4,7)(1, 4, 7), (4,7,10)(4, 7, 10), (1,4,10)(1, 4, 10).