You are given an array \(A\) having \(N\) integers. Find the number of triplets \((i, j, k)\) such that
- \(1 \le i \lt j \lt k \le N\).
- The integer \(A_j\) is equal to the median of the integers \(A_i,A_j,A_k\).
The median of three integers is the middle element after sorting the three integers. For example, the median of \((5, 1, 3)\) is \(3\), \((2, 4, 4)\) is \(4\).
Input format
- The first line of input contains an integer \(T\) denoting the number of test cases. The description of each test case is as follows:
- The first line of each test case contains an integers \(N\).
- The second line of each test case contains \(N\) integers \(A_1, A_2,\dots, A_N\).
Output format
For each test case, print the number of triplets that satisfies the given conditions in a separate line.
Constraints
In the first test case, there are \(2\) tuples that satisfy the given conditions:
- \((1, 2, 4)\): The median of \((A_1, A_2, A_4)=(3, 5, 5)\) is \(5\) which is equal to \(A_2.\)
-
\((2, 4,5)\): The median of \((A_2, A_4, A_5)=(5, 5, 4)\) is \(5\) which is equal to \(A_4.\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor