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 of integers.
Define vavale (noun, plural văvăi) as a subset of 5 indices , , , , such that the following conditions are met:
Informally, you could think of a vavale as the concatenation of a valley formed from , , with a valley formed from , , , with the extra condition that is strictly smaller than and (in a valley the middle element is strictly smaller than its two endpoints).
Task
Count the number of văvăi modulo .
Input data
The first line contains the integer . The second line contains integers, the array .
Output data
Output the number of văvăi modulo (a nonnegative integer).
Constraints and clarifications
Example 1
stdin
7
9 4 7 5 7 2 8
stdout
5
Explanation
The văvăi are formed of the following indices:
- , , , , ;
- , , , , ;
- , , , , ;
- , , , , ;
- , , , , .
Example 2
stdin
13
4 8 6 5 6 1 9 10 2 1 5 6 4
stdout
17