Given a sequence with positive integers, , , , , and queries. Each query specifies three subarrays , , and . Bob wants to find the value
where is the length of the subarray and represents the number of shared common integers in all three subarrays.
For example, if the st subarray is , the nd subarray is , and the rd subarray is , the shared common integers are , and thus the value Bob wants to find is .
Input Specification
The first line of input contains two integers and (), indicating the length of the sequence and the number of queries.
The second line of input contains integers ().
Each of the following lines contains six integers, , , , , , ().
Output Specification
Output one integer per line for each query.
Constraints
Subtask | Points | Additional constraints |
---|---|---|
. | ||
No additional constraints. |
Sample Input
5 2
1 2 2 3 3
1 2 2 3 3 4
1 5 1 5 1 5
Sample Output
3
0
Comments