Ilya is sitting in a waiting area of Metropolis airport and is bored of looking at time table that shows again and again that his plane is delayed. So he took out a sheet of paper and decided to solve some problems.

First Ilya has drawn a grid of size n × n and marked n squares on it, such that no two marked squares share the same row or the same column. He calls a rectangle on a grid with sides parallel to grid sides beautiful if exactly two of its corner squares are marked. There are exactly n·(n - 1) / 2 beautiful rectangles.

Ilya has chosen q query rectangles on a grid with sides parallel to grid sides (not necessarily beautiful ones), and for each of those rectangles he wants to find its beauty degree. Beauty degree of a rectangle is the number of beautiful rectangles that share at least one square with the given one.

Now Ilya thinks that he might not have enough time to solve the problem till the departure of his flight. You are given the description of marked cells and the query rectangles, help Ilya find the beauty degree of each of the query rectangles.

Input

The first line of input contains two integers n and q (2 ≤ n ≤ 200 000, 1 ≤ q ≤ 200 000) — the size of the grid and the number of query rectangles.

The second line contains n integers p1, p2, ..., pn, separated by spaces (1 ≤ pi ≤ n, all pi are different), they specify grid squares marked by Ilya: in column i he has marked a square at row pi, rows are numbered from 1 to n, bottom to top, columns are numbered from 1 to n, left to right.

The following q lines describe query rectangles. Each rectangle is described by four integers: l, d, r, u (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ u ≤ n), here l and r are the leftmost and the rightmost columns of the rectangle, d and u the bottommost and the topmost rows of the rectangle.

Output

For each query rectangle output its beauty degree on a separate line.

Examples

Input

2 3
1 2
1 1 1 1
1 1 1 2
1 1 2 2


Output

1
1
1


Input

4 2
1 3 2 4
4 1 4 4
1 1 2 3


Output

3
5

Note

The first sample test has one beautiful rectangle that occupies the whole grid, therefore the answer to any query is 1.

In the second sample test the first query rectangle intersects 3 beautiful rectangles, as shown on the picture below:

<image> <image> <image>

There are 5 beautiful rectangles that intersect the second query rectangle, as shown on the following picture:

<image> <image> <image> <image> <image>
import java.util.*;
import java.io.*;
/*
4 3
1 3 2 4
4 1 4 4
1 1 2 3
1 4 1 4

 */
public class c implements Runnable {
    PrintWriter out;
    int n, q;
    static long N;
    int[] rows;
    int[][] rects;
    public void main() throws Throwable {
        FastScanner in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        
        n = in.nextInt();
        q = in.nextInt();
        N = n;
        
        rows = new int[n];
        rects = new int[4][q];
        for (int i = 0; i < n; i++) {
            rows[i] = in.nextInt() - 1;
        }
        Query[] qs = new Query[q * 3];
        Rect[] mrs = new Rect[q];
        for (int i = 0; i < q; i++) {
            for (int j = 0; j < 4; j++) {
                rects[j][i] = in.nextInt() - 1;
            }
            Rect r = new Rect(rects[0][i], rects[1][i], rects[2][i], rects[3][i]);
            mrs[i] = r;
            qs[i] = new Query(r, r.l - 1, 0);
            qs[i+q] = new Query(r, r.r, 1);
            qs[i+q+q] = new Query(r, n - 1, 2);
        }
        BIT bit = new BIT(n + 3);
        Arrays.sort(qs);
        int curx = -1;

        for (Query q : qs) {
            while (curx < q.x) {
                curx++;
                bit.update(rows[curx], 1);
            }
            Rect r = q.rect;
            if (q.type == 0) {
                r.sw += bit.query(0, r.d - 1);
                r.w += bit.query(r.d, r.u);
                r.nw += bit.query(r.u + 1, n);
                
                r.s -= r.sw;
                r.c -= r.w;
                r.n -= r.nw;
            } else if (q.type == 1) {
                r.s += bit.query(0, r.d - 1);
                r.c += bit.query(r.d, r.u);
                r.n += bit.query(r.u + 1, n);
                
                r.se -= r.sw + r.s;
                r.e  -= r.w + r.c;
                r.ne -= r.nw + r.n;
            } else {
                r.se += bit.query(0, r.d - 1);
                r.e += bit.query(r.d, r.u);
                r.ne += bit.query(r.u + 1, n);
            }
        }
        for (Rect r : mrs) {
            out.println(r.getAns());
        }
        out.close();
    }

