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