Given a sequence
with
positive integers,
,
,
,
, and
queries. Each query specifies three subarrays
,
, and
. Bob wants to find the value
![\displaystyle \text{len}(L_1, R_1) + \text{len}(L_2, R_2) + \text{len}(L_3, R_3) - 3 \times \big| a[L_1:R_1] \cap a[L_2:R_2] \cap a[L_3:R_3] \big|](//static.dmoj.ca/mathoid/f10bdce72fa528acc5b8bd03370a6ae23f955c1d/svg)
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
Copy
5 2
1 2 2 3 3
1 2 2 3 3 4
1 5 1 5 1 5
Sample Output
Copy
3
0
Comments