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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
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;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int dayCount = in.readInt();
            int needCores = in.readInt();
            int planCount = in.readInt();
            List<Plan>[][] changes = new List[dayCount + 1][2];
            for (int i = 0; i <= dayCount; i++) {
                for (int j = 0; j < 2; j++) {
                    changes[i][j] = new ArrayList<>();
                }
            }
            for (int i = 0; i < planCount; i++) {
                int from = in.readInt() - 1;
                int to = in.readInt() - 1;
                int cores = in.readInt();
                int price = in.readInt();
                Plan plan = new Plan(i, from, to, cores, price);
                changes[from][0].add(plan);
                changes[to + 1][1].add(plan);
            }
            long takenCores = 0;
            long takenPrice = 0;
            long answer = 0;
            TreeSet<Plan> takenPlans = new TreeSet<>();
            Plan lastTotallyTaken = new Plan(-1, -1, -1, 0, 0);
            takenPlans.add(lastTotallyTaken);
            for (int i = 0; i < dayCount; i++) {
                for (Plan add : changes[i][0]) {
                    takenPlans.add(add);
                    if (add.compareTo(lastTotallyTaken) < 0) {
                        takenCores += add.cores;
                        takenPrice += add.totalPrice();
                        while (takenCores > needCores) {
                            takenCores -= lastTotallyTaken.cores;
                            takenPrice -= lastTotallyTaken.totalPrice();
                            lastTotallyTaken = takenPlans.lower(lastTotallyTaken);
                        }
                    }
                }
                for (Plan rem : changes[i][1]) {
                    if (rem.compareTo(lastTotallyTaken) <= 0) {
                        takenCores -= rem.cores;
                        takenPrice -= rem.totalPrice();
                        if (rem.equals(lastTotallyTaken)) {
                            lastTotallyTaken = takenPlans.lower(lastTotallyTaken);
                        }
                    }
                    takenPlans.remove(rem);
                }
                while (takenPlans.higher(lastTotallyTaken) != null &&
                        takenCores + takenPlans.higher(lastTotallyTaken).cores <= needCores) {
                    Plan next = takenPlans.higher(lastTotallyTaken);
                    takenCores += next.cores;
                    takenPrice += next.totalPrice();
                    lastTotallyTaken = next;
                }
                long addPrice = 0;
                if (takenPlans.higher(lastTotallyTaken) != null) {
                    addPrice += (needCores - takenCores) * (long) takenPlans.higher(lastTotallyTaken).price;
                }
                answer += takenPrice + addPrice;
            }
            out.print(answer);
        }

        class Plan implements Comparable<Plan> {
            int index;
            int from;
            int to;
            int cores;
            int price;

            Plan(int index, int from, int to, int cores, int price) {
                this.index = index;
                this.from = from;
                this.to = to;
                this.cores = cores;
                this.price = price;
            }

            public int compareTo(Plan o) {
                int c = Integer.compare(price, o.price);
                if (c == 0) {
                    c = Integer.compare(index, o.index);
                }
                return c;
            }

            public boolean equals(Object obj) {
                return compareTo((Plan) obj) == 0;
            }

            long totalPrice() {
                return cores * (long) price;
            }

            public String toString() {
                return "Plan{" +
                        "index=" + index +
                        ", from=" + from +
                        ", to=" + to +
                        ", cores=" + cores +
                        ", price=" + price +
                        '}';
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }
}