    static class Rect {
        long e, ne, n, nw, w, sw, s, se, c;
        int l, d, r, u;
        public Rect(int ll, int dd, int rr, int uu) {
            l = ll; d = dd; r = rr; u = uu;
        }
        public long getAns() {
            long ans = N * (N - 1) / 2;
            ans -= ne * e;
            ans -= ne * n;
            ans -= ne * nw;
            
            ans -= nw * n;
            ans -= nw * w;
            ans -= nw * sw;
            
            ans -= sw * w;
            ans -= sw * s;
            ans -= sw * se;
            
            ans -= se * s;
            ans -= se * e;
            ans -= se * ne;
            
            ans -= e * (e - 1) / 2;
            ans -= ne * (ne - 1) / 2;
            ans -= n * (n - 1) / 2;
            ans -= nw * (nw - 1) / 2;
            ans -= w * (w - 1) / 2;
            ans -= sw * (sw - 1) / 2;
            ans -= s * (s - 1) / 2;
            ans -= se * (se - 1) / 2;
            
            return ans;
        }
    }
    static class Query implements Comparable<Query> {
        Rect rect;
        int x;
        int type;
        public Query(Rect rectt, int xx, int typee) {
            rect = rectt; x = xx; type = typee;
        }
        public int compareTo(Query q) {
            if (x == q.x) return Integer.compare(type, q.type);
            return Integer.compare(x, q.x);
        }
    }
    
    
    static class BIT {
        int n;
        int[] tree;
        
        public BIT(int n) {
            this.n = n;
            tree = new int[n + 3];
        }
        int query(int a, int b) {
            a++;
            b++;
            if (a > b) return 0;
            return read(b) - read(a - 1);
        }
        int read(int i) {
            int sum = 0;
            while (i > 0) {
                sum += tree[i];
                i -= i & -i;
            }
            return sum;
        }
        
        void update(int i, int val) {
            i++;
            while (i <= n) {
                tree[i] += val;
                i += i & -i;
            }
        }
    }
    
    
    
    
    
    public static void main(String[] args) throws Exception {
        new Thread(null, new c(), "c", 1L << 28).start();
    }
    public void run() {
        try {
           main(); 
        } catch (Throwable t) {
            t.printStackTrace();
            System.exit(-1);
        }
    }
    static void sort(int[] arr) {
        Random rand = new Random();
        int n = arr.length;
        for (int i = 1; i < n; i++) {
            int j = rand.nextInt(i);
            int tmp = arr[i];
            arr[i] = arr[j];
            arr[j] = tmp;
        }
        Arrays.sort(arr);
    }
    static void sort(long[] arr) {
        Random rand = new Random();
        int n = arr.length;
        for (int i = 1; i < n; i++) {
            int j = rand.nextInt(i);
            long tmp = arr[i];
            arr[i] = arr[j];
            arr[j] = tmp;
        }
        Arrays.sort(arr);
    }
    static void sort(double[] arr) {
        Random rand = new Random();
        int n = arr.length;
        for (int i = 1; i < n; i++) {
            int j = rand.nextInt(i);
            double tmp = arr[i];
            arr[i] = arr[j];
            arr[j] = tmp;
        }
        Arrays.sort(arr);
    }
    static class FastScanner {
        BufferedReader br; StringTokenizer st;
        public FastScanner(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
            st = new StringTokenizer("");
        }
        public String next() throws Exception {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }
        public int nextInt() throws Exception {
            return Integer.parseInt(next());
        }
        public double nextDouble() throws Exception {
            return Double.parseDouble(next());
        }
        public long nextLong() throws Exception {
            return Long.parseLong(next());
        }
        public int[] nextIntArr(int n) throws Exception {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) arr[i] = nextInt();
            return arr;
        }
        public double[] nextDoubleArr(int n) throws Exception {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) arr[i] = nextDouble();
            return arr;
        }
        public long[] nextLongArr(int n) throws Exception {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) arr[i] = nextLong();
            return arr;
        }
        public int[] nextOffsetIntArr(int n) throws Exception {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) arr[i] = nextInt() - 1;
            return arr;
        }
        
        public int[][] nextIntArr(int n, int m) throws Exception {
            int[][] arr = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextInt();
            return arr;
        }
        public double[][] nextDoubleArr(int n, int m) throws Exception {
            double[][] arr = new double[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextDouble();
            return arr;
        }
        public long[][] nextLongArr(int n, int m) throws Exception {
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextLong();
            return arr;
        }
    }
}