Hai, hai cu trăsioara

Time limit: 2s Memory limit: 256MB Input: Output:

„Hai, hai cu trăsioara, până-n deal la Mărioara” — Source

You are given an array vv of NN integers.

Define vavale (noun, plural văvăi) as a subset of 5 indices i1i_1, i2i_2, i3i_3, i4i_4, i5i_5 such that the following conditions are met:

  • 1i1<i2<i3<i4<i5N1 \le i_1 \lt i_2 \lt i_3 \lt i_4 \lt i_5 \le N
  • vi1>vi2<vi3>vi4<vi5v_{i_1} \gt v_{i_2} \lt v_{i_3} \gt v_{i_4} \lt v_{i_5}
  • vi1>vi3<vi5v_{i_1} \gt v_{i_3} \lt v_{i_5}

Informally, you could think of a vavale as the concatenation of a valley formed from i1i_1, i2i_2, i3i_3 with a valley formed from i3i_3, i4i_4, i5i_5, with the extra condition that vi3v_{i_3} is strictly smaller than vi1v_{i_1} and vi5v_{i_5} (in a valley the middle element is strictly smaller than its two endpoints).

Task

Count the number of văvăi modulo 2642^{64}.

Input data

The first line contains the integer NN. The second line contains NN integers, the array vv.

Output data

Output the number of văvăi modulo 2642^{64} (a nonnegative integer).

Constraints and clarifications

  • 5N200 0005 \le N \le 200\ 000
  • 1vi1091 \le v_i \le 10^9

Example 1

stdin

7
9 4 7 5 7 2 8

stdout

5

Explanation

The 55 văvăi are formed of the following indices:

  • 11, 22, 33, 44, 77;
  • 11, 22, 33, 66, 77;
  • 11, 22, 44, 66, 77;
  • 11, 22, 55, 66, 77;
  • 11, 44, 55, 66, 77.

Example 2

stdin

13
4 8 6 5 6 1 9 10 2 1 5 6 4

stdout

17

Log in or sign up to be able to send submissions!