#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f ? x : -x;
}
const long long N = 1e6 + 10, M = 2e5 + 10;
struct node {
  long long x, c, p;
} a[M << 1];
bool cmp(node a, node b) { return a.x < b.x; }
struct SGT {
  long long cnt, sum;
} t[N << 2];
void modify(long long u, long long l, long long r, long long x) {
  if (l == a[x].p && r == a[x].p) {
    t[u].cnt += a[x].c;
    t[u].sum += a[x].c * a[x].p;
    return;
  }
  long long mid = (l + r) >> 1;
  if (a[x].p <= mid)
    modify(u << 1, l, mid, x);
  else
    modify((u << 1) | 1, mid + 1, r, x);
  t[u].cnt = t[u << 1].cnt + t[(u << 1) | 1].cnt;
  t[u].sum = t[u << 1].sum + t[(u << 1) | 1].sum;
}
pair<long long, long long> query1(long long u, long long l, long long r,
                                  long long cnt) {
  if (l == r) {
    pair<long long, long long> res;
    if (t[u].cnt == cnt)
      res.first = l;
    else
      res.first = l - 1, res.second = l * cnt;
    return res;
  }
  long long mid = (l + r) >> 1;
  if (t[u << 1].cnt >= cnt) return query1(u << 1, l, mid, cnt);
  return query1((u << 1) | 1, mid + 1, r, cnt - t[u << 1].cnt);
}
long long query2(long long u, long long l, long long r, long long L,
                 long long R) {
  if (L <= l && r <= R) return t[u].sum;
  long long res = 0;
  long long mid = (l + r) >> 1;
  if (L <= mid) res += query2(u << 1, l, mid, L, R);
  if (R > mid) res += query2((u << 1) | 1, mid + 1, r, L, R);
  return res;
}
long long n, k, m, maxp, ans;
signed main() {
  n = read(), k = read(), m = read();
  for (long long i = 1; i <= m; i++) {
    long long l = read(), r = read(), c = read(), p = read();
    a[i * 2 - 1] = {l, c, p};
    a[i * 2] = {r + 1, -c, p};
    maxp = max(maxp, p);
  }
  sort(a + 1, a + m * 2 + 1, cmp);
  modify(1, 1, maxp, 1);
  for (long long i = 2; i <= m * 2; i++) {
    long long time = a[i].x - a[i - 1].x;
    if (t[1].cnt <= k)
      ans += t[1].sum * time;
    else {
      pair<long long, long long> tmp = query1(1, 1, maxp, k);
      long long res = tmp.second;
      if (tmp.first) res += query2(1, 1, maxp, 1, tmp.first);
      ans += res * time;
    }
    modify(1, 1, maxp, i);
  }
  printf("%lld", ans);
  return 0;
}
