#d21001. 数数
数数
Counting
Problem Description
For two points and on the plane, the Manhattan distance between them is .
A triple of points is called bad if and only if .
A sequence is called good if and only if you cannot choose three distinct indices from such that form a bad triple.
You are given a sequence of length . How many subsegments of are good?
Input Format
The first line contains an integer (), the number of test cases.
For each test case:
The first line contains an integer (), the length of .
The second line contains the sequence ().
Output Format
Output one number: the number of good subsegments of .
Sample Input
3
4
2 4 1 3
5
6 9 1 9 6
2
13 37
Sample Output
10
12
3
Sample Explanation
In the first sample, no subsegment is bad, so .
In the second sample, is bad, because
so $d((a_1, 1), (a_4, 4)) = d((a_1, 1), (a_2, 2)) + d((a_2, 2), (a_4, 4))$.