Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day.

The cloud provider offers m tariff plans, the i-th tariff plan is characterized by the following parameters:

  * l_i and r_i — the i-th tariff plan is available only on days from l_i to r_i, inclusive, 
  * c_i — the number of cores per day available for rent on the i-th tariff plan, 
  * p_i — the price of renting one core per day on the i-th tariff plan. 



Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to c_i) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.

Find the minimum amount of money that Buber will pay for its work for n days from 1 to n. If on a day the total number of cores for all available tariff plans is strictly less than k, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly k cores this day.

Input

The first line of the input contains three integers n, k and m (1 ≤ n,k ≤ 10^6, 1 ≤ m ≤ 2⋅10^5) — the number of days to analyze, the desired daily number of cores, the number of tariff plans.

The following m lines contain descriptions of tariff plans, one description per line. Each line contains four integers l_i, r_i, c_i, p_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ c_i, p_i ≤ 10^6), where l_i and r_i are starting and finishing days of the i-th tariff plan, c_i — number of cores, p_i — price of a single core for daily rent on the i-th tariff plan.

Output

Print a single integer number — the minimal amount of money that Buber will pay.

Examples

Input

5 7 3
1 4 5 3
1 3 5 2
2 5 10 1


Output

44


Input

7 13 5
2 3 10 7
3 5 10 10
1 2 10 6
4 5 10 9
3 4 10 8


Output

462


Input

4 100 3
3 3 2 5
1 1 3 2
2 4 4 4


Output

64
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class TaskC {
        BigInteger findCost(ArrayList<Long> prices, Fenwick counts, Fenwick total, int l, int r, int k) {
            int pn = counts.n;
            long sum = counts.get(pn - 1);
            if (sum <= k) {
                return BigInteger.valueOf(total.get(pn - 1)).multiply(BigInteger.valueOf(r - l + 1));
            } else {
                int left = 1;
                int right = pn - 1;
                while (left < right) {
                    int mid = (left + right) / 2;
                    long cnt = counts.get(mid);
                    if (cnt <= k) {
                        left = mid + 1;
                    } else {
                        right = mid;
                    }
                }

                long cost = total.get(right - 1);
                long cores = counts.get(right - 1);
                return BigInteger.valueOf(cost + (prices.get(right - 1)) * (k - cores)).multiply(BigInteger.valueOf(r - l + 1));
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.ni();
            int k = in.ni();
            int m = in.ni();
            Interval[] intervals = new Interval[m];
            for (int i = 0; i < m; i++) {
                int l = in.ni();
                int r = in.ni();
                int c = in.ni();
                int p = in.ni();
                intervals[i] = new Interval(l, r, c, p);
            }
            ArrayList<Long> prices = new ArrayList<>();
            Arrays.sort(intervals, (o1, o2) -> Long.compare(o1.p, o2.p));
            long price = 0;
            int pi = 0;
            for (Interval interval : intervals) {
                if (interval.p > price) {
                    prices.add(interval.p);
                    price = interval.p;
                    pi++;
                }
                interval.pi = pi;
            }
            int l = 1;
            Arrays.sort(intervals, (a, b) -> Integer.compare(a.l, b.l));
            PriorityQueue<Interval> pq = new PriorityQueue<Interval>((o1, o2) -> Integer.compare(o1.r, o2.r));
            int pn = prices.size();
            Fenwick tree = new Fenwick(pn + 7);
            Fenwick total = new Fenwick(pn + 7);
            BigInteger ans = BigInteger.ZERO;
            for (int i = 0; i < m; i++) {
                Interval interval = intervals[i];
                if (interval.l > l) {
                    while (pq.size() > 0 && pq.peek().r < interval.l) {
                        Interval peek = pq.peek();
                        if (peek.r >= l) {
                            ans = ans.add(findCost(prices, tree, total, l, peek.r, k));
                            l = peek.r + 1;
                        }
                        Interval remove = pq.poll();
                        tree.add(remove.pi, -remove.c);
                        total.add(remove.pi, -remove.p * remove.c);
                    }
                    if (l < interval.l) {
                        ans = ans.add(findCost(prices, tree, total, l, interval.l - 1, k));
                    }
                    l = interval.l;
                }
                pq.add(interval);
                tree.add(interval.pi, interval.c);
                total.add(interval.pi, interval.p * interval.c);
            }

            while (pq.size() > 0) {
                Interval peek = pq.peek();
                if (peek.r >= l) {
                    ans = ans.add(findCost(prices, tree, total, l, peek.r, k));
                    l = peek.r + 1;
                }
                Interval remove = pq.poll();
                tree.add(remove.pi, -remove.c);
                total.add(remove.pi, -remove.p * remove.c);
            }
            out.println(ans);
        }

        class Interval {
            int l;
            int r;
            long c;
            long p;
            int pi;

            public Interval(int l, int r, int c, int p) {
                this.l = l;
                this.r = r;
                this.c = c;
                this.p = p;
            }

        }

    }

    static class Fenwick {
        public int n;
        public long[] t;

        public Fenwick(int n) {
            this.n = n;
            t = new long[n];
        }

        public long get(int r) {
            long ans = 0;
            while (r >= 0) {
                ans += t[r];
                r = (r & (r + 1)) - 1;
            }
            return ans;
        }

        public void add(int pos, long val) {
            while (pos < n) {
                t[pos] += val;
                pos |= pos + 1;
            }
        }

    }

    static class InputReader extends BufferedReader {
        public InputReader(InputStream st) {
            super(new InputStreamReader(st));
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        private int readByte() {
            try {
                return read();
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }

        public int ni() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}

