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.*;
import java.util.*;
import java.math.BigInteger;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class C extends PrintWriter {

    int cnt1, cnt2;

    class Node {
        final int fx, tx;
        final int[] y;
        final Node l, r;

        Node(int x, int y) {
            this.fx = this.tx = x;
            this.y = new int[] { y };
            l = r = null;
        }

        Node(Node l, Node r) {
            this.fx = l.fx;
            this.tx = r.tx;

            this.l = l;
            this.r = r;

            int[] ly = l.y;
            int[] ry = r.y;

            int lp = 0, rp = 0;
            int len = ly.length + ry.length;

            y = new int[len];

            for (int i = 0; i < len; i++) {
                if ((rp == ry.length) || (lp < ly.length && ly[lp] < ry[rp])) {
                    y[i] = ly[lp++];
                } else {
                    y[i] = ry[rp++];
                }
            }
        }

        void cnt(int from, int to, int up1, int up2) {
            if (to < from || tx < from || to < fx) {
                return;
            }

            if (from <= fx && tx <= to) {
                int i1 = Arrays.binarySearch(y, up1);
                int i2 = Arrays.binarySearch(y, up2);

                if (i1 < 0) {
                    cnt1 += ~i1;
                } else {
                    cnt1 += i1 + 1;
                }

                if (i2 < 0) {
                    cnt2 += ~i2;
                } else {
                    cnt2 += i2 + 1;
                }
                return;
            }

            l.cnt(from, to, up1, up2);
            r.cnt(from, to, up1, up2);
        }

    }

    void run() {
        int n = nextInt(), q = nextInt();
        Node[] tree = new Node[n];

        for (int i = 0; i < n; i++) {
            tree[i] = new Node(i + 1, nextInt());
        }

        int m = n;

        while (m > 1) {
            int k = 0;
            for (int i = 1; i < m; i += 2) {
                tree[k++] = new Node(tree[i - 1], tree[i]);
            }

            if (m % 2 == 1) {
                tree[k++] = tree[m - 1];
            }
            m = k;
        }

        Node root = tree[0];

        for (int i = 0; i < q; i++) {
            int lx = nextInt(), dy = nextInt();
            int rx = nextInt(), uy = nextInt();

            cnt1 = cnt2 = 0;
            root.cnt(1, lx - 1, dy - 1, uy);

            long adg = lx - 1;
            long dg = cnt2;
            long a = adg - dg;
            long g = cnt1;
            long d = dg - g;

            cnt1 = cnt2 = 0;
            root.cnt(lx, rx, dy - 1, uy);
            long beh = rx - lx + 1;
            long eh = cnt2;
            long b = beh - eh;
            long h = cnt1;
            long e = eh - h;

            long abc = n - uy;
            long c = abc - a - b;

            long def = uy - dy + 1;
            long f = def - d - e;

            long ghk = dy - 1;
            long k = ghk - g - h;

            long ans = 0;

            ans += e * (n - e);
            ans += e * (e - 1) / 2;

            ans += (a + d) * (f + h + k);
            ans += b * (d + f + g + h + k);
            ans += (c + f) * (g + h);
            ans += c * d;

            // println(a + " " + b + " " + c + " " + d + " " + e + " " + f + " " + g + " " + h + " " + k);

            println(ans);

        }

    }

    void safeSort(int[] a) {
        int n = a.length;

        for (int i = 23; i < n; i++) {
            int j = rnd.nextInt(i);
            a[i] ^= a[j];
            a[j] ^= a[i];
            a[i] ^= a[j];
        }

        Arrays.sort(a);
    }

    boolean skip() {
        while (hasNext()) {
            next();
        }
        return true;
    }

    int[][] nextMatrix(int n, int m) {
        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                matrix[i][j] = nextInt();
        return matrix;
    }

    String next() {
        while (!tokenizer.hasMoreTokens())
            tokenizer = new StringTokenizer(nextLine());
        return tokenizer.nextToken();
    }

    boolean hasNext() {
        while (!tokenizer.hasMoreTokens()) {
            String line = nextLine();
            if (line == null) {
                return false;
            }
            tokenizer = new StringTokenizer(line);
        }
        return true;
    }

    int[] nextArray(int n) {
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = nextInt();
        }
        return array;
    }

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

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException err) {
            return null;
        }
    }

    public C(OutputStream outputStream) {
        super(outputStream);
    }

    static BufferedReader reader;
    static StringTokenizer tokenizer = new StringTokenizer("");
    static Random rnd = new Random();
    static boolean OJ;

    public static void main(String[] args) throws IOException {
        OJ = System.getProperty("ONLINE_JUDGE") != null;
        C solution = new C(System.out);
        if (OJ) {
            reader = new BufferedReader(new InputStreamReader(System.in));
            solution.run();
        } else {
            reader = new BufferedReader(new FileReader(new File(C.class.getName() + ".txt")));
            long timeout = System.currentTimeMillis();
            while (solution.hasNext()) {
                solution.run();
                solution.println();
                solution.println("----------------------------------");
            }
            solution.println("time: " + (System.currentTimeMillis() - timeout));
        }
        solution.close();
        reader.close();
    }
}