Absolute Pairwise Distance

아직 제출이 없습니다시간 제한5.5초메모리 제한512 MB

문제

John Doe invented a nice way to measure distance between two arrays of different length. Let a_1,,a_l_1a\_1, \ldots, a\_{l\_1} be the first array and b_1,,b_l_2b\_1, \ldots, b\_{l\_2} be the second one. Then d(a,b)=_i=1l_1_j=1l_2a_ib_jd(a, b) = \sum\limits\_{i=1}^{l\_1} \sum\limits\_{j=1}^{l\_2} |a\_i - b\_j|. Unfortunately, this distance function does not satisfy the triangle inequality, but John decided to conduct a few experiments anyway.

John has a large array a_1,,a_na\_1, \ldots, a\_n. He would like to know the values d((a_l_1,a_l_1+1,,a_r_1),(a_l_2,a_l_2+1,,a_r_2))d\left((a\_{l\_1}, a\_{l\_1+1}, \ldots, a\_{r\_1}), (a\_{l\_2}, a\_{l\_2+1}, \ldots, a\_{r\_2})\right) for qq instances of values (l_1,r_1,l_2,r_2)(l\_1, r\_1, l\_2, r\_2). Help him find these values.

입력

The first line contains two integers nn and qq: the number of elements in the array and the number of queries (1n,q1051 \le n, q \le 10^5). The second line contains nn integers a_1,,a_na\_1, \ldots, a\_n: the elements of John's large array (0a_i1080 \le a\_i \le 10^8). The next qq lines contain four integers each: l_1l\_1, r_1r\_1, l_2l\_2, r_2r\_2, which are the parameters of the respective query (1l_1r_1n1 \le l\_1 \le r\_1 \le n, 1l_2r_2n1 \le l\_2 \le r\_2 \le n).

출력

For each query, print the value of d((a_l_1,a_l_1+1,,a_r_1),(a_l_2,a_l_2+1,,a_r_2))d\left((a\_{l\_1}, a\_{l\_1+1}, \ldots, a\_{r\_1}), (a\_{l\_2}, a\_{l\_2+1}, \ldots, a\_{r\_2})\right).