#include <bits/stdc++.h>
using namespace std;
struct fenwick_t {
  vector<long long> f;
  int n;
  fenwick_t(int n) : n(n) { f.resize(n + 1); }
  void add(int i, long long x) {
    for (int j = i; j <= n; j += j & (-j)) f[j] += x;
  }
  long long get(int i) {
    long long sum = 0;
    for (int j = i; j > 0; j -= j & (-j)) sum += f[j];
    return sum;
  }
};
struct event {
  long long pos, cores, price;
  int add;
  event() {}
  event(int a, int c, int p, int k) : pos(a), cores(c), price(p), add(k) {}
};
bool comp(const event &a, const event &b) {
  if (a.pos != b.pos) {
    return a.pos < b.pos;
  }
  return a.add < b.add;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, k, m;
  cin >> n >> k >> m;
  vector<event> e(2 * m);
  for (int i = 0; i < m; i++) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    e[i] = event(l, c, p, 1);
    e[m + i] = event(r + 1, c, p, -1);
  }
  sort(e.begin(), e.end(), comp);
  int prevpos = 1;
  long long dcost = 0, ans = 0;
  fenwick_t f1(1000000);
  fenwick_t f2(1000000);
  for (int i = 0; i < 2 * m; i++) {
    event t = e[i];
    ans += dcost * (t.pos - prevpos);
    prevpos = t.pos;
    f1.add(t.price, t.price * t.cores * t.add);
    f2.add(t.price, t.cores * t.add);
    if (f2.get(1000000) < k) {
      dcost = f1.get(1000000);
    } else {
      int l = 1, r = 1000000;
      while (l < r) {
        int mid = (l + r) / 2;
        if (f2.get(mid) < k) {
          l = mid + 1;
        } else {
          r = mid;
        }
      }
      long long t1 = f1.get(l - 1);
      long long c1 = f2.get(l - 1);
      dcost = 0;
      dcost += t1;
      dcost += l * (k - c1);
    }
  }
  cout << ans;
  return 0;
}
