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.util.function.IntConsumer;

public class Solution {


    static MyScanner sc;
    private static PrintWriter out;
    static long M = 1000000007;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("200000 200000 ");
//        int[] tt = new int[200000];
//        for (int p = 0; p < tt.length; p++) {
//            tt[p] = p + 1;
//        }
//        Random rnd = new Random();
//        for (int i = tt.length - 1; i > 1; i--) {
//            int nn = rnd.nextInt(i);
//            int k = tt[i];
//            tt[i] = tt[nn];
//            tt[nn] = k;
//        }
//        for (int k : tt) {
//            stringBuilder.append(k + " ");
//        }
//
//        for (int i = 0; i < tt.length; i++) {
//            int l = rnd.nextInt(100000) + 1;
//            int r = rnd.nextInt(100000) + 1;
//            stringBuilder.append(l + " " + r + " ");
//            l += rnd.nextInt(50000);
//            r += rnd.nextInt(50000);
//            stringBuilder.append(l + " " + r + " ");
//        }


        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));

        long t = System.currentTimeMillis();
        solve();
        out.flush();
    }


    private static void solve() {
        int n = sc.nextInt();
        int q = sc.nextInt();
        SparseMatrix p = new SparseMatrix(n);
        int[][] data = new int[n][2];
        for (int l = 0; l < n; l++) {
            data[l][0] = l + 1;
            data[l][1] = sc.nextInt();
        }
        Arrays.sort(data, Comparator.comparingInt(t -> t[1]));
        for (int [] k : data) {
            p.add(k[0], k[1]);
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int d = sc.nextInt();
            int r = sc.nextInt();
            int u = sc.nextInt();


            int[] k11 = new int[]{l - 1, r, n};
            int[] k22 = new int[]{d - 1, u, n};

            long[][] longs = new long[3][3];

            for (int k1 = 0; k1 < 3; k1++) {
                for (int k2 = 0; k2 < 3; k2++) {
                    longs[k1][k2] = p.sum(k11[k1], k22[k2]);
                }
            }
            long res = 0;
            res += t(longs[2][2]);
            res -= t(longs[2][0]);
            res -= t(longs[2][2] - longs[2][1]);
            res -= t(longs[0][2]);
            res -= t(longs[2][2] - longs[1][2]) ;
            res += t(longs[0][0]);
            res += t(longs[2][0] - longs[1][0]);
            res += t(longs[0][2] - longs[0][1]);
            res += t(longs[2][2] - longs[2][1]-longs[1][2] + longs[1][1]);

            out.println(res);
//            out.flush(   );
        }
    }

    private static long t(long l) {
        return l * (l - 1) / 2;
    }


    private static void solveT() {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }

    private static final class AList {
        int[] data;
        int c = 0;

        public AList(int n) {
            this.data = new int[Math.max(Integer.highestOneBit(n - 1) << 1, 4)];
        }

        public AList() {
            this(4);
        }

        public AList(int[] data) {
            this(data.length);
            System.arraycopy(data, 0, this.data, 0, data.length);
        }

        public void sort() {
            Arrays.sort(data, 0, c);
        }

        public void work(IntConsumer intConsumer) {
            for (int i = 0; i < c; i++) {
                intConsumer.accept(data[i]);
            }
        }

        public void add(int k) {
            if (c == data.length) {
                data = Arrays.copyOf(data, data.length << 1);
            }
            data[c++] = k;
        }


    }

    private static final class SparseMatrix {
        AList[] init;

        public SparseMatrix(int n) {
            init = new AList[n + 1];
            for (int i = 1; i <= n; i++) {
                init[i] = new AList();
            }
        }

        public void add(int row, int column) {
            while (row < init.length) {
                init[row].add(column);
                row += row & (-row);
            }
        }


        private long sum(int x, int y) {
            if (x >= init.length) x = init.length - 1;
            if (y >= init.length) y = init.length - 1;
            if (y <= 0) return 0;
            long sum = 0;
            while (x > 0) {
                sum += r(x, y);
                x -= x & (-x);
            }
            return sum;
        }

        private long r(int x, int y) {
            return biSearch(init[x].data, 0, init[x].c, y);
        }
    }

    static int biSearch(int[] k, int from, int to, int val) {
        int r = Arrays.binarySearch(k, from, to, val + 1);
        if (r < 0) r = -r - 1;
        return r;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextInt();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

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

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


}