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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int numQueries = in.nextInt();
            int[] p = new int[n + 2];
            p[0] = -1;
            p[n + 1] = -1;
            for (int i = 1; i <= n; i++) {
                p[i] = in.nextInt();
            }
            Rectangle[] rectanglesMinus = new Rectangle[4 * numQueries];
            Rectangle[] rectanglesPlus = new Rectangle[4 * numQueries];

            for (int queryId = 0; queryId < numQueries; queryId++) {
                int c1 = in.nextInt();
                int r1 = in.nextInt();
                int c2 = in.nextInt();
                int r2 = in.nextInt();
                rectanglesMinus[4 * queryId + 0] = new Rectangle(0, 0, r1 - 1, n + 1);
                rectanglesMinus[4 * queryId + 1] = new Rectangle(0, 0, n + 1, c1 - 1);
                rectanglesMinus[4 * queryId + 2] = new Rectangle(r2 + 1, 0, n + 1, n + 1);
                rectanglesMinus[4 * queryId + 3] = new Rectangle(0, c2 + 1, n + 1, n + 1);

                rectanglesPlus[4 * queryId + 0] = new Rectangle(0, 0, r1 - 1, c1 - 1);
                rectanglesPlus[4 * queryId + 1] = new Rectangle(0, c2 + 1, r1 - 1, n + 1);
                rectanglesPlus[4 * queryId + 2] = new Rectangle(r2 + 1, 0, n + 1, c1 - 1);
                rectanglesPlus[4 * queryId + 3] = new Rectangle(r2 + 1, c2 + 1, n + 1, n + 1);
            }

            int[] insideMinus = new int[rectanglesMinus.length];
            calcPointsInside(n + 2, p, rectanglesMinus, insideMinus);

            int[] insidePlus = new int[rectanglesMinus.length];
            calcPointsInside(n + 2, p, rectanglesPlus, insidePlus);

            long[] ans = new long[numQueries];
            Arrays.fill(ans, (long) n * (n - 1) / 2);
            for (int i = 0; i < insideMinus.length; i++) {
                long k = insideMinus[i];
                ans[i / 4] -= k * (k - 1) / 2;
            }
            for (int i = 0; i < insidePlus.length; i++) {
                long k = insidePlus[i];
                ans[i / 4] += k * (k - 1) / 2;
            }

            for (long x : ans) {
                out.println(x);
            }
        }

        private void calcPointsInside(int n, int[] p, Rectangle[] rs, int[] inside) {
            int[] tree = new int[n];
            Segment[] segments = new Segment[2 * rs.length];
            for (int i = 0; i < rs.length; i++) {
                segments[2 * i + 0] = new Segment(rs[i].r1, rs[i].r2, rs[i].c1, true, i);
                segments[2 * i + 1] = new Segment(rs[i].r1, rs[i].r2, rs[i].c2 + 1, false, i);
            }
            Segment[] first = new Segment[n + 1];
            for (Segment s : segments) {
                s.next = first[s.x];
                first[s.x] = s;
            }
            int ptr = 0;
            for (int x = 0; x <= n; x++) {
                while (ptr <= x - 1 && ptr < p.length) {
                    int r = p[ptr++];
                    if (r >= 0) {
                        add(tree, r);
                    }
                }
                for (Segment s = first[x]; s != null; s = s.next) {
                    if (s.opens) {
                        inside[s.id] -= sum(tree, s.l, s.r);
                    } else {
                        inside[s.id] += sum(tree, s.l, s.r);
                    }
                }
            }
        }

        private void add(int[] tree, int pos) {
            while (pos < tree.length) {
                ++tree[pos];
                pos |= pos + 1;
            }
        }

        private int sum(int[] tree, int l, int r) {
            return sum(tree, r) - sum(tree, l - 1);
        }

        private int sum(int[] tree, int r) {
            int res = 0;
            while (r >= 0) {
                res += tree[r];
                r = (r & (r + 1)) - 1;
            }
            return res;
        }

        class Segment implements Comparable<Segment> {
            int l;
            int r;
            int x;
            boolean opens;
            int id;
            Segment next;

            Segment(int l, int r, int x, boolean opens, int id) {
                this.l = l;
                this.r = r;
                this.x = x;
                this.opens = opens;
                this.id = id;
            }

            public int compareTo(Segment o) {
                return x - o.x;
            }

        }

        class Rectangle {
            int r1;
            int r2;
            int c1;
            int c2;

            Rectangle(int r1, int c1, int r2, int c2) {
                this.r1 = r1;
                this.c1 = c1;
                this.r2 = r2;
                this.c2 = c2;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

